Re: [fricas-devel] Re: Programming with BTREEs.
Martin Rubey <[email protected]> 07 Apr 2009 14:54:34 +0200
| Newsgroups | gmane.comp.mathematics.axiom.user |
|---|---|
| Message-ID | <[email protected]> |
Martin Rubey <[email protected]> writes: > Dear Ralf, > > I'm extremely grateful that you answered... > > Ralf Hemmecke <[email protected]> writes: > N := Union(Symbol, List Integer) > BT := BinaryTree N > B ==> binaryTree -- the 3-argument version > V ==> binaryTree -- the 1-argument version > bt:BT:=B(V e,[5,1],B(B(V a,[1,1],V b),[1,1],B(V c,[1,2],V d))) > > [...] > > S==>Symbol > L==>List Integer > construct(x: S, l: L, y: S): BT == binaryTree(V(x::N), l::N, V(y::N)) > bt2: BT := [e,[5,1],[[a,[1,1],b],[1,1],[c,[1,2],d]]] > > ['a, [1,3], 'b]@BT > > works for me > > but > > [e,[5,1],[[a,[1,1],b],[1,1],[c,[1,2],d]]]@BT > > cannot work, I think, because the argument types don't match. You > will need to allow also binary trees. construct(x: Union(S, BT), l: L, y: Union(S, BT)): BT == binaryTree((if x case S then V(x::N) else x::BT), l::N, (if y case S then V(y::N) else y::BT)) will work *almost*: (20) -> ['a, [1,3], ['d, [1,3], 'c]@BT]@BT (20) [a,[1,3],[d,[1,3],c]] Type: BinaryTree(Union(Symbol,List(Integer))) (21) -> ['a, [1,3], ['d, [1,3], 'c]]@BT Conversion failed in the compiled user function construct . Cannot convert from type List(Any) to Union(Symbol,BinaryTree(Union( Symbol,List(Integer)))) for value [d,[1,3],c] Not sure whether this is an improvement. Martin