Stavros Macrakis wrote:
>Here is some code to do that, though I'm not sure I see the point:
>
>threshsum(expr,vals,factor):=
> /* if expr not a sum, just return it */
> if atom(expr) or part(expr,0)#"+" then expr
> else
> block([prederror:false, /* keep terms of unknown magnitude */
> symterms: args(expr), /* symbolic terms */
> evterms, /* evaluated terms */
> minterm], /* minimum term to keep */
> evterms: makelist(abs(float(subst(vals,term))),term,symterms),
> /* evaluate each term with given values */
> minterm: apply('max,evterms)/factor,
> apply("+",
> map( lambda([symterm,evterm],
> if is(evterm<minterm)=true
> then (if debugmode then print("Excluding term
>",symterm=evterm),
> 0)
> else symterm),
> symterms,
> evterms )));
>
>
Beautiful, exactly what I needed. Thank you.
Here is some background.
When analyzing electric circuits containing linearized transistor
models, the expressions often contain parameters with large magnitude
differences where the small terms will have a very small effect on the
result. Since these expressions tend to be very long, reducing
unnecessary complexity is most welcome. A taylor expansion would not
help in this case since both the small and large terms would turn
up together in the taylor coefficients.
Regards
Henrik Johansson