/usr/share/axiom-20170501/src/algebra/BOP.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 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | )abbrev domain BOP BasicOperator
++ Author: Manuel Bronstein
++ Date Created: 22 March 1988
++ Date Last Updated: 11 October 1993
++ Description:
++ Basic system operators.
++ A basic operator is an object that can be applied to a list of
++ arguments from a set, the result being a kernel over that set.
BasicOperator() : SIG == CODE where
O ==> OutputForm
P ==> AssociationList(String, None)
L ==> List Record(key:String, entry:None)
SEX ==> InputForm
-- some internal properties
LESS? ==> "%less?"
EQUAL? ==> "%equal?"
WEIGHT ==> "%weight"
DISPLAY ==> "%display"
SEXPR ==> "%input"
SIG ==> OrderedSet with
name : $ -> Symbol
++ name(op) returns the name of op.
properties : $ -> P
++ properties(op) returns the list of all the properties
++ currently attached to op.
copy : $ -> $
++ copy(op) returns a copy of op.
operator : Symbol -> $
++ operator(f) makes f into an operator with arbitrary arity.
operator : (Symbol, NonNegativeInteger) -> $
++ operator(f, n) makes f into an n-ary operator.
arity : $ -> Union(NonNegativeInteger, "failed")
++ arity(op) returns n if op is n-ary, and
++ "failed" if op has arbitrary arity.
nullary? : $ -> Boolean
++ nullary?(op) tests if op is nullary.
unary? : $ -> Boolean
++ unary?(op) tests if op is unary.
nary? : $ -> Boolean
++ nary?(op) tests if op has arbitrary arity.
weight : $ -> NonNegativeInteger
++ weight(op) returns the weight attached to op.
weight : ($, NonNegativeInteger) -> $
++ weight(op, n) attaches the weight n to op.
equality : ($, ($, $) -> Boolean) -> $
++ equality(op, foo?) attaches foo? as the "%equal?" property
++ to op. If op1 and op2 have the same name, and one of them
++ has an "%equal?" property f, then \spad{f(op1, op2)} is called to
++ decide whether op1 and op2 should be considered equal.
comparison : ($, ($, $) -> Boolean) -> $
++ comparison(op, foo?) attaches foo? as the "%less?" property
++ to op. If op1 and op2 have the same name, and one of them
++ has a "%less?" property f, then \spad{f(op1, op2)} is called to
++ decide whether \spad{op1 < op2}.
display : $ -> Union(List O -> O, "failed")
++ display(op) returns the "%display" property of op if
++ it has one attached, and "failed" otherwise.
display : ($, List O -> O) -> $
++ display(op, foo) attaches foo as the "%display" property
++ of op. If op has a "%display" property f, then \spad{op(a1,...,an)}
++ gets converted to OutputForm as \spad{f(a1,...,an)}.
display : ($, O -> O) -> $
++ display(op, foo) attaches foo as the "%display" property
++ of op. If op has a "%display" property f, then \spad{op(a)}
++ gets converted to OutputForm as \spad{f(a)}.
++ Argument op must be unary.
input : ($, List SEX -> SEX) -> $
++ input(op, foo) attaches foo as the "%input" property
++ of op. If op has a "%input" property f, then \spad{op(a1,...,an)}
++ gets converted to InputForm as \spad{f(a1,...,an)}.
input : $ -> Union(List SEX -> SEX, "failed")
++ input(op) returns the "%input" property of op if
++ it has one attached, "failed" otherwise.
is? : ($, Symbol) -> Boolean
++ is?(op, s) tests if the name of op is s.
has? : ($, String) -> Boolean
++ has?(op, s) tests if property s is attached to op.
assert : ($, String) -> $
++ assert(op, s) attaches property s to op.
++ Argument op is modified "in place", no copy is made.
deleteProperty_! : ($, String) -> $
++ deleteProperty!(op, s) unattaches property s from op.
++ Argument op is modified "in place", no copy is made.
property : ($, String) -> Union(None, "failed")
++ property(op, s) returns the value of property s if
++ it is attached to op, and "failed" otherwise.
setProperty : ($, String, None) -> $
++ setProperty(op, s, v) attaches property s to op,
++ and sets its value to v.
++ Argument op is modified "in place", no copy is made.
setProperties : ($, P) -> $
++ setProperties(op, l) sets the property list of op to l.
++ Argument op is modified "in place", no copy is made.
CODE ==> add
-- if narg < 0 then the operator has variable arity.
Rep := Record(opname:Symbol, narg:SingleInteger, props:P)
oper: (Symbol, SingleInteger, P) -> $
is?(op, s) == name(op) = s
name op == op.opname
properties op == op.props
setProperties(op, l) == (op.props := l; op)
operator s == oper(s, -1::SingleInteger, table())
operator(s, n) == oper(s, n::Integer::SingleInteger, table())
property(op, name) == search(name, op.props)
assert(op, s) == setProperty(op, s, NIL$Lisp)
has?(op, name) == key?(name, op.props)
oper(se, n, prop) == [se, n, prop]
weight(op, n) == setProperty(op, WEIGHT, n pretend None)
nullary? op == zero?(op.narg)
unary? op == ((op.narg) = 1)
nary? op == negative?(op.narg)
equality(op, func) == setProperty(op, EQUAL?, func pretend None)
comparison(op, func) == setProperty(op, LESS?, func pretend None)
display(op:$, f:O -> O) == display(op,(x1:List(O)):O +-> f first x1)
deleteProperty_!(op, name) == (remove_!(name, properties op); op)
setProperty(op, name, valu) == (op.props.name := valu; op)
coerce(op:$):OutputForm == name(op)::OutputForm
input(op:$, f:List SEX -> SEX) == setProperty(op, SEXPR, f pretend None)
display(op:$, f:List O -> O) == setProperty(op, DISPLAY, f pretend None)
display op ==
(u := property(op, DISPLAY)) case "failed" => "failed"
(u::None) pretend (List O -> O)
input op ==
(u := property(op, SEXPR)) case "failed" => "failed"
(u::None) pretend (List SEX -> SEX)
arity op ==
negative?(n := op.narg) => "failed"
convert(n)@Integer :: NonNegativeInteger
copy op ==
oper(name op, op.narg,
table([[r.key, r.entry] for r in entries(properties op)@L]$L))
-- property EQUAL? contains a function f: (BOP, BOP) -> Boolean
-- such that f(o1, o2) is true iff o1 = o2
op1 = op2 ==
(EQ$Lisp)(op1, op2) => true
name(op1) ^= name(op2) => false
op1.narg ^= op2.narg => false
brace(keys properties op1)^=$Set(String) _
brace(keys properties op2) => false
(func := property(op1, EQUAL?)) case None =>
((func::None) pretend (($, $) -> Boolean)) (op1, op2)
true
-- property WEIGHT allows one to change the ordering around
-- by default, every operator has weigth 1
weight op ==
(w := property(op, WEIGHT)) case "failed" => 1
(w::None) pretend NonNegativeInteger
-- property LESS? contains a function f: (BOP, BOP) -> Boolean
-- such that f(o1, o2) is true iff o1 < o2
op1 < op2 ==
(w1 := weight op1) ^= (w2 := weight op2) => w1 < w2
op1.narg ^= op2.narg => op1.narg < op2.narg
name(op1) ^= name(op2) => name(op1) < name(op2)
n1 := #(k1 := brace(keys(properties op1))$Set(String))
n2 := #(k2 := brace(keys(properties op2))$Set(String))
n1 ^= n2 => n1 < n2
not zero?(n1 := #(d1 := difference(k1, k2))) =>
n1 ^= (n2 := #(d2 := difference(k2, k1))) => n1 < n2
inspect(d1) < inspect(d2)
(func := property(op1, LESS?)) case None =>
((func::None) pretend (($, $) -> Boolean)) (op1, op2)
(func := property(op1, EQUAL?)) case None =>
not(((func::None) pretend (($, $) -> Boolean)) (op1, op2))
false
|