Ask Your Question

Revision history [back]

There are two mistakes:

  • x is only defined as a vector inside the function, not outside
  • elim_x expects x[0] rather than [x[0]] as its second argument

The function elim_x can be slightly reformatted as follows:

def elim_x(representationH, elim_var, k):
    x = vector(SR, SR.var('x_', 3))
    ieqs = [[el.A()*x + el.b() >= 0] for el in DH]
    sol = [solve_ineq(ieq, [elim_var]) for ieq in ieqs]
    sol_r = flatten([x[1] for x in sol])
    ineq_ge = [z for z in sol_r if z.rhs() == elim_var]
    ineq_le = [z for z in sol_r if z.lhs() == elim_var]
    ineq_a = [z for z in sol_r if z.lhs() != elim_var and z.rhs() != x[0]]
    ineq_aa = [(z.lhs()).full_simplify() >= 0 for z in ineq_a]
    result = flatten(ineq_aa +
                     [[(ineq_le[j].rhs() - ineq_ge[i].lhs()).full_simplify() >= 0
                       for i in range(len(ineq_ge))]
                      for j in range(len(ineq_le))])
    reslhs = [el.lhs() for el in result]
    if k == 0:
        return result
    if k == 1:
        return reslhs

(only minor cosmetic changes: spacing, line breaks), and used as

sage: D = polytopes.dodecahedron()
sage: DH = D.Hrepresentation()
sage: x = vector(SR, SR.var('x_', 3))
sage: el0 = elim_x(DH, x[0], 1)
sage: el0[0]
-x_2*(sqrt(5) + 1) - 2*x_1 + 4