/usr/share/axiom-20170501/src/algebra/BTCAT.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | )abbrev category BTCAT BinaryTreeCategory
++ Author:W. H. Burge
++ Date Created:17 Feb 1992
++ Description:
++ \spadtype{BinaryTreeCategory(S)} is the category of
++ binary trees: a tree which is either empty or else is a
++ \spadfun{node} consisting of a value and a \spadfun{left} and
++ \spadfun{right}, both binary trees.
BinaryTreeCategory(S) : Category == SIG where
S : SetCategory
SIG ==> BinaryRecursiveAggregate(S) with
shallowlyMutable
++ Binary trees have updateable components
finiteAggregate
++ Binary trees have a finite number of components
node : (%,S,%) -> %
++ node(left,v,right) creates a binary tree with value \spad{v}, a
++ binary tree \spad{left}, and a binary tree \spad{right}.
add
cycleTreeMax ==> 5
copy t ==
empty? t => empty()
node(copy left t, value t, copy right t)
if % has shallowlyMutable then
map_!(f,t) ==
empty? t => t
t.value := f(t.value)
map_!(f,left t)
map_!(f,right t)
t
treeCount : (%, NonNegativeInteger) -> NonNegativeInteger
#t == treeCount(t,0)
treeCount(t,k) ==
empty? t => k
k := k + 1
k = cycleTreeMax and cyclic? t => error "cyclic binary tree"
k := treeCount(left t,k)
treeCount(right t,k)
|