ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 16 Jun 2021 21:52:17 +0200How do you assign (different) LaTex names to elements of a list?https://ask.sagemath.org/question/57589/how-do-you-assign-different-latex-names-to-elements-of-a-list/Say I have the following list of variables.
v = {(i,j): var("v_{}{}".format(i, j), latex_name="v_{{}{}}") for i in range(2) for j in range(2)}
How do I make it so that when I use the
show(v[0,0])
command, I get $v_{0,0}$ as output? I've tried stuff like
v = {(i,j): var("v_{}{}".format(i, j), latex_name="v_{i,j}") for i in range(2) for j in range(2)}
and
v = {(i,j): var("v_{}{}".format(i, j), latex_name="v_{{i}{j}}") for i in range(2) for j in range(2)}
but it only ever give me stuff like $v_{i,j}$ where it's just the literal symbols $i$ and $j$, not the entries of
v[k,m]
for some $k$ and $m$ I plug in, like 0, 0.
sum8tionWed, 16 Jun 2021 21:52:17 +0200https://ask.sagemath.org/question/57589/Polynomial ring indexed over an abelian group (magma).https://ask.sagemath.org/question/50799/polynomial-ring-indexed-over-an-abelian-group-magma/Hi, I wonder if currently there's a cleaner way to do $x^v \cdot x^w = x^{v+w}$ in Sage, where $v, w$ are some vectors in a vector space?
Once a basis $\{v_1, \cdots v_n\}$ for the vector space is chosen, this can be done by identifying $x_i$ with $x^{v_i}$, and use the multivariate ring $R[x_1, \cdots, x_n]$. However, I would like to do this in an intrinsic manner, i.e. not choosing a basis.
More generally, I think for any element $m$ in any magma $M$, we should be able to define an algebra $R[x^m|m\in M]$ over any given ring $R$. Notice that this is not the same as `FreeAbelianMonoid` generated over $M$, as in this case $x^m x^{n}$ is not the same as $x^{mn}$.
### Question
Is $R[x^m|m\in M$$ currently doable? If not, I might work on writing it.
### Application
A reason why I think it would be helpful: it can help calculating generalized characters of representations of quantum groups.jinThu, 16 Apr 2020 19:27:57 +0200https://ask.sagemath.org/question/50799/(Update) How to change/set variables?https://ask.sagemath.org/question/46993/update-how-to-changeset-variables/ I asked a simplified version of this question, and got an answer here:
https://ask.sagemath.org/question/46945/how-to-changeset-variables/
However I'm still having difficulty with a more complicated version of the same set-up, which I present here. Essentially I want to take a trace of an exponential of a matrix valued in forms. When I try running it with the forms I want, the run time takes far too long, certainly over an hour on my laptop. However, it's much shorter if I use forms with symbolic coefficients. What follows below is my attempt at computing the forms I want with symbols first, and then trying to set the coefficients at the end.
To start, I have
sage: M = Manifold(6, 'M', field='complex')
sage: U = M.open_subset('U')
sage: c_xyzXYZ.<x,y,z,X,Y,Z> = U.chart()
sage: eU = c_xyzXYZ.frame()
sage: var('x,y,z,X,Y,Z')
I create some symbolic differential forms in the following way,
sage: g = {(i, j, k): var("g_{}{}{}".format(i, j, k), latex_name="g_{{{}{}{}}}".format(i,
sage:... j, k)) for i in range(9) for j in range[3, 4, 5] for k in range(3)}
sage: f = [M.diff_form(2, name='f_{}'.format(i)) for i in range(9)]
sage: for i in range(9):
sage: for j in [3, 4, 5]:
sage: for k in range(3):
sage: f[i][eU, j, k] = g[(i, j, k)]
sage: F = [M.mixed_form(comp=[0, 0, f[i], 0, 0, 0, 0]) for i in range(9)]
Now I create a matrix valued in differential forms (I'm running the current beta version), define an identity matrix of mixed forms, define an exponential function (the usual .exp() for matrices doesn't seem to work when the matrix is valued in mixed forms)
sage: FF = Matrix([[F[0], F[1], F[2]], [F[3], F[4], F[5]], [F[6], F[7], F[8]]])
sage: G = FF.apply_map(lambda f: (I/2*pi)*f)
sage: I_00 = M.mixed_form(comp=[1, 0, 0, 0, 0, 0, 0])
sage: I_01 = M.mixed_form(comp=[0, 0, 0, 0, 0, 0, 0])
Id = matrix([[I_00, I_01, I_01], [I_01, I_00, I_01], [I_01, I_01, I_00]])
sage: EXP = lambda f: Id+f+(f^2).apply_map(lambda g: (1/2)*g)
sage: ...+(f^3).apply_map(lambda g: (1/6)*g)
sage: ...+(f^4).apply_map(lambda g: (1/24)*g)
sage: ...+(f^5).apply_map(lambda g: (1/120)*g)
sage: ...+(f^6).apply_map(lambda g: (1/720)*g)
Finally I compute the trace of the exponential of the matrix G,
sage: E = EXP(G)
sage: CH = E.trace()
Now if one trys to display CH in the frame eU, after about 10 minutes, this will print out some massive mixed form with coefficients being the g[(i, j, k)]. I now want to change the components of these forms to explicit forms. For simplicity of the example, lets just assume I want them all to be x^2.
sage: for i in range(9):
sage: for j in [3, 4, 5]:
sage: for k in range(3):
sage: g[(i, j, k)] = x^2
Than I update the forms as suggested in the answer to my original question,
sage: for i in range(9):
sage: for j in [3, 4, 5]:
sage: for k in range(3):
sage: f[i][eU, j, k] = g[(i, j, k)]
If you trying displaying any f, it's clear that this has worked. However, when I try to write
sage: CH.display(eU)
all the components are still in terms of g_{}{}{}, they have not been changed to x^2. Is there some way to do this without having to run the computation of CH again? The whole point of this convoluted example was to avoid doing this computation with the functions I'm actually interested in, and only set them at the end.sum8tionTue, 25 Jun 2019 18:45:38 +0200https://ask.sagemath.org/question/46993/How to change/set variables?https://ask.sagemath.org/question/46945/how-to-changeset-variables/I created a list of formal variables that I want to work with under addition, multiplication etc. in the following way:
g = list(var('g_%d' % i) for i in rang(4))
Specifically I'm working with differential forms
M = Manifold(4, 'M', field='complex')
U = M.open_subset('U')
c_xyXY<x, y, X, Y>=U.chart()
eU = c_xyXY.frame()
d = [[M.diff_form(2, name='d_{}{}'.format(j, i)) for i in range(2)] for j in range(2)]
d[0][0] [eU, 2, 0] = g[0]
d[0][1] [eU, 3, 0] = g[1]
d[1][0] [eU, 2, 1] = g[2]
d[1][1] [eU, 3, 1] = g[3]
I then want to set the variables to something specific like
g[0] = x^2
but when I try to display this I get
d[0][0].display(eU)
d_00 = -g_0dx/\dX
What I want is
d_00 = -x^2dx/\dX
EDIT: The question as originally asked has been sufficiently answered by eric_g below. However I'm still having difficulty with a more complicated version of the same set-up, which I present here:
https://ask.sagemath.org/question/46993/update-how-to-changeset-variables/sum8tionWed, 19 Jun 2019 19:57:49 +0200https://ask.sagemath.org/question/46945/How to make formal variables with more than one index?https://ask.sagemath.org/question/46942/how-to-make-formal-variables-with-more-than-one-index/I'd like to make formal variables that can be multiplied, added etc. but have them labelled by two indices.
Here:
https://ask.sagemath.org/question/7925/a-list-of-symbolic-variables/
it's done for variables with one index, and I asked a similar question about defining differential forms with multi-labels here:
https://ask.sagemath.org/question/46844/how-to-define-multiple-objects-with-a-for-loop/
I see no clear way of merging these two approaches. sum8tionWed, 19 Jun 2019 15:47:11 +0200https://ask.sagemath.org/question/46942/Defined variable in recursive functionhttps://ask.sagemath.org/question/44750/defined-variable-in-recursive-function/
@cached_function
def Folge2(n):
k = var('k')
if n < 1:
return 1
else:
return (-1/(n+1)*sum((binomial(n+1,k)*Folge2(k)),k,0,n-1))
print Folge2(1)
Hello.
I've got a problem with this program right here.
Sage is giving back a "RuntimeError: maximum recursion depth exceeded while calling a Python
object". It is likely because i'm calling Folge2(k) again with k as defined variable.
How can i avoid this?
Best regards.QuotenbananeSun, 23 Dec 2018 00:39:07 +0100https://ask.sagemath.org/question/44750/Variable declaration in recursiv functionhttps://ask.sagemath.org/question/44749/variable-declaration-in-recursiv-function/
@cached_function
def Folge2(n):
k = var('k')
if n < 1:
return 1
else:
return (-1/(n+1)*sum((binomial(n+1,k)*Folge2(k)),k,0,n-1))
print Folge2(1)
Hello.
I've got a problem with this program right here.
Sage is giving back a "RuntimeError: maximum recursion depth exceeded while calling a Python
object". It is likely because i'm calling Folge2(k) again with k as defined variable.
How can i avoid this?
Best regards.QuotenbananeSun, 23 Dec 2018 00:37:58 +0100https://ask.sagemath.org/question/44749/How to display all the symbolic variables and functions?https://ask.sagemath.org/question/42126/how-to-display-all-the-symbolic-variables-and-functions/ I have already declared a lot of stuff. How do I see what is already declared. something like: show (variables()) and show(functions()).
Something analogous to assumptions(). And why doesn't vars() work?ionsmeMon, 23 Apr 2018 00:06:12 +0200https://ask.sagemath.org/question/42126/Delayed assignmenthttps://ask.sagemath.org/question/40299/delayed-assignment/Hi!
I'm new in Sage and I'm trying with the following input:
a=2;
x=a;
a=3;
x
Then, the output isn't updated. Is there any way to set a delayed assignment? I'm talking about something similar to the ':=' form of assignment in Mathematica. Note that with a delayed assignment isn't required to define 'x' as a function.
Thank you so much in advance!dg.aragonesTue, 26 Dec 2017 12:06:31 +0100https://ask.sagemath.org/question/40299/Why is assume() so slow?https://ask.sagemath.org/question/37744/why-is-assume-so-slow/Declaring assumptions using `assume()` takes an awful lot of time, e.g.:
var('a b c d e f g h i')
assume([(var1, 'real') for var1 in [a, b, c, d, e, f, g, h, i]])
The same applies to declaring variables with the `domain` option, e.g. `var('a', domain='positive')`.
See also https://cocalc.com/projects/34b4b62a-2621-47c8-9bda-cde3a855f995/files/test_assumptions.ipynb for an example. Does anyone know why this takes so much time and/or how this could be made faster? Thanks a lot!stanTue, 30 May 2017 23:39:08 +0200https://ask.sagemath.org/question/37744/How to define a polynomial which can take matrix ?https://ask.sagemath.org/question/33441/how-to-define-a-polynomial-which-can-take-matrix/ I want to define a matrix valued function. for example..
If I have a polynomial of a matrix with me say $f(x)$ and I want to check $f(A)$. What can be done better?
The following will work for numbers but not for matrix.
var('x')
f(x)=2x^2+x+3
print f(A)# this is what I want as an answer..
**
In the above if I want to replace my x by a matrix what I have to do?
----------------------------------------
**
So, ultimate aim is to find define a polynomial which can take matrix
Thanks in advance...
daviddglWed, 18 May 2016 20:33:49 +0200https://ask.sagemath.org/question/33441/Where is information passed on to var() stored?https://ask.sagemath.org/question/32357/where-is-information-passed-on-to-var-stored/ We can link additional information to expressions defined by var(), such as the domain or latex expression, e.g.
> sage: var('xt1',domain = real,latex_name = 'x_{t1}')
Where is this information stored and is there a way to modify it, e.g. change the domain or latex_name without having to redefine the expression?stanThu, 28 Jan 2016 15:38:07 +0100https://ask.sagemath.org/question/32357/Naming variables in a loophttps://ask.sagemath.org/question/31794/naming-variables-in-a-loop/ I have this problem:
Lets say i have an matrix A and use A.gram_schmidt() on it. then i get a matrix B whose rows are orthogonal. So what do i do now if i want use the vectors of the rows. How can i make them to variables practical? I tried this:
O, t = A.gram_schmidt()
for i in range(n):
wi = O.row(i)
But clearly this doesnt work, because sage doesnt identiy the "i" in "wi"... bruno171092Wed, 23 Dec 2015 14:27:45 +0100https://ask.sagemath.org/question/31794/Compute $j$-invariant of elliptic curve in non-Weierstrass form with arbitrary coefficientshttps://ask.sagemath.org/question/29632/compute-j-invariant-of-elliptic-curve-in-non-weierstrass-form-with-arbitrary-coefficients/ One can compute the $j$-invariant of an elliptic curve not in Weierstrass form in Sage via the following (where the curve $ x+x^2+y-x^2y-xy^2+x^2y^2=0 $ -- not in Weierstrass form -- is used as an example):
x,y = polygen(QQ,'x,y')
E = Jacobian(x+x^2+y-x^2*y-x*y^2+x^2*y^2)
E.j_invariant()
If we include numerical coefficients of the various terms, this still works. However, I would like Sage to compute the j-invariant of such curves in non-Weierstrass form with arbitrary coefficients, e.g. $ax+bx^2+cy-dx^2y-exy^2+fx^2y^2$. Is this possible? I tried including the line:
var('a,b,c,d,e,f')
But got an error. Can anyone help? Thanks!
JamesReadMon, 28 Sep 2015 12:53:15 +0200https://ask.sagemath.org/question/29632/Finding Cremona label for Tunnell's y^2-x^3-n^2xhttps://ask.sagemath.org/question/9122/finding-cremona-label-for-tunnells-y2-x3-n2x/When I enter
E = EllipticCurve([-n^2,0]); E;E.label()
Sage gives an error that I have an unsupported operand type. I assume the problem is that I have not defined the variable 'n', which is a square free integer, but how does one do this? Any help would be greatly appreciated!!memory13Mon, 02 Jul 2012 11:20:30 +0200https://ask.sagemath.org/question/9122/doubly indexed variables in a non-commutative ringhttps://ask.sagemath.org/question/9823/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,
AnnaannabWed, 20 Feb 2013 12:44:19 +0100https://ask.sagemath.org/question/9823/variables vs argumentshttps://ask.sagemath.org/question/9789/variables-vs-arguments/I'm a newbie so please excuse me with this silly question. I just move from Mathematica to SAGE.
I cannot tell the difference between arguments and variables in SAGE. What're the differences?
Please help.
Thank you in advance! hacaoideasSat, 09 Feb 2013 02:26:22 +0100https://ask.sagemath.org/question/9789/Which variables are automagically defined in the sage shell?https://ask.sagemath.org/question/9665/which-variables-are-automagically-defined-in-the-sage-shell/I'm using the sage-5.5 command line and some variables are automatically declared. For instance I can do
f = x^2
but not
f = t^2
My question: How does this come about? Which variables are defined like this? Where is this documented?
ThomasThu, 03 Jan 2013 08:21:01 +0100https://ask.sagemath.org/question/9665/