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, 01 May 2024 13:08:10 +0200How to generate map in sagehttps://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/As you can see, I'm trying to repeatedly take the map x,y,z to xyx^-1, xzx^-1, (zy+1)x^-1 repeatedly. I'm getting a lot of errors though. Does anyone know how to fix my code? I think It might have something to do with the multiple variables calling the symbol 'x' but idk how else to not cause issues when I'm doing the three different parts of my map (like if I change X then the middle part has the wrong iteration of x).
That was my old question and someone gave me a response and I updated my code. I don't get why my new code doesn't work. If anyone knows how to fix it, or tell me another way to this please let me know!
A = algebras.Free(QQ, list('XYZ'), degrees=(1,1,1))
Ahat = A.completion()
A.inject_variables()
# Define elements x, y, and z
a = Ahat(X)
b = Ahat(Y)
c = Ahat(Z)
# Define the mapping function
def mymap(vx, vy, vz):
return vx * vy * ~vx, vx * vz * ~vx, (vz * vy + 1) * ~vx
# Apply the mapping function with the generators X, Y, and Z
print(mymap(a, b, c))Tue, 30 Apr 2024 00:58:00 +0200https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/Comment by John Palmieri for <p>As you can see, I'm trying to repeatedly take the map x,y,z to xyx^-1, xzx^-1, (zy+1)x^-1 repeatedly. I'm getting a lot of errors though. Does anyone know how to fix my code? I think It might have something to do with the multiple variables calling the symbol 'x' but idk how else to not cause issues when I'm doing the three different parts of my map (like if I change X then the middle part has the wrong iteration of x).</p>
<p>That was my old question and someone gave me a response and I updated my code. I don't get why my new code doesn't work. If anyone knows how to fix it, or tell me another way to this please let me know! </p>
<pre><code>A = algebras.Free(QQ, list('XYZ'), degrees=(1,1,1))
Ahat = A.completion()
A.inject_variables()
# Define elements x, y, and z
a = Ahat(X)
b = Ahat(Y)
c = Ahat(Z)
# Define the mapping function
def mymap(vx, vy, vz):
return vx * vy * ~vx, vx * vz * ~vx, (vz * vy + 1) * ~vx
# Apply the mapping function with the generators X, Y, and Z
print(mymap(a, b, c))
</code></pre>
https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77171#post-id-77171The `completion` method does not introduce inverses of the generators, but (I expect) only inverses of elements with nonzero constant term: elements which can be inverted using power series manipulations.Tue, 30 Apr 2024 20:56:20 +0200https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77171#post-id-77171Comment by Max Alekseyev for <p>As you can see, I'm trying to repeatedly take the map x,y,z to xyx^-1, xzx^-1, (zy+1)x^-1 repeatedly. I'm getting a lot of errors though. Does anyone know how to fix my code? I think It might have something to do with the multiple variables calling the symbol 'x' but idk how else to not cause issues when I'm doing the three different parts of my map (like if I change X then the middle part has the wrong iteration of x).</p>
<p>That was my old question and someone gave me a response and I updated my code. I don't get why my new code doesn't work. If anyone knows how to fix it, or tell me another way to this please let me know! </p>
<pre><code>A = algebras.Free(QQ, list('XYZ'), degrees=(1,1,1))
Ahat = A.completion()
A.inject_variables()
# Define elements x, y, and z
a = Ahat(X)
b = Ahat(Y)
c = Ahat(Z)
# Define the mapping function
def mymap(vx, vy, vz):
return vx * vy * ~vx, vx * vz * ~vx, (vz * vy + 1) * ~vx
# Apply the mapping function with the generators X, Y, and Z
print(mymap(a, b, c))
</code></pre>
https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77168#post-id-77168The given code breaks already at `Ahat = A.completion()` with the error: `AttributeError: 'FreeAlgebra_generic_with_category' object has no attribute 'completion'`Tue, 30 Apr 2024 18:06:36 +0200https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77168#post-id-77168Comment by Max Alekseyev for <p>As you can see, I'm trying to repeatedly take the map x,y,z to xyx^-1, xzx^-1, (zy+1)x^-1 repeatedly. I'm getting a lot of errors though. Does anyone know how to fix my code? I think It might have something to do with the multiple variables calling the symbol 'x' but idk how else to not cause issues when I'm doing the three different parts of my map (like if I change X then the middle part has the wrong iteration of x).</p>
<p>That was my old question and someone gave me a response and I updated my code. I don't get why my new code doesn't work. If anyone knows how to fix it, or tell me another way to this please let me know! </p>
<pre><code>A = algebras.Free(QQ, list('XYZ'), degrees=(1,1,1))
Ahat = A.completion()
A.inject_variables()
# Define elements x, y, and z
a = Ahat(X)
b = Ahat(Y)
c = Ahat(Z)
# Define the mapping function
def mymap(vx, vy, vz):
return vx * vy * ~vx, vx * vz * ~vx, (vz * vy + 1) * ~vx
# Apply the mapping function with the generators X, Y, and Z
print(mymap(a, b, c))
</code></pre>
https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77155#post-id-77155Link to previous question: https://ask.sagemath.org/question/76649Tue, 30 Apr 2024 05:19:59 +0200https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77155#post-id-77155Answer by Max Alekseyev for <p>As you can see, I'm trying to repeatedly take the map x,y,z to xyx^-1, xzx^-1, (zy+1)x^-1 repeatedly. I'm getting a lot of errors though. Does anyone know how to fix my code? I think It might have something to do with the multiple variables calling the symbol 'x' but idk how else to not cause issues when I'm doing the three different parts of my map (like if I change X then the middle part has the wrong iteration of x).</p>
<p>That was my old question and someone gave me a response and I updated my code. I don't get why my new code doesn't work. If anyone knows how to fix it, or tell me another way to this please let me know! </p>
<pre><code>A = algebras.Free(QQ, list('XYZ'), degrees=(1,1,1))
Ahat = A.completion()
A.inject_variables()
# Define elements x, y, and z
a = Ahat(X)
b = Ahat(Y)
c = Ahat(Z)
# Define the mapping function
def mymap(vx, vy, vz):
return vx * vy * ~vx, vx * vz * ~vx, (vz * vy + 1) * ~vx
# Apply the mapping function with the generators X, Y, and Z
print(mymap(a, b, c))
</code></pre>
https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?answer=77177#post-id-77177Here is a code based on [my answer](https://ask.sagemath.org/question/76591/how-to-simplify-non-commutative-expressions/?answer=76594#post-id-76594) to your earlier question:
F.<x,y,z> = FreeGroup()
A = F.algebra(QQ)
X = A(x)
Y = A(y)
Z = A(z)
# invert given element q
def myinv(q):
L = [(t,c) for t,c in q]
if len(L)!=1:
raise ValueError(f'Unable to invert {q}')
return A(L[0][0]^(-1)) / L[0][1]
# Define the mapping function
def mymap(vx, vy, vz):
return (vx * vy * myinv(vx), vx * vz * myinv(vx), (vz * vy + 1) * myinv(vx))
t = (X,Y,Z)
for i in range(6):
t = mymap(*t)
print(f'Iteration {i+1}: {t}')
It produces 3 iterations of `mymap`:
Iteration 1: (x*y*x^-1, x*z*x^-1, x^-1 + z*y*x^-1)
Iteration 2: (x*y*z*y^-1*x^-1, x*y*x^-1*y^-1*x^-1 + x*y*x^-1*z*x^-1, x*y^-1*x^-1 + z*y^-1*x^-1 + z*y*z*y^-1*x^-1)
Iteration 3: (x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1, x*y*z*(y^-1*x^-1)^2 + x*y*z*y^-1*x^-1*z*x^-1 + x*y*z*y^-1*z^-1*y^-1*x^-1, z^-1*y^-1*x^-1 + x*y*z^-1*y^-1*x^-1 + z*x^-1*z^-1*y^-1*x^-1 + z*y*z^-1*y^-1*x^-1 + z*x^-1*z*y*z^-1*y^-1*x^-1 + z*y*z*x^-1*z^-1*y^-1*x^-1 + z*y*z*x^-1*z*y*z^-1*y^-1*x^-1)
Then, however, it fails with the error:
ValueError: Unable to invert x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1
and it is what it is - I do not know how to invert `x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1`.Wed, 01 May 2024 02:51:56 +0200https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?answer=77177#post-id-77177Comment by Max Alekseyev for <p>Here is a code based on <a href="https://ask.sagemath.org/question/76591/how-to-simplify-non-commutative-expressions/?answer=76594#post-id-76594">my answer</a> to your earlier question:</p>
<pre><code>F.<x,y,z> = FreeGroup()
A = F.algebra(QQ)
X = A(x)
Y = A(y)
Z = A(z)
# invert given element q
def myinv(q):
L = [(t,c) for t,c in q]
if len(L)!=1:
raise ValueError(f'Unable to invert {q}')
return A(L[0][0]^(-1)) / L[0][1]
# Define the mapping function
def mymap(vx, vy, vz):
return (vx * vy * myinv(vx), vx * vz * myinv(vx), (vz * vy + 1) * myinv(vx))
t = (X,Y,Z)
for i in range(6):
t = mymap(*t)
print(f'Iteration {i+1}: {t}')
</code></pre>
<p>It produces 3 iterations of <code>mymap</code>:</p>
<pre><code>Iteration 1: (x*y*x^-1, x*z*x^-1, x^-1 + z*y*x^-1)
Iteration 2: (x*y*z*y^-1*x^-1, x*y*x^-1*y^-1*x^-1 + x*y*x^-1*z*x^-1, x*y^-1*x^-1 + z*y^-1*x^-1 + z*y*z*y^-1*x^-1)
Iteration 3: (x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1, x*y*z*(y^-1*x^-1)^2 + x*y*z*y^-1*x^-1*z*x^-1 + x*y*z*y^-1*z^-1*y^-1*x^-1, z^-1*y^-1*x^-1 + x*y*z^-1*y^-1*x^-1 + z*x^-1*z^-1*y^-1*x^-1 + z*y*z^-1*y^-1*x^-1 + z*x^-1*z*y*z^-1*y^-1*x^-1 + z*y*z*x^-1*z^-1*y^-1*x^-1 + z*y*z*x^-1*z*y*z^-1*y^-1*x^-1)
</code></pre>
<p>Then, however, it fails with the error:</p>
<pre><code>ValueError: Unable to invert x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1
</code></pre>
<p>and it is what it is - I do not know how to invert <code>x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1</code>.</p>
https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77182#post-id-77182I'm not sure if using power series was original intention of the OP.Wed, 01 May 2024 13:08:10 +0200https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77182#post-id-77182Comment by rburing for <p>Here is a code based on <a href="https://ask.sagemath.org/question/76591/how-to-simplify-non-commutative-expressions/?answer=76594#post-id-76594">my answer</a> to your earlier question:</p>
<pre><code>F.<x,y,z> = FreeGroup()
A = F.algebra(QQ)
X = A(x)
Y = A(y)
Z = A(z)
# invert given element q
def myinv(q):
L = [(t,c) for t,c in q]
if len(L)!=1:
raise ValueError(f'Unable to invert {q}')
return A(L[0][0]^(-1)) / L[0][1]
# Define the mapping function
def mymap(vx, vy, vz):
return (vx * vy * myinv(vx), vx * vz * myinv(vx), (vz * vy + 1) * myinv(vx))
t = (X,Y,Z)
for i in range(6):
t = mymap(*t)
print(f'Iteration {i+1}: {t}')
</code></pre>
<p>It produces 3 iterations of <code>mymap</code>:</p>
<pre><code>Iteration 1: (x*y*x^-1, x*z*x^-1, x^-1 + z*y*x^-1)
Iteration 2: (x*y*z*y^-1*x^-1, x*y*x^-1*y^-1*x^-1 + x*y*x^-1*z*x^-1, x*y^-1*x^-1 + z*y^-1*x^-1 + z*y*z*y^-1*x^-1)
Iteration 3: (x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1, x*y*z*(y^-1*x^-1)^2 + x*y*z*y^-1*x^-1*z*x^-1 + x*y*z*y^-1*z^-1*y^-1*x^-1, z^-1*y^-1*x^-1 + x*y*z^-1*y^-1*x^-1 + z*x^-1*z^-1*y^-1*x^-1 + z*y*z^-1*y^-1*x^-1 + z*x^-1*z*y*z^-1*y^-1*x^-1 + z*y*z*x^-1*z^-1*y^-1*x^-1 + z*y*z*x^-1*z*y*z^-1*y^-1*x^-1)
</code></pre>
<p>Then, however, it fails with the error:</p>
<pre><code>ValueError: Unable to invert x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1
</code></pre>
<p>and it is what it is - I do not know how to invert <code>x*y*z*x^-1*z^-1*y^-1*x^-1 + x*y*z*x^-1*z*y*z^-1*y^-1*x^-1</code>.</p>
https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77181#post-id-77181That equals `x*y*z*xinv*(1 + z*y)*zinv*yinv*xinv` and the inverse of `1 + z*y` is `1 - z*y + (z*y)^2 - (z*y)^3 + (z*y)^4 + ...`Wed, 01 May 2024 09:24:51 +0200https://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/?comment=77181#post-id-77181