Predictive Algorithm for Converting Linear Strings to General Mathematical Formulae
 2 Citations
 1.5k Downloads
Abstract
Standard input methods for entering mathematical expressions on digital devices are cumbersome. Our goal is to develop an intelligent mathematical input method that allows users to input mathematical expressions using colloquial linear strings. This paper presents the evaluation of an improved predictive algorithm for converting linear strings into general mathematical formulae. The results of our evaluation show that the prediction accuracy of the top ten ranking for our method is 85.2%.
Keywords
Normal Form Prediction Accuracy Mathematical Notation Natural Language Processing Mathematical Expression1 Introduction
In recent years, computeraided assessment (CAA) systems have been used in mathematics education. However, current mathematical input methods for digital devices are cumbersome for novice learners [1, 2].
To reduce the effort required to input mathematical expressions, we propose an interactive conversion input method that uses linear strings in a colloquial style [3, 4]. In this method, a list of candidates for the desired mathematical expression is shown in a “what you see is what you get” (WYSIWYG) editor. After all the elements are interactively chosen, the desired expression is formed. We have previously shown that an interface implementing this method is 1.2 to 1.6 times faster than standard interfaces [5]. However, users must convert each element into the appropriate colloquialstyle mathematical strings in the correct order from left to right [6].
We have previously addressed this shortcoming and proposed a predictive algorithm [7, 8, 9] for converting linear strings into complete mathematical expressions using a perceptron [10]. The results of an evaluation that involved the entry of quadratic polynomials achieved a prediction accuracy of 96.2% for the topten ranking. The mean CPU time for predicting each mathematical expression was 0.44 s.
However, it is not clear whether this algorithm results in the same high level of prediction accuracy for more general mathematical formulae. In fact, the results of our previous investigation showed that the prediction accuracy for complicated mathematical formulae decreased to approximately 70% and the prediction time increased remarkably, to more than 6 min in some cases.
This study aims to address these shortcomings by extending the previous algorithm to a wider field of mathematics. We present the improved algorithm and the results of its evaluation using a dataset containing 4,000 mathematical formulae. The prediction accuracy of the topten ranking for this improved method is 85.2%.
2 Predictive Conversion
In this section, we review our previously proposed predictive conversion system [7, 8, 9]. First, we define the linear string of a mathematical expression to be input by the user. We describe an intelligent predictive conversion system of such linear strings in Sect. 2.2. In Sect. 2.3, we formulate a predictive algorithm using machine learning.
2.1 Linear String Rules
The rules for a linear mathematical string for a mathematical expression are as follows:
Definition 1
(Linear String Rules). Set the key letters (or words) corresponding to the elements of a mathematical expression linearly in the order of the colloquial (read or spoken) style, without considering twodimensional placement and delimiters.
In other words, a key letter (or word) consists of the ASCII code(s) corresponding to the initial or clipped form (such as the Open image in new window form) of the objective mathematical symbol; a single key often supports many mathematical symbols. For example, when a user wants to input \(\theta ^2\), the linear string is denoted by “t2,” where “t” represents the “theta” symbol. It is unnecessary to include the power sign (i.e., the caret letter (\(\,\hat{}\,\))). The linear string denoting \(\frac{3}{x^21}\) is “3 / x2−1,” where it is not necessary to include the denominator (which is generally the operand of an operator) in parentheses, because they are not printed.
Examples of mathematical expressions using linear string rules.
Category  Linear strings  Math formulae 

Variable  t  t or \(\theta \) 
Polynomial  x2 + 2x + 1  \(x^2\,+\,2x\,+\,1\) 
Fraction  3/4  \(\frac{3}{4}\) 
Equation  (x\(3)2=0\)  \((x3)^2=0\) 
Square root  root2  \(\sqrt{2}\) 
Trigonometric  cos2t  \(\cos ^2 \theta \) 
Logarithm  log10x  \(\log _{10}x\) 
Exponent  epx  \(e^{\pi x}\) 
Summation  sumk = 1nak  \(\sum \limits _{k=1}^{n}a_k\) 
Integral  intabf(x)dx  \(\int _a^b f(x)dx\) 
2.2 A Predictive Conversion System
First, all node elements of the mathematical expressions are classified into the nine categories listed in Table 2. Thus, a node element is characterized by (k, e, t), where k is the key letter (or word) of the mathematical symbol e that belongs to type \(t(=N, V, P, A, B_L, B_R\), C, Q, R, or T) in Table 2. For example, the number 12 is characterized as (“12”,12, N), the variable a as (“a”, a, V), and the Greek letter \(\pi \) can either be characterized as (“pi”, \({\pi , V}\)) or (“p”, \(\pi , V\)). As an example of an operator, (“/”, \(\frac{\triangle _1}{\triangle _2}, C\)) represents a fraction symbol with input character “/”, where \(\triangle _1\) and \(\triangle _2\) represent arbitrary operands.
Nine types of mathematical expressive structures
Math element type  Type codes  Examples 

Number  N  \(3,\;\; 256\) 
Variable, Symbol  V  \(a,\;\; x,\;\; \alpha ,\;\; \theta ,\;\; \pi \) 
Prefix unary operator  P  \(\sqrt{\triangle _1},\;\; \sin \triangle _1\) 
Postfix unary operator  A  \(\triangle _1',\;\; \triangle _1^{\circ }\) 
Bracket  \(B_L, B_R\)  \((\triangle _1),\;\; \{\triangle _1\},\;\; \triangle _1\) 
Infix binary operator  C  \(\triangle _1+\triangle _2,\;\; \triangle _1\times \triangle _2,\;\; \frac{\triangle _1}{\triangle _2}\) 
Prefix binary operator  Q  \(\log _{\triangle _1}\triangle _2\) 
Prefix ternary operator  R  \(\int _{\triangle _1}^{\triangle _2}\triangle _3\) 
Infix ternary operator  T  \(\triangle _1 \mathop {\rightarrow }\limits ^{\triangle _2}\triangle _3\) 
In this study, our prototype system implements a total of 509 mathematical symbols and 599 operators in node element table \(\mathcal {D}\).
The totality Y(s) of the mathematical expressions converted from s is calculated using Procedures 1–3 (cf. [4, 7]), referring to node element table \(\mathcal {D}\).
 Procedure 1. A linear string s is separated in the group of keywords defined in (4) using the parser in this system. All possible key separation vectors \((k_1,k_2,\cdots ,k_K)\) are obtained by matching every part of s with a key in \(\mathcal {D}\).$$\begin{aligned} s=k_1\uplus k_2\uplus \cdots k_K \ \hbox {where} \ (k_i,v_i,t_i)\in \mathcal {D}, i=1,...,K \end{aligned}$$(4)

Procedure 2. Predictive expressive structures are fixed by analyzing all the key separation vectors of s and comparing the nine types of structures in Table 2.

Procedure 3. From the fixed structures corresponding to the operating relations between the nodes, we obtain Y(s) by applying all possible combinations of mathematical elements belonging to each keyword in \(\mathcal {D}\).
2.3 Predictive Algorithm

Step 1. Initialization \(\varvec{\theta }=\varvec{0}\), \(i=1\)
 Step 2. Decision regarding a candidate.$$\begin{aligned} y_p \; \; \hbox {s.t.} \; h_{\theta } \left( \varvec{X}(y_p) \right) =\max \{h_{\theta } \left( \varvec{X}(y) \right)  y\in Y(s_i)\} \end{aligned}$$(6)

Step 3. Training parameter.
if(\(y_p\ne y_i\)) {}$$\begin{aligned} \begin{array}{rcl} \mathrm {if }(\theta _{f}<S_{\max })\{\theta _{f}:=\theta _{f}+2 &{} \hbox { for } &{} \{f \le F_{total}  x_f(y_i)>0 \}\} \\ \theta _{\bar{f}}:=\theta _{\bar{f}}1 &{} \hbox { for } &{} \{\bar{f}\le F_{total}  x_{\bar{f}}(y_p)>0 \} \\ \end{array} \end{aligned}$$(7) 
Step 4. if(\(i < m\)){ \(i=i+1\); repeat from Step 2}
else { Output \(\varvec{\theta }\) and end}
This learning algorithm is simple and is similar to a structured perceptron used for natural language processing (NLP) [10]. However, in our previous study [7], we revised the increase weight from one to two in (7) to avoid negative score learning. When two different candidates belonging to the same key appear in the training dataset, e.g., the pair a and \(\alpha \), their scores change into a positive value from a negative value or vice versa; even if a candidate with a negative score has occurred many times, it has lower priority than one with a score of zero. Here, \(S_{\max }\) in (7) is a suitable upper bound for any mathematical element score, preventing the score parameter from continuing to increase as the algorithm runs.
3 Main Algorithm
In previous investigations [7, 8, 9] of the learning algorithm in Sect. 2.3, limiting the entered expressions to quadratic polynomials resulted in a prediction accuracy of 96.2% for the topten ranking. The mean CPU time for predicting each mathematical expression was 0.44 s.
However, the algorithm in Sect. 2.3 did not provide the same high performance given more general mathematical formulae. In fact, the results of our investigation using a dataset of 4000 math formulae from broader fields of mathematics (cf. Sect. 4.1) showed that prediction accuracy decreased to approximately 70% and prediction time increased considerably; for a complicated mathematical formula, prediction took more than 6 min.
As the reason for the decrease in prediction accuracy and increase in prediction time, we found the following three challenges in predicting general mathematical expressions.
 1.
Scores can increase based on the number of elements, instead of their priority.
 2.
If Y(s) includes the same mathematical expressions, but has different internal tree structures, machine learning does not work well.
 3.
The number of complicated mathematical expressions, which lead to long prediction times, increases when general mathematics fields are considered.
To overcome these shortcomings, we have revised the weight calculations of the score in Sect. 3.1, introduce a normal form for mathematical tree expressions in Sect. 3.2, and improved the search routine, breaking it off after ten seconds that is described in Sect. 3.3.
3.1 Balancing Scores with the Key Character Length
An expression’ score can increase based on the number of its elements, instead of their priority. For example, the score of \(sinx(=s\otimes i\otimes n\otimes x)\) is higher than the score of \(\sin x\) because sinx includes 7 nodes and 6 edges, compared to the 3 elements in \(\sin x\). (Here, in this paper, the symbol \(\otimes \) is used for recollection of an invisible multiplication that is also treated as an operator or node element.)
Generally, when Y(s) from linear string s with character length n is obtained by Procedures 1–3, s can be decomposed into a key separation vector with n elements, per (4), because the character keys of almost all ASCII codes are registered in our system’s key dictionary \(\mathcal {D}\).
3.2 Unique Normal Form for Mathematical Expressions
To overcome this shortcoming, we define a normal form for mathematical notation.
Definition 2
(Normal form for mathematical notation). A normal form for a mathematical notation ensures that all trees based on a mathematical expression with the same notation are recorded uniquely.
Normal form was discussed using “term rewriting system” by Knuth and Bendix [11] in 1967 and a unique normal form in computer algebra systems was discussed in [12], in particular, that there exists a unique normal form for polynomial systems. We proposed a normal form for mathematical notation to use in a math input interface in [4], in which we concretely define the normal form for mathematical notation to implement into our prediction system for general mathematical formulae.
The definition equation for the normal form of mathematical formulae using BNF
For example, the tree structure on the right in Fig. 1, which is formed as \(\langle \hbox {Factor} \rangle \otimes \langle \hbox {Term} \rangle \), is excluded because such a form is not included in the definition equation for \(\langle \hbox {Term} \rangle \) in Table 3.
Therefore, we treat only the normal form defined by Table 3 for mathematical tree expressions in this study. We converted the 4000 math formulae in the training dataset to the normal form and use only the normal form to predict the Nbest candidates from a linear string using the algorithm proposed in this section.
3.3 Complexity of Candidate Math Expressions and Calculation Time
Generally, the number of elements in Y(s), denoted by n(Y(s)), increases rapidly corresponding to the increase in the length of s. For example, because the key character “a” corresponds to seven symbols (\(Y(``a{\text {''}})=\{a, \alpha , \mathrm {a}, \mathbf{a}, {\varvec{a}}, \mathsf {a}, \aleph \}\)) and the invisible multiplication between a and b corresponds to \(Y(``ab{\text {''}})=\{ab, a^b, a_b, {}^ab, {}_ab\}\), then \(n(Y({``abc{\text {''}}}))=7^3\times 5^2=8575\). However, for a mathematical input interface, it is sufficient to calculate the Nbest high score candidates in Y(s) as shown in (1).
 1.
In Procedure 1, all the key separation vectors \((k_1,k_2,\cdots ,k_K)\) of s are sorted in ascending order of K in (4), i.e., in order starting from higher probability.
 2.
In Procedure 2, we set an upper limit \(T=10\) s for breaking down all possible calculations of the predictive expressive structures.
 3.
In Procedure 3, to obtain the Nbest candidates in Y(s), we apply only the Nbest mathematical elements for operand expressions related to an operator, instead of all possible combinations.
4 Experimental Evaluation
In this section, we experimentally investigate the prediction accuracy of the algorithm described in the previous section. Then, we present the results of this evaluation in Sect. 4.2 and discuss the results of this study in Sect. 4.3.
4.1 Method
We examined prediction accuracy using a dataset of 4000 mathematical formulae \(\mathcal {E}=\{(s_i,y_i)i=0,\cdots ,3999\}\) from a fivevolume mathematics textbook [13], organized into the following categories: algebra, geometry, vector algebra, sets/logic, numbers, probability/statistics, trigonometry, exponents/logarithms, sequences, limits, and calculus, which are studied in the tenth through twelfth grades in Japan. Dataset \(\mathcal {E}\) was generated manually with our previous system [14] in the order of appearance in the textbook by choosing individual expressions y with the corresponding linear string s, the length of which is less than 16.
In the experimental evaluation, we measured the proportion of correct predictions for 500 test datasets after learning the parameters using the predictive algorithm described in Sect. 3 on a training dataset consisting of 3500 formulae by 8fold crossvalidation.
4.2 Results
The machine learning results for our predictive algorithm are given in Table 4 for various training set sizes. Figure 2 illustrates this result and shows that 3500 training data are sufficient for performing our machine learning algorithm.
The accuracy of “Best 1” with our predictive algorithm was approximately 51.5% after being trained 3500 times and that of “Best 3” was 72.4%. However, for its topten ranking, this algorithm achieved an accuracy of 85.2%.
The mean CPU time for predicting each mathematical expression with corresponding linear string of length less than 16 was 2.85 s (\(SD=0.16\)).
Prediction accuracy using our predictive algorithm (%)
Training no.  Best 1  Best 3  Best 10 

0  16.0 (0.7)  20.2 (0.9)  23.8 (1.5) 
500  36.4 (2.9)  49.9 (5.2)  61.3 (7.9) 
1000  45.3 (2.6)  63.6 (1.8)  77.2 (1.9) 
1500  47.5 (4.2)  67.4 (2.6)  80.7 (1.6) 
2000  49.9 (3.3)  69.7 (2.2)  82.7 (1.6) 
2500  51.6 (4.5)  71.2 (3.6)  84.0 (1.7) 
3000  50.9 (3.9)  71.5 (3.3)  84.0 (1.7) 
3500  51.5 (3.1)  72.4 (2.2)  85.2 (1.8) 
4.3 Discussion
5 Related Works
In this section, we describe related works on NLP, along with other predictive inputs for mathematical formulae that use an Ngram model.
Inputword prediction has been studied in NLP since the 1980s, often to predict input characters for a word unit [15]. Structured perceptrons have been used in NLP to input Japanese characters since the 1990s. As explained in Sect. 2, our predictive algorithm uses a structured perceptron; however, mathematical formulae have tree structures, rather than the sentential chain structures of natural language. Indeed, none of the aforementioned methods consider sentence structures, although our method considers the tree structure of mathematical formulae.
Structurebased user interfaces for inputting mathematical formulae are popular. They enable users to format a desired mathematical formula on a PC in a WYSIWYG manner by selecting an icon corresponding to the structure of the expression. Users do so using a GUI template, e.g., a fraction bar or an exponent form, into which the mathematical elements can be entered. Hijikata et al. improved the input efficiency of mathematical formulae by proposing an algorithm for predicting mathematical elements using an Ngram model [16]. However, their proposal is still structurebased in the sense that users must understand the entire structure of a desired mathematical formula before selecting the corresponding icons.
In contrast, our predictive conversion method predicts mathematical structures from a linear string in a colloquial style, separating it from structurebased input methods.
6 Conclusion and Future Work
In this study, we proposed a predictive algorithm for linear string conversion to the Nbest candidate mathematical formulae, with an accuracy of 85.2% for the topten ranking, by improving upon a previously proposed structured perceptron algorithm to apply to general categories of mathematics. The mean CPU time for predicting each mathematical expression with a corresponding linear string of length less than 16 (obtained from a fivevolume mathematics textbook) was 2.84 s.
The most important avenues for future research are to reduce prediction time and to develop an intelligent mathematical input interface by implementing our proposed predictive algorithm.
This work was supported by JSPS KAKENHI Grant Number 26330413.
References
 1.Pollanen, M., Wisniewski, T., Yu, X.: Xpress: a novice interface for the realtime communication of mathematical expressions. In: Proceedings of the Workshop on Mathematical User Interfaces (2007)Google Scholar
 2.Sangwin, C.: Computer aided assessment of mathematics using STACK. In: Cho, S.J. (ed.) Selected Regular Lectures from the 12th International Congress on Mathematical Education, pp. 695–713. Springer, Cham (2015). doi: 10.1007/9783319171876_39 CrossRefGoogle Scholar
 3.Fukui, T.: An intelligent method of interactive user interface for digitalized mathematical expressions. RIMS Kokyuroku 1780, 160–171 (2012). (in Japanese)Google Scholar
 4.Fukui, T.: The performance of interactive user interface for digitalized mathematical expressions using an intelligent formatting from linear strings. RIMS Kokyuroku 1785, 32–44 (2012). (in Japanese)Google Scholar
 5.Shirai, S., Nakamura, Y., Fukui, T.: An interactive math input method for computer aided assessment systems in mathematics. IPSJ Trans. Comput. Educ. 1(3), 11–21 (2015). (in Japanese)Google Scholar
 6.Shirai, S., Fukui, T.: Improvement in the input of mathematical formulae into STACK using interactive methodology. Comput. Educ. 37, 85–90 (2014). (in Japanese)Google Scholar
 7.Fukui, T.: Prediction for converting linear strings to mathematical formulae using machine learning. In: Proceedings of ARG WI2, vol. 6, pp. 67–72 (2015). (in Japanese)Google Scholar
 8.Fukui, T., Shirai, S.: Predictive algorithm from linear string to mathematical formulae for math input method. In: Proceedings of the 21st Conference on Applications of Computer Algebra, pp. 17–22 (2015)Google Scholar
 9.Shirai, S., Fukui, T.: Evaluation of a predictive algorithm for converting linear strings to mathematical formulae for an input method. In: Kotsireas, I.S., Rump, S.M., Yap, C.K. (eds.) MACIS 2015. LNCS, vol. 9582, pp. 421–425. Springer, Cham (2016). doi: 10.1007/9783319328591_36 CrossRefGoogle Scholar
 10.Manning, C.D., Scheutze, H.: Foundations of Statistical Natural Language Processing. The MIT Press, London (2012)Google Scholar
 11.Knuth, D.E., Bendix, P.B.: Simple word problems in universal algebra. In: Proceedings of Oxford, vol. 67, pp. 263–298 (1967)Google Scholar
 12.Sasaki, T., Motoyoshi, F., Watanabe, S.: Computer Algebra System, vol. 36, Shoukoudo (1986). (in Japanese)Google Scholar
 13.Matano, H., et al.: Vols. I301, A301, II301, B301, and III301 of Mathematics, Japan. Tokyo Shoseki (2014). (in Japanese)Google Scholar
 14.Shirai, S., Fukui, T.: MathTOUCH: mathematical input interface for eassessment systems. MSOR Connections 15(2), 70–75 (2016)Google Scholar
 15.GarayVitoria, N., Abascal, J.: Text prediction systems: a survey. Univers. Access Inf. Soc. 4(3), 188–203 (2006)CrossRefGoogle Scholar
 16.Hijikata, Y., Horie, K., Nishida, S.: Predictive input interface of mathematical formulas. In: Kotzé, P., Marsden, G., Lindgaard, G., Wesson, J., Winckler, M. (eds.) INTERACT 2013. LNCS, vol. 8117, pp. 383–400. Springer, Heidelberg (2013). doi: 10.1007/9783642404832_27 CrossRefGoogle Scholar