[Date Index]
[Thread Index]
[Author Index]
Re: Simplifying constants
*To*: mathgroup at smc.vnet.net
*Subject*: [mg18586] Re: [mg18489] Simplifying constants
*From*: BobHanlon at aol.com
*Date*: Tue, 13 Jul 1999 01:01:23 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
Morten,
equiv = (A == b + c + d + e);
The possible substitutions are
subst = (Solve[equiv, #][[1]] & /@
Cases[equiv[[2]], _Symbol])
{{b -> A - c - d - e}, {c -> A - b - d - e}, {d -> A - b - c - e}, {e ->
A - b - c - d}}
Given an expression f
f = 2b + 6c + 5d + 3e + (b + c + d + e)*Sin[x];
soln = Simplify[Prepend[(f /. subst), f]]
{2 b + 6 c + 5 d + 3 e + (b + c + d + e) Sin[x],
2 A + 4 c + 3 d + e + A Sin[x], 6 A - 4 b - d - 3 e + A Sin[x],
5 A - 3 b + c - 2 e + A Sin[x], 3 A - b + 3 c + 2 d + A Sin[x]}
You then need some criterion to decide which form of the expression is
preferred.
LeafCount might be a common criteria.
Sort[soln, LeafCount[#1] < LeafCount[#2] &]
{5 A - 3 b + c - 2 e + A Sin[x], 2 A + 4 c + 3 d + e + A Sin[x],
3 A - b + 3 c + 2 d + A Sin[x], 6 A - 4 b - d - 3 e + A Sin[x],
2 b + 6 c + 5 d + 3 e + (b + c + d + e) Sin[x]}
% // First
5 A - 3 b + c - 2 e + A Sin[x]
Automating this process for at least simple cases:
simplifyWith[expr_, lhs_Symbol == rhs_] :=
Module[{varList, subst},
varList = Cases[rhs, _Symbol, Infinity];
subst = (Solve[lhs == rhs, #][[1]] & /@ varList);
First[
Sort[Simplify[Prepend[expr /. subst, expr]],
LeafCount[#1] < LeafCount[#2] &]]];
simplifyWith[f, equiv]
5 A - 3 b + c - 2 e + A Sin[x]
Bob Hanlon
In a message dated 7/8/99 3:40:39 AM, mgd at com.dtu.dk writes:
>I am working with some annoyingly long equations that I want to simplify
>by including one set of parameters in a constant (or function) A, and
>another in B and so on.
>
>You can easily do:
>
>A = b+c+d+e
>
>but what I want to do is the reverse:
>
>b+c+d+e = A
>
>and use this information to reduce the equations. Does anybody know how
>to do this?
>
Prev by Date:
**Re: Re: Simplifying constants...bug?**
Next by Date:
**Re: bug in 4.0**
Previous by thread:
**RE: Simplifying constants**
Next by thread:
**Re: Canceling square roots with Simplify**
| |