Reputation: 649
In the expressions below, x is variable and a, b, c, k are undefined constants. Is there a function to simplify constants in Maxima?
Examples,
Upvotes: 2
Views: 286
Reputation: 18979
There is a solution for this sort of problem here. (I'm not sure if that answer should be duplicated here and that issue closed as a duplicate of this or if this should just reference that.)
Upvotes: 0
Reputation: 17577
There is not a specific function for it, but I think you can create something via freeof
. E.g.:
(%i12) merge_constants (expr, var, newconst) :=
block ([freeof_var : sublist (args (expr), lambda ([e1], freeof (var, e1)))],
expr - apply ("+", freeof_var) + newconst) $
(%i13) merge_constants (x^2 - 2*a + b + c, x, k);
2
(%o13) x + k
(%i14) merge_constants (2^x + a/b + c^2, x, k);
x
(%o14) 2 + k
(%i15) merge_constants (sin(u) + u*cos(v) + v^2 + tan(w), u, m);
(%o15) u cos(v) + sin(u) + m
This function merge_constants
is just a first try. I'm sure there are ways to improve it. E.g. return the freeof_var
value to see what was replaced by newconst
. Anyway I hope this is useful.
Upvotes: 3