ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 10 Jun 2019 04:26:04 -0500Efficient way to define many variables?https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/Hi, I want to use a computer to look at some examples of a certain determinant function. This function depends on many variables (like up to 50-100 in some examples), and the only way I know how to define variables at the moment is something like this:
a, b, c = var('a, b, c')
So, this limits me to using no more than 26 variables. I would like to have variables x_{i,j}, y_{i,j}, z_{i,j} which are indexed by a pair of positive integers i,j not exceeding a number n (which will depend on the example I'm doing, e.g. let's say n=10).
Is there a good way to define all these variables and have Sage recognize them?
Also, this determinant is a polynomial in these variables, and many terms will cancel. Is there a way to get Sage to simplify the expression and make these cancellations? It seems I would need to tell it that my variables commute with each other, which I don't know how to do.Sun, 09 Jun 2019 03:38:14 -0500https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/Answer by FrédéricC for <p>Hi, I want to use a computer to look at some examples of a certain determinant function. This function depends on many variables (like up to 50-100 in some examples), and the only way I know how to define variables at the moment is something like this:</p>
<p>a, b, c = var('a, b, c')</p>
<p>So, this limits me to using no more than 26 variables. I would like to have variables x_{i,j}, y_{i,j}, z_{i,j} which are indexed by a pair of positive integers i,j not exceeding a number n (which will depend on the example I'm doing, e.g. let's say n=10).</p>
<p>Is there a good way to define all these variables and have Sage recognize them? </p>
<p>Also, this determinant is a polynomial in these variables, and many terms will cancel. Is there a way to get Sage to simplify the expression and make these cancellations? It seems I would need to tell it that my variables commute with each other, which I don't know how to do.</p>
https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/?answer=46875#post-id-46875If you mean polynomial variables:
sage: R = PolynomialRing(QQ, x, 44)
sage: x = R.gens()
sage: x[33]
x33
Sun, 09 Jun 2019 03:49:14 -0500https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/?answer=46875#post-id-46875Comment by slelievre for <p>If you mean polynomial variables:</p>
<pre><code>sage: R = PolynomialRing(QQ, x, 44)
sage: x = R.gens()
sage: x[33]
x33
</code></pre>
https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/?comment=46888#post-id-46888@anon -- if this answers your question, please click the "accept" button (tick mark) at the top left of the question. This will mark the answer as accepted and mark your question as answered in the list of questions on the front page of Ask Sage and in results for searches on Ask Sage.Mon, 10 Jun 2019 04:26:04 -0500https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/?comment=46888#post-id-46888Comment by anon for <p>If you mean polynomial variables:</p>
<pre><code>sage: R = PolynomialRing(QQ, x, 44)
sage: x = R.gens()
sage: x[33]
x33
</code></pre>
https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/?comment=46876#post-id-46876great thank you!Sun, 09 Jun 2019 04:12:46 -0500https://ask.sagemath.org/question/46873/efficient-way-to-define-many-variables/?comment=46876#post-id-46876