Deep Learning For Symbolic Mathematics

1 INTRODUCTION . A longstanding tradition in machine learning opposes rule-based inference to statistical learning ( Rumelhart et al. , 1986 ) , and neural networks clearly stand on the statistical side . They have proven to be extremely effective in statistical pattern recognition and now achieve state-of-the-art performance on a wide range of problems in computer vision , speech recognition , natural language processing ( NLP ) , etc . However , the success of neural networks in symbolic computation is still extremely limited : combining symbolic reasoning with continuous representations is now one of the challenges of machine learning . Only a few studies investigated the capacity of neural network to deal with mathematical objects , and apart from a small number of exceptions ( Zaremba et al. , 2014 ; Loos et al. , 2017 ; Allamanis et al. , 2017 ; Arabshahi et al. , 2018b ) , the majority of these works focus on arithmetic tasks like integer addition and multiplication ( Zaremba & Sutskever , 2014 ; Kaiser & Sutskever , 2015 ; Trask et al. , 2018 ) . On these tasks , neural approaches tend to perform poorly , and require the introduction of components biased towards the task at hand ( Kaiser & Sutskever , 2015 ; Trask et al. , 2018 ) . In this paper , we consider mathematics , and particularly symbolic calculations , as a target for NLP models . More precisely , we use sequence-to-sequence models ( seq2seq ) on two problems of symbolic mathematics : function integration and ordinary differential equations ( ODEs ) . Both are difficult , for trained humans and computer software . For integration , humans are taught a set of rules ( integration by parts , change of variable , etc . ) , that are not guaranteed to succeed , and Computer Algebra Systems use complex algorithms ( Geddes et al. , 1992 ) that explore a large number of specific cases . For instance , the complete description of the Risch algorithm ( Risch , 1970 ) for function integration is more than 100 pages long . Yet , function integration is actually an example where pattern recognition should be useful : detecting that an expression is of the form yy′ ( y2 + 1 ) −1/2 suggests that its primitive will contain √ y2 + 1 . Detecting this pattern may be easy for small expressions y , but becomes more difficult as the number of operators in y increases . However , to the best of our knowledge , no study has investigated the ability of neural networks to detect patterns in mathematical expressions . We first propose a representation of mathematical expressions and problems that can be used by seq2seq models , and discuss the size and structure of the resulting problem space . Then , we show how to generate datasets for supervised learning of integration and first and second order differential equations . Finally , we apply seq2seq models to these datasets , and show that they achieve a better performance than state-of-the-art computer algebra programs , namely Matlab and Mathematica . ∗ Equal contribution . 2 MATHEMATICS AS A NATURAL LANGUAGE . 2.1 EXPRESSIONS AS TREES . Mathematical expressions can be represented as trees , with operators and functions as internal nodes , operands as children , and numbers , constants and variables as leaves . The following trees represent expressions 2 + 3× ( 5 + 2 ) , 3x2 + cos ( 2x ) − 1 , and ∂ 2ψ ∂x2 − 1 ν2 ∂2ψ ∂t2 : + 2 × 3 + 5 2 + × 3 pow x 2 − cos × 2 x 1 - ∂ ∂ ψ x x × / 1 pow ν 2 ∂ ∂ ψ t t Trees disambiguate the order of operations , take care of precedence and associativity and eliminate the need for parentheses . Up to the addition of meaningless symbols like spaces , punctuation or redundant parentheses , different expressions result in different trees . With a few assumptions , discussed in Section A of the appendix , there is a one-to-one mapping between expressions and trees . We consider expressions as sequences of mathematical symbols . 2 + 3 and 3 + 2 are different expressions , as are √ 4x and 2x , and they will be represented by different trees . Most expressions represent meaningful mathematical objects . x / 0 , √ −2 or log ( 0 ) are also legitimate expressions , even though they do not necessarily make mathematical sense . Since there is a one-to-one correspondence between trees and expressions , equality between expressions will be reflected over their associated trees , as an equivalence : since 2+3 = 5 = 12−7 = 1×5 , the four trees corresponding to these expressions are equivalent . Many problems of formal mathematics can be reframed as operations over expressions , or trees . For instance , expression simplification amounts to finding a shorter equivalent representation of a tree . In this paper , we consider two problems : symbolic integration and differential equations . Both boil down to transforming an expression into another , e.g . mapping the tree of an equation to the tree of its solution . We regard this as a particular instance of machine translation . 2.2 TREES AS SEQUENCES . Machine translation systems typically operate on sequences ( Sutskever et al. , 2014 ; Bahdanau et al. , 2015 ) . Alternative approaches have been proposed to generate trees , such as Tree-LSTM ( Tai et al. , 2015 ) or Recurrent Neural Network Grammars ( RNNG ) ( Dyer et al. , 2016 ; Eriguchi et al. , 2017 ) . However , tree-to-tree models are more involved and much slower than their seq2seq counterparts , both at training and at inference . For the sake of simplicity , we use seq2seq models , which were shown to be effective at generating trees , e.g . in the context of constituency parsing ( Vinyals et al. , 2015 ) , where the task is to predict a syntactic parse tree of input sentences . Using seq2seq models to generate trees requires to map trees to sequences . To this effect , we use prefix notation ( also known as normal Polish notation ) , writing each node before its children , listed from left to right . For instance , the arithmetic expression 2+3∗ ( 5+2 ) is represented as the sequence [ + 2 ∗ 3 + 5 2 ] . In contrast to the more common infix notation 2 + 3 ∗ ( 5 + 2 ) , prefix sequences need no parentheses and are therefore shorter . Inside sequences , operators , functions or variables are represented by specific tokens , and integers by sequences of digits preceded by a sign . As in the case between expressions and trees , there exists a one-to-one mapping between trees and prefix sequences . 2.3 GENERATING RANDOM EXPRESSIONS . To create training data , we need to generate sets of random mathematical expressions . However , sampling uniformly expressions with n internal nodes is not a simple task . Naive algorithms ( such as recursive methods or techniques using fixed probabilities for nodes to be leaves , unary , or binary ) tend to favour deep trees over broad trees , or left-leaning over right leaning trees . Here are examples of different trees that we want to generate with the same probability . cos + × 3 sqrt + pow x 2 8 x × + 3 × x 3 pow x 2 + × × + sin x 8 x 5 3 + 3 × 5 × x + 8 sin x In Section C of the appendix , we present an algorithm to generate random trees and expressions , where the four expression trees above are all generated with the same probability . 2.4 COUNTING EXPRESSIONS . We now investigate the number of possible expressions . Expressions are created from a finite set of variables ( i.e . literals ) , constants , integers , and a list of operators that can be simple functions ( e.g . cos or exp ) or more involved operators ( e.g . differentiation or integration ) . More precisely , we define our problem space as : • trees with up to n internal nodes • a set of p1 unary operators ( e.g . cos , sin , exp , log ) • a set of p2 binary operators ( e.g . + , − , × , pow ) • a set of L leaf values containing variables ( e.g . x , y , z ) , constants ( e.g . e , π ) , integers ( e.g . { −10 , . . . , 10 } ) If p1 = 0 , expressions are represented by binary trees . The number of binary trees with n internal nodes is given by the n-th Catalan numbers Cn ( Sloane , 1996 ) . A binary tree with n internal nodes has exactly n+ 1 leaves . Each node and leaf can take respectively p2 and L different values . As a result , the number of expressions with n binary operators can be expressed by : En = Cnp n 2L n+1 ≈ 4 n n √ πn pn2L n+1 with Cn = 1 n+ 1 ( 2n n ) If p1 > 0 , expressions are unary-binary trees , and the number of trees with n internal nodes is the n-th large Schroeder number Sn ( Sloane , 1996 ) . It can be computed by recurrence using the following equation : ( n+ 1 ) Sn = 3 ( 2n− 1 ) Sn−1 − ( n− 2 ) Sn−2 ( 1 ) Finally , the number En of expressions with n internal nodes , p1 unary operator , p2 binary operators and L possible leaves is recursively computed as ( n+ 1 ) En = ( p1 + 2Lp2 ) ( 2n− 1 ) En−1 − p1 ( n− 2 ) En−2 ( 2 ) If p1 = p2 = L = 1 , Equation 2 boils down to Equation 1 . If p2 = L = 1 , p1 = 0 , we have ( n + 1 ) En = 2 ( 2n − 1 ) En−1 which is the recurrence relation satisfied by Catalan numbers . The derivations and properties of all these formulas are provided in Section B of the appendix . In Figure 1 , we represent the number of binary trees ( Cn ) and unary-binary trees ( Sn ) for different numbers of internal nodes . We also represent the number of possible expressions ( En ) for different sets of operators and leaves . 3 GENERATING DATASETS . Having defined a syntax for mathematical problems and techniques to randomly generate expressions , we are now in a position to build the datasets our models will use . In the rest of the paper , we focus on two problems of symbolic mathematics : function integration and solving ordinary differential equations ( ODE ) of the first and second order . To train our networks , we need datasets of problems and solutions . Ideally , we want to generate representative samples of the problem space , i.e . randomly generate functions to be integrated and differential equations to be solved . Unfortunately , solutions of random problems sometimes do not exist ( e.g . the integrals of f ( x ) = exp ( x2 ) or f ( x ) = log ( log ( x ) ) can not be expressed with usual functions ) , or can not be easily derived . In this section , we propose techniques to generate large training sets for integration and first and second order differential equations .

Summary: In this paper, the authors propose a method for generating two types of symbolic mathematics problems, integration and differential equations, and their solutions. The purpose of the method is to generate datasets for training transformer neural networks that solve integration and differential-equation problems. The authors note that while solving these problems is very difficult, generating solutions first and corresponding problems next automatically is feasible, and their method realizes this observation. The authors report that transformer networks trained on the synthetically generated solution-problem pairs outperform existing symbolic solvers for integration and differential equation.