I had tried the code below in Mathematica 8:
f[z_] := (5 + 1/(z-a)) / ( 8 + 1/(z-a))
f[a]
and surprisingly I got following warnings:
Power::infy: Infinite expression 1/0 encountered. >>
Power::infy: Infinite expression 1/0 encountered. >>
Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >
and the output is Indeterminate, which I think is not true because obviously it's 1.
What's weird is that when I changed the code to:
Simplify[(5 + 1/(z-a)) / ( 8 + 1/(z-a))] /. a -> z
I got the correct output 1. Why is that? And how should I deal with expressions involving ∞/∞ ?
Usually:
Limit[(5 + 1/(z - a))/(8 + 1/(z - a)), z -> a]
(*
-> 1
*)
Edit
You may also add a Direction option to take the limit coming from either side if necessary:
Limit[(5 + 1/(z - a))/(8 + 1/(z - a)), z -> a, Direction -> 1]
or
Limit[(5 + 1/(z - a))/(8 + 1/(z - a)), z -> a, Direction -> -1]
Edit 2
The weird behavior of Simplify[ ] (allowing some mathematically indefinite expressions to evaluate) is well documented in the help:
No, ∞/∞ is undefined. Consider that 2 ( ∞/∞ ) = (2∞/∞) = ∞/∞, which could be massaged to make 1 = 2 if ∞/∞ were defined as 1.
Infinity is not a number, so operations with it are pointless if you treat it as one:
infinity + 1 = infinity
(infinity + 1) - infinity = infinity - infinity
1 = 0
Other than that, limits are not always equal to the function's value, which is what Mathematica is hinting at when it gives you the error.
Infinity is not necessarily equal to infinity. Therefore, you cannot make the assertion that "infinity/infinity = 1".
Dividing infinity by infinity is indeed indeterminate. Taking the limit of f(x)/g(x) where f and g tend to infinity might produce an actual limit (or it might not). In your case the limit happens to be 1.
Related
I'm trying to obtain the real part of the result of an operation which involves an undefined variable (let's say x).
How can I have Mathematica return x when I execute Re[x] if I know that x will never be a complex number? I think this involves telling Mathematica that x is a real, but I don't know how.
In my case the expression for which I want the real part is more complicated than a simple variable, but the concept will remain the same.
Some examples:
INPUT OUTPUT DESIRED RESULT
----- ------ --------------
Re[x] Re[x] x
Re[1] 1 1
Re[Sin[x]] Re[Sin[x]] Sin[x]
Re[1+x+I] 1 + Re[x] 1+x
Re[1 + x*I] 1-Im[x] 1
You can use for example the input Simplify[Re[x], x \[Element] Reals] which will give x as output.
Use ComplexExpand. It assumes that the variables are real unless you indicate otherwise. For example:
In[76]:= ComplexExpand[Re[x]]
Out[76]= x
In[77]:= ComplexExpand[Re[Sin[x]]]
Out[77]= Sin[x]
In[78]:= ComplexExpand[Re[1+x+I]]
Out[78]= 1+x
Two more possibilities:
Assuming[x \[Element] Reals, Refine[Re[x]]]
Refine[Re[x], x \[Element] Reals]
Both return x.
It can at times be useful to define UpValues for a symbol. This is far from robust, but it nevertheless can handle a number of cases.
Re[x] ^= x;
Im[x] ^= 0;
Re[x]
Re[1]
Re[1 + x + I]
Re[1 + x*I]
x
1
1 + x
1
Re[Sin[x]] does not evaluate as you desire, but one of the transformations used by FullSimplify does place it in a form that triggers Re[x]:
Re[Sin[x]] // FullSimplify
Sin[x]
I came across some weird behaviour when using GroebnerBasis. In m1 below, I used a Greek letter as my variable and in m2, I used a Latin letter. Both of them have no rules associated with them. Why do I get vastly different answers depending on what variable I choose?
Image:
Copyable code:
Clear["Global`*"]
g = Module[{x},
x /. Solve[
z - x (1 - b -
b x ( (a (3 - 2 a (1 + x)))/(1 - 3 a x + 2 a^2 x^2))) == 0,
x]][[3]];
m1 = First#GroebnerBasis[\[Kappa] - g, z]
m2 = First#GroebnerBasis[k - g, z]
EDIT:
As pointed out by belisarius, my usage of GroebnerBasis is not entirely correct as it requires a polynomial input, whereas mine is not. This error, introduced by a copy-pasta, went unnoticed until now, as I was getting the answer that I expected when I followed through with the rest of my code using m1 from above. However, I'm not fully convinced that it is an unreasonable usage. Consider the example below:
x = (-b+Sqrt[b^2-4 a c])/2a;
p = First#GroebnerBasis[k - x,{a,b,c}]; (*get relation or cover for Riemann surface*)
q = First#GroebnerBasis[{D[p,k] == 0, p == 0},{a,b,c},k,
MonomialOrder -> EliminationOrder];
Solve[q==0, b] (*get condition on b for double root or branch point*)
{{b -> -2 Sqrt[a] Sqrt[c]}, {b -> 2 Sqrt[a] Sqrt[c]}}
which is correct. So my interpretation is that it is OK to use GroebnerBasis in such cases, but I'm not all too familiar with the deep theory behind it, so I could be completely wrong here.
P.S. I heard that if you mention GroebnerBasis three times in your post, Daniel Lichtblau will answer your question :)
The bug that was shown by these examples will be fixed in version 9. Offhand I do not know how to evade it in versions 8 and prior. If I recall correctly it was caused by an intermediate numeric overflow in some code that was checking whether a symbolic polynomial coefficient might be zero.
For some purposes it might be suitable to specify more variables and possibly a non-default term order. Also clearing denominators can be helpful at least in cases where that is a valid thing to do. That said, I do not know if these tactics would help in this example.
I'll look some more at this code but probably not in the near future.
Daniel Lichtblau
This may be related to the fact that Mathematica does not try all variable orders in functions like Simplify. Here is an example:
ClearAll[a, b, c]
expr = (c^4 b^2)/(c^4 b^2 + a^4 b^2 + c^2 a^2 (1 - 2 b^2));
Simplify[expr]
Simplify[expr /. {a -> b, b -> a}]
(b^2 c^4)/(a^4 b^2 + a^2 (1 - 2 b^2) c^2 + b^2 c^4)
(a^2 c^4)/(b^2 c^2 + a^2 (b^2 - c^2)^2)
Adam Strzebonski explained that:
...one can try FullSimplify with all
possible orderings of chosen
variables. Of course, this multiplies
the computation time by
Factorial[Length[variables]]...
if say i have a function given :
singlepattern = Cosh[theta] + Cosh[3theta]
How do i get a rational expression in terms of x of the function if i want to substitute Cosh[theta] by
"Cosh[theta] = ( x )/ 2 "
expression?
I retagged the question as a homework. You should look into ChebyshevT polynomials. It has the property that ChebyshevT[3, Cos[th] ]==Cos[3*th]. So for your problem the answer is
In[236]:= x/2 + ChebyshevT[3, x/2]
Out[236]= -x + x^3/2
Alternatively, you could use TrigExpand:
In[237]:= Cos[th] + Cos[3*th] // TrigExpand
Out[237]= Cos[th] + Cos[th]^3 - 3 Cos[th] Sin[th]^2
In[238]:= % /. Sin[th]^2 -> 1 - Cos[th]^2 // Expand
Out[238]= -2 Cos[th] + 4 Cos[th]^3
In[239]:= % /. Cos[th] -> x/2
Out[239]= -x + x^3/2
EDIT The reason the above has to do with the explicit question, is that Cosh[theta] == Cos[I*u] for some u. And since u or theta are formal, results will hold true.
Use Solve to solve for theta, then substitute, Expand, and Simplify:
In[16]:= TrigExpand[Cosh[3 theta] + Cosh[theta]] /.
Solve[Cosh[theta] == (x)/2, theta] // FullSimplify
During evaluation of In[16]:= Solve::ifun: Inverse functions are being used by Solve,
so some solutions may not be found; use Reduce for complete solution information. >>
Out[16]= {1/2 x (-2 + x^2), 1/2 x (-2 + x^2)}
This might interest you:
http://www.wolframalpha.com/input/?i=cosh%28x%29+%2B+cosh%283*x%29
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.)
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[]}