Ask Your Question

Revision history [back]

Here is what I would do

  • format your code with one instruction per line
  • indent everything by four spaces
  • add an unindented def something(m, n): in front
  • decide what to return at the end

For example:

def something(m, n):
    x = lambda i: SR.var(f"x_{i}", latex_name=f"x_{{{i}}}")
    X = vector([x(i) for i in [1 .. n]])
    b = VectorSpace(QQ, m).random_element()
    A = matrix(QQ, m, n)
    A[0, :] = ones_matrix(1, n)
    for i in [1 .. m - 2]:
        A[i, i:i + 2] = ones_matrix(1, 2)
    eq = [A[i]*X == b[i] for i in range(m)]
    a = matrix([[e.lhs().coefficient(v) for v in X] for e in eq])
    C = A.augment(b)
    D = C.right_kernel()
    return X, b, A, eq, a, C, D