This is mostly due to change r2093 "Remove unsound structure
from completions", so OrderedCompletion doesn't have many
signatures anymore, especially 0$INF.
I patched your file in attachment.
On 6/5/19 9:25 AM, Xiaojun wrote:
> Hi!
>
> I'm trying to compile an old spad file but get an error:
>
> )compile ORESUS.spad
>
> Compiling FriCAS source code from file
> /Users/lxj/Dropbox/SourceCode/MyProjects/ORESUS/test/ORESUS.spad
> using old system compiler.
> ORESUS abbreviates domain UnivariateSkewSeries
> ------------------------------------------------------------------------
> initializing NRLIB ORESUS for UnivariateSkewSeries
> compiling into NRLIB ORESUS
> compiling exported coerce : R -> $
> ****** comp fails at level 2 with expression: ******
> error in function coerce
>
> (|construct| | << | (|::| (|construct| |r|) (|Stream| R)) | >> | 0
> (|::| 0 (|OrderedCompletion| (|Integer|))))
> ****** level 2 ******
> $x:= (:: (construct r) (Stream R))
> $m:= R
> $f:=
> ((((|r| # #) (|copy| #) (|setelt!| #) (|lo| #) ...)))
>
> I'm pretty sure this file could be compiled before. It seems FriCAS has
> a lot of changes
> over time.
>
> So any suggestions on how to fix it?
>
> The spad file is attached.
>
> Thanks in advance!
>
> BR
> XJ
>
> --
> You received this message because you are subscribed to the Google
> Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/fricas-devel/a3104bc3-77ba-4223-ae47-f04c4ba39adc%40googlegroups.com
> <https://groups.google.com/d/msgid/fricas-devel/a3104bc3-77ba-4223-ae47-f04c4ba39adc%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/0bc96f67-7d9b-0f65-66a4-d4f9b76388c5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
-- Univariate Skew Series Domain
)abb domain ORESUS UnivariateSkewSeries
B ==> Boolean
I ==> Integer
NNI ==> NonNegativeInteger
INF ==> OrderedCompletion I
Sy ==> Symbol
LS ==> List Sy
PC ==> UnivariatePolynomial(Var,R)
BOP ==> BasicOperator
OUT ==> OutputForm
LC ==> List R
SC ==> Stream R
FI ==> Fraction(Integer)
SLen ==> _$streamCount$Lisp
SMin ==> minIndex([1$R]::SC)
UnivariateSkewSeries(R:Ring, Var:Symbol, sigma:Automorphism R,
invsigma:Automorphism R, delta: R -> R) : Exports == Implementation where
Exports == Join(Ring, BiModule(R, R)) with
coerce : (R) -> %
++ \axiom{coerce(r)} converts an element of
++ \axiom{Ring} into a skew series.
series: (SC,I) -> %
++ \axiom{series(sc,n)} generates a skew
++ series of order \axiom{n} from a stream
++ \axiom{sc} of coefficients.
series: (LC,I) -> %
++ \axiom{series(lc,n)} generates a skew
++ series of order \axiom{n} from a list
++ \axiom{lc} of coefficients.
series: (SC,I,INF) -> %
++ \axiom{series(cs, m, n)} generate skew
++ series by explicitly indicating the lowest
++ order.
pos: % -> %
++ \axiom{pos(s)} computes the non-negative
++ part of the skew series \axiom{s}
neg : % -> %
++ \axiom{neg(s)} computes the negative part
++ of the skew series \axiom{s}.
order: (%) -> I
++ \axiom{order(s)} returns the highest
++ exponent index occuring in \axiom{s}.
lowestOrder: (%) -> INF
++ \axiom{lowestOrder(s)} returns the lowest
++ exponent index occuring in \axiom{s}.
coefficient: (%, I) -> R
++ \axiom{coefficient(s,i)} returns the
++ coefficient of a specific exponent
++ \axiom{DOp^i}.
coefficients: (%) -> SC
++ \axiom{coefficients(s)} returns the stream
++ of the coefficients of a skew series \axiom{s}.
leadingCoefficient: (%) -> R
++ \axiom{leadingCoefficient(s)} returns the
++ highest order exponent's coefficient of a
++ skew series \axiom{s}
0: constant -> %
++ \axiom{0} creates a zero skew series.
1: constant -> %
++ \axiom{1} creates a identity skew series.
"=": (%, %) -> Boolean
++ \axiom{s1=s2} tests if two skew series are
++ equal.
"+": (%, %) -> %
++ \axiom{s1+s2} computes the sum of two skew
++ series. The sum is based on the exponents.
"-": (%) -> %
++ \axiom{-s1} returns a skew series, which is
++ the additive inverse of \axiom{s1}.
"+": (R, %) -> %
++ \axiom{r+s} computes the sum of an element
++ in R and an element of skew series, which is
++ done by convert r to a skew series of 0-order.
"+": (%, R) -> %
++ \axiom{s+r} is similar to the previous one.
"*": (%, %) -> %
++ \axiom{s1*s2} computes the product of two
++ skew series, yields a new skew series.
"*": (R, %) -> %
++ \axiom{r*s}
"*": (%, R) -> %
++ \axiom{s*r}
commutator: (%,%) -> %
++ \axiom{commutator} computes the commutator of
++ two skew series, namely A*B-B*A.
apply: (R->R, %) -> %
++ \axiom{applyToCoefficients} applies a map: R->R
++ to all the coefficients of a series x. This could
++ be very useful, for example, when you want to
++ differentiate the coefficients.
inv: (%) -> Union(%, "failed")
++ \axiom{inv(s)} computes the productive
++ inverse of a skew series. In order to
++ do that, the leading coefficient of this
++ skew series must be inversible. For
++ simplicity, we only consider the case
++ when coefficient domain is an integral
++ domain. In this case, if leading coefficient
++ is an inversible element, then the \axiom{inv(s)}
++ can be calculated. Otherwise, \axiom{inv(s)}
++ returns "failed".
"^":(%,I) -> Union(%, "failed")
++ \axiom{s^n} computes the \axiom{n}-th
++ exponents of \axiom{s}. When \axiom{n<0},
++ the \axiom{inv(s)} is first calculated.
if R has IntegralDomain then
--fracStream: (%, R, I, NNI, %) -> SC
++ will be local
--fractionOf: (%, R) -> Union(%, "failed")
++ will be local
fractionalPower: (%, FI, R) -> Union(%, "failed")
++ \axiom{rationalPower(s, p, r)} computes s
++ to the fractional power p. In order to
++ do that, the denominator of p must be a
++ divisor of the leading order of x, otherwise
++ it doesn't make sense (return "failed"). Moreover,
++ since there is no common square root operation for
++ an integral domain, so in order to make the rational
++ power work, the m-th root of the leading coefficient
++ of s should be provided, where m is the order of s.
Implementation == add
Rep := Record(coef:SC, hi: I, lo: INF)
coerce(r:R):% == [[r]::SC, 0, 0::I::INF]
series(s:SC, deg:I):% ==
explicitlyFinite? s => [s, deg, (deg-#entries(s)+1)::INF]
[s, deg, minusInfinity()]
series(s:SC, deg:I, low:INF):% ==
[s, deg, low]
series(l:LC, deg:I):% ==
series(l::SC, deg, (deg-#l+1)::INF)
neg(x:%):% ==
n := x.hi
n<0$I => x
finite?(m:=x.lo) and retract(m)>=0$I => 0$%
cs := x.coef
for i in 0..n repeat
cs := rest cs
[cs,-1,x.lo]
pos(x:%):% ==
x.hi < 0 => 0$%
x.lo >= 0::I::INF => x
n: I := x.hi + SMin
cs: LC := [x.coef.i for i in SMin..n]
[cs::SC, x.hi, 0::I::INF]
order(s:%) : I == s.hi
lowestOrder(s:%) : INF == s.lo
coefficients(s:%): SC == s.coef
coefficient(s:%, i:I): R ==
i>(n:= order s) => 0
k := n-i
xc := extend(s.coef, k+SMin)
explicitlyFinite?(xc) and (k>= #entries xc) => 0
s.coef.(k+SMin)
leadingCoefficient(s:%): R ==
cs: SC := s.coef
empty? cs => 0$ R
cs.1
-- ----------- --
-- Output Form --
-- ----------- --
monom(r:R, n: I):OUT ==
-- Output of a monom
-- Called by polynom
n=0 => r::OUT
res := Var::OUT
if not(n=1) then
res := res^n::OUT
if not one? r then
res := r::OUT * res
res
polynom(ls:LC, n: I):OUT ==
-- Output of a polynomial
-- Called by coerce
lt := ls
erg:List OUT := empty()
i:NNI
for i in 0.. while not empty?(lt) repeat
c := first(lt)
if not zero? c then
erg := cons(monom(c,n-i),erg)
lt := rest lt
empty? erg => 0$I :: OUT
#erg =1 => first erg
reduce("+",reverse! erg)
coerce(s:%): OUT ==
-- Output a skew series
-- for possibly infinite Skew series, the order of possible further
-- terms is indicated
empty?(cs:=s.coef) => 0$R::OUT
cs := extend(cs, SLen)
explicitlyFinite? cs => polynom(entries cs, s.hi)
i:NNI
polynom([cs.i for i in SMin..SLen],s.hi)+ prefix(outputForm("O"),
[Var::OUT^(s.hi-SLen-SMin+1)::OUT])
-- ----------------- --
-- Local Functions --
-- ----------------- --
move(x:SC,n:NNI):SC ==
-- Adds n leading zeros.
-- Called by "+".
insert([0$R for i in 1..n]::SC,x,1)
cutHead(x:%):% ==
-- Erases leading zeros in coefficient stream.
-- Called by "+" and differentiate.
cs := x.coef
count := 0$NNI
while not empty?(cs) and zero? frst(cs) and (count<=SLen) and
((x.hi-count)::INF > x.lo) repeat -- add one condition
cs := rst cs
count := count+1
empty? cs => 0
[cs,x.hi-count,x.lo]
cutTail(x:%):% ==
-- Erases trailing zeros in coefficient stream of finite PDOs.
-- Called by "+".
infinite?(x.lo) => x
n := (x.hi-retract(x.lo)+SMin)::NNI
cs:LC := [x.coef.i for i in SMin..n]
while last(cs)=0 and (n > 1) repeat -- add one condition
n := (n-1)::NNI
cs := first(cs,n)
[cs::SC,x.hi,(x.hi-n+1)::INF]
repeatedAct(aMap: R -> R, n: NNI, r: R): R ==
n = 0 => r
res: R := r
for i in 1..n repeat
res := aMap(res)
res
termForInvX(s:%, k:NNI):R ==
--k = 1 => sc.1
action : R -> R := r +-> - invsigma(delta(r))
res: R := 0 $ R
for i in 1..k repeat
r :R := coefficient(s, s.hi +1 -i)
res := res + repeatedAct(action, (k-i)::NNI, invsigma(r))
res
-- ------------------------- --
-- Simple Algebra Operations --
-- ------------------------- --
0 : % == [[0$R]::SC,0,0::I::INF]
1 : % == [[1$R]::SC,0,0::I::INF]
x:% = y:% == (x.hi=y.hi) and (x.lo=y.lo) and (x.coef=y.coef)
x:% + y:% ==
n := x.hi - y.hi
h := max(x.hi,y.hi)
l := min(x.lo,y.lo)
coefStreamX : SC := x.coef
coefStreamY : SC := y.coef
sumCoef: (R,R) -> R := (r1,r2) +-> r1+r2
-- align heads
if x.hi > y.hi then
coefStreamY := move(coefStreamY, n::NNI)
if x.hi < y.hi then
coefStreamX := move(coefStreamX, (-n)::NNI)
-- complete tail in order to add
if x.lo < y.lo then
coefStreamY := concat(coefStreamY, repeating[0])
if x.lo > y.lo then
coefStreamX := concat(coefStreamX, repeating[0])
res : SC := map(sumCoef, coefStreamX, coefStreamY)
infinite? l => cutHead [res,h,l]
cutTail cutHead [extend(res,h-retract(l)+1),h,l]
r:R + x:% == series([r],0) + x
x:% + r:R == x + series([r],0)
-x:% ==
minusCoef: R -> R := r1 +-> -r1
[map(minusCoef,x.coef),x.hi,x.lo]
-- --------------------- --
-- Multiplication --
-- --------------------- --
leftMultiplyByCoef(r: R, s:%):% ==
-- added by LXJ.
s = 0 $ % => 0$%
multByCoefMap: R -> R := r1 +-> r*r1
coefStream: SC := s.coef
series(map(multByCoefMap, coefStream), s.hi, s.lo)
leftMultiplyByX(s:%):% ==
-- Modified by LXJ. Remove complete function, using NEW series
aSigmaMap: R -> R := r +-> sigma(r)
if infinite? s.lo then
t1:% := series( map(delta,s.coef), s.hi, s.lo)
t2:% := series( map(aSigmaMap,s.coef), s.hi+1, s.lo)
else
t1:% := series( map(delta,s.coef), s.hi, s.lo)
t2:% := series( map(aSigmaMap,s.coef), s.hi+1,
(retract(s.lo)+1)::INF)
t1 + t2
multiplyInvXStream(x:%, k:NNI): SC ==
currentTerm : R := 0 $ R
act : R -> R := r +-> - invsigma(delta(r))
sc : SC := x.coef
if finite? x.lo then
sc := concat(sc, repeating[0])::SC
for i in 1..k repeat
r :R := sc.i
currentTerm := currentTerm + repeatedAct(act, (k-i)::NNI,
invsigma(r))
delay
concat(currentTerm, multiplyInvXStream(x, k+1))
leftMultiplyByInvX(s:%):% ==
s = 0 $ % => 0 $ %
-- if s is zero, return immediately (check the rule for delta and
sigma)
res: SC := multiplyInvXStream(s, 1)
-- the following is not always infinitly many terms. Just for
-- simplicity.
series(res, s.hi-1, minusInfinity())
leftMultiplyByNonNegativePart(x:%, y: %) : % ==
x.hi <0 => 0 $ %
result : % := 0 $ %
lowOrder : I := retract(max(0::I::INF, x.lo))
lowOrder > x.hi => 0 $ %
-- lowestOrder cannot beyond x.hi. So if it happens, returns 0
previousResult :% := y
if (lowOrder>0) then
for i in 1..lowOrder repeat
previousResult := leftMultiplyByX(previousResult)
for i in lowOrder..x.hi repeat
theCoef := coefficient(x, i)
result := result + leftMultiplyByCoef(theCoef, previousResult)
previousResult := leftMultiplyByX(previousResult)
result
multiplyNegativePartStream(x:%, y:%, k:PositiveInteger, preProcess:%) :
SC ==
-- assume x.lo < 0
currentTerm : R := 0$ R
firstOrder:I := min(-1, x.hi)
numTerms: INF := (firstOrder::INF) + (- x.lo) + 1::I::INF
finiteTermResult :% := 0$%
previousResult:% := preProcess
for i in 1..retract(min(k::INF, numTerms)) repeat
theCoef := coefficient(x, firstOrder -i + 1)
finiteTermResult := finiteTermResult +
leftMultiplyByCoef(theCoef, previousResult)
previousResult := leftMultiplyByInvX(previousResult)
currentTerm := coefficient(finiteTermResult, firstOrder + y.hi-k +
1)
delay
concat(currentTerm, multiplyNegativePartStream(x,y, k+1,
preProcess))
leftMultiplyByNegativePart(x:%, y:%) : % ==
x.lo >= 0::I::INF => 0 $ %
firstOrder := min(x.hi, -1)
preMultiplyResult := y
for i in 1..(-firstOrder) repeat
preMultiplyResult := leftMultiplyByInvX(preMultiplyResult)
[multiplyNegativePartStream(x,y, 1::PositiveInteger,
preMultiplyResult), y.hi+firstOrder, minusInfinity()]
x:% * y:% ==
leftMultiplyByNonNegativePart(x,y) + leftMultiplyByNegativePart(x,y)
r:R * x:% == series([r],0) * x
x:% * r:R == x * series([r],0)
commutator(x:%, y:%) : % == x * y - y * x
apply(f:R->R, x:%):% == [map(f,x.coef), x.hi, x.lo]
-- --------------------- --
-- Inverse of an ORESUS --
-- --------------------- --
if R has IntegralDomain then
invStream(x:%, leadingCoef:R, leadingOrder:I, usedTerms:%, n:NNI,
knownInv:%): SC ==
-- 计算一个算子逆的系数流, n 表示逆算子的第n个系数, n>1
-- 首先截取x的前n-1项,做成一个ORESUS,与已算出的
-- (knownInv)ORESUS相乘,提取第n项系数
-- 其中 x 是要取逆的算子, leadingCoef 是 x 的首项系数
-- m 是 x 的最高阶次数,n 是要算的第n阶,usedTerms是x的前n-1阶,knownInv
-- 逆算子已经算出的部分
an := coefficient(x, leadingOrder-n+1)
thisTerm :% := series([an],leadingOrder-n+1)
tmp := (usedTerms + thisTerm) * knownInv
a :R := coefficient(tmp, -n+1)
b := - (a exquo leadingCoef) :: R
if leadingOrder >= 0 then
action: R-> R := r +-> invsigma(r)
b := repeatedAct(action, leadingOrder::NNI, b)
else
action: R-> R := r +-> sigma(r)
b := repeatedAct(action, (-leadingOrder)::NNI, b)
thisInvTerm :% := series([b], -leadingOrder - n +1)
delay
concat(b, invStream(x, leadingCoef, leadingOrder,
usedTerms+thisTerm, n+1, knownInv + thisInvTerm))
inv(x:%): Union(%, "failed") ==
-- 计算一个算子的逆, 首先这个算子的首项必须是可逆的,然后
-- 我们用递归的办法逐渐算出它的逆
leadingCoef : R := leadingCoefficient(x)
not unit?(leadingCoef) => "failed"
m: I := order(x)
usedTerm:% := series([leadingCoef],m) $ %
b: R := (1 exquo leadingCoef)::R
if m>=0 then
action: R-> R := r +-> invsigma(r)
b := repeatedAct(action, m::NNI, b)
else
action: R-> R := r +-> sigma(r)
b := repeatedAct(action, (-m)::NNI, b)
knownInv : % := series([b], -m) $ %
cs:SC := invStream(x, leadingCoef, m, usedTerm, 2, knownInv)
cs := concat(b, cs)
[cs, -m, minusInfinity()]
x:% ^ n:I ==
n = 0 => 1 $ %
--n > 0 => x * x^(n-1)
res :% := 1 $ %
if n > 0 then
for i in 1..n repeat
res := x * res
if n < 0 then
(xInv := inv(x)) case "failed" => return "failed"
for i in 1..((-n)::NNI) repeat
res := (xInv::%) * res
res
--- -------------------------------------------- ---
--- Fractional Power of an ORESUS (exprimental)
--- Might work only for automorphism \sigma equals
--- to identity, and the ring R is an IntegralDomain,
--- And the n-th square root of the leadingCoefficient
--- a_0 is still in the ring (namely the equation x^n = a_0
--- is solvable in the ring.
--- Added by XJ (2014-7-23)
--- -------------------------------------------- ---
--if R has IntegralDomain then
fracStream(x:%, leadingFactor: R, leadingOrder: I, n: NNI,
knownFrac: %): SC ==
-- 计算一个算子 x 的若干次方根的系数流。n 表示这个系数流的第 n 个系数, n>1
-- 假设 x 的 leadingOrder = m (|m|>1)。首先将已知的 knownFrac 求 |m| 次方,
-- 然后求 (knownFrac)^|m| 的第 n 项的系数,这个系数与 x 的第 n 个系数比较,
-- 其差值除以 leadingCoef^|m-1| 次方后就是 m 次方根的第 n 项系数,然后递归
-- 即若 x = a_0 D^m + a_1 D^{m-1} + a_2 D^{m-2} + ......,则
-- a_0 = b_0^m; a_n = b_n * b_0^{m-1} + ((b_0 D + b_1 D^0 +
...+b_{n-1} D^{1-n})^m ) 的第 n 项系数
-- leadingFactor = b_0^{m-1}
m : NNI := abs(leadingOrder) :: NNI
j : I := if (leadingOrder >=0) then 1 else -1
--if leadingOrder >=0 then
-- m := leadingOrder :: NNI
-- j := 1
--else
-- m := (-leadingOrder) :: NNI
-- j := -1
tmpCoef: R := coefficient(x-knownFrac^m, leadingOrder-n)
-- because exquo returns Union(R, failed), so we should handle
the different output
b := (tmpCoef exquo (leadingFactor * (m::R)))
b case "failed" =>
error "Divided by a non-invertible element!"
-- otherwise, coerce b to element in R and continue
thisTerm : % := series([b::R], j-n)
delay
concat(b::R,fracStream(x, leadingFactor, leadingOrder, n+1,
knownFrac + thisTerm))
-- don't know why to put b in front of the stream
fractionOf(x:%, sqrtLeadCoefOfx: R): Union(%, "failed") ==
-- 计算一个算子 x 的 1/m 次方,其中 m = |leadingOrder(x)|,
-- 我们目前需要假设 x 的领头项是可以开 m 次方的,并且可逆, \sigma = identity
leadingCoef : R := leadingCoefficient(x)
not unit?(leadingCoef) => "failed"
not unit?(sqrtLeadCoefOfx) => "failed"
m: NNI := abs(order(x)) :: NNI
sqrtLeadCoefOfx^m ~= leadingCoef => "failed" -- not equal
m = 0 => [[sqrtLeadCoefOfx]::SC, 0,0::I::INF] -- need to check
m = 1 => x --need to check
leadingFactor:= (leadingCoef exquo sqrtLeadCoefOfx)
leadingFactor case "failed" => "failed"
j: I := if (order(x) > 0) then 1 else -1
--if order(x) > 0 then
-- j := 1
--else
-- j := -1
knownFrac : % := series([sqrtLeadCoefOfx],j) $ %
cs: SC := fracStream(x, leadingFactor::R , order(x), 1,
knownFrac)
cs := concat(sqrtLeadCoefOfx, cs)
[cs, j, minusInfinity()]
--x
fractionalPower(x: %, p: FI, r: R): Union(%, "failed") ==
-- 计算一个算子 x 的分数 p 次方, r 是 x 的首项系数的 1/m 次方,其中 m 是 x 的次数
-- 我们要检查 r 是 R 中的可逆元,并且目前我们要假设 \sigma(r) = r,否则会返回错误
leadingCoef: R := leadingCoefficient(x)
not unit?(leadingCoef) => "failed"
m: NNI := abs(order(x)) :: NNI
retractIfCan(p*m) case "failed" => "failed"
order(x)=0 => error "It's user's intelligence to find this
fractional power...I gave up"
if order(x)>0 then
r^m ~= leadingCoef => "failed"
else
(r^m) * leadingCoef ~= (1 :: R) => "failed"
tmp := fractionOf(x, r)
tmp case "failed" => "failed"
pwr: I := retract(p*m)
((tmp::%)^pwr)
--tmp