TheAlgorithms/Python · error · ValueError
solve_simultaneous() requires at least 1 full equation
Error message
solve_simultaneous() requires at least 1 full equation
What it means
Raised by solve_simultaneous() when every equation row contains at least one zero and therefore no 'full' row exists to reorder to the top. The elimination algorithm needs a pivot row with all non-zero coefficients to start; it pops the first zero-free row, and if none exists it gives up with this ValueError. Singular/underdetermined systems that merely need row swapping are handled, but all-zero-containing systems are not.
Source
Thrown at maths/simultaneous_linear_equation_solver.py:99
raise IndexError("solve_simultaneous() requires n lists of length n+1")
_length = len(equations) + 1
if any(len(item) != _length for item in equations):
raise IndexError("solve_simultaneous() requires n lists of length n+1")
for row in equations:
if any(not isinstance(column, (int, float)) for column in row):
raise ValueError("solve_simultaneous() requires lists of integers")
if len(equations) == 1:
return [equations[0][-1] / equations[0][0]]
data_set = equations.copy()
if any(0 in row for row in data_set):
temp_data = data_set.copy()
full_row = []
for row_index, row in enumerate(temp_data):
if 0 not in row:
full_row = data_set.pop(row_index)
break
if not full_row:
raise ValueError("solve_simultaneous() requires at least 1 full equation")
data_set.insert(0, full_row)
useable_form = data_set.copy()
simplified = simplify(useable_form)
simplified = simplified[::-1]
solutions: list = []
for row in simplified:
current_solution = row[-1]
if not solutions:
if row[-2] == 0:
solutions.append(0)
continue
solutions.append(current_solution / row[-2])
continue
temp_row = row.copy()[: len(row) - 1 :]
while temp_row[0] == 0:
temp_row.pop(0)
if len(temp_row) == 0:
solutions.append(0)
View on GitHub (pinned to f5988cc097)
Solutions
- Rearrange so at least one equation has all non-zero entries, if the system permits
- Scale/rewrite zero constant terms as small non-zero values only if mathematically acceptable
- Use a proper solver (sympy.solve, numpy.linalg) for systems with structural zeros — this implementation cannot pivot through them
Example fix
# before solve_simultaneous([[0, 2, 3], [4, 0, 6]]) # -> ValueError # after (structural zeros: use a general solver) import numpy as np a = np.array([[0.0, 2.0], [4.0, 0.0]]) b = np.array([3.0, 6.0]) print(np.linalg.solve(a, b)) # [1.5 0.75]
Defensive patterns
Strategy: try-catch
Validate before calling
if all(0 in row for row in equations):
# solver needs one row with no zeros at all (incl. constant)
print('system not supported; use numpy/sympy')
else:
solve_simultaneous(equations) Type guard
def has_full_row(eq: list) -> bool:
return any(all(x != 0 for x in row) for row in eq) Try / catch
try:
solve_simultaneous(equations)
except ValueError as e:
if 'at least 1 full equation' in str(e):
solutions = np.linalg.solve(np.array(a, float), np.array(b, float)) Prevention
- Zero constants also trigger this — x+y=0 is rejected
- Switch to numpy.linalg/sympy for structurally sparse systems
- Check for a zero-free row before calling
When it happens
Trigger: Calling solve_simultaneous([[0, 2, 3], [4, 0, 6]]) — each row has a 0 coefficient, so no row is 'full'. Note the constant term also participates in the 0 check: [[1, 2, 0], [3, 4, 0]] has zero constants and also raises, even though the system is solvable as homogeneous.
Common situations: Diagonal-style systems (x appears only in one equation); systems with zero right-hand sides; sparse coefficient matrices from modeling. The zero-in-constants false positive is a known sharp edge — a system like x+y=0 is rejected even though it is tractable.
Related errors
- solve_simultaneous() requires lists of integers
- Input list must be a non empty list
- Input series is not valid, valid series - [1, 2/3, 2]
- Input list must be a non empty list
- Input series cannot have 0 as an element
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/ed4709fd7ee4837f.
Report an issue: GitHub.