1 /* -*- mode: maxima -*- */
2 eval_when(batch,ttyoff:true)$
4 5:05pm Tuesday, 14 July 1981
5 7:53pm Saturday, 29 May 1982
6 Added a DIAGEVAL_VERSION for this file.
7 1:43pm Saturday, 12 June 1982
8 Changed loadflags to getversions, DEFINE_VARIABLE:'MODE.
12 define_variable:'mode)$
14 put('lrats,3,'diageval_version)$
16 define_variable(messlrats2,"Invalid argument to FULLRATSUBST:",any)$
18 define_variable(fullratsubstflag,false,boolean)$
20 lratsubst(listofeqns,expr):=block(
21 [partswitch:true,inflag:true,piece],
22 if not listp(listofeqns)
23 then if inpart(listofeqns,0)="="
24 then listofeqns:[listofeqns]
25 else if fullratsubstflag=true
26 then error(messlrats2,[listofeqns,expr])
27 else error("Invalid argument to lratsubst:",[listofeqns,expr]),
28 if listp(inpart(listofeqns,1)) then if length(listofeqns)>1 then error("lratsubst: improper argument:",listofeqns) else listofeqns:inpart(listofeqns,1),
29 for idum in listofeqns do
31 then if fullratsubstflag=true
32 then error(messlrats2,[listofeqns,expr])
33 else error("Invalid argument to lratsubst:",[listofeqns,expr]),
34 lratsubst1(listofeqns,expr))$
36 define_variable(lrats_max_iter,100000,integer)$
37 qput(lrats_max_iter,lambda([v], if v<=0 then error("lrats_max_iter must be set to a positive integer.")),value_check);
39 lratsubst1(listofeqns,expr):=block([dum,lrats_iter:0],
40 for eqn in listofeqns do [dum,expr]:[expr,ratsubst(inpart(eqn,2),inpart(eqn,1),expr)],
43 fullratsubst0(eqn,expr):= fullratsubst1(second(eqn),first(eqn),expr)$
45 fullratsubst1(substexpr,forexpr,expr):=fullratsubst2([forexpr=substexpr],expr)$
47 fullratsubst2(listofeqns,expr):=block(
49 while lrats_iter<lrats_max_iter and dum#expr do (
50 [dum,expr]:[expr,lratsubst1(listofeqns,expr)],
51 lrats_iter:1+lrats_iter),
52 if lrats_iter>=lrats_max_iter then warning("fullratsubst2(listofeqns,expr): reached maximum iterations of",lrats_max_iter,". Increase `lrats_max_iter' to increase this limit."),
55 fullratsubst([arglist]):=block(
56 [larglistdum:length(arglist),farglist,partswitch:true,inflag:true,piece],
58 then (farglist:first(arglist),
59 if listp(farglist) then fullratsubst2(farglist,second(arglist))
60 else if inpart(farglist,0)="=" then fullratsubst0(farglist,last(arglist))
61 else error(messlrats2,arglist))
63 then apply('fullratsubst1,arglist)
64 else error(messlrats2,arglist))$
66 eval_when(batch,ttyoff:false)$