New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FreeGroup
implementation in SymPy
#10350
Changes from 1 commit
45f3cf2
c1c324c
84dc4c3
642d2b0
c3f812e
e6d63ac
2b244c3
65ae08e
428945a
697cf88
cbab81e
a1848de
4512ff4
77e83a8
afde353
21343af
9115376
49a3eff
7daba8c
a96dd7e
a3e2ab5
23d151f
2c40d4d
efeef3d
9f1df56
11037dd
aa11087
15dd87a
a55835b
fc560cb
b3f1053
48158b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,15 +118,15 @@ def _generators(group): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 3, "swapnil" ) | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y, z = free_group("x, y, z") | ||
>>> f.generators | ||
[swapnil0, swapnil1, swapnil2] | ||
[x, y, z] | ||
|
||
""" | ||
gens = [] | ||
for i in range(group.rank): | ||
elm = ((i, 1),) | ||
elm = ((group.symbols[i], 1),) | ||
gens.append(group.dtype(elm)) | ||
return gens | ||
|
||
|
@@ -140,15 +140,6 @@ def __contains__(self, i): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4, "swap" ) | ||
>>> g = FreeGroup( 4, "swapnil" ) | ||
|
||
>>> f[0]**2*f[3] in f | ||
True | ||
>>> f[0]**2*f[3] in g | ||
False | ||
|
||
""" | ||
if not isinstance(i, FreeGroupElm): | ||
raise TypeError("FreeGroup contains only FreeGroupElm as elements " | ||
|
@@ -176,14 +167,6 @@ def __eq__(self, other): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4, "swapnil" ) | ||
>>> g = FreeGroup( 4, "swapnil" ) | ||
>>> f == g | ||
False | ||
>>> f == f | ||
True | ||
|
||
""" | ||
return self is other | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But for the above doctest i have added. It is such that even if the two instances There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see... This behaviour is probably inherited from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you want this behavior to work this way? The whole idea behind There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
|
@@ -221,16 +204,13 @@ def is_abelian(self): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4 ) | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y, z = free_group("x y z") | ||
>>> f.is_abelian | ||
False | ||
|
||
>>> g = FreeGroup( 0 ) | ||
>>> g.is_abelian | ||
True | ||
|
||
""" | ||
# this needs to be tested | ||
if self.rank == 0 or self.rank == 1: | ||
return True | ||
else: | ||
|
@@ -249,15 +229,15 @@ def contains(self, g): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4 ) | ||
>>> f.contains(f[0]**3*f[1]**2) | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y, z = free_group("x y z") | ||
>>> f.contains(x**3*y**2) | ||
True | ||
|
||
""" | ||
if not isinstance(i, FreeGroupElm): | ||
if not isinstance(g, FreeGroupElm): | ||
return False | ||
elif self != i.group: | ||
elif self != g.group: | ||
return False | ||
else: | ||
return True | ||
|
@@ -329,11 +309,11 @@ def array_form(self): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4 ) | ||
>>> (f[0]*f[2]).array_form | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y, z = free_group("x y z") | ||
>>> (x*z).array_form | ||
[(0, 1), (2, 1)] | ||
>>> (f[0]**2*f[2]*f[1]*f[0]**2).array_form | ||
>>> (x**2*z*y*x**2).array_form | ||
[(0, 2), (2, 1), (1, 1), (0, 2)] | ||
|
||
See Also | ||
|
@@ -355,13 +335,13 @@ def letter_form(self): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4 ) | ||
>>> (f[0]**3).letter_form | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b, c, d = free_group("a b c d") | ||
>>> (a**3).letter_form | ||
[1, 1, 1] | ||
>>> (f[0]**2*f[3]**-2*f[0]*f[1]**-4).letter_form | ||
>>> (a**2*d**-2*a*b**-4).letter_form | ||
[1, 1, -4, -4, 1, -2, -2, -2, -2] | ||
>>> (f[0]**-2*f[1]**3*f[3]).letter_form | ||
>>> (a**-2*b**3*d).letter_form | ||
[-1, -1, 2, 2, 2, 4] | ||
|
||
See Also | ||
|
@@ -392,15 +372,15 @@ def __str__(self): | |
for i in range(len(array_form)): | ||
if i == len(array_form) - 1: | ||
if array_form[i][1] == 1: | ||
str_form += str(symbols[array_form[i][0]]) | ||
str_form += str(array_form[i][0]) | ||
else: | ||
str_form += str(symbols[array_form[i][0]]) + \ | ||
str_form += str(array_form[i][0]) + \ | ||
"**" + str(array_form[i][1]) | ||
else: | ||
if array_form[i][1] == 1: | ||
str_form += str(symbols[array_form[i][0]]) + "*" | ||
str_form += str(array_form[i][0]) + "*" | ||
else: | ||
str_form += str(symbols[array_form[i][0]]) + \ | ||
str_form += str(array_form[i][0]) + \ | ||
"**" + str(array_form[i][1]) + "*" | ||
return str_form | ||
|
||
|
@@ -427,13 +407,13 @@ def __mul__(self, other): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4, "swapnil" ) | ||
>>> f[0]*f[1]**2*f[1]**-4 | ||
swapnil0*swapnil1**-2 | ||
>>> f[2]*f[1]**-2 | ||
swapnil2*swapnil1**-2 | ||
>>> (f[0]**2*f[1]*f[1]**-1*f[0]**-2) | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y, z = free_group("x y z") | ||
>>> x*y**2*y**-4 | ||
x*y**-2 | ||
>>> z*y**-2 | ||
z*y**-2 | ||
>>> x**2*y*y**-1*x**-2 | ||
<identity> | ||
|
||
""" | ||
|
@@ -452,19 +432,22 @@ def __mul__(self, other): | |
def __div__(self, other): | ||
return self*(other.inverse()) | ||
|
||
def __rdiv__(self, other): | ||
return other*(self.inverse()) | ||
|
||
def inverse(self): | ||
""" | ||
Returns the inverse of a `FreeGroupElm` element | ||
|
||
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 2, "swapnil" ) | ||
>>> f[0].inverse() | ||
swapnil0**-1 | ||
>>> (f[0]*f[1]).inverse() | ||
swapnil1**-1*swapnil0**-1 | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y, z = free_group("x y z") | ||
>>> x.inverse() | ||
x**-1 | ||
>>> (x*y).inverse() | ||
y**-1*x**-1 | ||
|
||
""" | ||
group = self.group | ||
|
@@ -477,9 +460,9 @@ def order(self): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4 ) | ||
>>> (f[0]**2*f[1]*f[1]**-1*f[0]**-2).order() | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y = free_group("x y") | ||
>>> (x**2*y*y**-1*x**-2).order() | ||
1 | ||
|
||
""" | ||
|
@@ -507,14 +490,13 @@ def eliminate_word(self, gen, by): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 4 ) | ||
>>> w = f[0]**5*f[1]*f[0]**2*f[1]**-4*f[0] | ||
>>> w.eliminate_word( f[0], f[0]**2 ) | ||
f0**10*f1*f0**4*f1**-4*f0**2 | ||
|
||
>>> w.eliminate_word( f[0], f[1]**-1 ) | ||
f1**-11 | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y = free_group("x y") | ||
>>> w = x**5*y*x**2*y**-4*x | ||
>>> w.eliminate_word( x, x**2 ) | ||
x**10*y*x**4*y**-4*x**2 | ||
>>> w.eliminate_word( x, y**-1 ) | ||
y**-5*y*y**-2*y**-4*y**-1 | ||
|
||
""" | ||
group = self.group | ||
|
@@ -540,7 +522,7 @@ def eliminate_word(self, gen, by): | |
|
||
if len(app) > 0: | ||
l.append(tuple(app)) | ||
l = zero_mul_simp(l) | ||
# zero_mul_simp to be used | ||
return group.dtype(l) | ||
|
||
def __len__(self): | ||
|
@@ -550,9 +532,8 @@ def __len__(self): | |
Examples | ||
======== | ||
|
||
>>> from sympy import free_group | ||
>>> f = free_group("x y") | ||
>>> a, b = f[0][0], f[0][1] | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b = free_group("a b") | ||
>>> w = a**5*b*a**2*b**-4*a | ||
>>> len(w) | ||
13 | ||
|
@@ -576,22 +557,22 @@ def __eq__(self, other): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> f = FreeGroup( 2, "swapnil" ) | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, swapnil0, swapnil1 = free_group("swapnil0 swapnil1") | ||
>>> f | ||
<free group on the generators [swapnil0, swapnil1]> | ||
>>> g = FreeGroup( 2 , "swapnil" ) | ||
>>> g, swap0, swap1 = free_group("swap0 swap1") | ||
>>> g | ||
<free group on the generators [swapnil0, swapnil1]> | ||
<free group on the generators [swapl0, swap1]> | ||
|
||
>>> f[0] == f[1] | ||
>>> swapnil0 == swapnil1 | ||
False | ||
>>> f[0]*f[1] == f[1]/f[1]*f[0]*f[1] | ||
>>> swapnil0*swapnil1 == swapnil1/swapnil1*swapnil0*swapnil1 | ||
True | ||
>>> f[0]*f[1] == f[1]*f[0] | ||
>>> swapnil0*swapnil1 == swapnil1*swapnil0 | ||
False | ||
|
||
>>> f[1]**0 == g[0]**0 | ||
>>> swapnil1**0 == swap0**0 | ||
False | ||
|
||
""" | ||
|
@@ -614,11 +595,11 @@ def __lt__(self, other): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> a = FreeGroup( 4, "swapnil" ) | ||
>>> a[1] < a[0] | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b = free_group("a b") | ||
>>> b < a | ||
False | ||
>>> a[0] < a[0].inverse() | ||
>>> a < a.inverse() | ||
False | ||
|
||
""" | ||
|
@@ -657,13 +638,13 @@ def __gt__(self, other): | |
Examples | ||
======== | ||
|
||
>>> from sympy.combinatorics.free_group import FreeGroup | ||
>>> b = FreeGroup( 3, "swapnil" ) | ||
>>> b[1]**2 > b[0]**2 | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, x, y, z = free_group("x y z") | ||
>>> y**2 > x**2 | ||
True | ||
>>> b[1]*b[2] > b[2]*b[1] | ||
>>> y*z > z*y | ||
False | ||
>>> b[0] > b[0].inverse() | ||
>>> x > x.inverse() | ||
True | ||
|
||
""" | ||
|
@@ -687,9 +668,8 @@ def exponent_sum_word(self, gen): | |
Examples | ||
======== | ||
|
||
>>> from sympy import free_group | ||
>>> f = freegroup("x y") | ||
>>> a, b = f[0][0], f[0][1] | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b = free_group("a b") | ||
>>> w = a**5*b*a**2*b**-4*a | ||
>>> w.exponent_sum_word(a) | ||
8 | ||
|
@@ -726,9 +706,8 @@ def subword(self, from_i, to_j): | |
Examples | ||
======== | ||
|
||
>>> from sympy import free_group | ||
>>> f = free_group("x y") | ||
>>> a, b = f[0][0], f[0][1] | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b = free_group("a b") | ||
>>> w = a**5*b*a**2*b**-4*a | ||
>>> w.subword(2, 6) | ||
x**3*y | ||
|
@@ -757,7 +736,7 @@ def number_syllables(self): | |
Examples | ||
======== | ||
|
||
>>> from sympy import free_group | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f = free_group("swapnil0 swapnil1") | ||
>>> swapnil0, swapnil1 = f[0][0], f[0][1] | ||
>>> (swapnil1**3*swapnil0*swapnil1**-1).number_syllables() | ||
|
@@ -774,9 +753,8 @@ def exponent_syllable(self, i): | |
Examples | ||
======== | ||
|
||
>>> from sympy import free_group | ||
>>> f = free_group("x y") | ||
>>> a, b = f[0][0], f[0][1] | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b = free_group("a b") | ||
>>> w = a**5*b*a**2*b**-4*a | ||
>>> w.exponent_syllable( 2 ) | ||
2 | ||
|
@@ -792,9 +770,8 @@ def generator_syllable(self, i): | |
Examples | ||
======== | ||
|
||
>>> from sympy import free_group | ||
>>> f = free_group("x y") | ||
>>> a, b = f[0][0], f[0][1] | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b = free_group("a b") | ||
>>> w = a**5*b*a**2*b**-4*a | ||
>>> w.generator_syllable( 3 ) | ||
1 | ||
|
@@ -812,9 +789,8 @@ def sub_syllables(self, from_i, to_j): | |
Examples | ||
======== | ||
|
||
>>> from sympy import free_group | ||
>>> f = free_group("x y") | ||
>>> a, b = f[0][0], f[0][1] | ||
>>> from sympy.combinatorics.free_group import free_group | ||
>>> f, a, b = free_group("a b") | ||
>>> w = a**5*b*a**2*b**-4*a | ||
>>> w.sub_syllables(1, 2) | ||
f1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
for sym in group.symbols:
.