Subject: Repeatedly applying trigsimp, ratsimp etc.
From: Barton Willis
Date: Sun, 4 Nov 2012 14:27:34 +0000
(1) To access a member of a list, I suggest using inpart, not [k]. Consider:
(%i1) larry(k) := block([r : [1,2,3]], r[k])$
(%i2) george(k) := block([r : [1,2,3]], inpart(r,k))$
(%i5) r[x] : 42$
Unintended:
(%i6) larry(1);
(%o6) r[1]
OK:
(%i7) george(1);
(%o7) 1
Alternatively,
larry(k) := block([r : [1,2,3]], local(r), r[k])$
is OK too.
(2) To loop over the members of a list r, consider using
for rk in r do ( ...
instead of
for k : 1 thru length(r) do ( ...
The function length gets called each time at the top of the loop--also you will also not need to do r[k] any more :)
(3) Consider giving the last argument of dssimp a goofy name such as %_r_%. This isn't foolproof, but it does give some protection against
problems such as
(%i5) dssimp(1,[fff]);
(%o5) 1
(%i6) dssimp(1,[r]);
apply: found r evaluates to [r] where a function was expected.
(4) To form a compound statement without local variables, an explicit 'block' isn't needed--just (XXX, YYY, ZZZ), not block(XXX, YYY, ZZZ).
--Barton
________________________________________
----------------------
(defmfun $conssize (x) (if (atom x) 0 (do ((x (cdr x) (cdr x)) (sz 1))
((null x) sz) (incf sz (1+ (conssize (car x)))))))
File dssimp.mac:
-----------------------
dssimp(expr, r) :=
block([exprSize, smallestExpr, smallestExprSize, simpdExpr,
simpdExprSize],
exprSize : conssize(expr),
smallestExpr : expr,
smallestExprSize : exprSize,
loop,
for i : 1 thru length(r) do
block(
simpdExpr : r[i](expr),
simpdExprSize : conssize(simpdExpr),
if simpdExprSize < smallestExprSize then
block(
smallestExpr : simpdExpr,
smallestExprSize : simpdExprSize
)
),
if smallestExprSize >= exprSize then
return(expr),
expr : smallestExpr,
exprSize : smallestExprSize,
go(loop)
);
dssimpall(expr) := dssimp(expr, [combine, logcontract, radcan, ratsimp,
rootscontract, trigrat, trigreduce, trigsimp, xthru]);