1
$\begingroup$

I am trying to perform Legendre transform on $x^2 \ln(1+x^{\frac{1}{3}}+x^{\frac{2}{3}})$ using this.

legendreTransform[f_, x_, y_] := 
Module[{k = Flatten[{x}], q = Flatten[{y}], h}, First[h /. 
Quiet[Solve[h == k.Grad[f, k] - f && q == Grad[f, k], 
  Append[k, h]], {Solve::incnst, Solve::ifun}]]]
Simplify[legendreTransform[a (Log[1 + c*x^(1/3) + d*x^(2/3)]), x, y],
Assumptions -> {Element[y, Reals]}]

And I did confirm this code gives correct Legendre transforms of $ e^x , x^2$.

However, it is taking very long for my computer (2 hours past, still no response after multiple tries) to run this with the expression above. This function is convex for x>0 , and this is the interval that I am interested in. Why is this the case?

Thank you very much for reading this question.

$\endgroup$
  • $\begingroup$ Likely it's the x^(1/3) causing problems, this is not a single valued function, and so it must choose which branch to calculate. Note that legendreTransform[Log[1 + x^(1/3)], x, y] is already multi-valued. $\endgroup$ – bill s Oct 2 '17 at 2:41
  • $\begingroup$ @bills then is it fine to add change the last part ' Assumptions -> {x>0, Element[x, Reals], Element[x, Reals]}' to solve that problem? $\endgroup$ – Duke Smith Oct 2 '17 at 2:49
  • $\begingroup$ That won't really help because the branch cuts are occurring within the legendreTransform function, while the Assumptions are part of the Simplify function. $\endgroup$ – bill s Oct 2 '17 at 3:01
  • $\begingroup$ @bills Where may I find info. on choosing the branch on Mathematica? is there a built-in function for it? $\endgroup$ – Duke Smith Oct 2 '17 at 3:12
  • $\begingroup$ legendreTransform[ Refine[x^2 (Log[1 + x^(1/3) + x^(2/3)]), Assumptions -> {x > 0, Element[x, Reals]}], x, y] doing this will not help either? $\endgroup$ – Duke Smith Oct 2 '17 at 3:28
4
$\begingroup$

You need to specify that you want Solve to work over the reals, not the complexes.

legendreTransform[f_, x_, y_] := Module[{k = Flatten[{x}], q = Flatten[{y}], h}, 
    First[h /. Quiet[
       Solve[
          h == k.Grad[f, k] - f && q == Grad[f, k], 
          Append[k, h],
          Reals
       ], 
       {Solve::incnst, Solve::ifun}]
     ]
]

This will help it choose appropriate branches, and in this case produces an answer in little over a second.

 AbsoluteTiming[Simplify[legendreTransform[a (Log[1 + c*x^(1/3) + d*x^(2/3)]), x, y],
Assumptions -> {Element[y, Reals]}];]

 (* {1.33583, Null}   I suppressed output becaues the result is big and ugly *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you, but why do I get an error (returns h$1874, with 'Solve::nsmet: This system cannot be solved with the methods available to Solve.') When I plug in a * x * (Log[1 + cx^(1/3) + dx^(2/3)]) as my function to this code? (all I did was multiplying x) $\endgroup$ – Duke Smith Oct 4 '17 at 1:42
  • 1
    $\begingroup$ Unfortunately, transcendental equations are not always solvable. Apparently, the one you get for that function falls into that camp. (And you're getting h$xxxx because Solve isn't returning a rule becuase it failed, so /. never evaluates, so the First seems extracts your module variable h from the /..) You can try removing the Reals and see if that returns a result over the complexes, but it would litterally spend hours or more trying to establish a solution. That may or may not work, and you may or may not be able to simplify the result to something usable over the reals. $\endgroup$ – Itai Seggev Oct 4 '17 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.