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, 29 Nov 2023 16:51:04 +0100Finding projective orders over residual class rings of form Z / (p)^{n} Zhttps://ask.sagemath.org/question/74590/finding-projective-orders-over-residual-class-rings-of-form-z-pn-z/I have been trying to compute the projective order of the matrix M (written below) over residual class ring Z/ (169) Z but my results show it to be 4826796, in contrast to actual order which is 28392. Could someone please suggest something as how to obtain order over Z / (13)^{2} Z ?
a = matrix ([[20,101,52,52,166,148,46,135,96,51,73,49,128], [166, 164, 159, 66, 123, 50, 144, 85, 29, 116, 22, 93, 10],[158, 152, 90, 65, 20, 167, 27, 96, 109, 154, 127, 164, 76],[120, 154, 132, 110, 22, 113, 115, 51, 25, 104, 108, 82, 33],[43, 148, 131, 45, 81, 2, 164, 145, 117, 157, 4, 108, 61],[134, 23, 151, 120, 151, 44, 30, 1, 76, 32, 60, 132, 165],[121, 40, 83, 4, 56, 88, 3, 134, 100, 85, 88, 18, 3],[23, 20, 20, 31, 66, 24, 41, 126, 47, 137, 33, 112, 49], [143, 18, 44, 26, 89, 109, 118, 148, 35, 16, 35, 122, 150], [144, 51, 47, 143, 109, 164, 52, 38, 92, 50, 98, 60, 104],[70, 165, 89, 80, 28, 75, 19, 110, 101, 41, 155, 78, 67],[123, 147, 54, 4, 60, 133, 49, 151, 30, 32, 157, 108, 82], [85, 139, 50, 70, 124, 168, 87, 63, 13, 104, 58, 107, 113]]);
b= mat.identity(13);
c= 73*b;
d= zero_matrix(13, 13);
M= block_matrix([[ a, c], [b, d]]);SwatiWed, 29 Nov 2023 16:51:04 +0100https://ask.sagemath.org/question/74590/Class numbers of cyclotomic fieldshttps://ask.sagemath.org/question/73815/class-numbers-of-cyclotomic-fields/I wrote following program for finding out which ring of integers of cyclotomic fields are unique factorization domains:
max_limit=100
i=3
while i <= max_limit:
K=CyclotomicField(i)
O_K=K.ring_of_integers()
print(i , O_K in UniqueFactorizationDomains())
i=i+1
This gives me output as false for all numbers. But [this wiki article](https://en.wikipedia.org/wiki/List_of_number_fields_with_class_number_one#Cyclotomic_fields) suggests that there are bunch of them for which the class number is actually 1 i.e. the rings are unique factorization domains. I don't understand where I went wrong?atuntuSun, 08 Oct 2023 09:13:13 +0200https://ask.sagemath.org/question/73815/How can I obtain representatives of a quotient ring?https://ask.sagemath.org/question/73816/how-can-i-obtain-representatives-of-a-quotient-ring/ I want to compute quotient of integer ring of $\mathbb{Q}(\omega) (\omega^3=1)$ by a prime ideal $(-4-3\omega)$. Especially I want to compute representatives.
N=3
x=polygen(ZZ,'x')
K.<a>=CyclotomicField(N)
O = K.ring_of_integers()
p=-4-3*a
R.<b,c>=QuotientRing(O, K.ideal(p))
What should I do next?
More, I want to compute its cardinality (=13), But
R.cardinality()
made error.Ys1123Sun, 08 Oct 2023 10:52:01 +0200https://ask.sagemath.org/question/73816/Free algebra identity (empty word) and involutionhttps://ask.sagemath.org/question/73178/free-algebra-identity-empty-word-and-involution/I didn't find the way to define an involution on the free algebra (say in two generators) yet. Specifically I want unitary elements. Thus, I added two variables, $y$ and $z$ which serve as $w^\star,x^\star$ and force a relation so that $w y=1$, the empty word, and similar relation $x z=1$ . But then typing
> A.<w,x,y,z> = FreeAlgebra(QQ,4)
> G=A.g_algebra({w*y: 1})
(x,y,z) =
> G.gens()
yields an error (#This is dirty, coercion is broken). That is: Question: which is the free algebra empty word here?
Of course, I tried to add a symbol $E$ which then satisfies $gE=g=Eg$ for all the generators $g$, But then
> G=A.g_algebra({w*y: E})
yields also an error.
> /usr/lib/python3/dist-packages/sage/algebras/free_algebra.py
> in g_algebra(self, relations, names,
> order, check)
> 873 d_poly = commuted - self(c) * self(m)
> 874 break
> --> 875 assert c_coef is not None, list(m)
> 876 v2_ind = self.gens().index(v2)
> 877 v1_ind = self.gens().index(v1)
>
> AssertionError: [(E, 1)]
Second question: does somebody know an easier way to to implement the involution here?c.p.Wed, 06 Sep 2023 10:53:00 +0200https://ask.sagemath.org/question/73178/Matrices with special spectral propertyhttps://ask.sagemath.org/question/69221/matrices-with-special-spectral-property/```
M = MatrixSpace(ZZ,4,4)
for A in M:
if A.determinant()!=0:
p=A.eigenvalues()
o=list(p)
for e in o:
X = Set([1,2,3,4])
for i,j in X:
if e[i]*e[j]==1:
print(A)
I am trying to find those 4 by 4 nonsingular integer matrices which satisfy the following property: Suppose that if $\lambda$ is an eigenvalue of $A$ iff $\frac{1}{\lambda}$ is also an eigenvalue of $A$ with the same multiplicity as that of $\lambda$. How to obtain that class of matrices?rewiFri, 16 Jun 2023 15:57:41 +0200https://ask.sagemath.org/question/69221/Are there any techniques to improve the results of `simplify` or `full_simplify`?https://ask.sagemath.org/question/68348/are-there-any-techniques-to-improve-the-results-of-simplify-or-full_simplify/(Updated to simplify the starting expression)
I have the following long expression, which I want to simplify for non-negative integer values of `n`:
var('A, B, C, E, α, β, γ')
fn = (
(12*A + 6*B + 4*C + 2*E + 4*α + 2*β + γ)^n
- (11*A + 6*B + 4*C + 2*E + 4*α + 2*β + γ)^n
- (11*A + 5*B + 4*C + 2*E + 4*α + 2*β + γ)^n
+ (10*A + 5*B + 4*C + 2*E + 4*α + 2*β + γ)^n
- (10*A + 5*B + 3*C + 2*E + 4*α + 2*β + γ)^n
+ ( 9*A + 5*B + 3*C + 2*E + 4*α + 2*β + γ)^n
+ ( 9*A + 4*B + 3*C + 2*E + 4*α + 2*β + γ)^n
- ( 8*A + 4*B + 3*C + 2*E + 4*α + 2*β + γ)^n
- ( 8*A + 4*B + 3*C + E + 4*α + 2*β + γ)^n
+ ( 7*A + 4*B + 3*C + E + 4*α + 2*β + γ)^n
+ ( 7*A + 3*B + 3*C + E + 4*α + 2*β + γ)^n
- ( 6*A + 3*B + 3*C + E + 4*α + 2*β + γ)^n
+ ( 6*A + 3*B + 2*C + E + 4*α + 2*β + γ)^n
- ( 6*A + 3*B + 2*C + E + 3*α + 2*β + γ)^n
- ( 6*A + 3*B + 2*C + E + 3*α + β + γ)^n
+ ( 6*A + 3*B + 2*C + E + 2*α + β + γ)^n
- ( 6*A + 3*B + 2*C + E + 2*α + β)^n
+ ( 6*A + 3*B + 2*C + E + α + β)^n
+ ( 6*A + 3*B + 2*C + E + α)^n
- ( 6*A + 3*B + 2*C + E)^n
+ ( 6*A + 3*B + C + E)^n
- ( 5*A + 3*B + C + E)^n
- ( 5*A + 2*B + C + E)^n
+ ( 4*A + 2*B + C + E)^n
+ ( 4*A + 2*B + C)^n
- ( 3*A + 2*B + C)^n
- ( 3*A + B + C)^n
+ ( 2*A + B + C)^n
- ( 2*A + B)^n
+ ( A + B)^n
+ A^n
)/factorial(n)
After replacing all `n`s with `0`s, the command `f0.full_simplify()` returns the correct result of `1`. After replacing all `n`s with `1`s or `2`s, the commands `f1.full_simplify()` or `f2.full_simplify()` return the correct result of `0`.
However, for higher integer values of `n`, the output is no longer fully simplified. The command `f3.full_simplify()` returns the result
2*A^3 + 3*A^2*B + A*B^2 + 2*α^3 + α*β^2 - 4*(A^2 + A*B)*α - (2*A^2 + 2*A*B - 3*α^2)*β - (A^2 + A*B - α^2 - α*β)*γ
which I was able to further simplify manually to get
A*(A + B)*(2*A + B - 4*α - 2*β - γ) + α*(α + β)*(2*α + β + γ)
Similarly, the command `f4.full_simplify()` returns the result
12*A^4 + 24*A^3*B + 15*A^2*B^2 + 3*A*B^3 + 2*(6*A + 3*B + 2*C + E)*α^3 + 4*α^4 + α*β^3 - 8*(A^2 + A*B)*α^2 - (2*A^2 + 2*A*B - (6*A + 3*B + 2*C + E)*α - 5*α^2)*β^2 - 1/2*(A^2 + A*B - α^2 - α*β)*γ^2 + 2*(2*A^3 + 3*A^2*B + A*B^2)*C + (2*A^3 + 3*A^2*B + A*B^2)*E - 2*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α - (10*A^3 + 15*A^2*B + 5*A*B^2 - 3*(6*A + 3*B + 2*C + E)*α^2 - 8*α^3 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E + 8*(A^2 + A*B)*α)*β - 1/2*(10*A^3 + 15*A^2*B + 5*A*B^2 - 2*(6*A + 3*B + 2*C + E)*α^2 - 6*α^3 - 3*α*β^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E + 8*(A^2 + A*B)*α + (4*A^2 + 4*A*B - 2*(6*A + 3*B + 2*C + E)*α - 9*α^2)*β)*γ
which I was able to manually simplify down to
(6*A + 3*B + 2*C + E + 1/2*(4*α + 2*β + γ))*(A*(A + B)*(2*A + B - 4*α - 2*β - γ) + α*(α + β)*(2*α + β + γ))
The command `f5.full_simplify()` returns the even longer result
137/2*A^5 + 685/4*A^4*B + 925/6*A^3*B^2 + 60*A^2*B^3 + 103/12*A*B^4 + 4*(6*A + 3*B + 2*C + E)*α^4 + 9/2*α^5 + 7/12*α*β^4 + 2*(A^2 + A*B)*C^3 + 1/3*(76*A^2 + 76*A*B + 27*B^2 + 36*(2*A + B)*C + 12*C^2 + 6*(6*A + 3*B + 2*C)*E + 3*E^2)*α^3 - 1/3*(4*A^2 + 4*A*B - 3*(6*A + 3*B + 2*C + E)*α - 12*α^2)*β^3 - 1/6*(A^2 + A*B - α^2 - α*β)*γ^3 + 10*(2*A^3 + 3*A^2*B + A*B^2)*C^2 + 1/2*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E^2 - 4*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α^2 - 1/6*(60*A^3 + 90*A^2*B + 30*A*B^2 - 30*(6*A + 3*B + 2*C + E)*α^2 - 61*α^3 + 24*(A^2 + A*B)*C + 12*(A^2 + A*B)*E - 3*(20*A^2 + 20*A*B + 9*B^2 + 12*(2*A + B)*C + 4*C^2 + 2*(6*A + 3*B + 2*C)*E + E^2)*α)*β^2 - 1/4*(10*A^3 + 15*A^2*B + 5*A*B^2 - 2*(6*A + 3*B + 2*C + E)*α^2 - 6*α^3 - 3*α*β^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E + 8*(A^2 + A*B)*α + (4*A^2 + 4*A*B - 2*(6*A + 3*B + 2*C + E)*α - 9*α^2)*β)*γ^2 + 16*(4*A^4 + 8*A^3*B + 5*A^2*B^2 + A*B^3)*C + (28*A^4 + 56*A^3*B + 35*A^2*B^2 + 7*A*B^3 + 3*(A^2 + A*B)*C^2 + 9*(2*A^3 + 3*A^2*B + A*B^2)*C)*E - 1/3*(55*A^4 + 110*A^3*B + 69*A^2*B^2 + 14*A*B^3 + 12*(A^2 + A*B)*C^2 + 6*(A^2 + A*B)*E^2 + 24*(2*A^3 + 3*A^2*B + A*B^2)*C + 6*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E)*α - 1/12*(110*A^4 + 220*A^3*B + 138*A^2*B^2 + 28*A*B^3 - 96*(6*A + 3*B + 2*C + E)*α^3 - 135*α^4 + 24*(A^2 + A*B)*C^2 + 12*(A^2 + A*B)*E^2 - 6*(76*A^2 + 76*A*B + 27*B^2 + 36*(2*A + B)*C + 12*C^2 + 6*(6*A + 3*B + 2*C)*E + 3*E^2)*α^2 + 48*(2*A^3 + 3*A^2*B + A*B^2)*C + 12*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E + 48*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α)*β - 1/12*(55*A^4 + 110*A^3*B + 69*A^2*B^2 + 14*A*B^3 - 36*(6*A + 3*B + 2*C + E)*α^3 - 55*α^4 - 14*α*β^3 + 12*(A^2 + A*B)*C^2 + 6*(A^2 + A*B)*E^2 - 6*(20*A^2 + 20*A*B + 9*B^2 + 12*(2*A + B)*C + 4*C^2 + 2*(6*A + 3*B + 2*C)*E + E^2)*α^2 + 3*(8*A^2 + 8*A*B - 6*(6*A + 3*B + 2*C + E)*α - 23*α^2)*β^2 + 24*(2*A^3 + 3*A^2*B + A*B^2)*C + 6*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E + 24*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α + 2*(60*A^3 + 90*A^2*B + 30*A*B^2 - 27*(6*A + 3*B + 2*C + E)*α^2 - 55*α^3 + 24*(A^2 + A*B)*C + 12*(A^2 + A*B)*E - 3*(20*A^2 + 20*A*B + 9*B^2 + 12*(2*A + B)*C + 4*C^2 + 2*(6*A + 3*B + 2*C)*E + E^2)*α)*β)*γ
and I'm getting tired of manually slogging through these rapidly-increasingly-long expressions to completely simplify them.
**Is there any way to get Sage to do a better job of completely simplifying these expressions?**ZLThu, 11 May 2023 15:58:59 +0200https://ask.sagemath.org/question/68348/Minimal Polynomial over specified fieldhttps://ask.sagemath.org/question/67346/minimal-polynomial-over-specified-field/ Is it possible to get a minimal polynomial over a custom field?
For example, say I define the below:
F.<a,b> = QQ[sqrt(2), sqrt(7)]
p = sqrt(6)
p.minpoly()
This gives me the minimal polynomial of sqrt(6) in QQ,
Is there a way to ask sage for the minimal polynomial of p in F?roeyroeyWed, 05 Apr 2023 18:21:11 +0200https://ask.sagemath.org/question/67346/Is there a way to find the symbolic matrix associated to an expended quadratic form?https://ask.sagemath.org/question/68218/is-there-a-way-to-find-the-symbolic-matrix-associated-to-an-expended-quadratic-form/ Suppose I have a complex quadratic form
$Q(p_x,p_y)=p_y^2 y^2 \alpha^2 - 2 p_x p_y x y \alpha\beta + p_x^2 x^2 \beta^2 - p_y^2 y^2 \alpha -p_x^2 x^2 \beta$
Of course all parameters has been declared as variables, that is
var('p_x p_y x y \alpha \beta')
(I use unicode $\alpha$ and $\beta$)
Is there a way to find the matrix $\boldsymbol{A}$ such that
$Q(\boldsymbol{p})= \boldsymbol{p}^\top \boldsymbol{A}\boldsymbol{p}$ ?CyrilleSat, 06 May 2023 16:35:05 +0200https://ask.sagemath.org/question/68218/Rational quadratic form from invariantshttps://ask.sagemath.org/question/65970/rational-quadratic-form-from-invariants/I'm trying to restore rational quadratic form from invariants using `quadratic_form_from_invariants` function. But why this code doesn't work? I'm taking rational quadratic form invariants and trying to restore it back.
Or am I doing something wrong?
Q = DiagonalQuadraticForm(QQ, [1, -1, -1])
P = [p for p in [-1] + list(prime_range(1000)) if Q.hasse_invariant(p) == -1]
params = Q.dim(), Q.Gram_det(), P, Q.signature_vector()[1]
print(params)
print(quadratic_form_from_invariants(QQ, *params))
It gets results
(3, 1, [-1, 2], 2)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [1], in <cell line: 7>()
4 params = Q.dim(), Q.Gram_det(), P, Q.signature_vector()[Integer(1)]
5 print(params)
----> 7 print(quadratic_form_from_invariants(QQ, *params))
File /home/sc_serv/sage/src/sage/quadratic_forms/quadratic_form.py:154, in quadratic_form_from_invariants(F, rk, det, P, sminus)
152 f = 1
153 if (f + len(P)) % 2 == 1:
--> 154 raise ValueError("invariants do not define a rational quadratic form")
155 D = []
156 while rk >= 2:
ValueError: invariants do not define a rational quadratic form
Thanks!olovoksTue, 17 Jan 2023 23:36:59 +0100https://ask.sagemath.org/question/65970/Constructing Objects in a Categoryhttps://ask.sagemath.org/question/65465/constructing-objects-in-a-category/Suppose I want to define a Hopf algebra H (or group, ring, etc.) and I want it to be an object of the category HopfAlgebras(QQ).
Programming aside, the information need to define a Hopf algebra is the underlying algebra, the comultiplication, antipode, and counit. If H is finitely generated, then I can define the algebra as the quotient of a free algebra, this I know how to do in sage. I can also define the comultiplication, antipode, and counit as ring homorphisms.
How do I use all of this data to make H into an instance of HopfAlgebras(QQ)?NoGoodMathematicianFri, 23 Dec 2022 04:35:09 +0100https://ask.sagemath.org/question/65465/Infinite-dimensional Lie algebras with generators and relationshttps://ask.sagemath.org/question/65416/infinite-dimensional-lie-algebras-with-generators-and-relations/ I need to work with the polynomial current Lie algebra of the general linear Lie algebra, that is $\mathfrak{gl}_N[x]$, which I consider as a complex Lie algebra. In fact I would like to work with its universal enveloping algebra. But the Lie algebra in question is infinite-dimensional. How can I define it by specifying the structure constants? Nikita_SafonkinTue, 20 Dec 2022 10:24:59 +0100https://ask.sagemath.org/question/65416/Poisson and double Poisson bracketshttps://ask.sagemath.org/question/65275/poisson-and-double-poisson-brackets/How can one use some standard Poisson and double Poisson brackets in sagemath?Nikita_SafonkinThu, 08 Dec 2022 08:38:44 +0100https://ask.sagemath.org/question/65275/Inner 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/