MathRuler
MathRuler is a powerful and versatile Python library, currently at version 0.1.0, designed to simplify and enhance mathematical calculations. It aims to provide tools for handling equations, units, and general computations, leveraging symbolic and numerical backends. As an early-stage library, its API is subject to iterative improvements with a rapid release cadence.
Common errors
-
ModuleNotFoundError: No module named 'mathruler'
cause The 'mathruler' package has not been installed in your current Python environment.fixRun `pip install mathruler` to install the library. -
AttributeError: 'MathRuler' object has no attribute 'xyz_method'
cause You are attempting to call a method that either does not exist, is misspelled, or has been renamed/removed in the version of MathRuler you are using.fixCheck the official documentation or the `mathruler` GitHub repository's README for the correct method names and their usage, especially when migrating between versions. For 0.1.0, the core methods are `equation`, `evaluate`, and `set_variable`. -
ValueError: Invalid equation or expression string provided.
cause The string passed to methods like `equation()` or `evaluate()` could not be parsed as a valid mathematical expression or equation by MathRuler's underlying parsers (e.g., SymPy).fixEnsure your equation or expression string is well-formed, uses standard mathematical operators, and adheres to any specific syntax requirements outlined in MathRuler's documentation. Avoid ambiguity, ensure balanced parentheses, and correct any typos in variable names or operators.
Warnings
- breaking As a 0.x.x version, the API of MathRuler is not yet stable and is subject to significant changes, including method signatures, class names, and module structure, without adhering to strict semantic versioning.
- gotcha While MathRuler aims to handle equations, parsing complex or ambiguous mathematical expressions can be challenging. Input strings must often adhere to a specific syntax or standard for correct interpretation.
- gotcha Mathematical calculations, especially with floating-point numbers, can introduce precision errors. MathRuler relies on underlying libraries like SymPy and NumPy, which also handle floats with standard IEEE 754 precision.
Install
-
pip install mathruler
Imports
- MathRuler
from mathruler import MathRuler
Quickstart
from mathruler import MathRuler
# Initialize the MathRuler
ruler = MathRuler()
# Solve a simple algebraic equation
result_equation = ruler.equation("2x + 5 = 10")
print(f"Equation result: {result_equation.solve_for('x')}")
# Perform a calculation with units (if supported in future versions, currently basic)
# Note: Unit support is an evolving feature and may require specific syntax.
# For 0.1.0, focus on basic equations.
# Example: Evaluate an expression
result_eval = ruler.evaluate("5 * (3 + 2)")
print(f"Evaluation result: {result_eval}")
# Define and use a variable
ruler.set_variable('y', 15)
result_var = ruler.evaluate("y / 3")
print(f"Variable calculation result: {result_var}")