/usr/share/axiom-20170501/src/algebra/FM1.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 | )abbrev domain FM1 FreeModule1
++ Author: Michel Petitot petitot@lifl.fr
++ Date Created: 91
++ Date Last Updated: 7 Juillet 92
++ Fix History: compilation v 2.1 le 13 dec 98
++ Description:
++ This domain implements linear combinations
++ of elements from the domain \spad{S} with coefficients
++ in the domain \spad{R} where \spad{S} is an ordered set
++ and \spad{R} is a ring (which may be non-commutative).
++ This domain is used by domains of non-commutative algebra such as:
++ XDistributedPolynomial, XRecursivePolynomial.
FreeModule1(R,S) : SIG == CODE where
R : Ring
S : OrderedSet
EX ==> OutputForm
TERM ==> Record(k:S,c:R)
SIG ==> FreeModuleCat(R,S) with
"*" : (S,R) -> %
++ \spad{s*r} returns the product \spad{r*s}
++ used by \spadtype{XRecursivePolynomial}
CODE ==> FreeModule(R,S) add
-- representation
Rep := List TERM
-- declarations
lt: List TERM
x : %
r : R
s : S
-- define
numberOfMonomials p ==
# (p::Rep)
listOfTerms(x) == x:List TERM
leadingTerm x == x.first
leadingMonomial x == x.first.k
coefficients x == [t.c for t in x]
monomials x == [ monom (t.k, t.c) for t in x]
retractIfCan x ==
numberOfMonomials(x) ^= 1 => "failed"
x.first.c = 1 => x.first.k
"failed"
coerce(s:S):% == [[s,1$R]]
retract x ==
(rr := retractIfCan x) case "failed" => error "FM1.retract impossible"
rr :: S
if R has noZeroDivisors then
r * x ==
r = 0 => 0
[[u.k,r * u.c]$TERM for u in x]
x * r ==
r = 0 => 0
[[u.k,u.c * r]$TERM for u in x]
else
r * x ==
r = 0 => 0
[[u.k,a] for u in x | not (a:=r*u.c)= 0$R]
x * r ==
r = 0 => 0
[[u.k,a] for u in x | not (a:=u.c*r)= 0$R]
r * s ==
r = 0 => 0
[[s,r]$TERM]
s * r ==
r = 0 => 0
[[s,r]$TERM]
monom(b,r):% == [[b,r]$TERM]
outTerm(r:R, s:S):EX ==
r=1 => s::EX
r::EX * s::EX
coerce(a:%):EX ==
empty? a => (0$R)::EX
reduce(_+, reverse_! [outTerm(t.c, t.k) for t in a])$List(EX)
coefficient(x,s) ==
null x => 0$R
x.first.k > s => coefficient(rest x,s)
x.first.k = s => x.first.c
0$R
|