PPivotQuartz
Product

Product features · Exact linear system solutions

01

Use PivotQuartz to follow exact pivot operations from a coefficient matrix to fractional solution values.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Exact linear system solutions

● ● ●PivotQuartz●
A concrete starting point · Exact linear system solutions ×
from fractions import Fraction

def solve_linear(matrix, rhs):
    matrix, rhs = [tuple(row) for row in matrix], tuple(rhs)
    n = len(matrix)
    if not 1 <= n <= 8 or len(rhs) != n or any(len(row) != n for row in matrix):
        raise ValueError("system.shape")
    if any(type(v) is not int or abs(v) > 1000000 for row in matrix for v in row) or any(type(v) is not int or abs(v) > 1000000 for v in rhs):
        raise ValueError("coefficient.range")
    a = [[Fraction(v) for v in row] + [Fraction(rhs[i])] for i, row in enumerate(matrix)]
    for col in range(n):
        pivot = next((r for r in range(col, n) if a[r][col]), None)
        if pivot is None:
            raise ValueError("system.singular")
        a[col], a[pivot] = a[pivot], a[col]
        scale = a[col][col]
        a[col] = [v / scale for v in a[col]]
        for r in range(n):
            if r != col:
                factor = a[r][col]
                a[r] = [x - factor * y for x, y in zip(a[r], a[col])]
    return [row[-1] for row in a]
✳Solve a square integer linear system of up to eight equations using exact fractions.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗