Working on contrib/topology/

release
slava 2006-07-27 22:57:44 +00:00
parent 7223b8c637
commit e18191daf4
4 changed files with 46 additions and 11 deletions

View File

@ -25,13 +25,14 @@ IN: hopf
! Differentiate using d ! Differentiate using d
: ?set-hash ( value key hash/f -- hash )
[ [ set-hash ] keep ] [ associate ] if* ;
SYMBOL: degrees SYMBOL: degrees
H{ } clone degrees set : deg= degrees [ ?set-hash ] change ;
: deg= degrees get set-hash ; : deg degrees get ?hash ;
: deg degrees get hash ;
: h. ( vec -- ) : h. ( vec -- )
hash>alist [ first2 >r concat r> 2array ] map (l.) ; hash>alist [ first2 >r concat r> 2array ] map (l.) ;
@ -67,14 +68,17 @@ H{ } clone degrees set
: duplicates? ( seq -- ? ) : duplicates? ( seq -- ? )
dup prune [ length ] 2apply > ; dup prune [ length ] 2apply > ;
: odd* ( n terms1 terms2 -- n terms ) : (odd*) ( n terms -- n terms )
append dup duplicates? [ dup duplicates? [
2drop 0 { } 2drop 0 { }
] [ ] [
dup permutation inversions -1^ rot * dup permutation inversions -1^ rot *
swap natural-sort swap natural-sort
] if ; ] if ;
: odd* ( n terms1 terms2 -- n terms )
append (odd*) ;
: even* ( terms1 terms2 -- terms ) : even* ( terms1 terms2 -- terms )
append natural-sort ; append natural-sort ;
@ -96,11 +100,10 @@ H{ } clone degrees set
SYMBOL: boundaries SYMBOL: boundaries
H{ } clone boundaries set : d= ( value basis -- )
boundaries [ ?set-hash ] change ;
: d= ( value basis -- ) boundaries get set-hash ; : ((d)) ( basis -- value ) boundaries get ?hash ;
: ((d)) ( basis -- value ) boundaries get hash ;
: dx.y ( x y -- vec ) >r ((d)) r> h* ; : dx.y ( x y -- vec ) >r ((d)) r> h* ;
@ -133,6 +136,8 @@ DEFER: (d)
3dup nth-bit? [ nth ] [ 2drop f ] if 3dup nth-bit? [ nth ] [ 2drop f ] if
] map [ ] subset 2nip ; ] map [ ] subset 2nip ;
SYMBOL: generators
: basis ( generators -- seq ) : basis ( generators -- seq )
[ [
dup length 1+ [ drop V{ } clone ] map \ basis set dup length 1+ [ drop V{ } clone ] map \ basis set
@ -142,4 +147,4 @@ DEFER: (d)
\ basis get [ [ { } 2array ] map ] map \ basis get [ [ { } 2array ] map ] map
] with-scope ; ] with-scope ;
: H* ( generators -- seq ) basis ker/im-d (H*) ; : H* ( -- seq ) generators get basis ker/im-d (H*) ;

View File

@ -0,0 +1,14 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: laplacian
USING: arrays hopf kernel namespaces sequences topology ;
! Some words for computing the Hodge star map (*), and the
! Laplacian.
: (star) ( term -- term )
generators get [ swap member? not ] subset-with
1 swap (odd*) h* ;
: star ( x -- *x )
>h [ first (star) ] linear-op ;

View File

@ -4,8 +4,10 @@ PROVIDE: topology
"linear.factor" "linear.factor"
"simplex.factor" "simplex.factor"
"hopf.factor" "hopf.factor"
"laplacian.factor"
} { } {
"test/matrix.factor" "test/matrix.factor"
"test/simplex.factor" "test/simplex.factor"
"test/hopf.factor" "test/hopf.factor"
"test/laplacian.factor"
} ; } ;

View File

@ -0,0 +1,14 @@
IN: temporary
USING: hopf kernel laplacian namespaces test topology ;
SYMBOLS: x y z ;
{ x y z } generators set
1 x deg=
1 y deg=
1 z deg=
[ t ] [ x star y z h* = ] unit-test
[ t ] [ y star z x h* = ] unit-test
[ t ] [ z star x y h* = ] unit-test