I am novice to Mathematica. I want to convert Mathematica code from my textbook to Java or Python to trace coding.

  • 10
    $\begingroup$ no. There is no way. Try to do it by hand. But how will you convert DSolve[] to Java? Or how will you convert Integrate or Simplify and the thousands of commands in Mathematica to Java? If the code contains no calls to Mathematica special build-in commands such as the above, but contains only basic commands, such as Table, Print, If etc..., then it can be possible to convert manually. $\endgroup$ – Nasser Jan 16 '19 at 4:27
  • 9
    $\begingroup$ Nope... and it would be a waste of time anyway. Mathematica is SOOO much more powerful than those languages that a single Mathematica function would need tens of thousands of lines in other languages. And then there is curated data. Etc. Learn how to use Mathematica and its tracing functions. MUCH better approach. $\endgroup$ – David G. Stork Jan 16 '19 at 6:24
  • 3
    $\begingroup$ Maybe some day: mathematica.stackexchange.com/q/173256/5478 $\endgroup$ – Kuba Jan 16 '19 at 9:21
  • 1
    $\begingroup$ There's no built-in way (and for many things there isn't a standard correspondence), but instead of trying to make your Mathematica code look like python code (I did that when I first switched over and it's a terrible experience and gives you slow code) I would suggest that you look up Functional Programming in a context you're more familiar with. Mathematica is primarily a functional programming language and using it as such will make you code cleaner, faster, and just generally make your life better. $\endgroup$ – b3m2a1 Jan 16 '19 at 10:14
  • $\begingroup$ There are some libraries which may help to port some small programs to other languages. $\endgroup$ – axelclk Mar 24 '19 at 11:35

I am not exactly sure what you mean by "trace coding", but in general, the Mathematica evalution methods are very complicated, and could be documented better. Again, in general, in any computer language, I suggest breaking code into smaller pieces and placing frequent output statements to see what the results of evaluations are. There is a Trace[] command but it produces volumnious and confusing output. Most Mathematica commands are higher level than those in other languages that you mentioned. Depending on the particular Mathematica code, if it is simple enough, it may be possible to "transliterate" it into another langauges. In any case, you need to read the documentation for the Mathematica commands you will be using. The FullForm[] and TreeForm[] commands will help you to see what the Mathematics expressions you are using really look like.

  • 2
    $\begingroup$ There is also actually a debugger inside the notebook. I remember reading a post here where one person actually managed to figure how to use i! I never figured how to use the Mathematica debugger myself, but in theory it is supposed to be an actual working debugger. For debugging I use Print statements and use a global flag to turn them off and on as needed. $\endgroup$ – Nasser Jan 16 '19 at 16:25

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.