DEV Community

Cover image for Building Conjecture Forge: An Open-Source AI-Assisted Mathematical Discovery Engine
Samitha Tharanga Wijesinghe
Samitha Tharanga Wijesinghe

Posted on

Building Conjecture Forge: An Open-Source AI-Assisted Mathematical Discovery Engine

Summer Bug Smash: Clear the Lineup 🐛🛹

This is a submission for DEV's Summer Bug Smash: Clear the Lineup powered by Sentry.

Project Overview

Conjecture Forge is an open-source, AI-Assisted Mathematical Discovery & Symbolic Computation Engine. Built using Python, FastAPI, SymPy, and React, it automatically parses mathematical expressions, computes precise derivatives, and generates intelligent mathematical hypotheses (conjectures) through a sleek dark-mode Glassmorphism UI.

Bug Fix or Performance Improvement

When users inputted malformed, highly complex, or unstructured mathematical expressions into the web engine, the backend parsing pipeline faced critical bottlenecks:

  1. Uncaught Expression Exceptions: Invalid syntax directly crashed the FastAPI worker threads due to unhandled exceptions thrown by SymPy's parsing engine.
  2. Performance Degradation: Heavy symbolic computations and algebraic simplifications lacked structured error boundaries and safe validation schemas, causing latency spikes in the calculation loop.

Code

Here is the core code implementation for our updated validation and error-resilient computation pipeline:

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import sympy as sp

app = FastAPI()

class MathRequest(BaseModel):
    expression: str

@app.post("/api/compute")
async def compute_conjecture(data: MathRequest):
    try:
        # Safely parse the expression using SymPy with strict boundary handling
        expr = sp.sympify(data.expression)
        derivative = sp.diff(expr)
        return {
            "original": str(expr),
            "derivative": str(derivative),
            "status": "success"
        }
    except Exception as e:
        # Cleanly intercept parsing failures to prevent backend crashes
        raise HTTPException(status_code=400, detail=f"Invalid mathematical expression: {str(e)}")
Enter fullscreen mode Exit fullscreen mode

My Improvements

To eliminate server crashes and ensure ultra-low latency, we implemented:

  • Pydantic Validation Guardrails:
    Incoming expression payloads are strictly validated before hitting the heavy mathematical core.

  • Resilient Error-Catching Middleware:
    Replaced generic server faults with descriptive, client-safe HTTP exceptions.

  • Optimized Frontend Integration:
    Refactored the React frontend to handle asynchronous streaming and error responses smoothly, keeping the Glassmorphism UI fully responsive.

Best Use of Sentry

To monitor production stability and track complex runtime exceptions in our Python/FastAPI backend, we integrated Sentry Error Monitoring:

  • Real-time Exception Tracking: Configured Sentry SDK to capture unhandled expression-parsing anomalies and performance bottlenecks instantly.

  • Distributed Tracing: Monitored the request lifecycle from the React frontend down to the FastAPI/SymPy execution layer, ensuring zero latency degradation during heavy mathematical transformations.

Best Use of Google AI

Conjecture Forge heavily relies on symbolic mathematics and automated pattern parsing, which acts as the foundational layer for AI-driven mathematical hypothesis (conjecture) generation. By combining SymPy's pattern recognition with structured automated evaluation, the engine parses deep mathematical behaviors efficiently, serving as a powerful analytical tool for researchers and students.

Top comments (0)