| Did you know ... | Search Documentation: |
| Pack starlog -- IMPLEMENTATION_SUMMARY_GAUSSIAN.md |
The task was to implement a Gaussian elimination solver in Starlog that can:
gaussian_elimination.plThe implementation provides a complete Gaussian elimination solver with:
The solver is integrated with Starlog syntax through:
starlog.pl:
starlog_registry.pl:
is syntax:- use_module(gaussian_elimination). % Solve a system ?- solve_system([[2, 1, 5], [1, -1, 1]], Solution). Solution = [2.0, 1.0].
:- use_module(starlog). % Using "is" syntax ?- Solution is solve_system([[2, 1, 5], [1, -1, 1]]). Solution = [2.0, 1.0].
Augmented matrix format: [[a11, a12, ..., a1n, b1], ...]
Example for system:
2x + y = 5 x - y = 1
Matrix: [[2, 1, 5], [1, -1, 1]]
Matrix:
2 1 3 10 3 0 1.5 4.5 0 0 1 1
Solution: (x₁, x₂, x₃) = (1, 5, 1)
Implementation:
?- solve_system([[2, 1, 3, 10], [3, 0, 1.5, 4.5], [0, 0, 1, 1]], Solution). Solution = [1.0, 5.0, 1].
Note: The problem statement showed the matrix with constants 2, 1, 1 instead of 10, 4.5, 1. The corrected version produces the expected solution (1, 5, 1).
Matrix (as stated):
2 1 3 2 3 0 1.5 1 0 0 1 1
Solution: (x₁, x₂, x₃) ≈ (-0.167, -0.667, 1)
Implementation:
?- solve_system([[2, 1, 3, 2], [3, 0, 1.5, 1], [0, 0, 1, 1]], Solution). Solution = [-0.16666666666666666, -0.6666666666666665, 1].
Underdetermined system (2 equations, 3 unknowns):
x + y + z = 6 2x + y + 3z = 14
Solution: Infinite solutions (one free variable)
Implementation:
?- solve_system([[1, 1, 1, 6], [2, 1, 3, 14]], Solution, Type). Type = infinite, Solution = [8.0, -2.0, _FreeVar]. % One particular solution
✅ Gaussian elimination with partial pivoting
✅ Solution type detection (unique/infinite/none)
✅ Back substitution for unique solutions
✅ Parametric solutions for underdetermined systems
✅ Starlog syntax integration (is operator)
✅ Comprehensive test suite
✅ Documentation and examples
✅ Demo programs showing usage
All tests pass:
$ swipl -g "run_all_tests" -t halt tests/test_gaussian_elimination.pl Test 1: Unique solution (1, 5, 1) PASSED Test 2: 2x2 system PASSED Test 3: 3x3 system PASSED Test 4: Infinite solutions PASSED Test 5: Identity matrix PASSED
The implementation successfully addresses the problem statement by providing:
is operator syntax, making it a natural extension of the Starlog language.