| Did you know ... | Search Documentation: |
| Pack starlog -- IMPLEMENTATION_SUMMARY_ALGEBRA.md |
"algebra (apply operations to both sides)"
Example: (Y+5)/2 is 2
Implemented a comprehensive algebraic equation solver that can solve equations by automatically applying inverse operations to both sides to isolate the variable.
algebra_solver.plsolve_equation(+Equation, -Solution) - Solve equation auto-detecting variablesolve_equation(+Equation, -Variable, -Solution) - Solve for specific variablecontains_var(+Expr, -Variable) - Detect variables in expressionsThe solver handles the following operations by applying their inverses:
| Operation | Inverse | Example |
|---|---|---|
Division (/) | Multiply both sides | Y/2 = 3 → Y = 6 |
Multiplication (*) | Divide both sides | 2*Y = 8 → Y = 4 |
Addition (+) | Subtract from both sides | Y+3 = 7 → Y = 4 |
Subtraction (-) | Add to both sides | Y-2 = 5 → Y = 7 |
Power (**) | Take nth root | Y**2 = 16 → Y = 4 |
The solver works recursively:
Solving (Y+5)/2 = 2:
Step 1: (Y+5)/2 = 2 [Original equation] Step 2: Y+5 = 4 [Multiply both sides by 2] Step 3: Y = -1 [Subtract 5 from both sides]
algebra_solver.pl - Main algebra solver module with solving logictests/test_algebra_solver.pl - Comprehensive test suite (13 tests)tests/test_integrated_algebra.pl - Integration tests with starlogdemo_algebra_solver.pl - Demonstration of various equation typesdemo_problem_statement.pl - Specific demo for the problem statementALGEBRA_SOLVER_GUIDE.md - Comprehensive user guide with examplesREADME.md - Updated with algebra solver sectionstarlog.pl - Updated to export algebra solver predicates?- solve_equation((Y+5)/2 is 2, Y, Solution). Solution = -1. ✓
Y+3 and 3+Y10-Y vs Y-10:- use_module(starlog). % Direct usage ?- solve_equation((Y+5)/2 is 2, Y, Solution). Y = -1, Solution = -1. % Auto-detect variable ?- solve_equation(3*X+7 is 22, Result). Result = 5. % Complex equation ?- solve_equation(((X+2)*3-1)/2 is 7, X, Result). X = 3, Result = 3.
All existing tests continue to pass, confirming no regressions:
Successfully implemented a fully functional algebraic equation solver that can solve equations by applying operations to both sides, exactly as specified in the problem statement "(Y+5)/2 is 2".