# Revision history [back]

Did you use the value of P you had in mind?

Did you try this in a fresh Sage session?

Here is what I get.

Define the last version of your function:

def one_dimension_less(P, param):
A, b = P
m = A.nrows()
M = range(m)
n = A.ncols()
c = zero_vector(m)
c[param] = 1
N = [i for i in M if A[i, :]*c < 0]
Z = [i for i in M if A[i, :]*c == 0]
P = [i for i in M if A[i, :]*c > 0]
p = Z + [(i, j) for i in N for j in P]
r = len(p)
D = Matrix(r, n)
d = Matrix(r, 1)
for i in range(0, r):
if not isinstance(p[i], tuple):
D[i, :] = A[p[i], :]
d[i] = b[p[i]]
else:
s, t = p[i]
D[i, :] = (A[t, :]*c)*A[s, :] - (A[s, :]*c)*A[t, :]
d[i] = (A[t, :]*c)*b[s] - (A[s, :]*c)*b[t]
return (D, d)

Run the suggested example:

sage: A = matrix([[1, 2, 3], [1, 2, 1], [2, 2, 1]])
sage: b = vector([1, 1, 1])
sage: one_dimension_less(P, 0)
Traceback (most recent call last)
...
NameError: name 'P' is not defined

Or, guessing that P should be (A, b):

sage: P = (A, b)
sage: one_dimension_less(P, 0)
([], [])