Mathparse Documentation

mathparse is a library for solving mathematical equations contained in strings

Parsing strings

Methods for evaluating mathematical equations in strings.

exception mathparse.mathparse.PostfixTokenEvaluationException[source]

Exception to be raised when a language code is given that is not a part of the ISO 639-2 standard.

mathparse.mathparse.evaluate_postfix(tokens)[source]

Given a list of evaluatable tokens in postfix format, calculate a solution.

mathparse.mathparse.extract_expression(dirty_string, language)[source]

Give a string such as: “What is 4 + 4?” Return the string “4 + 4”

mathparse.mathparse.find_word_groups(string, words)[source]

Find matches for words in the format “3 thousand 6 hundred 2”. The words parameter should be the list of words to check for such as “hundred”.

mathparse.mathparse.is_binary(string)[source]

Return true if the string is a defined binary operator.

mathparse.mathparse.is_constant(string)[source]

Return true if the string is a mathematical constant.

mathparse.mathparse.is_float(string)[source]

Return true if the string is a float.

mathparse.mathparse.is_int(string)[source]

Return true if string is an integer.

mathparse.mathparse.is_symbol(string)[source]

Return true if the string is a mathematical symbol.

mathparse.mathparse.is_unary(string)[source]

Return true if the string is a defined unary mathematical operator function.

mathparse.mathparse.is_word(word, language)[source]

Return true if the word is a math word for the specified language.

mathparse.mathparse.parse(string, language=None)[source]

Return a solution to the equation in the input string.

mathparse.mathparse.replace_word_tokens(string, language)[source]

Given a string and an ISO 639-2 language code, return the string with the words replaced with an operational equivalent.

mathparse.mathparse.to_postfix(tokens)[source]

Convert a list of evaluatable tokens to postfix format.

mathparse.mathparse.tokenize(string, language=None, escape='___')[source]

Given a string, return a list of math symbol tokens

The mathwords utility module

exception mathparse.mathwords.InvalidLanguageCodeException[source]

Exception to be raised when a language code is given that is not a part of the ISO 639-2 standard.

mathparse.mathwords.word_groups_for_language(language_code)[source]

Return the math word groups for a language code. The language_code should be an ISO 639-2 language code. https://www.loc.gov/standards/iso639-2/php/code_list.php

mathparse.mathwords.words_for_language(language_code)[source]

Return the math words for a language code. The language_code should be an ISO 639-2 language code. https://www.loc.gov/standards/iso639-2/php/code_list.php

Indices and tables


A special thanks to Griffin Cox for the design of the Mathparse logo.