(10 points, difficult; due Jan. 27 at the beginning of lab,
and you may do this problem in partnerships, if you wish, with each
partner getting up to 10 points of extra credit.)
Write a Python program that analyzes algebra word problems and
solves them. This program will have the following parts.
1. Reading in the problem. The problem should be read in
as a piece of English text represented as a string.
The general form of the problem will be "If (problem information)
then (specific question).
2. Separating the problem information from the specific
question to be answered.
3. Extracting a list of rough equations from the problem information
4. Identifying variables and replacing phrases by the variables
in the rough equations.
5. Parsing the equations and building nested lists to represent
the right-hand sides of the equations.
6. Applying a set of production rules to solve for the unknown.
7. Reporting the answer.
Partial extra credit is available, too: Completing 1-4 only
is worth 5 points. Completing 6 and 7 only is worth 5 points.
More details will be given later.
Here is an example of input to the program. The string is
broken here for display purposes. You should not assume any
particular line breaks.
If the area of a circle is pi times the square of the radius
and the radius is 10 meters
then what is the area of the circle?
The main output for this example should be something like this:
The area of the circle is 314.159265.
The problem information consists of the material between
"If" and "then". The specific question consists of the material
between "then" and "?". The rough equations are the components
of the problem information that are separated by occurrences of
"and". Each rough equation has the form: [variable phrase]
["is" or "equals"] [expression], and [unit] component such as
"meters" is optional. In the given example, there are two
rough equations. The first variable phrase is "the area of
a circle is pi times the square of the radius", and this breaks
down into a variable phrase: "the area of a circle" and an
expression "pi times the square of the radius".
The second rough equation is "the radius is 10 meters".
The variable phrase for this one is "the radius" and the expression is
"10". There is also a unit component, "meters".
The parsing of the expressions (right-hand sides of equations)
can assume that these are simple expressions involving
only a limited set of operators and a limited set of forms, such
as described by the following rules:
An expression is either an individual term, a sum of two terms or
a difference of two terms.
A term is either a factor, a factor times a factor, or a
factor divided by a factor.
A factor is either an atom or a function applied to an atom.
An atom is either a
number, a variable, or a constant.