Multilingual Mathematics


Jordi Saludes
Universitat Politècnica de Catalunya

3d GF Summer Course
Fraueninsel, August 2013

Presenter Notes

Introduction

  • A prototype from MOLTO.

    • Mathematical Grammar Library
    • 2 gf pathways: NL to Sage, Sage to NL.

Presenter Notes

gfsage dialog flow

Steps

  • Lexing
  • Parsing
  • Transfer
  • Computing
  • Transfer
  • Linearizing
  • Unlexing

Presenter Notes

How it started?

  • With the webALT project: webALT logo

  • Aiming at providing a multilingual repository of simple math exercises for secondary education.

  • GF the chosen tool

Presenter Notes

The Mathematics Grammar Library

  • Basic math objects from some OpenMath Content Dictionaries.

    • Small Type System: Base for the GF abstract module
  • 15 languages so far: mathbar

  • Available at svn://molto-project.eu/mgl

Presenter Notes

Structure

mgl vertical structure

Presenter Notes

Layers

The library is organized in 3 layers of increasing complexity:

  • Ground: For literal integers and variables
  • OpenMath: For OpenMath objects
  • Operations: Problems, verbalizations, ...

Presenter Notes

Other upper layers

  • Operations: Simple drills.

  • Commands: Queries/Answers to/from a Computer Algebra System.

  • Word Problems: Modeling and solving simple word problems.

Presenter Notes

Some examples

  • At OpenMath level:

    abs : ValNum -> ValNum ;            -- the absolute value of z
    times : [ValNum] -> ValNum ;        -- the product of x, y and z
    unary_minus : ValNum -> ValNum ;    -- minus x
    
  • At Commands level:

    Compute  :  (k: Kind) -> Value k -> Command ;
    Assign   :   (k: Kind) -> Variable k -> Value k -> Command ;
    Assert   : Prop -> Command ;
    Approximate  : ValNum -> Command ;
    BeginBlock  : String -> Command ;
    EndBlock    : String -> Command ;
    

Goal: Dependent types all the way down.

Presenter Notes

Abstract/Concrete types

  • Values:

    • ValNum, ValSet, ValTensor ... = Noun Phrase (NP)
    • ValFun = MathFunc = NP + Extra info
  • Variables:

    • VarNum, VarSet, ... = Symbol

Goal: Value Number, Variable Number, ...

Presenter Notes

Concrete differences

  • In English:

    oper abs_value_CN : CN = mkCN absolute_A value_N ;     -- In LexiconEng
    lin abs obj =
      mkNP the_Art
         (mkCN abs_value_CN (mkAdv possess_Prep obj)) ;  -- In Arith1I
    
     unary_minus ob = mkNP (mkCN minus_N ob) ;
    
  • In Finnish:

    unary_minus x = mkNP (E.GenNP x) (mkN "vastaluku") ;
    
  • In Sage:

    unary_minus x = mkPrec 1 ("-" ++ (usePrec 3 x));
    

Presenter Notes

Associative operators

fun plus : [ValNum] -> ValNum

lin plus : ListNP -> NP

DefGenCN sum_CN (mkNP and_Conj terms)
  • Lists are formed by prepending an object to an existing list (ConsNP).

  • ListNP is basically a list of NP which knows if there is 2 or more elements in it:

    • "the sum of x and y": BaseValNum x y
    • "the sum of x, y and z": ConsValNum x (BaseValNum y z)
  • We combine ListNP with the "and" conjunction to get a new NP

Presenter Notes

The case of functions

oper
   MathFunc = {t:FuncForm; s2:MathVar} ** NP ;
param
  FuncForm = FNoVar | FNamed | FVar | FGral ;
  • Named function
    • "the cosine of 3"
  • Function variable
    • "\(f\) at 3"
  • General case

    • "the derivative of the sine at 3"
  • Lambda abstraction

    • "x to the cosine of x where x is 3"

Presenter Notes

Goal: Mixtures

  • Most of the productions have a verbal/formula rendering

    • Arith1Eng
    • Arith1LaTeX
  • Goal: To combine them:

The square root of \( x^2 + 1\)

Presenter Notes

Goal: Qualified variables

number_typed : VarNum -> QVarNum ;
number_list  : [VarNum] -> QVarNum ;
number_range : VarNum -> VarNum -> QVarNum ;

\(n\) "number"

\(x\), \(y\) and \(z\) "prime numbers"

\(x_1,\dots,x_n\) "natural numbers"

q_natural,
q_integer,
q_rational,
q_even,
q_prime : QVarNum -> QVarNum ;

"Let \(x_1,\dots,x_n\) be natural numbers, ..."

Presenter Notes

Propositions

Utterance dependencies

Prop   = S
[Prop] = [S]
SimpleProp = MathCl = Cl ** {p:Polarity}
QProp = QS ;

Presenter Notes

Goal: Propositions

Prop = MathCl = Cl ** {p:Polarity}
[Prop] = [MathCl]
Prop --> S, QS

7 is prime.

is 7 prime?

[Prop] --> S, QS

7 is prime and 8 is not prime.

is it true that 7 is prime and 8 is not prime?

Presenter Notes

Transfers

"Compute the integral of the function mapping x to the square of x from minus infinity to infinity."

Compute Num (fromNum (
   defint_interval (lambda x (power2 (Var2Num x)))
       nums1_minus_infinity nums1_infinity))

Compute Num (fromNum (
   defint_interval (lambda x (power2 (Var2Num x)))
     (unary_minus nums1_infinity) nums1_infinity))
  • It is ambiguous? (not really)

  • power2 --> power (int2num 2)

  • (unary_minus nums1_infinity) --> nums1_minus_infinity

Presenter Notes

Transfers (2)

  • Modifying the abstract tree.

  • GF is very limited on this (def judgments).

  • Use the GF bindings to other languages

    • haskell
    • python,

Presenter Notes

Transfer example

cat
  Kind ;
  Command;
  Answer;
  Value Kind;
  Variable Kind ;

fun
  Num, Fun, Set, Tensor : Kind ;

data Compute :  (k: Kind) -> Value k -> Command ;

fun
  addTo : ValNum -> ValNum -> Command ;

  itNum   : ValNum ;
  itSet   : ValSet ;

  Simple :   (k: Kind) -> Value k -> Answer ;
  FeedBack : (k: Kind) -> Value k -> Value k -> Answer;

def
  addTo x y          = Compute Num (fromNum (plus (BaseValNum x y))) ;
  bracket_emptyset = Simple Set (fromSet emptyset) ; -- {}

def
  bin_over x y = divide x y ;
fun
  isEqual   : (k: Kind) -> Value k -> Value k-> Command ;
  isAppEqual: (k: Kind) -> Value k -> Value k-> Command ;

  Yes: Answer ;
  No: Answer ;
  YesApprox: Index -> Answer ;

Presenter Notes

In Haskell

 1 completeEmpty  :: Bool -> Tree -> Maybe Tree
 2 completeReturn :: Bool -> Tree -> [Tree] -> [Tree]
 3
 4 completeEmpty False _ = Nothing
 5 completeEmpty True question = Just $ gf $
 6   case fg question of
 7     GAssign k var value -> GAssigned k var value
 8     GAssert p           -> GAsserted p
 9
10 completeReturn feedback question answers = catMaybes $ map (comp' . fg) answers
11   where
12     comp' = comp (fg question)
13     comp g a@(GYesApprox _)  = Just (gf a)
14     comp g a@GNo             = Just (gf a)
15     comp g a@GYes            = Just (gf a)
16     comp g a@(GSimple k v2)  =
17      case value g of
18         Just v1 -> Just $ gf $ if feedback
19                             then (GFeedBack k v1 v2)
20                             else a
21         _       -> Nothing
22     comp _ a@(GBegunBlock _)     = Just (gf a)
23     comp _ a@(GEndedBlock _)     = Just (gf a)
24     comp _ _ = Nothing
25     value (GCompute _ v)       = Just v
26     value (GApproximate v)     = Just $ GfromNum v
27     value (GApproximateTo v _) = Just $ GfromNum v
28     value _                    = Nothing

Presenter Notes

Concluding remarks

  • The mgl GF library provides parsing/linearizing between 15 natural languages and an abstract representation similar to OpenMath.

    • Tested for 3 languages.
  • It can be used to interact with mathematical software using natural language.

Presenter Notes

Developing a new language L

  1. Resource Grammar support
  2. Fill LexiconL
  3. Review cycle
    • Fix idiomatic productions

Presenter Notes

Developing a new module M

  1. Add abstract module M
  2. Add entries to LexiconL to support M
  3. Add concrete modules for M
  4. Review cycle:
    • Input from language + maths experts

Presenter Notes

Future work

  • Dependent types

  • Reduce indirection and simplify module structure

  • Mixtures

  • Qualified variables

Presenter Notes