Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Seaus-tech/Calculator-App/llms.txt

Use this file to discover all available pages before exploring further.

Calculator App can solve single-variable equations entered directly at the terminal prompt. The solve_equation() function in solver.py tries a fast algebraic method for equations of the form a*x + b = c, then falls back to a brute-force integer search over the range -100,000 to 100,000 for everything else. Only integer solutions are returned by brute-force — non-integer roots and solutions outside that range will not be found.

How Equations Are Detected

In core.py, an input line is treated as an equation when it contains an = sign and at least one letter (the unknown variable):
if '=' in line and re.search(r'[a-zA-Z]', line):
    result = solve_equation(line)
    print(result)
This check runs before variable assignment and normal expression evaluation, so equations take priority.

Implicit Multiplication

Before solving, solver.py rewrites common shorthand into valid Python:
left = re.sub(r'(\d)([a-zA-Z])', r'\1*\2', left)   # 2x  → 2*x
left = re.sub(r'([a-zA-Z])\^(\d+)', r'\1**\2', left) # x^2 → x**2
This means you can write equations the way they appear in textbooks.

Solving Strategies

For expressions of the form a*x + b = c (no **2 term and a * operator present on the left side), the solver uses eval-based coefficient extraction:
  1. Substitute var = 0 into the left side to find the constant term b.
  2. Substitute var = 1 to find a + b; subtract b to get the coefficient a.
  3. Evaluate the right side to get c.
  4. Compute the solution as (c - b) / a.
b       = eval(left.replace(var, '0'))
a_plus_b = eval(left.replace(var, '1'))
a       = a_plus_b - b
c       = eval(right)
solution = (c - b) / a
This path is taken only when the left side contains a * operator but no **2. Equations like x+4=10 (no explicit *) fall through to the brute-force search instead.

Examples

> 2x+4=10
x = 3

> 6+x=7
x = 1

> 5x+101010=10
x = -20200

> x^2-4=0
x = -2
The brute-force search covers integers from -100,000 to 100,000 and returns the first solution found (starting from the most negative). For x^2 - 4 = 0, the solver finds x = -2 before x = 2. Non-integer solutions and values outside this range will result in "Could not solve equation".

Equation Examples by Type

Linear: ax + b = c

2x+4=10x = 3
6+x=7x = 1

Large coefficients

5x+101010=10x = -20200

Quadratic (brute-force)

x^2-4=0x = -2

No solution

Out-of-range or non-integer → Could not solve equation
Only one variable per equation is supported. The solver reads the first letter found on the left-hand side and uses it throughout. Equations with multiple unknowns (e.g., x + y = 5) will attempt to solve for x only, treating y as an unknown name which will cause an error.

Build docs developers (and LLMs) love