{"record":{"id":"ed4709fd7ee4837f","repo":"TheAlgorithms/Python","slug":"solve-simultaneous-requires-at-least-1-full-equa","errorCode":null,"errorMessage":"solve_simultaneous() requires at least 1 full equation","messagePattern":"solve_simultaneous\\(\\) requires at least 1 full equation","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/simultaneous_linear_equation_solver.py","lineNumber":99,"sourceCode":"        raise IndexError(\"solve_simultaneous() requires n lists of length n+1\")\r\n    _length = len(equations) + 1\r\n    if any(len(item) != _length for item in equations):\r\n        raise IndexError(\"solve_simultaneous() requires n lists of length n+1\")\r\n    for row in equations:\r\n        if any(not isinstance(column, (int, float)) for column in row):\r\n            raise ValueError(\"solve_simultaneous() requires lists of integers\")\r\n    if len(equations) == 1:\r\n        return [equations[0][-1] / equations[0][0]]\r\n    data_set = equations.copy()\r\n    if any(0 in row for row in data_set):\r\n        temp_data = data_set.copy()\r\n        full_row = []\r\n        for row_index, row in enumerate(temp_data):\r\n            if 0 not in row:\r\n                full_row = data_set.pop(row_index)\r\n                break\r\n        if not full_row:\r\n            raise ValueError(\"solve_simultaneous() requires at least 1 full equation\")\r\n        data_set.insert(0, full_row)\r\n    useable_form = data_set.copy()\r\n    simplified = simplify(useable_form)\r\n    simplified = simplified[::-1]\r\n    solutions: list = []\r\n    for row in simplified:\r\n        current_solution = row[-1]\r\n        if not solutions:\r\n            if row[-2] == 0:\r\n                solutions.append(0)\r\n                continue\r\n            solutions.append(current_solution / row[-2])\r\n            continue\r\n        temp_row = row.copy()[: len(row) - 1 :]\r\n        while temp_row[0] == 0:\r\n            temp_row.pop(0)\r\n        if len(temp_row) == 0:\r\n            solutions.append(0)\r","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/simultaneous_linear_equation_solver.py#L81-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nsolve_simultaneous([[0, 2, 3], [4, 0, 6]])  # -> ValueError\n\n# after (structural zeros: use a general solver)\nimport numpy as np\na = np.array([[0.0, 2.0], [4.0, 0.0]])\nb = np.array([3.0, 6.0])\nprint(np.linalg.solve(a, b))  # [1.5  0.75]","handlingStrategy":"try-catch","validationCode":"if all(0 in row for row in equations):\n    # solver needs one row with no zeros at all (incl. constant)\n    print('system not supported; use numpy/sympy')\nelse:\n    solve_simultaneous(equations)","typeGuard":"def has_full_row(eq: list) -> bool:\n    return any(all(x != 0 for x in row) for row in eq)","tryCatchPattern":"try:\n    solve_simultaneous(equations)\nexcept ValueError as e:\n    if 'at least 1 full equation' in str(e):\n        solutions = np.linalg.solve(np.array(a, float), np.array(b, float))","preventionTips":["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"],"tags":["python","math","linear-algebra","singular-system","value-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}