aboutsummaryrefslogtreecommitdiff
path: root/src/input/tree.input.pamphlet
blob: 45a67188118401b3da41de964b5d1a23852e4d8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/input tree.input}
\author{The Axiom Team}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{License}
<<license>>=
--Copyright The Numerical Algorithms Group Limited 1994.
@
<<*>>=
<<license>>
)cl all
)load TREE BTREE
bt := BinaryTree INT
ebtree:=empty()$(BTREE INT)
insleaf:(INT,bt)->bt
insleaf(x,t)==
     empty? t=> binaryTree(x)$(BTREE INT)
     x> value t => binaryTree(left t,value t,insleaf(x,right t))
     binaryTree(insleaf(x,left t),value t,right t)
b:bt:=reduce(insleaf,[8,3,5,4,6,2,1,5,7],ebtree)
bleaf x == reduce(insleaf,x,ebtree)
fln:bt-> List INT
fln t==
    empty? t => empty()$(List INT)
    concat(fln left t,concat(value t,fln right t))
fln b
split:(INT,bt)->List bt
split(x,t)==
     empty? t=> [ebtree,ebtree]
     x> value t =>
            a:=split(x,right t)
            [binaryTree(left t,value t,a.1),a.2]
     a:=split(x,left t)
     [a.1,binaryTree(a.2,value t,right t)]
split(3,b)
insroot:(INT,bt)->bt
insroot(x,t)==
      a:=split(x,t)
      binaryTree(a.1,x,a.2)
broot x == reduce(insroot,x,ebtree)
a:List INT:=[8,3,9,4,6,2,1,5,7]
l1:=bleaf a
r1:=broot reverse a
(l1=r1)::Boolean
broot a
bleaf reverse a
mg:(bt,bt)->bt
mg(x,y)==
    empty? x => y
    empty? y => x
    value x > value y => binaryTree(mg(y,left x),value x,right x)
    binaryTree(left y,value y,mg(x,right y))
mg1:(INT,bt)->bt
mg1(x,t)==mg(binaryTree x,t)
btourn:List INT-> bt
btourn x == reduce(mg1,x,ebtree)
btourn a
cmp:(List INT,List INT)-> Boolean
cmp(x,y)== x.2<y.2
sort2 : List List INT -> List List INT
sort2 x== sort(cmp,x)
invert x==[i.1 for i in  sort2  [[k,l]
          for k in 1..#x for  l in x]]
broot a
btourn invert a
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}