Search code examples
symbolic-mathmethodology

How can math programs accept equations of any form?


For example, I can type into Google or WolframAlpha 6+6, or 2+237, which could be programmed by asking a user for a and b, then evaluating return a+b. However, I might also type 5*5^(e) or any other combination, yet the program is hard-coded to only evaluate a+b expressions.

It's easy to represent the more complex problems in code, on any common language.

return 5*pow(5,Math.E) #pseudocode

But if I can't expect a user's input to be of a given form, then it isn't as simple as

x = Input("enter coefficient")
b = input("enter base")
p = input("enter power")
print(x*pow(b,p))

With this code, I'm locked-in to my program only able to evaluate a problem of the form x*b^p.

How do people write the code to dynamically handle math expressions of any form?


Solution

  • This might not be a question that 'appropriate' for this venue. But I think it's reasonable to ask. At the risk of having my answer voted out of existence along with the question, I'll offer a brief answer.

    Legitimate mathematical expressions, from simple to complicated, obey grammatical rules. Although a legal mathematical expression might seem unintelligible, grammatically speaking it will be far less complicated that the grammar needed to understand small bodies of human utterances.

    Still, there are levels of 'understanding' built into the products available on the 'net. Google and WolframAlpha are definitely 'high-end'. They attempt to get as close as possible to defining grammars capable of representing human utterance, in effect at least. Nearer the lower end are products such as Sympy which accept much more strictly defined input.

    Once the software decides what part of the input is a noun, and what is a verb, so to speak, it proceeds to perform the actions requested.

    To understand more you might have to undertake studies of formal language, artificial intelligence, programming and areas I can't imagine.