Mathematica Help: FullSimplify does not use conjugate identities - wolfram-mathematica

FullSimplify fails to recognize that:
a*Conjugate[b] + b*Conjugate[a] = 2 Re[a*b]
I have some very complex equations that could be simplified greatly if Mathematica could recognize this simple identity
(and that a*Conjugate[b] - b*Conjugate[a] = 2 Im[a*b]).
See, Mathematica will not finish solving my equations when written in
a*Conjugate[b] +b*Conjugate[a] form,
but I could at the very least write my final equations in an extremely descriptive and compact form if Mathematica recognized this. The actual expressions look like:
-((I q1 + q2)/(I q0 + Sqrt[-q0^2 + q1^2 + q2^2 + q3^2])) -
(Conjugate[q1] + I Conjugate[q2])/
(Conjugate[q0] + I Conjugate[Sqrt[-q0^2 + q1^2 + q2^2 + q3^2]])
I would do this myself, but there are 16 of such expressions and they form 4 sets of coupled systems. Since one sign error would render my work useless, I would strongly prefer an automated process.

The identity you gave, b Conjugate[a] + a Conjugate[b] == 2 Re[a b], is only true if at least one of a and b is real:
In[7]:= Simplify[
Reduce[a*Conjugate[b] + b*Conjugate[a] == 2 Re[a*b], {a, b}]]
Out[7]= Im[a] == 0 || Im[b] == 0
If this additional condition is in fact true in your application then you could give it to Simplify or FullSimplify as an assumption, as their second argument. For example:
In[14]:= FullSimplify[Im[a*Conjugate[b] + b*Conjugate[a]],
Im[a] == 0 || Im[b] == 0]
Out[14]= 0
By the way, here is one example when the identity is not true:
In[1]:= FindInstance[
a*Conjugate[b] + b*Conjugate[a] != 2 Re[a*b], {a, b}]
Out[1]= {{a -> -I, b -> -I}}

First pass: Use ComplexExpand[].
In := Simplify[ ComplexExpand[ a Conjugate[b] + b Conjugate[a], {a, b} ] ]
Out = 2 (Im[a] Im[b] + Re[a] Re[b])
For more fun, look at ComplexityFunction, although I find that a lot of trial and error is involved in tuning FullSimplify.

I think the correct identity should be:
a*Conjugate[b] + b*Conjugate[a] == 2 Re[Conjugate[a]*b]
It's always true:
In[1]:= FullSimplify[a*Conjugate[b] + b*Conjugate[a] == 2 Re[Conjugate[a]*b]]
Out[1]= True

Is your identity correct? I'm getting different numbers for two sides
{a*Conjugate[b] + b*Conjugate[a], 2 Re[a*b]} /. {a -> RandomComplex[],b -> RandomComplex[]}

Related

How to fix 'Equations may not give solutions for all "solve" variables' error

I am attempting a problem that can be solved with MUC (method of undetermined coefficients).
However, when I use the Solve function, it gives an error.
y[x_] := a x^3 + b x^2 + c x + d
Solve[{y''[x] + 2 y'[x] + y[x] == x^3}, {a, b, c, d}]
[ERROR]:
Solve::svars: Equations may not give solutions for all "solve" variables.
Shouldn't this solve for all variables in the set?
Thank You for your help :)
Looks like some extra methodology is needed for this.
As you stated, a function with the finite family of derivatives for x^3 is
y[x_] := a x^3 + b x^2 + c x + d
Equating coefficients
sol = Solve[Thread[CoefficientList[
y''[x] + 2 y'[x] + y[x], x] == CoefficientList[x^3, x]]]
{{a -> 1, b -> -6, c -> 18, d -> -24}}
Checking the results
FullSimplify[y''[x] + 2 y'[x] + y[x] == x^3 /. sol]
{True}

Question on "smart" replacing in mathematica

How do I tell mathematica to do this replacement smartly? (or how do I get smarter at telling mathematica to do what i want)
expr = b + c d + ec + 2 a;
expr /. a + b :> 1
Out = 2 a + b + c d + ec
I expect the answer to be a + cd + ec + 1. And before someone suggests, I don't want to do a :> 1 - b, because for aesthetic purposes, I'd like to have both a and b in my equation as long as the a+b = 1 simplification cannot be made.
In addition, how do I get it to replace all instances of 1-b, -b+1 or -1+b, b-1 with a or -a respectively and vice versa?
Here's an example for this part:
expr = b + c (1 - a) + (-1 + b)(a - 1) + (1 -a -b) d + 2 a
You can use a customised version of FullSimplify by supplying your own transformations to FullSimplify and let it figure out the details:
In[1]:= MySimplify[expr_,equivs_]:= FullSimplify[expr,
TransformationFunctions ->
Prepend[
Function[x,x-#]&/#Flatten#Map[{#,-#}&,equivs/.Equal->Subtract],
Automatic
]
]
In[2]:= MySimplify[2a+b+c*d+e*c, {a+b==1}]
Out[2]= a + c(d + e) + 1
equivs/.Equal->Subtract turns given equations into expressions equal to zero (e.g. a+b==1 -> a+b-1). Flatten#Map[{#,-#}&, ] then constructs also negated versions and flattens them into a single list. Function[x,x-#]& /# turns the zero expressions into functions, which subtract the zero expressions (the #) from what is later given to them (x) by FullSimplify.
It may be necessary to specify your own ComplexityFunction for FullSimplify, too, if your idea of simple differs from FullSimplify's default ComplexityFunction (which is roughly equivalent to LeafCount), e.g.:
MySimplify[expr_, equivs_] := FullSimplify[expr,
TransformationFunctions ->
Prepend[
Function[x,x-#]&/#Flatten#Map[{#,-#}&,equivs/.Equal->Subtract],
Automatic
],
ComplexityFunction -> (
1000 LeafCount[#] +
Composition[
Total,Flatten,Map[ArrayDepth[#]#&,#]&,CoefficientArrays
][#] &
)
]
In your example case, the default ComplexityFunction works fine, though.
For the first case, you might consider:
expr = b + c d + ec + 2 a
PolynomialReduce[expr, {a + b - 1}, {b, a}][[2]]
For the second case, consider:
expr = b + c (1 - a) + (-1 + b) (a - 1) + (1 - a - b) d + 2 a;
PolynomialReduce[expr, {x + b - 1}][[2]]
(% /. x -> 1 - b) == expr // Simplify
and:
PolynomialReduce[expr, {a + b - 1}][[2]]
Simplify[% == expr /. a -> 1 - b]

solving an equation for the square of the variable?

Given a expression (polynomial, or any equation in general) such as
a s^2+b = 0
I want to solve for s^2, to get s^2 = -b/a. We all know that one can't just write
Solve[eq==0,s^2]
because s^2 is not a 'variable'. only s is a 'variable'. So what I do is
eq = a s^2+b;
sol = First#Solve[eq==0/.s^2->z,z];
z/.sol
-(b/a)
I was wondering if there is a way to do the above, without the intermediate variable substitution?
I tried many commands, but no success (reduce, collect, eliminate, factor. etc...).
thanks
--Nasser
One way is to solve for s and then square it...
eq=a s^2+b;
sol=#^2 &# (s/.Solve[eq==0,s])//DeleteDuplicates
Out[1]= {-(b/a)}
You could use the Notation package, but it leads to other issues.
So here is your original equation:
In[1]:= Solve[b + a s^2 == 0, s^2]
During evaluation of In[1]:= Solve::ivar: s^2 is not a valid variable. >>
Out[1]= Solve[b + a s^2 == 0, s^2]
Now Symbolize s^2 so that the normal Mathematica evaluator treats it like any other symbol
In[2]:= Needs["Notation`"]
In[3]:= Symbolize[ParsedBoxWrapper[SuperscriptBox["s", "2"]]]
In[4]:= Solve[b + a s^2 == 0, s^2]
Out[4]= {{s^2 -> -(b/a)}}
The problem is that s^2 really is treated as just another symbol, eg
In[6]:= Sqrt[s^2] // PowerExpand
Out[6]= Sqrt[s^2]
A work around is to replace s^2 with s*s, since Symbolize only acts on user inputed expressions (ie at the level of interpreting inputted Box structures)
In[7]:= Sqrt[s^2] /. s^2 -> s s // PowerExpand
Out[7]= s

Converting vector equation to a list of equations in Mathematica

Due to DSolve syntax, systems of differential equations have to be given as lists of equations and not as a vector equation (Unlike Solve, which accepts both).
So my simple question is how to convert a vector equation such as:
{f'[t],g'[t]}=={{a,b},{c,d}}.{f[t],g[t]}
To list of equations:
{f'[t]==a*f[t]+b*g[t],g'[t]==c*f[t]+d*g[t]}
I think I knew once the answer, but I can't find it now and I think it could benefit others as well.
Try using Thread:
Thread[{f'[t], g'[t]} == {{a, b}, {c, d}}.{f[t], g[t]}]
(* {f'[t] == a f[t] + b g[t], g'[t] == c f[t] + d g[t] *)
It takes the equality operator == and applies it to each item within a list with the same Head.
The standard answer to this question is that which Brett presented,
i.e., using Thread.
However, I find that for use in DSolve, NDSolve, etc... the command LogicalExpand is better.
eqn = {f'[t], g'[t]} == {{a, b}, {c, d}}.{f[t], g[t]};
LogicalExpand[eqn]
(* f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)
It doesn't convert a vector equation to a list, but it is more useful since it automatically flattens out matrix/tensor equations and combinations of vector equations.
For example, if you wanted to add initial conditions to the above differential equation, you'd use
init = {f[0], g[0]} == {f0, g0};
LogicalExpand[eqn && init]
(* f[0] == f0 && g[0] == g0 &&
f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)
An example of a matrix equation is
mEqn = Array[a, {2, 2}] == Partition[Range[4], 2];
Using Thread here is awkward, you need to apply it multiple times and Flatten the result. Using LogicalExpand is easy
LogicalExpand[mEqn]
(* a[1, 1] == 1 && a[1, 2] == 2 && a[2, 1] == 3 && a[2, 2] == 4 *)

FullSimply Inequalities and then rearranging them in Mathematica 7

I am using Mathematica 7 in the notebook interface and I want to rearrange an inequality so that I get a certain variable on one side. For eg.
FullSimplify[x^3+L+r>3x^3+2r]
Gives
L > r + 2 x^3
However, I want :
r < L-2x^3
Is there anyway we can instruct FullSimplify to order variables in a particular way? I am using Mathematica for presentation as well so, the way I arrange the variables is important to me.
Thanks
SR
Edit: I tried Reduce, while that works for this example, it does not work for the actual expression I have, I get an error saying,
This system cannot be solved with the methods available to Reduce.
Edit: here is the actual expression:
{L - (m^2 ((-2 + e)^2 \[Delta] + (5 +
2 e (-7 + 4 e)) \[Tau]) \[Omega])/(36 (2 - 3 e + e^2)^2)} > {0}
I want this to be displayed in the form of \[delta]< *something*
Thanks!
First of all, getting Mathematica to output something exactly as you would like it is something of a black art, and requires a lot of patience. That said, if you apply Reduce to your original expression, as per Belisarius, you'd get
In[1]:=Reduce[x^3 + L + r > 3 x^3 + 2 r, r, Reals]
Out[1]:= r < L - 2 x^3
However, as you pointed out, this isn't the full expression, and Reduce produces what can only be described as a less than helpful answer when applied to it. It is at this point where patience and a lot of extra processing is required. I'd start with
In[2]:=Reduce[ <full expression>, Delta, Reals] // LogicalExpand // Simplify
While this doesn't give you a clean answer, it is better than before and reveals more of the structure of your solution. (I would not use FullSimplify as that mixes Delta in with the other terms.) At this point, we need to know more about the terms themselves, and the output from In[2] is not quite as useful as we want.
I'd re-expand this with LogicalExpand which gives you twelve terms that are significantly simpler than the what Reduce alone gives. (You'll note that only the last six terms actually involve Delta, so I'd check that the variable conditions actually match those.) Selecting those last six terms only,
In[3]:=%2[[-6;;]] // Simplify
Out[3]:= m != 0
&& ((Omega > 0 && Delta < something) || (Omega > 0 && Delta < something else)
&& (1 < e < 2 || e < 1 || e > 2)
The third term is tautological, but Simplify nor FullSimplify can't seem to remove it. And we're really only interested in the middle term anyway. If Omega > 0 your expression can then be extracted via %[[2,1,2]].
Putting this all together in one expression:
In[4]:=Simplify[LogicalExpand[Reduce[<expression>, Delta, Reals]]][[-6;;]] //
Simplify // #[[2,1,2]]&
Out[4]:= Delta < something
After writing that out, I realized that there is a much simpler way to approach this. I'd redo line 2, above, as follows:
In[5]:= Reduce[ <full expression>, Delta, Reals] // LogicalExpand // Simplify //
Cases[#, ___ && Delta < _ && ___, Infinity]&
Out[5]:= {Omega > 0 && Delta < something}
Or, provided you really do know that m != 0 and Omega > 0 you can do
In[6]:= Reduce[ <expr> && m!=0 && Omega > 0, Delta, Reals ] // LogicalExpand //
Simplify // #[[2]]&
Reduce[x^3 + L + r > 3 x^3 + 2 r, r, Reals]
Will do.
As I don't use Mathematica for editing or presentation, perhaps someone else may come with some extra advice.
Edit
based on your comment, you may try:
Reduce[{L - (m^2 ((-2 + e)^2 Delta + (5 +
2 e (-7 + 4 e)) Tau) Omega)/(36 (2 - 3 e + e^2)^2) > 0}, Delta, Reals]
Where I corrected some syntax errors. But you'll find that the resulting expression is rather unpleasant. To simplify it further you need to know the valid ranges for your vars. Please post that info if you have it.
HTH!
Inspect the output of
r=Simplify[Reduce[L-(m^2((-2+e)^2\\[Delta]+(5+2e(-7+4e))\\[Tau])\\[Omega])/(36(2-3e+e^2)^2)>0,\\[Delta],Reals]]
to see that
r[[2,1,1,1]] gives \\[Delta]>expr,
but
r[[2, 1, 2, 2]] gives \\[Delta]< expr,
because the sign of \[Omega] in the denominator of expr. All this ignores the other conditions on the values of L, e, m and \[Omega] that will change the result and different versions of Mathematica may change the form of the result from Simplify[Reduce[]] which will invalidate all of this.
Part of the difficulty in reducing the expressions returned by Reduce[] and LogicalExpand[] is that the supplied expression involves division by zero when e=1 or =2.
I get something bearably compact with
Assuming[{
(L | m | e | Tau | Omega | Delta) \[Element] Reals
},
FullSimplify[
LogicalExpand[
Reduce[{L - (m^2 ((-2 + e)^2 Delta + (5 +
2 e (-7 + 4 e)) Tau) Omega)/(36 (2 - 3 e + e^2)^2) >
0}, Delta, Reals]
]
]
]
Out[]:= (L > 0 && (1 < e < 2 || e < 1 || e > 2) && (m == 0 || Omega == 0)) ||
(m != 0 && (
(Omega > 0 &&
Delta < (36 (-1 + e)^2 L)/(m^2 Omega) + ((-5 + 2 (7 - 4 e) e) Tau)/(-2 + e)^2) ||
(Delta > (36 (-1 + e)^2 L)/(m^2 Omega) + ((-5 + 2 (7 - 4 e) e) Tau)/(-2 + e)^2 &&
Omega < 0)) &&
(e > 2 || e < 1 || 1 < e < 2))
where I've expended no effort to replace symbol names with symbols.
(Why Assuming[...]? Because I'm too lazy to remember to get the same assumptions jammed into each simplification step.)

Resources