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(zb_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 zb_op(expr) = binomial then
101 first(expr)!/second(expr)!/(first(expr)-second(expr))!
103 apply(zb_op(expr),makelist(removeBinomial(part(expr,i)),i,1,length(expr)));
106 removeBinomial(expr) :=
109 if mapatom(expr) then
112 if zb_op(expr) = binomial then
113 return(first(expr)!/second(expr)!/(first(expr)-second(expr))!)
115 if zb_op(expr) = "-" then
116 return(-removeBinomial(first(expr)))
119 map(removeBinomial, expr)
122 shiftFactPoly(expr,k,j) :=
126 if zb_op(expr) = "/" then
127 shiftFactPoly(first(expr),k,j)*shiftFactPoly(second(expr),k,j)^(-1)
129 if zb_op(expr) = "*" then
130 product(shiftFactPoly(part(expr,i__),k,j),i__,1,length(expr))
132 if zb_op(expr) = "^" then
133 if integerp(second(expr)) then
134 shiftFactPoly(first(expr),k,j)^second(expr)
138 expand(subst(k+j,k,expr));
143 sq_res : shiftQuoHypCheck(expr,k),
144 if second(sq_res) = HYP then
145 return(first(sq_res))
147 return(subst(k+1,k,first(sq_res))/first(sq_res))
151 shiftQuoOnlyHyp(expr,k) :=
153 sq_res : shiftQuoHypCheck(expr,k),
154 if second(sq_res) = HYP then
155 return(first(sq_res))
161 isPolynomial(expr,k) :=
162 if freeof(k,expr) or expr=k or expr=-k or constantp(expr) then
165 if zb_op(expr) = "^" then
166 ( freeof(k,second(expr)) and isPolynomial(first(expr),k) )
168 if zb_op(expr) = "-" then
169 isPolynomial(first(expr),k)
171 if zb_op(expr) = "*" or zb_op(expr)= "+" or zb_op(expr) = "-" then
172 apply("and", makelist(isPolynomial(part(expr,i),k),i,1,length(expr)))
179 if not(isPolynomial(expr,k)) and
180 not(zb_op(expr) = "/" and
181 isPolynomial(expand(num(expr)),k) and
182 isPolynomial(expand(denom(expr)), k)) then
184 if zb_op(expr) = "-" then
185 rationalp(first(expr),k)
192 shiftQuoHypCheck(expr,k) :=
193 block([xthru_expr,sq_res],
194 xthru_expr : xthru(removeBinomial(expr)),
195 sq_res : shiftQuoHypCheckAux(xthru_expr,k,HYP),
197 if rationalp(sq_res[1],k) then
200 return([sq_res[1],NO_HYP])
205 shiftQuoHypCheckAux(expr,k,hyp_flag) :=
206 block([sq_num,sq_den,sq_base,sq_exp],
207 if hyp_flag = NO_HYP then
208 return([expr,NO_HYP])
210 if freeof(k,expr) then
214 return([(k+1)/k,HYP])
216 if zb_op(expr) = "*" then
217 return(product(shiftQuoHypCheckAux(part(expr,i__),k,hyp_flag),
220 if zb_op(expr) = "/" then
222 sq_num : shiftQuoHypCheckAux(first(expr),k,hyp_flag),
223 sq_den : shiftQuoHypCheckAux(second(expr),k,hyp_flag),
224 return([first(sq_num)/first(sq_den),second(sq_num)*second(sq_den)])
227 if zb_op(expr) = "^" then
229 if (freeof(k, second(expr))) then
231 sq_base : shiftQuoHypCheckAux(first(expr), k, hyp_flag),
232 if sq_base[2]=NO_HYP then return([expr, NO_HYP])
233 else return([sq_base[1]^second(expr), hyp_flag])
235 else if (freeof(k, first(expr))) then
237 sq_exp: bothcoef(expand(second(expr)), k),
238 if not(freeof(k, second(sq_exp))) then return([expr, NO_HYP])
239 else return([first(expr)^first(sq_exp), hyp_flag])
241 else return([expr, NO_HYP])
244 if zb_op(expr) = "!" then
245 if not(integerp(leadCoeff(first(expr),k))) then
246 return([expr,NO_HYP])
248 if leadCoeff(first(expr),k)>0 then
250 [product(factor(first(expr)+i__),i__,1,leadCoeff(first(expr),k)),
254 1/product(factor(first(expr)-i__+1),
255 i__,1,-leadCoeff(first(expr),k)),hyp_flag]
258 if zb_op(expr) = binomial then
260 sq_num : shiftQuoHypCheckAux(factorial(first(expr)),k,hyp_flag),
261 sq_den : shiftQuoHypCheckAux(factorial(first(expr)-second(expr)),
263 shiftQuoHypCheckAux(factorial(second(expr)),
265 if second(sq_num) = HYP and second(sq_den)=HYP then
266 return([first(sq_num)/first(sq_den),HYP])
268 return([expr,NO_HYP])
273 if zb_op(expr) = "-" then block(
274 return(shiftQuoHypCheckAux(-expr, k, hyp_flag))
277 if zb_op(expr) = "+" then
278 return([shiftFactPoly(expr,k,1)/expr,hyp_flag])
281 if warnings then print("Unknown operator : ", zb_op(expr)),
282 return([expr,NO_HYP])