2006-07-14 03:29:42 -04:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-07-09 21:57:19 -04:00
|
|
|
USING: arrays errors hashtables io kernel math namespaces parser
|
2006-07-14 05:36:26 -04:00
|
|
|
prettyprint sequences topology words ;
|
2006-07-09 21:57:19 -04:00
|
|
|
IN: hopf
|
|
|
|
|
|
2006-07-14 03:29:42 -04:00
|
|
|
! Finitely generated Hopf algebras.
|
|
|
|
|
|
2006-07-09 21:57:19 -04:00
|
|
|
! An element is represented as a hashtable mapping basis
|
|
|
|
|
! elements to scalars.
|
|
|
|
|
|
2006-07-10 00:50:51 -04:00
|
|
|
! A basis element is a pair of arrays, odd/even generators.
|
2006-07-09 21:57:19 -04:00
|
|
|
|
2006-07-10 00:50:51 -04:00
|
|
|
! Define degrees using deg=
|
2006-07-09 21:57:19 -04:00
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
! Add elements using l+
|
2006-07-10 00:50:51 -04:00
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
! Multiply elements using h*
|
2006-07-10 00:50:51 -04:00
|
|
|
|
|
|
|
|
! The co-unit is co1
|
|
|
|
|
|
|
|
|
|
! Print elements using h.
|
|
|
|
|
|
|
|
|
|
! Define the differential using d=
|
|
|
|
|
|
|
|
|
|
! Differentiate using d
|
2006-07-09 21:57:19 -04:00
|
|
|
|
|
|
|
|
SYMBOL: degrees
|
|
|
|
|
|
|
|
|
|
H{ } clone degrees set
|
|
|
|
|
|
|
|
|
|
: deg= degrees get set-hash ;
|
|
|
|
|
|
|
|
|
|
: deg degrees get hash ;
|
|
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
: h. ( vec -- )
|
|
|
|
|
hash>alist [ first2 >r concat r> 2array ] map (l.) ;
|
|
|
|
|
|
2006-07-09 21:57:19 -04:00
|
|
|
: <basis-elt> ( generators -- { odd even } )
|
|
|
|
|
V{ } clone V{ } clone
|
|
|
|
|
rot [
|
|
|
|
|
3dup deg odd? [ drop ] [ nip ] if push
|
|
|
|
|
] each [ >array ] 2apply 2array ;
|
|
|
|
|
|
|
|
|
|
: >h ( obj -- vec )
|
|
|
|
|
{
|
|
|
|
|
{ [ dup not ] [ drop 0 >h ] }
|
|
|
|
|
{ [ dup number? ] [ { { } { } } associate ] }
|
|
|
|
|
{ [ dup array? ] [ <basis-elt> 1 swap associate ] }
|
|
|
|
|
{ [ dup hashtable? ] [ ] }
|
|
|
|
|
{ [ t ] [ 1array >h ] }
|
|
|
|
|
} cond ;
|
|
|
|
|
|
2006-07-10 00:50:51 -04:00
|
|
|
: co1 ( vec -- n ) { { } { } } swap hash [ 0 ] unless* ;
|
|
|
|
|
|
2006-07-09 21:57:19 -04:00
|
|
|
: permutation ( seq -- perm )
|
|
|
|
|
dup natural-sort [ swap index ] map-with ;
|
|
|
|
|
|
|
|
|
|
: (inversions) ( n seq -- n )
|
|
|
|
|
[ > ] subset-with length ;
|
|
|
|
|
|
|
|
|
|
: inversions ( seq -- n )
|
|
|
|
|
0 swap dup length [
|
|
|
|
|
swap [ nth ] 2keep >r 1+ r> tail-slice (inversions) +
|
|
|
|
|
] each-with ;
|
|
|
|
|
|
|
|
|
|
: duplicates? ( seq -- ? )
|
|
|
|
|
dup prune [ length ] 2apply > ;
|
|
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
: odd* ( n terms1 terms2 -- n terms )
|
2006-07-09 21:57:19 -04:00
|
|
|
append dup duplicates? [
|
|
|
|
|
2drop 0 { }
|
|
|
|
|
] [
|
|
|
|
|
dup permutation inversions -1^ rot *
|
|
|
|
|
swap natural-sort
|
|
|
|
|
] if ;
|
|
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
: even* ( terms1 terms2 -- terms )
|
2006-07-09 21:57:19 -04:00
|
|
|
append natural-sort ;
|
|
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
: (h*) ( n basis1 basis2 -- n basis )
|
2006-07-09 21:57:19 -04:00
|
|
|
[
|
2006-07-14 05:36:26 -04:00
|
|
|
[ first ] 2apply odd*
|
|
|
|
|
] 2keep [ second ] 2apply even* 2array ;
|
2006-07-09 21:57:19 -04:00
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
: h* ( x y -- x.y )
|
2006-07-09 21:57:19 -04:00
|
|
|
[ >h ] 2apply [
|
|
|
|
|
[
|
|
|
|
|
rot [
|
|
|
|
|
2swap [
|
2006-07-14 05:36:26 -04:00
|
|
|
swapd * -rot (h*) +@
|
2006-07-09 21:57:19 -04:00
|
|
|
] 2keep
|
|
|
|
|
] hash-each 2drop
|
|
|
|
|
] hash-each-with
|
|
|
|
|
] make-hash canonicalize ;
|
|
|
|
|
|
|
|
|
|
SYMBOL: boundaries
|
|
|
|
|
|
|
|
|
|
H{ } clone boundaries set
|
|
|
|
|
|
|
|
|
|
: d= ( value basis -- ) boundaries get set-hash ;
|
|
|
|
|
|
|
|
|
|
: ((d)) ( basis -- value ) boundaries get hash ;
|
|
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
: dx.y ( x y -- vec ) >r ((d)) r> h* ;
|
2006-07-09 21:57:19 -04:00
|
|
|
|
|
|
|
|
DEFER: (d)
|
|
|
|
|
|
2006-07-14 05:36:26 -04:00
|
|
|
: x.dy ( x y -- vec ) [ (d) h* ] keep [ deg ] map sum -1^ h* ;
|
2006-07-09 21:57:19 -04:00
|
|
|
|
|
|
|
|
: (d) ( product -- value )
|
2006-07-14 05:36:26 -04:00
|
|
|
#! d(x.y)=dx.y + (-1)^deg y x.dy
|
2006-07-09 21:57:19 -04:00
|
|
|
dup empty?
|
2006-07-14 05:36:26 -04:00
|
|
|
[ drop 0 ] [ unclip swap [ x.dy ] 2keep dx.y l+ ] if ;
|
2006-07-09 21:57:19 -04:00
|
|
|
|
|
|
|
|
: d ( x -- dx )
|
2006-07-14 05:36:26 -04:00
|
|
|
>h [ concat (d) ] linear-op ;
|