2 /* Conversion routines */
4 /* RISC Institute, Linz, Austria */
5 /* by Fabrizio Caruso */
8 /* It computes the norm of a non-trivial integer linear expression */
9 intLinConst(intLin,k,n) :=
10 intLin - coeff(intLin,n,1)*n - coeff(intLin,k,1)*k;
12 /* It converts an intLinNorm into an integer linear */
13 norm2intLin(norm,k) :=
16 /* It converts an intLinNorm into a power of an integer linear */
17 norm2polyPower(norm) :=
18 first(norm)^second(norm);
21 /* Norm of a non-zero degree (in k) integer linear */
22 intLinPolyNorm(expr,k) :=
23 if(freeof(k,expr)) then
26 [expand(expr/coeff(expr,k,1)),coeff(expr,k,1)];
29 if (freeof(k,expr)) then
32 [expand(expr/coeff(expr,k,degree(expr,k))),
33 coeff(expr,k,degree(expr,k))];
36 block([polyNorm,res,constRes],
37 if zb_operatorp(expr,"^") then
39 polyNorm : intLinPolyNorm(first(expr),k),
40 res : [polyNorm[1],second(expr)],
41 constRes : polyNorm[2]^second(expr)
45 polyNorm : intLinPolyNorm(expr,k),
46 res : [polyNorm[1],1],
47 constRes : polyNorm[2]
49 return([res,constRes])
54 block([base,res,constRes],
55 if zb_operatorp(expr,"^") then
57 base : polyNorm(first(expr),k),
58 res : [base[1],second(expr)],
59 constRes : base[2]^second(expr)
63 base : polyNorm(expr,k),
67 return([res,constRes])
71 /* It outputs the integer linear factor and non-integer linear factor of a given expression */
72 intLinCreate(expr,k) :=
74 [nonIntLinList,intLinList,length],
78 if atom(expr) or not(zb_operatorp(expr,"*")) then
79 if(integerLinear(expr,k)) then
90 for i:1 thru length-1 do
93 if integerLinear(first(expr),k) then
94 intLinList:cons(first(expr),intLinList)
96 nonIntLinList:cons(first(expr),nonIntLinList),
98 intLinList : cons(first(expr),intLinList),
102 intLinList:cons(expr,intLinList),
108 /* It outputs the integer linear factor and non-integer linear factor of a given expression */
111 [nonIntLinList,intLinList,length],
116 if atom(expr) or not(zb_operatorp(expr,"*")) then
117 if(integerLinear(expr,k)) then
128 for i:1 thru length-1 do
130 if integerLinear(first(expr),k) then
131 intLinList:cons(first(expr),intLinList)
133 nonIntLinList:cons(first(expr),nonIntLinList),
134 expr:expr/first(expr)
136 if integerLinear(expr,k) then
137 intLinList:cons(expr,intLinList)
139 nonIntLinList:cons(expr,nonIntLinList),
141 return([nonIntLinList,intLinList])
147 /* It creates a list of irreducible factors out of a factorized polynomial */
148 factored2List(expr) :=
153 if atom(expr)or not(zb_operatorp(expr,"*")) then
158 for i:1 thru length-1 do
160 list:cons(first(expr),list),
161 expr:expr/first(expr)
163 list:cons(expr,list),
169 /* It generates a list of normalized powers of integer linears */
170 intLinNormList(exprList,k) :=
173 for i:1 thru length(exprList) do
174 res:cons(intLinNorm(part(exprList,i),k),res),
179 normList(exprList,k) :=
182 for i:1 thru length(exprList) do
183 res:cons(powerNorm(part(exprList,i),k),res),