API reference

The root package exports metadata. Feature APIs are organized by math branch or shared utility area.

Metadata

  • edumath.__version__

Solvers

edumath.solvers contains reusable symbolic solving helpers for lessons and student-facing apps.

Equation solving

Use solve_equation_steps() to solve a single-variable SymPy equation and return a structured EquationSolution. The answer and transformations are computed with SymPy/edumath; no network access or API key is required. If the starting point is user text, parse it first with edumath.core.parse_equation().

from edumath.core import parse_equation
from edumath.solvers import solve_equation_steps

equation = parse_equation("2(x - 3) + 4 = 10")
solution = solve_equation_steps(equation)
solution.answer
'x = 6'

The same object can be rendered as text or Markdown for lessons:

print(solution.render_text())
Answer: x = 6

Method: linear equation

Steps:

1. Original equation:
Eq(2*(x - 1*3) + 4, 10)

2. Expand both sides:
Eq(2*x - 2, 10)

3. Move everything to one side:
Eq(2*x - 12, 0)
This writes the equation in the form ax + b = 0.

4. Move the constant term:
Eq(2*x, 12)

5. Divide by the coefficient of the variable:
Eq(x, 6)

Check:

x = 6: valid

Parsing user text

String parsing lives outside the solver layer. Use parse_expression() for expressions and parse_equation() for equations. The parser supports classroom input such as implicit multiplication (2x) and caret powers (x^2).

from edumath.core import parse_equation, parse_expression

parse_expression("2x^2 + 3x")
parse_equation("2y + 3 = 7")

\(\displaystyle 2 y + 3 = 7\)

Optional AI explanations

If an OpenAI API key is configured, solve_equation_steps() can add an optional tutor explanation after the symbolic solution has already been computed and checked. Without a configured key, the function simply returns the solved result with no AI explanation.

from edumath.core import parse_equation
from edumath.settings import configure
from edumath.solvers import solve_equation_steps

configure(openai_api_key="YOUR_OPENAI_API_KEY")
equation = parse_equation("2(x - 3) + 4 = 10")
solution = solve_equation_steps(equation, explain=True)
print(solution.explanation)

The OpenAI model can be changed with configure(openai_model=...), and tests or applications can provide a custom explanation_client= that follows the EquationExplanationClient protocol.

Main objects

  • EquationStep: one algebraic transformation.
  • EquationSolutionCheck: verification result for a candidate solution.
  • EquationSolution: final answer, solution set, steps, checks, and optional tutor explanation.
  • OpenAIEquationExplanationClient: small standard-library client for optional explanations through the OpenAI Responses API.