DEV Community

Yash Matrani
Yash Matrani

Posted on

How I built a symbolic log inequality solver as a 16-year-old

Logarithmic inequalities are annoying.

Not because they're hard — but because most solvers skip the domain constraints. They give you the answer, you trust it, and then you realize the base was invalid the whole time.

So I built my own. In Python. Using SymPy.

I'm 16, and this is my first serious symbolic math project.

The Problem

Variable-base log inequalities like:
log(x-1)(x+1) < 2

Here the base itself is (x-1), which means:

  • Base must be > 0
  • Base must ≠ 1
  • Argument must be > 0
  • Then solve the inequality

Most online solvers:

  • Skip domain constraints
  • Assume base > 1 only
  • Miss the 0 < base < 1 case
  • Return wrong or incomplete answers

I got tired of checking manually. So I wrote a script that does it properly.

The Approach

Using SymPy's solve_univariate_inequality, the script:

  1. Extracts free symbols from the base
  2. Splits into cases: base > 1 and 0 < base < 1
  3. Applies domain constraints (base > 0, base ≠ 1)
  4. Solves each case symbolically
  5. Returns the union of solution sets

Here's the core logic:


python
import sympy as sy

x = sy.Symbol('x')

def base_A(base):
    if x in base.free_symbols:
        return sy.solve_univariate_inequality(
            sy.And(base > 0, base != 1),
            x,
            relational=False
        )
    else:
        return base
The rest handles case splitting, domain checks, and union of intervals.

What I Learned
1. Symbolic math is different from numerical.
math.sqrt(2) gives 1.414.... SymPy gives sqrt(2) — exact.

2. Domain constraints matter more than the equation.
Most people solve the inequality, forget the domain, and get it wrong.

3. Edge cases break everything.
Base = 1? Base = 0? Base negative? Each one is a different failure mode.

4. SymPy is underrated.
Python devs use it for scripts. It's built for math.

What's Next
Add support for nested logarithms

Build a CLI interface with argument parsing

Maybe a web version with Streamlit

Links
Source code: Gumroad

GitHub: github.com/yashmatrani-cpu/My-Projects

X: @Developervxku

I'm still learning. Feedback welcome — especially from anyone who's worked with SymPy or symbolic solvers.

Thanks for reading.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)