1
/* Routines for computing: */
2
/* a) application of a lin. op. on a hyp. seq. */
3
/* b) shift quotient of a hyp. seq. */
5
/* RISC Institute, Linz, Austria */
6
/* by Fabrizio Caruso */
20
for count:1 unless (res=true)or(count>length(expr)) do
22
res : dependent(part(expr,count),var)
32
if atom(pol) or not(operatorp(pol,"*")) then
35
return(cons(first(pol),poly2list(pol/first(pol))))
38
extractConstant(polyList,var) :=
39
block([resConst, resDep,i],
42
for i : 1 thru length(polyList) do
43
if (atom(polyList[i]) and polyList[i]=var) or
44
(not(atom(polyList[i])) and dependent(polyList[i],var)) then
45
resDep : resDep * polyList[i]
47
resConst : resConst * polyList[i],
48
return([resDep,resConst])
52
/* It computes the rat. factor out of the appl. of a lin. op. to a hyp. seq. */
53
niceForm(hyp,var,parName,ord,sumVar) :=
55
[shQuo,numConst,denConst,num,den,res,i],
58
shQuo : shiftQuoHypCheck(hyp,var),
59
if second(shQuo) = NO_HYP then
61
else shQuo : first(shQuo),
63
numConst : extractConstant(poly2list(factor(num(shQuo))),sumVar),
64
denConst : extractConstant(poly2list(factor(denom(shQuo))),sumVar),
70
for i : ord step -1 thru 1 do
71
res : xthru(parName[i-1] + factor(shiftFactPoly(shQuo,var,i-1))*res),
73
return([res,numConst[2],denConst[2]])
77
/* It computes the rat. factor out of the appl. of a lin. op. to a hyp. seq. */
78
niceFormDB(hyp,var,parName,ord) :=
80
[shQuo,num,den,res,i],
83
shQuo : shiftQuo(hyp,var),
84
print("Shift quotient computed!"),
85
print("Order : ", ord),
86
for i : ord step -1 thru 1 do
88
res : xthru(parName[i-1] + shiftFactPoly(shQuo,n,i-1)*res),
96
removeBinomial(expr) :=
100
if op(expr) = binomial then
101
first(expr)!/second(expr)!/(first(expr)-second(expr))!
103
apply(op(expr),makelist(removeBinomial(part(expr,i)),i,1,length(expr)));
106
removeBinomial(expr) :=
112
if op(expr) = binomial then
113
return(first(expr)!/second(expr)!/(first(expr)-second(expr))!)
115
if op(expr) = "-" then
116
return(-removeBinomial(first(expr)))
119
return(apply(op(expr),makelist(removeBinomial(part(expr,i)),i,1,length(expr))))
123
shiftFactPoly(expr,k,j) :=
127
if op(expr) = "/" then
128
shiftFactPoly(first(expr),k,j)*shiftFactPoly(second(expr),k,j)^(-1)
130
if op(expr) = "*" then
131
product(shiftFactPoly(part(expr,i),k,j),i,1,length(expr))
133
if op(expr) = "^" then
134
if integerp(second(expr)) then
135
shiftFactPoly(first(expr),k,j)^second(expr)
139
expand(subst(k+j,k,expr));
144
sq_res : shiftQuoHypCheck(expr,k),
145
if second(sq_res) = HYP then
146
return(first(sq_res))
148
return(subst(k+1,k,first(sq_res))/first(sq_res))
152
shiftQuoOnlyHyp(expr,k) :=
154
sq_res : shiftQuoHypCheck(expr,k),
155
if second(sq_res) = HYP then
156
return(first(sq_res))
162
isPolynomial(expr,k) :=
163
if freeof(k,expr) or expr=k or expr=-k then
166
if op(expr) = "^" then
167
freeof(k,second(expr)) and isPolynomial(first(expr),k)
169
if op(expr) = "-" then
170
isPolynomial(first(expr),k)
172
if op(expr) = "*" or op(expr)= "+" or op(expr) = "-" then
173
apply("and", makelist(isPolynomial(part(expr,i),k),i,1,length(expr)))
180
if not(isPolynomial(expr,k)) and
181
not(op(expr) = "//" and
182
isPolynomial(expand(num(expr)),k) and
183
isPolynomial(expand(denom(expr)), k)) then
185
if op(expr) = "-" then
186
rationalp(first(expr),k)
193
shiftQuoHypCheck(expr,k) :=
194
block([xthru_expr,sq_res],
195
xthru_expr : xthru(removeBinomial(expr)),
196
sq_res : shiftQuoHypCheckAux(xthru_expr,k,HYP),
198
if ?ratp(sq_res[1],k) then
201
return([sq_res[1],NO_HYP])
206
shiftQuoHypCheckAux(expr,k,hyp_flag) :=
207
block([sq_num,sq_den,sq_base,sq_exp],
208
if hyp_flag = NO_HYP then
209
return([expr,NO_HYP])
211
if freeof(k,expr) then
215
return([(k+1)/k,HYP])
217
if op(expr) = "*" then
218
return(product(shiftQuoHypCheckAux(part(expr,i),k,hyp_flag),
221
if op(expr) = "//" then
223
sq_num : shiftQuoHypCheckAux(first(expr),k,hyp_flag),
224
sq_den : shiftQuoHypCheckAux(second(expr),k,hyp_flag),
225
return([first(sq_num)/first(sq_den),second(sq_num)*second(sq_den)])
228
if op(expr) = "^" then
231
if freeof(k,first(expr)) then
232
sq_base : [first(expr),hyp_flag]
234
sq_base : shiftQuoHypCheckAux(first(expr),k,hyp_flag),
235
sq_exp : leadCoeff(second(expr),k),
236
if integerp(sq_exp) then
237
return([first(sq_base)^sq_exp,second(sq_base)])
239
return([first(sq_base)^sq_exp,NO_HYP])
243
if op(expr) = "!" then
244
if not(integerp(leadCoeff(first(expr),k))) then
245
return([expr,NO_HYP])
247
if leadCoeff(first(expr),k)>0 then
249
[product(factor(first(expr)+i),i,1,leadCoeff(first(expr),k)),
253
1/product(factor(first(expr)-i+1),
254
i,1,-leadCoeff(first(expr),k)),hyp_flag]
257
if op(expr) = binomial then
259
sq_num : shiftQuoHypCheckAux(factorial(first(expr)),k,hyp_flag),
260
sq_den : shiftQuoHypCheckAux(factorial(first(expr)-second(expr)),
262
shiftQuoHypCheckAux(factorial(second(expr)),
264
if second(sq_num) = HYP and second(sq_den)=HYP then
265
return([first(sq_num)/first(sq_den),HYP])
267
return([expr,NO_HYP])
272
if op(expr) = "+" then
273
return([shiftFactPoly(expr,k,1)/expr,hyp_flag])
276
print("Unknown operator : ", op(expr)),
277
return([expr,NO_HYP])