Handwritten Mathematical Expression Solver Using CNN
Handwritten Mathematical Expression Solver Using CNN
https://doi.org/10.22214/ijraset.2022.46803
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IX Sep 2022- Available at www.ijraset.com
Abstract: Mathematics is the universal language. It is the core of all the scientific discoveries and is used extensively in all
possible fields. Hence, there arises the need for fast computation and instant results. This has led to the development of various
technologies and machines which would ease the strain on humans and also reduce the error and delays caused by them. Our
project caters to these needs by reducing the effort on user side. We want to make the experience of experimenting with
equations as simple as possible. The application is capable of performing fast calculations on human handwritten mathematical
expressions. Basic calculations like arithmetic and trigonometric functions can be done along with simultaneous equations. The
expression is extracted from the image and each character, symbol and number is recognised and then the entire expression is
further being solved displaying all possible solutions. The application developed is simple and user-friendly tool that can
leverage the power of existing powerful math packages.
Keywords: Handwritten Mathematical Expression, Character recognition, Convolutional Neural Network (CNN), Symbol
recognition, Image processing.
I. INTRODUCTION
Discovery, that is the word we associate with finding something new. The reason for this is that this universe already has everything
it requires, it's just in a form that mankind has yet to comprehend or discover. Mathematics is the simplest way to understand the
universe's transformations and intricacies. The language of mathematics which can describe the nature of the universe to the shapes
and structure and pattern of almost all objects that we perceive through our senses. Take any aspect and you will find a
mathematical description for it. For years mankind has tried to decipher this mathematical code by numerous methods and formulae
which were worked upon for years and years. And today we have reduced the time gap to get answers for tedious methods and
procedures with the help of new technologies and gadgets. The most general example would be a calculator which is used instead of
manually working out mathematical methods thus reducing the percentage of human error associated with it. But using the
calculator to solve the humongous equations and find answers for them is a tedious task since it requires the equations to be entered
accurately. Therefore, another need for innovation came to life and thus technology which could scan documents and interpret what
is written and further find the answer for it to ease the daily humdrum. This is where machine learning and neural networks come
into the picture, where a model is built in such a way that it can think and solve the problems in the same way a human brain would
do but swiftly and efficiently. Mathematical equations form an integral part of most research work, so researchers use such
mathematical tools to save time and boost efficiency keeping in mind the complexities and syntax of the chosen tool. If the syntax
rules are not followed properly, one might not get the desired output. Another concern is the task of entering all the equations and
expressions properly leaving no gap for human error since the system will be performing the calculations based on the input given.
This requires a lot of time and human intervention and also good knowledge of the tool being used. A convenient solution to this
can be to build a user-friendly tool that would capture the image of a mathematical equation, recognise the equation embedded in it
and present the user with the required solution. This is precisely the tool we have developed and discussed throughout this paper.
Computers can be made to think and act like a human would, by forming a neural network and also retaining their computational
superiority. In our project, we have attempted to simplify the interaction between humans and computers pertaining to the
processing and solving mathematical equations. We have focused on building a model which is simple to understand, by not
restricting the user with various syntax rules and complexities. In today’s world there are many tools, simulators which are
available for mathematical purposes. However, more the features, more the awareness about the particular tool is required from the
user. To shorten this gap of excessive awareness on the user’s side, the machine could be trained to understand the user’s needs
more accurately with very less effort from the concerned user. This being the ideology we have tried to build a machine learning
model which will take the image input of the mathematical expression written by the user and identify the input expression and
provide the answer with accuracy achieved while building the model.
©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 1205
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IX Sep 2022- Available at www.ijraset.com
©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 1206
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IX Sep 2022- Available at www.ijraset.com
IV. IMPLEMENTATION
The model created is a sequential model. The project implementation is divided into two phases, Handwritten Expression
Recognition Phase and Expression Evaluation Phase.
A. Dataset
The dataset was used from Kaggle and it consisted images of handwritten digits from 0 to 9 along with various math symbols and
alphabets. It consists of symbols from the Greek alphabet, English alphanumeric characters, math and set operators, basic predefined
math functions (such as sin, cos etc.) and math symbols (such as sum, sqrt, delta etc.). Every specific element has more than 100
images for the model to train on and predict. Dataset is fairly diverse since it contains handwritten samples of different individuals
which helps the CNN model to train on various parameters. Samples without any variation won’t be helpful since they usually lead
to overfitting. In this project we have used limited number of symbols and alphabets rather than considering all the 26 alphabets for
computation purposes. The dataset could be expanded even further to perform even more complex calculations.
B. Pre-processing
1) Binarization: The conversion of an input image into a bi-level target image is binarization. The term bi indicates two which
means that image pixels are divided into two groups, black and white pixels. The primary goal of image binarization is to sort
an image into foreground and background text. The given input image may consist of noise or other unwanted information
which can affect the processing of the expression. Hence, the conversion of the input image into binarized image is necessary.
2) Contour based Segmentation: Contours are defined as the line connecting all the points along an image's borders that have the
same intensity. Contours are useful for shape analysis, determining the size of an object of interest, and object detection. The
findContours() function in OpenCV aids in the extraction of contours from images. It is most effective with binary images.
These contours segregate the handwritten characters, symbols and numbers based on their intensities in binarized image which
are than further used for recognition.
©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 1207
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IX Sep 2022- Available at www.ijraset.com
The MaxPooling layer is used to reduce the dimensionality of the vector by replacing each cell in the array with the max value of
the sub matrix part of the required size around the cell in consideration. Dropout layer is included to avoid overfitting of the model.
It randomly sets the outgoing edges of neurons that make up hidden layers to 0 at each update. While the data is passing and
switching from one format to another, the weight ordering may change. This may affect the output and hence the Flatten layer is
used. It adds an extra channel to the batch size. It doesn’t much affect the output but is used as a form of prevention. The Dense
layer is the main part of the model where the neural networks are formed and which result in the correct prediction. Three layers of
Dense are applied to the model for better accuracy with activation=’ReLU’. The model works like a brain to analyse and classify
from the data given in training and based on that, predict into which class the given component can be classified.
©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 1208
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IX Sep 2022- Available at www.ijraset.com
D. Expression Evaluation
After the recognition of the characters and symbols, the expression is passed to the function to solve and display the solution. For all
the mathematical processing python library called SymPy is used [21]. SymPy depends on mpath which is a python library for real
and complex floating-point arithmetic with arbitrary precision. The final answer after calculation is displayed on the GUI based
page.
V. RESULTS
©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 1209
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.538
Volume 10 Issue IX Sep 2022- Available at www.ijraset.com
VII. ACKNOWLEDGMENT
The authors would like to express their gratitude to Kaggle for making the handwritten math symbols’ dataset available for public
use. We also sincerely thank the skilful developers of Keras, Tensorflow and Python for their ceaseless efforts in maintaining the
libraries.
REFERENCES
[1] Xue-Dong Tian, Hai-Yan Li, Xin-Fu Li, & Li-Ping Zhang. (n.d.). Research on Symbol Recognition for Mathematical Expressions. First International
Conference on Innovative Computing, Information and Control - Volume I (ICICIC’06). doi:10.1109/icicic.2006.506
[2] Okamoto M. Recognition of mathematical expressions by using the layout structure of symbols. InProc. 1st Int. Conf. Document Analysis and Recognition,
1991 1991 (pp. 242-250).
[3] Faure and Z. Wang, “Automatic perception of the structure of handwritten mathematical expressions,” Computer Processing of Handwriting, pp. 337 –361,
1990Faure C, Wang ZX. Automatic perception of the structure of handwritten mathematical expressions. In- Computer processing of handwriting 1990 (pp.
337-361).
[4] M. Okamoto and A. Miyazawa. An experimental implementation of a document recognition system for papers containing mathematical expressions. In H. S.
Baird, H. Bunke, and K. Yamamoto, editors, Structured Document Image Analysis, pages 3653. Springer- Verlag,Berlin, 1992.
[5] Ha J, Haralick RM, Phillips IT. Understanding mathematical expressions from document images. InProceedings of 3rd International Conference on Document
Analysis and Recognition 1995 Aug 14 (Vol. 2, pp. 956-959). IEEE.
[6] Chou PA. Recognition of equations using a two-dimensional stochastic context-free gram- mar. InVisual Communications and Image Processing IV 1989
Nov 1 (Vol. 1199, pp. 852- 865). International Society for Optics and Photonics.
[7] Yasutomo Nakayama. 1989. Mathematical formula editor for CAI. In Proceedings of the SIGCHI Conference on Human Factors in Computing Systems
(CHI ’89). Association for Computing Machinery, New York, NY, USA, 387–392. DOI:https://doi.org/10.1145/67449.67523
[8] A. Belaid and J. -P. Haton, ”A Syntactic Approach for Handwritten Mathematical Formula Recognition,” in IEEE Transactions on Pattern Analysis and
Machine Intelligence, vol. PAMI-6, no. 1, pp. 105-111, Jan. 1984, doi: 10.1109/TPAMI.1984.4767483.
[9] Chan KF, Yeung DY. Recognizing on-line handwritten alphanumeric characters through flexible structural matching. Pattern recognition. 1999 Jul
1;32(7):1099-114.
[10] L. H. Chen and P. Y. Yin. A system for on-line recognition of handwritten mathematical expressions. Computer Processing of Chinese and Oriental
Languages, 6(1):1939, June 1992.
[11] Fateman RJ, Tokuyasu T, Berman BP, Mitchell N. Optical character recognition and parsing of typeset mathematics1. Journal of Visual Communication and
Image Representation. 1996 Mar 1;7(1):2-15.
[12] Ha J, Haralick RM, Phillips IT. Understanding mathematical expressions from document images. InProceedings of 3rd International Conference on Document
Analysis and Recognition 1995 Aug 14 (Vol. 2, pp. 956-959). IEEE.
[13] Faure C, Wang ZX. Automatic perception of the structure of handwritten mathematical expressions. In Computer processing of handwriting 1990 (pp. 337-
361).
[14] Pfeiffer JJ. Parsing graphs representing two dimensional figures. InProceedings IEEE Workshop on Visual Languages 1992 Sep 15 (pp. 200-206). IEEE.
[15] Lee HJ, Wang JS. Design of a mathematical expression recognition system. InProceedings of 3rd International Conference on Document analysis and
Recognition 1995 Aug 14 (Vol. 2, pp. 1084-1087). IEEE
[16] Chan KF, Yeung DY. Mathematical expression recognition: a survey. International Journal on Document Analysis and Recognition. 2000 Aug 1;3(1):3-15.
[17] Miller EG, Viola PA. Ambiguity and constraint in mathematical expression recognition. InAAAI/IAAI 1998 Jul 1 (pp. 784-791).
[18] Zanibbi R, Blostein D. Recognition and retrieval of mathematical expressions. International Journal on Document Analysis and Recognition (IJDAR). 2012
Dec 1;15(4):331-57.
[19] L. D’souza and M. Mascarenhas, ”Offline Handwritten Mathematical Expression Recognition using Convolutional Neural Network,” 2018 International
Conference on Information , Communication, Engineering and Technology (ICICET), 2018, pp. 1-3, doi: 10.1109/ICI- CET.2018.8533789.
[20] Sagar Shinde, Dr. R. B. Waghulade, Dr. D. S. Bormane,“A new neural network based algorithm for identifying handwritten mathematical equations ”,
International Conference on Trends in Electronics and Informatics, 2017.
[21] SymPy Python Library https://www.sympy.org/en/index.html
©IJRASET: All Rights are Reserved | SJ Impact Factor 7.538 | ISRA Journal Impact Factor 7.894 | 1210