factor/libs/topology/simplex.factor

82 lines
1.8 KiB
Factor
Raw Normal View History

2006-07-14 03:29:42 -04:00
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2006-07-14 06:57:47 -04:00
IN: simplex
2006-07-14 05:36:26 -04:00
USING: arrays hashtables io kernel math matrices namespaces
prettyprint sequences topology words ;
2006-05-09 11:31:28 -04:00
! Utilities
: (lengthen) ( seq n -- seq )
over length - f <array> append ;
: lengthen ( sim sim -- sim sim )
2dup max-length tuck (lengthen) >r (lengthen) r> ;
: <point> ( -- sim ) gensym 1array ;
: (C) ( point sim -- sim )
[ [ append natural-sort ] map-with ] map-with ;
2006-07-14 05:36:26 -04:00
: (\/) ( sim sim -- sim )
lengthen [ append natural-sort ] 2map ;
2006-05-09 11:31:28 -04:00
! Simplicial complexes
SYMBOL: basepoint
: {*} ( -- sim )
#! Initial object in category
{ { { basepoint } } } ;
: \/ ( sim sim -- sim )
#! Glue two complexes at base point
(\/) [ prune ] map ;
: +point ( sim -- sim )
#! Adjoint an isolated point
2006-07-14 05:36:26 -04:00
unclip <point> add add* ;
2006-05-09 11:31:28 -04:00
: C ( sim -- sim )
#! Cone on a space
2006-07-14 05:36:26 -04:00
[
<point> dup 1array >r swap (C) r> add*
] keep (\/) ;
2006-05-09 11:31:28 -04:00
: S ( sim -- sim )
#! Suspension
[
<point> <point> 2dup 2array >r
2006-07-14 05:36:26 -04:00
pick (C) >r swap (C) r> (\/) r> add*
2006-05-09 11:31:28 -04:00
] keep (\/) ;
: S^0 ( -- sim )
#! Degenerate sphere -- two points
{*} +point ;
: S^ ( n -- sim )
#! Sphere
S^0 swap [ S ] times ;
: D^ ( n -- sim )
#! Disc
1- S^ C ;
2006-07-14 05:36:26 -04:00
! Boundary operator
: (d) ( seq -- chain )
2006-05-09 11:31:28 -04:00
dup length 1 <= [
H{ }
] [
2006-07-14 05:36:26 -04:00
dup length [ 2dup >r remove-nth r> -1^ ] map>hash
2006-05-09 11:31:28 -04:00
] if nip ;
2006-07-14 05:36:26 -04:00
: d ( chain -- chain )
[ (d) ] linear-op ;
: d-matrix ( n sim -- matrix )
[ ?nth ] 2keep >r 1- r> ?nth [ (d) ] op-matrix ;
2006-05-09 11:31:28 -04:00
: ker/im-d ( sim -- seq )
2006-07-14 05:36:26 -04:00
#! Dimension of kernel of C_{n-1} --> C_n, subsp. of C_{n-1}
#! Dimension of image C_{n-1} --> C_n, subsp. of C_n
dup length [ swap d-matrix null/rank 2array ] map-with ;
2006-05-09 11:31:28 -04:00
: H ( sim -- seq ) ker/im-d (H) ;