# doubly indexed variables in a non-commutative ring

I'm trying to do some basic arithmetic in a non-commutative polynomial ring with variables indexed by two indices i and j (say 1 \le i < j \le 6). Does anyone know how to ask for a doubly indexed variable like this?
Thanks, Anna

edit retag close merge delete

Sort by » oldest newest most voted

Symbolic variables don't have a notion of index directly, just a name. You can create a list of variables to send to the var() command that have a systematic naming scheme that corresponds to double indexing:

sage: var(','.join(['x_%d%d' % (i,j) for i in [1..6] for j in [1..6]]))
(x_11, x_12, x_13, x_14, x_15, x_16, x_21, x_22, x_23, x_24, x_25, x_26, x_31, x_32, x_33, x_34, x_35, x_36, x_41, x_42, x_43, x_44, x_45, x_46, x_51, x_52, x_53, x_54, x_55, x_56, x_61, x_62, x_63, x_64, x_65, x_66)


... and they even typeset correctly:

sage: latex(x_11)
x_{11}

more

Ok, so I can make this list of variables, but how do I make it the *non-commuting* variables over ZZ? I thought FreeAlgebra would do this, but it seems to make a FreeAlgebra in the commuting list of variables I give it.

( 2013-02-25 16:52:47 +0200 )edit

@benjaminfjones: I think what the OP wanted was how to define this in case of PolynomialRing. Something similar to this (obtained from the documentation):

sage: PolynomialRing(GF(7), 'y', 5)
Multivariate Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7


The answer is a simple modification to what you did, since I don't think two variable indices can be automatically created. But we can just create the same list as you did and provide it as the second argument:

sage: R = PolynomialRing(ZZ, ['x_%d%d' % (i,j) for i in [1..2] for j in [1..2]]); R
Multivariate Polynomial Ring in x_11, x_12, x_21, x_22 over Integer Ring
sage: R.inject_variables()
Defining x_11, x_12, x_21, x_22
sage: x_11*x_12 # Now we can use the variables
x_11*x_12

more

Thanks, but this makes a polynomial ring in a commuting list of variables. Do you know a way to make them not commute?

( 2013-02-25 16:53:34 +0200 )edit

Then maybe you don't want a polynomial ring. There is a FreeAlgebra class, or (from sage-5.7) a FreeGroup class which can give you noncommutative variables. sage: G = FreeAlgebra(ZZ, ['x_%d%d'%(i,j) for i in range(2) for j in range(2)]) sage: G Free Algebra on 4 generators (x_00, x_01, x_10, x_11) over Integer Ring sage: G.inject_variables() Defining x_00, x_01, x_10, x_11 sage: x_00 * x_01 == x_01 * x_00 False

( 2013-02-26 03:06:08 +0200 )edit