Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I recently found a website called Mathway

Basically, it works by allowing you to choose your "level of math" (which it uses to determine what tools it should provide to you) and then allows you to input a math problem which it then solves for you, and gives you detailed solutions (you have to try it, it's really cool).

I was wondering how it worked on two levels. First off, how would they parse the math problem (and all the sometimes foreign mathematical operators)? How do they get from text to numbers, variables, and operators?

Second, how do they generate the explanations? While you have to pay for the detailed solutions (which are explanations of how they solved the problem), I've seen their preview screenshots, and it looks very detailed. The explanations are given in full, accurate sentences. How would they generate something like that?

share|improve this question
    
+1 for the cool website. Really neat demonstration of technology helping with education. –  Stargazer712 Nov 28 '11 at 20:00
add comment

3 Answers

up vote 3 down vote accepted

It first breaks it into tokens using a lexer. In an expression like 3 + 5, the tokens are 3, +, and 5. Those tokens are fed into a parser, which knows the context and the relationships between all the tokens, and can call the appropriate functions.

For example, when the parser encounters the expression 3 + 5, it sees the + token and looks up in a table that says it should call a function named add with the tokens of 3 and 5 as arguments, which does the math and returns an 8.

If you don't want to evaluate an expression, but maybe want to solve an equation, the add function will do something different. For example, in the equation x + 5 = 8, the add function might follow the rules we learned in algebra and subtract 5 from the right hand side.

As for generating the explanations, as part of the add function, it simply records what it is doing: "Subtract 5 from the right hand side." The computer has to take those steps in order, so writing it out in English isn't that much additional work.

Add a few thousand much more complex "add" functions and voilà, you have Mathway. Obviously, that's a vast oversimplification, but that's what computer science courses are for.

share|improve this answer
add comment

As far as I know, Macsyma was the first system for automatically performing symbolic math. That would be a good place to start your research.

share|improve this answer
add comment

No software in the world can work all by itself until and unless it receives inputs from the user or another system. Once inputs are received, then they are processed into a form that is acceptable by the processor to process them further for the desired output. For example, data types are converted in other data types which we refer as casting. This is the answer to your question: How do they get from text to numbers, variables, and operators?

Also there is something what we call functional decomposition or stepwise refinement when analysing a certain complex process in programming. I would advise you to use the website further , jot down individual features, simplify them by breaking them up further and then research on those bits and pieces.

For performing Maths calculations, there are built-in maths libraries available for the said purpose. Also look into operator overloading. Have you ever tried adding two complex numbers in C++?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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