Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Works fine on 9.7.beta3 ... provided you use parent_ring.gens() (i. e. the indeterminates, Sage objects wrapping Singular objects) rather than parent_ring.variable_names() (the indeterminates' names as strings) to build beta. After running :

def create_matrix_with_variables(r):
    m=3*r
    variable_names_string=['b_%d_%d' %(i,j) for (i,j) in cartesian_product([range(1,m+1),range(1,r+1)])]
    parent_ring=ZZ[variable_names_string]
    betas=list(parent_ring.gens())
    beta=matrix(parent_ring,m,r,betas)
    return beta

I get :

sage: create_matrix_with_variables(2)
[b_1_1 b_1_2]
[b_2_1 b_2_2]
[b_3_1 b_3_2]
[b_4_1 b_4_2]
[b_5_1 b_5_2]
[b_6_1 b_6_2]
sage: create_matrix_with_variables(1)
[b_1_1]
[b_2_1]
[b_3_1]

BTW, you may simplify your creation as :

def create2(r, base_name="b"):
    parent_ring=PolynomialRing(ZZ, r*3*r,
                               flatten([["%s_%s_%s"%(base_name, u, v)
                                        for v in (1..r)]
                                       for u in (1..3*r)]))
    return matrix(parent_ring, 3*r, r, parent_ring.gens())

If necessary, inject_variables on the base_ring of your matrix...

That said, the behaviour using the strings is a bug. Care to file a ticket ?

HTH,