diff --git a/pystencils/utils.py b/pystencils/utils.py index f089dad1b8a1cbdcd28f38ab926919d389c2c9b8..6cbe324e94469010880497672369a01f2106a88e 100644 --- a/pystencils/utils.py +++ b/pystencils/utils.py @@ -206,6 +206,7 @@ class LinearEquationSystem: non_zero_rows = self.next_zero_row num_unknowns = len(self.unknowns) if non_zero_rows == 0: + print("test") return 'multiple' *row_begin, left, right = self._matrix.row(non_zero_rows - 1) @@ -239,8 +240,3 @@ class LinearEquationSystem: break result -= 1 self.next_zero_row = result - - -def find_unique_solutions_with_zeros(system: LinearEquationSystem): - if not system.solution_structure() != 'multiple': - raise ValueError("Function works only for underdetermined systems") diff --git a/pystencils_tests/test_utils.py b/pystencils_tests/test_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..0cc2895babf8ef6694b9000530c50d1b2a2e9ba3 --- /dev/null +++ b/pystencils_tests/test_utils.py @@ -0,0 +1,36 @@ +import sympy as sp +from pystencils.utils import LinearEquationSystem + + +def test_LinearEquationSystem(): + x, y, z = sp.symbols("x, y, z") + les = LinearEquationSystem([x, y, z]) + les.add_equation(1 * x + 2 * y - 1 * z + 4) + les.add_equation(2 * x + 1 * y + 1 * z - 2) + les.add_equation(1 * x + 2 * y + 1 * z + 2) + + # usually reduce is not necessary since almost every function of LinearEquationSystem calls reduce beforehand + les.reduce() + + expected_matrix = sp.Matrix([[1, 0, 0, sp.Rational(5, 3)], + [0, 1, 0, sp.Rational(-7, 3)], + [0, 0, 1, sp.Integer(1)]]) + assert les.matrix == expected_matrix + assert les.rank == 3 + + sol = les.solution() + assert sol[x] == sp.Rational(5, 3) + assert sol[y] == sp.Rational(-7, 3) + assert sol[z] == sp.Integer(1) + + les = LinearEquationSystem([x, y]) + assert les.solution_structure() == 'multiple' + + les.add_equation(x + 1) + assert les.solution_structure() == 'multiple' + + les.add_equation(y + 2) + assert les.solution_structure() == 'single' + + les.add_equation(x + y + 5) + assert les.solution_structure() == 'none'