views:

165

answers:

3

Hi,

I have a basic question for all of the math experts out there.

"If I have an academic paper, whats the easiest way to convert a simple mathematical equation into working Matlab (or C++) code?"

Ideally, there would be a Latex >> Matlab (or C++) conversion tool.

However, failing this, is there a "cheat sheet" which contains all of the common mathematical symbols, and their equivalent implementation keywords in Matlab (or R, or C++)?

+4  A: 

Mathematica can emit LaTex or Java code. Maybe you should check it out.

"cheat sheet"? Mathematics is a bigger subject than you imagine. And you probably wouldn't understand half the symbols on it if you had it.

The simple ones (number operations like addition, etc.; simple functions like square root and trig functions) are easy enough to map from symbols to code. But those aren't the kinds of things that people who write serious math in LaTeX do.

It'd be a challenging problem. That's why Mathematica licenses are expensive.

duffymo
Mathematica is not about translating papers into code. Mathematica is the result of translating many-many academic papers into code, so that the users don't have to do it all over again. If a numerical algorithm isn't included into Mathematica, then Mathematica can't use it. Someone needs to program it first. Think of Matematica as a big library + programming environment.
I know what Mathematica is about. I'm saying that Mathematica does allow you to run their algorithms in code, simply by adding their JAR to your CLASSPATH if you're writing Java. And it can also export work as LaTeX.
duffymo
+7  A: 

I've never seen such a thing. Most mathematical notation is written to be understood by a person of (at least) reasonable intelligence, so it frequently omits all sorts of details that would be necessary to produce working code. If you had such a tool, I doubt it would produce usable results more than (maybe) 10% of the time.

The reverse seems a great deal more tenable -- producing readable mathematical notation from code (especially from something like Matlab) sounds much more reasonable. It's much easier to omit information that's present than to try to synthesize information that's missing.

Jerry Coffin
Quite true. But sometimes it would be very handy to create a command-line script (in some language) from an expression found in a document. However, a major problem is that most documents are in the PDF format, and so the formulas are actually nothing more than graphical objects...
Andreas Rejbrand
But the reverse has a very similar problem - when I want to understand what some algorithm, esepecially a mathematical one does, I can dig myself through the code (a process of days or weeks) or I could ask the author for a short, human-understandable outline. I don't think the latter can be easily automated.
Doc Brown
@Doc Brown: Don't get me wrong: I don't expect to see a tool to convert large chunks of (say) C++ to really readable descriptions any time soon. Nonetheless, I can at least *imagine* such a thing producing halfway usable results, where I find it hard to even imagine going the other direction.
Jerry Coffin
@Jerry: if you ever find such a tool within the next 10 years or so which can produce useful results, let me know ;-)
Doc Brown
+2  A: 

It's not possible. Generally, mathematical expressions in papers are made for humans to understand, as Jerry Coffin said. Because of this, there are all sorts of issues. One I think off the top of my head is optimality. (Mathematical) code for human consumption is rarely optimal, bad example is the Fibonacci sequence. Nobody would write Fibonacci code as humans understand it.

So, even if you did get the code parsed, you'll still have so much work to do it's the same as just writing it yourself.

John Smith