The Aim
A robust Python-based tool designed to solve complex IGCSE-level mathematics intuitively.
Detailed Summary
- Calculator: The daily driver. A terminal-based arithmetic engine that feeds heavily into the global history state, acting as the memory bank for active math sessions.
- Unit Converter: A rapid-fire input/output tool. You type the value and the unit, and it spits out the conversions for Length, Mass, Temperature, and Volume straight to the next line of the terminal.
- Number Tools: The pure number cruncher. Handles prime factorizations, calculates Highest Common Factors (HCF) and Lowest Common Multiples (LCM), and simplifies fractions instantly.
- Algebra Tools: The SymPy powerhouse. Prompts the user for a raw string equation, then silently parses it to output exact factorizations, expanded polynomials, and solved variables.
- Geometry Calculator: A step-by-step terminal wizard. It asks you a series of questions based on your shape (e.g., "Enter Radius:", "Enter Height:"), then uses constants like math.pi to output exact 2D areas, 3D volumes, surface areas, and coordinate geometry results.
- Statistics Machine: You feed it a space-separated string of numbers, and it prints a perfectly formatted text block containing Mean, Median, Mode, Range, Variance, and Standard Deviation.
- Linear Regression: Takes X and Y datasets, prints the exact equation (y = mx + c) and correlation (r) to the console, and then halts the terminal to pop up a Matplotlib window showing the scatter plot and line of best fit.
- Universal Sequence Solver: A massive logic loop. It swallows a string of numbers, runs a finite differences algorithm in the background, and prints the exact nth term formula (whether arithmetic, geometric, or hybrid) directly to the console.
- Calculus Machine: The absolute heavyweight. A deep, three-tier nested menu system handling:
- The Basics: Prompts for functions and limits, returning exact derivatives and integrals (+ C).
- Curve Analysis: Asks for a function and an X-coordinate, then spits out the exact equations for tangent and perpendicular lines, alongside calculated max/min/inflection points.
- Advanced: Takes user inputs for centers, target variables, and boundaries to solve Taylor series, multivariable partial derivatives, ODEs, Laplace transforms, and infinite summations.
- Matrix Tools: A grid-based input system that takes rows of numbers, constructs a matrix, and executes arithmetic, determinants, and inverses, printing the resulting grid back to the screen.
- Complex Numbers: Prompts the user for real and imaginary parts, calculating and returning the magnitude, argument, and complex conjugate of i-based mathematics.
- Probability Tools: A terminal tool that asks for populations (n) and selections (r) to instantly return permutations, combinations, and core distribution probabilities.
- Graphing Calculator: You type in a function (like sin(x)*e^x), and the console pauses to launch a dedicated Matplotlib window, plotting the curve across a standard Cartesian grid.
Tech Stack
Core Language: Python 3.
- Symbolic Engine: sympy. Used extensively to parse raw string inputs into mathematical objects, utilizing parse_expr with standard_transformations and implicit_multiplication_application so users can type naturally (e.g., 2x instead of 2*x).
- Data Visualization: matplotlib.pyplot. Used to generate separate, pop-up graphical windows for linear regression and function plotting.
- Data Processing: Built-in math and statistics libraries for rapid, hardcoded numerical crunching.
The Architecture
- Global Memory State (var_saver): The absolute standout feature. A custom-built global history system that saves the output of previous calculations into active memory variables, allowing the user to chain answers together across different modules.
- Deep Nested Logic Loops: Masterful use of while True loops and cascading if/elif console menus to create a navigable "folder" structure entirely out of text prompts.
- Robust Input Sanitization: Custom get_expr_safe, get_num, and data_check functions built to catch human typos before they reach the fragile math engines.
Code Showcase
The core logic loop that evaluates mathematical operations safely.
def math_machine(num1, num2, operation):
# Performs basic arithmetic operations
if operation == '+':
return num1 + num2
elif operation == '-':
return num1 - num2
elif operation == '*':
return num1 * num2
elif operation == '/':
return num1 / num2 if num2 != 0 else 'Error: Division by zero'
else:
return 'Invalid operation'
# Example usage
result = math_machine(42, 10, '+')
print(f"Result: {result}")
Interactive Live Playground
Try out the Math Machine directly in your browser. Powered by Pyodide.
math_machine.py
Machine Output
Ready.