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.Thu, 28 Jul 2022 04:54:36 +0200Inner products with dimension $n$.https://ask.sagemath.org/question/63428/inner-products-with-dimension-n/ Is there a way to work with inner products with unspecified dimension in Sage? All the options that I've been able to find e.g. `FreeModule` have a required argument that asks for a dimension, basis or rank of some sort.
Ideally, what I need would work like:
> INN = InnerProdSpace(RR); u, v = INN(u,v); u.dot(v)
and it would be able to perform basic simplifications like:
> u.dot(v + r*u) = u.dot(v) + r*u.dot(u)
I know that some modules like `VectorSpace` already do this and much more; but I would like to do it without needing to specify the dimension.
LuisThu, 28 Jul 2022 04:54:36 +0200https://ask.sagemath.org/question/63428/Strange problem with Solve functionhttps://ask.sagemath.org/question/62372/strange-problem-with-solve-function/I am running into a strange issue when trying to solve an equation, which seems pretty simple to solve. When I ask SAGE preform
x=var('x')
solve(1630*x^3 + 2991*x^2 + 1628*x + 1==0, x)
Everything goes fine, and it gives me the roots of the equation. However, when I ask it to do the same for a larger equation, I get this:
x=var('x')
solve(1953125*x^5 + 6793750*x^4 + 5942255*x^3 + 8749866*x^2 + 5857878*x + 1==0, x)
and the result is:
[0 == 1953125*x^5 + 6793750*x^4 + 5942255*x^3 + 8749866*x^2 + 5857878*x + 1]
And I do not understand why. I even checked using WolframAlpha, and the issue is not that this equation has no roots. Indeed, WolframAlpha was able to solve this equation with no issues.
What is the issue here? What am I missing?RuneMon, 09 May 2022 19:02:02 +0200https://ask.sagemath.org/question/62372/Constructing Cayley Graphshttps://ask.sagemath.org/question/62098/constructing-cayley-graphs/I am having confusions in constructing a Cayley Graph in Sage Math.
Say, I want to construct the Cayley graph on the Symmetric Group $S_4$
with respect to the generating set consisting of all transpositions,
what code do I use.
I tried the following minimal code:
G = SymmetricGroup(4)
CG = G.cayley_graph(generators=[PermutationGroupElement([1, 2]),
PermutationGroupElement([1, 3]),
PermutationGroupElement([1, 4]),
PermutationGroupElement([2, 3]),
PermutationGroupElement([2, 4]),
PermutationGroupElement([3, 4])])
CGU = CG.to_undirected()
CGU.show()
But, I get the error
501 # a valid permutation (else segfaults, infinite loops may occur).
502 if not is_valid_permutation(self.perm, self.n):
--> 503 raise ValueError("invalid data to initialize a permutation")
504
505 # This is more expensive
ValueError: invalid data to initialize a permutation
How do I rectify the code so as to produce my desired Cayley Graph. Any suggestions?vidyarthiFri, 22 Apr 2022 13:48:42 +0200https://ask.sagemath.org/question/62098/How do we define commutation relations?https://ask.sagemath.org/question/62106/how-do-we-define-commutation-relations/ Let us say I have the following commutation relations for an algebra:
$[J0,J1]=J2$
$[J0,J2]=-J1$
$[J1,J2]=2J0$
I would like to define these commutation relations and do manipulations with them. For example, I would like to calculate
$[J0,[J0,J1]]+[[J1,J2],J1]$.
How do (or, can) we do this in SageMath?
**Bonus question:** Can we find the Casimir operator for this algebra in SageMath?tolgaFri, 22 Apr 2022 23:09:27 +0200https://ask.sagemath.org/question/62106/Define a polynomial subalgebra generated by given polynomialshttps://ask.sagemath.org/question/61717/define-a-polynomial-subalgebra-generated-by-given-polynomials/Given a polynomial algebra in some variables, say $\mathbb{Q}[x_1,x_2,x_3,x_4]$, I'd like to define certain subalgebras that are generated by elements, e.g. $x_4$, $x_3^2-x_2x_4$. So I'd like to define $\mathbb{Q}[x_4,x_3^2-x_2x_4]$. As this uses the variables of the bigger space, I assume it needs to be defined as a subalgebra. But I could not seem to find a way of doing so.
I'm actually just interested in the dimensions of the degree-graded spaces of the subalgebra if that makes it easier.NicconMon, 28 Mar 2022 12:48:28 +0200https://ask.sagemath.org/question/61717/Can I expand a composite function symbolically in sagehttps://ask.sagemath.org/question/60916/can-i-expand-a-composite-function-symbolically-in-sage/ The title says it all really. I think I can use ‘expand’ but can’t work out the syntax. Eg, given f(x) = a polynomial and g(x) = some other bit of algebra can I expand fg(x)nerak99Thu, 03 Feb 2022 08:36:50 +0100https://ask.sagemath.org/question/60916/Ideals in the Group Algebra C[GL(2,R)]https://ask.sagemath.org/question/60868/ideals-in-the-group-algebra-cgl2r/I was hoping to use Sage to determine whether some element is generated by given generators in the group algebra C[GL(2,R)]. However, it went completely wrong when I tried the following naive thing.
sage: G=GL(2,RR)
sage: R=GroupAlgebra(G,CC)
sage: T=R(G([[1,1],[0,1]]))
sage: I=[T-1]*R;
sage: J=[T-1,(T-1)^2]*R;
sage: I==J
False
I thought I defined the ideals in the wrong way so I tried the following as well, which worked out great.
sage: var('t')
sage: R=PolynomialRing(QQ, 't')
sage: I=[R(t)]*R
sage: J=[R(t),R(t^2)]*R;
sage: I==J
True
I was wondering whether I indeed did something wrong or this is just a bug of Sage, and whether there is a way to fix it or bypass it. Thank you so much!
EDIT: There are in fact two issues going around. When I typed this into the Sage (version 8.7) on my computer, it came out as written above. However, when I tried this on the webpage version of Sage, there is this 'is_commutative' error as mentioned by tmonteil in the comment, and I don't know how this error comes up either. In any case, it seems to be impossible to compute ideals in this group algebra.chbeSun, 30 Jan 2022 00:21:43 +0100https://ask.sagemath.org/question/60868/Constructing a non-commutative algebra over Z[q, q^-1] given some relationshttps://ask.sagemath.org/question/60516/constructing-a-non-commutative-algebra-over-zq-q-1-given-some-relations/
I would like to construct a non-commutative alegebra over Z[q, q^-1] generated by the variables u1, u2, u3 with the relations:
u2*u1 = q*u1*u2
u3*u2 = (q^2)*u2*u3
u3*u1 = u1*u3
but I am having some trouble getting this to work. I have primarily been trying to do this using the FreeAlgebra structure. Here is what I have tried:
----------
Zq.<q> = LaurentPolynomialRing(ZZ)
A.<u1,u2, u3> = FreeAlgebra(Zq, 3)
G = A.g_algebra({u2*u1: q*u1*u2, u3*u2: (q**2)*u2*u3})
G
but I get the errors:
AttributeError: 'FreeAlgebra_generic_with_category.element_class' object has no attribute 'lift'
TypeError: unable to coerce <class 'sage.algebras.free_algebra.FreeAlgebra_generic_with_category.element_class'> to `an integer`
----------
Zqring.<q, qinv> = ZZ[]
qideal = Zqring.ideal(q*qinv - 1)
Zq.<q, qinv> = Zqring.quotient(qideal)
A.<u1,u2,u3> = FreeAlgebra(Zq, 3)
I = A.ideal(u2*u1-q*u1*u2, u3*u2-(q**2)*u2*u3, side = "twosided")
W.<u1, u2, u3> = quotient(A,I)
u2*u1-q*u1*u2
but this outputs "(-q)*u1*u2 + u2*u1" and not "0"
----------
Zqring.<q, qinv> = ZZ[]
qideal = Zqring.ideal(q*qinv - 1)
Zq.<q, qinv> = Zqring.quotient(qideal)
A.<u1,u2,u3> = FreeAlgebra(Zq, 3)
I = A*[u2*u1-q*u1*u2]*A
W.<u1,u2,u3> = A.quo(I)
W(u2*u1-q*u1*u2)
and, again, the output is not "0".
Is there a better way I can construct such a non-commutative algebra?
Thanks!kAllenMathSun, 02 Jan 2022 17:22:35 +0100https://ask.sagemath.org/question/60516/How to define tensor product of algebras (and make it an algebra)https://ask.sagemath.org/question/60133/how-to-define-tensor-product-of-algebras-and-make-it-an-algebra/I'm in my first week of Sage (also new to Python). Aiming at symbolic calculations, suppose I have an associative algebra $A$ (think of the Clifford algebra, or the free algebra, for concreteness).
In particular $A$ is a vector space, and I'd like to define a tensor product $A\otimes A$. I've seen that tensor algebra is implemented in SageMath, but I only need two factors, and anyway, I'd like to make $A\otimes A$ an algebra in a way that is *not* endowed with the obvious product $(a\otimes b) \cdot (c\otimes d) = ac\otimes bd$.
(Ideally, the final algebra will depend on a state on $A$, but for simplicity think of my product being, say, $(a\otimes b) \cdot (c\otimes d) = ac\otimes db$.)
An example of how to do what I wish (although not precisely the same object), is along the lines of
[Mathematica Stack Exchange answer 165511](https://mathematica.stackexchange.com/a/165511):
CenterDot[X___, Y_Plus, Z___] := CenterDot[X, #, Z] & /@ Y (* additivity *)
CenterDot[] = 1;
CenterDot[X_] := X
CenterDot[X___, 1, Y___] := CenterDot[X, Y] (* unital*)
SetAttributes[CenterDot, Flat] (* associativity *)
This allows to create a product `CenterDot` that behaves as it should. But in SageMath I need to define the analogue of this on $A\otimes A$ and this is not even clear to me how to define this product. (I.e. if it's not implemented, I probably should do something analogous to the code above, first for $\otimes$, tell it that it has to be bilinear, etc.)c.p.Tue, 07 Dec 2021 11:42:27 +0100https://ask.sagemath.org/question/60133/Select element of a list through the value of an operatorhttps://ask.sagemath.org/question/59544/select-element-of-a-list-through-the-value-of-an-operator/Here follow an occurence of a Fourier-Motzkin elimination.
fmf=[z<=4*x_1+ 3*x_2, x_1 + 3*x_2 <= 2100, 4*x_1+ 2*x_2<=1900, x_1<=200,x_2>=300, x_1 >=0,x_2 >=0]
fmf
fm_sol=solve_ineq(fmf,[x_1, x_2,z])
fm_sol
How can I select only the elements of the list generated by `fm_sol` where the operator for z is `==` ?CyrillePSat, 30 Oct 2021 17:37:22 +0200https://ask.sagemath.org/question/59544/Index problemhttps://ask.sagemath.org/question/57817/index-problem/I am absolutely confused to ask a question that I think to have asked a lot of time but each time I am confused.
I have this simple code
x = list(var('x_%i' % i) for i in (0..1))
show(x)
Ineq = [x[1] + x[0] <= -2, x[1] >=0,x[0] >=0]
show(Ineq)
type(Ineq[0])
sol0=solve_ineq([x[0] + x[1] <= -2, x[1] >=0,x[0] >=0],[x[0],x[1]])
sol0
If I replace `(0..1)` by `(1..2)` whith the correction for the x[i], I have an error of the type `list index out of range`. Why ?CyrilleTue, 29 Jun 2021 22:48:32 +0200https://ask.sagemath.org/question/57817/I am trying to change the ring in sage.https://ask.sagemath.org/question/57808/i-am-trying-to-change-the-ring-in-sage/ I have been able to use .change_ring(FiniteField()) for finite fields. I was instructed to try .change_ring(IntergerModRing()) for other non finite fields but it is not working. What other commands could I try?JSCHWINGTue, 29 Jun 2021 17:15:25 +0200https://ask.sagemath.org/question/57808/Doubt about solve_ineqhttps://ask.sagemath.org/question/57791/doubt-about-solve_ineq/ This question is about the solution of `solve_ineq()`. Here is a simple system of 3 equations :
$x+y >= 3$, $2x-y <=6$ and $3 x-y <= 3$. The graphical representation is given by
f0(x)=3-x
f1(x)=2*x-6
f2(x)=1+(1/3)*x
p=plot(f0(x),x,1.48,3,thickness=3,ticks=None)
p+=plot(f1(x),x,3,4.2,thickness=3,ticks=None)
p+=plot(f2(x),x,1.48,4.2,thickness=3,ticks=None)
sol0=solve(f0==f1,x)
sol1=solve(f0==f2,x)
sol2=solve(f1==f2,x)
p+=point((sol0[0].rhs(),f1(sol0[0].rhs())), rgbcolor=(0.26, 0.80, 0.50),size=60, zorder=10,axes_labels=['$x_1$','$x_2$'])
p+=point((sol1[0].rhs(),f2(sol1[0].rhs())), rgbcolor=(0.26, 0.80, 0.50),size=60, zorder=10)
p+=point((sol2[0].rhs(),f1(sol2[0].rhs())), rgbcolor=(0.26, 0.80, 0.50),size=60, zorder=10)
p+=point((0,f2(sol2[0].rhs())), rgbcolor=(0.99, 0.86, 0.23),size=60, zorder=10)
p+=point((0,0), rgbcolor=(0.99, 0.86, 0.23),size=60, zorder=10)
p+=line([(0,0),(0,f2(sol2[0].rhs()))],rgbcolor=(.5, 0.5, 0.69),thickness=3, zorder=8)
p+=point((sol1[0].rhs(),0), rgbcolor=(1, 0.1, 0.5),size=60, zorder=10)
p+=point((sol2[0].rhs(),0), rgbcolor=(1, 0.1, 0.5),size=60, zorder=10)
p+=line([(sol1[0].rhs(),0),(sol2[0].rhs(),0)],rgbcolor=(1, 0.5, 0.69),thickness=3, zorder=8)
p+=polygon([(sol0[0].rhs(),f1(sol0[0].rhs())),(sol1[0].rhs(),f2(sol1[0].rhs())),(sol2[0].rhs(),f1(sol2[0].rhs()))], rgbcolor=(0.9098, 0.3804, 0))
p+=text("$\\mathrm{Points }\\,\\, \\mathrm{intérieurs}$",(2.8,1.2),color='white')
p+=text("$x_2=3-x_1$",(1.9,.6),rotation=-44.0, horizontal_alignment='left',color='white',fontsize=12)
p+=text("$x_2=2x_1-6$",(3.5,1.2),rotation=62.0, horizontal_alignment='left',color='white',fontsize=12)
p+=text("$0$",(-.15,0.1), horizontal_alignment='center',color='black',fontsize=12)
p+=text("$x_2=1+(1/3)x_1$",(2.4,2.),rotation=18.0, horizontal_alignment='center',color='white',fontsize=12)
p+=text(r"$\mathrm{Elimination}\,\, \mathrm{de}\,\, x_1$",(0.2,1.2),rotation=90.0, horizontal_alignment='center',color='white',fontsize=12)
p+=text(r"$\mathrm{Elimination}\,\, \mathrm{de}\,\, x_2$",(3,-0.4),rotation=0.0, horizontal_alignment='center',color='white',fontsize=12)
p+=line([(sol1[0].rhs(),0),(sol1[0].rhs(),f2(sol1[0].rhs()))],linestyle="--",color='white')
p+=line([(sol1[0].rhs(),0),(sol1[0].rhs(),f2(sol1[0].rhs()))],linestyle="--",color='white')
p+=line([(sol2[0].rhs(),0),(sol2[0].rhs(),f2(sol2[0].rhs())), (0,f2(sol2[0].rhs()))],linestyle="--",color='white')
p+=line([(0,0), (sol1[0].rhs(),0)],linestyle="--",color='black', zorder=8)
p.axes_color('white')
p.axes_label_color('white')
p.tick_label_color('white')
show(p,aspect_ratio=1,transparent=True,ticks=None)
![image description](/upfiles/16248254087668092.png)
The graphic shows clearly the interval of validity when $x$ is eliminated or when it's $y$. Now I use `solve_ineq()` which, if I understand use Maxima Fourier_Motzkin implementation on the same sytem :
var('x y') #déclarer x est facultatif
sol0=solve_ineq([x + y >= 3, 2*x - y <=6, 3*y-x <=3],[x,y])
show(sol0)
sol0[2]
As you can see the solution display the 3 points which are the vertices of the polygon. But if you look at `sol0[2]`, if I am not wrong there is a big mistake because the interval conditions are on $y$ when obviously, according the the graphics and my hand written calculations it should be on $x$
![image description](/upfiles/1624826282905778.png)
His this an error of mine or a bugg ?
CyrilleSun, 27 Jun 2021 22:40:04 +0200https://ask.sagemath.org/question/57791/Is it possible to compute a Gröbner basis of an ideal of a graded commutative algebra in SageMathhttps://ask.sagemath.org/question/57617/is-it-possible-to-compute-a-grobner-basis-of-an-ideal-of-a-graded-commutative-algebra-in-sagemath/Let me start by saying that I am a newbie to Sage.
Let us say I have a graded commutative algebra `A` using the command
`GradedCommutativeAlgebra`, and an ideal `I` of `A`.
For instance, something like the following (but this is just a toy example!):
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=((1,1), (2,1), (3,2))
sage: I = A.ideal([z*y - x*y*y])
I would like to get a Gröbner basis of `I` from SageMath
(not for the previous example, which is immediate).
I know how to do this for polynomial algebras, but for graded
commutative algebras constructed using `GradedCommutativeAlgebra`
this does not seem to work. Is it possible?
Thanks in advance!
EDIT: I slightly changed the previous example to avoid any misunderstanding. I remark that, if one forgets the multidegree of the algebras, the algebras I am interested in (and produced by the command `GradedCommutativeAlgebra`) are super commutative for the underlying Z/2Z grading. In particular, in the previous example, we have `z*z = 0` in `A`, because `z` has total odd degree, and `z*y = - y * z` in `A`, since `y` also has odd degree.EstanislaoFri, 18 Jun 2021 10:54:18 +0200https://ask.sagemath.org/question/57617/Building a homomorphism from group algebra to matrix spacehttps://ask.sagemath.org/question/57568/building-a-homomorphism-from-group-algebra-to-matrix-space/
I would like to define an algebra homomorphism between a group algebra over the integers and a complex matrix space.
More precisely I have a free group F on 4 generators and the associated group algebra G and I would like to construct a homomorphism which sends each of the generators to a certain complex matrix. Inspired by a similar question, I have tried multiple things, but nothing seems to work
I have
F.<A,B,C,D>=FreeGroup(4)
F.inject_variables()
R=MatrixSpace(CC,2)
A1 = matrix(CC,[[0,I],[I,0]])
B1 = matrix(CC,[[I,0],[0,-I]])
C1 = matrix(CC,[[0,1],[-1,0]])
G=GroupAlgebra(F, ZZ)
I would like to define the homomorphism G->R which sends A to A1, B to B1 and both C and D to C1.
cate15Tue, 15 Jun 2021 19:02:04 +0200https://ask.sagemath.org/question/57568/How to interpret Solve_ineq() result ?https://ask.sagemath.org/question/57512/how-to-interpret-solve_ineq-result/For this code
R = PolynomialRing(QQ, 'x', 2)
X = vector(R.gens())
show(X)
A=matrix(QQ,[[1, 2], [-3, 4]])
b=vector(QQ,[[2], [-4]])
show(A,"....", b)
Z=A*X+b
ZZ=[SR(y) for y in Z]
ZZZ=[eq<=0 for eq in ZZ]
Y=[SR(X[i]).variables()[0] for i in range(len(X))]
show(Y)
show(ZZZ)
sol=solve_ineq(ZZZ,[x[0]])
sol
`sol[0]` gives `[x0 == -2*x1 - 2, 5*x1 + 1]`. And here is the question what means `5*x1 + 1` (no equality, inequality ...)
CyrilleWed, 09 Jun 2021 19:56:13 +0200https://ask.sagemath.org/question/57512/multiplication of a polytopehttps://ask.sagemath.org/question/57455/multiplication-of-a-polytope/ I answering to my question `https://ask.sagemath.org/question/57371/how-to-transform-a-derived-set-of-inequation-in-the-good-polyhedron-format/` tmonteil gives me the very nice code
D = polytopes.dodecahedron()
M = matrix([[0,1,0],[0,0,1]])
(M * D).plot()
which do so simply what I was expecting. But as I am curious, I would like to know what is the internal representation of the polyhedra wich permit such product. Hope this is not a too stupid question with a self evident answer.
A second question is : how to translate D in the 3D space ?CyrilleFri, 04 Jun 2021 19:04:27 +0200https://ask.sagemath.org/question/57455/How to transform a derived set of inequation in the good polyhedron formathttps://ask.sagemath.org/question/57371/how-to-transform-a-derived-set-of-inequation-in-the-good-polyhedron-format/This is a follow-up to:
- [Ask Sage question 57318: Use solve with inequality extracted from polytope](https://ask.sagemath.org/question/57318)
- [Ask Sage question 57359: Symbolic expression not scriptable in Solve](https://ask.sagemath.org/question/57359)
- [Ask Sage question 57364: Inequation solution doesn't isolate the operational variable](https://ask.sagemath.org/question/57364)
Applying this code
def one_dimension_less(representationH):
x = list(var('x_%i' % i) for i in (0..2))
sol = [solve_ineq(ieq, [x[0]]) for ieq in Ineq]
sol_r = flatten([x[1] for x in sol])
ineq_ge = [z for z in sol_r if z.rhs() == x[0]]
ineq_le = [z for z in sol_r if z.lhs() == x[0]]
ineq_a = [z for z in sol_r if z.lhs() != x[0] 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))])
# result1 = [result[i].factor() for i in range(len(result))]
return result
to
D = polytopes.dodecahedron()
DH = D.Hrepresentation()
with
PD1 = one_dimension_less(DH)
show(PD1)
I can eliminate one variable and obtain a set of inequalities
defining a polyhedron in a lower dimension
(here I go from 3 to 2 but it can be higher.
For each `x in PD1`, I can isolate its right hand side but I don't
know how to isolate the parameters in such a way to write it as
sage: Polyhedron(ieqs=[(0, 1, 0), (0, 0, 1), (1, -1, -1)]).Hrepresentation()
(An inequality (-1, -1) x + 1 >= 0,
An inequality (1, 0) x + 0 >= 0,
An inequality (0, 1) x + 0 >= 0)`
the lists needed to feed `ieqs` in `Polyhedron`. How to do that?CyrilleMon, 31 May 2021 11:41:12 +0200https://ask.sagemath.org/question/57371/how to calcualte the basis of quotient module over the steenrod algebra in Sagehttps://ask.sagemath.org/question/56943/how-to-calcualte-the-basis-of-quotient-module-over-the-steenrod-algebra-in-sage/ A(2) is steenrod algebra generated by sq1, sq2,sq4 with Adem relations, we knew A(2) has dimension 64, how to calculate the basis like quotient algebra A(2)/A(2){sq1} and A(2)/A(2){sq1,sq2sq3} and A(2)/A(2){sq1, sq7,sq3sq7+sq4sq6} in Sage? Thanks !wittenheTue, 04 May 2021 14:28:08 +0200https://ask.sagemath.org/question/56943/Substitution of an indexed variable in an expressionhttps://ask.sagemath.org/question/56830/substitution-of-an-indexed-variable-in-an-expression/ Until a certain stage of my computation, I do not need indices in my work. Then I want to substitute indexed variables
x,y,p,q=SR.var('x, y, p, q')
A=matrix(SR,2,2,[x,-y,-x,0])
B=matrix(SR,2,2,[-x,y,x,0])
pp = vector(SR,[p, 1-p])
qq = vector(SR,[q, 1-q])
EGe0 = (pp*A*qq).collect(p)
EGp0 = (pp*B*qq).collect(q)
p = var("p", n=10, latex_name='\\overline{p}')
EGe0 = (pp*A*qq).collect(p).substitute_expression(p==p[0])
show(EGe0)
But I certainly have made an error. (I also tried `.subs()`)CyrilleTue, 27 Apr 2021 16:17:43 +0200https://ask.sagemath.org/question/56830/factor symbolic expressionhttps://ask.sagemath.org/question/56805/factor-symbolic-expression/ In the following code, if I add `.collect(p)` to the `pp*A*qq` in the before last expression, I have an error. Why ?
LE=LatexExpr
x,y,p,q=SR.var('x, y, p, q')
A=matrix(SR,2,2,[x,-x,-x,0])
B=matrix(SR,2,2,[-x,y,x,0])
show(LE(r"\boldsymbol{A} = "),A, LE(r"\,\,\,\,\,\text{et}\,\,\,\,\,"),LE(r"\boldsymbol{B} = "),B)
pp = vector(SR,[p, 1-p])
qq = vector(SR,[q, 1-q])
show(LE(r"\boldsymbol{p} = "),pp, LE(r"\,\,\,\,\,\text{et}\,\,\,\,\,"),LE(r"\boldsymbol{q} = "),qq)
EGe0 = pp*A*qq.collect(p)
show(LE(r"\mathbb{E}G_e^0 = "),EGe0)
CyrilleSun, 25 Apr 2021 16:47:57 +0200https://ask.sagemath.org/question/56805/"Ratio" of two elements in a ringhttps://ask.sagemath.org/question/56538/ratio-of-two-elements-in-a-ring/Suppose I have a $\mathbb{Q}$-algebra R, and I have two elements x and y in R. I happen to know that x is a scalar multiple of y. Is there a way to figure out what the scalar is?
In other words, I want to identify the $\mathbb{Q}$-span of y with 1-dimensional vector space, choose an isomorphism of this vector space with $\mathbb{Q}$ (sending y to 1), and see where x goes.
The general context is that R is a finite-dimensional graded $\mathbb{Q}$-algebra (given as a quotient of a polynomial ring), and the top degree piece has dimension 1. I have an isomorphism of this top degree piece with $\mathbb{Q}$ (defined by sending a certain element to 1), and I want to be able to compute what it does to other elements.
An example of such a ring: let $A = \mathbb{Q}[x_1, x_2, x_3, x_4]$. Let $I_1 = (x_1x_3, x_2x_4)$. Let $I_2 = (x_1 + x_3, x_2 + x_4)$. Let $R = A/(I_1 + I_2)$.
(Note that $R$ is the Stanley-Reisner ring of simplicial complex (a triangulation of the circle) modulo a linear system of parameters. So it is graded by degree, and as the simplicial complex is a circle, the degree 2 is a 1-dimensional vector space.)
Let $y = x_1 x_2$, and let $x = (x_1 + x_4)(x_2 + x_3)$. Then x is a scalar multiple of y (as they are both in degree 2), and I would like to know what the scalar is.
(In this case, x = 2y.)
Later edit: fixed typovukovThu, 08 Apr 2021 04:40:24 +0200https://ask.sagemath.org/question/56538/Splitting a matrixhttps://ask.sagemath.org/question/56377/splitting-a-matrix/Dear SAGE community,
I am looking for a way that can help me split this matrix, A
A = matrix([[x], [x - 2*y]]), which is a linear combination of variables x, and y
into a Coefficient matrix, C = matrix([[1, 0], [1, -2]]) times the vector containing independent variables b = matrix([[x], [y]]).
Basically, A = C*b.
If there's a way to obtain the matrix C, would be really helpful.
-TIAApoorvThu, 25 Mar 2021 20:18:08 +0100https://ask.sagemath.org/question/56377/Solve for coefficients of polynomialshttps://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/I want to solve for the coefficients $\alpha(n, m, k)$ an equation that looks like this:
$$
0 = (1 + x + y + z) \\sum_{n, m, k \\in \\{0, 1, \dots, N\\}} \\alpha(n, m, k) x^n y^m z^k
$$
where $\\alpha(n, m, k) \\in \\{0, 1\\}$ and $x^n y^m z^k$
are polynomials over $\mathbb{F}_2$ that satisfy
$x^L = y^L = z^L = 1$ for some integer $L$.
Is there a way to do this in Sage? Notice there are three generators $x,y,$ but the number of coefficents $\alpha$ is $2^{3L}$.
I tried to follow [this](https://ask.sagemath.org/question/51639/equating-coefficients-of-multivariate-polynomials/) answer and wrote this code that failed-
R = PolynomialRing(GF(2),3,"xyz")
x,y,z = R.gens()
S.<a,b,c> = R.quotient((x^2 + 1,y^2+1,z^2+1))
K = PolynomialRing(GF(2),2,'q') # Coefficients
q = K.gens()
Pol = (q[1]*a+q[0])*(a*b)-5*b*a # Equation to solve
I = K.ideal(Pol.coefficients())
I.variety()
And I get the following error:
TypeError Traceback (most recent call last)
<ipython-input-90-e45cccb450b5> in <module>
5 q = K.gens()
6
----> 7 Pol = (q[Integer(1)]*a+q[Integer(0)])*(a*b)-Integer(5)*b*a # Equation to solve
8
9 K.ideal(Pol.coefficients())
/opt/sagemath-9.2/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__mul__ (build/cythonized/sage/structure/element.c:12199)()
1513 return (<Element>left)._mul_(right)
1514 if BOTH_ARE_ELEMENT(cl):
-> 1515 return coercion_model.bin_op(left, right, mul)
1516
1517 cdef long value
/opt/sagemath-9.2/local/lib/python3.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11304)()
1246 # We should really include the underlying error.
1247 # This causes so much headache.
-> 1248 raise bin_op_exception(op, x, y)
1249
1250 cpdef canonical_coercion(self, x, y):
TypeError: unsupported operand parent(s) for *: 'Multivariate Polynomial Ring in q0, q1 over Finite Field of size 2' and 'Quotient of Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 by the ideal (x^2 + 1, y^2 + 1, z^2 + 1)'ofir_arWed, 27 Jan 2021 17:33:29 +0100https://ask.sagemath.org/question/55474/How can I compute a fixed field over the p-adicshttps://ask.sagemath.org/question/55336/how-can-i-compute-a-fixed-field-over-the-p-adics/I have problems to implement the following set up:
I want to have a field $K = \mathbb{Q}_3$ and an extension $L = \mathbb{Q}_3(\alpha)$ over $K$ where $f:=\min_K(\alpha) = x^4 - 3x^2 + 18$. This extension has degree $4$ and ramification index $2$. Furthermore, let $F/K$ be the unique unramified extension of $K$ of degree $4$ which is generated by a primitive $5$-th root of unity $\zeta_5$.
Then one can show that $\varphi: \alpha \mapsto \frac{(2 \alpha^2 - 3)\sqrt{-\frac{2}{7}}}{\alpha},$ $\zeta_5 \mapsto \zeta_5^3$ is an element of the Galois group of $LF/K$. Now let $L' = (LF)^{\langle \varphi \rangle}$. This must be a quadratic and totally ramified extension of $K$. There are only two possibilities for that: $K(\sqrt{3})$ or $K(\sqrt{-3})$.
**Question**: How to determine whether $L' = K(\sqrt{3})$ or $L' = K(\sqrt{-3})$ (or equivalently, $\varphi(\sqrt{3}) = \sqrt{3}$ or $\varphi(\sqrt{-3}) = \sqrt{-3}$)?
Since I only have only superficial knowledge about Sage, I was not even able to set up the easy things like the field $L$ properly. When I use
K = Qp(3)
R.<x> = ZZ[]
f = x^4 - 3*x^2 + 18
L.<alpha> = K.extension(f)
I get an error that my polynomial $f$ must be either unramified or Eisenstein (which of course does not exist since $L/K$ is neither unramified nor totally ramified). Furthermore, I have no idea how to approach with my problem with Sage otherwise. And since computation by hand is pretty hard in this case (I already tried!), it would be nice to solve with problem here, so I can use it for similar computations in the future.
Could you please help me with this problem?RotdatMon, 18 Jan 2021 16:41:46 +0100https://ask.sagemath.org/question/55336/How to do low degree computation in a Free Algebra ?https://ask.sagemath.org/question/55269/how-to-do-low-degree-computation-in-a-free-algebra/Say $F$ is a free algebra over $n$ generators of degree $1$, and i want to compute in this algebra but i only need to get my expressions up to degree $k$. For example, if $k=2$, $(ab +a)*b$ should be $ab$.
For now, i have been doing the computation and truncating everything above degree $k$, but the time complexity is too high when i launch a big computation.
I am actually asking how to compute in the tensor Algebra $T(V)$ modulo $T_{\geq k}(V)$. For free Lie algebras, this can be done using nilpotent Lie algebras, (for example `L = LieAlgebra(QQ, 3, step=3)` implements a 3-nilpotent free Lie algebra). How to do this with free algebras ?qfaesThu, 14 Jan 2021 16:03:58 +0100https://ask.sagemath.org/question/55269/Determine Two quadratic form is integer congruence (rational equivalent)?https://ask.sagemath.org/question/55294/determine-two-quadratic-form-is-integer-congruence-rational-equivalent/Fix $n \\geq 2$ and consider $A,B \\in \\operatorname{GL}(n,\\mathbb{Z}).$
We know that we have the Smith normal form.
One can find $U, V \\in \\operatorname{SL}(n,\\mathbb{Z})$ such that $A=UDV.$
Likewise for $B$. The Smith normal form is easy to compute using Mathematica.
We also call two matrices $A,B$ congruent if there exists
$X \\in \\operatorname{PSL}(n,\\mathbb{Z})$ such that $X^TAX=B$.
Now we have the following: if two matrices are congruent, then they have the same $D$.
But now, given two 4 by 4 matrices with same Smith normal form $D$,
how to verify they are congruent?
An if they are, how to find a matrix $X$ such that $X^T A X = B$.
To be more specific, suppose
$A = \\begin{bmatrix}
2 & -1 & -1 & -1 \\\\
-1 & 2 & 0 & 0 \\\\
-1 & 0 & 2 & 0 \\\\
-1 & 0 & 0 & 2 \\\\
\\end{bmatrix}$
and
$B = \\begin{bmatrix}
4 & -6 & 4 & -2 \\\\
-6 & 12 & -8 & 4 \\\\
4 & -8 & 6 & -3 \\\\
-2 & 4 & -3 & 2 \\\\
\\end{bmatrix}.$
I want to ask whether $A,B$ are congruent. Here is how far I got.
$A$, $B$ both have the same Smith normal form
$D = \\begin{bmatrix}
1 & 0 & 0 & 0 \\\\
0 & 1 & 0 & 0 \\\\
0 & 0 & 2 & 0 \\\\
0 & 0 & 0 & 2 \\\\
\\end{bmatrix}.$
So they define the same integer lattices.
But I do not know whether they are congruent.
I suspect they are congruent but I have no idea how to prove it.
Any ideas or comments are really appreciated.
By the way, $A$ is the Cartan matrix of $SO(8).$
I think it will not help.
I used Sage and typed them in as quadratic forms.
But I found that the `is_rationally_isometric` function only works
for number field but not integers ring (if I use integers,
there will be an error like no real_embedding).
The `is_rationally_isometric` is True.
But I do not know whether they are isometric over the integers.
If the answer is true, can I find such X?
sage: A = QuadraticForm(QQ, 4, [4, -12, 8, -4, 12, -16, 8, 6, -6, 2])
sage: print(A)
sage: A1 = QuadraticForm(QQ, 4, [2, -2, -2, -2, 2, 0, 0, 2, 0, 2])
sage: print(A1)
sage: A1.is_rationally_isometric(A)
TrueGracecatSat, 16 Jan 2021 03:33:07 +0100https://ask.sagemath.org/question/55294/How to compute in the Tensor Algebra $T(V)$ ?https://ask.sagemath.org/question/55256/how-to-compute-in-the-tensor-algebra-tv/I need to make some computations in low degree in the Tensor algebra $T(V)$ of a rational vector space $V$, but i cannot find a good way of doing this. I could use FreeAlgebras, but then i cannot get access to the summands in my element : for example i want to be able to retrieve $a$ $b$ and $c$ from the element $a*b*c $ (whenever the element is homogeneous).
The reason for this is I need to define a 'cycle' function that associates $Wa$ to a tensor $aW$ when $W$ is a tensor and $a \in V$.qfaesWed, 13 Jan 2021 16:21:54 +0100https://ask.sagemath.org/question/55256/Matrix-scalar and vector-scalar operationshttps://ask.sagemath.org/question/54844/matrix-scalar-and-vector-scalar-operations/ Consider :
sage: b=vector([var("b_{}".format(u)) for u in (1..3)])
sage: B=matrix(b).transpose()*matrix(b)
Unsurprisingly :
sage: B*x
[ b_1^2*x b_1*b_2*x b_1*b_3*x]
[b_1*b_2*x b_2^2*x b_2*b_3*x]
[b_1*b_3*x b_2*b_3*x b_3^2*x]
This is less obvious (but intuitively compatible with associativity) :
sage: B+x
[b_1^2 + x b_1*b_2 b_1*b_3]
[ b_1*b_2 b_2^2 + x b_2*b_3]
[ b_1*b_3 b_2*b_3 b_3^2 + x]
This also is unsurprising :
sage: b*x
(b_1*x, b_2*x, b_3*x)
But there is nothing "obviously expectable" from this :
sage: b+x
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-29-58bd66da7aa5> in <module>
----> 1 b+x
/usr/local/sage-9/local/lib/python3.9/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__add__ (build/cythonized/sage/structure/element.c:10988)()
1230 # Left and right are Sage elements => use coercion model
1231 if BOTH_ARE_ELEMENT(cl):
-> 1232 return coercion_model.bin_op(left, right, add)
1233
1234 cdef long value
/usr/local/sage-9/local/lib/python3.9/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11708)()
1248 # We should really include the underlying error.
1249 # This causes so much headache.
-> 1250 raise bin_op_exception(op, x, y)
1251
1252 cpdef canonical_coercion(self, x, y):
TypeError: unsupported operand parent(s) for +: 'Vector space of dimension 3 over Symbolic Ring' and 'Symbolic Ring'
However,
sage: vector([u+x for u in b])
(b_1 + x, b_2 + x, b_3 + x)
would be a possible candidate, but I have trouble visualizing the consequences in the rest of algebraic computation rules in Sage. Is this documented ?Emmanuel CharpentierTue, 22 Dec 2020 21:02:35 +0100https://ask.sagemath.org/question/54844/Erasing some of the decimals in a listhttps://ask.sagemath.org/question/54401/erasing-some-of-the-decimals-in-a-list/ This is a nice table to the reserve of the to long decimals
A=[[10,10,10,10,10,10,10,10,10,10],[100,0,0,0,0,0,0,0,0,0],[11.1,11.1,11.1,11.1,11.1,11.1,11.1,11.1,11.1,0]
,[20,20,20,20,20,0,0,0,0,0],[50,25,12.5,6.25,3.125,1.56,0.78,0.39,0.19,0.09]]
t=table(A,header_row=["$1$","$2$","$3$","$4$","$5$","$6$","$7$","$8$","$9$","$10$"],header_column=["","Équi-Rep","Tout pour un","Un déshérité","Injuste pour 1/2","$5$","Injuste croissante"])
show(t)
I have tried to construct a function `f(x)=round(x,2)` and then to use `A.map_apply(f)` but this doesnot works since
`f(x)=round(x,2)` generates an error. How shouild I do ?CyrilleThu, 26 Nov 2020 19:11:43 +0100https://ask.sagemath.org/question/54401/