Another CPS example: mathematical reasoning - PowerPoint PPT Presentation

About This Presentation
Title:

Another CPS example: mathematical reasoning

Description:

loge (x2 - 1) = c. logUV = W - V = UW. x2 - 1 = ec. U - V = W - U = W V. x2 = ec 1 ... loge (x 1) loge (x-1) = c. can be represented as the following list: ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 20
Provided by: csC5
Learn more at: https://www.cs.ccsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Another CPS example: mathematical reasoning


1
Another CPS example mathematical reasoning
  • The problem given a mathematical equation, find
    its solution.
  • Problem space nodes represent mathematical
    equations, arcs represent algebraic laws
    transforming one equation into another.
  • Example
  • loge (x1) loge (x-1)
    c
  • logw
    U logw V lt-gt logw U V
  • loge (x1) (x-1) c
  • (U
    V) (U - V) lt-gt U2 - V2
  • loge (x2 - 1) c

  • logUV W lt-gt V UW
  • x2 - 1 ec

  • U - V W lt-gt U W V
  • x2 ec 1
  • U2
    V lt-gt U /- (sqr V)
  • x /- (sqr (ec 1))

2
How to reduce the complexity of the search?
  • We can apply "expert knowledge" to choose the
    best operator at each step.To make this
  • possible, we must
  • Explicate implicit expert knowledge.
  • Formally represent it.
  • Alan Bundy suggested that mathematicians use
    three categories of methods controlling the
  • use of algebraic laws
  • Attraction methods.
  • Collection methods
  • Isolation methods
  • These methods are used to analyze how a given law
    transforms an equation, and whether
  • a transformation leads towards the goal. They can
    be represented as production rules,
  • and using pattern-matching and forward chaining
    the problem space can be efficiently
  • searched.

3
Attraction methods
  • Attraction methods move occurrences of the
    unknown closer together.
  • Example Consider the following algebraic law
    W U W V --gt W (U V). Assume that only U
    and V contain the unknown, x.
  • The initial expression is represented
    The transformed expression is represented
  • by the following tree
    by the following tree


  • W
  • W U W V
    U V
  • The distance between occurrences of x is the
    number of steps required to move through
  • the tree from one occurrence to another.
  • Other algebraic laws belonging to this category
    are
  • logw U logw V --gt logw U V
  • (WU)V --gt WUV
  • UVW --gt (UV)W

4
Attraction methods (cont.)
  • Attraction methods can be applied only to the
    least dominant term in the equation, i.e. to
  • a term containing at least two subterms
    containing x.
  • Example
  • log (x) xp (x - 1) (x 1) q
  • each of the two subterms contain two
    occurrences of x.
  • Expression,ltfirst subtermgt ltsecond
    subtermgt also contains more than two
  • occurrences of x.Therefore, this
    expression has three least dominant terms to
    which
  • attraction methods can be applied
  • log(x) xp
  • (x - 1) (x 1)
  • log (x) xp (x - 1) (x 1)

5
Collection methods
  • Collection methods reduce the number of
    occurrences of the unknown in the equation.
  • Example Assume that U and V contain occurrences
    of the unknown, x, in the following law
  • (U V) (U - V) --gt U2 - V2
  • Trees describing the left hand side
    (lhs) and the right hand side (rhs) of this
    transformation are

  • -
  • -
    2 2
  • U V U V
    U V
  • Another algebraic law belonging to this category
    is
  • U W U Y --gt U (W Y)
    assume that only U and V contain x.
  • Collection methods are also applied to least
    dominant terms in the expression.

6
Isolation methods
  • Isolation methods reduce the depth of the
    occurrences of the unknown, x. They are applied
  • to the whole equation.
  • Example Assume that only U contains occurrences
    of the unknown, x, in the following law
  • U - W Y --gt U Y W
  • Trees describing the left hand side
    (lhs) and the right hand side (rhs) of this
    transformation are

  • - Y
    U
  • U W
    Y W
  • Two more algebraic laws belong to this category
    (only U contains x)
  • logWU Y --gt U WY
  • U2 W --gt U /- (sqrt W)

7
Implementation of a CPS for algebra problems
  • 1. Representation of states assuming that an
    equation is described in a prefix
  • form, we can use a list to represent it. For
    example, the equation
  • loge (x1) loge (x-1) c
  • can be represented as the following list
  • ( ltleft hand sidegt ltright hand
    sidegt)
  • ( ( (log ( x 1) e) (log (- x 1) e)) c )
  • 2. Representation of operators
  • (ltoperator namegt ltexpansion proceduregt)
  • symbol returns a list of pairs
    ltoperator stategt
  • To implement operator procedures, we need
  • A way to match components of the equation to
    those in a specific law being explored (i.e. we
    need a pattern-matching procedure)

8
Example
  • Consider the following isolation law represented
    as a pattern, with W, U, Y being
  • pattern variables
  • logW U Y --gt U WY
  • The lhs expression can be represented as follows
  • ( (log (? arg) (? base)) (? rhs))
  • To match this pattern to a state means to define
    specific values for pattern variables,
  • (? arg), (? base), (? rhs). Assume that these
    values are stored in a dictionary of
  • bindings. Then, the rhs expression, U WY,
    represented as
  • ( (? arg) (expt (? base) (? rhs)))
  • can be computed by means of the following
    substitution procedure
  • Matching phase ( (log (? arg) (? base))
    (? rhs))

  • Operator logW U Y --gt U WY

9
Additional constraints on the pattern-matching
process
  • 1. Some of pattern variables contain instances
    of x, while others do not. To account for
  • this property, we can expand the representation
    of pattern variables as follows
  • (? patt-var contains-x?)
  • (? patt-var no-x?)
  • Example logW U Y --gt U WY will be
    represented as follows
  • ( log (? arg contains-x?) (? base no-x?)
    (? rhs no-x?)
  • 2. There are laws that are always worth
    applying, because they reduce the complexity of
  • the expression. For example
  • U 0 --gt U
  • U 0 --gt 0
  • U 1 --gt U
  • If possible, replace a sub-term by its values.
    Example sub-term ( 2 2) can be replaced by its
    value, 4, thus reducing the complexity of the
    expression.

10
  • To use the same pattern-matching mechanism in
    applying these simplifying rules, we must
  • account for the following cases
  • 0 --gt
  • 1 --gt
  • 0 --gt 0
  • segment variables
  • Let us call whatever comes before and after 0 and
    1 terms segment variables. Segment
  • variables may match more than one element on a
    list. To represent them, we use
  • (?? segm-var). For example,
  • ( (?? pre) 0 (?? post)) --gt ( (?? pre)
    (?? post))
  • Segment variables allow a pattern to match an
    expression in more than one way. For
  • Example, expression
  • (a b foo foo foo c d) can
    be represented as ((?? before) foo (?? after)),

11
  • To summarize, the pattern matcher must recognize
    two types of variable
  • Segment variable. These match zero or several
    elements on a list, and start with ??
  • Element variables. These match exactly one
    element on a list, and are represented as
  • (? ltvar-namegt lta predicate representing
    an optional restrictiongt)
  • To handle pattern variables we need the following
    functions (refer to match.lsp)
  • pattern-variable?
  • element-variable?
  • segment-variable?
  • var-name
  • var-restriction
  • var-value
  • lookup-var
  • bind-element-var
  • bind-segment-var

12
  • One more detail that must be addressed is
    substituting expressions with their values. This
  • can be implemented as follows
  • ( (? num1 numberp) (? num2 numberp)
    (?? terms))
  • these two are to be
    added
  • ( (eval ( (? num1) (? num2))) (??
    tems))
  • eval is a special form which computes
    the result of the expression and places it in the
    dictionary.
  • The simplification rule now becomes
  • ( (? num1 numberp) (? num2 numberp)
    (?? terms)) --gt
  • (
    (eval ( (? num1) (? num2))) (?? tems))

13
  • Consider the following expression
  • ( A 2 3)
  • Note that it will not match the simplification
    rule, but the equivalent expression ( 2 3 A)
  • will. To handle such cases we must be able to
    rearrange the expression bringing its
  • numerical terms before non-numerical terms. This
    can be done by introducing a
  • relationship "less than" on the order of term,
    where
  • Numerical terms are "less than" non-numerical.
  • The expression is sorted with respect to this
    relationship.
  • This is implemented by the form splice.
  • To run the CPS for solving algebra problem, you
    need the following files search.lsp,
  • variants.lsp, algebra.lsp, simplify.lsp,
    match.lsp A specific example is defined in
    algebra.lsp
  • (defvar bundy '( ( (log ( x 1) E) (log (- x
    1) E)) C)
  • "A single example problem from Alan Bundy's
    reasoner.")

14
Example (book, page 60)
  • Function setup-algebra-problem in algebra.lsp
    defines a particular problem
  • (same as in setup-subway-problem)
  • (defun setup-algebra-problem ()
  • "Create an generic algebra 'problem space'."
  • (make-problem
  • NAME 'Algebra
  • GOAL-RECOGNIZER 'got-algebra-goal?
  • OPERATOR-APPLIER 'find-algebra-operator
  • STATE-PRINTER '(lambda (f) (format nil "A"
    f))
  • SOLUTION-ELEMENT-PRINTER 'print-derivation-st
    ep
  • STATES-IDENTICAL? 'equal
  • DISTANCE-REMAINING 'algebra-distance
  • OPERATORS '((Isolate-Log try-isolate-log)
  • (Isolate-Sum try-isolate-sum)
  • (Isolate-Difference
    try-isolate-difference)
  • (Isolate-Square
    try-isolate-square)
  • (Collect-Product-Difference
    try-collect-prod-diff)
  • (Attract-Log-Sum
    try-attract-log-sum)

15
Implementation of the pattern-matcher
  • Consider the following expression and the pattern
    it matches
  • ( (log
    ( x 1) e) (log (- x 1) e)
  • ( (log (? U has-unknown?) (? W
    no-unknown?)) (log (? V has-unknown? (? W))
  • The following substitutions are required for
    these matches
  • (V (- x 1))
    Assume that these substitutions are stored in a
  • (W e)
    dictionary of bindings as an association list.
  • (U ( x 1))
  • The dictionary has the following format
  • ((patt_var1 value) (patt_var2 value)
    )
  • Given the key, patt_varN, the corresponding value
    can be accessed via the assoc primitive

16
The match function
  • The match function takes the following
    parameters pat, dat, and the current
  • dictionary, and returns the new extended
    dictionary. It must consider the
  • following cases
  • A component is found for which the pattern and
    the expression do not match, therefore the match
    fails.
  • pat is a symbol
  • pat is an element variable
  • pat is an empty list
  • pat is a segment variable
  • pat is a list, but dat is an atom, therefore the
    match process fails.
  • If none of these is the case, match must return
    the dictionary accumulated so far.

17
The substitution process
  • As a result of the substitution process, a new
    expression is created. This new expression
  • represents the rhs of the simplification rule
    being applied. To carry out this process,
  • we need
  • the dictionary generated during the matching
    process,
  • the expression constituting the rhs of the
    simplification rule.
  • Example Assume that (?? A) has the value (1 2),
    and (?? B) has the value (3 4). Then
  • expression ( (?? A) (?? B)) is transform by the
    substitution process into
  • ( (1 2) (3 4)).
  • (eval ((?? A) (?? B)) returns 10.
  • ( (splice (42 (?? A) (?? B)))) returns ( 42 1
    2 3 4)

18
Implementation of the simplifier
  • Consider the following expression ( ( x -2)
    ( x 2)). It is always 0, which is why it must
  • be eliminated as early as possible. A
    simplification of this type can be performed by a
    set
  • of rewrite rules of the form (ltpatterngt
    ltresultgt).Note that knowledge needed to recognize
  • situations where simplification is possible must
    be acquired and embedded in the PS.
  • There are 4 categories of simplification rules
  • Rules for recognizing special arguments to
    operators. Example
  • Rule 0 U --gt U. Encoded (( (?
    Zero zero?) (?? E)) ( (?? E)))
  • Rule e0 --gt 1. Encoded ((expt (? E)
    (? Zero zero?)) 1)
  • 2. Rules dealing with equivalences
    involving multiplication, squaring and exponent.
  • Rule (sqrt (U2)) --gt U. Encoded
    ((sqrt (sqr (? E))) (abs (? E)))
  • 3. Rules for reducing expressions if
    numerical values are available. Examples
  • Rule A / B --gt value.
  • Encoded ((/ (? e1 numberp) (? e2
    numberp)) (eval (/ (? e1) (? e2))))
  • Rule A (B C) --gt A B C.
  • Encoded (((? op /?) (?? e1) ((?
    op) (?? e2) (?? e3)))((? op) (?? e1) (?? e2) (??
    e3)))
  • 4. Rules for producing canonical forms.
    Example
  • ( a 2 3) --gt ( 2 3 a)

19
Problems with the CPS model
  • In 1957, Herbert Simon wrote " It is not my aim
    to surprise or shock you
  • But the simplest way I can summarize is to say
    that there are now in the world
  • machines that think, that learn and create.
    Moreover, their ability to do these
  • things is going to increase rapidly - in a
    visible future - the range of problems
  • they can handle will be coextensive with the
    range to which the human mind has
  • been applied
  • Was Herbert Simon right? The short answer is NO.
    And the short explanation is
  • that the CPS-type systems are based on the idea
    that there exists a general
  • Problem solving method that can be applied to any
    problem requiring human
  • intelligence. 10 years were needed to realize
    that the real power of human
  • intelligence is not the problem solving per se,
    but knowledge behind the problem
  • solving process. In CPS, knowledge is embedded
    implicitly (like in conventional
  • computer programs), although it is separated from
    the search engine.
  • To build a powerful AI program, we need a way
    to represent knowledge
  • explicitly. This is true for both, domain
    knowledge and control knowledge.
Write a Comment
User Comments (0)
About PowerShow.com