From 2fda6a490f5993fa8adbf3e4f86959885112a3cf Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 24 Apr 2023 22:42:29 -0700 Subject: [PATCH 01/26] sage.combinat: Add # optional --- src/sage/combinat/backtrack.py | 2 +- src/sage/combinat/combinat.py | 258 +++++++++--------- src/sage/combinat/combination.py | 10 +- src/sage/combinat/combinatorial_map.py | 4 +- src/sage/combinat/composition.py | 73 +++--- src/sage/combinat/permutation.py | 345 +++++++++++++------------ 6 files changed, 358 insertions(+), 334 deletions(-) diff --git a/src/sage/combinat/backtrack.py b/src/sage/combinat/backtrack.py index 565b3efa973..777e511531f 100644 --- a/src/sage/combinat/backtrack.py +++ b/src/sage/combinat/backtrack.py @@ -63,7 +63,7 @@ def __iter__(self): sage: from sage.combinat.permutation import PatternAvoider sage: p = PatternAvoider(Permutations(4), [[1,3,2]]) - sage: len(list(p)) + sage: len(list(p)) # optional - sage.combinat 14 """ # Initialize the stack of generators with the initial data. diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 195ff344e50..c4128a176b8 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -319,17 +319,17 @@ def bell_number(n, algorithm='flint', **options) -> Integer: EXAMPLES:: - sage: bell_number(10) + sage: bell_number(10) # optional - sage.libs.flint 115975 - sage: bell_number(2) + sage: bell_number(2) # optional - sage.libs.flint 2 - sage: bell_number(-10) + sage: bell_number(-10) # optional - sage.libs.flint Traceback (most recent call last): ... ArithmeticError: Bell numbers not defined for negative indices - sage: bell_number(1) + sage: bell_number(1) # optional - sage.libs.flint 1 - sage: bell_number(1/3) + sage: bell_number(1/3) # optional - sage.libs.flint Traceback (most recent call last): ... TypeError: no conversion of this rational to integer @@ -339,17 +339,17 @@ def bell_number(n, algorithm='flint', **options) -> Integer: first time, we deem the precision too low, we use our guess to (temporarily) raise mpmath's precision and the Bell number is recomputed. :: - sage: k = bell_number(30, 'mpmath'); k + sage: k = bell_number(30, 'mpmath'); k # optional - mpmath 846749014511809332450147 - sage: k == bell_number(30) + sage: k == bell_number(30) # optional - mpmath sage.libs.flint True If you knows what precision is necessary before computing the Bell number, you can use the ``prec`` option:: - sage: k2 = bell_number(30, 'mpmath', prec=30); k2 + sage: k2 = bell_number(30, 'mpmath', prec=30); k2 # optional - mpmath 846749014511809332450147 - sage: k == k2 + sage: k == k2 # optional - mpmath True .. WARNING:: @@ -357,18 +357,19 @@ def bell_number(n, algorithm='flint', **options) -> Integer: Running mpmath with the precision set too low can result in incorrect results:: - sage: k = bell_number(30, 'mpmath', prec=15); k + sage: k = bell_number(30, 'mpmath', prec=15); k # optional - mpmath 846749014511809388871680 - sage: k == bell_number(30) + sage: k == bell_number(30) # optional - mpmath False TESTS:: sage: all(bell_number(n) == bell_number(n,'dobinski') for n in range(100)) True - sage: all(bell_number(n) == bell_number(n,'gap') for n in range(100)) + sage: all(bell_number(n) == bell_number(n,'gap') for n in range(100)) # optional - sage.libs.gap True - sage: all(bell_number(n) == bell_number(n,'mpmath', prec=500) for n in range(200, 220)) + sage: all(bell_number(n) == bell_number(n,'mpmath', prec=500) # optional - mpmath sage.libs.flint + ....: for n in range(200, 220)) True AUTHORS: @@ -547,12 +548,12 @@ def euler_number(n, algorithm='flint') -> Integer: EXAMPLES:: - sage: [euler_number(i) for i in range(10)] + sage: [euler_number(i) for i in range(10)] # optional - sage.libs.flint [1, 0, -1, 0, 5, 0, -61, 0, 1385, 0] sage: x = PowerSeriesRing(QQ, 'x').gen().O(10) sage: 2/(exp(x)+exp(-x)) 1 - 1/2*x^2 + 5/24*x^4 - 61/720*x^6 + 277/8064*x^8 + O(x^10) - sage: [euler_number(i)/factorial(i) for i in range(11)] + sage: [euler_number(i)/factorial(i) for i in range(11)] # optional - sage.libs.flint [1, 0, -1/2, 0, 5/24, 0, -61/720, 0, 277/8064, 0, -50521/3628800] sage: euler_number(-1) Traceback (most recent call last): @@ -561,7 +562,7 @@ def euler_number(n, algorithm='flint') -> Integer: TESTS:: - sage: euler_number(6, 'maxima') + sage: euler_number(6, 'maxima') # optional - sage.symbolic -61 REFERENCES: @@ -705,21 +706,21 @@ def fibonacci(n, algorithm="pari") -> Integer: EXAMPLES:: - sage: fibonacci(10) + sage: fibonacci(10) # optional - sage.libs.pari 55 - sage: fibonacci(10, algorithm='gap') + sage: fibonacci(10, algorithm='gap') # optional - sage.libs.gap 55 :: - sage: fibonacci(-100) + sage: fibonacci(-100) # optional - sage.libs.pari -354224848179261915075 - sage: fibonacci(100) + sage: fibonacci(100) # optional - sage.libs.pari 354224848179261915075 :: - sage: fibonacci(0) + sage: fibonacci(0) # optional - sage.libs.pari 0 sage: fibonacci(1/2) Traceback (most recent call last): @@ -758,17 +759,17 @@ def lucas_number1(n, P, Q): EXAMPLES:: - sage: lucas_number1(5,1,-1) + sage: lucas_number1(5,1,-1) # optional - sage.libs.gap 5 - sage: lucas_number1(6,1,-1) + sage: lucas_number1(6,1,-1) # optional - sage.libs.gap 8 - sage: lucas_number1(7,1,-1) + sage: lucas_number1(7,1,-1) # optional - sage.libs.gap 13 - sage: lucas_number1(7,1,-2) + sage: lucas_number1(7,1,-2) # optional - sage.libs.gap 43 - sage: lucas_number1(5,2,3/5) + sage: lucas_number1(5,2,3/5) # optional - sage.libs.gap 229/25 - sage: lucas_number1(5,2,1.5) + sage: lucas_number1(5,2,1.5) # optional - sage.libs.gap 1/4 There was a conjecture that the sequence `L_n` defined by @@ -776,8 +777,9 @@ def lucas_number1(n, P, Q): `L_2=3`, has the property that `n` prime implies that `L_n` is prime. :: - sage: lucas = lambda n : Integer((5/2)*lucas_number1(n,1,-1)+(1/2)*lucas_number2(n,1,-1)) - sage: [[lucas(n),is_prime(lucas(n)),n+1,is_prime(n+1)] for n in range(15)] + sage: def lucas(n): + ....: return Integer((5/2)*lucas_number1(n,1,-1) + (1/2)*lucas_number2(n,1,-1)) + sage: [[lucas(n), is_prime(lucas(n)), n+1, is_prime(n+1)] for n in range(15)] # optional - sage.libs.gap [[1, False, 1, False], [3, True, 2, True], [4, False, 3, True], @@ -825,26 +827,26 @@ def lucas_number2(n, P, Q): EXAMPLES:: - sage: [lucas_number2(i,1,-1) for i in range(10)] + sage: [lucas_number2(i,1,-1) for i in range(10)] # optional - sage.libs.gap [2, 1, 3, 4, 7, 11, 18, 29, 47, 76] - sage: [fibonacci(i-1)+fibonacci(i+1) for i in range(10)] + sage: [fibonacci(i-1)+fibonacci(i+1) for i in range(10)] # optional - sage.libs.pari [2, 1, 3, 4, 7, 11, 18, 29, 47, 76] :: - sage: n = lucas_number2(5,2,3); n + sage: n = lucas_number2(5,2,3); n # optional - sage.libs.gap 2 - sage: type(n) + sage: type(n) # optional - sage.libs.gap - sage: n = lucas_number2(5,2,-3/9); n + sage: n = lucas_number2(5,2,-3/9); n # optional - sage.libs.gap 418/9 - sage: type(n) + sage: type(n) # optional - sage.libs.gap The case `P=1`, `Q=-1` is the Lucas sequence in Brualdi's Introductory Combinatorics, 4th ed., Prentice-Hall, 2004:: - sage: [lucas_number2(n,1,-1) for n in range(10)] + sage: [lucas_number2(n,1,-1) for n in range(10)] # optional - sage.libs.gap [2, 1, 3, 4, 7, 11, 18, 29, 47, 76] """ n = ZZ(n) @@ -873,20 +875,20 @@ def stirling_number1(n, k, algorithm="gap") -> Integer: EXAMPLES:: - sage: stirling_number1(3,2) + sage: stirling_number1(3,2) # optional - sage.libs.gap 3 - sage: stirling_number1(5,2) + sage: stirling_number1(5,2) # optional - sage.libs.gap 50 - sage: 9*stirling_number1(9,5)+stirling_number1(9,4) + sage: 9*stirling_number1(9,5) + stirling_number1(9,4) # optional - sage.libs.gap 269325 - sage: stirling_number1(10,5) + sage: stirling_number1(10,5) # optional - sage.libs.gap 269325 Indeed, `S_1(n,k) = S_1(n-1,k-1) + (n-1)S_1(n-1,k)`. TESTS:: - sage: stirling_number1(10,5, algorithm='flint') + sage: stirling_number1(10,5, algorithm='flint') # optional - sage.libs.flint 269325 sage: s_sage = stirling_number1(50,3, algorithm="mutta") @@ -975,20 +977,17 @@ def stirling_number2(n, k, algorithm=None) -> Integer: 13707767141249454929449108424328432845001327479099713037876832759323918134840537229737624018908470350134593241314462032607787062188356702932169472820344473069479621239187226765307960899083230982112046605340713218483809366970996051181537181362810003701997334445181840924364501502386001705718466534614548056445414149016614254231944272872440803657763210998284198037504154374028831561296154209804833852506425742041757849726214683321363035774104866182331315066421119788248419742922490386531970053376982090046434022248364782970506521655684518998083846899028416459701847828711541840099891244700173707021989771147674432503879702222276268661726508226951587152781439224383339847027542755222936463527771486827849728880 sage: stirling_number2(500,31) 5832088795102666690960147007601603328246123996896731854823915012140005028360632199516298102446004084519955789799364757997824296415814582277055514048635928623579397278336292312275467402957402880590492241647229295113001728653772550743446401631832152281610081188041624848850056657889275564834450136561842528589000245319433225808712628826136700651842562516991245851618481622296716433577650218003181535097954294609857923077238362717189185577756446945178490324413383417876364657995818830270448350765700419876347023578011403646501685001538551891100379932684279287699677429566813471166558163301352211170677774072447414719380996777162087158124939742564291760392354506347716119002497998082844612434332155632097581510486912 - sage: n = stirling_number2(20,11) - sage: n + sage: n = stirling_number2(20,11); n 1900842429486 sage: type(n) - sage: n = stirling_number2(20,11,algorithm='gap') - sage: n + sage: n = stirling_number2(20, 11, algorithm='gap'); n # optional - sage.libs.gap 1900842429486 - sage: type(n) + sage: type(n) # optional - sage.libs.gap - sage: n = stirling_number2(20,11,algorithm='flint') - sage: n + sage: n = stirling_number2(20, 11, algorithm='flint'); n # optional - sage.libs.flint 1900842429486 - sage: type(n) + sage: type(n) # optional - sage.libs.flint Sage's implementation splitting the computation of the Stirling @@ -997,7 +996,7 @@ def stirling_number2(n, k, algorithm=None) -> Integer: For `n<200`:: - sage: for n in Subsets(range(100,200), 5).random_element(): + sage: for n in Subsets(range(100,200), 5).random_element(): # optional - sage.libs.flint sage.libs.gap ....: for k in Subsets(range(n), 5).random_element(): ....: s_sage = stirling_number2(n,k) ....: s_flint = stirling_number2(n,k, algorithm = "flint") @@ -1007,7 +1006,7 @@ def stirling_number2(n, k, algorithm=None) -> Integer: For `n\geq 200`:: - sage: for n in Subsets(range(200,300), 5).random_element(): + sage: for n in Subsets(range(200,300), 5).random_element(): # optional - sage.libs.flint sage.libs.gap ....: for k in Subsets(range(n), 5).random_element(): ....: s_sage = stirling_number2(n,k) ....: s_flint = stirling_number2(n,k, algorithm = "flint") @@ -1015,10 +1014,10 @@ def stirling_number2(n, k, algorithm=None) -> Integer: ....: if not (s_sage == s_flint and s_sage == s_gap): ....: print("Error with n<200") - sage: stirling_number2(20,3, algorithm="maxima") + sage: stirling_number2(20, 3, algorithm="maxima") # optional - sage.symbolic 580606446 - sage: s_sage = stirling_number2(5,3, algorithm="namba") + sage: s_sage = stirling_number2(5, 3, algorithm="namba") Traceback (most recent call last): ... ValueError: unknown algorithm: namba @@ -1174,11 +1173,11 @@ def __init__(self, l, copy=True): Test indirectly that we copy the input (see :trac:`18184`):: - sage: L = IntegerListsLex(element_class=Partition) - sage: x = [3, 2, 1] - sage: P = L(x) - sage: x[0] = 5 - sage: list(P) + sage: L = IntegerListsLex(element_class=Partition) # optional - sage.combinat + sage: x = [3, 2, 1] # optional - sage.combinat + sage: P = L(x) # optional - sage.combinat + sage: x[0] = 5 # optional - sage.combinat + sage: list(P) # optional - sage.combinat [3, 2, 1] """ if copy: @@ -1616,7 +1615,7 @@ def is_finite(self) -> bool: EXAMPLES:: - sage: Partitions(5).is_finite() + sage: Partitions(5).is_finite() # optional - sage.combinat True sage: Permutations().is_finite() False @@ -1650,7 +1649,7 @@ def __str__(self) -> str: EXAMPLES:: - sage: str(Partitions(5)) + sage: str(Partitions(5)) # optional - sage.combinat 'Partitions of the integer 5' """ return repr(self) @@ -1659,7 +1658,7 @@ def _repr_(self) -> str: """ EXAMPLES:: - sage: repr(Partitions(5)) # indirect doctest + sage: repr(Partitions(5)) # indirect doctest # optional - sage.combinat 'Partitions of the integer 5' """ if hasattr(self, '_name') and self._name: @@ -1682,7 +1681,7 @@ def __contains__(self, x) -> bool: EXAMPLES:: sage: C = CombinatorialClass() - sage: x in C + sage: x in C # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError @@ -1697,11 +1696,11 @@ def __eq__(self, other): EXAMPLES:: - sage: p5 = Partitions(5) - sage: p6 = Partitions(6) - sage: repr(p5) == repr(p6) + sage: p5 = Partitions(5) # optional - sage.combinat + sage: p6 = Partitions(6) # optional - sage.combinat + sage: repr(p5) == repr(p6) # optional - sage.combinat False - sage: p5 == p6 + sage: p5 == p6 # optional - sage.combinat False """ return repr(self) == repr(other) @@ -1712,9 +1711,9 @@ def __ne__(self, other): EXAMPLES:: - sage: p5 = Partitions(5) - sage: p6 = Partitions(6) - sage: p5 != p6 + sage: p5 = Partitions(5) # optional - sage.combinat + sage: p6 = Partitions(6) # optional - sage.combinat + sage: p5 != p6 # optional - sage.combinat True """ return not (self == other) @@ -1766,14 +1765,14 @@ def __call__(self, x): EXAMPLES:: - sage: p5 = Partitions(5) - sage: a = [2,2,1] - sage: type(a) + sage: p5 = Partitions(5) # optional - sage.combinat + sage: a = [2,2,1] # optional - sage.combinat + sage: type(a) # optional - sage.combinat - sage: a = p5(a) - sage: type(a) + sage: a = p5(a) # optional - sage.combinat + sage: type(a) # optional - sage.combinat - sage: p5([2,1]) + sage: p5([2,1]) # optional - sage.combinat Traceback (most recent call last): ... ValueError: [2, 1] is not an element of Partitions of the integer 5 @@ -1795,8 +1794,8 @@ def element_class(self): TESTS:: - sage: P5 = Partitions(5) - sage: P5.element_class + sage: P5 = Partitions(5) # optional - sage.combinat + sage: P5.element_class # optional - sage.combinat """ # assert not isinstance(self, Parent) # Raises an alert if we override the proper definition from Parent @@ -1811,9 +1810,9 @@ def _element_constructor_(self, x): TESTS:: - sage: P5 = Partitions(5) - sage: p = P5([3,2]) # indirect doctest - sage: type(p) + sage: P5 = Partitions(5) # optional - sage.combinat + sage: p = P5([3,2]) # indirect doctest # optional - sage.combinat + sage: type(p) # optional - sage.combinat """ # assert not isinstance(self, Parent) # Raises an alert if we override the proper definition from Parent @@ -1829,7 +1828,7 @@ def __list_from_iterator(self): sage: class C(CombinatorialClass): ....: def __iter__(self): ....: return iter([1,2,3]) - sage: C().list() #indirect doctest + sage: C().list() #indirect doctest [1, 2, 3] """ return [x for x in self] @@ -1949,8 +1948,8 @@ def __iter__(self): EXAMPLES:: - sage: p5 = Partitions(5) - sage: [i for i in p5] + sage: p5 = Partitions(5) # optional - sage.combinat + sage: [i for i in p5] # optional - sage.combinat [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]] sage: C = CombinatorialClass() sage: iter(C) @@ -2117,7 +2116,7 @@ def filter(self, f, name=None): sage: from sage.combinat.combinat import Permutations_CC sage: P = Permutations_CC(3).filter(lambda x: x.avoids([1,2])) - sage: P.list() + sage: P.list() # optional - sage.combinat [[3, 2, 1]] """ return FilteredCombinatorialClass(self, f, name=name) @@ -2151,7 +2150,8 @@ class by `f`, as a combinatorial class. EXAMPLES:: sage: R = Permutations(3).map(attrcall('reduced_word')); R - Image of Standard permutations of 3 by The map *.reduced_word() from Standard permutations of 3 + Image of Standard permutations of 3 by + The map *.reduced_word() from Standard permutations of 3 sage: R.cardinality() 6 sage: R.list() @@ -2161,15 +2161,15 @@ class by `f`, as a combinatorial class. If the function is not injective, then there may be repeated elements:: - sage: P = Partitions(4) - sage: P.list() + sage: P = Partitions(4) # optional - sage.combinat + sage: P.list() # optional - sage.combinat [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]] - sage: P.map(len).list() + sage: P.map(len).list() # optional - sage.combinat [1, 2, 2, 3, 4] Use ``is_injective=False`` to get a correct result in this case:: - sage: P.map(len, is_injective=False).list() + sage: P.map(len, is_injective=False).list() # optional - sage.combinat [1, 2, 3, 4] TESTS:: @@ -2238,7 +2238,7 @@ def cardinality(self) -> Integer: sage: from sage.combinat.combinat import Permutations_CC sage: P = Permutations_CC(3).filter(lambda x: x.avoids([1,2])) - sage: P.cardinality() + sage: P.cardinality() # optional - sage.combinat 1 """ c = 0 @@ -2252,7 +2252,7 @@ def __iter__(self) -> Iterator: sage: from sage.combinat.combinat import Permutations_CC sage: P = Permutations_CC(3).filter(lambda x: x.avoids([1,2])) - sage: list(P) + sage: list(P) # optional - sage.combinat [[3, 2, 1]] """ for x in self.combinatorial_class: @@ -2481,13 +2481,13 @@ class MapCombinatorialClass(ImageSubobject, CombinatorialClass): EXAMPLES:: - sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) - sage: R.an_element() + sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) # optional - sage.groups + sage: R.an_element() # optional - sage.groups [9, 8, 7, 6, 5, 4, 3, 2] - sage: R.cardinality() + sage: R.cardinality() # optional - sage.groups 3628800 - sage: i = iter(R) - sage: next(i), next(i), next(i) + sage: i = iter(R) # optional - sage.groups + sage: next(i), next(i), next(i) # optional - sage.groups ([], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1]) """ @@ -2625,9 +2625,9 @@ def tuples(S, k, algorithm='itertools'): :: - sage: K. = GF(4, 'a') - sage: mset = [x for x in K if x != 0] - sage: tuples(mset, 2) + sage: K. = GF(4, 'a') # optional - sage.rings.finite_rings + sage: mset = [x for x in K if x != 0] # optional - sage.rings.finite_rings + sage: tuples(mset, 2) # optional - sage.rings.finite_rings [(a, a), (a, a + 1), (a, 1), (a + 1, a), (a + 1, a + 1), (a + 1, 1), (1, a), (1, a + 1), (1, 1)] @@ -2711,16 +2711,16 @@ def number_of_tuples(S, k, algorithm='naive') -> Integer: sage: S = [1,2,3,4,5] sage: number_of_tuples(S,2) 25 - sage: number_of_tuples(S,2, algorithm="gap") + sage: number_of_tuples(S,2, algorithm="gap") # optional - sage.libs.gap 25 sage: S = [1,1,2,3,4,5] sage: number_of_tuples(S,2) 25 - sage: number_of_tuples(S,2, algorithm="gap") + sage: number_of_tuples(S,2, algorithm="gap") # optional - sage.libs.gap 25 sage: number_of_tuples(S,0) 1 - sage: number_of_tuples(S,0, algorithm="gap") + sage: number_of_tuples(S,0, algorithm="gap") # optional - sage.libs.gap 1 """ if algorithm == 'naive': @@ -2772,7 +2772,7 @@ def unordered_tuples(S, k, algorithm='itertools'): We check that this agrees with GAP:: - sage: unordered_tuples(S, 3, algorithm='gap') + sage: unordered_tuples(S, 3, algorithm='gap') # optional - sage.libs.gap [(1, 1, 1), (1, 1, 2), (1, 2, 2), (2, 2, 2)] We check the result on strings:: @@ -2780,13 +2780,13 @@ def unordered_tuples(S, k, algorithm='itertools'): sage: S = ["a","b","c"] sage: unordered_tuples(S, 2) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] - sage: unordered_tuples(S, 2, algorithm='gap') + sage: unordered_tuples(S, 2, algorithm='gap') # optional - sage.libs.gap [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] Lastly we check on a multiset:: sage: S = [1,1,2] - sage: unordered_tuples(S, 3) == unordered_tuples(S, 3, 'gap') + sage: unordered_tuples(S, 3) == unordered_tuples(S, 3, 'gap') # optional - sage.libs.gap True sage: unordered_tuples(S, 3) [(1, 1, 1), (1, 1, 2), (1, 2, 2), (2, 2, 2)] @@ -2827,16 +2827,16 @@ def number_of_unordered_tuples(S, k, algorithm='naive') -> Integer: sage: S = [1,2,3,4,5] sage: number_of_unordered_tuples(S,2) 15 - sage: number_of_unordered_tuples(S,2, algorithm="gap") + sage: number_of_unordered_tuples(S,2, algorithm="gap") # optional - sage.libs.gap 15 sage: S = [1,1,2,3,4,5] sage: number_of_unordered_tuples(S,2) 15 - sage: number_of_unordered_tuples(S,2, algorithm="gap") + sage: number_of_unordered_tuples(S,2, algorithm="gap") # optional - sage.libs.gap 15 sage: number_of_unordered_tuples(S,0) 1 - sage: number_of_unordered_tuples(S,0, algorithm="gap") + sage: number_of_unordered_tuples(S,0, algorithm="gap") # optional - sage.libs.gap 1 """ if algorithm == 'naive': @@ -2936,19 +2936,19 @@ def bell_polynomial(n: Integer, k: Integer): EXAMPLES:: - sage: bell_polynomial(6,2) + sage: bell_polynomial(6,2) # optional - sage.combinat 10*x2^2 + 15*x1*x3 + 6*x0*x4 - sage: bell_polynomial(6,3) + sage: bell_polynomial(6,3) # optional - sage.combinat 15*x1^3 + 60*x0*x1*x2 + 15*x0^2*x3 TESTS: Check that :trac:`18338` is fixed:: - sage: bell_polynomial(0,0).parent() + sage: bell_polynomial(0,0).parent() # optional - sage.combinat Multivariate Polynomial Ring in x over Integer Ring - sage: for n in (0..4): + sage: for n in (0..4): # optional - sage.combinat ....: print([bell_polynomial(n,k).coefficients() for k in (0..n)]) [[1]] [[], [1]] @@ -2999,13 +2999,12 @@ def fibonacci_sequence(start, stop=None, algorithm=None) -> Iterator: EXAMPLES:: - sage: fibs = [i for i in fibonacci_sequence(10, 20)] - sage: fibs + sage: fibs = [i for i in fibonacci_sequence(10, 20)]; fibs # optional - sage.libs.pari [55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181] :: - sage: sum([i for i in fibonacci_sequence(100, 110)]) + sage: sum([i for i in fibonacci_sequence(100, 110)]) # optional - sage.libs.pari 69919376923075308730013 .. SEEALSO:: @@ -3039,26 +3038,25 @@ def fibonacci_xrange(start, stop=None, algorithm='pari') -> Iterator: EXAMPLES:: - sage: fibs_in_some_range = [i for i in fibonacci_xrange(10^7, 10^8)] - sage: len(fibs_in_some_range) + sage: fibs_in_some_range = [i for i in fibonacci_xrange(10^7, 10^8)] # optional - sage.libs.pari + sage: len(fibs_in_some_range) # optional - sage.libs.pari 4 - sage: fibs_in_some_range + sage: fibs_in_some_range # optional - sage.libs.pari [14930352, 24157817, 39088169, 63245986] :: - sage: fibs = [i for i in fibonacci_xrange(10, 100)] - sage: fibs + sage: fibs = [i for i in fibonacci_xrange(10, 100)]; fibs # optional - sage.libs.pari [13, 21, 34, 55, 89] :: - sage: list(fibonacci_xrange(13, 34)) + sage: list(fibonacci_xrange(13, 34)) # optional - sage.libs.pari [13, 21] A solution to the second Project Euler problem:: - sage: sum([i for i in fibonacci_xrange(10^6) if is_even(i)]) + sage: sum([i for i in fibonacci_xrange(10^6) if is_even(i)]) # optional - sage.libs.pari 1089154 .. SEEALSO:: @@ -3116,30 +3114,30 @@ def bernoulli_polynomial(x, n: Integer): EXAMPLES:: sage: y = QQ['y'].0 - sage: bernoulli_polynomial(y, 5) + sage: bernoulli_polynomial(y, 5) # optional - sage.libs.flint y^5 - 5/2*y^4 + 5/3*y^3 - 1/6*y - sage: bernoulli_polynomial(y, 5)(12) + sage: bernoulli_polynomial(y, 5)(12) # optional - sage.libs.flint 199870 - sage: bernoulli_polynomial(12, 5) + sage: bernoulli_polynomial(12, 5) # optional - sage.libs.flint 199870 - sage: bernoulli_polynomial(y^2 + 1, 5) + sage: bernoulli_polynomial(y^2 + 1, 5) # optional - sage.libs.flint y^10 + 5/2*y^8 + 5/3*y^6 - 1/6*y^2 sage: P. = ZZ[] - sage: p = bernoulli_polynomial(t, 6) - sage: p.parent() + sage: p = bernoulli_polynomial(t, 6) # optional - sage.libs.flint + sage: p.parent() # optional - sage.libs.flint Univariate Polynomial Ring in t over Rational Field We verify an instance of the formula which is the origin of the Bernoulli polynomials (and numbers):: sage: power_sum = sum(k^4 for k in range(10)) - sage: 5*power_sum == bernoulli_polynomial(10, 5) - bernoulli(5) + sage: 5*power_sum == bernoulli_polynomial(10, 5) - bernoulli(5) # optional - sage.libs.flint True TESTS:: sage: x = polygen(QQ, 'x') - sage: bernoulli_polynomial(x, 0).parent() + sage: bernoulli_polynomial(x, 0).parent() # optional - sage.libs.flint Univariate Polynomial Ring in x over Rational Field REFERENCES: diff --git a/src/sage/combinat/combination.py b/src/sage/combinat/combination.py index 42e727c6877..fc8b044d89d 100644 --- a/src/sage/combinat/combination.py +++ b/src/sage/combinat/combination.py @@ -148,15 +148,15 @@ class of combinations of ``mset`` of size ``k``. It is possible to take combinations of Sage objects:: - sage: Combinations([vector([1,1]), vector([2,2]), vector([3,3])], 2).list() + sage: Combinations([vector([1,1]), vector([2,2]), vector([3,3])], 2).list() # optional - sage.modules [[(1, 1), (2, 2)], [(1, 1), (3, 3)], [(2, 2), (3, 3)]] TESTS: We check that the code works even for non mutable objects:: - sage: l = [vector((0,0)), vector((0,1))] - sage: Combinations(l).list() + sage: l = [vector((0,0)), vector((0,1))] # optional - sage.modules + sage: Combinations(l).list() # optional - sage.modules [[], [(0, 0)], [(0, 1)], [(0, 0), (0, 1)]] """ # Check to see if everything in mset is unique @@ -269,7 +269,7 @@ def cardinality(self): sage: Combinations([1,2,3]).cardinality() 8 - sage: Combinations(['a','a','b']).cardinality() + sage: Combinations(['a','a','b']).cardinality() # optional - sage.libs.gap 6 """ c = 0 @@ -431,7 +431,7 @@ def cardinality(self): EXAMPLES:: sage: mset = [1,1,2,3,4,4,5] - sage: Combinations(mset,2).cardinality() + sage: Combinations(mset,2).cardinality() # optional - sage.libs.gap 12 """ from sage.libs.gap.libgap import libgap diff --git a/src/sage/combinat/combinatorial_map.py b/src/sage/combinat/combinatorial_map.py index 01d552498ee..0ff4ffe34bc 100644 --- a/src/sage/combinat/combinatorial_map.py +++ b/src/sage/combinat/combinatorial_map.py @@ -302,9 +302,9 @@ def __call__(self, *args, **kwds): sage: p = Permutation([1,3,2,4]) sage: cm = type(p).left_tableau; cm Combinatorial map: Robinson-Schensted insertion tableau - sage: cm(p) + sage: cm(p) # optional - sage.combinat [[1, 2, 4], [3]] - sage: cm(Permutation([4,3,2,1])) + sage: cm(Permutation([4,3,2,1])) # optional - sage.combinat [[1], [2], [3], [4]] """ if self._inst is not None: diff --git a/src/sage/combinat/composition.py b/src/sage/combinat/composition.py index d030152605b..50f1ee26780 100644 --- a/src/sage/combinat/composition.py +++ b/src/sage/combinat/composition.py @@ -172,18 +172,18 @@ def _ascii_art_(self): """ TESTS:: - sage: ascii_art(Compositions(4).list()) + sage: ascii_art(Compositions(4).list()) # optional - sage.combinat [ * ] [ * ** * * ] [ * * ** *** * ** * ] [ *, * , * , * , **, ** , ***, **** ] - sage: Partitions.options(diagram_str='#', convention="French") - sage: ascii_art(Compositions(4).list()) + sage: Partitions.options(diagram_str='#', convention="French") # optional - sage.combinat + sage: ascii_art(Compositions(4).list()) # optional - sage.combinat [ # ] [ # # # ## ] [ # # ## # # ## ### ] [ #, ##, #, ###, #, ##, #, #### ] - sage: Partitions.options._reset() + sage: Partitions.options._reset() # optional - sage.combinat """ from sage.typeset.ascii_art import ascii_art return ascii_art(self.to_skew_partition()) @@ -192,20 +192,20 @@ def _unicode_art_(self): """ TESTS:: - sage: unicode_art(Compositions(4).list()) + sage: unicode_art(Compositions(4).list()) # optional - sage.combinat ⎡ ┌┐ ⎤ ⎢ ├┤ ┌┬┐ ┌┐ ┌┐ ⎥ ⎢ ├┤ ├┼┘ ┌┼┤ ┌┬┬┐ ├┤ ┌┬┐ ┌┐ ⎥ ⎢ ├┤ ├┤ ├┼┘ ├┼┴┘ ┌┼┤ ┌┼┼┘ ┌┬┼┤ ┌┬┬┬┐ ⎥ ⎣ └┘, └┘ , └┘ , └┘ , └┴┘, └┴┘ , └┴┴┘, └┴┴┴┘ ⎦ - sage: Partitions.options(diagram_str='#', convention="French") - sage: unicode_art(Compositions(4).list()) + sage: Partitions.options(diagram_str='#', convention="French") # optional - sage.combinat + sage: unicode_art(Compositions(4).list()) # optional - sage.combinat ⎡ ┌┐ ⎤ ⎢ ├┤ ┌┐ ┌┐ ┌┬┐ ⎥ ⎢ ├┤ ├┤ ├┼┐ ┌┐ └┼┤ ┌┬┐ ┌┬┬┐ ⎥ ⎢ ├┤ ├┼┐ └┼┤ ├┼┬┐ ├┤ └┼┼┐ └┴┼┤ ┌┬┬┬┐ ⎥ ⎣ └┘, └┴┘, └┘, └┴┴┘, └┘, └┴┘, └┘, └┴┴┴┘ ⎦ - sage: Partitions.options._reset() + sage: Partitions.options._reset() # optional - sage.combinat """ from sage.typeset.unicode_art import unicode_art return unicode_art(self.to_skew_partition()) @@ -254,7 +254,7 @@ def conjugate(self) -> Composition: The ribbon shape of the conjugate of `I` is the conjugate of the ribbon shape of `I`:: - sage: all( I.conjugate().to_skew_partition() + sage: all( I.conjugate().to_skew_partition() # optional - sage.combinat ....: == I.to_skew_partition().conjugate() ....: for I in Compositions(4) ) True @@ -1178,11 +1178,11 @@ def to_partition(self): EXAMPLES:: - sage: Composition([2,1,3]).to_partition() + sage: Composition([2,1,3]).to_partition() # optional - sage.combinat [3, 2, 1] - sage: Composition([4,2,2]).to_partition() + sage: Composition([4,2,2]).to_partition() # optional - sage.combinat [4, 2, 2] - sage: Composition([]).to_partition() + sage: Composition([]).to_partition() # optional - sage.combinat [] """ from sage.combinat.partition import Partition @@ -1202,15 +1202,15 @@ def to_skew_partition(self, overlap=1): EXAMPLES:: - sage: Composition([3,4,1]).to_skew_partition() + sage: Composition([3,4,1]).to_skew_partition() # optional - sage.combinat [6, 6, 3] / [5, 2] - sage: Composition([3,4,1]).to_skew_partition(overlap=0) + sage: Composition([3,4,1]).to_skew_partition(overlap=0) # optional - sage.combinat [8, 7, 3] / [7, 3] - sage: Composition([]).to_skew_partition() + sage: Composition([]).to_skew_partition() # optional - sage.combinat [] / [] - sage: Composition([1,2]).to_skew_partition() + sage: Composition([1,2]).to_skew_partition() # optional - sage.combinat [2, 1] / [] - sage: Composition([2,1]).to_skew_partition() + sage: Composition([2,1]).to_skew_partition() # optional - sage.combinat [2, 2] / [1] """ from sage.combinat.skew_partition import SkewPartition @@ -1264,32 +1264,40 @@ def shuffle_product(self, other, overlap=False): sage: alph = Composition([2,2]) sage: beta = Composition([1,1,3]) - sage: S = alph.shuffle_product(beta); S + sage: S = alph.shuffle_product(beta); S # optional - sage.combinat Shuffle product of [2, 2] and [1, 1, 3] - sage: S.list() - [[2, 2, 1, 1, 3], [2, 1, 2, 1, 3], [2, 1, 1, 2, 3], [2, 1, 1, 3, 2], [1, 2, 2, 1, 3], [1, 2, 1, 2, 3], [1, 2, 1, 3, 2], [1, 1, 2, 2, 3], [1, 1, 2, 3, 2], [1, 1, 3, 2, 2]] + sage: S.list() # optional - sage.combinat + [[2, 2, 1, 1, 3], [2, 1, 2, 1, 3], [2, 1, 1, 2, 3], [2, 1, 1, 3, 2], + [1, 2, 2, 1, 3], [1, 2, 1, 2, 3], [1, 2, 1, 3, 2], [1, 1, 2, 2, 3], + [1, 1, 2, 3, 2], [1, 1, 3, 2, 2]] The *overlapping* shuffle product of `[2,2]` and `[1,1,3]`:: sage: alph = Composition([2,2]) sage: beta = Composition([1,1,3]) - sage: O = alph.shuffle_product(beta, overlap=True); O + sage: O = alph.shuffle_product(beta, overlap=True); O # optional - sage.combinat Overlapping shuffle product of [2, 2] and [1, 1, 3] - sage: O.list() - [[2, 2, 1, 1, 3], [2, 1, 2, 1, 3], [2, 1, 1, 2, 3], [2, 1, 1, 3, 2], [1, 2, 2, 1, 3], [1, 2, 1, 2, 3], [1, 2, 1, 3, 2], [1, 1, 2, 2, 3], [1, 1, 2, 3, 2], [1, 1, 3, 2, 2], [3, 2, 1, 3], [2, 3, 1, 3], [3, 1, 2, 3], [2, 1, 3, 3], [3, 1, 3, 2], [2, 1, 1, 5], [1, 3, 2, 3], [1, 2, 3, 3], [1, 3, 3, 2], [1, 2, 1, 5], [1, 1, 5, 2], [1, 1, 2, 5], [3, 3, 3], [3, 1, 5], [1, 3, 5]] + sage: O.list() # optional - sage.combinat + [[2, 2, 1, 1, 3], [2, 1, 2, 1, 3], [2, 1, 1, 2, 3], [2, 1, 1, 3, 2], + [1, 2, 2, 1, 3], [1, 2, 1, 2, 3], [1, 2, 1, 3, 2], [1, 1, 2, 2, 3], + [1, 1, 2, 3, 2], [1, 1, 3, 2, 2], + [3, 2, 1, 3], [2, 3, 1, 3], [3, 1, 2, 3], [2, 1, 3, 3], [3, 1, 3, 2], + [2, 1, 1, 5], [1, 3, 2, 3], [1, 2, 3, 3], [1, 3, 3, 2], [1, 2, 1, 5], + [1, 1, 5, 2], [1, 1, 2, 5], + [3, 3, 3], [3, 1, 5], [1, 3, 5]] Note that the shuffle product of two compositions can include the same composition more than once since a composition can be a shuffle of two compositions in several ways. For example:: sage: w1 = Composition([1]) - sage: S = w1.shuffle_product(w1); S + sage: S = w1.shuffle_product(w1); S # optional - sage.combinat Shuffle product of [1] and [1] - sage: S.list() + sage: S.list() # optional - sage.combinat [[1, 1], [1, 1]] - sage: O = w1.shuffle_product(w1, overlap=True); O + sage: O = w1.shuffle_product(w1, overlap=True); O # optional - sage.combinat Overlapping shuffle product of [1] and [1] - sage: O.list() + sage: O.list() # optional - sage.combinat [[1, 1], [1, 1], [2]] TESTS:: @@ -1392,11 +1400,10 @@ def specht_module(self, base_ring=None): EXAMPLES:: - sage: SM = Composition([1,2,2]).specht_module(QQ) - sage: SM + sage: SM = Composition([1,2,2]).specht_module(QQ); SM # optional - sage.combinat sage.modules Specht module of [(0, 0), (1, 0), (1, 1), (2, 0), (2, 1)] over Rational Field - sage: s = SymmetricFunctions(QQ).s() - sage: s(SM.frobenius_image()) + sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat sage.modules + sage: s(SM.frobenius_image()) # optional - sage.combinat sage.modules s[2, 2, 1] """ from sage.combinat.specht_module import SpechtModule @@ -1421,9 +1428,9 @@ def specht_module_dimension(self, base_ring=None): EXAMPLES:: - sage: Composition([1,2,2]).specht_module_dimension() + sage: Composition([1,2,2]).specht_module_dimension() # optional - sage.combinat sage.modules 5 - sage: Composition([1,2,2]).specht_module_dimension(GF(2)) + sage: Composition([1,2,2]).specht_module_dimension(GF(2)) # optional - sage.combinat sage.modules sage.rings.finite_rings 5 """ from sage.combinat.specht_module import specht_module_rank diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 9593055e9ed..de92bc8acf7 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -1188,14 +1188,14 @@ def to_matrix(self): EXAMPLES:: - sage: Permutation([1,2,3]).to_matrix() + sage: Permutation([1,2,3]).to_matrix() # optional - sage.modules [1 0 0] [0 1 0] [0 0 1] Alternatively:: - sage: matrix(Permutation([1,3,2])) + sage: matrix(Permutation([1,3,2])) # optional - sage.modules [1 0 0] [0 0 1] [0 1 0] @@ -1208,16 +1208,16 @@ def to_matrix(self): sage: Permutations.options.mult='r2l' sage: p = Permutation([2,1,3]) sage: q = Permutation([3,1,2]) - sage: (p*q).to_matrix() + sage: (p*q).to_matrix() # optional - sage.modules [0 0 1] [0 1 0] [1 0 0] - sage: p.to_matrix()*q.to_matrix() + sage: p.to_matrix()*q.to_matrix() # optional - sage.modules [0 0 1] [0 1 0] [1 0 0] sage: Permutations.options.mult='l2r' - sage: (p*q).to_matrix() + sage: (p*q).to_matrix() # optional - sage.modules [1 0 0] [0 0 1] [0 1 0] @@ -1238,11 +1238,11 @@ def to_alternating_sign_matrix(self): EXAMPLES:: - sage: m = Permutation([1,2,3]).to_alternating_sign_matrix(); m + sage: m = Permutation([1,2,3]).to_alternating_sign_matrix(); m # optional - sage.combinat sage.modules [1 0 0] [0 1 0] [0 0 1] - sage: parent(m) + sage: parent(m) # optional - sage.combinat sage.modules Alternating sign matrices of size 3 """ from sage.combinat.alternating_sign_matrix import AlternatingSignMatrix @@ -1252,12 +1252,12 @@ def __mul__(self, rp): """ TESTS:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: SM = SGA.specht_module([2,1]) - sage: p213 = Permutations(3)([2,1,3]) - sage: p213 * SGA.an_element() + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: SM = SGA.specht_module([2,1]) # optional - sage.combinat sage.modules + sage: p213 = Permutations(3)([2,1,3]) # optional - sage.combinat sage.modules + sage: p213 * SGA.an_element() # optional - sage.combinat sage.modules 3*[1, 2, 3] + [1, 3, 2] + [2, 1, 3] + 2*[3, 1, 2] - sage: p213 * SM.an_element() + sage: p213 * SM.an_element() # optional - sage.combinat sage.modules 2*B[0] - 4*B[1] """ if not isinstance(rp, Permutation) and isinstance(rp, Element): @@ -1297,8 +1297,8 @@ def __rmul__(self, lp) -> Permutation: [3, 2, 1] sage: Permutations.options.mult='l2r' - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: SGA.an_element() * Permutations(3)(p213) + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: SGA.an_element() * Permutations(3)(p213) # optional - sage.combinat sage.modules 3*[1, 2, 3] + [2, 1, 3] + 2*[2, 3, 1] + [3, 2, 1] """ if not isinstance(lp, Permutation) and isinstance(lp, Element): @@ -1678,18 +1678,19 @@ def to_digraph(self) -> DiGraph: EXAMPLES:: - sage: d = Permutation([3, 1, 2]).to_digraph() - sage: d.edges(sort=True, labels=False) + sage: d = Permutation([3, 1, 2]).to_digraph() # optional - sage.graphs + sage: d.edges(sort=True, labels=False) # optional - sage.graphs [(1, 3), (2, 1), (3, 2)] sage: P = Permutations(range(1, 10)) - sage: d = Permutation(P.random_element()).to_digraph() - sage: all(c.is_cycle() for c in d.strongly_connected_components_subgraphs()) + sage: d = Permutation(P.random_element()).to_digraph() # optional - sage.graphs + sage: all(c.is_cycle() # optional - sage.graphs + ....: for c in d.strongly_connected_components_subgraphs()) True TESTS:: - sage: d = Permutation([1]).to_digraph() - sage: d.edges(sort=True, labels=False) + sage: d = Permutation([1]).to_digraph() # optional - sage.graphs + sage: d.edges(sort=True, labels=False) # optional - sage.graphs [(1, 1)] """ return DiGraph([self, enumerate(self, start=1)], @@ -1720,14 +1721,15 @@ def show(self, representation="cycles", orientation="landscape", **args): EXAMPLES:: - sage: Permutations(20).random_element().show(representation = "cycles") - sage: Permutations(20).random_element().show(representation = "chord-diagram") - sage: Permutations(20).random_element().show(representation = "braid") - sage: Permutations(20).random_element().show(representation = "braid", orientation='portrait') + sage: Permutations(20).random_element().show(representation="cycles") + sage: Permutations(20).random_element().show(representation="chord-diagram") + sage: Permutations(20).random_element().show(representation="braid") + sage: Permutations(20).random_element().show(representation="braid", + ....: orientation='portrait') TESTS:: - sage: Permutations(20).random_element().show(representation = "modern_art") + sage: Permutations(20).random_element().show(representation="modern_art") Traceback (most recent call last): ... ValueError: The value of 'representation' must be equal to 'cycles', 'chord-diagram' or 'braid' @@ -2246,9 +2248,9 @@ def longest_increasing_subsequences(self): EXAMPLES:: - sage: Permutation([2,3,4,1]).longest_increasing_subsequences() + sage: Permutation([2,3,4,1]).longest_increasing_subsequences() # optional - sage.graphs [[2, 3, 4]] - sage: Permutation([5, 7, 1, 2, 6, 4, 3]).longest_increasing_subsequences() + sage: Permutation([5, 7, 1, 2, 6, 4, 3]).longest_increasing_subsequences() # optional - sage.graphs [[1, 2, 6], [1, 2, 4], [1, 2, 3]] .. NOTE:: @@ -2306,16 +2308,17 @@ def longest_increasing_subsequences_number(self): The algorithm is similar to :meth:`longest_increasing_subsequences`. Namely, the longest increasing subsequences are encoded as increasing sequences in a ranked poset from a smallest to a largest element. Their - number can be obtained via dynamic programming : for each `v` in the poset + number can be obtained via dynamic programming: for each `v` in the poset we compute the number of paths from a smallest element to `v`. EXAMPLES:: - sage: sum(p.longest_increasing_subsequences_number() for p in Permutations(8)) + sage: sum(p.longest_increasing_subsequences_number() + ....: for p in Permutations(8)) 120770 sage: p = Permutations(50).random_element() - sage: (len(p.longest_increasing_subsequences()) == + sage: (len(p.longest_increasing_subsequences()) == # optional - sage.graphs ....: p.longest_increasing_subsequences_number()) True """ @@ -2354,7 +2357,7 @@ def cycle_type(self): EXAMPLES:: - sage: Permutation([3,1,2,4]).cycle_type() + sage: Permutation([3,1,2,4]).cycle_type() # optional - sage.combinat [3, 1] """ cycle_type = [len(c) for c in self.to_cycles()] @@ -3019,9 +3022,9 @@ def rothe_diagram(self): EXAMPLES:: sage: p = Permutation([4,2,1,3]) - sage: D = p.rothe_diagram(); D + sage: D = p.rothe_diagram(); D # optional - sage.combinat [(0, 0), (0, 1), (0, 2), (1, 0)] - sage: D.pp() + sage: D.pp() # optional - sage.combinat O O O . O . . . . . . . @@ -3038,7 +3041,7 @@ def number_of_reduced_words(self): EXAMPLES:: sage: p = Permutation([6,4,2,5,1,8,3,7]) - sage: len(p.reduced_words()) == p.number_of_reduced_words() + sage: len(p.reduced_words()) == p.number_of_reduced_words() # optional - sage.combinat True """ Tx = self.rothe_diagram().peelable_tableaux() @@ -4221,8 +4224,10 @@ def right_permutohedron_interval_iterator(self, other): EXAMPLES:: - sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) # indirect doctest - [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] + sage: p = Permutation([2, 1, 4, 5, 3]); q = Permutation([2, 5, 4, 1, 3]) + sage: p.right_permutohedron_interval(q) # indirect doctest # optional - sage.graphs + [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], + [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] """ if len(self) != len(other): raise ValueError("len({}) and len({}) must be equal".format(self, other)) @@ -4246,24 +4251,28 @@ def right_permutohedron_interval(self, other): EXAMPLES:: - sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) - [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] + sage: p = Permutation([2, 1, 4, 5, 3]); q = Permutation([2, 5, 4, 1, 3]) + sage: p.right_permutohedron_interval(q) # optional - sage.graphs + [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], + [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] TESTS:: - sage: Permutation([]).right_permutohedron_interval(Permutation([])) + sage: Permutation([]).right_permutohedron_interval(Permutation([])) # optional - sage.graphs [[]] - sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) + sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) # optional - sage.graphs [[3, 1, 2]] - sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) - [[3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1], [1, 3, 4, 2], [1, 3, 2, 4], [3, 2, 4, 1], [3, 2, 1, 4], [3, 1, 2, 4]] - sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) - [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] - sage: Permutation([2, 5, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) + sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) # optional - sage.graphs + [[3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1], [1, 3, 4, 2], + [1, 3, 2, 4], [3, 2, 4, 1], [3, 2, 1, 4], [3, 1, 2, 4]] + sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) # optional - sage.graphs + [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], + [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] + sage: Permutation([2, 5, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs Traceback (most recent call last): ... ValueError: [2, 5, 4, 1, 3] must be lower or equal than [2, 1, 4, 5, 3] for the right permutohedron order - sage: Permutation([2, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) + sage: Permutation([2, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs Traceback (most recent call last): ... ValueError: len([2, 4, 1, 3]) and len([2, 1, 4, 5, 3]) must be equal @@ -4502,7 +4511,7 @@ def has_pattern(self, patt) -> bool: EXAMPLES:: - sage: Permutation([3,5,1,4,6,2]).has_pattern([1,3,2]) + sage: Permutation([3,5,1,4,6,2]).has_pattern([1,3,2]) # optional - sage.combinat True """ p = self @@ -4522,11 +4531,11 @@ def avoids(self, patt) -> bool: EXAMPLES:: - sage: Permutation([6,2,5,4,3,1]).avoids([4,2,3,1]) + sage: Permutation([6,2,5,4,3,1]).avoids([4,2,3,1]) # optional - sage.combinat False - sage: Permutation([6,1,2,5,4,3]).avoids([4,2,3,1]) + sage: Permutation([6,1,2,5,4,3]).avoids([4,2,3,1]) # optional - sage.combinat True - sage: Permutation([6,1,2,5,4,3]).avoids([3,4,1,2]) + sage: Permutation([6,1,2,5,4,3]).avoids([3,4,1,2]) # optional - sage.combinat True """ return not self.has_pattern(patt) @@ -4538,7 +4547,7 @@ def pattern_positions(self, patt) -> list: EXAMPLES:: - sage: Permutation([3,5,1,4,6,2]).pattern_positions([1,3,2]) + sage: Permutation([3,5,1,4,6,2]).pattern_positions([1,3,2]) # optional - sage.combinat [[0, 1, 3], [2, 3, 5], [2, 4, 5]] """ p = self @@ -4563,7 +4572,7 @@ def simion_schmidt(self, avoid=[1,2,3]): sage: P = Permutations(6) sage: p = P([4,5,1,6,3,2]) sage: pl = [ [1,2,3], [1,3,2], [3,1,2], [3,2,1] ] - sage: for q in pl: + sage: for q in pl: # optional - sage.combinat ....: s = p.simion_schmidt(q) ....: print("{} {}".format(s, s.has_pattern(q))) [4, 6, 1, 5, 3, 2] False @@ -4647,20 +4656,23 @@ def permutation_poset(self): EXAMPLES:: - sage: Permutation([3,1,5,4,2]).permutation_poset().cover_relations() + sage: Permutation([3,1,5,4,2]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs [[(2, 1), (5, 2)], [(2, 1), (3, 5)], [(2, 1), (4, 4)], [(1, 3), (3, 5)], [(1, 3), (4, 4)]] - sage: Permutation([]).permutation_poset().cover_relations() + sage: Permutation([]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs [] - sage: Permutation([1,3,2]).permutation_poset().cover_relations() + sage: Permutation([1,3,2]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs [[(1, 1), (2, 3)], [(1, 1), (3, 2)]] - sage: Permutation([1,2]).permutation_poset().cover_relations() + sage: Permutation([1,2]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs [[(1, 1), (2, 2)]] - sage: P = Permutation([1,5,2,4,3]) - sage: P.permutation_poset().greene_shape() == P.RS_partition() # This should hold for any P. + sage: P = Permutation([1,5,2,4,3]) # optional - sage.combinat sage.graphs + + This should hold for any `P`:: + + sage: P.permutation_poset().greene_shape() == P.RS_partition() # optional - sage.combinat sage.graphs True """ from sage.combinat.posets.posets import Poset @@ -4732,7 +4744,7 @@ def robinson_schensted(self): EXAMPLES:: - sage: Permutation([6,2,3,1,7,5,4]).robinson_schensted() + sage: Permutation([6,2,3,1,7,5,4]).robinson_schensted() # optional - sage.combinat [[[1, 3, 4], [2, 5], [6, 7]], [[1, 3, 5], [2, 6], [4, 7]]] """ return RSK(self, check_standard=True) @@ -4764,7 +4776,7 @@ def left_tableau(self): EXAMPLES:: - sage: Permutation([1,4,3,2]).left_tableau() + sage: Permutation([1,4,3,2]).left_tableau() # optional - sage.combinat [[1, 2], [3], [4]] """ return RSK(self, check_standard=True)[0] @@ -4777,7 +4789,7 @@ def right_tableau(self): EXAMPLES:: - sage: Permutation([1,4,3,2]).right_tableau() + sage: Permutation([1,4,3,2]).right_tableau() # optional - sage.combinat [[1, 2], [3], [4]] """ return RSK(self, check_standard=True)[1] @@ -4788,17 +4800,17 @@ def increasing_tree(self, compare=min): EXAMPLES:: - sage: Permutation([1,4,3,2]).increasing_tree() + sage: Permutation([1,4,3,2]).increasing_tree() # optional - sage.combinat 1[., 2[3[4[., .], .], .]] - sage: Permutation([4,1,3,2]).increasing_tree() + sage: Permutation([4,1,3,2]).increasing_tree() # optional - sage.combinat 1[4[., .], 2[3[., .], .]] By passing the option ``compare=max`` one can have the decreasing tree instead:: - sage: Permutation([2,3,4,1]).increasing_tree(max) + sage: Permutation([2,3,4,1]).increasing_tree(max) # optional - sage.combinat 4[3[2[., .], .], 1[., .]] - sage: Permutation([2,3,1,4]).increasing_tree(max) + sage: Permutation([2,3,1,4]).increasing_tree(max) # optional - sage.combinat 4[3[2[., .], 1[., .]], .] """ from sage.combinat.binary_tree import LabelledBinaryTree as LBT @@ -4819,17 +4831,17 @@ def increasing_tree_shape(self, compare=min): EXAMPLES:: - sage: Permutation([1,4,3,2]).increasing_tree_shape() + sage: Permutation([1,4,3,2]).increasing_tree_shape() # optional - sage.combinat [., [[[., .], .], .]] - sage: Permutation([4,1,3,2]).increasing_tree_shape() + sage: Permutation([4,1,3,2]).increasing_tree_shape() # optional - sage.combinat [[., .], [[., .], .]] By passing the option ``compare=max`` one can have the decreasing tree instead:: - sage: Permutation([2,3,4,1]).increasing_tree_shape(max) + sage: Permutation([2,3,4,1]).increasing_tree_shape(max) # optional - sage.combinat [[[., .], .], [., .]] - sage: Permutation([2,3,1,4]).increasing_tree_shape(max) + sage: Permutation([2,3,1,4]).increasing_tree_shape(max) # optional - sage.combinat [[[., .], [., .]], .] """ return self.increasing_tree(compare).shape() @@ -4855,22 +4867,22 @@ def binary_search_tree(self, left_to_right=True): EXAMPLES:: - sage: Permutation([1,4,3,2]).binary_search_tree() + sage: Permutation([1,4,3,2]).binary_search_tree() # optional - sage.combinat 1[., 4[3[2[., .], .], .]] - sage: Permutation([4,1,3,2]).binary_search_tree() + sage: Permutation([4,1,3,2]).binary_search_tree() # optional - sage.combinat 4[1[., 3[2[., .], .]], .] By passing the option ``left_to_right=False`` one can have the insertion going from right to left:: - sage: Permutation([1,4,3,2]).binary_search_tree(False) + sage: Permutation([1,4,3,2]).binary_search_tree(False) # optional - sage.combinat 2[1[., .], 3[., 4[., .]]] - sage: Permutation([4,1,3,2]).binary_search_tree(False) + sage: Permutation([4,1,3,2]).binary_search_tree(False) # optional - sage.combinat 2[1[., .], 3[., 4[., .]]] TESTS:: - sage: Permutation([]).binary_search_tree() + sage: Permutation([]).binary_search_tree() # optional - sage.combinat . """ from sage.combinat.binary_tree import LabelledBinaryTree as LBT @@ -4891,17 +4903,17 @@ def binary_search_tree_shape(self, left_to_right=True): EXAMPLES:: - sage: Permutation([1,4,3,2]).binary_search_tree_shape() + sage: Permutation([1,4,3,2]).binary_search_tree_shape() # optional - sage.combinat [., [[[., .], .], .]] - sage: Permutation([4,1,3,2]).binary_search_tree_shape() + sage: Permutation([4,1,3,2]).binary_search_tree_shape() # optional - sage.combinat [[., [[., .], .]], .] By passing the option ``left_to_right=False`` one can have the insertion going from right to left:: - sage: Permutation([1,4,3,2]).binary_search_tree_shape(False) + sage: Permutation([1,4,3,2]).binary_search_tree_shape(False) # optional - sage.combinat [[., .], [., [., .]]] - sage: Permutation([4,1,3,2]).binary_search_tree_shape(False) + sage: Permutation([4,1,3,2]).binary_search_tree_shape(False) # optional - sage.combinat [[., .], [., [., .]]] """ from sage.combinat.binary_tree import binary_search_tree_shape @@ -4948,7 +4960,7 @@ def sylvester_class(self, left_to_right=False): The sylvester class of a permutation in `S_5`:: sage: p = Permutation([3, 5, 1, 2, 4]) - sage: sorted(p.sylvester_class()) + sage: sorted(p.sylvester_class()) # optional - sage.combinat [[1, 3, 2, 5, 4], [1, 3, 5, 2, 4], [1, 5, 3, 2, 4], @@ -4960,20 +4972,20 @@ def sylvester_class(self, left_to_right=False): The sylvester class of a permutation `p` contains `p`:: - sage: all( p in p.sylvester_class() for p in Permutations(4) ) + sage: all(p in p.sylvester_class() for p in Permutations(4)) # optional - sage.combinat True Small cases:: - sage: list(Permutation([]).sylvester_class()) + sage: list(Permutation([]).sylvester_class()) # optional - sage.combinat [[]] - sage: list(Permutation([1]).sylvester_class()) + sage: list(Permutation([1]).sylvester_class()) # optional - sage.combinat [[1]] The sylvester classes in `S_3`:: - sage: [sorted(p.sylvester_class()) for p in Permutations(3)] + sage: [sorted(p.sylvester_class()) for p in Permutations(3)] # optional - sage.combinat [[[1, 2, 3]], [[1, 3, 2], [3, 1, 2]], [[2, 1, 3]], @@ -4983,7 +4995,8 @@ def sylvester_class(self, left_to_right=False): The left sylvester classes in `S_3`:: - sage: [sorted(p.sylvester_class(left_to_right=True)) for p in Permutations(3)] + sage: [sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat + ....: for p in Permutations(3)] [[[1, 2, 3]], [[1, 3, 2]], [[2, 1, 3], [2, 3, 1]], @@ -4994,7 +5007,7 @@ def sylvester_class(self, left_to_right=False): A left sylvester class in `S_5`:: sage: p = Permutation([4, 2, 1, 5, 3]) - sage: sorted(p.sylvester_class(left_to_right=True)) + sage: sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat [[4, 2, 1, 3, 5], [4, 2, 1, 5, 3], [4, 2, 3, 1, 5], @@ -5017,7 +5030,7 @@ def RS_partition(self): EXAMPLES:: - sage: Permutation([1,4,3,2]).RS_partition() + sage: Permutation([1,4,3,2]).RS_partition() # optional - sage.combinat [2, 1, 1] """ return RSK(self)[1].shape() @@ -5239,15 +5252,16 @@ def hyperoctahedral_double_coset_type(self): EXAMPLES:: - sage: Permutation([3, 4, 6, 1, 5, 7, 2, 8]).hyperoctahedral_double_coset_type() + sage: p = Permutation([3, 4, 6, 1, 5, 7, 2, 8]) + sage: p.hyperoctahedral_double_coset_type() # optional - sage.combinat [3, 1] - sage: all(p.hyperoctahedral_double_coset_type() == + sage: all(p.hyperoctahedral_double_coset_type() == # optional - sage.combinat ....: p.inverse().hyperoctahedral_double_coset_type() ....: for p in Permutations(4)) True - sage: Permutation([]).hyperoctahedral_double_coset_type() + sage: Permutation([]).hyperoctahedral_double_coset_type() # optional - sage.combinat [] - sage: Permutation([3,1,2]).hyperoctahedral_double_coset_type() + sage: Permutation([3,1,2]).hyperoctahedral_double_coset_type() # optional - sage.combinat Traceback (most recent call last): ... ValueError: [3, 1, 2] is a permutation of odd size and has no coset-type @@ -5324,21 +5338,23 @@ def shifted_shuffle(self, other): EXAMPLES:: - sage: Permutation([]).shifted_shuffle(Permutation([])) + sage: Permutation([]).shifted_shuffle(Permutation([])) # optional - sage.graphs [[]] - sage: Permutation([1, 2, 3]).shifted_shuffle(Permutation([1])) + sage: Permutation([1, 2, 3]).shifted_shuffle(Permutation([1])) # optional - sage.graphs [[4, 1, 2, 3], [1, 2, 3, 4], [1, 2, 4, 3], [1, 4, 2, 3]] - sage: Permutation([1, 2]).shifted_shuffle(Permutation([2, 1])) - [[4, 1, 3, 2], [4, 3, 1, 2], [1, 4, 3, 2], [1, 4, 2, 3], [1, 2, 4, 3], [4, 1, 2, 3]] - sage: Permutation([1]).shifted_shuffle([1]) + sage: Permutation([1, 2]).shifted_shuffle(Permutation([2, 1])) # optional - sage.graphs + [[4, 1, 3, 2], [4, 3, 1, 2], [1, 4, 3, 2], + [1, 4, 2, 3], [1, 2, 4, 3], [4, 1, 2, 3]] + sage: Permutation([1]).shifted_shuffle([1]) # optional - sage.graphs [[2, 1], [1, 2]] - sage: len(Permutation([3, 1, 5, 4, 2]).shifted_shuffle(Permutation([2, 1, 4, 3]))) + sage: p = Permutation([3, 1, 5, 4, 2]) + sage: len(p.shifted_shuffle(Permutation([2, 1, 4, 3]))) # optional - sage.graphs 126 The shifted shuffle product is associative. We can test this on an admittedly toy example:: - sage: all( all( all( sorted(flatten([abs.shifted_shuffle(c) + sage: all( all( all( sorted(flatten([abs.shifted_shuffle(c) # optional - sage.graphs ....: for abs in a.shifted_shuffle(b)])) ....: == sorted(flatten([a.shifted_shuffle(bcs) ....: for bcs in b.shifted_shuffle(c)])) @@ -5351,7 +5367,7 @@ def shifted_shuffle(self, other): permutations as the ``shifted_shuffle`` method on words (but is faster):: - sage: all( all( sorted(p1.shifted_shuffle(p2)) + sage: all( all( sorted(p1.shifted_shuffle(p2)) # optional - sage.graphs ....: == sorted([Permutation(p) for p in ....: Word(p1).shifted_shuffle(Word(p2))]) ....: for p2 in Permutations(3) ) @@ -5368,9 +5384,9 @@ def _tableau_contribution(T): EXAMPLES:: - sage: T = Tableau([[1,1,1],[2]]) + sage: T = Tableau([[1,1,1],[2]]) # optional - sage.combinat sage: from sage.combinat.permutation import _tableau_contribution - sage: _tableau_contribution(T) + sage: _tableau_contribution(T) # optional - sage.combinat 3 """ from sage.combinat.tableau import StandardTableaux @@ -5460,7 +5476,7 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(['c', 'a', 't'], 2); p Permutations of the set ['c', 'a', 't'] of length 2 - sage: p.list() + sage: p.list() # optional - sage.libs.gap [['c', 'a'], ['c', 't'], ['a', 'c'], ['a', 't'], ['t', 'c'], ['t', 'a']] :: @@ -5487,14 +5503,16 @@ class Permutations(UniqueRepresentation, Parent): :: sage: p = Permutations(bruhat_smaller=[1,3,2,4]); p - Standard permutations that are less than or equal to [1, 3, 2, 4] in the Bruhat order + Standard permutations that are less than or equal + to [1, 3, 2, 4] in the Bruhat order sage: p.list() [[1, 2, 3, 4], [1, 3, 2, 4]] :: sage: p = Permutations(bruhat_greater=[4,2,3,1]); p - Standard permutations that are greater than or equal to [4, 2, 3, 1] in the Bruhat order + Standard permutations that are greater than or equal + to [4, 2, 3, 1] in the Bruhat order sage: p.list() [[4, 2, 3, 1], [4, 3, 2, 1]] @@ -5892,14 +5910,14 @@ class Permutations_mset(Permutations): [2, 2, 1, 1, 2], [2, 2, 1, 2, 1], [2, 2, 2, 1, 1]] - sage: MS = MatrixSpace(GF(2),2,2) - sage: A = MS([1,0,1,1]) - sage: rows = A.rows() - sage: rows[0].set_immutable() - sage: rows[1].set_immutable() - sage: P = Permutations_mset(rows); P + sage: MS = MatrixSpace(GF(2), 2, 2) # optional - sage.modules sage.rings.finite_rings + sage: A = MS([1,0,1,1]) # optional - sage.modules sage.rings.finite_rings + sage: rows = A.rows() # optional - sage.modules sage.rings.finite_rings + sage: rows[0].set_immutable() # optional - sage.modules sage.rings.finite_rings + sage: rows[1].set_immutable() # optional - sage.modules sage.rings.finite_rings + sage: P = Permutations_mset(rows); P # optional - sage.modules sage.rings.finite_rings Permutations of the multi-set [(1, 0), (1, 1)] - sage: sorted(P) + sage: sorted(P) # optional - sage.modules sage.rings.finite_rings [[(1, 0), (1, 1)], [(1, 1), (1, 0)]] """ @staticmethod @@ -6442,7 +6460,7 @@ def _repr_(self): """ TESTS:: - sage: Permutations([1,2,2],2) + sage: Permutations([1,2,2], 2) Permutations of the multi-set [1, 2, 2] of length 2 """ return "Permutations of the multi-set %s of length %s" % (list(self.mset), self._k) @@ -6453,7 +6471,7 @@ def cardinality(self): EXAMPLES:: - sage: Permutations([1,2,2],2).cardinality() + sage: Permutations([1,2,2], 2).cardinality() # optional - sage.libs.gap 3 """ return ZZ.sum(1 for z in self) @@ -6462,7 +6480,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations([1,2,2],2).list() + sage: Permutations([1,2,2], 2).list() # optional - sage.libs.gap [[1, 2], [2, 1], [2, 2]] """ mset = self.mset @@ -6571,7 +6589,7 @@ class Arrangements(Permutations): EXAMPLES:: sage: mset = [1,1,2,3,4,4,5] - sage: Arrangements(mset,2).list() + sage: Arrangements(mset, 2).list() # optional - sage.libs.gap [[1, 1], [1, 2], [1, 3], @@ -6594,11 +6612,11 @@ class Arrangements(Permutations): [5, 2], [5, 3], [5, 4]] - sage: Arrangements(mset,2).cardinality() + sage: Arrangements(mset, 2).cardinality() # optional - sage.libs.gap 22 - sage: Arrangements( ["c","a","t"], 2 ).list() + sage: Arrangements( ["c","a","t"], 2 ).list() # optional - sage.libs.gap [['c', 'a'], ['c', 't'], ['a', 'c'], ['a', 't'], ['t', 'c'], ['t', 'a']] - sage: Arrangements( ["c","a","t"], 3 ).list() + sage: Arrangements( ["c","a","t"], 3 ).list() # optional - sage.libs.gap [['c', 'a', 't'], ['c', 't', 'a'], ['a', 'c', 't'], @@ -6630,7 +6648,7 @@ def cardinality(self): EXAMPLES:: sage: A = Arrangements([1,1,2,3,4,4,5], 2) - sage: A.cardinality() + sage: A.cardinality() # optional - sage.libs.gap 22 """ one = ZZ.one() @@ -6901,20 +6919,20 @@ def _coerce_map_from_(self, G): EXAMPLES:: sage: P = Permutations(6) - sage: P.has_coerce_map_from(SymmetricGroup(6)) + sage: P.has_coerce_map_from(SymmetricGroup(6)) # optional - sage.groups True - sage: P.has_coerce_map_from(SymmetricGroup(5)) + sage: P.has_coerce_map_from(SymmetricGroup(5)) # optional - sage.groups True - sage: P.has_coerce_map_from(SymmetricGroup(7)) + sage: P.has_coerce_map_from(SymmetricGroup(7)) # optional - sage.groups False sage: P.has_coerce_map_from(Permutations(5)) True sage: P.has_coerce_map_from(Permutations(7)) False - sage: P.has_coerce_map_from(groups.misc.Cactus(5)) + sage: P.has_coerce_map_from(groups.misc.Cactus(5)) # optional - sage.groups True - sage: P.has_coerce_map_from(groups.misc.Cactus(7)) + sage: P.has_coerce_map_from(groups.misc.Cactus(7)) # optional - sage.groups False """ if isinstance(G, SymmetricGroup): @@ -6936,9 +6954,9 @@ def _from_permutation_group_element(self, x): TESTS:: sage: P = Permutations(4) - sage: G = SymmetricGroup(4) - sage: x = G([4,3,1,2]) - sage: P._from_permutation_group_element(x) + sage: G = SymmetricGroup(4) # optional - sage.groups + sage: x = G([4,3,1,2]) # optional - sage.groups + sage: P._from_permutation_group_element(x) # optional - sage.groups [4, 3, 1, 2] """ return self(x.domain()) @@ -6949,11 +6967,11 @@ def _from_cactus_group_element(self, x): EXAMPLES:: - sage: J3 = groups.misc.Cactus(3) - sage: s12,s13,s23 = J3.gens() - sage: elt = s12 * s23 * s13 - sage: P5 = Permutations(5) - sage: P5._from_cactus_group_element(elt) + sage: J3 = groups.misc.Cactus(3) # optional - sage.groups + sage: s12,s13,s23 = J3.gens() # optional - sage.groups + sage: elt = s12 * s23 * s13 # optional - sage.groups + sage: P5 = Permutations(5) # optional - sage.groups + sage: P5._from_cactus_group_element(elt) # optional - sage.groups [1, 3, 2, 4, 5] """ return self(x.to_permutation()) @@ -6965,12 +6983,11 @@ def as_permutation_group(self): EXAMPLES:: sage: P = Permutations(4) - sage: PG = P.as_permutation_group() - sage: PG + sage: PG = P.as_permutation_group(); PG # optional - sage.groups Symmetric group of order 4! as a permutation group - sage: G = SymmetricGroup(4) - sage: PG is G + sage: G = SymmetricGroup(4) # optional - sage.groups + sage: PG is G # optional - sage.groups True """ from sage.groups.perm_gps.permgroup_named import SymmetricGroup @@ -7119,7 +7136,7 @@ def element_in_conjugacy_classes(self, nu): EXAMPLES:: sage: PP = Permutations(5) - sage: PP.element_in_conjugacy_classes([2,2]) + sage: PP.element_in_conjugacy_classes([2,2]) # optional - sage.combinat [2, 1, 4, 3, 5] """ from sage.combinat.partition import Partition @@ -7151,7 +7168,7 @@ def conjugacy_classes_representatives(self): EXAMPLES:: sage: G = Permutations(5) - sage: G.conjugacy_classes_representatives() + sage: G.conjugacy_classes_representatives() # optional - sage.combinat [[1, 2, 3, 4, 5], [2, 1, 3, 4, 5], [2, 1, 4, 3, 5], @@ -7165,10 +7182,10 @@ def conjugacy_classes_representatives(self): Check some border cases:: sage: S = Permutations(0) - sage: S.conjugacy_classes_representatives() + sage: S.conjugacy_classes_representatives() # optional - sage.combinat [[]] sage: S = Permutations(1) - sage: S.conjugacy_classes_representatives() + sage: S.conjugacy_classes_representatives() # optional - sage.combinat [[1]] """ from sage.combinat.partition import Partitions_n @@ -7182,7 +7199,7 @@ def conjugacy_classes_iterator(self): EXAMPLES:: sage: G = Permutations(4) - sage: list(G.conjugacy_classes_iterator()) == G.conjugacy_classes() + sage: list(G.conjugacy_classes_iterator()) == G.conjugacy_classes() # optional - sage.combinat True """ from sage.combinat.partition import Partitions_n @@ -7197,7 +7214,7 @@ def conjugacy_classes(self): EXAMPLES:: sage: G = Permutations(4) - sage: G.conjugacy_classes() + sage: G.conjugacy_classes() # optional - sage.combinat [Conjugacy class of cycle type [1, 1, 1, 1] in Standard permutations of 4, Conjugacy class of cycle type [2, 1, 1] in Standard permutations of 4, Conjugacy class of cycle type [2, 2] in Standard permutations of 4, @@ -7218,9 +7235,9 @@ def conjugacy_class(self, g): sage: G = Permutations(5) sage: g = G([2,3,4,1,5]) - sage: G.conjugacy_class(g) + sage: G.conjugacy_class(g) # optional - sage.combinat Conjugacy class of cycle type [4, 1] in Standard permutations of 5 - sage: G.conjugacy_class(Partition([2, 1, 1, 1])) + sage: G.conjugacy_class(Partition([2, 1, 1, 1])) # optional - sage.combinat Conjugacy class of cycle type [2, 1, 1, 1] in Standard permutations of 5 """ from sage.groups.perm_gps.symgp_conjugacy_class import PermutationsConjugacyClass @@ -7238,15 +7255,16 @@ def algebra(self, base_ring, category=None): EXAMPLES:: sage: P = Permutations(4) - sage: A = P.algebra(QQ); A + sage: A = P.algebra(QQ); A # optional - sage.combinat sage.modules Symmetric group algebra of order 4 over Rational Field - sage: A.category() + sage: A.category() # optional - sage.combinat sage.modules Join of Category of coxeter group algebras over Rational Field and Category of finite group algebras over Rational Field - and Category of finite dimensional cellular algebras with basis over Rational Field - sage: A = P.algebra(QQ, category=Monoids()) - sage: A.category() + and Category of finite dimensional cellular algebras + with basis over Rational Field + sage: A = P.algebra(QQ, category=Monoids()) # optional - sage.combinat sage.modules + sage: A.category() # optional - sage.combinat sage.modules Category of finite dimensional cellular monoid algebras over Rational Field """ from sage.combinat.symmetric_group_algebra import SymmetricGroupAlgebra @@ -7275,9 +7293,9 @@ def cartan_type(self): EXAMPLES:: - sage: A = SymmetricGroup([2,3,7]); A.cartan_type() + sage: A = SymmetricGroup([2,3,7]); A.cartan_type() # optional - sage.combinat sage.groups ['A', 2] - sage: A = SymmetricGroup([]); A.cartan_type() + sage: A = SymmetricGroup([]); A.cartan_type() # optional - sage.combinat sage.groups ['A', 0] """ from sage.combinat.root_system.cartan_type import CartanType @@ -7542,8 +7560,8 @@ def from_permutation_group_element(pge, parent=None): EXAMPLES:: sage: import sage.combinat.permutation as permutation - sage: pge = PermutationGroupElement([(1,2),(3,4)]) - sage: permutation.from_permutation_group_element(pge) + sage: pge = PermutationGroupElement([(1,2),(3,4)]) # optional - sage.groups + sage: permutation.from_permutation_group_element(pge) # optional - sage.groups [2, 1, 4, 3] """ if not isinstance(pge, PermutationGroupElement): @@ -7852,25 +7870,26 @@ def bistochastic_as_sum_of_permutations(M, check = True): sage: L.append((6,Permutation([5, 3, 4, 1, 2]))) sage: L.append((3,Permutation([3, 1, 4, 2, 5]))) sage: L.append((2,Permutation([1, 4, 2, 3, 5]))) - sage: M = sum([c * p.to_matrix() for (c,p) in L]) - sage: decomp = bistochastic_as_sum_of_permutations(M) - sage: print(decomp) - 2*B[[1, 4, 2, 3, 5]] + 3*B[[3, 1, 4, 2, 5]] + 9*B[[4, 1, 3, 5, 2]] + 6*B[[5, 3, 4, 1, 2]] + sage: M = sum([c * p.to_matrix() for (c,p) in L]) # optional - sage.modules + sage: decomp = bistochastic_as_sum_of_permutations(M) # optional - sage.graphs sage.modules + sage: print(decomp) # optional - sage.graphs sage.modules + 2*B[[1, 4, 2, 3, 5]] + 3*B[[3, 1, 4, 2, 5]] + + 9*B[[4, 1, 3, 5, 2]] + 6*B[[5, 3, 4, 1, 2]] An exception is raised when the matrix is not positive and bistochastic:: sage: M = Matrix([[2,3],[2,2]]) - sage: decomp = bistochastic_as_sum_of_permutations(M) + sage: decomp = bistochastic_as_sum_of_permutations(M) # optional - sage.graphs sage.modules Traceback (most recent call last): ... ValueError: The matrix is not bistochastic - sage: bistochastic_as_sum_of_permutations(Matrix(GF(7), 2, [2,1,1,2])) + sage: bistochastic_as_sum_of_permutations(Matrix(GF(7), 2, [2,1,1,2])) # optional - sage.graphs sage.modules sage.rings.finite_rings Traceback (most recent call last): ... ValueError: The base ring of the matrix must have a coercion map to RR - sage: bistochastic_as_sum_of_permutations(Matrix(ZZ, 2, [2,-1,-1,2])) + sage: bistochastic_as_sum_of_permutations(Matrix(ZZ, 2, [2,-1,-1,2])) # optional - sage.graphs sage.modules Traceback (most recent call last): ... ValueError: The matrix should have nonnegative entries @@ -7937,12 +7956,12 @@ def bounded_affine_permutation(A): EXAMPLES:: sage: from sage.combinat.permutation import bounded_affine_permutation - sage: A = Matrix(ZZ, [[1,0,0,0], [0,1,0,0]]) - sage: bounded_affine_permutation(A) + sage: A = Matrix(ZZ, [[1,0,0,0], [0,1,0,0]]) # optional - sage.modules + sage: bounded_affine_permutation(A) # optional - sage.modules [5, 6, 3, 4] - sage: A = Matrix(ZZ, [[0,1,0,1,0], [0,0,1,1,0]]) - sage: bounded_affine_permutation(A) + sage: A = Matrix(ZZ, [[0,1,0,1,0], [0,0,1,1,0]]) # optional - sage.modules + sage: bounded_affine_permutation(A) # optional - sage.modules [1, 4, 7, 8, 5] REFERENCES: From 429577ded5e60bad3543f9d30f23ce343303a509 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 25 Apr 2023 22:56:36 -0700 Subject: [PATCH 02/26] sage.combinat: More # optional --- src/sage/combinat/combinat.py | 20 +-- src/sage/combinat/composition.py | 2 +- src/sage/combinat/permutation.py | 265 ++++++++++++++++--------------- src/sage/combinat/subset.py | 22 +-- 4 files changed, 156 insertions(+), 153 deletions(-) diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index c4128a176b8..22a314d2636 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -364,9 +364,9 @@ def bell_number(n, algorithm='flint', **options) -> Integer: TESTS:: - sage: all(bell_number(n) == bell_number(n,'dobinski') for n in range(100)) + sage: all(bell_number(n) == bell_number(n,'dobinski') for n in range(100)) # optional - sage.libs.flint True - sage: all(bell_number(n) == bell_number(n,'gap') for n in range(100)) # optional - sage.libs.gap + sage: all(bell_number(n) == bell_number(n,'gap') for n in range(100)) # optional - sage.libs.flint sage.libs.gap True sage: all(bell_number(n) == bell_number(n,'mpmath', prec=500) # optional - mpmath sage.libs.flint ....: for n in range(200, 220)) @@ -551,7 +551,7 @@ def euler_number(n, algorithm='flint') -> Integer: sage: [euler_number(i) for i in range(10)] # optional - sage.libs.flint [1, 0, -1, 0, 5, 0, -61, 0, 1385, 0] sage: x = PowerSeriesRing(QQ, 'x').gen().O(10) - sage: 2/(exp(x)+exp(-x)) + sage: 2/(exp(x)+exp(-x)) # optional - sage.symbolic 1 - 1/2*x^2 + 5/24*x^4 - 61/720*x^6 + 277/8064*x^8 + O(x^10) sage: [euler_number(i)/factorial(i) for i in range(11)] # optional - sage.libs.flint [1, 0, -1/2, 0, 5/24, 0, -61/720, 0, 277/8064, 0, -50521/3628800] @@ -1512,12 +1512,12 @@ class CombinatorialElement(CombinatorialObject, Element, EXAMPLES:: sage: from sage.combinat.combinat import CombinatorialElement - sage: e = CombinatorialElement(Partitions(6), [3,2,1]) - sage: e == loads(dumps(e)) + sage: e = CombinatorialElement(Partitions(6), [3,2,1]) # optional - sage.combinat + sage: e == loads(dumps(e)) # optional - sage.combinat True - sage: parent(e) + sage: parent(e) # optional - sage.combinat Partitions of the integer 6 - sage: list(e) + sage: list(e) # optional - sage.combinat [3, 2, 1] Check classcalls:: @@ -2225,9 +2225,9 @@ def __contains__(self, x) -> bool: False sage: [4,3,2,1] in P False - sage: Permutation([1,2,3]) in P + sage: Permutation([1,2,3]) in P # optional - sage.combinat False - sage: Permutation([3,2,1]) in P + sage: Permutation([3,2,1]) in P # optional - sage.combinat True """ return x in self.combinatorial_class and self.f(x) @@ -2495,7 +2495,7 @@ def __init__(self, cc, f, name=None, *, is_injective=True): """ TESTS:: - sage: Partitions(3).map(attrcall('conjugate')) + sage: Partitions(3).map(attrcall('conjugate')) # optional - sage.combinat Image of Partitions of the integer 3 by The map *.conjugate() from Partitions of the integer 3 """ diff --git a/src/sage/combinat/composition.py b/src/sage/combinat/composition.py index 50f1ee26780..3b6d51a1b6e 100644 --- a/src/sage/combinat/composition.py +++ b/src/sage/combinat/composition.py @@ -1303,7 +1303,7 @@ def shuffle_product(self, other, overlap=False): TESTS:: sage: empty = Composition([]) - sage: empty.shuffle_product(empty).list() + sage: empty.shuffle_product(empty).list() # optional - sage.combinat [[]] """ if overlap: diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index de92bc8acf7..465045b15d4 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -390,8 +390,8 @@ class Permutation(CombinatorialElement): We construct a :class:`Permutation` from a :class:`PermutationGroupElement`:: - sage: g = PermutationGroupElement([2,1,3]) - sage: Permutation(g) + sage: g = PermutationGroupElement([2,1,3]) # optional - sage.groups + sage: Permutation(g) # optional - sage.groups [2, 1, 3] From a pair of tableaux of the same shape. This uses the inverse @@ -399,15 +399,15 @@ class Permutation(CombinatorialElement): sage: p = [[1, 4, 7], [2, 5], [3], [6]] sage: q = [[1, 2, 5], [3, 6], [4], [7]] - sage: P = Tableau(p) - sage: Q = Tableau(q) - sage: Permutation( (p, q) ) + sage: P = Tableau(p) # optional - sage.combinat + sage: Q = Tableau(q) # optional - sage.combinat + sage: Permutation( (p, q) ) # optional - sage.combinat [3, 6, 5, 2, 7, 4, 1] - sage: Permutation( [p, q] ) + sage: Permutation( [p, q] ) # optional - sage.combinat [3, 6, 5, 2, 7, 4, 1] - sage: Permutation( (P, Q) ) + sage: Permutation( (P, Q) ) # optional - sage.combinat [3, 6, 5, 2, 7, 4, 1] - sage: Permutation( [P, Q] ) + sage: Permutation( [P, Q] ) # optional - sage.combinat [3, 6, 5, 2, 7, 4, 1] TESTS:: @@ -423,9 +423,9 @@ class Permutation(CombinatorialElement): From a pair of empty tableaux :: - sage: Permutation( ([], []) ) + sage: Permutation( ([], []) ) # optional - sage.combinat [] - sage: Permutation( [[], []] ) + sage: Permutation( [[], []] ) # optional - sage.combinat [] """ @staticmethod @@ -697,11 +697,11 @@ def _gap_(self, gap): EXAMPLES:: - sage: gap(Permutation([1,2,3])) + sage: gap(Permutation([1,2,3])) # optional - sage.libs.gap () - sage: gap(Permutation((1,2,3))) + sage: gap(Permutation((1,2,3))) # optional - sage.libs.gap (1,2,3) - sage: type(_) + sage: type(_) # optional - sage.libs.gap """ return self.to_permutation_group_element()._gap_(gap) @@ -865,9 +865,9 @@ def to_tableau_by_shape(self, shape): EXAMPLES:: - sage: Permutation([3,4,1,2,5]).to_tableau_by_shape([3,2]) + sage: T = Permutation([3,4,1,2,5]).to_tableau_by_shape([3,2]); T # optional - sage.combinat [[1, 2, 5], [3, 4]] - sage: Permutation([3,4,1,2,5]).to_tableau_by_shape([3,2]).reading_word_permutation() + sage: T.reading_word_permutation() # optional - sage.combinat [3, 4, 1, 2, 5] """ import sage.combinat.tableau as tableau @@ -1137,9 +1137,9 @@ def to_permutation_group_element(self): EXAMPLES:: - sage: Permutation([2,1,4,3]).to_permutation_group_element() + sage: Permutation([2,1,4,3]).to_permutation_group_element() # optional - sage.groups (1,2)(3,4) - sage: Permutation([1,2,3]).to_permutation_group_element() + sage: Permutation([1,2,3]).to_permutation_group_element() # optional - sage.groups () """ grp = SymmetricGroup(len(self)) @@ -1721,15 +1721,16 @@ def show(self, representation="cycles", orientation="landscape", **args): EXAMPLES:: - sage: Permutations(20).random_element().show(representation="cycles") - sage: Permutations(20).random_element().show(representation="chord-diagram") - sage: Permutations(20).random_element().show(representation="braid") - sage: Permutations(20).random_element().show(representation="braid", - ....: orientation='portrait') + sage: P20 = Permutations(20) + sage: P20.random_element().show(representation="cycles") # optional - sage.graphs + sage: P20.random_element().show(representation="chord-diagram") # optional - sage.graphs + sage: P20.random_element().show(representation="braid") # optional - sage.plot + sage: P20.random_element().show(representation="braid", # optional - sage.plot + ....: orientation='portrait') TESTS:: - sage: Permutations(20).random_element().show(representation="modern_art") + sage: P20.random_element().show(representation="modern_art") Traceback (most recent call last): ... ValueError: The value of 'representation' must be equal to 'cycles', 'chord-diagram' or 'braid' @@ -1908,7 +1909,7 @@ def absolute_length(self) -> Integer: EXAMPLES:: - sage: Permutation([4,2,3,1]).absolute_length() + sage: Permutation([4,2,3,1]).absolute_length() # optional - sage.combinat 1 """ return self.size() - len(self.cycle_type()) @@ -2217,7 +2218,8 @@ def longest_increasing_subsequence_length(self) -> Integer: sage: Permutation([2,3,1,4]).longest_increasing_subsequence_length() 3 - sage: all(i.longest_increasing_subsequence_length() == len(RSK(i)[0][0]) for i in Permutations(5)) + sage: all(i.longest_increasing_subsequence_length() == len(RSK(i)[0][0]) # optional - sage.combinat + ....: for i in Permutations(5)) True sage: Permutation([]).longest_increasing_subsequence_length() 0 @@ -2415,9 +2417,9 @@ def forget_cycles(self): results as a poset under the Bruhat order:: sage: l = [p.forget_cycles().inverse() for p in l] - sage: B = Poset([l, lambda x,y: x.bruhat_lequal(y)]) + sage: B = Poset([l, lambda x,y: x.bruhat_lequal(y)]) # optional - sage.combinat sage.graphs sage: R. = QQ[] - sage: sum(q^B.rank_function()(x) for x in B) + sage: sum(q^B.rank_function()(x) for x in B) # optional - sage.combinat sage.graphs q^5 + 2*q^4 + 3*q^3 + 3*q^2 + 2*q + 1 We check the statement in [CC2013]_ that the posets @@ -2425,8 +2427,8 @@ def forget_cycles(self): sage: l2 = [p for p in P if [len(t) for t in p.to_cycles()] == [1,3,1,1]] sage: l2 = [p.forget_cycles().inverse() for p in l2] - sage: B2 = Poset([l2, lambda x,y: x.bruhat_lequal(y)]) - sage: B.is_isomorphic(B2) + sage: B2 = Poset([l2, lambda x,y: x.bruhat_lequal(y)]) # optional - sage.combinat sage.graphs + sage: B.is_isomorphic(B2) # optional - sage.combinat sage.graphs True .. SEEALSO:: @@ -2737,7 +2739,7 @@ def destandardize(self, weight, ordered_alphabet=None): - ``weight`` -- list or tuple of nonnegative integers that sum to `n` if ``self`` is a permutation in `S_n`. - - ``ordered_alphabet`` -- (default: None) a list or tuple specifying the ordered alphabet the + - ``ordered_alphabet`` -- (default: ``None``) a list or tuple specifying the ordered alphabet the destandardized word is over OUTPUT: word over the ``ordered_alphabet`` which standardizes to ``self`` @@ -2752,7 +2754,7 @@ def destandardize(self, weight, ordered_alphabet=None): EXAMPLES:: sage: p = Permutation([1,2,5,3,6,4]) - sage: p.destandardize([3,1,2]) + sage: p.destandardize([3,1,2]) # optional - sage.combinat word: 113132 sage: p = Permutation([2,1,3]) sage: p.destandardize([2,1]) @@ -2763,7 +2765,7 @@ def destandardize(self, weight, ordered_alphabet=None): TESTS:: sage: p = Permutation([4,1,2,3,5,6]) - sage: p.destandardize([2,1,3], ordered_alphabet = [1,'a',3]) + sage: p.destandardize([2,1,3], ordered_alphabet = [1,'a',3]) # optional - sage.combinat word: 311a33 sage: p.destandardize([2,1,3], ordered_alphabet = [1,'a']) Traceback (most recent call last): @@ -5490,14 +5492,14 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations([1,1,2], 2); p Permutations of the multi-set [1, 1, 2] of length 2 - sage: p.list() + sage: p.list() # optional - sage.libs.gap [[1, 1], [1, 2], [2, 1]] :: sage: p = Permutations(descents=([1], 4)); p Standard permutations of 4 with descents [1] - sage: p.list() + sage: p.list() # optional - sage.graphs [[2, 4, 1, 3], [3, 4, 1, 2], [1, 4, 2, 3], [1, 3, 2, 4], [2, 3, 1, 4]] :: @@ -5520,28 +5522,28 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(recoils_finer=[2,1]); p Standard permutations whose recoils composition is finer than [2, 1] - sage: p.list() + sage: p.list() # optional - sage.graphs [[3, 1, 2], [1, 2, 3], [1, 3, 2]] :: sage: p = Permutations(recoils_fatter=[2,1]); p Standard permutations whose recoils composition is fatter than [2, 1] - sage: p.list() + sage: p.list() # optional - sage.graphs [[3, 1, 2], [3, 2, 1], [1, 3, 2]] :: sage: p = Permutations(recoils=[2,1]); p Standard permutations whose recoils composition is [2, 1] - sage: p.list() + sage: p.list() # optional - sage.graphs [[3, 1, 2], [1, 3, 2]] :: sage: p = Permutations(4, avoiding=[1,3,2]); p Standard permutations of 4 avoiding [[1, 3, 2]] - sage: p.list() + sage: p.list() # optional - sage.combinat [[4, 1, 2, 3], [4, 2, 1, 3], [4, 2, 3, 1], @@ -5561,9 +5563,9 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(5, avoiding=[[3,4,1,2], [4,2,3,1]]); p Standard permutations of 5 avoiding [[3, 4, 1, 2], [4, 2, 3, 1]] - sage: p.cardinality() + sage: p.cardinality() # optional - sage.combinat 88 - sage: p.random_element().parent() is p + sage: p.random_element().parent() is p # optional - sage.combinat True """ @staticmethod @@ -6427,7 +6429,7 @@ def __init__(self, mset, k): TESTS:: sage: P = Permutations([1,2,2],2) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.libs.gap """ Permutations_mset.__init__(self, mset) self._k = k @@ -6814,21 +6816,21 @@ def _element_constructor_(self, x, check=True): sage: P([2,3,1]) [2, 3, 1, 4, 5] - sage: G = SymmetricGroup(4) + sage: G = SymmetricGroup(4) # optional - sage.groups sage: P = Permutations(4) - sage: x = G([4,3,1,2]); x + sage: x = G([4,3,1,2]); x # optional - sage.groups (1,4,2,3) - sage: P(x) + sage: P(x) # optional - sage.groups [4, 3, 1, 2] - sage: G(P(x)) + sage: G(P(x)) # optional - sage.groups (1,4,2,3) - sage: P = PermutationGroup([[(1,3,5),(2,4)],[(1,3)]]) - sage: x = P([(3,5),(2,4)]); x + sage: P = PermutationGroup([[(1,3,5),(2,4)],[(1,3)]]) # optional - sage.groups + sage: x = P([(3,5),(2,4)]); x # optional - sage.groups (2,4)(3,5) - sage: Permutations(6)(SymmetricGroup(6)(x)) + sage: Permutations(6)(SymmetricGroup(6)(x)) # optional - sage.groups [1, 4, 5, 2, 3, 6] - sage: Permutations(6)(x) # known bug + sage: Permutations(6)(x) # known bug # optional - sage.groups [1, 4, 5, 2, 3, 6] """ if len(x) < self.n: @@ -7878,7 +7880,7 @@ def bistochastic_as_sum_of_permutations(M, check = True): An exception is raised when the matrix is not positive and bistochastic:: - sage: M = Matrix([[2,3],[2,2]]) + sage: M = Matrix([[2,3],[2,2]]) # optional - sage.modules sage: decomp = bistochastic_as_sum_of_permutations(M) # optional - sage.graphs sage.modules Traceback (most recent call last): ... @@ -8021,7 +8023,7 @@ def __init__(self, d, n): TESTS:: sage: P = Permutations(descents=([1,0,2], 5)) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.graphs """ StandardPermutations_n_abstract.__init__(self, n) self._d = d @@ -8123,7 +8125,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(descents=([2,0],5)).list() + sage: Permutations(descents=([2,0],5)).list() # optional - sage.graphs [[5, 2, 4, 1, 3], [5, 3, 4, 1, 2], [4, 3, 5, 1, 2], @@ -8152,7 +8154,7 @@ def descents_composition_list(dc): EXAMPLES:: sage: import sage.combinat.permutation as permutation - sage: permutation.descents_composition_list([1,2,2]) + sage: permutation.descents_composition_list([1,2,2]) # optional - sage.graphs [[5, 2, 4, 1, 3], [5, 3, 4, 1, 2], [4, 3, 5, 1, 2], @@ -8245,7 +8247,7 @@ def __init__(self, recoils): TESTS:: sage: P = Permutations(recoils_finer=[2,2]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.graphs """ Permutations.__init__(self, category=FiniteEnumeratedSets()) self.recoils = recoils @@ -8266,7 +8268,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils_finer=[2,2]).list() + sage: Permutations(recoils_finer=[2,2]).list() # optional - sage.graphs [[3, 1, 4, 2], [3, 4, 1, 2], [1, 3, 4, 2], @@ -8313,7 +8315,7 @@ def __init__(self, recoils): TESTS:: sage: P = Permutations(recoils_fatter=[2,2]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.graphs """ Permutations.__init__(self, category=FiniteEnumeratedSets()) self.recoils = recoils @@ -8334,7 +8336,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils_fatter=[2,2]).list() + sage: Permutations(recoils_fatter=[2,2]).list() # optional - sage.graphs [[4, 3, 2, 1], [3, 2, 1, 4], [3, 2, 4, 1], @@ -8388,7 +8390,7 @@ def __init__(self, recoils): TESTS:: sage: P = Permutations(recoils=[2,2]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.graphs """ Permutations.__init__(self, category=FiniteEnumeratedSets()) self.recoils = recoils @@ -8409,7 +8411,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils=[2,2]).list() + sage: Permutations(recoils=[2,2]).list() # optional - sage.graphs [[3, 1, 4, 2], [3, 4, 1, 2], [1, 3, 4, 2], [1, 3, 2, 4], [3, 1, 2, 4]] """ recoils = self.recoils @@ -8717,15 +8719,15 @@ def to_standard(p, key=None): EXAMPLES:: sage: import sage.combinat.permutation as permutation - sage: permutation.to_standard([4,2,7]) + sage: permutation.to_standard([4,2,7]) # optional - sage.combinat [2, 1, 3] - sage: permutation.to_standard([1,2,3]) + sage: permutation.to_standard([1,2,3]) # optional - sage.combinat [1, 2, 3] - sage: permutation.to_standard([]) + sage: permutation.to_standard([]) # optional - sage.combinat [] - sage: permutation.to_standard([1,2,3], key=lambda x: -x) + sage: permutation.to_standard([1,2,3], key=lambda x: -x) # optional - sage.combinat [3, 2, 1] - sage: permutation.to_standard([5,8,2,5], key=lambda x: -x) + sage: permutation.to_standard([5,8,2,5], key=lambda x: -x) # optional - sage.combinat [2, 1, 4, 3] TESTS: @@ -8733,7 +8735,7 @@ def to_standard(p, key=None): Does not mutate the list:: sage: a = [1,2,4] - sage: permutation.to_standard(a) + sage: permutation.to_standard(a) # optional - sage.combinat [1, 2, 3] sage: a [1, 2, 4] @@ -8752,8 +8754,8 @@ def to_standard(p, key=None): ....: i += 1 ....: c[smallest_index] = biggest ....: return Permutations()(s) - sage: p = list(Words(100, 1000).random_element()) - sage: std(p) == permutation.to_standard(p) + sage: p = list(Words(100, 1000).random_element()) # optional - sage.combinat + sage: std(p) == permutation.to_standard(p) # optional - sage.combinat True """ ev_dict = evaluation_dict(p) @@ -8783,14 +8785,14 @@ class CyclicPermutations(Permutations_mset): EXAMPLES:: - sage: CyclicPermutations(range(4)).list() + sage: CyclicPermutations(range(4)).list() # optional - sage.combinat [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]] - sage: CyclicPermutations([1,1,1]).list() + sage: CyclicPermutations([1,1,1]).list() # optional - sage.combinat [[1, 1, 1]] """ @staticmethod @@ -8825,16 +8827,16 @@ def __iter__(self, distinct=False): """ EXAMPLES:: - sage: CyclicPermutations(range(4)).list() # indirect doctest + sage: CyclicPermutations(range(4)).list() # indirect doctest # optional - sage.combinat [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]] - sage: CyclicPermutations([1,1,1]).list() + sage: CyclicPermutations([1,1,1]).list() # optional - sage.combinat [[1, 1, 1]] - sage: CyclicPermutations([1,1,1]).list(distinct=True) + sage: CyclicPermutations([1,1,1]).list(distinct=True) # optional - sage.combinat [[1, 1, 1], [1, 1, 1]] """ if distinct: @@ -8855,7 +8857,7 @@ def list(self, distinct=False): """ EXAMPLES:: - sage: CyclicPermutations(range(4)).list() + sage: CyclicPermutations(range(4)).list() # optional - sage.combinat [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], @@ -8876,7 +8878,7 @@ class CyclicPermutationsOfPartition(Permutations): EXAMPLES:: - sage: CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]).list() + sage: CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]).list() # optional - sage.combinat [[[1, 2, 3, 4], [5, 6, 7]], [[1, 2, 4, 3], [5, 6, 7]], [[1, 3, 2, 4], [5, 6, 7]], @@ -8892,7 +8894,7 @@ class CyclicPermutationsOfPartition(Permutations): :: - sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() + sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() # optional - sage.combinat [[[1, 2, 3, 4], [4, 4, 4]], [[1, 2, 4, 3], [4, 4, 4]], [[1, 3, 2, 4], [4, 4, 4]], @@ -8902,12 +8904,12 @@ class CyclicPermutationsOfPartition(Permutations): :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # optional - sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]] :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # optional - sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]], [[1, 2, 3], [4, 4, 4]], @@ -8935,7 +8937,7 @@ def __init__(self, partition): sage: CP = CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]) sage: CP Cyclic permutations of partition [[1, 2, 3, 4], [5, 6, 7]] - sage: TestSuite(CP).run() + sage: TestSuite(CP).run() # optional - sage.combinat """ self.partition = partition Permutations.__init__(self, category=FiniteEnumeratedSets()) @@ -8952,8 +8954,8 @@ def check(self): EXAMPLES:: sage: CP = CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]) - sage: elt = CP[0] - sage: elt.check() + sage: elt = CP[0] # optional - sage.combinat + sage: elt.check() # optional - sage.combinat """ if [sorted(_) for _ in self] != [sorted(_) for _ in self.parent().partition]: raise ValueError("Invalid cyclic permutation of the partition" % self.parent().partition) @@ -8976,7 +8978,8 @@ def __iter__(self, distinct=False): EXAMPLES:: - sage: CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]).list() # indirect doctest + sage: CyclicPermutationsOfPartition([[1,2,3,4], # indirect doctest # optional - sage.combinat + ....: [5,6,7]]).list() [[[1, 2, 3, 4], [5, 6, 7]], [[1, 2, 4, 3], [5, 6, 7]], [[1, 3, 2, 4], [5, 6, 7]], @@ -8992,7 +8995,7 @@ def __iter__(self, distinct=False): :: - sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() + sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() # optional - sage.combinat [[[1, 2, 3, 4], [4, 4, 4]], [[1, 2, 4, 3], [4, 4, 4]], [[1, 3, 2, 4], [4, 4, 4]], @@ -9002,12 +9005,12 @@ def __iter__(self, distinct=False): :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # optional - sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]] :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # optional - sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]], [[1, 2, 3], [4, 4, 4]], @@ -9027,9 +9030,9 @@ def list(self, distinct=False): """ EXAMPLES:: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # optional - sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]] - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # optional - sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]], [[1, 2, 3], [4, 4, 4]], @@ -9065,7 +9068,7 @@ def __init__(self, a): TESTS:: sage: P = Permutations(avoiding=[[2,1,3],[1,2,3]]) - sage: TestSuite(P).run(max_runs=25) + sage: TestSuite(P).run(max_runs=25) # optional - sage.combinat """ Permutations.__init__(self, category=InfiniteEnumeratedSets()) self._a = a @@ -9095,13 +9098,13 @@ def __contains__(self, x): """ TESTS:: - sage: [1,3,2] in Permutations(avoiding=[1,3,2]) + sage: [1,3,2] in Permutations(avoiding=[1,3,2]) # optional - sage.combinat False - sage: [1,3,2] in Permutations(avoiding=[[1,3,2]]) + sage: [1,3,2] in Permutations(avoiding=[[1,3,2]]) # optional - sage.combinat False - sage: [2,1,3] in Permutations(avoiding=[[1,3,2],[1,2,3]]) + sage: [2,1,3] in Permutations(avoiding=[[1,3,2],[1,2,3]]) # optional - sage.combinat True - sage: [2,1,3] in Permutations(avoiding=[]) + sage: [2,1,3] in Permutations(avoiding=[]) # optional - sage.combinat True """ if not super().__contains__(x): @@ -9116,7 +9119,7 @@ def __iter__(self): TESTS:: sage: it = iter(Permutations(avoiding=[[2,1,3],[1,2,3]])) - sage: [next(it) for i in range(10)] + sage: [next(it) for i in range(10)] # optional - sage.combinat [[], [1], [1, 2], @@ -9161,7 +9164,7 @@ def __init__(self, n, a): EXAMPLES:: sage: P = Permutations(3, avoiding=[[2,1,3],[1,2,3]]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat sage: type(P) """ @@ -9202,13 +9205,13 @@ def __contains__(self, x): """ TESTS:: - sage: [1,3,2] in Permutations(3, avoiding=[1,3,2]) + sage: [1,3,2] in Permutations(3, avoiding=[1,3,2]) # optional - sage.combinat False - sage: [1,3,2] in Permutations(3, avoiding=[[1,3,2]]) + sage: [1,3,2] in Permutations(3, avoiding=[[1,3,2]]) # optional - sage.combinat False - sage: [2,1,3] in Permutations(3, avoiding=[[1,3,2],[1,2,3]]) + sage: [2,1,3] in Permutations(3, avoiding=[[1,3,2],[1,2,3]]) # optional - sage.combinat True - sage: [2,1,3] in Permutations(3, avoiding=[]) + sage: [2,1,3] in Permutations(3, avoiding=[]) # optional - sage.combinat True """ if not super().__contains__(x): @@ -9229,9 +9232,9 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[[2, 1, 3],[1,2,3]]).list() + sage: Permutations(3, avoiding=[[2, 1, 3],[1,2,3]]).list() # optional - sage.combinat [[1, 3, 2], [3, 1, 2], [2, 3, 1], [3, 2, 1]] - sage: Permutations(0, avoiding=[[2, 1, 3],[1,2,3]]).list() + sage: Permutations(0, avoiding=[[2, 1, 3],[1,2,3]]).list() # optional - sage.combinat [[]] """ if self.n > 0: @@ -9245,7 +9248,7 @@ def cardinality(self): EXAMPLES:: sage: P = Permutations(3, avoiding=[[2, 1, 3],[1,2,3]]) - sage: P.cardinality() + sage: P.cardinality() # optional - sage.combinat 4 """ one = ZZ.one() @@ -9258,7 +9261,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[1, 2]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([1, 2]),)) @@ -9266,7 +9269,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[1,2]).list() + sage: Permutations(3, avoiding=[1,2]).list() # optional - sage.combinat [[3, 2, 1]] """ yield self.element_class(self, range(self.n, 0, -1), check=False) @@ -9278,7 +9281,7 @@ def cardinality(self): EXAMPLES:: sage: P = Permutations(3, avoiding=[1, 2]) - sage: P.cardinality() + sage: P.cardinality() # optional - sage.combinat 1 """ return ZZ.one() @@ -9290,7 +9293,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 1]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([2, 1]),)) @@ -9298,7 +9301,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[2,1]).list() + sage: Permutations(3, avoiding=[2,1]).list() # optional - sage.combinat [[1, 2, 3]] """ yield self.element_class(self, range(1, self.n+1), check=False) @@ -9310,7 +9313,7 @@ def cardinality(self): EXAMPLES:: sage: P = Permutations(3, avoiding=[2, 1]) - sage: P.cardinality() + sage: P.cardinality() # optional - sage.combinat 1 """ return ZZ.one() @@ -9322,7 +9325,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[1, 3, 2]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([1, 3, 2]),)) @@ -9332,7 +9335,7 @@ def cardinality(self): sage: Permutations(5, avoiding=[1, 3, 2]).cardinality() 42 - sage: len( Permutations(5, avoiding=[1, 3, 2]).list() ) + sage: len( Permutations(5, avoiding=[1, 3, 2]).list() ) # optional - sage.combinat 42 """ return catalan_number(self.n) @@ -9341,9 +9344,9 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[1,3,2]).list() # indirect doctest + sage: Permutations(3, avoiding=[1,3,2]).list() # indirect doctest # optional - sage.combinat [[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] - sage: Permutations(4, avoiding=[1,3,2]).list() + sage: Permutations(4, avoiding=[1,3,2]).list() # optional - sage.combinat [[4, 1, 2, 3], [4, 2, 1, 3], [4, 2, 3, 1], @@ -9399,7 +9402,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 1, 3]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([1, 2, 3]),)) @@ -9407,9 +9410,9 @@ def cardinality(self) -> Integer: """ EXAMPLES:: - sage: Permutations(5, avoiding=[1, 2, 3]).cardinality() + sage: Permutations(5, avoiding=[1, 2, 3]).cardinality() # optional - sage.combinat 42 - sage: len( Permutations(5, avoiding=[1, 2, 3]).list() ) + sage: len( Permutations(5, avoiding=[1, 2, 3]).list() ) # optional - sage.combinat 42 """ return catalan_number(self.n) @@ -9418,11 +9421,11 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[1, 2, 3]).list() # indirect doctest + sage: Permutations(3, avoiding=[1, 2, 3]).list() # indirect doctest # optional - sage.combinat [[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] - sage: Permutations(2, avoiding=[1, 2, 3]).list() + sage: Permutations(2, avoiding=[1, 2, 3]).list() # optional - sage.combinat [[1, 2], [2, 1]] - sage: Permutations(3, avoiding=[1, 2, 3]).list() + sage: Permutations(3, avoiding=[1, 2, 3]).list() # optional - sage.combinat [[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ if self.n == 0: @@ -9471,7 +9474,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[3, 2, 1]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([3, 2, 1]),)) @@ -9479,9 +9482,9 @@ def cardinality(self): """ EXAMPLES:: - sage: Permutations(5, avoiding=[3, 2, 1]).cardinality() + sage: Permutations(5, avoiding=[3, 2, 1]).cardinality() # optional - sage.combinat 42 - sage: len( Permutations(5, avoiding=[3, 2, 1]).list() ) + sage: len( Permutations(5, avoiding=[3, 2, 1]).list() ) # optional - sage.combinat 42 """ return catalan_number(self.n) @@ -9490,7 +9493,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[3, 2, 1]).list() #indirect doctest + sage: Permutations(3, avoiding=[3, 2, 1]).list() # indirect doctest # optional - sage.combinat [[2, 3, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]] """ for p in StandardPermutations_avoiding_123(self.n): @@ -9503,7 +9506,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 3, 1]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([2, 3, 1]),)) @@ -9511,9 +9514,9 @@ def cardinality(self): """ EXAMPLES:: - sage: Permutations(5, avoiding=[2, 3, 1]).cardinality() + sage: Permutations(5, avoiding=[2, 3, 1]).cardinality() # optional - sage.combinat 42 - sage: len( Permutations(5, avoiding=[2, 3, 1]).list() ) + sage: len( Permutations(5, avoiding=[2, 3, 1]).list() ) # optional - sage.combinat 42 """ return catalan_number(self.n) @@ -9522,7 +9525,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[2, 3, 1]).list() + sage: Permutations(3, avoiding=[2, 3, 1]).list() # optional - sage.combinat [[3, 2, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]] """ for p in StandardPermutations_avoiding_132(self.n): @@ -9535,7 +9538,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[3, 1, 2]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([3, 1, 2]),)) @@ -9545,7 +9548,7 @@ def cardinality(self): sage: Permutations(5, avoiding=[3, 1, 2]).cardinality() 42 - sage: len( Permutations(5, avoiding=[3, 1, 2]).list() ) + sage: len( Permutations(5, avoiding=[3, 1, 2]).list() ) # optional - sage.combinat 42 """ return catalan_number(self.n) @@ -9554,7 +9557,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[3, 1, 2]).list() + sage: Permutations(3, avoiding=[3, 1, 2]).list() # optional - sage.combinat [[3, 2, 1], [2, 3, 1], [2, 1, 3], [1, 3, 2], [1, 2, 3]] """ for p in StandardPermutations_avoiding_132(self.n): @@ -9567,7 +9570,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 1, 3]) - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.combinat """ super().__init__(n, (Permutations()([2, 1, 3]),)) @@ -9577,7 +9580,7 @@ def cardinality(self): sage: Permutations(5, avoiding=[2, 1, 3]).cardinality() 42 - sage: len( Permutations(5, avoiding=[2, 1, 3]).list() ) + sage: len( Permutations(5, avoiding=[2, 1, 3]).list() ) # optional - sage.combinat 42 """ return catalan_number(self.n) @@ -9586,7 +9589,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[2, 1, 3]).list() + sage: Permutations(3, avoiding=[2, 1, 3]).list() # optional - sage.combinat [[1, 2, 3], [1, 3, 2], [3, 1, 2], [2, 3, 1], [3, 2, 1]] """ for p in StandardPermutations_avoiding_132(self.n): @@ -9615,7 +9618,7 @@ def _rec(self, obj, state): sage: from sage.combinat.permutation import PatternAvoider sage: P = Permutations(4) sage: p = PatternAvoider(P, [[1,2]]) - sage: list(p._rec([1], 2)) + sage: list(p._rec([1], 2)) # optional - sage.combinat [([2, 1], 3, False)] """ i = state diff --git a/src/sage/combinat/subset.py b/src/sage/combinat/subset.py index c27b1eb04ed..8cb6edb1fc4 100644 --- a/src/sage/combinat/subset.py +++ b/src/sage/combinat/subset.py @@ -1,7 +1,7 @@ r""" Subsets -The set of subsets of a finite set. The set can be given as a list or a Set +The set of subsets of a finite set. The set can be given as a list or a :class:`Set` or else as an integer `n` which encodes the set `\{1,2,...,n\}`. See :class:`Subsets` for more information and examples. @@ -186,11 +186,11 @@ class Subsets_s(Parent): {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}] - sage: S = Subsets(Subsets(Subsets(GF(3)))); S + sage: S = Subsets(Subsets(Subsets(GF(3)))); S # optional - sage.rings.finite_rings Subsets of Subsets of Subsets of Finite Field of size 3 - sage: S.cardinality() + sage: S.cardinality() # optional - sage.rings.finite_rings 115792089237316195423570985008687907853269984665640564039457584007913129639936 - sage: S.unrank(3149254230) # random + sage: S.unrank(3149254230) # random # optional - sage.rings.finite_rings {{{1}, {0, 2}}, {{0, 1, 2}, {0, 1}, {1}, {1, 2}}, {{2}, {1, 2}, {0, 1, 2}, {0, 2}, {1}, {}}, {{1, 2}, {0}}, @@ -248,7 +248,7 @@ def underlying_set(self): EXAMPLES:: - sage: Subsets(GF(13)).underlying_set() + sage: Subsets(GF(13)).underlying_set() # optional - sage.rings.finite_rings {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} """ return self.element_class(self._s) @@ -550,10 +550,10 @@ def lattice(self): EXAMPLES:: sage: X = Subsets([7,8,9]) - sage: X.lattice() + sage: X.lattice() # optional - sage.combinat sage.graphs Finite lattice containing 8 elements sage: Y = Subsets(0) - sage: Y.lattice() + sage: Y.lattice() # optional - sage.combinat sage.graphs Finite lattice containing 1 elements """ @@ -874,8 +874,8 @@ def an_element(self): def dict_to_list(d): r""" - Return a list whose elements are the elements of i of d repeated with - multiplicity d[i]. + Return a list whose elements are the elements of ``i`` of ``d`` repeated with + multiplicity ``d[i]``. EXAMPLES:: @@ -1168,7 +1168,7 @@ def _element_constructor_(self,X): class SubMultiset_sk(SubMultiset_s): """ - The combinatorial class of the subsets of size k of a multiset s. Note + The combinatorial class of the subsets of size ``k`` of a multiset ``s``. Note that each subset is represented by a list of the elements rather than a set since we can have multiplicities (no multiset data structure yet in sage). @@ -1291,7 +1291,7 @@ def __contains__(self, s): def random_element(self): r""" - Return a random submultiset of given length + Return a random submultiset of given length. EXAMPLES:: From c415d7acb117a4e769d5627f9a1c0da311846c5c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 26 Apr 2023 23:19:18 -0700 Subject: [PATCH 03/26] sage.combinat: More # optional --- src/sage/combinat/free_module.py | 8 ++++---- src/sage/combinat/permutation.py | 9 +++++---- src/sage/rings/polynomial/all__sagemath_polyhedra.py | 0 3 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 src/sage/rings/polynomial/all__sagemath_polyhedra.py diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py index 746b0079b9e..2db919f8931 100644 --- a/src/sage/combinat/free_module.py +++ b/src/sage/combinat/free_module.py @@ -252,11 +252,11 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): TESTS:: - sage: XQ = SchubertPolynomialRing(QQ) - sage: XZ = SchubertPolynomialRing(ZZ) - sage: XQ == XZ + sage: XQ = SchubertPolynomialRing(QQ) # optional - sage.combinat + sage: XZ = SchubertPolynomialRing(ZZ) # optional - sage.combinat + sage: XQ == XZ # optional - sage.combinat False - sage: XQ == XQ + sage: XQ == XQ # optional - sage.combinat True We check that issue :trac:`28681` is fixed:: diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 465045b15d4..56944d57dae 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -8059,14 +8059,15 @@ def cardinality(self): sage: Permutations(descents=([1,4], 6)).cardinality() 40 - sage: P = lambda D, n: Permutations(descents=(D, n+1)) - sage: all(P(D, n).cardinality() == len(P(D, n).list()) + sage: def P(D, n): + ....: return Permutations(descents=(D, n + 1)) + sage: all(P(D, n).cardinality() == len(P(D, n).list()) # optional - sage.graphs ....: for n in range(5) for D in subsets(range(n))) True - sage: n = 20; + sage: n = 20 sage: D = [6, 8, 10, 11, 12, 13, 14, 15, 17, 19] - sage: P(D, n).cardinality() + sage: P(D, n).cardinality() # optional - sage.graphs 125291047596 """ diff --git a/src/sage/rings/polynomial/all__sagemath_polyhedra.py b/src/sage/rings/polynomial/all__sagemath_polyhedra.py new file mode 100644 index 00000000000..e69de29bb2d From 9e9f1f1bccb8499f5599475f2c465c0e3f95f500 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 28 Apr 2023 11:56:25 -0700 Subject: [PATCH 04/26] sage.combinat: More # optional --- src/sage/combinat/subsets_hereditary.py | 32 ++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/sage/combinat/subsets_hereditary.py b/src/sage/combinat/subsets_hereditary.py index 5a1347c5218..68fe53e98ea 100644 --- a/src/sage/combinat/subsets_hereditary.py +++ b/src/sage/combinat/subsets_hereditary.py @@ -57,13 +57,14 @@ def subsets_with_hereditary_property(f,X,max_obstruction_size=None,ncpus=1): Sets whose elements all have the same remainder mod 2:: sage: from sage.combinat.subsets_hereditary import subsets_with_hereditary_property - sage: f = lambda x: (not x) or all(xx%2 == x[0]%2 for xx in x) - sage: list(subsets_with_hereditary_property(f,range(4))) + sage: def f(x): + ....: return (not x) or all(xx % 2 == x[0] % 2 for xx in x) + sage: list(subsets_with_hereditary_property(f, range(4))) [[], [0], [1], [2], [3], [0, 2], [1, 3]] Same, on two threads:: - sage: sorted(subsets_with_hereditary_property(f,range(4),ncpus=2)) + sage: sorted(subsets_with_hereditary_property(f, range(4), ncpus=2)) [[], [0], [0, 2], [1], [1, 3], [2], [3]] One can use this function to compute the independent sets of a graph. We @@ -71,33 +72,35 @@ def subsets_with_hereditary_property(f,X,max_obstruction_size=None,ncpus=1): have size 2. We can thus set ``max_obstruction_size=2``, which reduces the number of calls to `f` from 91 to 56:: - sage: num_calls=0 + sage: num_calls = 0 sage: g = graphs.PetersenGraph() sage: def is_independent_set(S): ....: global num_calls - ....: num_calls+=1 - ....: return g.subgraph(S).size()==0 - sage: l1=list(subsets_with_hereditary_property(is_independent_set, g.vertices(sort=False))) + ....: num_calls += 1 + ....: return g.subgraph(S).size() == 0 + sage: l1 = list(subsets_with_hereditary_property(is_independent_set, + ....: g.vertices(sort=False))) sage: num_calls 91 - sage: num_calls=0 - sage: l2=list(subsets_with_hereditary_property(is_independent_set, g.vertices(sort=False), max_obstruction_size=2)) + sage: num_calls = 0 + sage: l2 = list(subsets_with_hereditary_property(is_independent_set, + ....: g.vertices(sort=False), + ....: max_obstruction_size=2)) sage: num_calls 56 - sage: l1==l2 + sage: l1 == l2 True TESTS:: - sage: list(subsets_with_hereditary_property(lambda x:False,range(4))) + sage: list(subsets_with_hereditary_property(lambda x: False, range(4))) [] - sage: list(subsets_with_hereditary_property(lambda x:len(x)<1,range(4))) + sage: list(subsets_with_hereditary_property(lambda x: len(x)<1, range(4))) [[]] - sage: list(subsets_with_hereditary_property(lambda x:True,range(2))) + sage: list(subsets_with_hereditary_property(lambda x: True, range(2))) [[], [0], [1], [0, 1]] """ from sage.data_structures.bitset import Bitset - from sage.parallel.decorate import parallel # About the implementation: # # 1) We work on X={0,...,n-1} but remember X to return correctly @@ -155,6 +158,7 @@ def explore_neighbors(s): return if ncpus != 1: + from sage.parallel.decorate import parallel explore_neighbors_paral = parallel(ncpus=ncpus)(explore_neighbors) # All sets of size 0, then size 1, then ... From 397ebd38b050ace0535498a1ff65f2b0f5c366f4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 14 May 2023 21:30:55 -0700 Subject: [PATCH 05/26] sage.combinat: Add # optional, docstring cosmetics --- .../combinat/binary_recurrence_sequences.py | 23 +- .../cluster_algebra_quiver/cluster_seed.py | 517 +++++++++--------- .../cluster_algebra_quiver/interact.py | 6 +- .../combinat/cluster_algebra_quiver/quiver.py | 10 +- .../quiver_mutation_type.py | 8 +- src/sage/combinat/crystals/mv_polytopes.py | 2 +- src/sage/combinat/designs/block_design.py | 8 +- .../combinat/designs/difference_family.py | 6 +- .../combinat/designs/incidence_structures.py | 21 +- src/sage/combinat/diagram_algebras.py | 28 +- src/sage/combinat/finite_state_machine.py | 14 +- src/sage/combinat/k_tableau.py | 2 +- src/sage/combinat/partition.py | 25 +- src/sage/combinat/path_tableaux/frieze.py | 47 +- src/sage/combinat/perfect_matching.py | 8 +- src/sage/combinat/posets/posets.py | 4 +- src/sage/combinat/q_analogues.py | 12 +- src/sage/combinat/ribbon_tableau.py | 14 +- .../non_symmetric_macdonald_polynomials.py | 10 +- .../root_system/root_lattice_realizations.py | 164 +++--- src/sage/combinat/root_system/root_system.py | 2 +- src/sage/combinat/root_system/type_A.py | 8 +- src/sage/combinat/root_system/type_G.py | 8 +- src/sage/combinat/root_system/type_affine.py | 16 +- src/sage/combinat/rooted_tree.py | 6 +- src/sage/combinat/set_partition.py | 9 +- src/sage/combinat/sf/elementary.py | 4 +- src/sage/combinat/sf/homogeneous.py | 4 +- src/sage/combinat/sf/monomial.py | 4 +- src/sage/combinat/sf/ns_macdonald.py | 14 +- src/sage/combinat/sf/powersum.py | 10 +- src/sage/combinat/sf/schur.py | 6 +- src/sage/combinat/species/structure.py | 5 +- src/sage/combinat/tutorial.py | 122 ++--- src/sage/combinat/words/finite_word.py | 8 +- src/sage/combinat/words/word_generators.py | 56 +- 36 files changed, 623 insertions(+), 588 deletions(-) diff --git a/src/sage/combinat/binary_recurrence_sequences.py b/src/sage/combinat/binary_recurrence_sequences.py index 8c244342712..46c99fd24aa 100644 --- a/src/sage/combinat/binary_recurrence_sequences.py +++ b/src/sage/combinat/binary_recurrence_sequences.py @@ -19,12 +19,12 @@ sage: R.pthpowers(2, 10**10) # long time (7 seconds) -- in fact these are all squares, c.f. [BMS06] [0, 1, 2, 12] - sage: S = BinaryRecurrenceSequence(8,1) #a Lucas sequence + sage: S = BinaryRecurrenceSequence(8,1) #a Lucas sequence sage: S.period(73) 148 sage: S(5) % 73 == S(5 +148) %73 True - sage: S.pthpowers(3,10**10) # long time (3 seconds) -- provably finds the indices of all 3rd powers less than 10^10 + sage: S.pthpowers(3, 10**10) # long time (3 seconds) -- provably finds the indices of all 3rd powers less than 10^10 [0, 1, 2] sage: T = BinaryRecurrenceSequence(2,0,1,2) @@ -34,10 +34,11 @@ True sage: T.is_geometric() True - sage: T.pthpowers(7,10**30) + sage: T.pthpowers(7, 10**30) # optional - sage.symbolic Traceback (most recent call last): ... - ValueError: the degenerate binary recurrence sequence is geometric or quasigeometric and has many pth powers + ValueError: the degenerate binary recurrence sequence is geometric or quasigeometric + and has many pth powers AUTHORS: @@ -544,17 +545,18 @@ def pthpowers(self, p, Bound): True sage: T.is_geometric() True - sage: T.pthpowers(7,10**30) + sage: T.pthpowers(7, 10**30) # optional - sage.symbolic Traceback (most recent call last): ... - ValueError: the degenerate binary recurrence sequence is geometric or quasigeometric and has many pth powers + ValueError: the degenerate binary recurrence sequence is geometric or + quasigeometric and has many pth powers sage: L = BinaryRecurrenceSequence(4,0,2,2) sage: [L(i).factor() for i in range(10)] [2, 2, 2^3, 2^5, 2^7, 2^9, 2^11, 2^13, 2^15, 2^17] sage: L.is_quasigeometric() True - sage: L.pthpowers(2,10**30) + sage: L.pthpowers(2, 10**30) # optional - sage.symbolic [] .. NOTE:: @@ -1051,7 +1053,8 @@ def _estimated_time(M2, M1, length, p): EXAMPLES:: - sage: sage.combinat.binary_recurrence_sequences._estimated_time(2**4*3**2*5*7*11*13*17, 2**4*3**2*5*7*11*13, 20, 7) + sage: from sage.combinat.binary_recurrence_sequences import _estimated_time + sage: _estimated_time(2**4*3**2*5*7*11*13*17, 2**4*3**2*5*7*11*13, 20, 7) # optional - sage.symbolic 106.211159309421 """ @@ -1137,9 +1140,9 @@ def _is_p_power(a, p): EXAMPLES:: - sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7,7) + sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7, 7) # optional - sage.symbolic True - sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7*3**2,7) + sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7*3**2, 7) # optional - sage.symbolic False """ return int(a**(1/p))**p == a diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index 1209bdcdbbc..31eac5999df 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -66,12 +66,12 @@ class ClusterSeed(SageObject): - ``data`` -- can be any of the following:: - * QuiverMutationType - * str - a string representing a QuiverMutationType or a common quiver type (see Examples) - * ClusterQuiver - * Matrix - a skew-symmetrizable matrix - * DiGraph - must be the input data for a quiver - * List of edges - must be the edge list of a digraph for a quiver + * :class:`QuiverMutationType` + * :class:`str` -- a string representing a :class:`QuiverMutationType` or a common quiver type (see Examples) + * :class:`ClusterQuiver` + * :class:`Matrix` -- a skew-symmetrizable matrix + * :class:`DiGraph` -- must be the input data for a quiver + * List of edges -- must be the edge list of a digraph for a quiver EXAMPLES:: @@ -110,24 +110,21 @@ class ClusterSeed(SageObject): sage: S = ClusterSeed(['A',4]); S._use_fpolys True - sage: S._use_d_vec True - sage: S._use_g_vec True - sage: S._use_c_vec True sage: S = ClusterSeed(['A', 4]); S.use_fpolys(False); S._use_fpolys False - sage: S = ClusterSeed(DiGraph([['a', 'b'], ['c', 'b'], ['c', 'd'], ['e', 'd']]), frozen = - ....: ['c']); S + sage: S = ClusterSeed(DiGraph([['a', 'b'], ['c', 'b'], ['c', 'd'], ['e', 'd']]), + ....: frozen=['c']); S A seed for a cluster algebra of rank 4 with 1 frozen variable - sage: S = ClusterSeed(['D', 4],user_labels = [-1, 0, 1, 2]);S + sage: S = ClusterSeed(['D', 4],user_labels = [-1, 0, 1, 2]); S A seed for a cluster algebra of rank 4 of type ['D', 4] """ @@ -367,14 +364,16 @@ def __init__(self, data, frozen=None, is_principal=False, user_labels=None, user def use_c_vectors(self, use=True, bot_is_c=False, force=False): r""" - Reconstruct c vectors from other data or initialize if no usable data exists. + Reconstruct c-vectors from other data or initialize if no usable data exists. Warning: Initialization may lead to inconsistent data. INPUT: - - ``use`` -- (default:True) If True, will use c vectors - - ``bot_is_c`` -- (default:False) If True and ClusterSeed self has self._m == self._n, then will assume bottom half of the extended exchange matrix is the c-matrix. If true, lets the ClusterSeed know c-vectors can be calculated. + - ``use`` -- (default: ``True``) If ``True``, will use c-vectors + - ``bot_is_c`` -- (default: ``False``) If ``True`` and :class:`ClusterSeed` ``self`` has ``self._m == self._n``, + then will assume bottom half of the extended exchange matrix is the c-matrix. + If ``True``, lets the :class:`ClusterSeed` know c-vectors can be calculated. EXAMPLES:: @@ -443,13 +442,13 @@ def use_c_vectors(self, use=True, bot_is_c=False, force=False): def use_g_vectors(self, use=True, force=False): r""" - Reconstruct g vectors from other data or initialize if no usable data exists. + Reconstruct g-vectors from other data or initialize if no usable data exists. Warning: Initialization may lead to inconsistent data. INPUT: - - ``use`` -- (default:True) If True, will use g vectors + - ``use`` -- (default: ``True``) If ``True``, will use g-vectors EXAMPLES:: @@ -524,13 +523,13 @@ def use_g_vectors(self, use=True, force=False): def use_d_vectors(self, use=True, force=False): r""" - Reconstruct d vectors from other data or initialize if no usable data exists. + Reconstruct d-vectors from other data or initialize if no usable data exists. Warning: Initialization may lead to inconsistent data. INPUT: - - ``use`` -- (default:True) If True, will use d vectors + - ``use`` -- (default: ``True``) If ``True``, will use d-vectors EXAMPLES:: @@ -542,7 +541,8 @@ def use_d_vectors(self, use=True, force=False): [ 0 0 -1 0] [ 0 0 0 -1] - sage: S = ClusterSeed(['A',4]); S.use_d_vectors(False); S.track_mutations(False); S.mutate(1); S.d_matrix() + sage: S = ClusterSeed(['A',4]); S.use_d_vectors(False) + sage: S.track_mutations(False); S.mutate(1); S.d_matrix() [-1 0 0 0] [ 0 1 0 0] [ 0 0 -1 0] @@ -553,14 +553,16 @@ def use_d_vectors(self, use=True, force=False): ... ValueError: Unable to calculate d-vectors. Need to use d vectors. - sage: S = ClusterSeed(['A',4]); S.use_d_vectors(False); S.track_mutations(False); S.mutate(1); S.d_matrix() + sage: S = ClusterSeed(['A',4]); S.use_d_vectors(False) + sage: S.track_mutations(False); S.mutate(1); S.d_matrix() [-1 0 0 0] [ 0 1 0 0] [ 0 0 -1 0] [ 0 0 0 -1] sage: S.use_fpolys(False) sage: S.use_d_vectors(True) - Warning: Initializing d-vectors at this point could lead to inconsistent seed data. + Warning: Initializing d-vectors at this point + could lead to inconsistent seed data. sage: S.use_d_vectors(True, force=True) sage: S.d_matrix() @@ -610,9 +612,9 @@ def use_fpolys(self, use=True, user_labels=None, user_labels_prefix=None): INPUT: - - ``use`` -- (default:True) If True, will use F-polynomials - - ``user_labels`` -- (default:None) If set will overwrite the default cluster variable labels - - ``user_labels_prefix`` -- (default:None) If set will overwrite the default + - ``use`` -- (default: ``True``) If ``True``, will use F-polynomials + - ``user_labels`` -- (default: ``None``) If set, will overwrite the default cluster variable labels + - ``user_labels_prefix`` -- (default: ``None``) If set, will overwrite the default EXAMPLES:: @@ -621,11 +623,13 @@ def use_fpolys(self, use=True, user_labels=None, user_labels_prefix=None): sage: S.cluster() [x0, x1, x2, x3] - sage: S = ClusterSeed(['A',4]); S.use_fpolys(False); S.track_mutations(False); S.mutate(1) + sage: S = ClusterSeed(['A',4]); S.use_fpolys(False); S.track_mutations(False) + sage: S.mutate(1) sage: S.use_fpolys(True) Traceback (most recent call last): ... - ValueError: F-polynomials and Cluster Variables cannot be reconstructed from given data. + ValueError: F-polynomials and Cluster Variables cannot be reconstructed + from given data. sage: S.cluster() Traceback (most recent call last): ... @@ -698,11 +702,11 @@ def track_mutations(self, use=True): r""" Begins tracking the mutation path. - Warning: May initialize all other data to ensure that all c, d, and g vectors agree on the start of mutations. + Warning: May initialize all other data to ensure that all c-, d-, and g-vectors agree on the start of mutations. INPUT: - - ``use`` -- (default:True) If True, will begin filling the mutation path + - ``use`` -- (default: ``True``) If ``True``, will begin filling the mutation path EXAMPLES:: @@ -758,7 +762,7 @@ def _sanitize_init_vars(self, user_labels, user_labels_prefix='x'): INPUT: - ``user_labels`` -- The labels that need sanitizing - - ``user_labels_prefix`` -- (default:'x') The prefix to use for labels if integers given for labels + - ``user_labels_prefix`` -- (default: ``'x'``) The prefix to use for labels if integers given for labels EXAMPLES:: @@ -821,12 +825,12 @@ def _sanitize_init_vars(self, user_labels, user_labels_prefix='x'): def set_c_matrix(self, data): r""" - Will force set the c matrix according to a matrix, a quiver, or a seed. + Will force set the c-matrix according to a matrix, a quiver, or a seed. INPUT: - - ``data`` -- The matrix to set the c matrix to. Also allowed - to be a quiver or cluster seed, in which case the b_matrix + - ``data`` -- The matrix to set the c-matrix to. Also allowed + to be a quiver or cluster seed, in which case the b-matrix is used. EXAMPLES:: @@ -841,7 +845,8 @@ def set_c_matrix(self, data): sage: Y = matrix([[-1,0,1],[0,1,0],[1,0,0]]) sage: S.set_c_matrix(Y) - C matrix does not look to be valid - there exists a column containing positive and negative entries. + C matrix does not look to be valid - there exists a column + containing positive and negative entries. Continuing... sage: Z = matrix([[1,0,1],[0,1,0],[2,0,2]]) @@ -872,7 +877,7 @@ def set_c_matrix(self, data): def __eq__(self, other): r""" - Returns True iff ``self`` represent the same cluster seed as ``other`` and all tracked data agrees. + Return ``True`` iff ``self`` represent the same cluster seed as ``other`` and all tracked data agrees. EXAMPLES:: @@ -945,7 +950,7 @@ def __hash__(self): def _repr_(self): r""" - Returns the description of ``self``. + Return the description of ``self``. EXAMPLES:: @@ -976,25 +981,25 @@ def _repr_(self): def plot(self, circular=False, mark=None, save_pos=False, force_c=False, with_greens=False, add_labels=False): r""" - Returns the plot of the quiver of ``self``. + Return the plot of the quiver of ``self``. INPUT: - - ``circular`` -- (default:False) if True, the circular plot is chosen, otherwise >>spring<< is used. - - ``mark`` -- (default: None) if set to i, the vertex i is highlighted. - - ``save_pos`` -- (default:False) if True, the positions of the vertices are saved. - - ``force_c`` -- (default:False) if True, will show the frozen vertices even if they were never initialized - - ``with_greens`` -- (default:False) if True, will display the green vertices in green - - ``add_labels`` -- (default:False) if True, will use the initial variables as labels + - ``circular`` -- (default: ``False``) if ``True``, the circular plot is chosen, otherwise >>spring<< is used. + - ``mark`` -- (default: ``None``) if set to i, the vertex i is highlighted. + - ``save_pos`` -- (default: ``False``) if ``True``, the positions of the vertices are saved. + - ``force_c`` -- (default: ``False``) if ``True``, will show the frozen vertices even if they were never initialized + - ``with_greens`` -- (default: ``False``) if ``True``, will display the green vertices in green + - ``add_labels`` -- (default: ``False``) if ``True``, will use the initial variables as labels EXAMPLES:: sage: S = ClusterSeed(['A',5]) - sage: S.plot() + sage: S.plot() # optional - sage.plot sage.symbolic Graphics object consisting of 15 graphics primitives - sage: S.plot(circular=True) + sage: S.plot(circular=True) # optional - sage.plot sage.symbolic Graphics object consisting of 15 graphics primitives - sage: S.plot(circular=True, mark=1) + sage: S.plot(circular=True, mark=1) # optional - sage.plot sage.symbolic Graphics object consisting of 15 graphics primitives """ greens = [] @@ -1019,17 +1024,17 @@ def show(self, fig_size=1, circular=False, mark=None, save_pos=False, force_c=Fa INPUT: - ``fig_size`` -- (default: 1) factor by which the size of the plot is multiplied. - - ``circular`` -- (default: False) if True, the circular plot is chosen, otherwise >>spring<< is used. - - ``mark`` -- (default: None) if set to i, the vertex i is highlighted. - - ``save_pos`` -- (default:False) if True, the positions of the vertices are saved. - - ``force_c`` -- (default:False) if True, will show the frozen vertices even if they were never initialized - - ``with_greens`` -- (default:False) if True, will display the green vertices in green - - ``add_labels`` -- (default:False) if True, will use the initial variables as labels + - ``circular`` -- (default: ``False``) if ``True``, the circular plot is chosen, otherwise >>spring<< is used. + - ``mark`` -- (default: ``None``) if set to i, the vertex i is highlighted. + - ``save_pos`` -- (default: ``False``) if ``True``, the positions of the vertices are saved. + - ``force_c`` -- (default: ``False``) if ``True``, will show the frozen vertices even if they were never initialized + - ``with_greens`` -- (default: ``False``) if ``True``, will display the green vertices in green + - ``add_labels`` -- (default: ``False``) if ``True``, will use the initial variables as labels TESTS:: sage: S = ClusterSeed(['A',5]) - sage: S.show() # long time + sage: S.show() # long time # optional - sage.plot sage.symbolic """ greens = [] if with_greens: @@ -1063,27 +1068,27 @@ def interact(self, fig_size=1, circular=True): TESTS:: sage: S = ClusterSeed(['A',4]) - sage: S.interact() + sage: S.interact() # optional - sage.plot sage.symbolic ...VBox(children=... """ return cluster_interact(self, fig_size, circular, kind='seed') def save_image(self, filename, circular=False, mark=None, save_pos=False): r""" - Saves the plot of the underlying digraph of the quiver of ``self``. + Save the plot of the underlying digraph of the quiver of ``self``. INPUT: - ``filename`` -- the filename the image is saved to. - - ``circular`` -- (default: False) if True, the circular plot is chosen, otherwise >>spring<< is used. - - ``mark`` -- (default: None) if set to i, the vertex i is highlighted. - - ``save_pos`` -- (default:False) if True, the positions of the vertices are saved. + - ``circular`` -- (default: ``False``) if ``True``, the circular plot is chosen, otherwise >>spring<< is used. + - ``mark`` -- (default: ``None``) if set to i, the vertex i is highlighted. + - ``save_pos`` -- (default: ``False``) if ``True``, the positions of the vertices are saved. EXAMPLES:: sage: S = ClusterSeed(['F',4,[1,2]]) sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.plot sage.symbolic ....: S.save_image(f.name) """ graph_plot = self.plot(circular=circular, mark=mark, save_pos=save_pos) @@ -1091,7 +1096,7 @@ def save_image(self, filename, circular=False, mark=None, save_pos=False): def b_matrix(self): r""" - Returns the `B` *-matrix* of ``self``. + Return the `B` *-matrix* of ``self``. EXAMPLES:: @@ -1123,7 +1128,7 @@ def b_matrix(self): def ground_field(self): r""" - Returns the *ground field* of the cluster of ``self``. + Return the *ground field* of the cluster of ``self``. EXAMPLES:: @@ -1136,7 +1141,7 @@ def ground_field(self): def x(self, k): r""" Return the `k` *-th initial cluster variable* for the associated cluster seed, - or the cluster variable of the corresponding vertex in self.quiver. + or the cluster variable of the corresponding vertex in ``self.quiver``. EXAMPLES:: @@ -1152,7 +1157,7 @@ def x(self, k): x2 sage: dg = DiGraph([['a', 'b'], ['b', 'c']], format="list_of_edges") - sage: S = ClusterSeed(dg, frozen = ['c']) + sage: S = ClusterSeed(dg, frozen=['c']) sage: S.x(0) a sage: S.x('a') @@ -1175,7 +1180,7 @@ def y(self, k): r""" Return the `k` *-th initial coefficient (frozen variable)* for the associated cluster seed, or the cluster variable of the corresponding - vertex in self.quiver. + vertex in ``self.quiver``. EXAMPLES:: @@ -1191,7 +1196,7 @@ def y(self, k): y2 sage: dg = DiGraph([['a', 'b'], ['b', 'c']], format="list_of_edges") - sage: S = ClusterSeed(dg, frozen = ['c']) + sage: S = ClusterSeed(dg, frozen=['c']) sage: S.y(0) c sage: S.y('c') @@ -1223,7 +1228,7 @@ def n(self): def m(self): r""" - Returns the number of *frozen variables* of ``self``. + Return the number of *frozen variables* of ``self``. EXAMPLES:: @@ -1247,7 +1252,7 @@ def free_vertices(self): EXAMPLES:: sage: S = ClusterSeed(DiGraph([['a', 'b'], ['c', 'b'], ['c', 'd'], ['e', 'd']]), - ....: frozen = ['b', 'd']) + ....: frozen=['b', 'd']) sage: S.free_vertices() ['a', 'c', 'e'] @@ -1264,7 +1269,7 @@ def frozen_vertices(self): EXAMPLES:: sage: S = ClusterSeed(DiGraph([['a', 'b'], ['c', 'b'], ['c', 'd'], ['e', 'd']]), - ....: frozen = ['b', 'd']) + ....: frozen=['b', 'd']) sage: sorted(S.frozen_vertices()) ['b', 'd'] """ @@ -1334,7 +1339,7 @@ def cluster_variable(self, k): def cluster(self): r""" - Returns a copy of the *cluster* of ``self``. + Return a copy of the *cluster* of ``self``. EXAMPLES:: @@ -1422,7 +1427,8 @@ def f_polynomial(self, k): sage: [S.f_polynomial(k) for k in range(3)] [1, y1*y2 + y2 + 1, y1 + 1] - sage: S = ClusterSeed(Matrix([[0,1],[-1,0],[1,0],[-1,1]])); S.use_c_vectors(bot_is_c=True); S + sage: S = ClusterSeed(Matrix([[0,1],[-1,0],[1,0],[-1,1]])) + sage: S.use_c_vectors(bot_is_c=True); S A seed for a cluster algebra of rank 2 with 2 frozen variables sage: T = ClusterSeed(Matrix([[0,1],[-1,0]])).principal_extension(); T A seed for a cluster algebra of rank 2 with principal coefficients @@ -1534,14 +1540,16 @@ def g_matrix(self, show_warnings=True): [ 1 0 0] [ 0 0 1] - sage: S = ClusterSeed(['A',4]); S.use_g_vectors(False); S.use_fpolys(False); S.g_matrix() + sage: S = ClusterSeed(['A',4]) + sage: S.use_g_vectors(False); S.use_fpolys(False); S.g_matrix() [1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1] sage: S = ClusterSeed(['A',4]) - sage: S.use_g_vectors(False); S.use_c_vectors(False); S.use_fpolys(False); S.track_mutations(False); S.g_matrix() + sage: S.use_g_vectors(False); S.use_c_vectors(False); S.use_fpolys(False) + sage: S.track_mutations(False); S.g_matrix() Traceback (most recent call last): ... ValueError: Unable to calculate g-vectors. Need to use g vectors. @@ -1630,7 +1638,8 @@ def c_vector(self, k): sage: S.c_vector(0) (1, 0) - sage: S = ClusterSeed(Matrix([[0,1],[-1,0],[1,0],[-1,1]])); S.use_c_vectors(bot_is_c=True); S + sage: S = ClusterSeed(Matrix([[0,1],[-1,0],[1,0],[-1,1]])) + sage: S.use_c_vectors(bot_is_c=True); S A seed for a cluster algebra of rank 2 with 2 frozen variables sage: S.c_vector(0) (1, -1) @@ -1662,7 +1671,8 @@ def c_matrix(self, show_warnings=True): [ 0 -1 0] sage: S = ClusterSeed(['A',4]) - sage: S.use_g_vectors(False); S.use_fpolys(False); S.use_c_vectors(False); S.use_d_vectors(False); S.track_mutations(False); + sage: S.use_g_vectors(False); S.use_fpolys(False) + sage: S.use_c_vectors(False); S.use_d_vectors(False); S.track_mutations(False) sage: S.c_matrix() Traceback (most recent call last): ... @@ -1861,7 +1871,7 @@ def quiver(self): def is_acyclic(self) -> bool: r""" - Return True iff self is acyclic (i.e., if the underlying quiver is acyclic). + Return ``True`` iff ``self`` is acyclic (i.e., if the underlying quiver is acyclic). EXAMPLES:: @@ -1878,11 +1888,11 @@ def is_acyclic(self) -> bool: def is_bipartite(self, return_bipartition=False): r""" - Return True iff self is bipartite (i.e., if the underlying quiver is bipartite). + Return ``True`` iff ``self`` is bipartite (i.e., if the underlying quiver is bipartite). INPUT: - - return_bipartition -- (default:False) if True, the bipartition is returned in the case of ``self`` being bipartite. + - ``return_bipartition`` -- (default: ``False``) if ``True``, the bipartition is returned in the case of ``self`` being bipartite. EXAMPLES:: @@ -2014,7 +2024,7 @@ def urban_renewals(self, return_first=False): INPUT: - - ``return_first`` -- (default:False) if True, will return the first urban renewal + - ``return_first`` -- (default: ``False``) if ``True``, will return the first urban renewal OUTPUT: @@ -2056,7 +2066,7 @@ def highest_degree_denominator(self, filter=None): INPUT: - - ``filter`` - Filter should be a list or iterable + - ``filter`` -- a list or iterable OUTPUT: @@ -2064,7 +2074,8 @@ def highest_degree_denominator(self, filter=None): EXAMPLES:: - sage: B = matrix([[0,-1,0,-1,1,1],[1,0,1,0,-1,-1],[0,-1,0,-1,1,1],[1,0,1,0,-1,-1],[-1,1,-1,1,0,0],[-1,1,-1,1,0,0]]) + sage: B = matrix([[0,-1,0,-1,1,1], [1,0,1,0,-1,-1], [0,-1,0,-1,1,1], + ....: [1,0,1,0,-1,-1], [-1,1,-1,1,0,0], [-1,1,-1,1,0,0]]) sage: C = ClusterSeed(B).principal_extension(); C.mutate([0,1,2,4,3,2,5,4,3]) sage: C.highest_degree_denominator() 5 @@ -2102,20 +2113,17 @@ def highest_degree_denominator(self, filter=None): def smallest_c_vector(self): r""" - Return the vertex with the smallest c vector. - - OUTPUT: + Return the vertex with the smallest c-vector. - An integer. + OUTPUT: An integer. EXAMPLES:: - sage: B = matrix([[0,2],[-2,0]]) + sage: B = matrix([[0,2], [-2,0]]) sage: C = ClusterSeed(B).principal_extension() sage: C.mutate(0) sage: C.smallest_c_vector() 0 - """ min_sum = infinity vertex_to_mutate = [] @@ -2135,7 +2143,6 @@ def smallest_c_vector(self): def most_decreased_edge_after_mutation(self): r""" - Return the vertex that will produce the least degrees after mutation EXAMPLES:: @@ -2144,7 +2151,6 @@ def most_decreased_edge_after_mutation(self): sage: S.mutate([0,2,3,1,2,3,1,2,0,2,3]) sage: S.most_decreased_edge_after_mutation() 2 - """ analysis = self.mutation_analysis(['edge_diff']) least_edge = infinity @@ -2165,7 +2171,6 @@ def most_decreased_edge_after_mutation(self): def most_decreased_denominator_after_mutation(self): r""" - Return the vertex that will produce the most decrease in denominator degrees after mutation EXAMPLES:: @@ -2174,7 +2179,6 @@ def most_decreased_denominator_after_mutation(self): sage: S.mutate([0,2,3,1,2,3,1,2,0,2,3]) sage: S.most_decreased_denominator_after_mutation() 2 - """ analysis = self.mutation_analysis(['d_matrix']) least_change = infinity @@ -2639,13 +2643,13 @@ def mutation_sequence(self, sequence, show_sequence=False, INPUT: - ``sequence`` -- an iterable of vertices of self. - - ``show_sequence`` -- (default: False) if True, a png containing the associated quivers is shown. + - ``show_sequence`` -- (default: ``False``) if ``True``, a png containing the associated quivers is shown. - ``fig_size`` -- (default: 1.2) factor by which the size of the plot is multiplied. - ``return_output`` -- (default: 'seed') determines what output is to be returned:: - * if 'seed', outputs all the cluster seeds obtained by the ``sequence`` of mutations. - * if 'matrix', outputs a list of exchange matrices. - * if 'var', outputs a list of new cluster variables obtained at each step. + * if ``'seed'``, outputs all the cluster seeds obtained by the ``sequence`` of mutations. + * if ``'matrix'``, outputs a list of exchange matrices. + * if ``'var'``, outputs a list of new cluster variables obtained at each step. EXAMPLES:: @@ -2693,8 +2697,8 @@ def mutation_analysis(self, options=['all'], filter=None): INPUT: - - ``options`` -- (default: ['all']) a list of mutation options. - - ``filter`` -- (default: None) A vertex or interval of vertices to limit our search to + - ``options`` -- (default: [``'all'``]) a list of mutation options. + - ``filter`` -- (default: ``None``) A vertex or interval of vertices to limit our search to Possible options are: @@ -2717,7 +2721,7 @@ def mutation_analysis(self, options=['all'], filter=None): Outputs a dictionary indexed by the vertex numbers. Each vertex will itself also be a dictionary with each desired option included as a key in the dictionary. As an example - you would get something similar to: {0: {'edges': 1}, 1: {'edges': 2}}. This represents + you would get something similar to: ``{0: {'edges': 1}, 1: {'edges': 2}}``. This represents that if you were to do a mutation at the current seed then mutating at vertex 0 would result in a quiver with 1 edge and mutating at vertex 0 would result in a quiver with 2 edges. @@ -2727,118 +2731,118 @@ def mutation_analysis(self, options=['all'], filter=None): sage: S = ClusterSeed(matrix(B)); S.mutate([2,3,1,2,1,3,0,2]) sage: S.mutation_analysis() {0: {'d_matrix': [ 0 0 1 0] - [ 0 -1 0 0] - [ 0 0 0 -1] - [-1 0 0 0], - 'denominators': [1, 1, x0, 1], - 'edge_diff': 6, - 'edges': 13, - 'green_vertices': [0, 1, 3], - 'green_vertices_diff': {'added': [0], 'removed': []}, - 'red_vertices': [2], - 'red_vertices_diff': {'added': [], 'removed': [0]}, - 'sinks': [], - 'sinks_diff': {'added': [], 'removed': [2]}, - 'sources': [], - 'sources_diff': {'added': [], 'removed': []}, - 'urban_renewals': [], - 'urban_renewals_diff': {'added': [], 'removed': []}}, + [ 0 -1 0 0] + [ 0 0 0 -1] + [-1 0 0 0], + 'denominators': [1, 1, x0, 1], + 'edge_diff': 6, + 'edges': 13, + 'green_vertices': [0, 1, 3], + 'green_vertices_diff': {'added': [0], 'removed': []}, + 'red_vertices': [2], + 'red_vertices_diff': {'added': [], 'removed': [0]}, + 'sinks': [], + 'sinks_diff': {'added': [], 'removed': [2]}, + 'sources': [], + 'sources_diff': {'added': [], 'removed': []}, + 'urban_renewals': [], + 'urban_renewals_diff': {'added': [], 'removed': []}}, 1: {'d_matrix': [ 1 4 1 0] - [ 0 1 0 0] - [ 0 0 0 -1] - [ 1 4 0 0], - 'denominators': [x0*x3, x0^4*x1*x3^4, x0, 1], - 'edge_diff': 2, - 'edges': 9, - 'green_vertices': [0, 3], - 'green_vertices_diff': {'added': [0], 'removed': [1]}, - 'red_vertices': [1, 2], - 'red_vertices_diff': {'added': [1], 'removed': [0]}, - 'sinks': [2], - 'sinks_diff': {'added': [], 'removed': []}, - 'sources': [], - 'sources_diff': {'added': [], 'removed': []}, - 'urban_renewals': [], - 'urban_renewals_diff': {'added': [], 'removed': []}}, + [ 0 1 0 0] + [ 0 0 0 -1] + [ 1 4 0 0], + 'denominators': [x0*x3, x0^4*x1*x3^4, x0, 1], + 'edge_diff': 2, + 'edges': 9, + 'green_vertices': [0, 3], + 'green_vertices_diff': {'added': [0], 'removed': [1]}, + 'red_vertices': [1, 2], + 'red_vertices_diff': {'added': [1], 'removed': [0]}, + 'sinks': [2], + 'sinks_diff': {'added': [], 'removed': []}, + 'sources': [], + 'sources_diff': {'added': [], 'removed': []}, + 'urban_renewals': [], + 'urban_renewals_diff': {'added': [], 'removed': []}}, 2: {'d_matrix': [ 1 0 0 0] - [ 0 -1 0 0] - [ 0 0 0 -1] - [ 1 0 1 0], - 'denominators': [x0*x3, 1, x3, 1], - 'edge_diff': 0, - 'edges': 7, - 'green_vertices': [1, 2, 3], - 'green_vertices_diff': {'added': [2], 'removed': []}, - 'red_vertices': [0], - 'red_vertices_diff': {'added': [], 'removed': [2]}, - 'sinks': [], - 'sinks_diff': {'added': [], 'removed': [2]}, - 'sources': [2], - 'sources_diff': {'added': [2], 'removed': []}, - 'urban_renewals': [], - 'urban_renewals_diff': {'added': [], 'removed': []}}, + [ 0 -1 0 0] + [ 0 0 0 -1] + [ 1 0 1 0], + 'denominators': [x0*x3, 1, x3, 1], + 'edge_diff': 0, + 'edges': 7, + 'green_vertices': [1, 2, 3], + 'green_vertices_diff': {'added': [2], 'removed': []}, + 'red_vertices': [0], + 'red_vertices_diff': {'added': [], 'removed': [2]}, + 'sinks': [], + 'sinks_diff': {'added': [], 'removed': [2]}, + 'sources': [2], + 'sources_diff': {'added': [2], 'removed': []}, + 'urban_renewals': [], + 'urban_renewals_diff': {'added': [], 'removed': []}}, 3: {'d_matrix': [ 1 0 1 1] - [ 0 -1 0 0] - [ 0 0 0 1] - [ 1 0 0 1], - 'denominators': [x0*x3, 1, x0, x0*x2*x3], - 'edge_diff': -1, - 'edges': 6, - 'green_vertices': [1], - 'green_vertices_diff': {'added': [], 'removed': [3]}, - 'red_vertices': [0, 2, 3], - 'red_vertices_diff': {'added': [3], 'removed': []}, - 'sinks': [2], - 'sinks_diff': {'added': [], 'removed': []}, - 'sources': [1], - 'sources_diff': {'added': [1], 'removed': []}, - 'urban_renewals': [], - 'urban_renewals_diff': {'added': [], 'removed': []}}} + [ 0 -1 0 0] + [ 0 0 0 1] + [ 1 0 0 1], + 'denominators': [x0*x3, 1, x0, x0*x2*x3], + 'edge_diff': -1, + 'edges': 6, + 'green_vertices': [1], + 'green_vertices_diff': {'added': [], 'removed': [3]}, + 'red_vertices': [0, 2, 3], + 'red_vertices_diff': {'added': [3], 'removed': []}, + 'sinks': [2], + 'sinks_diff': {'added': [], 'removed': []}, + 'sources': [1], + 'sources_diff': {'added': [1], 'removed': []}, + 'urban_renewals': [], + 'urban_renewals_diff': {'added': [], 'removed': []}}} sage: S = ClusterSeed(['A',3]).principal_extension() sage: S.mutation_analysis() {0: {'d_matrix': [ 1 0 0] - [ 0 -1 0] - [ 0 0 -1], - 'denominators': [x0, 1, 1], - 'green_vertices': [1, 2], - 'green_vertices_diff': {'added': [], 'removed': [0]}, - 'red_vertices': [0], - 'red_vertices_diff': {'added': [0], 'removed': []}, - 'sinks': [], - 'sinks_diff': {'added': [], 'removed': [1]}, - 'sources': [4, 5], - 'sources_diff': {'added': [], 'removed': [3]}, - 'urban_renewals': [], - 'urban_renewals_diff': {'added': [], 'removed': []}}, + [ 0 -1 0] + [ 0 0 -1], + 'denominators': [x0, 1, 1], + 'green_vertices': [1, 2], + 'green_vertices_diff': {'added': [], 'removed': [0]}, + 'red_vertices': [0], + 'red_vertices_diff': {'added': [0], 'removed': []}, + 'sinks': [], + 'sinks_diff': {'added': [], 'removed': [1]}, + 'sources': [4, 5], + 'sources_diff': {'added': [], 'removed': [3]}, + 'urban_renewals': [], + 'urban_renewals_diff': {'added': [], 'removed': []}}, 1: {'d_matrix': [-1 0 0] - [ 0 1 0] - [ 0 0 -1], - 'denominators': [1, x1, 1], - 'green_vertices': [0, 2], - 'green_vertices_diff': {'added': [], 'removed': [1]}, - 'red_vertices': [1], - 'red_vertices_diff': {'added': [1], 'removed': []}, - 'sinks': [0, 2, 4], - 'sinks_diff': {'added': [0, 2, 4], 'removed': [1]}, - 'sources': [1, 3, 5], - 'sources_diff': {'added': [1], 'removed': [4]}, - 'urban_renewals': [], - 'urban_renewals_diff': {'added': [], 'removed': []}}, + [ 0 1 0] + [ 0 0 -1], + 'denominators': [1, x1, 1], + 'green_vertices': [0, 2], + 'green_vertices_diff': {'added': [], 'removed': [1]}, + 'red_vertices': [1], + 'red_vertices_diff': {'added': [1], 'removed': []}, + 'sinks': [0, 2, 4], + 'sinks_diff': {'added': [0, 2, 4], 'removed': [1]}, + 'sources': [1, 3, 5], + 'sources_diff': {'added': [1], 'removed': [4]}, + 'urban_renewals': [], + 'urban_renewals_diff': {'added': [], 'removed': []}}, 2: {'d_matrix': [-1 0 0] - [ 0 -1 0] - [ 0 0 1], - 'denominators': [1, 1, x2], - 'green_vertices': [0, 1], - 'green_vertices_diff': {'added': [], 'removed': [2]}, - 'red_vertices': [2], - 'red_vertices_diff': {'added': [2], 'removed': []}, - 'sinks': [], - 'sinks_diff': {'added': [], 'removed': [1]}, - 'sources': [3, 4], - 'sources_diff': {'added': [], 'removed': [5]}, - 'urban_renewals': [], - 'urban_renewals_diff': {'added': [], 'removed': []}}} + [ 0 -1 0] + [ 0 0 1], + 'denominators': [1, 1, x2], + 'green_vertices': [0, 1], + 'green_vertices_diff': {'added': [], 'removed': [2]}, + 'red_vertices': [2], + 'red_vertices_diff': {'added': [2], 'removed': []}, + 'sinks': [], + 'sinks_diff': {'added': [], 'removed': [1]}, + 'sources': [3, 4], + 'sources_diff': {'added': [], 'removed': [5]}, + 'urban_renewals': [], + 'urban_renewals_diff': {'added': [], 'removed': []}}} """ V = range(self._n) if filter is None: @@ -3243,7 +3247,8 @@ def reset_cluster(self): sage: T.cluster() [x0, x1, x2] - sage: S = ClusterSeed(['B',3],user_labels=[[1,2],[2,3],[3,4]],user_labels_prefix='p') + sage: S = ClusterSeed(['B',3], user_labels=[[1,2],[2,3],[3,4]], + ....: user_labels_prefix='p') sage: S.mutate([0,1]) sage: S.cluster() [(p_2_3 + 1)/p_1_2, (p_1_2*p_3_4^2 + p_2_3 + 1)/(p_1_2*p_2_3), p_3_4] @@ -3271,7 +3276,7 @@ def reset_coefficients(self): This raises an error if the number of frozen variables is different than the number of exchangeable variables. - WARNING: This command to be phased out since 'use_c_vectors() does this more effectively. + WARNING: This command to be phased out since :meth:`use_c_vectors` does this more effectively. EXAMPLES:: @@ -3326,10 +3331,10 @@ def mutation_class_iter(self, depth=infinity, show_depth=False, INPUT: - ``depth`` -- (default: infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned. - - ``show_depth`` -- (default: False) if True, the current depth of the mutation is shown while computing. - - ``return_paths`` -- (default: False) if True, a shortest path of mutations from ``self`` to the given quiver is returned as well. - - ``up_to_equivalence`` -- (default: True) if True, only one seed up to simultaneous permutation of rows and columns of the exchange matrix is recorded. - - ``sink_source`` -- (default: False) if True, only mutations at sinks and sources are applied. + - ``show_depth`` -- (default: ``False``) if ``True``, the current depth of the mutation is shown while computing. + - ``return_paths`` -- (default: ``False``) if ``True``, a shortest path of mutations from ``self`` to the given quiver is returned as well. + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only one seed up to simultaneous permutation of rows and columns of the exchange matrix is recorded. + - ``sink_source`` -- (default: ``False``) if ``True``, only mutations at sinks and sources are applied. EXAMPLES: @@ -3387,7 +3392,8 @@ def mutation_class_iter(self, depth=infinity, show_depth=False, sage: len([T for T in it]) 84 - sage: it = ClusterSeed(['A',2]).mutation_class_iter(return_paths=True,up_to_equivalence=False) + sage: it = ClusterSeed(['A',2]).mutation_class_iter(return_paths=True, + ....: up_to_equivalence=False) sage: mutation_class = list(it) sage: len(mutation_class) 10 @@ -3549,13 +3555,13 @@ def mutation_class(self, depth=infinity, show_depth=False, return_paths=False, def cluster_class_iter(self, depth=infinity, show_depth=False, up_to_equivalence=True): r""" - Returns an iterator through all clusters in the mutation class of ``self``. + Return an iterator through all clusters in the mutation class of ``self``. INPUT: - - ``depth`` -- (default: infinity) integer or infinity, only seeds with distance at most depth from self are returned - - ``show_depth`` -- (default False) - if True, ignored if depth is set; returns the depth of the mutation class, i.e., the maximal distance from self of an element in the mutation class - - ``up_to_equivalence`` -- (default: True) if True, only clusters up to equivalence are considered. + - ``depth`` -- (default: infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned + - ``show_depth`` -- (default: ``False``) if ``True``, ignored if ``depth`` is set; returns the depth of the mutation class, i.e., the maximal distance from ``self`` of an element in the mutation class + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only clusters up to equivalence are considered. EXAMPLES: @@ -3631,7 +3637,7 @@ def cluster_class_iter(self, depth=infinity, show_depth=False, up_to_equivalence For a cluster seed from an arbitrarily labelled digraph:: sage: dg = DiGraph([['a', 'b'], ['b', 'c']], format="list_of_edges") - sage: S = ClusterSeed(dg, frozen = ['b']) + sage: S = ClusterSeed(dg, frozen=['b']) sage: S.cluster_class() [[a, c], [a, (b + 1)/c], [(b + 1)/a, c], [(b + 1)/a, (b + 1)/c]] @@ -3649,9 +3655,9 @@ def cluster_class(self, depth=infinity, show_depth=False, up_to_equivalence=True INPUT: - - ``depth`` -- (default: infinity) integer, only seeds with distance at most depth from self are returned - - ``return_depth`` -- (default False) - if True, ignored if depth is set; returns the depth of the mutation class, i.e., the maximal distance from self of an element in the mutation class - - ``up_to_equivalence`` -- (default: True) if True, only clusters up to equivalence are considered. + - ``depth`` -- (default: infinity) integer, only seeds with distance at most ``depth`` from ``self`` are returned + - ``return_depth`` -- (default: ``False``) - if ``True``, ignored if ``depth`` is set; returns the depth of the mutation class, i.e., the maximal distance from ``self`` of an element in the mutation class + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only clusters up to equivalence are considered. EXAMPLES: @@ -3668,12 +3674,12 @@ def cluster_class(self, depth=infinity, show_depth=False, up_to_equivalence=True def b_matrix_class_iter(self, depth=infinity, up_to_equivalence=True): r""" - Returns an iterator through all `B`-matrices in the mutation class of ``self``. + Return an iterator through all `B`-matrices in the mutation class of ``self``. INPUT: - - ``depth`` -- (default:infinity) integer or infinity, only seeds with distance at most depth from self are returned - - ``up_to_equivalence`` -- (default: True) if True, only 'B'-matrices up to equivalence are considered. + - ``depth`` -- (default:infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only `B`-matrices up to equivalence are considered. EXAMPLES: @@ -3772,12 +3778,12 @@ def b_matrix_class_iter(self, depth=infinity, up_to_equivalence=True): def b_matrix_class(self, depth=infinity, up_to_equivalence=True): r""" - Returns all `B`-matrices in the mutation class of ``self``. + Return all `B`-matrices in the mutation class of ``self``. INPUT: - - ``depth`` -- (default:infinity) integer or infinity, only seeds with distance at most depth from self are returned - - ``up_to_equivalence`` -- (default: True) if True, only 'B'-matrices up to equivalence are considered. + - ``depth`` -- (default: infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only `B`-matrices up to equivalence are considered. EXAMPLES: @@ -3795,12 +3801,12 @@ def b_matrix_class(self, depth=infinity, up_to_equivalence=True): def variable_class_iter(self, depth=infinity, ignore_bipartite_belt=False): r""" - Returns an iterator for all cluster variables in the mutation class of ``self``. + Return an iterator for all cluster variables in the mutation class of ``self``. INPUT: - - ``depth`` -- (default:infinity) integer, only seeds with distance at most depth from self are returned - - ``ignore_bipartite_belt`` -- (default:False) if True, the algorithms does not use the bipartite belt + - ``depth`` -- (default: infinity) integer, only seeds with distance at most ``depth`` from ``self`` are returned + - ``ignore_bipartite_belt`` -- (default: ``False``) if ``True``, the algorithm does not use the bipartite belt EXAMPLES: @@ -3921,12 +3927,12 @@ def variable_class_iter(self, depth=infinity, ignore_bipartite_belt=False): def variable_class(self, depth=infinity, ignore_bipartite_belt=False): r""" - Returns all cluster variables in the mutation class of ``self``. + Return all cluster variables in the mutation class of ``self``. INPUT: - - ``depth`` -- (default:infinity) integer, only seeds with distance at most depth from self are returned - - ``ignore_bipartite_belt`` -- (default:False) if True, the algorithms does not use the bipartite belt + - ``depth`` -- (default: infinity) integer, only seeds with distance at most ``depth`` from ``self`` are returned + - ``ignore_bipartite_belt`` -- (default: ``False``) if ``True``, the algorithms does not use the bipartite belt EXAMPLES: @@ -3970,12 +3976,13 @@ def is_finite(self) -> bool: def is_mutation_finite(self, nr_of_checks=None, return_path=False): r""" - Returns True if ``self`` is of finite mutation type. + Return True if ``self`` is of finite mutation type. INPUT: - - ``nr_of_checks`` -- (default: None) number of mutations applied. Standard is 500*(number of vertices of self). - - ``return_path`` -- (default: False) if True, in case of self not being mutation finite, a path from self to a quiver with an edge label (a,-b) and a*b > 4 is returned. + - ``nr_of_checks`` -- (default: ``None``) number of mutations applied. Standard is 500*(number of vertices of ``self``). + - ``return_path`` -- (default: ``False``) if ``True``, in case of ``self`` not being mutation finite, + a path from ``self`` to a quiver with an edge label `(a,-b)` and `a*b > 4` is returned. ALGORITHM: @@ -4005,7 +4012,7 @@ def is_mutation_finite(self, nr_of_checks=None, return_path=False): def mutation_type(self): r""" - Returns the mutation_type of each connected component of ``self``, if it can be determined. + Return the mutation_type of each connected component of ``self``, if it can be determined. Otherwise, the mutation type of this component is set to be unknown. The mutation types of the components are ordered by vertex labels. @@ -4031,7 +4038,8 @@ def mutation_type(self): sage: S.mutation_type() ['A', 5] - sage: S = ClusterSeed(DiGraph([['a','b'],['c','b'],['c','d'],['e','d']]), frozen = ['c']) + sage: S = ClusterSeed(DiGraph([['a','b'],['c','b'],['c','d'],['e','d']]), + ....: frozen=['c']) sage: S.mutation_type() [ ['A', 2], ['A', 2] ] @@ -4073,10 +4081,10 @@ def mutation_type(self): def greedy(self, a1, a2, algorithm='by_recursion'): r""" - Returns the greedy element `x[a_1,a_2]` assuming that self is rank two. + Return the greedy element `x[a_1,a_2]` assuming that self is rank two. - The third input can be 'by_recursion', 'by_combinatorics', or - 'just_numbers' to specify if the user wants the element + The third input can be ``'by_recursion'``, ``'by_combinatorics'``, or + ``'just_numbers'`` to specify if the user wants the element computed by the recurrence, combinatorial formula, or wants to set `x_1` and `x_2` to be one. @@ -4086,9 +4094,11 @@ def greedy(self, a1, a2, algorithm='by_recursion'): sage: S = ClusterSeed(['R2', [3, 3]]) sage: S.greedy(4, 4) - (x0^12 + x1^12 + 4*x0^9 + 4*x1^9 + 6*x0^6 + 4*x0^3*x1^3 + 6*x1^6 + 4*x0^3 + 4*x1^3 + 1)/(x0^4*x1^4) + (x0^12 + x1^12 + 4*x0^9 + 4*x1^9 + 6*x0^6 + + 4*x0^3*x1^3 + 6*x1^6 + 4*x0^3 + 4*x1^3 + 1)/(x0^4*x1^4) sage: S.greedy(4, 4, 'by_combinatorics') - (x0^12 + x1^12 + 4*x0^9 + 4*x1^9 + 6*x0^6 + 4*x0^3*x1^3 + 6*x1^6 + 4*x0^3 + 4*x1^3 + 1)/(x0^4*x1^4) + (x0^12 + x1^12 + 4*x0^9 + 4*x1^9 + 6*x0^6 + + 4*x0^3*x1^3 + 6*x1^6 + 4*x0^3 + 4*x1^3 + 1)/(x0^4*x1^4) sage: S.greedy(4, 4, 'just_numbers') 35 sage: S = ClusterSeed(['R2', [2, 2]]) @@ -4163,7 +4173,7 @@ def oriented_exchange_graph(self): The seed must be a cluster seed for a cluster algebra of finite type with principal coefficients (the corresponding - quiver must have mutable vertices 0,1,...,n-1). + quiver must have mutable vertices `0,1,...,n-1`). EXAMPLES:: @@ -4221,7 +4231,7 @@ def oriented_exchange_graph(self): def find_upper_bound(self, verbose=False): r""" - Return the upper bound of the given cluster algebra as a quotient_ring. + Return the upper bound of the given cluster algebra as a quotient ring. The upper bound is the intersection of the Laurent polynomial rings of the initial cluster and its neighboring clusters. As @@ -4254,15 +4264,24 @@ def find_upper_bound(self, verbose=False): sage: S = ClusterSeed(['A',3]) sage: S.find_upper_bound() - Quotient of Multivariate Polynomial Ring in x0, x1, x2, x0p, x1p, x2p, z0 over Rational Field by the ideal (x0*x0p - x1 - 1, x1*x1p - x0*x2 - 1, x2*x2p - x1 - 1, x0*z0 - x2p, x1*z0 + z0 - x0p*x2p, x2*z0 - x0p, x1p*z0 + z0 - x0p*x1p*x2p + x1 + 1) + Quotient of Multivariate Polynomial Ring in x0, x1, x2, x0p, x1p, x2p, z0 + over Rational Field + by the ideal (x0*x0p - x1 - 1, x1*x1p - x0*x2 - 1, x2*x2p - x1 - 1, + x0*z0 - x2p, x1*z0 + z0 - x0p*x2p, x2*z0 - x0p, + x1p*z0 + z0 - x0p*x1p*x2p + x1 + 1) - Markov:: sage: B = matrix([[0,2,-2],[-2,0,2],[2,-2,0]]) sage: S = ClusterSeed(B) sage: S.find_upper_bound() - Quotient of Multivariate Polynomial Ring in x0, x1, x2, x0p, x1p, x2p, z0 over Rational Field by the ideal (x0*x0p - x2^2 - x1^2, x1*x1p - x2^2 - x0^2, x2*x2p - x1^2 - x0^2, x0p*x1p*x2p - x0*x1*x2p - x0*x2*x1p - x1*x2*x0p - 2*x0*x1*x2, x0^3*z0 - x1p*x2p + x1*x2, x0*x1*z0 - x2p - x2, x1^3*z0 - x0p*x2p + x0*x2, x0*x2*z0 - x1p - x1, x1*x2*z0 - x0p - x0, x2^3*z0 - x0p*x1p + x0*x1) - + Quotient of Multivariate Polynomial Ring in x0, x1, x2, x0p, x1p, x2p, z0 + over Rational Field + by the ideal (x0*x0p - x2^2 - x1^2, x1*x1p - x2^2 - x0^2, x2*x2p - x1^2 - x0^2, + x0p*x1p*x2p - x0*x1*x2p - x0*x2*x1p - x1*x2*x0p - 2*x0*x1*x2, + x0^3*z0 - x1p*x2p + x1*x2, x0*x1*z0 - x2p - x2, + x1^3*z0 - x0p*x2p + x0*x2, x0*x2*z0 - x1p - x1, + x1*x2*z0 - x0p - x0, x2^3*z0 - x0p*x1p + x0*x1) """ rank = self.n() @@ -4327,18 +4346,18 @@ def find_upper_bound(self, verbose=False): def get_upper_cluster_algebra_element(self,a): r""" - Computes an element in the upper cluster algebra of `B` corresponding to the vector `a \in \ZZ^n`. + Compute an element in the upper cluster algebra of `B` corresponding to the vector `a \in \ZZ^n`. See [LLM2014]_ for more details. INPUT: - `B` -- a skew-symmetric matrix. Must have the same number of columns as the length of the vectors in `vd`. - - `a` -- a vector in `\ZZ^n` where `n` is the number of columns in `B`. + - ``a`` -- a vector in `\ZZ^n` where `n` is the number of columns in `B`. OUTPUT: - Returns an element in the upper cluster algebra. Depending on the input it may or may not be irreducible. + Return an element in the upper cluster algebra. Depending on the input it may or may not be irreducible. EXAMPLES:: @@ -4427,7 +4446,7 @@ def _compute_compatible_vectors(self, vd): - `B` -- a skew-symmetric matrix. Must have the same number of columns as the length of the vectors in ``vd``. - ``vd`` -- a collection of tuples `(v,z)` with `v \in \{0,1\}^n` and `z \in \ZZ`. - `n` must be the number of columns in `B`. Taken from the output of vector_decomposition. + `n` must be the number of columns in `B`. Taken from the output of vector_decomposition. OUTPUT: @@ -4758,7 +4777,7 @@ def get_green_vertices(C): INPUT: - - ``C`` -- The C matrix to check + - ``C`` -- The C-matrix to check EXAMPLES:: @@ -4779,7 +4798,7 @@ def get_red_vertices(C): INPUT: - - ``C`` -- The C matrix to check + - ``C`` -- The C-matrix to check EXAMPLES:: @@ -4804,7 +4823,7 @@ def _vector_decomposition(a, length): A decomposition of `a` into vectors `b_i \in \{0,1\}^n` such that `a= \sum c_i b_i` for `c_i \in \ZZ.` - Returns an array of tuples `\right[b_i,c_i\left].` + Return an array of tuples `\right[b_i,c_i\left].` EXAMPLES:: diff --git a/src/sage/combinat/cluster_algebra_quiver/interact.py b/src/sage/combinat/cluster_algebra_quiver/interact.py index 1c88e613b4c..f0225803be1 100644 --- a/src/sage/combinat/cluster_algebra_quiver/interact.py +++ b/src/sage/combinat/cluster_algebra_quiver/interact.py @@ -10,8 +10,8 @@ def cluster_interact(self, fig_size=1, circular=True, kind='seed'): Only in *Jupyter notebook mode*. - Not to be called directly. Use the interact methods - of ClusterSeed and ClusterQuiver instead. + Not to be called directly. Use the :meth:`interact` methods + of :class:`ClusterSeed` and :class:`ClusterQuiver` instead. INPUT: @@ -26,7 +26,7 @@ def cluster_interact(self, fig_size=1, circular=True, kind='seed'): TESTS:: sage: S = ClusterSeed(['A',4]) - sage: S.interact() # indirect doctest + sage: S.interact() # indirect doctest # optional - sage.symbolic ...VBox(children=... """ if kind not in ['seed', 'quiver']: diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver.py b/src/sage/combinat/cluster_algebra_quiver/quiver.py index 5a34fed2294..ba1168749b7 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver.py @@ -549,11 +549,11 @@ def plot(self, circular=True, center=(0, 0), directed=True, mark=None, EXAMPLES:: sage: Q = ClusterQuiver(['A',5]) - sage: Q.plot() + sage: Q.plot() # optional - sage.plot sage.symbolic Graphics object consisting of 15 graphics primitives - sage: Q.plot(circular=True) + sage: Q.plot(circular=True) # optional - sage.plot sage.symbolic Graphics object consisting of 15 graphics primitives - sage: Q.plot(circular=True, mark=1) + sage: Q.plot(circular=True, mark=1) # optional - sage.plot sage.symbolic Graphics object consisting of 15 graphics primitives """ from sage.plot.colors import rainbow @@ -699,7 +699,7 @@ def interact(self, fig_size=1, circular=True): TESTS:: sage: S = ClusterQuiver(['A',4]) - sage: S.interact() + sage: S.interact() # optional - sage.plot sage.symbolic ...VBox(children=... """ return cluster_interact(self, fig_size, circular, kind="quiver") @@ -717,7 +717,7 @@ def save_image(self, filename, circular=False): sage: Q = ClusterQuiver(['F',4,[1,2]]) sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.plot sage.symbolic ....: Q.save_image(f.name) """ graph_plot = self.plot(circular=circular) diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py index 13349acbb42..66b2385b3af 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py @@ -677,7 +677,7 @@ def plot(self, circular=False, directed=True): INPUT: - - ``circular`` -- (default:``False``) if ``True``, the + - ``circular`` -- (default: ``False``) if ``True``, the circular plot is chosen, otherwise >>spring<< is used. - ``directed`` -- (default: ``True``) if ``True``, the @@ -686,8 +686,8 @@ def plot(self, circular=False, directed=True): EXAMPLES:: sage: QMT = QuiverMutationType(['A',5]) - sage: pl = QMT.plot() - sage: pl = QMT.plot(circular=True) + sage: pl = QMT.plot() # optional - sage.plot sage.symbolic + sage: pl = QMT.plot(circular=True) # optional - sage.plot sage.symbolic """ return self.standard_quiver().plot(circular=circular, directed=directed) @@ -783,7 +783,7 @@ def b_matrix(self): EXAMPLES:: - sage: mut_type = QuiverMutationType( ['A',5] ); mut_type + sage: mut_type = QuiverMutationType(['A',5]); mut_type ['A', 5] sage: mut_type.b_matrix() [ 0 1 0 0 0] diff --git a/src/sage/combinat/crystals/mv_polytopes.py b/src/sage/combinat/crystals/mv_polytopes.py index ddcff43c6f4..bcb2654da60 100644 --- a/src/sage/combinat/crystals/mv_polytopes.py +++ b/src/sage/combinat/crystals/mv_polytopes.py @@ -85,7 +85,7 @@ def _latex_(self): sage: MV = crystals.infinity.MVPolytopes(['A',2]) sage: u = MV.highest_weight_vector() sage: b = u.f_string([1,2,2,1]) - sage: latex(b) + sage: latex(b) # optional - sage.symbolic \begin{tikzpicture} \draw (0, 0) -- (3/2, -989/1142) -- (3/2, -2967/1142) -- (0, -1978/571); \draw (0, 0) -- (-3/2, -989/1142) -- (-3/2, -2967/1142) -- (0, -1978/571); diff --git a/src/sage/combinat/designs/block_design.py b/src/sage/combinat/designs/block_design.py index 608a06581e1..cb81f997f3d 100644 --- a/src/sage/combinat/designs/block_design.py +++ b/src/sage/combinat/designs/block_design.py @@ -404,16 +404,16 @@ def q3_minus_one_matrix(K): sage: m.multiplicative_order() == 3**3 - 1 True - sage: m = q3_minus_one_matrix(GF(4,'a')) - sage: m.multiplicative_order() == 4**3 - 1 + sage: m = q3_minus_one_matrix(GF(4, 'a')) # optional - sage.symbolic + sage: m.multiplicative_order() == 4**3 - 1 # optional - sage.symbolic True sage: m = q3_minus_one_matrix(GF(5)) sage: m.multiplicative_order() == 5**3 - 1 True - sage: m = q3_minus_one_matrix(GF(9,'a')) - sage: m.multiplicative_order() == 9**3 - 1 + sage: m = q3_minus_one_matrix(GF(9, 'a')) # optional - sage.symbolic + sage: m.multiplicative_order() == 9**3 - 1 # optional - sage.symbolic True """ q = K.cardinality() diff --git a/src/sage/combinat/designs/difference_family.py b/src/sage/combinat/designs/difference_family.py index 52a95805ea5..51cbd1e0501 100644 --- a/src/sage/combinat/designs/difference_family.py +++ b/src/sage/combinat/designs/difference_family.py @@ -2040,9 +2040,6 @@ def skew_supplementary_difference_set_over_polynomial_ring(n, existence=False, c ... NotImplementedError: skew SDS of order 7 not yet implemented """ - from sage.symbolic.ring import SymbolicRing - from sage.rings.finite_rings.integer_mod_ring import Zmod - data = { 81: (3, lambda x: x**4 - x**3 - 1, 16, 5, [1, 2, 4, 6, 8, 10, 12, 14], [1, 2, 3, 4, 10, 11, 13], @@ -2060,6 +2057,9 @@ def skew_supplementary_difference_set_over_polynomial_ring(n, existence=False, c mod, poly, exp, order, ind1, ind2, ind3, ind4 = data[n] + from sage.symbolic.ring import SymbolicRing + from sage.rings.finite_rings.integer_mod_ring import Zmod + Z3 = Zmod(mod) R = SymbolicRing() x = R.var('x') diff --git a/src/sage/combinat/designs/incidence_structures.py b/src/sage/combinat/designs/incidence_structures.py index 1aa6c34d733..94f2e3f9c0d 100644 --- a/src/sage/combinat/designs/incidence_structures.py +++ b/src/sage/combinat/designs/incidence_structures.py @@ -433,20 +433,21 @@ def is_isomorphic(self, other, certificate=False): TESTS:: - sage: IS = IncidenceStructure([["A",5,pi],["A",5,"Wouhou"],["A","Wouhou",(9,9)],[pi,12]]) - sage: IS2 = IS.copy() - sage: IS2.relabel(IS2.canonical_label()) - sage: IS.is_isomorphic(IS2) + sage: IS = IncidenceStructure([["A",5,pi],["A",5,"Wouhou"], # optional - sage.symbolic + ....: ["A","Wouhou",(9,9)],[pi,12]]) + sage: IS2 = IS.copy() # optional - sage.symbolic + sage: IS2.relabel(IS2.canonical_label()) # optional - sage.symbolic + sage: IS.is_isomorphic(IS2) # optional - sage.symbolic True - sage: canon = IS.is_isomorphic(IS2,certificate=True) - sage: IS.relabel(canon) - sage: IS==IS2 + sage: canon = IS.is_isomorphic(IS2, certificate=True) # optional - sage.symbolic + sage: IS.relabel(canon) # optional - sage.symbolic + sage: IS==IS2 # optional - sage.symbolic True sage: IS2 = IncidenceStructure([[1,2]]) - sage: IS2.is_isomorphic(IS) + sage: IS2.is_isomorphic(IS) # optional - sage.symbolic False - sage: IS2.is_isomorphic(IS,certificate=True) + sage: IS2.is_isomorphic(IS, certificate=True) # optional - sage.symbolic {} Checking whether two :class:`IncidenceStructure` are isomorphic @@ -454,7 +455,7 @@ def is_isomorphic(self, other, certificate=False): subsequent calls to :meth:`is_isomorphic` will be faster:: sage: IS1 = designs.projective_plane(3) - sage: IS2 = IS1.relabel(Permutations(IS1.ground_set()).random_element(),inplace=False) + sage: IS2 = IS1.relabel(Permutations(IS1.ground_set()).random_element(), inplace=False) sage: IS2 = IncidenceStructure(IS2.blocks()) sage: IS1._canonical_label is None and IS2._canonical_label is None True diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py index bd281fdbb77..4909dc33f09 100644 --- a/src/sage/combinat/diagram_algebras.py +++ b/src/sage/combinat/diagram_algebras.py @@ -2490,21 +2490,21 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): Shorthands for working with basis elements are as follows:: sage: S = SymmetricGroupAlgebra(ZZ, 3) - sage: A = PartitionAlgebra(3, x, SR) + sage: A = PartitionAlgebra(3, x, SR) # optional - sage.symbolic - sage: A([[1,3],[-1],[-3]]) # pair up the omitted nodes as `{-i, i}`, if possible + sage: A([[1,3],[-1],[-3]]) # pair up the omitted nodes as `{-i, i}`, if possible # optional - sage.symbolic P{{-3}, {-2, 2}, {-1}, {1, 3}} - sage: A([[1,3],[-1],[-3]]) == A[[1,3],[-1],[-3]] + sage: A([[1,3],[-1],[-3]]) == A[[1,3],[-1],[-3]] # optional - sage.symbolic True - sage: A([[1,2]]) + sage: A([[1,2]]) # optional - sage.symbolic P{{-3, 3}, {-2}, {-1}, {1, 2}} - sage: A([[1,2]]) == A[[1,2]] + sage: A([[1,2]]) == A[[1,2]] # optional - sage.symbolic True - sage: A([2,3,1]) # permutations in one-line notation are imported as well + sage: A([2,3,1]) # permutations in one-line notation are imported as well # optional - sage.symbolic P{{-3, 2}, {-2, 1}, {-1, 3}} - sage: A([2,3,1]) == A(S([2,3,1])) + sage: A([2,3,1]) == A(S([2,3,1])) # optional - sage.symbolic True """ @staticmethod @@ -3592,9 +3592,9 @@ def ambient(self): EXAMPLES:: - sage: x = var('x') - sage: BA = BrauerAlgebra(2, x) - sage: BA.ambient() + sage: x = var('x') # optional - sage.symbolic + sage: BA = BrauerAlgebra(2, x) # optional - sage.symbolic + sage: BA.ambient() # optional - sage.symbolic Partition Algebra of rank 2 with parameter x over Symbolic Ring """ return self.lift.codomain() @@ -3833,11 +3833,11 @@ def jucys_murphy(self, j): EXAMPLES:: - sage: z = var('z') - sage: B = BrauerAlgebra(3,z) - sage: B.jucys_murphy(1) + sage: z = var('z') # optional - sage.symbolic + sage: B = BrauerAlgebra(3,z) # optional - sage.symbolic + sage: B.jucys_murphy(1) # optional - sage.symbolic (1/2*z-1/2)*B{{-3, 3}, {-2, 2}, {-1, 1}} - sage: B.jucys_murphy(3) + sage: B.jucys_murphy(3) # optional - sage.symbolic -B{{-3, -2}, {-1, 1}, {2, 3}} - B{{-3, -1}, {-2, 2}, {1, 3}} + B{{-3, 1}, {-2, 2}, {-1, 3}} + B{{-3, 2}, {-2, 3}, {-1, 1}} + (1/2*z-1/2)*B{{-3, 3}, {-2, 2}, {-1, 1}} diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index 2c1f52e9588..04106d2b7a3 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -10437,11 +10437,11 @@ def moments_waiting_time(self, test=bool, is_zero=None, and the variance are `\sum_{k\ge 1} k2^{-k}=2` and `\sum_{k\ge 1} (k-2)^2 2^{-k}=2`:: - sage: var('k') + sage: var('k') # optional - sage.symbolic k - sage: sum(k * 2^(-k), k, 1, infinity) + sage: sum(k * 2^(-k), k, 1, infinity) # optional - sage.symbolic 2 - sage: sum((k-2)^2 * 2^(-k), k, 1, infinity) + sage: sum((k-2)^2 * 2^(-k), k, 1, infinity) # optional - sage.symbolic 2 We now compute the same expectation and variance by using a @@ -11846,13 +11846,13 @@ def shannon_parry_markov_chain(self): sage: NAF = Automaton([(0, 0, 0), (0, 1, 1), (0, 1, -1), ....: (1, 0, 0)], initial_states=[0], ....: final_states=[0, 1]) - sage: P_NAF = NAF.shannon_parry_markov_chain() - sage: P_NAF.transitions() + sage: P_NAF = NAF.shannon_parry_markov_chain() # optional - sage.symbolic + sage: P_NAF.transitions() # optional - sage.symbolic [Transition from 0 to 0: 1/2|0, Transition from 0 to 1: 1/4|1, Transition from 0 to 1: 1/4|-1, Transition from 1 to 0: 1|0] - sage: for s in P_NAF.iter_states(): + sage: for s in P_NAF.iter_states(): # optional - sage.symbolic ....: print(s.color) 3/4 3/2 @@ -11860,7 +11860,7 @@ def shannon_parry_markov_chain(self): The stationary distribution is also computed and saved as the initial probabilities of the returned Markov chain:: - sage: for s in P_NAF.states(): + sage: for s in P_NAF.states(): # optional - sage.symbolic ....: print("{} {}".format(s, s.initial_probability)) 0 2/3 1 1/3 diff --git a/src/sage/combinat/k_tableau.py b/src/sage/combinat/k_tableau.py index 5fb1d56b82c..5beac7acb5e 100644 --- a/src/sage/combinat/k_tableau.py +++ b/src/sage/combinat/k_tableau.py @@ -205,7 +205,7 @@ def WeakTableaux(k, shape , weight, representation = "core"): for the 'bounded' representation, the shape is inputted as a `k`-bounded partition; for skew tableaux, the shape is inputted as a tuple of the outer and inner shape - ``weight`` -- the weight of the weak `k`-tableaux as a list or tuple - - ``representation`` -- 'core', 'bounded', or 'factorized_permutation' (default: 'core') + - ``representation`` -- ``'core'``, ``'bounded'``, or ``'factorized_permutation'`` (default: ``'core'``) EXAMPLES:: diff --git a/src/sage/combinat/partition.py b/src/sage/combinat/partition.py index 8e3b777c35e..5513086de21 100644 --- a/src/sage/combinat/partition.py +++ b/src/sage/combinat/partition.py @@ -3279,9 +3279,9 @@ def hook_product(self, a): EXAMPLES:: - sage: Partition([3,2,1]).hook_product(x) + sage: Partition([3,2,1]).hook_product(x) # optional - sage.symbolic (2*x + 3)*(x + 2)^2 - sage: Partition([2,2]).hook_product(x) + sage: Partition([2,2]).hook_product(x) # optional - sage.symbolic 2*(x + 2)*(x + 1) """ @@ -3422,7 +3422,7 @@ def upper_hook(self, i, j, alpha): 3 sage: p.hook_length(0,0) 3 - sage: [ p.upper_hook(i,j,x) for i,j in p.cells() ] + sage: [ p.upper_hook(i,j,x) for i,j in p.cells() ] # optional - sage.symbolic [2*x + 1, x, x] """ p = self @@ -3444,7 +3444,7 @@ def upper_hook_lengths(self, alpha): EXAMPLES:: - sage: Partition([3,2,1]).upper_hook_lengths(x) + sage: Partition([3,2,1]).upper_hook_lengths(x) # optional - sage.symbolic [[3*x + 2, 2*x + 1, x], [2*x + 1, x], [x]] sage: Partition([3,2,1]).upper_hook_lengths(1) [[5, 3, 1], [3, 1], [1]] @@ -3474,7 +3474,7 @@ def lower_hook(self, i, j, alpha): 3 sage: p.hook_length(0,0) 3 - sage: [ p.lower_hook(i,j,x) for i,j in p.cells() ] + sage: [ p.lower_hook(i,j,x) for i,j in p.cells() ] # optional - sage.symbolic [x + 2, 1, 1] """ p = self @@ -3496,7 +3496,7 @@ def lower_hook_lengths(self, alpha): EXAMPLES:: - sage: Partition([3,2,1]).lower_hook_lengths(x) + sage: Partition([3,2,1]).lower_hook_lengths(x) # optional - sage.symbolic [[2*x + 3, x + 2, 1], [x + 2, 1], [1]] sage: Partition([3,2,1]).lower_hook_lengths(1) [[5, 3, 1], [3, 1], [1]] @@ -5310,18 +5310,19 @@ def outline(self, variable=None): EXAMPLES:: - sage: [Partition([5,4]).outline()(x=i) for i in range(-10,11)] + sage: [Partition([5,4]).outline()(x=i) for i in range(-10,11)] # optional - sage.symbolic [10, 9, 8, 7, 6, 5, 6, 5, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10] - sage: Partition([]).outline() + sage: Partition([]).outline() # optional - sage.symbolic abs(x) - sage: Partition([1]).outline() + sage: Partition([1]).outline() # optional - sage.symbolic abs(x + 1) + abs(x - 1) - abs(x) - sage: y = SR.var("y") - sage: Partition([6,5,1]).outline(variable=y) - abs(y + 6) - abs(y + 5) + abs(y + 4) - abs(y + 3) + abs(y - 1) - abs(y - 2) + abs(y - 3) + sage: y = SR.var("y") # optional - sage.symbolic + sage: Partition([6,5,1]).outline(variable=y) # optional - sage.symbolic + abs(y + 6) - abs(y + 5) + abs(y + 4) - abs(y + 3) + + abs(y - 1) - abs(y - 2) + abs(y - 3) TESTS:: diff --git a/src/sage/combinat/path_tableaux/frieze.py b/src/sage/combinat/path_tableaux/frieze.py index fd33a72ff26..d63935a6a3b 100644 --- a/src/sage/combinat/path_tableaux/frieze.py +++ b/src/sage/combinat/path_tableaux/frieze.py @@ -84,9 +84,10 @@ class FriezePattern(PathTableau, metaclass=InheritComparisonClasscallMetaclass): This constructs the examples from [HJ18]_:: - sage: K. = NumberField(x^2-3) - sage: t = path_tableaux.FriezePattern([1,sqrt3,2,sqrt3,1,1], field=K) - sage: path_tableaux.CylindricalDiagram(t) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: t = path_tableaux.FriezePattern([1,sqrt3,2,sqrt3,1,1], field=K) # optional - sage.rings.number_field + sage: path_tableaux.CylindricalDiagram(t) # optional - sage.rings.number_field [ 0, 1, sqrt3, 2, sqrt3, 1, 1, 0] [ , 0, 1, sqrt3, 2, sqrt3, sqrt3 + 1, 1, 0] [ , , 0, 1, sqrt3, 2, sqrt3 + 2, sqrt3, 1, 0] @@ -96,11 +97,12 @@ class FriezePattern(PathTableau, metaclass=InheritComparisonClasscallMetaclass): [ , , , , , , 0, 1, sqrt3 + 1, sqrt3 + 2, sqrt3 + 2, sqrt3 + 1, 1, 0] [ , , , , , , , 0, 1, sqrt3, 2, sqrt3, 1, 1, 0] - sage: TestSuite(t).run() + sage: TestSuite(t).run() # optional - sage.rings.number_field - sage: K. = NumberField(x^2-2) - sage: t = path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], field=K) - sage: path_tableaux.CylindricalDiagram(t) + sage: K. = NumberField(x^2 - 2) # optional - sage.rings.number_field + sage: t = path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], # optional - sage.rings.number_field + ....: field=K) + sage: path_tableaux.CylindricalDiagram(t) # optional - sage.rings.number_field [ 0, 1, sqrt2, 1, sqrt2, 3, 2*sqrt2, 5, 3*sqrt2, 1, 0] [ , 0, 1, sqrt2, 3, 5*sqrt2, 7, 9*sqrt2, 11, 2*sqrt2, 1, 0] [ , , 0, 1, 2*sqrt2, 7, 5*sqrt2, 13, 8*sqrt2, 3, sqrt2, 1, 0] @@ -113,7 +115,7 @@ class FriezePattern(PathTableau, metaclass=InheritComparisonClasscallMetaclass): [ , , , , , , , , , 0, 1, 2*sqrt2, 3, sqrt2, 1, sqrt2, 1, sqrt2, 1, 0] [ , , , , , , , , , , 0, 1, sqrt2, 1, sqrt2, 3, 2*sqrt2, 5, 3*sqrt2, 1, 0] - sage: TestSuite(t).run() + sage: TestSuite(t).run() # optional - sage.rings.number_field """ @staticmethod def __classcall_private__(cls, fp, field=QQ): @@ -132,13 +134,14 @@ def __classcall_private__(cls, fp, field=QQ): ... ValueError: invalid input 2 - sage: K. = NumberField(x^2-3) - sage: t = path_tableaux.FriezePattern([1,sqrt3,2,sqrt3,1,1]) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: t = path_tableaux.FriezePattern([1,sqrt3,2,sqrt3,1,1]) # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: [1, sqrt3, 2, sqrt3, 1, 1] is not a sequence in the field Rational Field - sage: path_tableaux.FriezePattern([1,2,1,2,3,1],field=Integers()) + sage: path_tableaux.FriezePattern([1,2,1,2,3,1], field=Integers()) Traceback (most recent call last): ... ValueError: Integer Ring must be a field @@ -274,8 +277,9 @@ def is_positive(self): sage: path_tableaux.FriezePattern([1,-3,4,5,1]).is_positive() False - sage: K. = NumberField(x^2-3) - sage: path_tableaux.FriezePattern([1,sqrt3,1],K).is_positive() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: path_tableaux.FriezePattern([1,sqrt3,1], K).is_positive() # optional - sage.rings.number_field True """ return all(a > 0 for a in self[1:-1]) @@ -312,14 +316,15 @@ def triangulation(self): EXAMPLES:: - sage: path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]).triangulation() + sage: path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]).triangulation() # optional - sage.plot sage.symbolic Graphics object consisting of 25 graphics primitives - sage: path_tableaux.FriezePattern([1,2,1/7,5,3]).triangulation() + sage: path_tableaux.FriezePattern([1,2,1/7,5,3]).triangulation() # optional - sage.plot sage.symbolic Graphics object consisting of 12 graphics primitives - sage: K. = NumberField(x^2-2) - sage: path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], field=K).triangulation() + sage: K. = NumberField(x^2 - 2) # optional - sage.rings.number_field + sage: path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], # optional - sage.plot sage.rings.number_field sage.symbolic + ....: field=K).triangulation() Graphics object consisting of 24 graphics primitives """ n = len(self)-1 @@ -372,17 +377,17 @@ def plot(self, model='UHP'): EXAMPLES:: sage: t = path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]) - sage: t.plot() + sage: t.plot() # optional - sage.plot sage.symbolic Graphics object consisting of 18 graphics primitives - sage: t.plot(model='UHP') + sage: t.plot(model='UHP') # optional - sage.plot sage.symbolic Graphics object consisting of 18 graphics primitives - sage: t.plot(model='PD') + sage: t.plot(model='PD') # optional - sage.plot sage.symbolic Traceback (most recent call last): ... TypeError: '>' not supported between instances of 'NotANumber' and 'Pi' - sage: t.plot(model='KM') + sage: t.plot(model='KM') # optional - sage.plot sage.symbolic Graphics object consisting of 18 graphics primitives """ from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane diff --git a/src/sage/combinat/perfect_matching.py b/src/sage/combinat/perfect_matching.py index 383f6522903..9d57f0b59ac 100644 --- a/src/sage/combinat/perfect_matching.py +++ b/src/sage/combinat/perfect_matching.py @@ -453,11 +453,11 @@ def Weingarten_function(self, d, other=None): EXAMPLES:: - sage: var('N') + sage: var('N') # optional - sage.symbolic N sage: m = PerfectMatching([(1,3),(2,4)]) sage: n = PerfectMatching([(1,2),(3,4)]) - sage: factor(m.Weingarten_function(N,n)) + sage: factor(m.Weingarten_function(N, n)) # optional - sage.symbolic -1/((N + 2)*(N - 1)*N) """ if other is None: @@ -764,8 +764,8 @@ def Weingarten_matrix(self, N): EXAMPLES:: - sage: M = PerfectMatchings(4).Weingarten_matrix(var('N')) - sage: N*(N-1)*(N+2)*M.apply_map(factor) + sage: M = PerfectMatchings(4).Weingarten_matrix(var('N')) # optional - sage.symbolic + sage: N*(N-1)*(N+2)*M.apply_map(factor) # optional - sage.symbolic [N + 1 -1 -1] [ -1 N + 1 -1] [ -1 -1 N + 1] diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index fe3385e7472..2217b59a7bc 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -2783,7 +2783,7 @@ def is_incomparable_chain_free(self, m, n=None) -> bool: sage: Q = Poset({0:[2], 1:[2], 2:[3], 3:[4], 4:[]}) sage: Q.is_incomparable_chain_free(2, 20/10) True - sage: Q.is_incomparable_chain_free(2, pi) + sage: Q.is_incomparable_chain_free(2, pi) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: 2 and pi must be integers @@ -8732,7 +8732,7 @@ def kazhdan_lusztig_polynomial(self, x=None, y=None, q=None, canonical_labels=No sage: y = '3421' sage: L.kazhdan_lusztig_polynomial(x, y) -q + 1 - sage: L.kazhdan_lusztig_polynomial(x, y, var('t')) + sage: L.kazhdan_lusztig_polynomial(x, y, var('t')) # optional - sage.symbolic -t + 1 AUTHORS: diff --git a/src/sage/combinat/q_analogues.py b/src/sage/combinat/q_analogues.py index 0b204630b93..541fc98353c 100644 --- a/src/sage/combinat/q_analogues.py +++ b/src/sage/combinat/q_analogues.py @@ -248,18 +248,18 @@ def q_binomial(n, k, q=None, algorithm='auto'): This also works for variables in the symbolic ring:: - sage: z = var('z') - sage: factor(q_binomial(4, 2, z)) + sage: z = var('z') # optional - sage.symbolic + sage: factor(q_binomial(4, 2, z)) # optional - sage.symbolic (z^2 + z + 1)*(z^2 + 1) This also works for complex roots of unity:: - sage: q_binomial(10, 4, QQbar(I)) + sage: q_binomial(10, 4, QQbar(I)) # optional - sage.rings.number_field 2 Note that the symbolic computation works (see :trac:`14982`):: - sage: q_binomial(10, 4, I) + sage: q_binomial(10, 4, I) # optional - sage.rings.number_field 2 Check that the algorithm does not matter:: @@ -578,7 +578,7 @@ def q_pochhammer(n, a, q=None): 1 sage: q_pochhammer(0, 1) 1 - sage: q_pochhammer(0, var('a')) + sage: q_pochhammer(0, var('a')) # optional - sage.symbolic 1 We check that :trac:`25715` is fixed:: @@ -637,7 +637,7 @@ def q_jordan(t, q=None): [615195, 40635, 5643, 2331, 1491, 515, 147, 87, 47, 11, 1] sage: q_jordan([3,2,1]) 16*q^4 + 24*q^3 + 14*q^2 + 5*q + 1 - sage: q_jordan([2,1], x) + sage: q_jordan([2,1], x) # optional - sage.symbolic 2*x + 1 If the partition is trivial (i.e. has only one part), we get diff --git a/src/sage/combinat/ribbon_tableau.py b/src/sage/combinat/ribbon_tableau.py index a2955884c7d..65b9b7079cd 100644 --- a/src/sage/combinat/ribbon_tableau.py +++ b/src/sage/combinat/ribbon_tableau.py @@ -664,19 +664,19 @@ def spin_polynomial(part, weight, length): EXAMPLES:: sage: from sage.combinat.ribbon_tableau import spin_polynomial - sage: spin_polynomial([6,6,6],[4,2],3) + sage: spin_polynomial([6,6,6],[4,2],3) # optional - sage.symbolic t^6 + t^5 + 2*t^4 + t^3 + t^2 - sage: spin_polynomial([6,6,6],[4,1,1],3) + sage: spin_polynomial([6,6,6],[4,1,1],3) # optional - sage.symbolic t^6 + 2*t^5 + 3*t^4 + 2*t^3 + t^2 - sage: spin_polynomial([3,3,3,2,1], [2,2], 3) + sage: spin_polynomial([3,3,3,2,1], [2,2], 3) # optional - sage.symbolic t^(7/2) + t^(5/2) - sage: spin_polynomial([3,3,3,2,1], [2,1,1], 3) + sage: spin_polynomial([3,3,3,2,1], [2,1,1], 3) # optional - sage.symbolic 2*t^(7/2) + 2*t^(5/2) + t^(3/2) - sage: spin_polynomial([3,3,3,2,1], [1,1,1,1], 3) + sage: spin_polynomial([3,3,3,2,1], [1,1,1,1], 3) # optional - sage.symbolic 3*t^(7/2) + 5*t^(5/2) + 3*t^(3/2) + sqrt(t) - sage: spin_polynomial([5,4,3,2,1,1,1], [2,2,1], 3) + sage: spin_polynomial([5,4,3,2,1,1,1], [2,2,1], 3) # optional - sage.symbolic 2*t^(9/2) + 6*t^(7/2) + 2*t^(5/2) - sage: spin_polynomial([[6]*6, [3,3]], [4,4,2], 3) + sage: spin_polynomial([[6]*6, [3,3]], [4,4,2], 3) # optional - sage.symbolic 3*t^9 + 5*t^8 + 9*t^7 + 6*t^6 + 3*t^5 """ from sage.symbolic.ring import SR diff --git a/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py b/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py index ae39e62ce01..37fd54ce2f3 100644 --- a/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py +++ b/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py @@ -1074,21 +1074,21 @@ class NonSymmetricMacdonaldPolynomials(CherednikOperatorsEigenvectors): sage: K = QQ['q','t'].fraction_field() sage: q,t = K.gens() sage: def to_SR(x): return x.expand([SR.var('x%s'%i) for i in range(1,x.parent().basis().keys().dimension()+1)]).subs(q=SR.var('q'), t=SR.var('t')) - sage: var('x1,x2,x3') + sage: var('x1,x2,x3') # optional - sage.symbolic (x1, x2, x3) sage: E = NonSymmetricMacdonaldPolynomials(["BC",2,2], q=q, q1=t^2,q2=-1) sage: omega=E.keys().fundamental_weights() sage: expected = (t-1)*(t+1)*(2+q^4+2*q^2-2*t^2-2*q^2*t^2-t^4*q^2-q^4*t^4+t^4-3*q^6*t^6-2*q^4*t^6+2*q^6*t^8+2*q^4*t^8+t^10*q^8)*q^4/((q^2*t^3-1)*(q^2*t^3+1)*(t*q-1)*(t*q+1)*(t^2*q^3+1)*(t^2*q^3-1))+(t-1)^2*(t+1)^2*(2*q^2+q^4+2+q^4*t^2)*q^3*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)^2*(t+1)^2*(q^2+1)*q^5/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^4*x2/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(2*q^2+q^4+2+q^4*t^2)*q^3*x2/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)^2*(t+1)^2*(q^2+1)*q^5/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x2)+x1^2*x2^2+(t-1)*(t+1)*(-2*q^2-q^4-2+2*q^2*t^2+t^2+q^6*t^4+q^4*t^4)*q^2*x2*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q*x2^2*x1/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^3*x1^2/((t^2*q^3-1)*(t^2*q^3+1)*x2)+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q*x2*x1^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^6/((t^2*q^3+1)*(t^2*q^3-1)*x1*x2)+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q^2*x1^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q^2*x2^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^3*x2^2/((t^2*q^3-1)*(t^2*q^3+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^4*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x2) - sage: to_SR(E[2*omega[2]]) - expected # long time (3.5s) + sage: to_SR(E[2*omega[2]]) - expected # long time (3.5s) # optional - sage.symbolic 0 - sage: E = NonSymmetricMacdonaldPolynomials(["BC",3,2], q=q, q1=t^2,q2=-1) + sage: E = NonSymmetricMacdonaldPolynomials(["BC",3,2], q=q, q1=t^2, q2=-1) sage: omega=E.keys().fundamental_weights() sage: mu = -3*omega[1] + 3*omega[2] - omega[3]; mu (-1, 2, -1) sage: expected = (t-1)^2*(t+1)^2*(3*q^2+q^4+1+t^2*q^4+q^2*t^2-3*t^4*q^2-5*t^6*q^4+2*t^8*q^4-4*t^8*q^6-q^8*t^10+2*t^10*q^6-2*q^8*t^12+t^14*q^8-t^14*q^10+q^10*t^16+q^8*t^16+q^10*t^18+t^18*q^12)*x2*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(q^2*t^6+2*t^6*q^4-q^4*t^4+t^4*q^2-q^2*t^2+t^2-2-q^2)*q^2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*(-q^2-1+t^4*q^2-q^4*t^4+2*t^6*q^4)*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t+1)*(t-1)*x2^2*x3/((t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(3*q^2+q^4+2+t^2*q^4+2*q^2*t^2-4*t^4*q^2+q^4*t^4-6*t^6*q^4+t^8*q^4-4*t^8*q^6-q^8*t^10+t^10*q^6-3*q^8*t^12-2*t^14*q^10+2*t^14*q^8+2*q^10*t^16+q^8*t^16+t^18*q^12+2*q^10*t^18)*q*x2/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(1+q^4+2*q^2+t^2*q^4-3*t^4*q^2+q^2*t^6-5*t^6*q^4+3*t^8*q^4-4*t^8*q^6+2*t^10*q^6-q^8*t^12-t^14*q^10+t^14*q^8+q^10*t^16+t^18*q^12)*x3*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(2*q^2+1+q^4+t^2*q^4-t^2+q^2*t^2-4*t^4*q^2+q^4*t^4+q^2*t^6-5*t^6*q^4+3*t^8*q^4-4*t^8*q^6+2*t^10*q^6+q^6*t^12-2*q^8*t^12-2*t^14*q^10+2*t^14*q^8+q^10*t^16+t^18*q^12)*q*x3/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(1+t^2+t^4*q^2)*q*x3*x2^2/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2+t^4-q^4*t^4-t^4*q^2+3*q^2*t^6-t^6*q^4-t^8*q^6+t^8*q^4+t^10*q^4+2*q^6*t^12-q^8*t^12+t^14*q^8)*q*x3*x2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*x1^2/((q^3*t^5-1)*(q^3*t^5+1)*x3*x2)+(t-1)*(t+1)*(-q^2-1+t^4*q^2-q^4*t^4+2*t^6*q^4)*x2^2/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)*(t+1)*(t^3*q-1)*(t^3*q+1)*x3*x2^2*x1/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*(q^2+1)*q*x1/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x3*x2)+(t-1)^2*(t+1)^2*(t^3*q-1)*(t^3*q+1)*x3*x2*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)^2*(t+1)^2*q^3*x3/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1*x2)+(t-1)*(t+1)*(-1-q^2+q^2*t^2+t^10*q^6)*q*x2/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x3*x1)+x2^2/(x1*x3)+(t-1)*(t+1)*q*x2^2/((t*q-1)*(t*q+1)*x3)+(t-1)^3*(t+1)^3*(1+t^2+t^4*q^2)*q*x2*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)^2*(t+1)^2*q*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(q^2*t^6+2*t^6*q^4-q^4*t^4+t^4*q^2-q^2*t^2+t^2-2-q^2)*q^3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)*(t+1)*(q^2+2-t^2+q^4*t^4-t^4*q^2-3*t^6*q^4+t^8*q^4-2*t^10*q^6-q^8*t^12+q^6*t^12+q^8*t^16+q^10*t^16)*q^2*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3*x2)+(t-1)*(t+1)*(1+q^4+2*q^2-2*q^2*t^2+t^4*q^6-q^4*t^4-3*q^6*t^6-t^6*q^4+2*t^8*q^6-t^10*q^6-q^8*t^10-t^14*q^10+t^14*q^8+2*q^10*t^16)*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2-q^4*t^4+2*t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^8)*q^3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)^2*(t+1)^2*(-1-q^2-q^2*t^2+t^2+t^4*q^2-q^4*t^4+2*t^6*q^4)*q^2*x3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)*(t+1)*q*x2^2/((t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(1+t^2+t^4*q^2)*q*x2^2*x1/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*q*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*(-1-q^4-2*q^2-t^2*q^4-q^2*t^2+t^4*q^2-t^4*q^6-2*q^4*t^4+3*t^6*q^4-q^6*t^6-t^8*q^8+t^8*q^6+2*t^10*q^6-q^10*t^12+3*q^8*t^12+2*t^14*q^10)*x3*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*(q^2+1-t^2+q^4*t^4-t^4*q^2+q^2*t^6-3*t^6*q^4+t^8*q^4-t^10*q^6+q^6*t^12-q^8*t^12+q^10*t^16)*q^2*x3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)*(t+1)*(-1-q^2+q^2*t^2+t^10*q^6)*q^2/((t*q-1)*(t*q+1)*(q^3*t^5+1)*(q^3*t^5-1)*x1*x3)+(t-1)*(t+1)*(1+q^4+2*q^2-3*q^2*t^2+t^4*q^6-q^4*t^4-3*q^6*t^6-t^6*q^4+t^8*q^4+2*t^8*q^6-t^10*q^6+t^14*q^8-t^14*q^10+q^10*t^16)*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(3*q^2+q^4+2+q^2*t^2-t^2+t^2*q^4-6*t^4*q^2+q^4*t^4-7*t^6*q^4+q^2*t^6+3*t^8*q^4-4*t^8*q^6+t^10*q^4+3*t^10*q^6-q^8*t^12-t^14*q^10+t^14*q^8+q^8*t^16+q^10*t^18)*q*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2-q^4*t^4+2*t^6*q^4+t^10*q^6+q^6*t^12+t^14*q^8)*q*x2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t+1)*(t-1)*x2^2*x1/((t*q-1)*(t*q+1)*x3)+(t-1)^3*(t+1)^3*(1+t^2+t^4*q^2)*q*x3*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*q^3/((q^3*t^5+1)*(q^3*t^5-1)*x1*x2*x3)+(t-1)^2*(t+1)^2*(3+3*q^2+q^4+2*q^2*t^2-t^2+t^2*q^4-6*t^4*q^2+q^4*t^4-8*t^6*q^4+q^2*t^6+2*t^8*q^4-4*t^8*q^6+t^10*q^4+2*t^10*q^6-2*q^8*t^12-t^14*q^10+t^14*q^8+q^8*t^16+q^10*t^16+2*q^10*t^18)*q^2/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(-q^4-2*q^2-1-t^2*q^4-t^4*q^6+2*q^6*t^6+t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^10)*q/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(-1-q^2-q^2*t^2+t^2+t^4*q^2-q^4*t^4+2*t^6*q^4)*q*x3*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*x2*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*x3*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*q^4/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x1*x2)+(t-1)^2*(t+1)^2*(-q^2-1-q^2*t^2-q^4*t^4+t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^10)*q*x3*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1) - sage: to_SR(E[mu]) - expected # long time (20s) + sage: to_SR(E[mu]) - expected # long time (20s) # optional - sage.symbolic 0 sage: E = NonSymmetricMacdonaldPolynomials(["BC",1,2], q=q, q1=t^2,q2=-1) @@ -1096,7 +1096,7 @@ class NonSymmetricMacdonaldPolynomials(CherednikOperatorsEigenvectors): sage: mu = -4*omega[1]; mu (-4) sage: expected = (t-1)*(t+1)*(-1+q^2*t^2-q^2-3*q^10-7*q^26*t^8+5*t^2*q^6-q^16-3*q^4+4*t^10*q^30-4*t^6*q^22-10*q^20*t^6+2*q^32*t^10-3*q^6-4*q^8+q^34*t^10-4*t^8*q^24-2*q^12-q^14+2*q^22*t^10+4*q^26*t^10+4*q^28*t^10+t^6*q^30-2*q^32*t^8-2*t^8*q^22+2*q^24*t^10-q^20*t^2-2*t^6*q^12+t^8*q^14+2*t^4*q^24-4*t^8*q^30+2*t^8*q^20-9*t^6*q^16+3*q^26*t^6+q^28*t^6+3*t^2*q^4+2*q^18*t^8-6*t^6*q^14+4*t^4*q^22-2*q^24*t^6+3*t^2*q^12+7*t^4*q^20-t^2*q^16+11*q^18*t^4-2*t^2*q^18+9*q^16*t^4-t^4*q^6+6*q^8*t^2+5*q^10*t^2-6*q^28*t^8+q^12*t^4+8*t^4*q^14-10*t^6*q^18-q^4*t^4+q^16*t^8-2*t^4*q^8)/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*(q^5*t^2+1)*(q^5*t^2-1))+(q^2+1)*(q^4+1)*(t-1)*(t+1)*(-1+q^2*t^2-q^2+t^2*q^6-q^4+t^6*q^22+3*q^10*t^4+t^2-q^8-2*t^8*q^24+q^22*t^10+q^26*t^10-2*t^8*q^22+q^24*t^10-4*t^6*q^12-2*t^8*q^20-3*t^6*q^16+2*t^2*q^4-t^6*q^10-2*t^6*q^14+t^8*q^12-t^2*q^12+2*q^16*t^4+q^8*t^2-q^10*t^2+3*q^12*t^4+2*t^4*q^14+t^6*q^18-2*q^4*t^4+q^16*t^8+q^20*t^10)*q*x1/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*(q^5*t^2+1)*(q^5*t^2-1))+(q^2+1)*(q^4+1)*(t-1)*(t+1)*(1+q^8+q^4+q^2-q^8*t^2-2*t^2*q^4-t^2*q^6+t^2*q^12-t^2+t^4*q^6-2*q^16*t^4-t^4*q^14-2*q^12*t^4+t^6*q^12+t^6*q^16+t^6*q^18+t^6*q^14)*q/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*x1)+(t-1)*(t+1)*(-1-q^2-q^6-q^4-q^8+t^2*q^4-t^2*q^14+t^2*q^6-q^10*t^2+q^8*t^2-t^2*q^12+q^12*t^4+q^10*t^4+q^16*t^4+2*t^4*q^14)*(q^4+1)/((q^7*t^2+1)*(q^7*t^2-1)*(t*q^4-1)*(t*q^4+1)*x1^2)+(t-1)*(t+1)*(q^4+1)*(q^2+1)*q/((t*q^4-1)*(t*q^4+1)*x1^3)+(q^4+1)*(t-1)*(t+1)*(1+q^6+q^8+q^2+q^4-q^2*t^2-3*t^2*q^4+q^10*t^2+t^2*q^12-2*t^2*q^6-q^8*t^2-2*q^16*t^4+q^4*t^4+t^4*q^6-q^10*t^4-2*q^12*t^4-2*t^4*q^14+t^6*q^12+t^6*q^18+2*t^6*q^16+t^6*q^14)*x1^2/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1))+(t-1)*(t+1)*(-1-t^2*q^6+t^2+t^4*q^8)*(q^4+1)*(q^2+1)*q*x1^3/((q^7*t^2+1)*(q^7*t^2-1)*(t*q^4-1)*(t*q^4+1))+1/x1^4+(t-1)*(t+1)*x1^4/((t*q^4-1)*(t*q^4+1)) - sage: to_SR(E[mu]) - expected + sage: to_SR(E[mu]) - expected # optional - sage.symbolic 0 Type `BC` dual, comparison with hand calculations by Bogdan Ion:: diff --git a/src/sage/combinat/root_system/root_lattice_realizations.py b/src/sage/combinat/root_system/root_lattice_realizations.py index faadbe3ea21..2e2b2d2f3a9 100644 --- a/src/sage/combinat/root_system/root_lattice_realizations.py +++ b/src/sage/combinat/root_system/root_lattice_realizations.py @@ -2094,8 +2094,7 @@ def plot_parse_options(self, **args): EXAMPLES:: sage: L = RootSystem(["A",2,1]).ambient_space() - sage: options = L.plot_parse_options() - sage: options + sage: options = L.plot_parse_options(); options # optional - sage.symbolic .. SEEALSO:: @@ -2120,7 +2119,7 @@ def _plot_projection(self, x): sage: L = RootSystem(["B",3]).root_lattice() sage: l = L.an_element(); l 2*alpha[1] + 2*alpha[2] + 3*alpha[3] - sage: L._plot_projection(l) + sage: L._plot_projection(l) # optional - sage.symbolic 2*alpha[1] + 2*alpha[2] + 3*alpha[3] In the ambient space of type `A_2`, this is the @@ -2154,22 +2153,22 @@ def _plot_projection_barycentric_matrix(self): EXAMPLES:: - sage: RootSystem(["A",0]).ambient_space()._plot_projection_barycentric_matrix() + sage: RootSystem(["A",0]).ambient_space()._plot_projection_barycentric_matrix() # optional - sage.symbolic [] - sage: m = RootSystem(["A",1]).ambient_space()._plot_projection_barycentric_matrix(); m + sage: m = RootSystem(["A",1]).ambient_space()._plot_projection_barycentric_matrix(); m # optional - sage.symbolic [ 1 -1] - sage: sum(m.columns()) + sage: sum(m.columns()) # optional - sage.symbolic (0) - sage: m = RootSystem(["A",2]).ambient_space()._plot_projection_barycentric_matrix(); m + sage: m = RootSystem(["A",2]).ambient_space()._plot_projection_barycentric_matrix(); m # optional - sage.symbolic [ 1/2 -1 1/2] [ 989/1142 0 -989/1142] - sage: sum(m.columns()) + sage: sum(m.columns()) # optional - sage.symbolic (0, 0) - sage: m = RootSystem(["A",3]).ambient_space()._plot_projection_barycentric_matrix(); m + sage: m = RootSystem(["A",3]).ambient_space()._plot_projection_barycentric_matrix(); m # optional - sage.symbolic [ 1277/1564 -1277/1564 0 0] [1009460/2141389 849/1801 -1121/1189 0] [ 1/3 1/3 1/3 -1] - sage: sum(m.columns()) + sage: sum(m.columns()) # optional - sage.symbolic (0, 0, 0) """ @@ -2197,11 +2196,11 @@ def _plot_projection_barycentric(self, x): sage: L = RootSystem(["A",2]).ambient_space() sage: e = L.basis() - sage: L._plot_projection_barycentric(e[0]) + sage: L._plot_projection_barycentric(e[0]) # optional - sage.symbolic (1/2, 989/1142) - sage: L._plot_projection_barycentric(e[1]) + sage: L._plot_projection_barycentric(e[1]) # optional - sage.symbolic (-1, 0) - sage: L._plot_projection_barycentric(e[2]) + sage: L._plot_projection_barycentric(e[2]) # optional - sage.symbolic (1/2, -989/1142) .. SEEALSO:: @@ -2235,36 +2234,36 @@ def plot_roots(self, collection="simple", **options): EXAMPLES:: - sage: RootSystem(["B",3]).ambient_space().plot_roots() + sage: RootSystem(["B",3]).ambient_space().plot_roots() # optional - sage.plot Graphics3d Object - sage: RootSystem(["B",3]).ambient_space().plot_roots("all") + sage: RootSystem(["B",3]).ambient_space().plot_roots("all") # optional - sage.plot Graphics3d Object TESTS:: - sage: list(RootSystem(["A",2]).root_lattice().plot_roots()) + sage: list(RootSystem(["A",2]).root_lattice().plot_roots()) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (1.0,0.0), Text '$\alpha_{1}$' at the point (1.05,0.0), Arrow from (0.0,0.0) to (0.0,1.0), Text '$\alpha_{2}$' at the point (0.0,1.05)] - sage: list(RootSystem(["A",2]).weight_lattice().plot_roots(labels=False)) + sage: list(RootSystem(["A",2]).weight_lattice().plot_roots(labels=False)) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (2.0,-1.0), Arrow from (0.0,0.0) to (-1.0,2.0)] - sage: list(RootSystem(["A",2]).ambient_lattice().plot_roots()) + sage: list(RootSystem(["A",2]).ambient_lattice().plot_roots()) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (1.5,0.86...), Text '$\alpha_{1}$' at the point (1.575...,0.90...), Arrow from (0.0,0.0) to (-1.5,0.86...), Text '$\alpha_{2}$' at the point (-1.575...,0.90...)] - sage: list(RootSystem(["B",2]).ambient_space().plot_roots()) + sage: list(RootSystem(["B",2]).ambient_space().plot_roots()) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (1.0,-1.0), Text '$\alpha_{1}$' at the point (1.05,-1.05), Arrow from (0.0,0.0) to (0.0,1.0), Text '$\alpha_{2}$' at the point (0.0,1.05)] - sage: list(RootSystem(["A",2]).root_lattice().plot_roots("all")) + sage: list(RootSystem(["A",2]).root_lattice().plot_roots("all")) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (1.0,0.0), Text '$\alpha_{1}$' at the point (1.05,0.0), Arrow from (0.0,0.0) to (0.0,1.0), @@ -2370,18 +2369,18 @@ def plot_fundamental_weights(self, **options): EXAMPLES:: - sage: RootSystem(["B",3]).ambient_space().plot_fundamental_weights() + sage: RootSystem(["B",3]).ambient_space().plot_fundamental_weights() # optional - sage.plot Graphics3d Object TESTS:: - sage: sorted(RootSystem(["A",2]).weight_lattice().plot_fundamental_weights(), key=str) + sage: sorted(RootSystem(["A",2]).weight_lattice().plot_fundamental_weights(), key=str) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (0.0,1.0), Arrow from (0.0,0.0) to (1.0,0.0), Text '$\Lambda_{1}$' at the point (1.05,0.0), Text '$\Lambda_{2}$' at the point (0.0,1.05)] - sage: sorted(RootSystem(["A",2]).ambient_lattice().plot_fundamental_weights(), key=str) + sage: sorted(RootSystem(["A",2]).ambient_lattice().plot_fundamental_weights(), key=str) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (-0.5,0.86602451838...), Arrow from (0.0,0.0) to (0.5,0.86602451838...), Text '$\Lambda_{1}$' at the point (0.525,0.909325744308...), @@ -2423,21 +2422,21 @@ def plot_reflection_hyperplanes(self, collection="simple", **options): EXAMPLES:: - sage: RootSystem(["A",2,1]).ambient_space().plot_reflection_hyperplanes() + sage: RootSystem(["A",2,1]).ambient_space().plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics object consisting of 6 graphics primitives - sage: RootSystem(["G",2,1]).ambient_space().plot_reflection_hyperplanes() + sage: RootSystem(["G",2,1]).ambient_space().plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics object consisting of 6 graphics primitives - sage: RootSystem(["A",3]).weight_space().plot_reflection_hyperplanes() + sage: RootSystem(["A",3]).weight_space().plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["B",3]).ambient_space().plot_reflection_hyperplanes() + sage: RootSystem(["B",3]).ambient_space().plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["A",3,1]).weight_space().plot_reflection_hyperplanes() + sage: RootSystem(["A",3,1]).weight_space().plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["B",3,1]).ambient_space().plot_reflection_hyperplanes() + sage: RootSystem(["B",3,1]).ambient_space().plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["A",2,1]).weight_space().plot_reflection_hyperplanes(affine=False, level=1) + sage: RootSystem(["A",2,1]).weight_space().plot_reflection_hyperplanes(affine=False, level=1) # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["A",2]).root_lattice().plot_reflection_hyperplanes() + sage: RootSystem(["A",2]).root_lattice().plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics object consisting of 4 graphics primitives TESTS:: @@ -2507,27 +2506,27 @@ def plot_hedron(self, **options): EXAMPLES:: - sage: RootSystem(["A",2]).ambient_space().plot_hedron() + sage: RootSystem(["A",2]).ambient_space().plot_hedron() # optional - sage.plot sage.symbolic Graphics object consisting of 8 graphics primitives - sage: RootSystem(["A",3]).ambient_space().plot_hedron() + sage: RootSystem(["A",3]).ambient_space().plot_hedron() # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["B",3]).ambient_space().plot_hedron() + sage: RootSystem(["B",3]).ambient_space().plot_hedron() # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["C",3]).ambient_space().plot_hedron() + sage: RootSystem(["C",3]).ambient_space().plot_hedron() # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["D",3]).ambient_space().plot_hedron() + sage: RootSystem(["D",3]).ambient_space().plot_hedron() # optional - sage.plot sage.symbolic Graphics3d Object Surprise: polyhedra of large dimension know how to project themselves nicely:: - sage: RootSystem(["F",4]).ambient_space().plot_hedron() # long time + sage: RootSystem(["F",4]).ambient_space().plot_hedron() # long time # optional - sage.plot sage.symbolic Graphics3d Object TESTS:: sage: L = RootSystem(["B",2]).ambient_space() - sage: print(L.plot_hedron().description()) + sage: print(L.plot_hedron().description()) # optional - sage.plot sage.symbolic Polygon defined by 8 points: [(1.5, 0.5), (0.5, 1.5), (-0.5, 1.5), (-1.5, 0.5), (-1.5, -0.5), (-0.5, -1.5), (0.5, -1.5), (1.5, -0.5)] Line defined by 2 points: [(-0.5, -1.5), (0.5, -1.5)] Line defined by 2 points: [(-0.5, 1.5), (0.5, 1.5)] @@ -2567,18 +2566,18 @@ def plot_fundamental_chamber(self, style="normal", **options): 2D plots:: - sage: RootSystem(["B",2]).ambient_space().plot_fundamental_chamber() + sage: RootSystem(["B",2]).ambient_space().plot_fundamental_chamber() # optional - sage.plot Graphics object consisting of 1 graphics primitive - sage: RootSystem(["B",2,1]).ambient_space().plot_fundamental_chamber() + sage: RootSystem(["B",2,1]).ambient_space().plot_fundamental_chamber() # optional - sage.plot Graphics object consisting of 1 graphics primitive - sage: RootSystem(["B",2,1]).ambient_space().plot_fundamental_chamber("classical") + sage: RootSystem(["B",2,1]).ambient_space().plot_fundamental_chamber("classical") # optional - sage.plot Graphics object consisting of 1 graphics primitive 3D plots:: - sage: RootSystem(["A",3,1]).weight_space() .plot_fundamental_chamber() + sage: RootSystem(["A",3,1]).weight_space() .plot_fundamental_chamber() # optional - sage.plot Graphics3d Object - sage: RootSystem(["B",3,1]).ambient_space().plot_fundamental_chamber() + sage: RootSystem(["B",3,1]).ambient_space().plot_fundamental_chamber() # optional - sage.plot Graphics3d Object This feature is currently not available in the root lattice/space:: @@ -2591,10 +2590,10 @@ def plot_fundamental_chamber(self, style="normal", **options): TESTS:: sage: L = RootSystem(["B",2,1]).ambient_space() - sage: print(L.plot_fundamental_chamber().description()) + sage: print(L.plot_fundamental_chamber().description()) # optional - sage.plot Polygon defined by 3 points: [(0.5, 0.5), (1.0, 0.0), (0.0, 0.0)] - sage: print(L.plot_fundamental_chamber(style="classical").description()) + sage: print(L.plot_fundamental_chamber(style="classical").description()) # optional - sage.plot Polygon defined by 3 points: [(0.0, 0.0), (3.0, 3.0), (3.0, 0.0)] """ plot_options = self.plot_parse_options(**options) @@ -2639,28 +2638,28 @@ def plot_alcoves(self, alcoves=True, alcove_labels=False, wireframe=False, **opt 2D plots:: - sage: RootSystem(["B",2,1]).ambient_space().plot_alcoves() # long time (3s) + sage: RootSystem(["B",2,1]).ambient_space().plot_alcoves() # long time (3s) # optional - sage.plot sage.symbolic Graphics object consisting of 228 graphics primitives 3D plots:: - sage: RootSystem(["A",2,1]).weight_space() .plot_alcoves(affine=False) # long time (3s) + sage: RootSystem(["A",2,1]).weight_space() .plot_alcoves(affine=False) # long time (3s) # optional - sage.plot sage.symbolic Graphics3d Object - sage: RootSystem(["G",2,1]).ambient_space().plot_alcoves(affine=False, level=1) # long time (3s) + sage: RootSystem(["G",2,1]).ambient_space().plot_alcoves(affine=False, level=1) # long time (3s) # optional - sage.plot sage.symbolic Graphics3d Object Here we plot a single alcove:: sage: L = RootSystem(["A",3,1]).ambient_space() sage: W = L.weyl_group() - sage: L.plot(alcoves=[W.one()], reflection_hyperplanes=False, bounding_box=2) + sage: L.plot(alcoves=[W.one()], reflection_hyperplanes=False, bounding_box=2) # optional - sage.plot sage.symbolic Graphics3d Object TESTS:: sage: L = RootSystem(["A",2,1]).weight_space() - sage: p = L.plot_alcoves(alcoves=[[0,0]]) - sage: print(p.description()) + sage: p = L.plot_alcoves(alcoves=[[0,0]]) # optional - sage.plot sage.symbolic + sage: print(p.description()) # optional - sage.plot sage.symbolic Line defined by 2 points: [(-1.0, 0.0), (0.0, -1.0)] Line defined by 2 points: [(-1.0, 1.0), (-1.0, 0.0)] Line defined by 2 points: [(-1.0, 1.0), (0.0, 0.0)] @@ -2673,7 +2672,7 @@ def plot_alcoves(self, alcoves=True, alcove_labels=False, wireframe=False, **opt Line defined by 2 points: [(1.0, -1.0), (0.0, -1.0)] Line defined by 2 points: [(1.0, 0.0), (0.0, 0.0)] Line defined by 2 points: [(1.0, 0.0), (1.0, -1.0)] - sage: sorted((line.options()['rgbcolor'], line.options()['thickness']) for line in p) + sage: sorted((line.options()['rgbcolor'], line.options()['thickness']) for line in p) # optional - sage.plot sage.symbolic [('black', 2), ('black', 2), ('black', 2), ('black', 2), ('black', 2), ('black', 2), ('blue', 1), ('blue', 1), ('blue', 1), @@ -2867,32 +2866,34 @@ def plot_alcove_walk(self, word, start=None, foldings=None, color="orange", **op sage: L = RootSystem(["A",2,1]).ambient_space() sage: w1 = [0,2,1,2,0,2,1,0,2,1,2,1,2,0,2,0,1,2,0] - sage: p = L.plot_alcoves(bounding_box=5) # long time (5s) - sage: p += L.plot_alcove_walk(w1) # long time - sage: p # long time + sage: p = L.plot_alcoves(bounding_box=5) # long time (5s) # optional - sage.plot sage.symbolic + sage: p += L.plot_alcove_walk(w1) # long time # optional - sage.plot sage.symbolic + sage: p # long time # optional - sage.plot sage.symbolic Graphics object consisting of 375 graphics primitives The same plot with another alcove walk:: sage: w2 = [2,1,2,0,2,0,2,1,2,0,1,2,1,2,1,0,1,2,0,2,0,1,2,0,2] - sage: p += L.plot_alcove_walk(w2, color="orange") # long time + sage: p += L.plot_alcove_walk(w2, color="orange") # long time # optional - sage.plot sage.symbolic And another with some foldings:: - sage: pic = L.plot_alcoves(bounding_box=3) # long time - sage: pic += L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], # long time (3s) - ....: foldings = [False, False, True, False, False, False, True, False, True, False], + sage: pic = L.plot_alcoves(bounding_box=3) # long time # optional - sage.plot sage.symbolic + sage: pic += L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], # long time (3s), optional - sage.plot sage.symbolic + ....: foldings=[False, False, True, False, False, + ....: False, True, False, True, False], ....: color="green"); pic Graphics object consisting of 155 graphics primitives TESTS:: sage: L = RootSystem(["A",2,1]).weight_space() - sage: p = L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], - ....: foldings = [False, False, True, False, False, False, True, False, True, False], + sage: p = L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], # optional - sage.plot sage.symbolic + ....: foldings=[False, False, True, False, False, + ....: False, True, False, True, False], ....: color="green", ....: start=L.rho()) - sage: print(p.description()) + sage: print(p.description()) # optional - sage.plot sage.symbolic Line defined by 2 points: [(-1.0, 8.0), (-1.5, 9.0)] Line defined by 2 points: [(1.0, 4.0), (1.5, 4.5)] Line defined by 2 points: [(1.0, 7.0), (1.5, 6.0)] @@ -2982,14 +2983,14 @@ def plot_ls_paths(self, paths, plot_labels=None, colored_labels=True, **options) sage: B = crystals.LSPaths(['A',2], [1,1]) sage: L = RootSystem(['A',2]).ambient_space() - sage: L.plot_fundamental_weights() + L.plot_ls_paths(B) + sage: L.plot_fundamental_weights() + L.plot_ls_paths(B) # optional - sage.plot sage.symbolic Graphics object consisting of 14 graphics primitives This also works in 3 dimensions:: sage: B = crystals.LSPaths(['B',3], [2,0,0]) sage: L = RootSystem(['B',3]).ambient_space() - sage: L.plot_ls_paths(B) + sage: L.plot_ls_paths(B) # optional - sage.plot sage.symbolic Graphics3d Object """ if not isinstance(paths, (list, tuple, set)): @@ -3050,7 +3051,7 @@ def plot_mv_polytope(self, mv_polytope, mark_endpoints=True, sage: B = crystals.infinity.MVPolytopes(['C',2]) sage: L = RootSystem(['C',2]).ambient_space() sage: p = B.highest_weight_vector().f_string([1,2,1,2]) - sage: L.plot_fundamental_weights() + L.plot_mv_polytope(p) + sage: L.plot_fundamental_weights() + L.plot_mv_polytope(p) # optional - sage.geometry.polyhedron sage.plot sage.symbolic Graphics object consisting of 14 graphics primitives This also works in 3 dimensions:: @@ -3058,7 +3059,7 @@ def plot_mv_polytope(self, mv_polytope, mark_endpoints=True, sage: B = crystals.infinity.MVPolytopes(['A',3]) sage: L = RootSystem(['A',3]).ambient_space() sage: p = B.highest_weight_vector().f_string([2,1,3,2]) - sage: L.plot_mv_polytope(p) + sage: L.plot_mv_polytope(p) # optional - sage.geometry.polyhedron sage.plot sage.symbolic Graphics3d Object """ from sage.geometry.polyhedron.all import Polyhedron @@ -3128,17 +3129,18 @@ def plot_crystal(self, crystal, sage: L = RootSystem(['A',2]).ambient_space() sage: C = crystals.Tableaux(['A',2], shape=[2,1]) - sage: L.plot_crystal(C, plot_labels='multiplicities') + sage: L.plot_crystal(C, plot_labels='multiplicities') # optional - sage.plot sage.symbolic Graphics object consisting of 15 graphics primitives sage: C = crystals.Tableaux(['A',2], shape=[8,4]) - sage: p = L.plot_crystal(C, plot_labels='circles') - sage: p.show(figsize=15) + sage: p = L.plot_crystal(C, plot_labels='circles') # optional - sage.plot sage.symbolic + sage: p.show(figsize=15) # optional - sage.plot sage.symbolic A 3-dimensional example:: sage: L = RootSystem(['B',3]).ambient_space() sage: C = crystals.Tableaux(['B',3], shape=[2,1]) - sage: L.plot_crystal(C, plot_labels='circles', edge_labels=True) # long time + sage: L.plot_crystal(C, plot_labels='circles', # long time # optional - sage.plot sage.symbolic + ....: edge_labels=True) Graphics3d Object TESTS: @@ -3232,7 +3234,8 @@ def dual_type_cospace(self): sage: CartanType(['B',2]).root_system().root_lattice().dual_type_cospace() Coroot lattice of the Root system of type ['C', 2] sage: CartanType(['F',4]).root_system().coweight_lattice().dual_type_cospace() - Weight lattice of the Root system of type ['F', 4] relabelled by {1: 4, 2: 3, 3: 2, 4: 1} + Weight lattice of the Root system of type ['F', 4] + relabelled by {1: 4, 2: 3, 3: 2, 4: 1} """ from .root_space import RootSpace @@ -3257,18 +3260,19 @@ def to_ambient_space_morphism(self): EXAMPLES:: - sage: CartanType(['B',2]).root_system().root_lattice().to_ambient_space_morphism() + sage: B2rs = CartanType(['B',2]).root_system() + sage: B2rs.root_lattice().to_ambient_space_morphism() Generic morphism: - From: Root lattice of the Root system of type ['B', 2] - To: Ambient space of the Root system of type ['B', 2] - sage: CartanType(['B',2]).root_system().coroot_lattice().to_ambient_space_morphism() + From: Root lattice of the Root system of type ['B', 2] + To: Ambient space of the Root system of type ['B', 2] + sage: B2rs.coroot_lattice().to_ambient_space_morphism() Generic morphism: - From: Coroot lattice of the Root system of type ['B', 2] - To: Ambient space of the Root system of type ['B', 2] - sage: CartanType(['B',2]).root_system().weight_lattice().to_ambient_space_morphism() + From: Coroot lattice of the Root system of type ['B', 2] + To: Ambient space of the Root system of type ['B', 2] + sage: B2rs.weight_lattice().to_ambient_space_morphism() Generic morphism: - From: Weight lattice of the Root system of type ['B', 2] - To: Ambient space of the Root system of type ['B', 2] + From: Weight lattice of the Root system of type ['B', 2] + To: Ambient space of the Root system of type ['B', 2] """ diff --git a/src/sage/combinat/root_system/root_system.py b/src/sage/combinat/root_system/root_system.py index fc84a35b4c1..039be92e684 100644 --- a/src/sage/combinat/root_system/root_system.py +++ b/src/sage/combinat/root_system/root_system.py @@ -218,7 +218,7 @@ class RootSystem(UniqueRepresentation, SageObject): We can also plot various components of the ambient spaces:: sage: L = RootSystem(['A',2]).ambient_space() - sage: L.plot() + sage: L.plot() # optional - sage.plot sage.symbolic Graphics object consisting of 13 graphics primitives For more on plotting, see :ref:`sage.combinat.root_system.plot`. diff --git a/src/sage/combinat/root_system/type_A.py b/src/sage/combinat/root_system/type_A.py index c1134668507..f3cb037d644 100644 --- a/src/sage/combinat/root_system/type_A.py +++ b/src/sage/combinat/root_system/type_A.py @@ -28,16 +28,16 @@ class AmbientSpace(ambient_space.AmbientSpace): sage: L = RootSystem(["A",2]).ambient_space() sage: e = L.basis() - sage: L._plot_projection(e[0]) + sage: L._plot_projection(e[0]) # optional - sage.symbolic (1/2, 989/1142) - sage: L._plot_projection(e[1]) + sage: L._plot_projection(e[1]) # optional - sage.symbolic (-1, 0) - sage: L._plot_projection(e[2]) + sage: L._plot_projection(e[2]) # optional - sage.symbolic (1/2, -989/1142) sage: L = RootSystem(["A",3]).ambient_space() sage: l = L.an_element(); l (2, 2, 3, 0) - sage: L._plot_projection(l) + sage: L._plot_projection(l) # optional - sage.symbolic (0, -1121/1189, 7/3) .. SEEALSO:: diff --git a/src/sage/combinat/root_system/type_G.py b/src/sage/combinat/root_system/type_G.py index ce953036dc1..8bc189ef756 100644 --- a/src/sage/combinat/root_system/type_G.py +++ b/src/sage/combinat/root_system/type_G.py @@ -34,16 +34,16 @@ class AmbientSpace(ambient_space.AmbientSpace): sage: L = RootSystem(["G",2]).ambient_space() sage: e = L.basis() - sage: L._plot_projection(e[0]) + sage: L._plot_projection(e[0]) # optional - sage.symbolic (1/2, 989/1142) - sage: L._plot_projection(e[1]) + sage: L._plot_projection(e[1]) # optional - sage.symbolic (-1, 0) - sage: L._plot_projection(e[2]) + sage: L._plot_projection(e[2]) # optional - sage.symbolic (1/2, -989/1142) sage: L = RootSystem(["A",3]).ambient_space() sage: l = L.an_element(); l (2, 2, 3, 0) - sage: L._plot_projection(l) + sage: L._plot_projection(l) # optional - sage.symbolic (0, -1121/1189, 7/3) .. SEEALSO:: diff --git a/src/sage/combinat/root_system/type_affine.py b/src/sage/combinat/root_system/type_affine.py index b24f2d2afa5..50caa62f259 100644 --- a/src/sage/combinat/root_system/type_affine.py +++ b/src/sage/combinat/root_system/type_affine.py @@ -405,24 +405,24 @@ def _plot_projection(self, x): sage: L = RootSystem(["B",2,1]).ambient_space() sage: e = L.basis() - sage: L._plot_projection(e[0]) + sage: L._plot_projection(e[0]) # optional - sage.symbolic (1, 0, 0) - sage: L._plot_projection(e[1]) + sage: L._plot_projection(e[1]) # optional - sage.symbolic (0, 1, 0) - sage: L._plot_projection(e["delta"]) + sage: L._plot_projection(e["delta"]) # optional - sage.symbolic (0, 0, 0) - sage: L._plot_projection(e["deltacheck"]) + sage: L._plot_projection(e["deltacheck"]) # optional - sage.symbolic (0, 0, 1) sage: L = RootSystem(["A",2,1]).ambient_space() sage: e = L.basis() - sage: L._plot_projection(e[0]) + sage: L._plot_projection(e[0]) # optional - sage.symbolic (1/2, 989/1142, 0) - sage: L._plot_projection(e[1]) + sage: L._plot_projection(e[1]) # optional - sage.symbolic (-1, 0, 0) - sage: L._plot_projection(e["delta"]) + sage: L._plot_projection(e["delta"]) # optional - sage.symbolic (0, 0, 0) - sage: L._plot_projection(e["deltacheck"]) + sage: L._plot_projection(e["deltacheck"]) # optional - sage.symbolic (0, 0, 1) """ from sage.modules.free_module_element import vector diff --git a/src/sage/combinat/rooted_tree.py b/src/sage/combinat/rooted_tree.py index fa260e70343..abb96594d2a 100644 --- a/src/sage/combinat/rooted_tree.py +++ b/src/sage/combinat/rooted_tree.py @@ -522,10 +522,10 @@ def __init__(self): """ TESTS:: - sage: sum(x**len(t) for t in - ....: set(RootedTree(t) for t in OrderedTrees(6))) + sage: sum(x**len(t) # optional - sage.symbolic + ....: for t in set(RootedTree(t) for t in OrderedTrees(6))) x^5 + x^4 + 3*x^3 + 6*x^2 + 9*x - sage: sum(x**len(t) for t in RootedTrees(6)) + sage: sum(x**len(t) for t in RootedTrees(6)) # optional - sage.symbolic x^5 + x^4 + 3*x^3 + 6*x^2 + 9*x sage: TestSuite(RootedTrees()).run() # long time diff --git a/src/sage/combinat/set_partition.py b/src/sage/combinat/set_partition.py index 6edf7d963da..fa95061a4df 100644 --- a/src/sage/combinat/set_partition.py +++ b/src/sage/combinat/set_partition.py @@ -1891,7 +1891,7 @@ def plot(self, angle=None, color='black', base_set_dict=None): EXAMPLES:: sage: p = SetPartition([[1,10,11],[2,3,7],[4,5,6],[8,9]]) - sage: p.plot() + sage: p.plot() # optional - sage.plot sage.symbolic Graphics object consisting of 29 graphics primitives .. PLOT:: @@ -1902,7 +1902,7 @@ def plot(self, angle=None, color='black', base_set_dict=None): :: sage: p = SetPartition([[1,3,4],[2,5]]) - sage: print(p.plot().description()) + sage: print(p.plot().description()) # optional - sage.plot sage.symbolic Point set defined by 1 point(s): [(0.0, 0.0)] Point set defined by 1 point(s): [(1.0, 0.0)] Point set defined by 1 point(s): [(2.0, 0.0)] @@ -1920,7 +1920,7 @@ def plot(self, angle=None, color='black', base_set_dict=None): Arc with center (2.5,-1.5) radii (2.1213203435...,2.1213203435...) angle 0.0 inside the sector (0.785398163397...,2.35619449019...) sage: p = SetPartition([['a','c'],['b','d'],['e']]) - sage: print(p.plot().description()) + sage: print(p.plot().description()) # optional - sage.plot sage.symbolic Point set defined by 1 point(s): [(0.0, 0.0)] Point set defined by 1 point(s): [(1.0, 0.0)] Point set defined by 1 point(s): [(2.0, 0.0)] @@ -1936,7 +1936,8 @@ def plot(self, angle=None, color='black', base_set_dict=None): Arc with center (2.0,-1.0) radii (1.41421356237...,1.41421356237...) angle 0.0 inside the sector (0.785398163397...,2.35619449019...) sage: p = SetPartition([['a','c'],['b','d'],['e']]) - sage: print(p.plot(base_set_dict={'a':0,'b':1,'c':2,'d':-2.3,'e':5.4}).description()) + sage: print(p.plot(base_set_dict={'a':0,'b':1,'c':2, # optional - sage.plot sage.symbolic + ....: 'd':-2.3,'e':5.4}).description()) Point set defined by 1 point(s): [(-2.3, 0.0)] Point set defined by 1 point(s): [(0.0, 0.0)] Point set defined by 1 point(s): [(1.0, 0.0)] diff --git a/src/sage/combinat/sf/elementary.py b/src/sage/combinat/sf/elementary.py index 8d242f55b84..a7e5d9cf44c 100644 --- a/src/sage/combinat/sf/elementary.py +++ b/src/sage/combinat/sf/elementary.py @@ -370,7 +370,7 @@ def principal_specialization(self, n=infinity, q=None): By default, we return a rational functions in `q`. Sometimes it is better to obtain an element of the symbolic ring:: - sage: x.principal_specialization(q=var("q")) + sage: x.principal_specialization(q=var("q")) # optional - sage.symbolic -3*q/((q^2 - 1)*(q - 1)^2) - 5/(q - 1)^3 + 1 TESTS:: @@ -468,7 +468,7 @@ def exponential_specialization(self, t=None, q=1): sage: x.exponential_specialization() 1/12*t^5 sage: x = 5*e[2] + 3*e[1] + 1 - sage: x.exponential_specialization(t=var("t"), q=var("q")) + sage: x.exponential_specialization(t=var("t"), q=var("q")) # optional - sage.symbolic 5*q*t^2/(q + 1) + 3*t + 1 TESTS:: diff --git a/src/sage/combinat/sf/homogeneous.py b/src/sage/combinat/sf/homogeneous.py index b97bfae074c..da55fef0426 100644 --- a/src/sage/combinat/sf/homogeneous.py +++ b/src/sage/combinat/sf/homogeneous.py @@ -280,7 +280,7 @@ def principal_specialization(self, n=infinity, q=None): sage: x.principal_specialization(3) q^6 + 2*q^5 + 4*q^4 + 4*q^3 + 4*q^2 + 2*q + 1 sage: x = 3*h[2] + 2*h[1] + 1 - sage: x.principal_specialization(3, q=var("q")) + sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic 2*(q^3 - 1)/(q - 1) + 3*(q^4 - 1)*(q^3 - 1)/((q^2 - 1)*(q - 1)) + 1 TESTS:: @@ -384,7 +384,7 @@ def exponential_specialization(self, t=None, q=1): We also support the `q`-exponential_specialization:: - sage: factor(h[3].exponential_specialization(q=var("q"), t=var("t"))) + sage: factor(h[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) TESTS:: diff --git a/src/sage/combinat/sf/monomial.py b/src/sage/combinat/sf/monomial.py index ea1b9da133d..588d8154add 100644 --- a/src/sage/combinat/sf/monomial.py +++ b/src/sage/combinat/sf/monomial.py @@ -365,7 +365,7 @@ def principal_specialization(self, n=infinity, q=None): q^7 + q^6 + q^5 + q^3 + q^2 + q sage: x = 5*m[2] + 3*m[1] + 1 - sage: x.principal_specialization(3, q=var("q")) + sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic -10*(q^3 - 1)*q/(q - 1) + 5*(q^3 - 1)^2/(q - 1)^2 + 3*(q^3 - 1)/(q - 1) + 1 TESTS:: @@ -451,7 +451,7 @@ def exponential_specialization(self, t=None, q=1): We also support the `q`-exponential_specialization:: - sage: factor(m[3].exponential_specialization(q=var("q"), t=var("t"))) + sage: factor(m[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic (q - 1)^2*t^3/(q^2 + q + 1) TESTS:: diff --git a/src/sage/combinat/sf/ns_macdonald.py b/src/sage/combinat/sf/ns_macdonald.py index 1013718d4b5..44075c054cf 100644 --- a/src/sage/combinat/sf/ns_macdonald.py +++ b/src/sage/combinat/sf/ns_macdonald.py @@ -533,8 +533,8 @@ def coeff(self, q, t): EXAMPLES:: sage: a = AugmentedLatticeDiagramFilling([[1,6],[2],[3,4,2],[],[],[5,5]]) - sage: q,t = var('q,t') - sage: a.coeff(q,t) + sage: q,t = var('q,t') # optional - sage.symbolic + sage: a.coeff(q,t) # optional - sage.symbolic (t - 1)^4/((q^2*t^3 - 1)^2*(q*t^2 - 1)^2) """ res = 1 @@ -554,8 +554,8 @@ def coeff_integral(self, q, t): EXAMPLES:: sage: a = AugmentedLatticeDiagramFilling([[1,6],[2],[3,4,2],[],[],[5,5]]) - sage: q,t = var('q,t') - sage: a.coeff_integral(q,t) + sage: q,t = var('q,t') # optional - sage.symbolic + sage: a.coeff_integral(q,t) # optional - sage.symbolic (q^2*t^3 - 1)^2*(q*t^2 - 1)^2*(t - 1)^4 """ res = 1 @@ -806,15 +806,15 @@ def _check_muqt(mu, q, t, pi=None): :: - sage: q,t = var('q,t') - sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,None) + sage: q,t = var('q,t') # optional - sage.symbolic + sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,None) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: you must specify either both q and t or neither of them :: - sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,2) + sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,2) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: the parents of q and t must be the same diff --git a/src/sage/combinat/sf/powersum.py b/src/sage/combinat/sf/powersum.py index 22a277b1ef8..fb9ecb31e91 100644 --- a/src/sage/combinat/sf/powersum.py +++ b/src/sage/combinat/sf/powersum.py @@ -760,11 +760,11 @@ def principal_specialization(self, n=infinity, q=None): sage: p = SymmetricFunctions(QQ).p() sage: x = p[8,7,3,1] - sage: x.principal_specialization(3, q=var("q")) + sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic (q^24 - 1)*(q^21 - 1)*(q^9 - 1)/((q^8 - 1)*(q^7 - 1)*(q - 1)) sage: x = 5*p[1,1,1] + 3*p[2,1] + 1 - sage: x.principal_specialization(3, q=var("q")) + sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic 5*(q^3 - 1)^3/(q - 1)^3 + 3*(q^6 - 1)*(q^3 - 1)/((q^2 - 1)*(q - 1)) + 1 By default, we return a rational function in `q`:: @@ -774,7 +774,7 @@ def principal_specialization(self, n=infinity, q=None): If ``n`` is not given we return the stable principal specialization:: - sage: x.principal_specialization(q=var("q")) + sage: x.principal_specialization(q=var("q")) # optional - sage.symbolic 3/((q^2 - 1)*(q - 1)) - 5/(q - 1)^3 + 1 TESTS:: @@ -881,12 +881,12 @@ def exponential_specialization(self, t=None, q=1): sage: x.exponential_specialization() 0 sage: x = p[3] + 5*p[1,1] + 2*p[1] + 1 - sage: x.exponential_specialization(t=var("t")) + sage: x.exponential_specialization(t=var("t")) # optional - sage.symbolic 5*t^2 + 2*t + 1 We also support the `q`-exponential_specialization:: - sage: factor(p[3].exponential_specialization(q=var("q"), t=var("t"))) + sage: factor(p[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic (q - 1)^2*t^3/(q^2 + q + 1) TESTS:: diff --git a/src/sage/combinat/sf/schur.py b/src/sage/combinat/sf/schur.py index 914d5aef8d6..202c31d7cee 100644 --- a/src/sage/combinat/sf/schur.py +++ b/src/sage/combinat/sf/schur.py @@ -661,10 +661,10 @@ def principal_specialization(self, n=infinity, q=None): q^4 + q^3 + 2*q^2 + q + 1 sage: x = 3*s[2,2] + 2*s[1] + 1 - sage: x.principal_specialization(3, q=var("q")) + sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic 3*(q^4 - 1)*(q^3 - 1)*q^2/((q^2 - 1)*(q - 1)) + 2*(q^3 - 1)/(q - 1) + 1 - sage: x.principal_specialization(q=var("q")) + sage: x.principal_specialization(q=var("q")) # optional - sage.symbolic -2/(q - 1) + 3*q^2/((q^3 - 1)*(q^2 - 1)^2*(q - 1)) + 1 TESTS:: @@ -805,7 +805,7 @@ def exponential_specialization(self, t=None, q=1): We also support the `q`-exponential_specialization:: - sage: factor(s[3].exponential_specialization(q=var("q"), t=var("t"))) + sage: factor(s[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) TESTS:: diff --git a/src/sage/combinat/species/structure.py b/src/sage/combinat/species/structure.py index 371d78eef9d..a4de6349c6d 100644 --- a/src/sage/combinat/species/structure.py +++ b/src/sage/combinat/species/structure.py @@ -12,11 +12,12 @@ Here we define this species using the default structures:: - sage: ball = species.SingletonSpecies(); o = var('o') + sage: ball = species.SingletonSpecies() sage: bar = species.EmptySetSpecies() sage: BB = CombinatorialSpecies() sage: BB.define(ball + ball*BB + ball*bar*BB) - sage: BB.isotypes([o]*3).list() + sage: o = var('o') # optional - sage.symbolic + sage: BB.isotypes([o]*3).list() # optional - sage.symbolic [o*(o*o), o*((o*{})*o), (o*{})*(o*o), (o*{})*((o*{})*o)] If we ignore the parentheses, we can read off that the integer diff --git a/src/sage/combinat/tutorial.py b/src/sage/combinat/tutorial.py index 6422d920378..904c7c3339c 100644 --- a/src/sage/combinat/tutorial.py +++ b/src/sage/combinat/tutorial.py @@ -275,37 +275,37 @@ introduce two variables, `C` and `z`, and we define the equation:: - sage: C, z = var('C,z') - sage: sys = [ C == z + C*C ] + sage: C, z = var('C,z') # optional - sage.symbolic + sage: sys = [ C == z + C*C ] # optional - sage.symbolic There are two solutions, which happen to have closed forms:: - sage: sol = solve(sys, C, solution_dict=True); sol + sage: sol = solve(sys, C, solution_dict=True); sol # optional - sage.symbolic [{C: -1/2*sqrt(-4*z + 1) + 1/2}, {C: 1/2*sqrt(-4*z + 1) + 1/2}] - sage: s0 = sol[0][C]; s1 = sol[1][C] + sage: s0 = sol[0][C]; s1 = sol[1][C] # optional - sage.symbolic and whose Taylor series begin as follows:: - sage: s0.series(z, 6) + sage: s0.series(z, 6) # optional - sage.symbolic 1*z + 1*z^2 + 2*z^3 + 5*z^4 + 14*z^5 + Order(z^6) - sage: s1.series(z, 6) + sage: s1.series(z, 6) # optional - sage.symbolic 1 + (-1)*z + (-1)*z^2 + (-2)*z^3 + (-5)*z^4 + (-14)*z^5 + Order(z^6) The second solution is clearly aberrant, while the first one gives the expected coefficients. Therefore, we set:: - sage: C = s0 + sage: C = s0 # optional - sage.symbolic We can now calculate the next terms:: - sage: C.series(z, 11) + sage: C.series(z, 11) # optional - sage.symbolic 1*z + 1*z^2 + 2*z^3 + 5*z^4 + 14*z^5 + 42*z^6 + 132*z^7 + 429*z^8 + 1430*z^9 + 4862*z^10 + Order(z^11) or calculate, more or less instantaneously, the 100-th coefficient:: - sage: C.series(z, 101).coefficient(z,100) + sage: C.series(z, 101).coefficient(z,100) # optional - sage.symbolic 227508830794229349661819540395688853956041682601541047340 It is unfortunate to have to recalculate everything if at some point we @@ -321,7 +321,7 @@ define by a recursive equation:: sage: C = L.undefined(valuation=1) - sage: C.define( z + C * C ) + sage: C.define(z + C * C) :: @@ -338,19 +338,19 @@ We now return to the closed form of `C(z)`:: - sage: z = var('z') - sage: C = s0; C + sage: z = var('z') # optional - sage.symbolic + sage: C = s0; C # optional - sage.symbolic -1/2*sqrt(-4*z + 1) + 1/2 The `n`-th coefficient in the Taylor series for `C(z)` being given by `\frac{1}{n!} C(z)^{(n)}(0)`, we look at the successive derivatives `C(z)^{(n)}(z)`:: - sage: derivative(C, z, 1) + sage: derivative(C, z, 1) # optional - sage.symbolic 1/sqrt(-4*z + 1) - sage: derivative(C, z, 2) + sage: derivative(C, z, 2) # optional - sage.symbolic 2/(-4*z + 1)^(3/2) - sage: derivative(C, z, 3) + sage: derivative(C, z, 3) # optional - sage.symbolic 12/(-4*z + 1)^(5/2) This suggests the existence of a simple explicit formula, which we will @@ -373,9 +373,9 @@ We check this:: - sage: n = var('n') - sage: c = 1/n*binomial(2*(n-1),n-1) - sage: [c.subs(n=k) for k in range(1, 11)] + sage: n = var('n') # optional - sage.symbolic + sage: c = 1/n*binomial(2*(n-1),n-1) # optional - sage.symbolic + sage: [c.subs(n=k) for k in range(1, 11)] # optional - sage.symbolic [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862] sage: [catalan_number(k-1) for k in range(1, 11)] [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862] @@ -383,14 +383,14 @@ We can now calculate coefficients much further; here we calculate `c_{100000}` which has more than `60000` digits:: - sage: cc = c(n = 100000) + sage: cc = c(n=100000) # optional - sage.symbolic This takes a couple of seconds:: - sage: %time cc = c(100000) # not tested + sage: %time cc = c(100000) # not tested # optional - sage.symbolic CPU times: user 2.34 s, sys: 0.00 s, total: 2.34 s Wall time: 2.34 s - sage: ZZ(cc).ndigits() + sage: ZZ(cc).ndigits() # optional - sage.symbolic 60198 The methods which we have used generalize to all recursively defined @@ -417,11 +417,11 @@ In the present case, `P=y^2-y+x`. We formally differentiate this equation with respect to `z`:: - sage: x, y, z = var('x, y, z') - sage: P = function('P')(x, y) - sage: C = function('C')(z) - sage: equation = P(x=z, y=C) == 0 - sage: diff(equation, z) + sage: x, y, z = var('x, y, z') # optional - sage.symbolic + sage: P = function('P')(x, y) # optional - sage.symbolic + sage: C = function('C')(z) # optional - sage.symbolic + sage: equation = P(x=z, y=C) == 0 # optional - sage.symbolic + sage: diff(equation, z) # optional - sage.symbolic diff(C(z), z)*D[1](P)(z, C(z)) + D[0](P)(z, C(z)) == 0 or, in a more readable format, @@ -434,9 +434,9 @@ In the case of complete binary trees, this gives:: - sage: P = y^2 - y + x - sage: Px = diff(P, x); Py = diff(P, y) - sage: - Px / Py + sage: P = y^2 - y + x # optional - sage.symbolic + sage: Px = diff(P, x); Py = diff(P, y) # optional - sage.symbolic + sage: - Px / Py # optional - sage.symbolic -1/(2*y - 1) Recall that `P(z, C(z))=0`. Thus, we can calculate this fraction @@ -476,7 +476,7 @@ sage: fraction = fraction.lift(); fraction (1/2/(x - 1/4))*y - 1/4/(x - 1/4) - sage: fraction(x=z, y=C) + sage: fraction(x=z, y=C) # optional - sage.symbolic 2*C(z)/(4*z - 1) - 1/(4*z - 1) or, more legibly, @@ -486,13 +486,13 @@ In this simple case, we can directly deduce from this expression a linear differential equation with coefficients in `\QQ[z]`:: - sage: equadiff = diff(C,z) == fraction(x=z, y=C) - sage: equadiff + sage: equadiff = diff(C,z) == fraction(x=z, y=C) # optional - sage.symbolic + sage: equadiff # optional - sage.symbolic diff(C(z), z) == 2*C(z)/(4*z - 1) - 1/(4*z - 1) - sage: equadiff = equadiff.simplify_rational() - sage: equadiff = equadiff * equadiff.rhs().denominator() - sage: equadiff = equadiff - equadiff.rhs() - sage: equadiff + sage: equadiff = equadiff.simplify_rational() # optional - sage.symbolic + sage: equadiff = equadiff * equadiff.rhs().denominator() # optional - sage.symbolic + sage: equadiff = equadiff - equadiff.rhs() # optional - sage.symbolic + sage: equadiff # optional - sage.symbolic (4*z - 1)*diff(C(z), z) - 2*C(z) + 1 == 0 or, more legibly, @@ -501,10 +501,10 @@ It is trivial to verify this equation on the closed form:: - sage: Cf = sage.symbolic.function_factory.function('C') - sage: equadiff.substitute_function(Cf, s0.function(z)) + sage: Cf = sage.symbolic.function_factory.function('C') # optional - sage.symbolic + sage: equadiff.substitute_function(Cf, s0.function(z)) # optional - sage.symbolic (4*z - 1)/sqrt(-4*z + 1) + sqrt(-4*z + 1) == 0 - sage: bool(equadiff.substitute_function(Cf, s0.function(z))) + sage: bool(equadiff.substitute_function(Cf, s0.function(z))) # optional - sage.symbolic True .. On veut non seulement remplacer les occurrences de C(z), mais @@ -774,14 +774,14 @@ formula. We look at the number of compositions of `n` ranging from `0` to `9`:: - sage: [ Compositions(n).cardinality() for n in range(10) ] + sage: [Compositions(n).cardinality() for n in range(10)] [1, 1, 2, 4, 8, 16, 32, 64, 128, 256] Similarly, if we consider the number of compositions of `5` by length, we find a line of Pascal’s triangle:: - sage: x = var('x') - sage: sum( x^len(c) for c in C5 ) + sage: x = var('x') # optional - sage.symbolic + sage: sum(x^len(c) for c in C5) # optional - sage.symbolic x^5 + 4*x^4 + 6*x^3 + 4*x^2 + x The above example uses a functionality which we have not seen yet: @@ -893,8 +893,8 @@ or the algebra of `2\times 2` matrices over the finite field `\ZZ/2\ZZ`:: - sage: C = MatrixSpace(GF(2), 2) - sage: C.list() + sage: C = MatrixSpace(GF(2), 2) # optional - sage.modules sage.rings.finite_rings + sage: C.list() # optional - sage.modules sage.rings.finite_rings [ [0 0] [1 0] [0 1] [0 0] [0 0] [1 1] [1 0] [1 0] [0 1] [0 1] [0 0], [0 0], [0 0], [1 0], [0 1], [0 0], [1 0], [0 1], [1 0], [0 1], @@ -902,7 +902,7 @@ [0 0] [1 1] [1 1] [1 0] [0 1] [1 1] [1 1], [1 0], [0 1], [1 1], [1 1], [1 1] ] - sage: C.cardinality() + sage: C.cardinality() # optional - sage.modules sage.rings.finite_rings 16 .. topic:: Exercise @@ -1146,24 +1146,24 @@ :: - sage: x = var('x') - sage: sum( x^len(s) for s in Subsets(8) ) + sage: x = var('x') # optional - sage.symbolic + sage: sum(x^len(s) for s in Subsets(8)) # optional - sage.symbolic x^8 + 8*x^7 + 28*x^6 + 56*x^5 + 70*x^4 + 56*x^3 + 28*x^2 + 8*x + 1 :: - sage: sum( x^p.length() for p in Permutations(3) ) + sage: sum(x^p.length() for p in Permutations(3)) # optional - sage.symbolic x^3 + 2*x^2 + 2*x + 1 :: - sage: factor(sum( x^p.length() for p in Permutations(3) )) + sage: factor(sum(x^p.length() for p in Permutations(3))) # optional - sage.symbolic (x^2 + x + 1)*(x + 1) :: sage: P = Permutations(5) - sage: all( p in P for p in P ) + sage: all(p in P for p in P) True :: @@ -1238,7 +1238,7 @@ ^^^^^^^^^^^^^^^^^^^^^^^ ``Python`` provides numerous tools for manipulating iterators; most of them -are in the ``itertools`` library, which can be imported by:: +are in the :mod:`itertools` library, which can be imported by:: sage: import itertools @@ -1375,15 +1375,15 @@ to define a formal variable ``Leaf`` for the leaves and a formal 2-ary function ``Node``:: - sage: var('Leaf') + sage: var('Leaf') # optional - sage.symbolic Leaf - sage: function('Node', nargs=2) + sage: function('Node', nargs=2) # optional - sage.symbolic Node The second tree in :ref:`figure-examples-catalan-trees` can be represented by the expression:: - sage: tr = Node(Node(Leaf, Node(Leaf, Leaf)), Leaf) + sage: tr = Node(Node(Leaf, Node(Leaf, Leaf)), Leaf) # optional - sage.symbolic .. _section-constructions: @@ -1666,7 +1666,7 @@ combinatorial species:: sage: from sage.combinat.species.library import * - sage: o = var('o') + sage: o = var('o') # optional - sage.symbolic We begin by redefining the complete binary trees; to do so, we stipulate the recurrence relation directly on the sets:: @@ -1678,10 +1678,10 @@ Now we can construct the set of trees with five nodes, list them, count them...:: - sage: BT5 = BT.isotypes([o]*5) - sage: BT5.cardinality() + sage: BT5 = BT.isotypes([o]*5) # optional - sage.symbolic + sage: BT5.cardinality() # optional - sage.symbolic 14 - sage: BT5.list() + sage: BT5.list() # optional - sage.symbolic [o*(o*(o*(o*o))), o*(o*((o*o)*o)), o*((o*o)*(o*o)), o*((o*(o*o))*o), o*(((o*o)*o)*o), (o*o)*(o*(o*o)), (o*o)*((o*o)*o), (o*(o*o))*(o*o), ((o*o)*o)*(o*o), @@ -1730,8 +1730,8 @@ :: - sage: FW3 = FW.isotypes([o]*3) - sage: FW3.list() + sage: FW3 = FW.isotypes([o]*3) # optional - sage.symbolic + sage: FW3.list() # optional - sage.symbolic [o*(o*(o*{})), o*(o*(({}*o)*{})), o*((({}*o)*o)*{}), (({}*o)*o)*(o*{}), (({}*o)*o)*(({}*o)*{})] @@ -1819,7 +1819,7 @@ them, exactly the same algorithm can be used, selecting only the children which are planar:: - sage: [len(list(graphs(n, property = lambda G: G.is_planar()))) + sage: [len(list(graphs(n, property=lambda G: G.is_planar()))) ....: for n in range(7)] [1, 1, 2, 4, 11, 33, 142] diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index d1aeb7c5b8a..ab639164b5a 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -1461,16 +1461,16 @@ def topological_entropy(self, n): sage: W = Words([0, 1]) sage: w = W([0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1]) - sage: t = w.topological_entropy(3); t + sage: t = w.topological_entropy(3); t # optional - sage.symbolic 1/3*log(7)/log(2) - sage: n(t) + sage: n(t) # optional - sage.symbolic 0.935784974019201 :: sage: w = words.ThueMorseWord()[:100] sage: topo = w.topological_entropy - sage: for i in range(0, 41, 5): + sage: for i in range(0, 41, 5): # optional - sage.symbolic ....: print("{} {}".format(i, n(topo(i), digits=5))) 0 1.0000 5 0.71699 @@ -1494,7 +1494,7 @@ def topological_entropy(self, n): sage: W = Words(range(20)) sage: w = W(range(20)) - sage: w.topological_entropy(3) + sage: w.topological_entropy(3) # optional - sage.symbolic 1/3*log(18)/log(20) """ d = self.parent().alphabet().cardinality() diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index 9c42e379cd4..07b504b2a78 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -540,9 +540,9 @@ def FibonacciWord(self, alphabet=(0, 1), construction_method="recursive"): :: - sage: words.FibonacciWord([0,1], 'function') + sage: words.FibonacciWord([0,1], 'function') # optional - sage.symbolic word: 0100101001001010010100100101001001010010... - sage: words.FibonacciWord('ab', 'function') + sage: words.FibonacciWord('ab', 'function') # optional - sage.symbolic word: abaababaabaababaababaabaababaabaababaaba... TESTS:: @@ -555,7 +555,7 @@ def FibonacciWord(self, alphabet=(0, 1), construction_method="recursive"): word: 0100101001001010010100100101001001010010... sage: f[:10000] == w[:10000] True - sage: f[:10000] == u[:10000] #long time + sage: f[:10000] == u[:10000] #long time True sage: words.FibonacciWord("abc") Traceback (most recent call last): @@ -745,17 +745,17 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): INPUT: - - ``slope`` - the slope of the word. It can be one of the following: + - ``slope`` -- the slope of the word. It can be one of the following: - real number in `]0, 1[` - iterable over the continued fraction expansion of a real number in `]0, 1[` - - ``alphabet`` - any container of length two that is suitable to + - ``alphabet`` -- any container of length two that is suitable to build an instance of OrderedAlphabet (list, tuple, str, ...) - - ``bits`` - integer (optional and considered only if ``slope`` is + - ``bits`` -- integer (optional and considered only if ``slope`` is a real number) the number of bits to consider when computing the continued fraction. @@ -774,7 +774,7 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): From real slope:: - sage: words.CharacteristicSturmianWord(1/golden_ratio^2) + sage: words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic word: 0100101001001010010100100101001001010010... sage: words.CharacteristicSturmianWord(4/5) word: 11110 @@ -927,19 +927,19 @@ def _CharacteristicSturmianWord_LetterIterator(self, cf, alphabet=(0,1)): EXAMPLES:: - sage: continued_fraction(1/golden_ratio^2)[:8] + sage: continued_fraction(1/golden_ratio^2)[:8] # optional - sage.symbolic [0; 2, 1, 1, 1, 1, 2] - sage: cf = iter(_) - sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) + sage: cf = iter(_) # optional - sage.symbolic + sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) # optional - sage.symbolic word: 0100101001001010010100100101001010 :: - sage: alpha = (sqrt(3)-1)/2 - sage: continued_fraction(alpha)[:10] + sage: alpha = (sqrt(3)-1)/2 # optional - sage.symbolic + sage: continued_fraction(alpha)[:10] # optional - sage.symbolic [0; 2, 1, 2, 1, 2, 1, 2, 1, 2] - sage: cf = iter(_) - sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) + sage: cf = iter(_) # optional - sage.symbolic + sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) # optional - sage.symbolic word: 0100100101001001001010010010010100100101... """ try: @@ -1133,23 +1133,23 @@ def LowerMechanicalWord(self, alpha, rho=0, alphabet=None): EXAMPLES:: - sage: words.LowerMechanicalWord(1/golden_ratio^2) + sage: words.LowerMechanicalWord(1/golden_ratio^2) # optional - sage.symbolic word: 0010010100100101001010010010100100101001... - sage: words.LowerMechanicalWord(1/5) + sage: words.LowerMechanicalWord(1/5) # optional - sage.symbolic word: 0000100001000010000100001000010000100001... - sage: words.LowerMechanicalWord(1/pi) + sage: words.LowerMechanicalWord(1/pi) # optional - sage.symbolic word: 0001001001001001001001000100100100100100... TESTS:: - sage: m = words.LowerMechanicalWord(1/golden_ratio^2)[1:] - sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) - sage: m[:500] == s[:500] + sage: m = words.LowerMechanicalWord(1/golden_ratio^2)[1:] # optional - sage.symbolic + sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic + sage: m[:500] == s[:500] # optional - sage.symbolic True Check that this returns a word in an alphabet (:trac:`10054`):: - sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() + sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() # optional - sage.symbolic Infinite words over {0, 1} """ if not 0 <= alpha <= 1: @@ -1193,23 +1193,23 @@ def UpperMechanicalWord(self, alpha, rho=0, alphabet=None): EXAMPLES:: - sage: words.UpperMechanicalWord(1/golden_ratio^2) + sage: words.UpperMechanicalWord(1/golden_ratio^2) # optional - sage.symbolic word: 1010010100100101001010010010100100101001... - sage: words.UpperMechanicalWord(1/5) + sage: words.UpperMechanicalWord(1/5) # optional - sage.symbolic word: 1000010000100001000010000100001000010000... - sage: words.UpperMechanicalWord(1/pi) + sage: words.UpperMechanicalWord(1/pi) # optional - sage.symbolic word: 1001001001001001001001000100100100100100... TESTS:: - sage: m = words.UpperMechanicalWord(1/golden_ratio^2)[1:] - sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) - sage: m[:500] == s[:500] + sage: m = words.UpperMechanicalWord(1/golden_ratio^2)[1:] # optional - sage.symbolic + sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic + sage: m[:500] == s[:500] # optional - sage.symbolic True Check that this returns a word in an alphabet (:trac:`10054`):: - sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() + sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() # optional - sage.symbolic Infinite words over {0, 1} """ if not 0 <= alpha <= 1: From 672a986a6648c9f4cb84e2cad409c5f5cc67bb2b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 15 May 2023 13:39:01 -0700 Subject: [PATCH 06/26] sage.combinat: Add # optional --- .../cluster_algebra_quiver/cluster_seed.py | 4 +- src/sage/combinat/k_regular_sequence.py | 242 +++++++++--------- src/sage/combinat/parallelogram_polyomino.py | 28 +- src/sage/combinat/partition.py | 2 +- src/sage/combinat/path_tableaux/frieze.py | 2 + src/sage/combinat/plane_partition.py | 3 +- src/sage/combinat/root_system/plot.py | 155 +++++------ .../root_system/reflection_group_complex.py | 2 +- .../root_system/root_lattice_realizations.py | 12 +- src/sage/combinat/sf/sfa.py | 12 +- src/sage/combinat/six_vertex_model.py | 2 +- src/sage/combinat/words/alphabet.py | 6 +- src/sage/combinat/words/word_generators.py | 2 +- 13 files changed, 242 insertions(+), 230 deletions(-) diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index 31eac5999df..8f8a2a9fb3c 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -124,7 +124,7 @@ class ClusterSeed(SageObject): ....: frozen=['c']); S A seed for a cluster algebra of rank 4 with 1 frozen variable - sage: S = ClusterSeed(['D', 4],user_labels = [-1, 0, 1, 2]); S + sage: S = ClusterSeed(['D', 4], user_labels=[-1, 0, 1, 2]); S A seed for a cluster algebra of rank 4 of type ['D', 4] """ @@ -3019,7 +3019,7 @@ def universal_extension(self): [ 0 1] [ 0 -1] - sage: S = ClusterSeed(['A', 5], user_labels = [-2, -1, 0, 1 ,2]) + sage: S = ClusterSeed(['A', 5], user_labels=[-2, -1, 0, 1 ,2]) sage: U = S.universal_extension() sage: U.b_matrix() == ClusterSeed(['A', 5]).universal_extension().b_matrix() True diff --git a/src/sage/combinat/k_regular_sequence.py b/src/sage/combinat/k_regular_sequence.py index 596b6adb2a7..5b5f2398cc0 100644 --- a/src/sage/combinat/k_regular_sequence.py +++ b/src/sage/combinat/k_regular_sequence.py @@ -330,17 +330,17 @@ def subsequence(self, a, b): We check if the linear representation of the subsequences above indeed represent the correct vector valued sequences:: - sage: var('n') + sage: var('n') # optional - sage.symbolic n sage: def v(n): ....: return vector([3*n + 1, 6*n + 1]) - sage: S31.mu[0] * v(n) == v(2*n) + sage: S31.mu[0] * v(n) == v(2*n) # optional - sage.symbolic True - sage: S31.mu[1] * v(n) == v(2*n + 1) + sage: S31.mu[1] * v(n) == v(2*n + 1) # optional - sage.symbolic True - sage: function('delta_0') + sage: function('delta_0') # optional - sage.symbolic delta_0 sage: def simplify_delta(expr): @@ -348,17 +348,17 @@ def subsequence(self, a, b): sage: def v(n): ....: return vector([n -1 + delta_0(n), 2*n - 1 + delta_0(n), 4*n + 1]) - sage: simplify_delta(v(2*n) - Srs.mu[0]*v(n)).is_zero() + sage: simplify_delta(v(2*n) - Srs.mu[0]*v(n)).is_zero() # optional - sage.symbolic True - sage: simplify_delta(v(2*n + 1) - Srs.mu[1]*v(n)).is_zero() + sage: simplify_delta(v(2*n + 1) - Srs.mu[1]*v(n)).is_zero() # optional - sage.symbolic True sage: def v(n): ....: return vector([1 - delta_0(n), 1]) - sage: simplify_delta(v(2*n) - Sbd.mu[0]*v(n)).is_zero() + sage: simplify_delta(v(2*n) - Sbd.mu[0]*v(n)).is_zero() # optional - sage.symbolic True - sage: simplify_delta(v(2*n + 1) - Sbd.mu[1]*v(n)).is_zero() + sage: simplify_delta(v(2*n + 1) - Sbd.mu[1]*v(n)).is_zero() # optional - sage.symbolic True We check some corner-cases:: @@ -933,11 +933,11 @@ def from_recurrence(self, *args, **kwds): :: sage: Seq2 = kRegularSequenceSpace(2, ZZ) - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: Seq2.from_recurrence([ + sage: Seq2.from_recurrence([ # optional - sage.symbolic ....: f(2*n) == 2*f(n), f(2*n + 1) == 3*f(n) + 4*f(n - 1), ....: f(0) == 0, f(1) == 1], f, n) 2-regular sequence 0, 0, 0, 1, 2, 3, 4, 10, 6, 17, ... @@ -1021,26 +1021,26 @@ def from_recurrence(self, *args, **kwds): Stern--Brocot Sequence:: sage: Seq2 = kRegularSequenceSpace(2, ZZ) - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: SB = Seq2.from_recurrence([ + sage: SB = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], f, n) - sage: SB + sage: SB # optional - sage.symbolic 2-regular sequence 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, ... Number of Odd Entries in Pascal's Triangle:: - sage: Seq2.from_recurrence([ + sage: Seq2.from_recurrence([ # optional - sage.symbolic ....: f(2*n) == 3*f(n), f(2*n + 1) == 2*f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], f, n) 2-regular sequence 0, 1, 3, 5, 9, 11, 15, 19, 27, 29, ... Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: UB = Seq2.from_recurrence([ + sage: UB = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -1054,20 +1054,20 @@ def from_recurrence(self, *args, **kwds): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3) - sage: UB + sage: UB # optional - sage.symbolic 2-regular sequence 1, 2, 2, 4, 2, 4, 6, 0, 4, 4, ... Binary sum of digits `S(n)`, characterized by the recurrence relations `S(4n) = S(2n)`, `S(4n + 1) = S(2n + 1)`, `S(4n + 2) = S(2n + 1)` and `S(4n + 3) = -S(2n) + 2S(2n + 1)`:: - sage: S = Seq2.from_recurrence([ + sage: S = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n + 1), ....: f(4*n + 2) == f(2*n + 1), ....: f(4*n + 3) == -f(2*n) + 2*f(2*n + 1), ....: f(0) == 0, f(1) == 1], f, n) - sage: S + sage: S # optional - sage.symbolic 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ... In order to check if this sequence is indeed the binary sum of digits, @@ -1077,7 +1077,7 @@ def from_recurrence(self, *args, **kwds): sage: S2 = Seq2( ....: (Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [1, 1]])), ....: left=vector([0, 1]), right=vector([1, 0])) - sage: (S - S2).is_trivial_zero() + sage: (S - S2).is_trivial_zero() # optional - sage.symbolic True Alternatively, we can also use the simpler but inhomogeneous recurrence relations @@ -1095,13 +1095,13 @@ def from_recurrence(self, *args, **kwds): Number of Non-Zero Elements in the Generalized Pascal's Triangle (see [LRS2017]_):: sage: Seq2 = kRegularSequenceSpace(2, QQ) - sage: P = Seq2.from_recurrence([ + sage: P = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(4*n) == 5/3*f(2*n) - 1/3*f(2*n + 1), ....: f(4*n + 1) == 4/3*f(2*n) + 1/3*f(2*n + 1), ....: f(4*n + 2) == 1/3*f(2*n) + 4/3*f(2*n + 1), ....: f(4*n + 3) == -1/3*f(2*n) + 5/3*f(2*n + 1), ....: f(0) == 1, f(1) == 2], f, n) - sage: P + sage: P # optional - sage.symbolic 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ... Finally, the same sequence can also be obtained via direct parameters @@ -1117,7 +1117,7 @@ def from_recurrence(self, *args, **kwds): TESTS:: - sage: Seq2.from_recurrence([ # long time + sage: Seq2.from_recurrence([ # long time # optional - sage.symbolic ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n), ....: f(4*n + 2) == f(2*n), @@ -1129,7 +1129,7 @@ def from_recurrence(self, *args, **kwds): :: - sage: S = Seq2.from_recurrence([ + sage: S = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n), ....: f(4*n + 2) == f(2*n), @@ -1138,7 +1138,7 @@ def from_recurrence(self, *args, **kwds): ....: f(5) == 5, f(6) == 6, f(7) == 7, f(16) == 4, f(18) == 4, ....: f(20) == 4, f(22) == 4, f(24) == 6, f(26) == 6, f(28) == 6], ....: f, n, offset=2) - sage: all([S[4*i] == S[2*i] and + sage: all([S[4*i] == S[2*i] and # optional - sage.symbolic ....: S[4*i + 1] == S[2*i] and ....: S[4*i + 2] == S[2*i] and ....: S[4*i + 3] == S[2*i + 16] for i in srange(2, 100)]) @@ -1146,7 +1146,7 @@ def from_recurrence(self, *args, **kwds): :: - sage: S = Seq2.from_recurrence([ + sage: S = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n), ....: f(4*n + 2) == f(2*n), @@ -1159,7 +1159,7 @@ def from_recurrence(self, *args, **kwds): ....: f(22) == 22, f(23) == 23, f(24) == 24, f(25) == 25, ....: f(26) == 26, f(27) == 27, f(28) == 28, f(29) == 29, ....: f(30) == 30, f(31) == 31], f, n, offset=8) - sage: all([S[4*i] == S[2*i] and + sage: all([S[4*i] == S[2*i] and # optional - sage.symbolic ....: S[4*i + 1] == S[2*i] and ....: S[4*i + 2] == S[2*i] and ....: S[4*i + 3] == S[2*i - 16] for i in srange(8, 100)]) @@ -1167,11 +1167,11 @@ def from_recurrence(self, *args, **kwds): Same test with different variable and function names:: - sage: var('m') + sage: var('m') # optional - sage.symbolic m - sage: function('g') + sage: function('g') # optional - sage.symbolic g - sage: T = Seq2.from_recurrence([ + sage: T = Seq2.from_recurrence([ # optional - sage.symbolic ....: g(4*m) == g(2*m), ....: g(4*m + 1) == g(2*m), ....: g(4*m + 2) == g(2*m), @@ -1184,12 +1184,12 @@ def from_recurrence(self, *args, **kwds): ....: g(22) == 22, g(23) == 23, g(24) == 24, g(25) == 25, ....: g(26) == 26, g(27) == 27, g(28) == 28, g(29) == 29, ....: g(30) == 30, g(31) == 31], g, m, offset=8) - sage: (S - T).is_trivial_zero() # long time + sage: (S - T).is_trivial_zero() # long time # optional - sage.symbolic True Zero-sequence with non-zero initial values:: - sage: Seq2.from_recurrence([ + sage: Seq2.from_recurrence([ # optional - sage.symbolic ....: f(2*n) == 0, f(2*n + 1) == 0, ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n) Traceback (most recent call last): @@ -1198,14 +1198,14 @@ def from_recurrence(self, *args, **kwds): :: - sage: Seq2.from_recurrence([ + sage: Seq2.from_recurrence([ # optional - sage.symbolic ....: f(2*n) == 0, f(2*n + 1) == 0, ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n, offset=2) 2-regular sequence 1, 1, 2, 3, 0, 0, 0, 0, 0, 0, ... Check if inhomogeneities `0` do not change the sequence:: - sage: Seq2.from_recurrence([ + sage: Seq2.from_recurrence([ # optional - sage.symbolic ....: f(2*n) == 0, f(2*n + 1) == 0, ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n, offset=2, ....: inhomogeneities={0: 0, 1: Seq2.zero()}) @@ -1247,7 +1247,7 @@ def from_recurrence(self, *args, **kwds): Number of Unbordered Factors in the Thue--Morse Sequence, but partly encoded with inhomogeneities:: - sage: UB2 = Seq2.from_recurrence([ + sage: UB2 = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1), @@ -1263,7 +1263,7 @@ def from_recurrence(self, *args, **kwds): ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3, ....: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1), ....: 6: UB.subsequence(4, 2) + UB.subsequence(4, 3)}) - sage: (UB2 - Seq2(UB)).is_trivial_zero() + sage: (UB2 - Seq2(UB)).is_trivial_zero() # optional - sage.symbolic True """ RP = RecurrenceParser(self.k, self.coefficient_ring()) @@ -1324,11 +1324,11 @@ def parse_recurrence(self, equations, function, var): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: RP.parse_recurrence([ + sage: RP.parse_recurrence([ # optional - sage.symbolic ....: f(4*n) == f(2*n) + 2*f(2*n + 1) + 3*f(2*n - 2), ....: f(4*n + 1) == 4*f(2*n) + 5*f(2*n + 1) + 6*f(2*n - 2), ....: f(4*n + 2) == 7*f(2*n) + 8*f(2*n + 1) + 9*f(2*n - 2), @@ -1340,7 +1340,7 @@ def parse_recurrence(self, equations, function, var): Stern--Brocot Sequence:: - sage: RP.parse_recurrence([ + sage: RP.parse_recurrence([ # optional - sage.symbolic ....: f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], f, n) (1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, {0: 0, 1: 1}) @@ -1353,28 +1353,28 @@ def parse_recurrence(self, equations, function, var): The following tests check that the equations are well-formed:: - sage: RP.parse_recurrence([], f, n) + sage: RP.parse_recurrence([], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: List of recurrence equations is empty. :: - sage: RP.parse_recurrence([f(4*n + 1)], f, n) + sage: RP.parse_recurrence([f(4*n + 1)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: f(4*n + 1) is not an equation with ==. :: - sage: RP.parse_recurrence([42], f, n) + sage: RP.parse_recurrence([42], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: 42 is not a symbolic expression. :: - sage: RP.parse_recurrence([f(2*n) + 1 == f(n)], f, n) + sage: RP.parse_recurrence([f(2*n) + 1 == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(2*n) + 1 in the equation f(2*n) + 1 == f(n) is @@ -1382,7 +1382,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n, 5) == 3], f, n) + sage: RP.parse_recurrence([f(2*n, 5) == 3], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(2*n, 5) in the equation f(2*n, 5) == 3 does not @@ -1390,7 +1390,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f() == 3], f, n) + sage: RP.parse_recurrence([f() == 3], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f() in the equation f() == 3 does not have one @@ -1398,7 +1398,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(1/n + 1) == f(n)], f, n) + sage: RP.parse_recurrence([f(1/n + 1) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(1/n + 1) in the equation f(1/n + 1) == f(n): @@ -1406,7 +1406,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n + 1/2) == f(n)], f, n) + sage: RP.parse_recurrence([f(2*n + 1/2) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(2*n + 1/2) in the equation f(2*n + 1/2) == f(n): @@ -1414,7 +1414,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n^2) == f(2*n^2)], f, n) + sage: RP.parse_recurrence([f(4*n^2) == f(2*n^2)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(4*n^2) in the equation f(4*n^2) == f(2*n^2): @@ -1422,7 +1422,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(42) == 1/2], f, n) + sage: RP.parse_recurrence([f(42) == 1/2], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Initial value 1/2 given by the equation f(42) == (1/2) @@ -1430,14 +1430,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(42) == 0, f(42) == 1], f, n) + sage: RP.parse_recurrence([f(42) == 0, f(42) == 1], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Initial value f(42) is given twice. :: - sage: RP.parse_recurrence([f(42) == f(n)], f, n) + sage: RP.parse_recurrence([f(42) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Initial value f(n) given by the equation f(42) == f(n) @@ -1445,7 +1445,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(n), f(2*n) == f(n)], f, n) + sage: RP.parse_recurrence([f(4*n) == f(n), f(2*n) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(2*n) in the equation f(2*n) == f(n): 2 does not @@ -1454,7 +1454,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(3*n + 1) == f(n)], f, n) + sage: RP.parse_recurrence([f(3*n + 1) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(3*n + 1) in the equation f(3*n + 1) == f(n): @@ -1462,7 +1462,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(n + 1) == f(n)], f, n) + sage: RP.parse_recurrence([f(n + 1) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(n + 1) in the equation f(n + 1) == f(n): @@ -1470,14 +1470,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n), f(2*n) == 0], f, n) + sage: RP.parse_recurrence([f(2*n) == f(n), f(2*n) == 0], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: There are more than one recurrence relation for f(2*n). :: - sage: RP.parse_recurrence([f(2*n + 2) == f(n)], f, n) + sage: RP.parse_recurrence([f(2*n + 2) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(2*n + 2) in the equation f(2*n + 2) == f(n): @@ -1485,7 +1485,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n - 1) == f(n)], f, n) + sage: RP.parse_recurrence([f(2*n - 1) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(2*n - 1) in the equation f(2*n - 1) == f(n): @@ -1493,7 +1493,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 2*n], f, n) + sage: RP.parse_recurrence([f(2*n) == 2*n], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term 2*n in the equation f(2*n) == 2*n does not @@ -1501,7 +1501,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 1/2*f(n)], f, n) + sage: RP.parse_recurrence([f(2*n) == 1/2*f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term 1/2*f(n) in the equation f(2*n) == 1/2*f(n): @@ -1509,21 +1509,21 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 1/f(n)], f, n) + sage: RP.parse_recurrence([f(2*n) == 1/f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: 1/f(n) is not a valid right hand side. :: - sage: RP.parse_recurrence([f(2*n) == 2*n*f(n)], f, n) + sage: RP.parse_recurrence([f(2*n) == 2*n*f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: 2*n*f(n) is not a valid right hand side. :: - sage: RP.parse_recurrence([f(2*n) == 2*f(n, 5)], f, n) + sage: RP.parse_recurrence([f(2*n) == 2*f(n, 5)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(n, 5) in the equation f(2*n) == 2*f(n, 5) @@ -1531,14 +1531,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 2*f()], f, n) + sage: RP.parse_recurrence([f(2*n) == 2*f()], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f() in the equation f(2*n) == 2*f() has no argument. :: - sage: RP.parse_recurrence([f(2*n) == 1/f(n) + 2*f(n)], f, n) + sage: RP.parse_recurrence([f(2*n) == 1/f(n) + 2*f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term 1/f(n) in the equation f(2*n) == 1/f(n) + 2*f(n) @@ -1546,7 +1546,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 2*f(1/n)], f, n) + sage: RP.parse_recurrence([f(2*n) == 2*f(1/n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(1/n) in the equation f(2*n) == 2*f(1/n): @@ -1554,7 +1554,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n + 1/2)], f, n) + sage: RP.parse_recurrence([f(2*n) == f(n + 1/2)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(n + 1/2) in the equation f(2*n) == f(n + 1/2): @@ -1562,7 +1562,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(1/2*n)], f, n) + sage: RP.parse_recurrence([f(2*n) == f(1/2*n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(1/2*n) in the equation f(2*n) == f(1/2*n): @@ -1570,7 +1570,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n^2 + 1)], f, n) + sage: RP.parse_recurrence([f(2*n) == f(n^2 + 1)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(n^2 + 1) in the equation f(2*n) == f(n^2 + 1): @@ -1578,7 +1578,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(1)], f, n) + sage: RP.parse_recurrence([f(2*n) == f(1)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(1) in the equation f(2*n) == f(1): @@ -1586,7 +1586,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(2*n) + f(n)], f, n) + sage: RP.parse_recurrence([f(4*n) == f(2*n) + f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(n) in the equation f(4*n) == f(2*n) + f(n): @@ -1595,7 +1595,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(2*n), f(4*n + 1) == f(n)], + sage: RP.parse_recurrence([f(4*n) == f(2*n), f(4*n + 1) == f(n)], # optional - sage.symbolic ....: f, n) Traceback (most recent call last): ... @@ -1605,7 +1605,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(3*n)], f, n) + sage: RP.parse_recurrence([f(4*n) == f(3*n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(3*n) in the equation f(4*n) == f(3*n): 3 is not @@ -1613,7 +1613,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(4*n)], f, n) + sage: RP.parse_recurrence([f(2*n) == f(4*n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(4*n) in the equation f(2*n) == f(4*n): @@ -1621,7 +1621,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(2*n)], f, n) + sage: RP.parse_recurrence([f(2*n) == f(2*n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Term f(2*n) in the equation f(2*n) == f(2*n): @@ -1629,14 +1629,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n)], f, n) + sage: RP.parse_recurrence([f(2*n) == f(n)], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Recurrence relations for [f(2*n + 1)] are missing. :: - sage: RP.parse_recurrence([f(4*n) == f(n), f(4*n + 3) == 0], f, n) + sage: RP.parse_recurrence([f(4*n) == f(n), f(4*n + 3) == 0], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Recurrence relations for [f(4*n + 1), f(4*n + 2)] @@ -1644,20 +1644,20 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(42) == 0], f, n) + sage: RP.parse_recurrence([f(42) == 0], f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: No recurrence relations are given. :: - sage: RP.parse_recurrence( + sage: RP.parse_recurrence( # optional - sage.symbolic ....: [f(4*n + r) == f(n) for r in srange(4)], f, n) (2, 0, {(0, 0): 1, (1, 0): 1, (2, 0): 1, (3, 0): 1}, {}) :: - sage: RP.parse_recurrence( + sage: RP.parse_recurrence( # optional - sage.symbolic ....: [f(8*n) == f(n)] + ....: [f(8*n + r) == f(2*n) for r in srange(1,8)], f, n) Traceback (most recent call last): @@ -1668,35 +1668,35 @@ def parse_recurrence(self, equations, function, var): Finally, also for the zero-sequence the output is as expected:: - sage: RP.parse_recurrence([f(2*n) == 0, f(2*n + 1) == 0], f, n) + sage: RP.parse_recurrence([f(2*n) == 0, f(2*n + 1) == 0], f, n) # optional - sage.symbolic (1, 0, {}, {}) We check that the output is of the correct type (:trac:`33158`):: sage: RP = RecurrenceParser(2, QQ) - sage: equations = [ + sage: equations = [ # optional - sage.symbolic ....: f(4*n) == 5/3*f(2*n) - 1/3*f(2*n + 1), ....: f(4*n + 1) == 4/3*f(2*n) + 1/3*f(2*n + 1), ....: f(4*n + 2) == 1/3*f(2*n) + 4/3*f(2*n + 1), ....: f(4*n + 3) == -1/3*f(2*n) + 5/3*f(2*n + 1), ....: f(0) == 1, f(1) == 2] - sage: M, m, coeffs, initial_values = RP.parse_recurrence(equations, f, n) - sage: M.parent() + sage: M, m, coeffs, initial_values = RP.parse_recurrence(equations, f, n) # optional - sage.symbolic + sage: M.parent() # optional - sage.symbolic Integer Ring - sage: m.parent() + sage: m.parent() # optional - sage.symbolic Integer Ring - sage: all(v.parent() == QQ for v in coeffs.values()) + sage: all(v.parent() == QQ for v in coeffs.values()) # optional - sage.symbolic True - sage: all(v.parent() == QQ for v in initial_values.values()) + sage: all(v.parent() == QQ for v in initial_values.values()) # optional - sage.symbolic True This results in giving the correct (see :trac:`33158`) minimization in:: sage: Seq2 = kRegularSequenceSpace(2, QQ) - sage: P = Seq2.from_recurrence(equations, f, n) - sage: P + sage: P = Seq2.from_recurrence(equations, f, n) # optional - sage.symbolic + sage: P # optional - sage.symbolic 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ... - sage: P.minimized() + sage: P.minimized() # optional - sage.symbolic 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ... """ from sage.arith.srange import srange @@ -2118,9 +2118,9 @@ def parameters(self, M, m, coeffs, initial_values, offset=0, inhomogeneities={}) TESTS:: - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, + sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, # optional - sage.symbolic ....: {-1: 0, 1: 0, 10: 0, I: 0, n: 0}) Traceback (most recent call last): ... @@ -2129,7 +2129,7 @@ def parameters(self, M, m, coeffs, initial_values, offset=0, inhomogeneities={}) :: - sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, + sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, # optional - sage.symbolic ....: {0: n}) Traceback (most recent call last): ... @@ -2584,11 +2584,11 @@ def shifted_inhomogeneities(self, recurrence_rules): TESTS:: sage: Seq2 = kRegularSequenceSpace(2, ZZ) - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: UB = Seq2.from_recurrence([ + sage: UB = Seq2.from_recurrence([ # optional - sage.symbolic ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -2602,16 +2602,16 @@ def shifted_inhomogeneities(self, recurrence_rules): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3) - sage: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1), + sage: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1), # optional - sage.symbolic ....: 6: UB.subsequence(4, 2) + UB.subsequence(4, 3)} - sage: recurrence_rules_UB = RR(M=3, m=2, ll=0, uu=9, + sage: recurrence_rules_UB = RR(M=3, m=2, ll=0, uu=9, # optional - sage.symbolic ....: inhomogeneities=inhomogeneities) - sage: shifted_inhomog = RP.shifted_inhomogeneities(recurrence_rules_UB) - sage: shifted_inhomog + sage: shifted_inhomog = RP.shifted_inhomogeneities(recurrence_rules_UB) # optional - sage.symbolic + sage: shifted_inhomog # optional - sage.symbolic {2: 2-regular sequence 8, 8, 8, 12, 12, 16, 12, 16, 12, 24, ..., 3: 2-regular sequence -10, -8, -8, -8, -8, -8, -8, -8, -8, -12, ..., 6: 2-regular sequence 20, 22, 24, 28, 28, 32, 28, 32, 32, 48, ...} - sage: shifted_inhomog[2].mu[0].ncols() == 3*inhomogeneities[2].mu[0].ncols() + sage: shifted_inhomog[2].mu[0].ncols() == 3*inhomogeneities[2].mu[0].ncols() # optional - sage.symbolic True .. SEEALSO:: @@ -2718,11 +2718,11 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic ....: f(8*n) == -1*f(2*n - 1) + 1*f(2*n + 1), ....: f(8*n + 1) == -11*f(2*n - 1) + 10*f(2*n) + 11*f(2*n + 1), ....: f(8*n + 2) == -21*f(2*n - 1) + 20*f(2*n) + 21*f(2*n + 1), @@ -2733,9 +2733,9 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): ....: f(8*n + 7) == -71*f(2*n - 1) + 70*f(2*n) + 71*f(2*n + 1), ....: f(0) == 0, f(1) == 1, f(2) == 2, f(3) == 3, f(4) == 4, ....: f(5) == 5, f(6) == 6, f(7) == 7], f, n) - sage: rules = RP.parameters( + sage: rules = RP.parameters( # optional - sage.symbolic ....: M, m, coeffs, initial_values, 0) - sage: RP.matrix(rules, 0, False) + sage: RP.matrix(rules, 0, False) # optional - sage.symbolic [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] @@ -2753,7 +2753,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): [ 0 0 0 -31 30 31 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 -41 40 41 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 -51 50 51 0 0 0 0 0 0 0 0 0 0 0] - sage: RP.matrix(rules, 1, False) + sage: RP.matrix(rules, 1, False) # optional - sage.symbolic [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0] @@ -2788,7 +2788,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -2802,9 +2802,9 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n) - sage: UB_rules = RP.parameters( + sage: UB_rules = RP.parameters( # optional - sage.symbolic ....: M, m, coeffs, initial_values, 3) - sage: RP.matrix(UB_rules, 0) + sage: RP.matrix(UB_rules, 0) # optional - sage.symbolic [ 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] @@ -2821,7 +2821,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): [ 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] - sage: RP.matrix(UB_rules, 1) + sage: RP.matrix(UB_rules, 1) # optional - sage.symbolic [ 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] @@ -3015,9 +3015,9 @@ def right(self, recurrence_rules): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f sage: SB_rules = RP.parameters( ....: 1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, @@ -3027,7 +3027,7 @@ def right(self, recurrence_rules): Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -3041,9 +3041,9 @@ def right(self, recurrence_rules): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n) - sage: UB_rules = RP.parameters( + sage: UB_rules = RP.parameters( # optional - sage.symbolic ....: M, m, coeffs, initial_values, 3) - sage: RP.right(UB_rules) + sage: RP.right(UB_rules) # optional - sage.symbolic (1, 1, 2, 1, 2, 2, 4, 2, 4, 6, 0, 4, 4, 1, 0, 0) """ from sage.modules.free_module_element import vector @@ -3079,12 +3079,12 @@ def __call__(self, *args, **kwds): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: RP([f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), + sage: RP([f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic ....: f(0) == 0, f(1) == 1], f, n) ([ [1 0 0] [1 1 0] @@ -3094,7 +3094,7 @@ def __call__(self, *args, **kwds): (1, 0, 0), (0, 1, 1)) - sage: RP(equations=[f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), + sage: RP(equations=[f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic ....: f(0) == 0, f(1) == 1], function=f, var=n) ([ [1 0 0] [1 1 0] diff --git a/src/sage/combinat/parallelogram_polyomino.py b/src/sage/combinat/parallelogram_polyomino.py index bb73b09df96..9c4ceedfd19 100644 --- a/src/sage/combinat/parallelogram_polyomino.py +++ b/src/sage/combinat/parallelogram_polyomino.py @@ -3703,14 +3703,14 @@ def _plot_diagram(self): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_diagram() + sage: pp._plot_diagram() # optional - sage.plot Graphics object consisting of 7 graphics primitives sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_diagram() + sage: pp._plot_diagram() # optional - sage.plot Graphics object consisting of 25 graphics primitives """ G = Graphics() @@ -3755,14 +3755,14 @@ def _plot_bounce(self, directions=None): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_bounce(directions=[1]) + sage: pp._plot_bounce(directions=[1]) # optional - sage.plot Graphics object consisting of 1 graphics primitive sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_bounce(directions=[0,1]) + sage: pp._plot_bounce(directions=[0,1]) # optional - sage.plot Graphics object consisting of 9 graphics primitives """ @@ -3798,14 +3798,14 @@ def _plot_bounce_values(self, bounce=0): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_bounce_values() + sage: pp._plot_bounce_values() # optional - sage.plot Graphics object consisting of 4 graphics primitives sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_bounce_values(bounce=1) + sage: pp._plot_bounce_values(bounce=1) # optional - sage.plot Graphics object consisting of 10 graphics primitives """ G = Graphics() @@ -3847,14 +3847,14 @@ def _plot_tree(self): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_tree() + sage: pp._plot_tree() # optional - sage.plot Graphics object consisting of 2 graphics primitives sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_tree() + sage: pp._plot_tree() # optional - sage.plot Graphics object consisting of 2 graphics primitives """ G = Graphics() @@ -3869,17 +3869,17 @@ def plot(self): EXAMPLES:: sage: pp = ParallelogramPolyomino([[0,1],[1,0]]) - sage: pp.plot() + sage: pp.plot() # optional - sage.plot Graphics object consisting of 4 graphics primitives sage: pp.set_options( ....: drawing_components=dict( - ....: diagram = True - ....: , bounce_0 = True - ....: , bounce_1 = True - ....: , bounce_values = 0 + ....: diagram=True, + ....: bounce_0=True, + ....: bounce_1=True, + ....: bounce_values=0, ....: ) ....: ) - sage: pp.plot() + sage: pp.plot() # optional - sage.plot Graphics object consisting of 7 graphics primitives """ G = Graphics() diff --git a/src/sage/combinat/partition.py b/src/sage/combinat/partition.py index 5513086de21..3470e41cc77 100644 --- a/src/sage/combinat/partition.py +++ b/src/sage/combinat/partition.py @@ -5326,7 +5326,7 @@ def outline(self, variable=None): TESTS:: - sage: integrate(Partition([1]).outline()-abs(x),(x,-10,10)) + sage: integrate(Partition([1]).outline()-abs(x),(x,-10,10)) # optional - sage.symbolic 2 """ if variable is None: diff --git a/src/sage/combinat/path_tableaux/frieze.py b/src/sage/combinat/path_tableaux/frieze.py index d63935a6a3b..23ff179039c 100644 --- a/src/sage/combinat/path_tableaux/frieze.py +++ b/src/sage/combinat/path_tableaux/frieze.py @@ -322,6 +322,8 @@ def triangulation(self): sage: path_tableaux.FriezePattern([1,2,1/7,5,3]).triangulation() # optional - sage.plot sage.symbolic Graphics object consisting of 12 graphics primitives + + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) # optional - sage.rings.number_field sage: path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], # optional - sage.plot sage.rings.number_field sage.symbolic ....: field=K).triangulation() diff --git a/src/sage/combinat/plane_partition.py b/src/sage/combinat/plane_partition.py index af96a0659fc..31ef06d95fa 100644 --- a/src/sage/combinat/plane_partition.py +++ b/src/sage/combinat/plane_partition.py @@ -38,8 +38,7 @@ from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation from sage.rings.integer_ring import ZZ -from sage.arith.misc import Sigma -from sage.functions.other import floor, ceil, binomial, factorial +from sage.arith.misc import Sigma, integer_floor as floor, integer_ceil as ceil, binomial, factorial from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets from sage.sets.family import Family from sage.sets.non_negative_integers import NonNegativeIntegers diff --git a/src/sage/combinat/root_system/plot.py b/src/sage/combinat/root_system/plot.py index ee23f9fe836..2c7a0bfbe45 100644 --- a/src/sage/combinat/root_system/plot.py +++ b/src/sage/combinat/root_system/plot.py @@ -29,7 +29,7 @@ angle:: sage: L = RootSystem(["A",2]).ambient_space() - sage: L.plot() + sage: L.plot() # optional - sage.plot sage.symbolic Graphics object consisting of 13 graphics primitives .. PLOT:: @@ -56,7 +56,7 @@ full picture in 3D:: sage: L = RootSystem(["A",2]).ambient_space() - sage: L.plot(projection=False) + sage: L.plot(projection=False) # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -72,7 +72,7 @@ `G_2`:: sage: L = RootSystem(["G",2]).ambient_space() - sage: L.plot(reflection_hyperplanes="all") + sage: L.plot(reflection_hyperplanes="all") # optional - sage.plot sage.symbolic Graphics object consisting of 21 graphics primitives .. PLOT:: @@ -107,7 +107,7 @@ its corresponding reflection hyperplane:: sage: L = RootSystem(["A",2]).weight_space() - sage: L.plot(roots="all", reflection_hyperplanes="all").show(figsize=15) + sage: L.plot(roots="all", reflection_hyperplanes="all").show(figsize=15) # optional - sage.plot sage.symbolic .. NOTE:: @@ -128,7 +128,7 @@ sage: Q = RootSystem(["G",2]).root_space() sage: L = RootSystem(["G",2]).ambient_space() - sage: L.plot(roots=list(Q.positive_roots()), fundamental_weights=False) + sage: L.plot(roots=list(Q.positive_roots()), fundamental_weights=False) # optional - sage.plot sage.symbolic Graphics object consisting of 17 graphics primitives .. PLOT:: @@ -149,7 +149,8 @@ sage: L = RootSystem(["E",8]).ambient_space() sage: L.dimension() 8 - sage: L.plot(roots="all", reflection_hyperplanes=False, projection=lambda v: M*vector(v), labels=False) # long time + sage: L.plot(roots="all", reflection_hyperplanes=False, # long time # optional - sage.plot sage.symbolic + ....: projection=lambda v: M*vector(v), labels=False) Graphics3d Object .. PLOT:: @@ -184,7 +185,8 @@ elements of the Weyl group. We enlarge a bit the bounding box to make sure everything fits in the picture:: - sage: RootSystem(["G",2]).ambient_space().plot(alcoves=True, alcove_labels=True, bounding_box=5) + sage: RootSystem(["G",2]).ambient_space().plot(alcoves=True, # optional - sage.plot sage.symbolic +....: alcove_labels=True, bounding_box=5) Graphics object consisting of 37 graphics primitives .. PLOT:: @@ -194,7 +196,7 @@ The same picture in 3D, for type `B_3`:: - sage: RootSystem(["B",3]).ambient_space().plot(alcoves=True, alcove_labels=True) + sage: RootSystem(["B",3]).ambient_space().plot(alcoves=True, alcove_labels=True) # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -213,7 +215,7 @@ We now draw the usual alcove picture for affine type `A_2^{(1)}`:: sage: L = RootSystem(["A",2,1]).ambient_space() - sage: L.plot() # long time + sage: L.plot() # long time # optional - sage.plot sage.symbolic Graphics object consisting of 160 graphics primitives .. PLOT:: @@ -231,7 +233,7 @@ we are visualizing here what's happening at level `1`. Here is the full picture in 3D:: - sage: L.plot(bounding_box=[[-3,3],[-3,3],[-1,1]], affine=False) # long time + sage: L.plot(bounding_box=[[-3,3],[-3,3],[-1,1]], affine=False) # long time # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -246,7 +248,7 @@ It's usually more readable to only draw the intersection of the reflection hyperplanes with the level `1` hyperplane:: - sage: L.plot(affine=False, level=1) # long time + sage: L.plot(affine=False, level=1) # long time # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -259,7 +261,7 @@ level 1:: sage: L = RootSystem(["G",2,1]).ambient_space() - sage: L.plot(affine=False, level=1) + sage: L.plot(affine=False, level=1) # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -274,8 +276,8 @@ options of the :meth:`~sage.plot.plot3d.base.Graphics3d.show` method:: - sage: p = L.plot(affine=False, level=1) - sage: p.show(aspect_ratio=[1,1,2], frame=False) + sage: p = L.plot(affine=False, level=1) # optional - sage.plot sage.symbolic + sage: p.show(aspect_ratio=[1,1,2], frame=False) # optional - sage.plot sage.symbolic .. TOPIC:: Exercise @@ -289,7 +291,7 @@ `u = vs_i`; the color of that wall is given by `i`:: sage: L = RootSystem(["C",2,1]).ambient_space() - sage: L.plot(coroots="simple", alcove_labels=True) # long time + sage: L.plot(coroots="simple", alcove_labels=True) # long time # optional - sage.plot sage.symbolic Graphics object consisting of 216 graphics primitives .. PLOT:: @@ -308,7 +310,7 @@ sage: positive_roots = RecursivelyEnumeratedSet(seed, succ, structure='graded') sage: it = iter(positive_roots) sage: first_positive_roots = [next(it) for i in range(10)] - sage: L.plot(roots=first_positive_roots, affine=False, alcoves=False) + sage: L.plot(roots=first_positive_roots, affine=False, alcoves=False) # optional - sage.plot sage.symbolic Graphics object consisting of 24 graphics primitives .. PLOT:: @@ -346,11 +348,12 @@ sage: positive_coroots = RecursivelyEnumeratedSet(seed, succ, structure='graded') sage: it = iter(positive_coroots) sage: first_positive_coroots = [next(it) for i in range(20)] - sage: p = L.plot(fundamental_chamber=True, reflection_hyperplanes=first_positive_coroots, + sage: p = L.plot(fundamental_chamber=True, # optional - sage.plot sage.symbolic + ....: reflection_hyperplanes=first_positive_coroots, ....: affine=False, alcove_labels=1, ....: bounding_box=[[-9,9],[-1,2]], ....: projection=lambda x: matrix([[1,-1],[1,1]])*vector(x)) - sage: p.show(figsize=20) # long time + sage: p.show(figsize=20) # long time # optional - sage.plot sage.symbolic Higher dimension affine pictures @@ -360,7 +363,7 @@ tiled by the alcoves, each of which is a 3D simplex:: sage: L = RootSystem(["A",3,1]).ambient_space() - sage: L.plot(reflection_hyperplanes=False, bounding_box=85/100) # long time + sage: L.plot(reflection_hyperplanes=False, bounding_box=85/100) # long time # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -376,7 +379,7 @@ the Weyl group:: sage: W = L.weyl_group() - sage: L.plot(reflection_hyperplanes=False, alcoves=[W.one()], bounding_box=2) + sage: L.plot(reflection_hyperplanes=False, alcoves=[W.one()], bounding_box=2) # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -390,7 +393,7 @@ center in the root lattice:: sage: W = L.weyl_group() - sage: L.plot(reflection_hyperplanes=False, alcoves=[[0,0]], bounding_box=2) + sage: L.plot(reflection_hyperplanes=False, alcoves=[[0,0]], bounding_box=2) # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -409,11 +412,12 @@ sage: L = RootSystem(["B",3,1]).ambient_space() sage: W = L.weyl_group() - sage: alcoves = [~w for d in range(12) for w in W.affine_grassmannian_elements_of_given_length(d)] - sage: p = L.plot_fundamental_chamber("classical") - sage: p += L.plot_alcoves(alcoves=alcoves, wireframe=True) - sage: p += L.plot_fundamental_weights() - sage: p.show(frame=False) + sage: alcoves = [~w for d in range(12) + ....: for w in W.affine_grassmannian_elements_of_given_length(d)] + sage: p = L.plot_fundamental_chamber("classical") # optional - sage.plot sage.symbolic + sage: p += L.plot_alcoves(alcoves=alcoves, wireframe=True) # optional - sage.plot sage.symbolic + sage: p += L.plot_fundamental_weights() # optional - sage.plot sage.symbolic + sage: p.show(frame=False) # optional - sage.plot sage.symbolic .. PLOT:: :width: 300 px @@ -448,7 +452,7 @@ sage: L = RootSystem(["A",2,1]).ambient_space() sage: w1 = [0,2,1,2,0,2,1,0,2,1,2,1,2,0,2,0,1,2,0] - sage: L.plot(alcove_walk=w1, bounding_box=6) # long time + sage: L.plot(alcove_walk=w1, bounding_box=6) # long time # optional - sage.plot sage.symbolic Graphics object consisting of 535 graphics primitives .. PLOT:: @@ -463,7 +467,7 @@ instead, it is actually built on top of many methods (see the list below) that can be called independently and combined at will:: - sage: L.plot_roots() + L.plot_reflection_hyperplanes() + sage: L.plot_roots() + L.plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic Graphics object consisting of 12 graphics primitives .. PLOT:: @@ -479,9 +483,9 @@ tend to pollute the picture. Annoyingly they come back when combining them. Here is a workaround:: - sage: p = L.plot_roots() + L.plot_reflection_hyperplanes() - sage: p.axes(False) - sage: p + sage: p = L.plot_roots() + L.plot_reflection_hyperplanes() # optional - sage.plot sage.symbolic + sage: p.axes(False) # optional - sage.plot sage.symbolic + sage: p # optional - sage.plot sage.symbolic Graphics object consisting of 12 graphics primitives .. PLOT:: @@ -500,10 +504,12 @@ sage: plot_options = L.plot_parse_options(bounding_box=[[-2,5],[-2,6]]) sage: w2 = [2,1,2,0,2,0,2,1,2,0,1,2,1,2,1,0,1,2,0,2,0,1,2,0,2] - sage: p = L.plot_alcoves(plot_options=plot_options) # long time - sage: p += L.plot_alcove_walk(w1, color="green", plot_options=plot_options) # long time - sage: p += L.plot_alcove_walk(w2, color="orange", plot_options=plot_options) # long time - sage: p # long time + sage: p = L.plot_alcoves(plot_options=plot_options) # long time # optional - sage.plot sage.symbolic + sage: p += L.plot_alcove_walk(w1, color="green", # long time # optional - sage.plot sage.symbolic + ....: plot_options=plot_options) + sage: p += L.plot_alcove_walk(w2, color="orange", # long time # optional - sage.plot sage.symbolic + ....: plot_options=plot_options) + sage: p # long time # optional - sage.plot sage.symbolic Graphics object consisting of ... graphics primitives .. PLOT:: @@ -519,11 +525,12 @@ And another with some foldings:: - sage: p += L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], - ....: foldings=[False, False, True, False, False, False, True, False, True, False], + sage: p += L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], # optional - sage.plot sage.symbolic + ....: foldings=[False, False, True, False, False, + ....: False, True, False, True, False], ....: color="purple") - sage: p.axes(False) - sage: p.show(figsize=20) + sage: p.axes(False) # optional - sage.plot sage.symbolic + sage: p.show(figsize=20) # optional - sage.plot sage.symbolic .. PLOT:: :width: 300 px @@ -550,12 +557,13 @@ sage: t = 6*Lambda[1] - 2*Lambda[2] - 4*Lambda[0] sage: walk = L.reduced_word_of_translation(L(t)) sage: plot_options = L.plot_parse_options(bounding_box=[[-2,5],[-2,5]]) - sage: p = L.plot(plot_options=plot_options) # long time - sage: p += L.plot_alcove_walk(walk, color="green", plot_options=plot_options) # long time - sage: p += plot_options.family_of_vectors({t: L(t)}) # long time - sage: plot_options.finalize(p) # long time + sage: p = L.plot(plot_options=plot_options) # long time # optional - sage.plot sage.symbolic + sage: p += L.plot_alcove_walk(walk, color="green", # long time # optional - sage.plot sage.symbolic + ....: plot_options=plot_options) + sage: p += plot_options.family_of_vectors({t: L(t)}) # long time # optional - sage.plot sage.symbolic + sage: plot_options.finalize(p) # long time # optional - sage.plot sage.symbolic Graphics object consisting of ... graphics primitives - sage: p # long time + sage: p # long time # optional - sage.plot sage.symbolic Graphics object consisting of ... graphics primitives .. PLOT:: @@ -583,7 +591,8 @@ sage: L = RootSystem(["B",3,1]).ambient_space() sage: w3 = [0,2,1,3,2,0,2,1,0,2,3,1,2,1,3,2,0,2,0,1,2,0] - sage: L.plot_fundamental_weights() + L.plot_reflection_hyperplanes(bounding_box=2) + L.plot_alcove_walk(w3) + sage: (L.plot_fundamental_weights() # optional - sage.plot sage.symbolic + ....: + L.plot_reflection_hyperplanes(bounding_box=2) + L.plot_alcove_walk(w3) Graphics3d Object .. PLOT:: @@ -610,7 +619,8 @@ sage: L = RootSystem(["A",3,1]).ambient_space() sage: alcoves = cartesian_product([[0,1],[0,1],[0,1]]) sage: color = lambda i: "black" if i==0 else None - sage: L.plot_alcoves(alcoves=alcoves, color=color, bounding_box=10,wireframe=True).show(frame=False) # long time + sage: L.plot_alcoves(alcoves=alcoves, color=color, # long time # optional - sage.plot sage.symbolic + ....: bounding_box=10, wireframe=True).show(frame=False) .. PLOT:: :width: 300 px @@ -635,8 +645,9 @@ Now you can create your own customized color Coxeter graph paper:: sage: L = RootSystem(["C",2,1]).ambient_space() - sage: p = L.plot(bounding_box=[[-8,9],[-5,7]], coroots="simple") # long time (10 s) - sage: p # long time + sage: p = L.plot(bounding_box=[[-8,9],[-5,7]], # long time (10 s) # optional - sage.plot sage.symbolic + ....: coroots="simple") + sage: p # long time # optional - sage.plot sage.symbolic Graphics object consisting of ... graphics primitives .. PLOT:: @@ -649,7 +660,7 @@ if printed on paper. Instead, we recommend saving the picture in postscript or svg before printing it:: - sage: p.save("C21paper.eps") # not tested + sage: p.save("C21paper.eps") # not tested # optional - sage.plot sage.symbolic .. NOTE:: @@ -676,11 +687,11 @@ sage: W = L.weyl_group() sage: g = W.cayley_graph(side="right") sage: positions = {w: plot_options.projection(w.action(rho)) for w in W} - sage: p = L.plot_alcoves() - sage: p += g.plot(pos = positions, vertex_size=0, + sage: p = L.plot_alcoves() # optional - sage.plot sage.symbolic + sage: p += g.plot(pos=positions, vertex_size=0, # optional - sage.plot sage.symbolic ....: color_by_label=plot_options.color) - sage: p.axes(False) - sage: p + sage: p.axes(False) # optional - sage.plot sage.symbolic + sage: p # optional - sage.plot sage.symbolic Graphics object consisting of 30 graphics primitives .. PLOT:: @@ -707,9 +718,9 @@ sage: W = L.weyl_group() sage: g = W.cayley_graph(side="right") sage: positions = {w: plot_options.projection(w.action(rho)) for w in W} - sage: p = L.plot_roots() - sage: p += g.plot3d(pos3d=positions, color_by_label=plot_options.color) - sage: p + sage: p = L.plot_roots() # optional - sage.plot sage.symbolic + sage: p += g.plot3d(pos3d=positions, color_by_label=plot_options.color) # optional - sage.plot sage.symbolic + sage: p # optional - sage.plot sage.symbolic Graphics3d Object .. PLOT:: @@ -747,11 +758,11 @@ sage: g = C.digraph() sage: positions = {x: plot_options.projection(x.weight()) for x in C} - sage: p = L.plot() - sage: p += g.plot(pos=positions, + sage: p = L.plot() # optional - sage.plot sage.symbolic + sage: p += g.plot(pos=positions, # optional - sage.plot sage.symbolic ....: color_by_label=plot_options.color, vertex_size=0) - sage: p.axes(False) - sage: p.show(figsize=15) + sage: p.axes(False) # optional - sage.plot sage.symbolic + sage: p.show(figsize=15) # optional - sage.plot sage.symbolic .. PLOT:: :width: 300 px @@ -781,11 +792,11 @@ sage: L = C.weight_lattice_realization() sage: plot_options = L.plot_parse_options() sage: g = C.digraph() - sage: positions = {x:plot_options.projection(x.weight()) for x in C} - sage: p = L.plot(reflection_hyperplanes=False, fundamental_weights=False) - sage: p += g.plot3d(pos3d=positions, vertex_labels=True, + sage: positions = {x: plot_options.projection(x.weight()) for x in C} # optional - sage.plot sage.symbolic + sage: p = L.plot(reflection_hyperplanes=False, fundamental_weights=False) # optional - sage.plot sage.symbolic + sage: p += g.plot3d(pos3d=positions, vertex_labels=True, # optional - sage.plot sage.symbolic ....: color_by_label=plot_options.color, edge_labels=True) - sage: p + sage: p # optional - sage.plot sage.symbolic Graphics3d Object .. TOPIC:: Exercise @@ -1496,7 +1507,7 @@ def reflection_hyperplane(self, coroot, as_polyhedron=False): @cached_function def barycentric_projection_matrix(n, angle=0): r""" - Returns a family of `n+1` vectors evenly spaced in a real vector space of dimension `n` + Return a family of `n+1` vectors evenly spaced in a real vector space of dimension `n`. Those vectors are of norm `1`, the scalar product between any two vector is `1/n`, thus the distance between two tips is constant. @@ -1530,25 +1541,25 @@ def barycentric_projection_matrix(n, angle=0): Three vectors in dimension 2:: - sage: barycentric_projection_matrix(2) + sage: barycentric_projection_matrix(2) # optional - sage.symbolic [ 1/2*sqrt(3) -1/2*sqrt(3) 0] [ 1/2 1/2 -1] Four vectors in dimension 3:: - sage: m = barycentric_projection_matrix(3); m + sage: m = barycentric_projection_matrix(3); m # optional - sage.symbolic [ 1/3*sqrt(3)*sqrt(2) -1/3*sqrt(3)*sqrt(2) 0 0] [ 1/3*sqrt(2) 1/3*sqrt(2) -2/3*sqrt(2) 0] [ 1/3 1/3 1/3 -1] The columns give four vectors that sum up to zero:: - sage: sum(m.columns()) + sage: sum(m.columns()) # optional - sage.symbolic (0, 0, 0) and have regular mutual angles:: - sage: m.transpose()*m + sage: m.transpose()*m # optional - sage.symbolic [ 1 -1/3 -1/3 -1/3] [-1/3 1 -1/3 -1/3] [-1/3 -1/3 1 -1/3] @@ -1556,19 +1567,19 @@ def barycentric_projection_matrix(n, angle=0): Here is a plot of them:: - sage: sum(arrow((0,0,0),x) for x in m.columns()) + sage: sum(arrow((0,0,0),x) for x in m.columns()) # optional - sage.plot sage.symbolic Graphics3d Object For 2D drawings of root systems, it is desirable to rotate the result to match with the usual conventions:: - sage: barycentric_projection_matrix(2, angle=2*pi/3) + sage: barycentric_projection_matrix(2, angle=2*pi/3) # optional - sage.symbolic [ 1/2 -1 1/2] [ 1/2*sqrt(3) 0 -1/2*sqrt(3)] TESTS:: - sage: for n in range(1, 7): + sage: for n in range(1, 7): # optional - sage.symbolic ....: m = barycentric_projection_matrix(n) ....: assert sum(m.columns()).is_zero() ....: assert matrix(QQ, n+1,n+1, lambda i,j: 1 if i==j else -1/n) == m.transpose()*m diff --git a/src/sage/combinat/root_system/reflection_group_complex.py b/src/sage/combinat/root_system/reflection_group_complex.py index 346cb59061b..87424491233 100644 --- a/src/sage/combinat/root_system/reflection_group_complex.py +++ b/src/sage/combinat/root_system/reflection_group_complex.py @@ -1737,7 +1737,7 @@ def invariant_value(i,j): coeffs = [] for i in self.index_set(): - coeff = 1-E(S[i].order()) + coeff = 1 - E(S[i].order()) if coeff in QQ: coeff = QQ(coeff) coeffs.append(coeff) diff --git a/src/sage/combinat/root_system/root_lattice_realizations.py b/src/sage/combinat/root_system/root_lattice_realizations.py index 2e2b2d2f3a9..70814864cd6 100644 --- a/src/sage/combinat/root_system/root_lattice_realizations.py +++ b/src/sage/combinat/root_system/root_lattice_realizations.py @@ -2442,13 +2442,13 @@ def plot_reflection_hyperplanes(self, collection="simple", **options): TESTS:: sage: L = RootSystem(["A",2]).ambient_space() - sage: print(L.plot_reflection_hyperplanes().description()) + sage: print(L.plot_reflection_hyperplanes().description()) # optional - sage.plot sage.symbolic Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15...) Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15...) Line defined by 2 points: [(-1.73..., 3.0), (1.73..., -3.0)] Line defined by 2 points: [(1.73..., 3.0), (-1.73..., -3.0)] - sage: print(L.plot_reflection_hyperplanes("all").description()) + sage: print(L.plot_reflection_hyperplanes("all").description()) # optional - sage.plot sage.symbolic Text '$H_{\alpha^\vee_{1} + \alpha^\vee_{2}}$' at the point (3.15...,0.0) Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15...) Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15...) @@ -2457,7 +2457,7 @@ def plot_reflection_hyperplanes(self, collection="simple", **options): Line defined by 2 points: [(3.0, 0.0), (-3.0, 0.0)] sage: L = RootSystem(["A",2,1]).ambient_space() - sage: print(L.plot_reflection_hyperplanes().description()) + sage: print(L.plot_reflection_hyperplanes().description()) # optional - sage.plot sage.symbolic Text '$H_{\alpha^\vee_{0}}$' at the point (3.15...,0.90...) Text '$H_{\alpha^\vee_{1}}$' at the point (-1.81...,3.15...) Text '$H_{\alpha^\vee_{2}}$' at the point (1.81...,3.15...) @@ -2832,12 +2832,12 @@ def plot_bounding_box(self, **options): EXAMPLES:: sage: L = RootSystem(["A",2,1]).ambient_space() - sage: L.plot_bounding_box() + sage: L.plot_bounding_box() # optional - sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive TESTS:: - sage: list(L.plot_bounding_box()) + sage: list(L.plot_bounding_box()) # optional - sage.plot sage.symbolic [Polygon defined by 4 points] """ plot_options = self.plot_parse_options(**options) @@ -3149,7 +3149,7 @@ def plot_crystal(self, crystal, sage: LS = crystals.LSPaths(['A',2], [1,1]) sage: L = RootSystem(['A',2]).ambient_space() - sage: L.plot_crystal(LS) + sage: L.plot_crystal(LS) # optional - sage.plot sage.symbolic Graphics object consisting of 16 graphics primitives """ from sage.plot.arrow import arrow diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index a39e6358709..d32397c2879 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -4915,8 +4915,8 @@ def scalar_qt(self, x, q=None, t=None): -q^3 + 2*q^2 - 2*q + 1 sage: a.scalar_qt(a,5,7) # q=5 and t=7 490/1539 - sage: (x,y) = var('x,y') - sage: a.scalar_qt(a,q=x,t=y) + sage: (x,y) = var('x,y') # optional - sage.symbolic + sage: a.scalar_qt(a, q=x, t=y) # optional - sage.symbolic 1/3*(x^3 - 1)/(y^3 - 1) + 2/3*(x - 1)^3/(y - 1)^3 sage: Rn = QQ['q','t','y','z'].fraction_field() sage: (q,t,y,z) = Rn.gens() @@ -6029,7 +6029,7 @@ def principal_specialization(self, n=infinity, q=None): it is better to obtain an element of the symbolic ring:: sage: h = SymmetricFunctions(QQ).h() - sage: (h[3]+h[2]).principal_specialization(q=var("q")) + sage: (h[3]+h[2]).principal_specialization(q=var("q")) # optional - sage.symbolic 1/((q^2 - 1)*(q - 1)) - 1/((q^3 - 1)*(q^2 - 1)*(q - 1)) In case ``q`` is in the base ring, it must be passed explicitly:: @@ -6290,11 +6290,11 @@ def exponential_specialization(self, t=None, q=1): sage: x = m[3]+m[2,1]+m[1,1,1] sage: d = x.homogeneous_degree() - sage: var("q t") + sage: var("q t") # optional - sage.symbolic (q, t) - sage: factor((x.principal_specialization()*(1-q)^d*t^d)) + sage: factor((x.principal_specialization()*(1-q)^d*t^d)) # optional - sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) - sage: factor(x.exponential_specialization(q=q, t=t)) + sage: factor(x.exponential_specialization(q=q, t=t)) # optional - sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) TESTS:: diff --git a/src/sage/combinat/six_vertex_model.py b/src/sage/combinat/six_vertex_model.py index 9bd289ff221..b688bdecb53 100644 --- a/src/sage/combinat/six_vertex_model.py +++ b/src/sage/combinat/six_vertex_model.py @@ -650,7 +650,7 @@ def partition_function(self, beta, epsilon): EXAMPLES:: sage: M = SixVertexModel(3, boundary_conditions='ice') - sage: M.partition_function(2, [1,2,1,2,1,2]) + sage: M.partition_function(2, [1,2,1,2,1,2]) # optional - sage.symbolic e^(-24) + 2*e^(-28) + e^(-30) + 2*e^(-32) + e^(-36) REFERENCES: diff --git a/src/sage/combinat/words/alphabet.py b/src/sage/combinat/words/alphabet.py index 3286eb8b3b4..5d1b0d5468a 100644 --- a/src/sage/combinat/words/alphabet.py +++ b/src/sage/combinat/words/alphabet.py @@ -193,15 +193,15 @@ def build_alphabet(data=None, names=None, name=None): Traceback (most recent call last): ... ValueError: invalid value for names - sage: Alphabet(8, x) + sage: Alphabet(8, x) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: invalid value for names - sage: Alphabet(name=x, names="punctuation") + sage: Alphabet(name=x, names="punctuation") # optional - sage.symbolic Traceback (most recent call last): ... ValueError: name cannot be specified with any other argument - sage: Alphabet(x) + sage: Alphabet(x) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: unable to construct an alphabet from the given parameters diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index 07b504b2a78..3a0fb332d51 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -780,7 +780,7 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): word: 11110 sage: words.CharacteristicSturmianWord(5/14) word: 01001001001001 - sage: words.CharacteristicSturmianWord(pi-3) + sage: words.CharacteristicSturmianWord(pi - 3) # optional - sage.symbolic word: 0000001000000100000010000001000000100000... From an iterator of the continued fraction expansion of a real:: From 0edead8dc4f1e8b30c7885acf3e7748fe0af98ce Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 15 May 2023 17:10:33 -0700 Subject: [PATCH 07/26] sage.combinat: Add # optional - sage.plot --- src/sage/combinat/binary_tree.py | 2 +- .../combinat/cluster_algebra_quiver/quiver.py | 16 ++-- src/sage/combinat/crystals/crystals.py | 2 +- src/sage/combinat/crystals/letters.pyx | 6 +- src/sage/combinat/crystals/mv_polytopes.py | 2 +- src/sage/combinat/dyck_word.py | 2 +- src/sage/combinat/finite_state_machine.py | 2 +- .../combinat/fully_commutative_elements.py | 2 +- src/sage/combinat/fully_packed_loop.py | 13 +-- src/sage/combinat/interval_posets.py | 4 +- src/sage/combinat/k_regular_sequence.py | 8 +- src/sage/combinat/nu_dyck_word.py | 2 +- src/sage/combinat/ordered_tree.py | 4 +- src/sage/combinat/permutation.py | 4 +- src/sage/combinat/plane_partition.py | 4 +- src/sage/combinat/posets/posets.py | 44 +++++----- .../rigged_configurations/kleber_tree.py | 2 +- .../non_symmetric_macdonald_polynomials.py | 8 +- src/sage/combinat/root_system/plot.py | 2 +- .../root_system/reflection_group_complex.py | 6 +- .../root_system/root_lattice_realizations.py | 4 +- src/sage/combinat/root_system/weyl_group.py | 4 +- src/sage/combinat/six_vertex_model.py | 2 +- .../symmetric_group_representations.py | 58 +++++++------- src/sage/combinat/tableau.py | 8 +- src/sage/combinat/words/finite_word.py | 24 +++--- src/sage/combinat/words/morphism.py | 80 +++++++++++-------- src/sage/combinat/words/paths.py | 78 +++++++++--------- src/sage/combinat/words/suffix_trees.py | 18 ++--- src/sage/combinat/words/word_generators.py | 14 ++-- src/sage/combinat/yang_baxter_graph.py | 12 +-- 31 files changed, 229 insertions(+), 208 deletions(-) diff --git a/src/sage/combinat/binary_tree.py b/src/sage/combinat/binary_tree.py index da0585e29ff..26923650782 100644 --- a/src/sage/combinat/binary_tree.py +++ b/src/sage/combinat/binary_tree.py @@ -867,7 +867,7 @@ def show(self, with_leaves=False): TESTS:: sage: t1 = BinaryTree([[], [[], None]]) - sage: t1.show() + sage: t1.show() # optional - sage.plot """ try: self.graph(with_leaves=with_leaves).show(layout='tree', tree_root=0, tree_orientation="down") diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver.py b/src/sage/combinat/cluster_algebra_quiver/quiver.py index ba1168749b7..c02b38073ef 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver.py @@ -742,7 +742,7 @@ def qmu_save(self, filename=None): sage: Q = ClusterQuiver(['F',4,[1,2]]) sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # optional - sage.plot sage.symbolic ....: Q.qmu_save(f.name) Make sure we can save quivers with `m != n` frozen variables, see :trac:`14851`:: @@ -751,7 +751,7 @@ def qmu_save(self, filename=None): sage: T1 = S.principal_extension() sage: Q = T1.quiver() sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # optional - sage.plot sage.symbolic ....: Q.qmu_save(f.name) """ M = self.b_matrix() @@ -1475,14 +1475,16 @@ def mutation_sequence(self, sequence, show_sequence=False, fig_size=1.2 ): INPUT: - ``sequence`` -- a list or tuple of vertices of ``self``. - - ``show_sequence`` -- (default: False) if True, a png containing the mutation sequence is shown. + - ``show_sequence`` -- (default: ``False``) if ``True``, a png containing the mutation sequence is shown. - ``fig_size`` -- (default: 1.2) factor by which the size of the sequence is expanded. EXAMPLES:: sage: Q = ClusterQuiver(['A',4]) sage: seq = Q.mutation_sequence([0,1]); seq - [Quiver on 4 vertices of type ['A', 4], Quiver on 4 vertices of type ['A', 4], Quiver on 4 vertices of type ['A', 4]] + [Quiver on 4 vertices of type ['A', 4], + Quiver on 4 vertices of type ['A', 4], + Quiver on 4 vertices of type ['A', 4]] sage: [T.b_matrix() for T in seq] [ [ 0 1 0 0] [ 0 -1 0 0] [ 0 1 -1 0] @@ -1491,8 +1493,6 @@ def mutation_sequence(self, sequence, show_sequence=False, fig_size=1.2 ): [ 0 0 -1 0], [ 0 0 -1 0], [ 0 0 -1 0] ] """ - from sage.plot.plot import Graphics - from sage.plot.text import text n = self._n m = self._m if m == 0: @@ -1520,9 +1520,13 @@ def mutation_sequence(self, sequence, show_sequence=False, fig_size=1.2 ): quiver_sequence.append( copy( quiver ) ) if show_sequence: + from sage.plot.plot import Graphics + from sage.plot.text import text + def _plot_arrow( v, k, center=(0,0) ): return text(r"$\longleftrightarrow$",(center[0],center[1]), fontsize=25) + text(r"$\mu_"+str(v)+"$",(center[0],center[1]+0.15), fontsize=15) \ + text("$"+str(k)+"$",(center[0],center[1]-0.2), fontsize=15) + plot_sequence = [ quiver_sequence[i].plot( circular=True, center=(i*width_factor,0) ) for i in range(len(quiver_sequence)) ] arrow_sequence = [ _plot_arrow( sequence[i],i+1,center=((i+0.5)*width_factor,0) ) for i in range(len(sequence)) ] sequence = [] diff --git a/src/sage/combinat/crystals/crystals.py b/src/sage/combinat/crystals/crystals.py index 8b965b79c09..dbc2e9a211f 100644 --- a/src/sage/combinat/crystals/crystals.py +++ b/src/sage/combinat/crystals/crystals.py @@ -103,7 +103,7 @@ One can get (currently) crude plotting via:: - sage: Tab.plot() + sage: Tab.plot() # optional - sage.plot Graphics object consisting of 52 graphics primitives If dot2tex is installed, one can obtain nice latex pictures via:: diff --git a/src/sage/combinat/crystals/letters.pyx b/src/sage/combinat/crystals/letters.pyx index 29ca6086c57..36edb9c8f86 100644 --- a/src/sage/combinat/crystals/letters.pyx +++ b/src/sage/combinat/crystals/letters.pyx @@ -1494,7 +1494,7 @@ cdef class Crystal_of_letters_type_E6_element(LetterTuple): sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None) True sage: G = C.digraph() - sage: G.show(edge_labels=true, figsize=12, vertex_size=1) + sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot """ def _repr_(self): @@ -1751,7 +1751,7 @@ cdef class Crystal_of_letters_type_E6_element_dual(LetterTuple): sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None) True sage: G = C.digraph() - sage: G.show(edge_labels=true, figsize=12, vertex_size=1) + sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot """ def _repr_(self): @@ -1911,7 +1911,7 @@ cdef class Crystal_of_letters_type_E7_element(LetterTuple): sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None) True sage: G = C.digraph() - sage: G.show(edge_labels=true, figsize=12, vertex_size=1) + sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot """ def weight(self): diff --git a/src/sage/combinat/crystals/mv_polytopes.py b/src/sage/combinat/crystals/mv_polytopes.py index bcb2654da60..cd6a4497d8e 100644 --- a/src/sage/combinat/crystals/mv_polytopes.py +++ b/src/sage/combinat/crystals/mv_polytopes.py @@ -218,7 +218,7 @@ def plot(self, P=None, **options): sage: MV = crystals.infinity.MVPolytopes(['C', 2]) sage: b = MV.highest_weight_vector().f_string([1,2,1,2,2,2,1,1,1,1,2,1]) - sage: b.plot() + sage: b.plot() # optional - sage.plot Graphics object consisting of 12 graphics primitives Here is the above example placed inside the ambient space diff --git a/src/sage/combinat/dyck_word.py b/src/sage/combinat/dyck_word.py index e4d2138e699..a6620735321 100644 --- a/src/sage/combinat/dyck_word.py +++ b/src/sage/combinat/dyck_word.py @@ -957,7 +957,7 @@ def plot(self, **kwds): EXAMPLES:: sage: w = DyckWords(100).random_element() - sage: w.plot() + sage: w.plot() # optional - sage.plot Graphics object consisting of 1 graphics primitive """ from sage.plot.plot import list_plot diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index 04106d2b7a3..decef1d4479 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -9708,7 +9708,7 @@ def plot(self): TESTS:: - sage: FiniteStateMachine([('A', 'A', 0)]).plot() + sage: FiniteStateMachine([('A', 'A', 0)]).plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives """ return self.graph(edge_labels='words_in_out').plot() diff --git a/src/sage/combinat/fully_commutative_elements.py b/src/sage/combinat/fully_commutative_elements.py index bb46692a8b7..5b338912e6c 100644 --- a/src/sage/combinat/fully_commutative_elements.py +++ b/src/sage/combinat/fully_commutative_elements.py @@ -268,7 +268,7 @@ def plot_heap(self): EXAMPLES:: sage: FC = CoxeterGroup(['B', 5]).fully_commutative_elements() - sage: FC([3,2,4,3,1]).plot_heap() + sage: FC([3,2,4,3,1]).plot_heap() # optional - sage.plot Graphics object consisting of 15 graphics primitives .. PLOT:: diff --git a/src/sage/combinat/fully_packed_loop.py b/src/sage/combinat/fully_packed_loop.py index 070275077cd..a16c2c369e3 100644 --- a/src/sage/combinat/fully_packed_loop.py +++ b/src/sage/combinat/fully_packed_loop.py @@ -157,7 +157,7 @@ class FullyPackedLoop(Element, metaclass=InheritComparisonClasscallMetaclass): The class also has a plot method:: - sage: fpl.plot() + sage: fpl.plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives which gives: @@ -781,7 +781,7 @@ def plot(self, **options): sage: A = AlternatingSignMatrix([[0, 1, 0], [1, -1, 1], [0, 1, 0]]) sage: fpl = FullyPackedLoop(A) - sage: fpl.plot() + sage: fpl.plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives The resulting graphics is as follows @@ -798,7 +798,7 @@ def plot(self, **options): sage: A = AlternatingSignMatrix([[0, 1, 0], [1, -1, 1], [0, 1, 0]]) sage: fpl = FullyPackedLoop(A) - sage: fpl.plot(link_color_map='rainbow') + sage: fpl.plot(link_color_map='rainbow') # optional - sage.plot Graphics object consisting of 3 graphics primitives .. PLOT:: @@ -811,8 +811,9 @@ def plot(self, **options): You can plot the 42 fully packed loops of size `4 \times 4` using:: - sage: G = [fpl.plot(link_color_map='winter', loop_color='black') for fpl in FullyPackedLoops(4)] - sage: graphics_array(G, 7, 6) + sage: G = [fpl.plot(link_color_map='winter', loop_color='black') # optional - sage.plot + ....: for fpl in FullyPackedLoops(4)] + sage: graphics_array(G, 7, 6) # optional - sage.plot Graphics Array of size 7 x 6 .. PLOT:: @@ -833,7 +834,7 @@ def plot(self, **options): ....: 00000000+-0000+00000000000000+0000000000" sage: a = matrix(20, [{'0':0, '+':1, '-': -1}[i] for i in s]) sage: fpl = FullyPackedLoop(a) - sage: fpl.plot(loop_fill=True, loop_color_map='rainbow') + sage: fpl.plot(loop_fill=True, loop_color_map='rainbow') # optional - sage.plot Graphics object consisting of 27 graphics primitives .. PLOT:: diff --git a/src/sage/combinat/interval_posets.py b/src/sage/combinat/interval_posets.py index a2d4f6e607c..346cd954e21 100644 --- a/src/sage/combinat/interval_posets.py +++ b/src/sage/combinat/interval_posets.py @@ -437,13 +437,13 @@ def plot(self, **kwds): EXAMPLES:: sage: ti = TamariIntervalPosets(4)[2] - sage: ti.plot() + sage: ti.plot() # optional - sage.plot Graphics object consisting of 6 graphics primitives TESTS:: sage: ti = TamariIntervalPoset(3, [[2,1], [2,3]]) - sage: ti.plot() + sage: ti.plot() # optional - sage.plot Graphics object consisting of 6 graphics primitives """ c0 = 'blue' # self.latex_options()["color_increasing"] diff --git a/src/sage/combinat/k_regular_sequence.py b/src/sage/combinat/k_regular_sequence.py index 5b5f2398cc0..74329d1f794 100644 --- a/src/sage/combinat/k_regular_sequence.py +++ b/src/sage/combinat/k_regular_sequence.py @@ -1228,20 +1228,20 @@ def from_recurrence(self, *args, **kwds): of non-zero elements in the generalized Pascal's triangle (see [LRS2017]_):: - sage: U = Seq2.from_recurrence(M=1, m=0, + sage: U = Seq2.from_recurrence(M=1, m=0, # optional - sage.symbolic ....: coeffs={(0, 0): 1}, ....: initial_values={0: 0, 1: 1}, ....: inhomogeneities={1: P}) - sage: (U - Seq2(SB)).is_trivial_zero() + sage: (U - Seq2(SB)).is_trivial_zero() # optional - sage.symbolic True :: - sage: U = Seq2.from_recurrence(M=1, m=0, + sage: U = Seq2.from_recurrence(M=1, m=0, # optional - sage.symbolic ....: coeffs={}, ....: initial_values={0: 0, 1: 1}, ....: inhomogeneities={0: SB, 1: P}) - sage: (U - Seq2(SB)).is_trivial_zero() + sage: (U - Seq2(SB)).is_trivial_zero() # optional - sage.symbolic True Number of Unbordered Factors in the Thue--Morse Sequence, but partly diff --git a/src/sage/combinat/nu_dyck_word.py b/src/sage/combinat/nu_dyck_word.py index b319f1326fe..efb0af7f572 100644 --- a/src/sage/combinat/nu_dyck_word.py +++ b/src/sage/combinat/nu_dyck_word.py @@ -873,7 +873,7 @@ def plot(self, **kwds): EXAMPLES:: sage: NDW = NuDyckWord('010','010') - sage: NDW.plot() + sage: NDW.plot() # optional - sage.plot Graphics object consisting of 1 graphics primitive """ from sage.plot.plot import list_plot diff --git a/src/sage/combinat/ordered_tree.py b/src/sage/combinat/ordered_tree.py index e874f5ccdf6..6a8f1206ff7 100644 --- a/src/sage/combinat/ordered_tree.py +++ b/src/sage/combinat/ordered_tree.py @@ -674,7 +674,7 @@ def plot(self): o o o | o - sage: p.plot() + sage: p.plot() # optional - sage.plot Graphics object consisting of 10 graphics primitives .. PLOT:: @@ -691,7 +691,7 @@ def plot(self): 2 3 5 | 4 - sage: g.plot() + sage: g.plot() # optional - sage.plot Graphics object consisting of 10 graphics primitives .. PLOT:: diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 56944d57dae..b9c0be15ee6 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -1722,8 +1722,8 @@ def show(self, representation="cycles", orientation="landscape", **args): EXAMPLES:: sage: P20 = Permutations(20) - sage: P20.random_element().show(representation="cycles") # optional - sage.graphs - sage: P20.random_element().show(representation="chord-diagram") # optional - sage.graphs + sage: P20.random_element().show(representation="cycles") # optional - sage.graphs sage.plot + sage: P20.random_element().show(representation="chord-diagram") # optional - sage.graphs sage.plot sage: P20.random_element().show(representation="braid") # optional - sage.plot sage: P20.random_element().show(representation="braid", # optional - sage.plot ....: orientation='portrait') diff --git a/src/sage/combinat/plane_partition.py b/src/sage/combinat/plane_partition.py index 31ef06d95fa..e7cb63842b9 100644 --- a/src/sage/combinat/plane_partition.py +++ b/src/sage/combinat/plane_partition.py @@ -667,7 +667,7 @@ def plot(self, show_box=False, colors=None): EXAMPLES:: sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) - sage: PP.plot() + sage: PP.plot() # optional - sage.plot Graphics object consisting of 27 graphics primitives """ from sage.functions.trig import cos, sin @@ -764,7 +764,7 @@ def plot3d(self, colors=None): EXAMPLES:: sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) - sage: PP.plot3d() + sage: PP.plot3d() # optional - sage.plot Graphics3d Object """ if colors is None: diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 2217b59a7bc..0812da9a83c 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -1932,24 +1932,24 @@ def plot(self, label_elements=True, element_labels=None, This function can be used without any parameters:: sage: D12 = posets.DivisorLattice(12) - sage: D12.plot() + sage: D12.plot() # optional - sage.plot Graphics object consisting of 14 graphics primitives Just the abstract form of the poset; examples of relabeling:: - sage: D12.plot(label_elements=False) + sage: D12.plot(label_elements=False) # optional - sage.plot Graphics object consisting of 8 graphics primitives sage: d = {1: 0, 2: 'a', 3: 'b', 4: 'c', 6: 'd', 12: 1} - sage: D12.plot(element_labels=d) + sage: D12.plot(element_labels=d) # optional - sage.plot Graphics object consisting of 14 graphics primitives - sage: d = {i:str(factor(i)) for i in D12} - sage: D12.plot(element_labels=d) + sage: d = {i: str(factor(i)) for i in D12} + sage: D12.plot(element_labels=d) # optional - sage.plot Graphics object consisting of 14 graphics primitives Some settings for coverings:: sage: d = {(a, b): b/a for a, b in D12.cover_relations()} - sage: D12.plot(cover_labels=d, cover_color='gray', cover_style='dotted') + sage: D12.plot(cover_labels=d, cover_color='gray', cover_style='dotted') # optional - sage.plot Graphics object consisting of 21 graphics primitives To emphasize some elements and show some options:: @@ -1960,7 +1960,7 @@ def plot(self, label_elements=True, element_labels=None, ....: 10: [12], 11: [12], 12: [13]}) sage: F = L.frattini_sublattice() sage: F_internal = [c for c in F.cover_relations() if c in L.cover_relations()] - sage: L.plot(figsize=12, border=True, element_shape='s', + sage: L.plot(figsize=12, border=True, element_shape='s', # optional - sage.plot ....: element_size=400, element_color='white', ....: element_colors={'blue': F, 'green': L.double_irreducibles()}, ....: cover_color='lightgray', cover_colors={'black': F_internal}, @@ -1971,7 +1971,9 @@ def plot(self, label_elements=True, element_labels=None, We check that ``label_elements`` and ``element_labels`` are honored:: - sage: def get_plot_labels(P): return sorted(t.string for t in P if isinstance(t, sage.plot.text.Text)) + sage: def get_plot_labels(P): + ....: return sorted(t.string for t in P + ....: if isinstance(t, sage.plot.text.Text)) sage: P1 = Poset({ 0:[1,2], 1:[3], 2:[3,4] }) sage: P2 = Poset({ 0:[1,2], 1:[3], 2:[3,4] }, facade=True) sage: get_plot_labels(P1.plot(label_elements=False)) @@ -1991,25 +1993,23 @@ def plot(self, label_elements=True, element_labels=None, sage: P.plot(heights=heights) Graphics object consisting of 8 graphics primitives sage: elem_labels = {0 : 'a', 1 : 'b', 2 : 'c', 3 : 'd'} - sage: P.plot(element_labels=elem_labels, heights=heights) + sage: P.plot(element_labels=elem_labels, heights=heights) # optional - sage.plot Graphics object consisting of 8 graphics primitives The following checks that equal labels are allowed (:trac:`15206`):: sage: P = Poset({1: [2,3]}) - sage: labs = {i: P.rank(i) for i in range(1, 4)} - sage: labs + sage: labs = {i: P.rank(i) for i in range(1, 4)}; labs {1: 0, 2: 1, 3: 1} - sage: P.plot(element_labels=labs) + sage: P.plot(element_labels=labs) # optional - sage.plot Graphics object consisting of 6 graphics primitives The following checks that non-hashable labels are allowed (:trac:`15206`):: sage: P = Poset({1: [2,3]}) - sage: labs = {1: [2, 3], 2: [], 3: []} - sage: labs + sage: labs = {1: [2, 3], 2: [], 3: []}; labs {1: [2, 3], 2: [], 3: []} - sage: P.plot(element_labels=labs) + sage: P.plot(element_labels=labs) # optional - sage.plot Graphics object consisting of 6 graphics primitives Plot of the empty poset:: @@ -2102,16 +2102,16 @@ def show(self, label_elements=True, element_labels=None, EXAMPLES:: sage: D = Poset({ 0:[1,2], 1:[3], 2:[3,4] }) - sage: D.plot(label_elements=False) + sage: D.plot(label_elements=False) # optional - sage.plot Graphics object consisting of 6 graphics primitives - sage: D.show() + sage: D.show() # optional - sage.plot sage: elm_labs = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e'} - sage: D.show(element_labels=elm_labs) + sage: D.show(element_labels=elm_labs) # optional - sage.plot One more example with cover labels:: sage: P = posets.PentagonPoset() - sage: P.show(cover_labels=lambda a, b: a - b) + sage: P.show(cover_labels=lambda a, b: a - b) # optional - sage.plot """ # We split the arguments into those meant for plot() and those meant for show() @@ -6704,16 +6704,16 @@ def order_ideal_plot(self, elements): EXAMPLES:: sage: P = Poset((divisors(1000), attrcall("divides"))) - sage: P.order_ideal_plot([20, 25]) + sage: P.order_ideal_plot([20, 25]) # optional - sage.plot Graphics object consisting of 41 graphics primitives TESTS:: sage: P = Poset() # Test empty poset - sage: P.order_ideal_plot([]) + sage: P.order_ideal_plot([]) # optional - sage.plot Graphics object consisting of 0 graphics primitives sage: C = posets.ChainPoset(5) - sage: C.order_ideal_plot([]) + sage: C.order_ideal_plot([]) # optional - sage.plot Graphics object consisting of 10 graphics primitives """ order_ideal = self.order_ideal(elements) diff --git a/src/sage/combinat/rigged_configurations/kleber_tree.py b/src/sage/combinat/rigged_configurations/kleber_tree.py index 82c99e8ad73..22768d9caad 100644 --- a/src/sage/combinat/rigged_configurations/kleber_tree.py +++ b/src/sage/combinat/rigged_configurations/kleber_tree.py @@ -1045,7 +1045,7 @@ def plot(self, **options): sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree sage: KT = KleberTree(['D', 4, 1], [[2, 2]]) - sage: print(KT.plot()) + sage: print(KT.plot()) # optional - sage.plot Graphics object consisting of 8 graphics primitives """ return self.digraph().plot(edge_labels=True, vertex_size=0, **options) diff --git a/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py b/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py index 37fd54ce2f3..a7cad09cdb5 100644 --- a/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py +++ b/src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py @@ -1078,8 +1078,8 @@ class NonSymmetricMacdonaldPolynomials(CherednikOperatorsEigenvectors): (x1, x2, x3) sage: E = NonSymmetricMacdonaldPolynomials(["BC",2,2], q=q, q1=t^2,q2=-1) - sage: omega=E.keys().fundamental_weights() - sage: expected = (t-1)*(t+1)*(2+q^4+2*q^2-2*t^2-2*q^2*t^2-t^4*q^2-q^4*t^4+t^4-3*q^6*t^6-2*q^4*t^6+2*q^6*t^8+2*q^4*t^8+t^10*q^8)*q^4/((q^2*t^3-1)*(q^2*t^3+1)*(t*q-1)*(t*q+1)*(t^2*q^3+1)*(t^2*q^3-1))+(t-1)^2*(t+1)^2*(2*q^2+q^4+2+q^4*t^2)*q^3*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)^2*(t+1)^2*(q^2+1)*q^5/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^4*x2/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(2*q^2+q^4+2+q^4*t^2)*q^3*x2/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)^2*(t+1)^2*(q^2+1)*q^5/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x2)+x1^2*x2^2+(t-1)*(t+1)*(-2*q^2-q^4-2+2*q^2*t^2+t^2+q^6*t^4+q^4*t^4)*q^2*x2*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q*x2^2*x1/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^3*x1^2/((t^2*q^3-1)*(t^2*q^3+1)*x2)+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q*x2*x1^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^6/((t^2*q^3+1)*(t^2*q^3-1)*x1*x2)+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q^2*x1^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q^2*x2^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^3*x2^2/((t^2*q^3-1)*(t^2*q^3+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^4*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x2) + sage: omega = E.keys().fundamental_weights() + sage: expected = (t-1)*(t+1)*(2+q^4+2*q^2-2*t^2-2*q^2*t^2-t^4*q^2-q^4*t^4+t^4-3*q^6*t^6-2*q^4*t^6+2*q^6*t^8+2*q^4*t^8+t^10*q^8)*q^4/((q^2*t^3-1)*(q^2*t^3+1)*(t*q-1)*(t*q+1)*(t^2*q^3+1)*(t^2*q^3-1))+(t-1)^2*(t+1)^2*(2*q^2+q^4+2+q^4*t^2)*q^3*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)^2*(t+1)^2*(q^2+1)*q^5/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^4*x2/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(2*q^2+q^4+2+q^4*t^2)*q^3*x2/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)^2*(t+1)^2*(q^2+1)*q^5/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x2)+x1^2*x2^2+(t-1)*(t+1)*(-2*q^2-q^4-2+2*q^2*t^2+t^2+q^6*t^4+q^4*t^4)*q^2*x2*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1))+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q*x2^2*x1/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^3*x1^2/((t^2*q^3-1)*(t^2*q^3+1)*x2)+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q*x2*x1^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^6/((t^2*q^3+1)*(t^2*q^3-1)*x1*x2)+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q^2*x1^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*(q^2+1+q^4*t^2)*q^2*x2^2/((t^2*q^3-1)*(t^2*q^3+1))+(t-1)*(t+1)*q^3*x2^2/((t^2*q^3-1)*(t^2*q^3+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^4*x1/((t^2*q^3+1)*(t^2*q^3-1)*(t*q-1)*(t*q+1)*x2) # optional - sage.symbolic sage: to_SR(E[2*omega[2]]) - expected # long time (3.5s) # optional - sage.symbolic 0 @@ -1087,7 +1087,7 @@ class NonSymmetricMacdonaldPolynomials(CherednikOperatorsEigenvectors): sage: omega=E.keys().fundamental_weights() sage: mu = -3*omega[1] + 3*omega[2] - omega[3]; mu (-1, 2, -1) - sage: expected = (t-1)^2*(t+1)^2*(3*q^2+q^4+1+t^2*q^4+q^2*t^2-3*t^4*q^2-5*t^6*q^4+2*t^8*q^4-4*t^8*q^6-q^8*t^10+2*t^10*q^6-2*q^8*t^12+t^14*q^8-t^14*q^10+q^10*t^16+q^8*t^16+q^10*t^18+t^18*q^12)*x2*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(q^2*t^6+2*t^6*q^4-q^4*t^4+t^4*q^2-q^2*t^2+t^2-2-q^2)*q^2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*(-q^2-1+t^4*q^2-q^4*t^4+2*t^6*q^4)*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t+1)*(t-1)*x2^2*x3/((t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(3*q^2+q^4+2+t^2*q^4+2*q^2*t^2-4*t^4*q^2+q^4*t^4-6*t^6*q^4+t^8*q^4-4*t^8*q^6-q^8*t^10+t^10*q^6-3*q^8*t^12-2*t^14*q^10+2*t^14*q^8+2*q^10*t^16+q^8*t^16+t^18*q^12+2*q^10*t^18)*q*x2/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(1+q^4+2*q^2+t^2*q^4-3*t^4*q^2+q^2*t^6-5*t^6*q^4+3*t^8*q^4-4*t^8*q^6+2*t^10*q^6-q^8*t^12-t^14*q^10+t^14*q^8+q^10*t^16+t^18*q^12)*x3*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(2*q^2+1+q^4+t^2*q^4-t^2+q^2*t^2-4*t^4*q^2+q^4*t^4+q^2*t^6-5*t^6*q^4+3*t^8*q^4-4*t^8*q^6+2*t^10*q^6+q^6*t^12-2*q^8*t^12-2*t^14*q^10+2*t^14*q^8+q^10*t^16+t^18*q^12)*q*x3/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(1+t^2+t^4*q^2)*q*x3*x2^2/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2+t^4-q^4*t^4-t^4*q^2+3*q^2*t^6-t^6*q^4-t^8*q^6+t^8*q^4+t^10*q^4+2*q^6*t^12-q^8*t^12+t^14*q^8)*q*x3*x2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*x1^2/((q^3*t^5-1)*(q^3*t^5+1)*x3*x2)+(t-1)*(t+1)*(-q^2-1+t^4*q^2-q^4*t^4+2*t^6*q^4)*x2^2/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)*(t+1)*(t^3*q-1)*(t^3*q+1)*x3*x2^2*x1/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*(q^2+1)*q*x1/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x3*x2)+(t-1)^2*(t+1)^2*(t^3*q-1)*(t^3*q+1)*x3*x2*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)^2*(t+1)^2*q^3*x3/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1*x2)+(t-1)*(t+1)*(-1-q^2+q^2*t^2+t^10*q^6)*q*x2/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x3*x1)+x2^2/(x1*x3)+(t-1)*(t+1)*q*x2^2/((t*q-1)*(t*q+1)*x3)+(t-1)^3*(t+1)^3*(1+t^2+t^4*q^2)*q*x2*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)^2*(t+1)^2*q*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(q^2*t^6+2*t^6*q^4-q^4*t^4+t^4*q^2-q^2*t^2+t^2-2-q^2)*q^3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)*(t+1)*(q^2+2-t^2+q^4*t^4-t^4*q^2-3*t^6*q^4+t^8*q^4-2*t^10*q^6-q^8*t^12+q^6*t^12+q^8*t^16+q^10*t^16)*q^2*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3*x2)+(t-1)*(t+1)*(1+q^4+2*q^2-2*q^2*t^2+t^4*q^6-q^4*t^4-3*q^6*t^6-t^6*q^4+2*t^8*q^6-t^10*q^6-q^8*t^10-t^14*q^10+t^14*q^8+2*q^10*t^16)*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2-q^4*t^4+2*t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^8)*q^3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)^2*(t+1)^2*(-1-q^2-q^2*t^2+t^2+t^4*q^2-q^4*t^4+2*t^6*q^4)*q^2*x3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)*(t+1)*q*x2^2/((t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(1+t^2+t^4*q^2)*q*x2^2*x1/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*q*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*(-1-q^4-2*q^2-t^2*q^4-q^2*t^2+t^4*q^2-t^4*q^6-2*q^4*t^4+3*t^6*q^4-q^6*t^6-t^8*q^8+t^8*q^6+2*t^10*q^6-q^10*t^12+3*q^8*t^12+2*t^14*q^10)*x3*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*(q^2+1-t^2+q^4*t^4-t^4*q^2+q^2*t^6-3*t^6*q^4+t^8*q^4-t^10*q^6+q^6*t^12-q^8*t^12+q^10*t^16)*q^2*x3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)*(t+1)*(-1-q^2+q^2*t^2+t^10*q^6)*q^2/((t*q-1)*(t*q+1)*(q^3*t^5+1)*(q^3*t^5-1)*x1*x3)+(t-1)*(t+1)*(1+q^4+2*q^2-3*q^2*t^2+t^4*q^6-q^4*t^4-3*q^6*t^6-t^6*q^4+t^8*q^4+2*t^8*q^6-t^10*q^6+t^14*q^8-t^14*q^10+q^10*t^16)*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(3*q^2+q^4+2+q^2*t^2-t^2+t^2*q^4-6*t^4*q^2+q^4*t^4-7*t^6*q^4+q^2*t^6+3*t^8*q^4-4*t^8*q^6+t^10*q^4+3*t^10*q^6-q^8*t^12-t^14*q^10+t^14*q^8+q^8*t^16+q^10*t^18)*q*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2-q^4*t^4+2*t^6*q^4+t^10*q^6+q^6*t^12+t^14*q^8)*q*x2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t+1)*(t-1)*x2^2*x1/((t*q-1)*(t*q+1)*x3)+(t-1)^3*(t+1)^3*(1+t^2+t^4*q^2)*q*x3*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*q^3/((q^3*t^5+1)*(q^3*t^5-1)*x1*x2*x3)+(t-1)^2*(t+1)^2*(3+3*q^2+q^4+2*q^2*t^2-t^2+t^2*q^4-6*t^4*q^2+q^4*t^4-8*t^6*q^4+q^2*t^6+2*t^8*q^4-4*t^8*q^6+t^10*q^4+2*t^10*q^6-2*q^8*t^12-t^14*q^10+t^14*q^8+q^8*t^16+q^10*t^16+2*q^10*t^18)*q^2/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(-q^4-2*q^2-1-t^2*q^4-t^4*q^6+2*q^6*t^6+t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^10)*q/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(-1-q^2-q^2*t^2+t^2+t^4*q^2-q^4*t^4+2*t^6*q^4)*q*x3*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*x2*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*x3*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*q^4/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x1*x2)+(t-1)^2*(t+1)^2*(-q^2-1-q^2*t^2-q^4*t^4+t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^10)*q*x3*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1) + sage: expected = (t-1)^2*(t+1)^2*(3*q^2+q^4+1+t^2*q^4+q^2*t^2-3*t^4*q^2-5*t^6*q^4+2*t^8*q^4-4*t^8*q^6-q^8*t^10+2*t^10*q^6-2*q^8*t^12+t^14*q^8-t^14*q^10+q^10*t^16+q^8*t^16+q^10*t^18+t^18*q^12)*x2*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(q^2*t^6+2*t^6*q^4-q^4*t^4+t^4*q^2-q^2*t^2+t^2-2-q^2)*q^2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*(-q^2-1+t^4*q^2-q^4*t^4+2*t^6*q^4)*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t+1)*(t-1)*x2^2*x3/((t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(3*q^2+q^4+2+t^2*q^4+2*q^2*t^2-4*t^4*q^2+q^4*t^4-6*t^6*q^4+t^8*q^4-4*t^8*q^6-q^8*t^10+t^10*q^6-3*q^8*t^12-2*t^14*q^10+2*t^14*q^8+2*q^10*t^16+q^8*t^16+t^18*q^12+2*q^10*t^18)*q*x2/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(1+q^4+2*q^2+t^2*q^4-3*t^4*q^2+q^2*t^6-5*t^6*q^4+3*t^8*q^4-4*t^8*q^6+2*t^10*q^6-q^8*t^12-t^14*q^10+t^14*q^8+q^10*t^16+t^18*q^12)*x3*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(2*q^2+1+q^4+t^2*q^4-t^2+q^2*t^2-4*t^4*q^2+q^4*t^4+q^2*t^6-5*t^6*q^4+3*t^8*q^4-4*t^8*q^6+2*t^10*q^6+q^6*t^12-2*q^8*t^12-2*t^14*q^10+2*t^14*q^8+q^10*t^16+t^18*q^12)*q*x3/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(1+t^2+t^4*q^2)*q*x3*x2^2/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2+t^4-q^4*t^4-t^4*q^2+3*q^2*t^6-t^6*q^4-t^8*q^6+t^8*q^4+t^10*q^4+2*q^6*t^12-q^8*t^12+t^14*q^8)*q*x3*x2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*x1^2/((q^3*t^5-1)*(q^3*t^5+1)*x3*x2)+(t-1)*(t+1)*(-q^2-1+t^4*q^2-q^4*t^4+2*t^6*q^4)*x2^2/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)*(t+1)*(t^3*q-1)*(t^3*q+1)*x3*x2^2*x1/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*(q^2+1)*q*x1/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x3*x2)+(t-1)^2*(t+1)^2*(t^3*q-1)*(t^3*q+1)*x3*x2*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)^2*(t+1)^2*q^3*x3/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1*x2)+(t-1)*(t+1)*(-1-q^2+q^2*t^2+t^10*q^6)*q*x2/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x3*x1)+x2^2/(x1*x3)+(t-1)*(t+1)*q*x2^2/((t*q-1)*(t*q+1)*x3)+(t-1)^3*(t+1)^3*(1+t^2+t^4*q^2)*q*x2*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)^2*(t+1)^2*q*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(q^2*t^6+2*t^6*q^4-q^4*t^4+t^4*q^2-q^2*t^2+t^2-2-q^2)*q^3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)*(t+1)*(q^2+2-t^2+q^4*t^4-t^4*q^2-3*t^6*q^4+t^8*q^4-2*t^10*q^6-q^8*t^12+q^6*t^12+q^8*t^16+q^10*t^16)*q^2*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)^2*(t+1)^2*(q^2+1)*q^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3*x2)+(t-1)*(t+1)*(1+q^4+2*q^2-2*q^2*t^2+t^4*q^6-q^4*t^4-3*q^6*t^6-t^6*q^4+2*t^8*q^6-t^10*q^6-q^8*t^10-t^14*q^10+t^14*q^8+2*q^10*t^16)*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2-q^4*t^4+2*t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^8)*q^3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)^2*(t+1)^2*(-1-q^2-q^2*t^2+t^2+t^4*q^2-q^4*t^4+2*t^6*q^4)*q^2*x3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)*(t+1)*q*x2^2/((t*q-1)*(t*q+1)*x1)+(t-1)^2*(t+1)^2*(1+t^2+t^4*q^2)*q*x2^2*x1/((t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1))+(t-1)^2*(t+1)^2*q*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*(-1-q^4-2*q^2-t^2*q^4-q^2*t^2+t^4*q^2-t^4*q^6-2*q^4*t^4+3*t^6*q^4-q^6*t^6-t^8*q^8+t^8*q^6+2*t^10*q^6-q^10*t^12+3*q^8*t^12+2*t^14*q^10)*x3*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*(q^2+1-t^2+q^4*t^4-t^4*q^2+q^2*t^6-3*t^6*q^4+t^8*q^4-t^10*q^6+q^6*t^12-q^8*t^12+q^10*t^16)*q^2*x3/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1)+(t-1)*(t+1)*(-1-q^2+q^2*t^2+t^10*q^6)*q^2/((t*q-1)*(t*q+1)*(q^3*t^5+1)*(q^3*t^5-1)*x1*x3)+(t-1)*(t+1)*(1+q^4+2*q^2-3*q^2*t^2+t^4*q^6-q^4*t^4-3*q^6*t^6-t^6*q^4+t^8*q^4+2*t^8*q^6-t^10*q^6+t^14*q^8-t^14*q^10+q^10*t^16)*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(3*q^2+q^4+2+q^2*t^2-t^2+t^2*q^4-6*t^4*q^2+q^4*t^4-7*t^6*q^4+q^2*t^6+3*t^8*q^4-4*t^8*q^6+t^10*q^4+3*t^10*q^6-q^8*t^12-t^14*q^10+t^14*q^8+q^8*t^16+q^10*t^18)*q*x1/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(-q^2-2-q^2*t^2-q^4*t^4+2*t^6*q^4+t^10*q^6+q^6*t^12+t^14*q^8)*q*x2*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t+1)*(t-1)*x2^2*x1/((t*q-1)*(t*q+1)*x3)+(t-1)^3*(t+1)^3*(1+t^2+t^4*q^2)*q*x3*x1^2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1))+(t-1)*(t+1)*q^3/((q^3*t^5+1)*(q^3*t^5-1)*x1*x2*x3)+(t-1)^2*(t+1)^2*(3+3*q^2+q^4+2*q^2*t^2-t^2+t^2*q^4-6*t^4*q^2+q^4*t^4-8*t^6*q^4+q^2*t^6+2*t^8*q^4-4*t^8*q^6+t^10*q^4+2*t^10*q^6-2*q^8*t^12-t^14*q^10+t^14*q^8+q^8*t^16+q^10*t^16+2*q^10*t^18)*q^2/((q^3*t^5+1)*(q^3*t^5-1)*(t*q-1)*(t*q+1)*(t^3*q^2+1)*(t^3*q^2-1)*(t^2*q-1)*(t^2*q+1))+(t-1)^2*(t+1)^2*(-q^4-2*q^2-1-t^2*q^4-t^4*q^6+2*q^6*t^6+t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^10)*q/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*(-1-q^2-q^2*t^2+t^2+t^4*q^2-q^4*t^4+2*t^6*q^4)*q*x3*x1/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*x2*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x3)+(t-1)^2*(t+1)^2*x3*x1^2/((t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x2)+(t-1)^2*(t+1)^2*q^4/((t*q+1)*(t*q-1)*(q^3*t^5+1)*(q^3*t^5-1)*x1*x2)+(t-1)^2*(t+1)^2*(-q^2-1-q^2*t^2-q^4*t^4+t^6*q^4+t^10*q^6+q^8*t^12+t^14*q^10)*q*x3*x2/((t^3*q^2-1)*(t^3*q^2+1)*(t*q+1)*(t*q-1)*(q^3*t^5-1)*(q^3*t^5+1)*x1) # optional - sage.symbolic sage: to_SR(E[mu]) - expected # long time (20s) # optional - sage.symbolic 0 @@ -1095,7 +1095,7 @@ class NonSymmetricMacdonaldPolynomials(CherednikOperatorsEigenvectors): sage: omega=E.keys().fundamental_weights() sage: mu = -4*omega[1]; mu (-4) - sage: expected = (t-1)*(t+1)*(-1+q^2*t^2-q^2-3*q^10-7*q^26*t^8+5*t^2*q^6-q^16-3*q^4+4*t^10*q^30-4*t^6*q^22-10*q^20*t^6+2*q^32*t^10-3*q^6-4*q^8+q^34*t^10-4*t^8*q^24-2*q^12-q^14+2*q^22*t^10+4*q^26*t^10+4*q^28*t^10+t^6*q^30-2*q^32*t^8-2*t^8*q^22+2*q^24*t^10-q^20*t^2-2*t^6*q^12+t^8*q^14+2*t^4*q^24-4*t^8*q^30+2*t^8*q^20-9*t^6*q^16+3*q^26*t^6+q^28*t^6+3*t^2*q^4+2*q^18*t^8-6*t^6*q^14+4*t^4*q^22-2*q^24*t^6+3*t^2*q^12+7*t^4*q^20-t^2*q^16+11*q^18*t^4-2*t^2*q^18+9*q^16*t^4-t^4*q^6+6*q^8*t^2+5*q^10*t^2-6*q^28*t^8+q^12*t^4+8*t^4*q^14-10*t^6*q^18-q^4*t^4+q^16*t^8-2*t^4*q^8)/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*(q^5*t^2+1)*(q^5*t^2-1))+(q^2+1)*(q^4+1)*(t-1)*(t+1)*(-1+q^2*t^2-q^2+t^2*q^6-q^4+t^6*q^22+3*q^10*t^4+t^2-q^8-2*t^8*q^24+q^22*t^10+q^26*t^10-2*t^8*q^22+q^24*t^10-4*t^6*q^12-2*t^8*q^20-3*t^6*q^16+2*t^2*q^4-t^6*q^10-2*t^6*q^14+t^8*q^12-t^2*q^12+2*q^16*t^4+q^8*t^2-q^10*t^2+3*q^12*t^4+2*t^4*q^14+t^6*q^18-2*q^4*t^4+q^16*t^8+q^20*t^10)*q*x1/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*(q^5*t^2+1)*(q^5*t^2-1))+(q^2+1)*(q^4+1)*(t-1)*(t+1)*(1+q^8+q^4+q^2-q^8*t^2-2*t^2*q^4-t^2*q^6+t^2*q^12-t^2+t^4*q^6-2*q^16*t^4-t^4*q^14-2*q^12*t^4+t^6*q^12+t^6*q^16+t^6*q^18+t^6*q^14)*q/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*x1)+(t-1)*(t+1)*(-1-q^2-q^6-q^4-q^8+t^2*q^4-t^2*q^14+t^2*q^6-q^10*t^2+q^8*t^2-t^2*q^12+q^12*t^4+q^10*t^4+q^16*t^4+2*t^4*q^14)*(q^4+1)/((q^7*t^2+1)*(q^7*t^2-1)*(t*q^4-1)*(t*q^4+1)*x1^2)+(t-1)*(t+1)*(q^4+1)*(q^2+1)*q/((t*q^4-1)*(t*q^4+1)*x1^3)+(q^4+1)*(t-1)*(t+1)*(1+q^6+q^8+q^2+q^4-q^2*t^2-3*t^2*q^4+q^10*t^2+t^2*q^12-2*t^2*q^6-q^8*t^2-2*q^16*t^4+q^4*t^4+t^4*q^6-q^10*t^4-2*q^12*t^4-2*t^4*q^14+t^6*q^12+t^6*q^18+2*t^6*q^16+t^6*q^14)*x1^2/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1))+(t-1)*(t+1)*(-1-t^2*q^6+t^2+t^4*q^8)*(q^4+1)*(q^2+1)*q*x1^3/((q^7*t^2+1)*(q^7*t^2-1)*(t*q^4-1)*(t*q^4+1))+1/x1^4+(t-1)*(t+1)*x1^4/((t*q^4-1)*(t*q^4+1)) + sage: expected = (t-1)*(t+1)*(-1+q^2*t^2-q^2-3*q^10-7*q^26*t^8+5*t^2*q^6-q^16-3*q^4+4*t^10*q^30-4*t^6*q^22-10*q^20*t^6+2*q^32*t^10-3*q^6-4*q^8+q^34*t^10-4*t^8*q^24-2*q^12-q^14+2*q^22*t^10+4*q^26*t^10+4*q^28*t^10+t^6*q^30-2*q^32*t^8-2*t^8*q^22+2*q^24*t^10-q^20*t^2-2*t^6*q^12+t^8*q^14+2*t^4*q^24-4*t^8*q^30+2*t^8*q^20-9*t^6*q^16+3*q^26*t^6+q^28*t^6+3*t^2*q^4+2*q^18*t^8-6*t^6*q^14+4*t^4*q^22-2*q^24*t^6+3*t^2*q^12+7*t^4*q^20-t^2*q^16+11*q^18*t^4-2*t^2*q^18+9*q^16*t^4-t^4*q^6+6*q^8*t^2+5*q^10*t^2-6*q^28*t^8+q^12*t^4+8*t^4*q^14-10*t^6*q^18-q^4*t^4+q^16*t^8-2*t^4*q^8)/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*(q^5*t^2+1)*(q^5*t^2-1))+(q^2+1)*(q^4+1)*(t-1)*(t+1)*(-1+q^2*t^2-q^2+t^2*q^6-q^4+t^6*q^22+3*q^10*t^4+t^2-q^8-2*t^8*q^24+q^22*t^10+q^26*t^10-2*t^8*q^22+q^24*t^10-4*t^6*q^12-2*t^8*q^20-3*t^6*q^16+2*t^2*q^4-t^6*q^10-2*t^6*q^14+t^8*q^12-t^2*q^12+2*q^16*t^4+q^8*t^2-q^10*t^2+3*q^12*t^4+2*t^4*q^14+t^6*q^18-2*q^4*t^4+q^16*t^8+q^20*t^10)*q*x1/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*(q^5*t^2+1)*(q^5*t^2-1))+(q^2+1)*(q^4+1)*(t-1)*(t+1)*(1+q^8+q^4+q^2-q^8*t^2-2*t^2*q^4-t^2*q^6+t^2*q^12-t^2+t^4*q^6-2*q^16*t^4-t^4*q^14-2*q^12*t^4+t^6*q^12+t^6*q^16+t^6*q^18+t^6*q^14)*q/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1)*x1)+(t-1)*(t+1)*(-1-q^2-q^6-q^4-q^8+t^2*q^4-t^2*q^14+t^2*q^6-q^10*t^2+q^8*t^2-t^2*q^12+q^12*t^4+q^10*t^4+q^16*t^4+2*t^4*q^14)*(q^4+1)/((q^7*t^2+1)*(q^7*t^2-1)*(t*q^4-1)*(t*q^4+1)*x1^2)+(t-1)*(t+1)*(q^4+1)*(q^2+1)*q/((t*q^4-1)*(t*q^4+1)*x1^3)+(q^4+1)*(t-1)*(t+1)*(1+q^6+q^8+q^2+q^4-q^2*t^2-3*t^2*q^4+q^10*t^2+t^2*q^12-2*t^2*q^6-q^8*t^2-2*q^16*t^4+q^4*t^4+t^4*q^6-q^10*t^4-2*q^12*t^4-2*t^4*q^14+t^6*q^12+t^6*q^18+2*t^6*q^16+t^6*q^14)*x1^2/((t*q^4-1)*(t*q^4+1)*(q^7*t^2-1)*(q^7*t^2+1)*(t*q^3-1)*(t*q^3+1))+(t-1)*(t+1)*(-1-t^2*q^6+t^2+t^4*q^8)*(q^4+1)*(q^2+1)*q*x1^3/((q^7*t^2+1)*(q^7*t^2-1)*(t*q^4-1)*(t*q^4+1))+1/x1^4+(t-1)*(t+1)*x1^4/((t*q^4-1)*(t*q^4+1)) # optional - sage.symbolic sage: to_SR(E[mu]) - expected # optional - sage.symbolic 0 diff --git a/src/sage/combinat/root_system/plot.py b/src/sage/combinat/root_system/plot.py index 2c7a0bfbe45..2789540d238 100644 --- a/src/sage/combinat/root_system/plot.py +++ b/src/sage/combinat/root_system/plot.py @@ -186,7 +186,7 @@ sure everything fits in the picture:: sage: RootSystem(["G",2]).ambient_space().plot(alcoves=True, # optional - sage.plot sage.symbolic -....: alcove_labels=True, bounding_box=5) + ....: alcove_labels=True, bounding_box=5) Graphics object consisting of 37 graphics primitives .. PLOT:: diff --git a/src/sage/combinat/root_system/reflection_group_complex.py b/src/sage/combinat/root_system/reflection_group_complex.py index 87424491233..3adeea5d5c7 100644 --- a/src/sage/combinat/root_system/reflection_group_complex.py +++ b/src/sage/combinat/root_system/reflection_group_complex.py @@ -212,10 +212,8 @@ from sage.matrix.special import identity_matrix from sage.structure.element import is_Matrix from sage.interfaces.gap3 import gap3 -from sage.rings.universal_cyclotomic_field import E from sage.modules.free_module_element import vector from sage.combinat.root_system.cartan_matrix import CartanMatrix -from sage.rings.universal_cyclotomic_field import UniversalCyclotomicField from sage.misc.sage_eval import sage_eval @@ -1710,6 +1708,8 @@ def _invariant_form_brute_force(self): [1 0] [0 1] """ + from sage.rings.universal_cyclotomic_field import E + base_change = self.base_change_matrix() Delta = tuple(self.independent_roots()) basis_is_Delta = base_change.is_one() @@ -2194,6 +2194,8 @@ def is_regular(self, h, is_class_representative=False): sage: len([w for w in W if w.is_regular(w.order())]) # optional - gap3 18 """ + from sage.rings.universal_cyclotomic_field import UniversalCyclotomicField, E + evs = self.reflection_eigenvalues(is_class_representative=is_class_representative) P = self.parent() I = identity_matrix(P.rank()) diff --git a/src/sage/combinat/root_system/root_lattice_realizations.py b/src/sage/combinat/root_system/root_lattice_realizations.py index 70814864cd6..e7f0e87807f 100644 --- a/src/sage/combinat/root_system/root_lattice_realizations.py +++ b/src/sage/combinat/root_system/root_lattice_realizations.py @@ -2319,12 +2319,12 @@ def plot_coroots(self, collection="simple", **options): EXAMPLES:: - sage: RootSystem(["B",3]).ambient_space().plot_coroots() + sage: RootSystem(["B",3]).ambient_space().plot_coroots() # optional - sage.plot sage.symbolic Graphics3d Object TESTS:: - sage: list(RootSystem(["B",2]).ambient_space().plot_coroots()) + sage: list(RootSystem(["B",2]).ambient_space().plot_coroots()) # optional - sage.plot sage.symbolic [Arrow from (0.0,0.0) to (1.0,-1.0), Text '$\alpha^\vee_{1}$' at the point (1.05,-1.05), Arrow from (0.0,0.0) to (0.0,2.0), diff --git a/src/sage/combinat/root_system/weyl_group.py b/src/sage/combinat/root_system/weyl_group.py index 6842f0467fa..1e032d45ad9 100644 --- a/src/sage/combinat/root_system/weyl_group.py +++ b/src/sage/combinat/root_system/weyl_group.py @@ -16,14 +16,14 @@ sage: w = WeylGroup(['A',3]) sage: d = w.cayley_graph(); d Digraph on 24 vertices - sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) + sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) # optional - sage.plot The Cayley graph of the Weyl Group of type ['D', 4]:: sage: w = WeylGroup(['D',4]) sage: d = w.cayley_graph(); d Digraph on 192 vertices - sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) #long time (less than one minute) + sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) # long time (less than one minute) # optional - sage.plot .. TODO:: diff --git a/src/sage/combinat/six_vertex_model.py b/src/sage/combinat/six_vertex_model.py index b688bdecb53..cbfd004ca35 100644 --- a/src/sage/combinat/six_vertex_model.py +++ b/src/sage/combinat/six_vertex_model.py @@ -149,7 +149,7 @@ def plot(self, color='sign'): EXAMPLES:: sage: M = SixVertexModel(2, boundary_conditions='ice') - sage: print(M[0].plot().description()) + sage: print(M[0].plot().description()) # optional - sage.plot Arrow from (-1.0,0.0) to (0.0,0.0) Arrow from (-1.0,1.0) to (0.0,1.0) Arrow from (0.0,0.0) to (0.0,-1.0) diff --git a/src/sage/combinat/symmetric_group_representations.py b/src/sage/combinat/symmetric_group_representations.py index 8a6b58ae87c..23f310b89ea 100644 --- a/src/sage/combinat/symmetric_group_representations.py +++ b/src/sage/combinat/symmetric_group_representations.py @@ -75,28 +75,28 @@ def SymmetricGroupRepresentation(partition, implementation="specht", :: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal"); orth + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal"); orth # optional - sage.symbolic Orthogonal representation of the symmetric group corresponding to [2, 1] - sage: all(a*a.transpose() == a.parent().identity_matrix() for a in orth) + sage: all(a*a.transpose() == a.parent().identity_matrix() for a in orth) # optional - sage.symbolic True :: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal"); orth + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal"); orth # optional - sage.symbolic Orthogonal representation of the symmetric group corresponding to [3, 2] - sage: orth([2,1,3,4,5]) + sage: orth([2,1,3,4,5]) # optional - sage.symbolic [ 1 0 0 0 0] [ 0 1 0 0 0] [ 0 0 -1 0 0] [ 0 0 0 1 0] [ 0 0 0 0 -1] - sage: orth([1,3,2,4,5]) + sage: orth([1,3,2,4,5]) # optional - sage.symbolic [ 1 0 0 0 0] [ 0 -1/2 1/2*sqrt(3) 0 0] [ 0 1/2*sqrt(3) 1/2 0 0] [ 0 0 0 -1/2 1/2*sqrt(3)] [ 0 0 0 1/2*sqrt(3) 1/2] - sage: orth([1,2,4,3,5]) + sage: orth([1,2,4,3,5]) # optional - sage.symbolic [ -1/3 2/3*sqrt(2) 0 0 0] [2/3*sqrt(2) 1/3 0 0 0] [ 0 0 1 0 0] @@ -200,13 +200,13 @@ def SymmetricGroupRepresentations(n, implementation="specht", ring=None, :: - sage: orth = SymmetricGroupRepresentations(3, "orthogonal"); orth + sage: orth = SymmetricGroupRepresentations(3, "orthogonal"); orth # optional - sage.symbolic Orthogonal representations of the symmetric group of order 3! over Symbolic Ring - sage: orth.list() + sage: orth.list() # optional - sage.symbolic [Orthogonal representation of the symmetric group corresponding to [3], Orthogonal representation of the symmetric group corresponding to [2, 1], Orthogonal representation of the symmetric group corresponding to [1, 1, 1]] - sage: orth([2,1])([1,2,3]) + sage: orth([2,1])([1,2,3]) # optional - sage.symbolic [1 0] [0 1] @@ -516,8 +516,8 @@ def __iter__(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentations(3, "orthogonal") - sage: for x in orth: print(x) + sage: orth = SymmetricGroupRepresentations(3, "orthogonal") # optional - sage.symbolic + sage: for x in orth: print(x) # optional - sage.symbolic Orthogonal representation of the symmetric group corresponding to [3] Orthogonal representation of the symmetric group corresponding to [2, 1] Orthogonal representation of the symmetric group corresponding to [1, 1, 1] @@ -540,8 +540,8 @@ def _yang_baxter_graph(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") - sage: orth._yang_baxter_graph + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # optional - sage.symbolic + sage: orth._yang_baxter_graph # optional - sage.symbolic Yang-Baxter graph of [3, 2], with top vertex (0, -1, 2, 1, 0) """ Y = YangBaxterGraph_partition(self._partition) @@ -565,8 +565,8 @@ def _tableau_dict(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") - sage: orth._tableau_dict + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # optional - sage.symbolic + sage: orth._tableau_dict # optional - sage.symbolic {(0, -1, 2, 1, 0): [[1, 2, 3], [4, 5]], (0, 2, -1, 1, 0): [[1, 2, 4], [3, 5]], (0, 2, 1, -1, 0): [[1, 3, 4], [2, 5]], @@ -591,8 +591,8 @@ def _word_dict(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") - sage: orth._word_dict + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # optional - sage.symbolic + sage: orth._word_dict # optional - sage.symbolic {(0, -1, 2, 1, 0): (4, 5, 1, 2, 3), (0, 2, -1, 1, 0): (3, 5, 1, 2, 4), (0, 2, 1, -1, 0): (2, 5, 1, 3, 4), @@ -610,11 +610,11 @@ def representation_matrix_for_simple_transposition(self, i): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") - sage: orth.representation_matrix_for_simple_transposition(1) + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic + sage: orth.representation_matrix_for_simple_transposition(1) # optional - sage.symbolic [ 1 0] [ 0 -1] - sage: orth.representation_matrix_for_simple_transposition(2) + sage: orth.representation_matrix_for_simple_transposition(2) # optional - sage.symbolic [ -1/2 1/2*sqrt(3)] [1/2*sqrt(3) 1/2] @@ -663,11 +663,11 @@ def _representation_matrix_uncached(self, permutation): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") - sage: orth._representation_matrix_uncached(Permutation([2,1,3])) + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic + sage: orth._representation_matrix_uncached(Permutation([2,1,3])) # optional - sage.symbolic [ 1 0] [ 0 -1] - sage: orth._representation_matrix_uncached(Permutation([1,3,2])) + sage: orth._representation_matrix_uncached(Permutation([1,3,2])) # optional - sage.symbolic [ -1/2 1/2*sqrt(3)] [1/2*sqrt(3) 1/2] @@ -696,11 +696,11 @@ def representation_matrix(self, permutation): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") - sage: orth.representation_matrix(Permutation([2,1,3])) + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic + sage: orth.representation_matrix(Permutation([2,1,3])) # optional - sage.symbolic [ 1 0] [ 0 -1] - sage: orth.representation_matrix(Permutation([1,3,2])) + sage: orth.representation_matrix(Permutation([1,3,2])) # optional - sage.symbolic [ -1/2 1/2*sqrt(3)] [1/2*sqrt(3) 1/2] @@ -779,7 +779,7 @@ def _repr_(self): EXAMPLES:: - sage: SymmetricGroupRepresentation([2,1], "orthogonal") + sage: SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic Orthogonal representation of the symmetric group corresponding to [2, 1] """ return "Orthogonal representation of the symmetric group corresponding to {}".format(self._partition) @@ -796,8 +796,8 @@ def _2x2_matrix_entries(self, beta): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") - sage: orth._2x2_matrix_entries(1/2) + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic + sage: orth._2x2_matrix_entries(1/2) # optional - sage.symbolic (-1/2, 1/2*sqrt(3), 1/2*sqrt(3), 1/2) """ return (-beta, sqrt(1 - beta**2), sqrt(1 - beta**2), beta) diff --git a/src/sage/combinat/tableau.py b/src/sage/combinat/tableau.py index 4df26efd41d..719f2260608 100644 --- a/src/sage/combinat/tableau.py +++ b/src/sage/combinat/tableau.py @@ -890,15 +890,15 @@ def plot(self, descents=False): EXAMPLES:: sage: t = Tableau([[1,2,4],[3]]) - sage: t.plot() + sage: t.plot() # optional - sage.plot Graphics object consisting of 11 graphics primitives - sage: t.plot(descents=True) + sage: t.plot(descents=True) # optional - sage.plot Graphics object consisting of 12 graphics primitives sage: t = Tableau([[2,2,4],[3]]) - sage: t.plot() + sage: t.plot() # optional - sage.plot Graphics object consisting of 11 graphics primitives - sage: t.plot(descents=True) + sage: t.plot(descents=True) # optional - sage.plot Traceback (most recent call last): ... ValueError: the tableau must be standard for 'descents=True' diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index ab639164b5a..53e04002cf6 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -136,7 +136,7 @@ sage: st = w.suffix_tree() sage: st Implicit Suffix Tree of the word: abaabbba - sage: st.show(word_labels=True) + sage: st.show(word_labels=True) # optional - sage.plot :: @@ -6824,18 +6824,18 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn EXAMPLES:: - sage: Word(range(20)).colored_vector() + sage: Word(range(20)).colored_vector() # optional - sage.plot Graphics object consisting of 21 graphics primitives - sage: Word(range(100)).colored_vector(0,0,10,1) + sage: Word(range(100)).colored_vector(0,0,10,1) # optional - sage.plot Graphics object consisting of 101 graphics primitives - sage: Words(range(100))(range(10)).colored_vector() + sage: Words(range(100))(range(10)).colored_vector() # optional - sage.plot Graphics object consisting of 11 graphics primitives sage: w = Word('abbabaab') - sage: w.colored_vector() + sage: w.colored_vector() # optional - sage.plot Graphics object consisting of 9 graphics primitives - sage: w.colored_vector(cmap='autumn') + sage: w.colored_vector(cmap='autumn') # optional - sage.plot Graphics object consisting of 9 graphics primitives - sage: Word(range(20)).colored_vector(label='Rainbow') + sage: Word(range(20)).colored_vector(label='Rainbow') # optional - sage.plot Graphics object consisting of 23 graphics primitives When two words are defined under the same parent, same letters are @@ -6844,25 +6844,25 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn sage: W = Words(range(20)) sage: w = W(range(20)) sage: y = W(range(10,20)) - sage: y.colored_vector(y=1, x=10) + w.colored_vector() + sage: y.colored_vector(y=1, x=10) + w.colored_vector() # optional - sage.plot Graphics object consisting of 32 graphics primitives TESTS: The empty word:: - sage: Word().colored_vector() + sage: Word().colored_vector() # optional - sage.plot Graphics object consisting of 1 graphics primitive - sage: Word().colored_vector(label='empty') + sage: Word().colored_vector(label='empty') # optional - sage.plot Graphics object consisting of 3 graphics primitives Unknown cmap:: - sage: Word(range(100)).colored_vector(cmap='jolies') + sage: Word(range(100)).colored_vector(cmap='jolies') # optional - sage.plot Traceback (most recent call last): ... RuntimeError: Color map jolies not known - sage: Word(range(100)).colored_vector(cmap='__doc__') + sage: Word(range(100)).colored_vector(cmap='__doc__') # optional - sage.plot Traceback (most recent call last): ... RuntimeError: Color map __doc__ not known diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 0b8e99ce5c5..33a76127699 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -2790,113 +2790,127 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, #. The Rauzy fractal of the Tribonacci substitution:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: s.rauzy_fractal_plot() # long time + sage: s.rauzy_fractal_plot() # long time # optional - sage.plot Graphics object consisting of 3 graphics primitives #. The "Hokkaido" fractal. We tweak the plot using the plotting options to get a nice reusable picture, in which we mark the origin by a black dot:: sage: s = WordMorphism('a->ab,b->c,c->d,d->e,e->a') - sage: G = s.rauzy_fractal_plot(n=100000, point_size=3, plot_origin=(50,"black")) # not tested + sage: G = s.rauzy_fractal_plot(n=100000, point_size=3, # not tested + ....: plot_origin=(50,"black")) sage: G.show(figsize=10, axes=false) # not tested #. Another "Hokkaido" fractal and its domain exchange:: sage: s = WordMorphism({1:[2], 2:[4,3], 3:[4], 4:[5,3], 5:[6], 6:[1]}) - sage: s.rauzy_fractal_plot() # not tested takes > 1 second - sage: s.rauzy_fractal_plot(exchange=True) # not tested takes > 1 second + sage: s.rauzy_fractal_plot() # not tested (> 1 second) + sage: s.rauzy_fractal_plot(exchange=True) # not tested (> 1 second) #. A three-dimensional Rauzy fractal:: sage: s = WordMorphism('1->12,2->13,3->14,4->1') - sage: s.rauzy_fractal_plot() # not tested takes > 1 second + sage: s.rauzy_fractal_plot() # not tested (> 1 second) #. A one-dimensional Rauzy fractal (very scattered):: sage: s = WordMorphism('1->2122,2->1') - sage: s.rauzy_fractal_plot().show(figsize=20) # not tested takes > 1 second + sage: s.rauzy_fractal_plot().show(figsize=20) # not tested (> 1 second) #. A high resolution plot of a complicated fractal:: sage: s = WordMorphism('1->23,2->123,3->1122233') - sage: G = s.rauzy_fractal_plot(n=300000) # not tested takes > 1 second - sage: G.show(axes=false, figsize=20) # not tested takes > 1 second + sage: G = s.rauzy_fractal_plot(n=300000) # not tested (> 1 second) + sage: G.show(axes=false, figsize=20) # not tested (> 1 second) #. A nice colorful animation of a domain exchange:: sage: s = WordMorphism('1->21,2->3,3->4,4->25,5->6,6->7,7->1') - sage: L = [s.rauzy_fractal_plot(), s.rauzy_fractal_plot(exchange=True)] # not tested takes > 1 second - sage: animate(L, axes=false).show(delay=100) # not tested takes > 1 second + sage: L = [s.rauzy_fractal_plot(), # not tested (> 1 second) + ....: s.rauzy_fractal_plot(exchange=True)] + sage: animate(L, axes=false).show(delay=100) # not tested (> 1 second) #. Plotting with only one color:: sage: s = WordMorphism('1->12,2->31,3->1') - sage: s.rauzy_fractal_plot(colormap={'1':'black', '2':'black', '3':'black'}) # not tested takes > 1 second + sage: cm = {'1':'black', '2':'black', '3':'black'} + sage: s.rauzy_fractal_plot(colormap=cm) # not tested (> 1 second) #. Different fractals can be obtained by choosing another (non-Pisot) eigenvalue:: sage: s = WordMorphism('1->12,2->3,3->45,4->5,5->6,6->7,7->8,8->1') sage: E = s.incidence_matrix().eigenvalues() sage: x = [x for x in E if -0.8 < x < -0.7][0] - sage: s.rauzy_fractal_plot() # not tested takes > 1 second - sage: s.rauzy_fractal_plot(eig=x) # not tested takes > 1 second + sage: s.rauzy_fractal_plot() # not tested (> 1 second) + sage: s.rauzy_fractal_plot(eig=x) # not tested (> 1 second) #. A Pisot reducible substitution with seemingly overlapping tiles:: - sage: s = WordMorphism({1:[1,2], 2:[2,3], 3:[4], 4:[5], 5:[6], 6:[7], 7:[8], 8:[9], 9:[10], 10:[1]}) - sage: s.rauzy_fractal_plot() # not tested takes > 1 second + sage: s = WordMorphism({1:[1,2], 2:[2,3], 3:[4], 4:[5], 5:[6], + ....: 6:[7], 7:[8], 8:[9], 9:[10], 10:[1]}) + sage: s.rauzy_fractal_plot() # not tested (> 1 second) #. A non-Pisot reducible substitution with a strange Rauzy fractal:: sage: s = WordMorphism({1:[3,2], 2:[3,3], 3:[4], 4:[1]}) - sage: s.rauzy_fractal_plot() # not tested takes > 1 second + sage: s.rauzy_fractal_plot() # not tested (> 1 second) #. A substitution with overlapping tiles. We use the options ``colormap`` and ``opacity`` to study how the tiles overlap:: sage: s = WordMorphism('1->213,2->4,3->5,4->1,5->21') - sage: s.rauzy_fractal_plot() # not tested takes > 1 second - sage: s.rauzy_fractal_plot(colormap={'1':'red', '4':'purple'}) # not tested takes > 1 second - sage: s.rauzy_fractal_plot(opacity={'1':0.1,'2':1,'3':0.1,'4':0.1,'5':0.1}, n=150000) # not tested takes > 1 second + sage: s.rauzy_fractal_plot() # not tested (> 1 second) + sage: s.rauzy_fractal_plot(colormap={'1':'red', '4':'purple'}) # not tested (> 1 second) + sage: s.rauzy_fractal_plot(n=150000, # not tested (> 1 second) + ....: opacity={'1':0.1,'2':1,'3':0.1,'4':0.1,'5':0.1}) #. Funny experiments by playing with the precision of the float numbers used to plot the fractal:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: s.rauzy_fractal_plot(prec=6) # not tested - sage: s.rauzy_fractal_plot(prec=9) # not tested - sage: s.rauzy_fractal_plot(prec=15) # not tested - sage: s.rauzy_fractal_plot(prec=19) # not tested - sage: s.rauzy_fractal_plot(prec=25) # not tested + sage: s.rauzy_fractal_plot(prec=6) # not tested + sage: s.rauzy_fractal_plot(prec=9) # not tested + sage: s.rauzy_fractal_plot(prec=15) # not tested + sage: s.rauzy_fractal_plot(prec=19) # not tested + sage: s.rauzy_fractal_plot(prec=25) # not tested #. Using the ``translate`` option to plot periodic tilings:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: s.rauzy_fractal_plot(n=10000, translate=[(0,0,0),(-1,0,1),(0,-1,1),(1,-1,0),(1,0,-1),(0,1,-1),(-1,1,0)]) # not tested takes > 1 second + sage: s.rauzy_fractal_plot(n=10000, # not tested (> 1 second) + ....: translate=[(0,0,0),(-1,0,1),(0,-1,1),(1,-1,0), + ....: (1,0,-1),(0,1,-1),(-1,1,0)]) :: sage: t = WordMorphism("a->aC,b->d,C->de,d->a,e->ab") # substitution found by Julien Bernat sage: V = [vector((0,0,1,0,-1)), vector((0,0,1,-1,0))] - sage: S = set(map(tuple, [i*V[0] + j*V[1] for i in [-1,0,1] for j in [-1,0,1]])) - sage: t.rauzy_fractal_plot(n=10000, translate=S, exchange=true) # not tested takes > 1 second + sage: S = set(map(tuple, [i*V[0] + j*V[1] + ....: for i in [-1,0,1] for j in [-1,0,1]])) + sage: t.rauzy_fractal_plot(n=10000, # not tested (> 1 second) + ....: translate=S, exchange=true) #. Using the ``translate`` option to plot arbitrary tilings with the fractal pieces. This can be used for example to plot the self-replicating tiling of the Rauzy fractal:: sage: s = WordMorphism({1:[1,2], 2:[3], 3:[4,3], 4:[5], 5:[6], 6:[1]}) - sage: s.rauzy_fractal_plot() # not tested takes > 1 second - sage: D = {1:[(0,0,0,0,0,0), (0,1,0,0,0,0)], 3:[(0,0,0,0,0,0), (0,1,0,0,0,0)], 6:[(0,1,0,0,0,0)]} - sage: s.rauzy_fractal_plot(n=30000, translate=D) # not tested takes > 1 second + sage: s.rauzy_fractal_plot() # not tested (> 1 second) + sage: D = {1: [(0,0,0,0,0,0), (0,1,0,0,0,0)], + ....: 3: [(0,0,0,0,0,0), (0,1,0,0,0,0)], 6: [(0,1,0,0,0,0)]} + sage: s.rauzy_fractal_plot(n=30000, translate=D) # not tested (> 1 second) #. Plot the projection of the canonical basis with the fractal:: - sage: s = WordMorphism({1:[2,1], 2:[3], 3:[6,4], 4:[5,1], 5:[6], 6:[7], 7:[8], 8:[9], 9:[1]}) - sage: s.rauzy_fractal_plot(plot_basis=True) # not tested takes > 1 second + sage: s = WordMorphism({1:[2,1], 2:[3], 3:[6,4], 4:[5,1], + ....: 5:[6], 6:[7], 7:[8], 8:[9], 9:[1]}) + sage: s.rauzy_fractal_plot(plot_basis=True) # not tested (> 1 second) TESTS:: sage: s = WordMorphism('a->ab,b->c,c->d,d->e,e->a') - sage: s.rauzy_fractal_plot(n=1000, colormap='Set1', opacity={'a':0.5,'b':1,'c':0.7,'d':0,'e':0.2}, plot_origin=(100,"black"), plot_basis=True, point_size=2.5) + sage: s.rauzy_fractal_plot(n=1000, colormap='Set1', # optional - sage.plot + ....: opacity={'a':0.5,'b':1,'c':0.7,'d':0,'e':0.2}, + ....: plot_origin=(100,"black"), plot_basis=True, + ....: point_size=2.5) Graphics object consisting of 10 graphics primitives REFERENCES: diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index 07db12ec123..a924eb45c03 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -45,7 +45,7 @@ [(0, 0), (1, 2), (-2, 6), (-1, 8), (-1, 5), (-1, 2), (-4, 6), (-3, 8)] sage: p.is_closed() False - sage: p.plot() + sage: p.plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives To obtain a list of all the available word path specific functions, @@ -1365,15 +1365,15 @@ def plot_projection(self, v=None, letters=None, color=None, ring=None, To remove the axis, do like this:: - sage: r = w.plot_projection(v) - sage: r.axes(False) - sage: r # long time (2s) + sage: r = w.plot_projection(v) # optional - sage.plot + sage: r.axes(False) # optional - sage.plot + sage: r # long time (2s) # optional - sage.plot Graphics object consisting of 200 graphics primitives You can assign different colors to each letter:: - sage: color = {'1':'purple', '2':(.2,.3,.4), '3': 'magenta'} - sage: w.plot_projection(v, color=color) # long time (2s) + sage: color = {'1': 'purple', '2': (.2,.3,.4), '3': 'magenta'} + sage: w.plot_projection(v, color=color) # long time (2s) # optional - sage.plot Graphics object consisting of 200 graphics primitives The 3d-Rauzy fractal:: @@ -1383,14 +1383,14 @@ def plot_projection(self, v=None, letters=None, color=None, ring=None, sage: v = s.pisot_eigenvector_right() sage: P = WordPaths('1234',[(1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)]) sage: w = P(D[:200]) - sage: w.plot_projection(v) + sage: w.plot_projection(v) # optional - sage.plot Graphics3d Object The dimension of vector space of the parent must be 3 or 4:: sage: P = WordPaths('ab', [(1, 0), (0, 1)]) sage: p = P('aabbabbab') - sage: p.plot_projection() + sage: p.plot_projection() # optional - sage.plot Traceback (most recent call last): ... TypeError: The dimension of the vector space (=2) must be 3 or 4 @@ -1444,7 +1444,7 @@ def projected_path(self, v=None, ring=None): sage: p = w.projected_path(v) sage: p Path: 1213121121312121312112131213121121312121... - sage: p[:20].plot() + sage: p[:20].plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives The ``ring`` argument allows to change the precision of the @@ -1530,42 +1530,42 @@ def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), A non closed path on the square grid:: sage: P = WordPaths('abAB') - sage: P('abababAABAB').plot() + sage: P('abababAABAB').plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives A closed path on the square grid:: - sage: P('abababAABABB').plot() + sage: P('abababAABABB').plot() # optional - sage.plot Graphics object consisting of 4 graphics primitives A Dyck path:: sage: P = WordPaths('()', steps='dyck') - sage: P('()()()((()))').plot() + sage: P('()()()((()))').plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives A path in the triangle grid:: sage: P = WordPaths('abcdef', steps='triangle_grid') - sage: P('abcdedededefab').plot() + sage: P('abcdedededefab').plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives A polygon of length 220 that tiles the plane in two ways:: sage: P = WordPaths('abAB') - sage: P('aBababAbabaBaBABaBabaBaBABAbABABaBabaBaBABaBababAbabaBaBABaBabaBaBABAbABABaBABAbAbabAbABABaBABAbABABaBabaBaBABAbABABaBABAbAbabAbABAbAbabaBababAbABAbAbabAbABABaBABAbAbabAbABAbAbabaBababAbabaBaBABaBababAbabaBababAbABAbAbab').plot() + sage: P('aBababAbabaBaBABaBabaBaBABAbABABaBabaBaBABaBababAbabaBaBABaBabaBaBABAbABABaBABAbAbabAbABABaBABAbABABaBabaBaBABAbABABaBABAbAbabAbABAbAbabaBababAbABAbAbabAbABABaBABAbAbabAbABAbAbabaBababAbabaBaBABaBababAbabaBababAbABAbAbab').plot() # optional - sage.plot Graphics object consisting of 4 graphics primitives With gridlines:: - sage: P('ababababab').plot(gridlines=True) + sage: P('ababababab').plot(gridlines=True) # optional - sage.plot TESTS:: sage: P = WordPaths('abAB') - sage: P().plot() + sage: P().plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives - sage: sum(map(plot,map(P,['a','A','b','B']))) + sage: sum(map(plot,map(P,['a','A','b','B']))) # optional - sage.plot Graphics object consisting of 12 graphics primitives """ G = Graphics() @@ -1614,44 +1614,44 @@ def animate(self): sage: P = WordPaths('abAB') sage: p = P('aaababbb') - sage: a = p.animate(); print(a) + sage: a = p.animate(); print(a) # optional - sage.plot Animation with 9 frames - sage: show(a) # long time # optional -- ImageMagick - sage: show(a, delay=35, iterations=3) # long time # optional -- ImageMagick + sage: show(a) # long time # optional -- ImageMagick sage.plot + sage: show(a, delay=35, iterations=3) # long time # optional -- ImageMagick sage.plot :: sage: P = WordPaths('abcdef',steps='triangle') sage: p = P('abcdef') - sage: a = p.animate(); print(a) + sage: a = p.animate(); print(a) # optional - sage.plot Animation with 8 frames - sage: show(a) # long time # optional -- ImageMagick + sage: show(a) # long time # optional -- ImageMagick sage.plot If the path is closed, the plain polygon is added at the end of the animation:: sage: P = WordPaths('abAB') sage: p = P('ababAbABABaB') - sage: a = p.animate(); print(a) + sage: a = p.animate(); print(a) # optional - sage.plot Animation with 14 frames - sage: show(a) # long time # optional -- ImageMagick + sage: show(a) # long time # optional -- ImageMagick sage.plot Another example illustrating a Fibonacci tile:: sage: w = words.fibonacci_tile(2) - sage: a = w.animate(); print(a) + sage: a = w.animate(); print(a) # optional - sage.plot Animation with 54 frames - sage: show(a) # long time # optional -- ImageMagick + sage: show(a) # long time # optional -- ImageMagick sage.plot The first 4 Fibonacci tiles in an animation:: - sage: a = words.fibonacci_tile(0).animate() - sage: b = words.fibonacci_tile(1).animate() - sage: c = words.fibonacci_tile(2).animate() - sage: d = words.fibonacci_tile(3).animate() - sage: print(a*b*c*d) + sage: a = words.fibonacci_tile(0).animate() # optional - sage.plot + sage: b = words.fibonacci_tile(1).animate() # optional - sage.plot + sage: c = words.fibonacci_tile(2).animate() # optional - sage.plot + sage: d = words.fibonacci_tile(3).animate() # optional - sage.plot + sage: print(a*b*c*d) # optional - sage.plot Animation with 296 frames - sage: show(a*b*c*d) # long time # optional -- ImageMagick + sage: show(a*b*c*d) # long time # optional -- ImageMagick sage.plot .. note:: @@ -1713,17 +1713,17 @@ def plot_directive_vector(self, options=dict(rgbcolor='blue')): Word Paths on the square grid sage: p = P('aaaccaccacacacaccccccbbdd'); p Path: aaaccaccacacacaccccccbbdd - sage: R = p.plot() + p.plot_directive_vector() - sage: R.axes(False) - sage: R.set_aspect_ratio(1) - sage: R.plot() + sage: R = p.plot() + p.plot_directive_vector() # optional - sage.plot + sage: R.axes(False) # optional - sage.plot + sage: R.set_aspect_ratio(1) # optional - sage.plot + sage: R.plot() # optional - sage.plot Graphics object consisting of 4 graphics primitives TESTS: A closed path:: - sage: P('acbd').plot_directive_vector() + sage: P('acbd').plot_directive_vector() # optional - sage.plot Graphics object consisting of 1 graphics primitive """ start = self.start_point() @@ -2020,12 +2020,12 @@ def plot(self, pathoptions=dict(rgbcolor='red',arrow_head=True,thickness=3), Word Paths over 2 steps sage: p = P('ababab'); p Path: ababab - sage: p.plot() + sage: p.plot() # optional - sage.plot Graphics3d Object sage: P = WordPaths('abcABC', steps='cube_grid') sage: p = P('abcabcAABBC') - sage: p.plot() + sage: p.plot() # optional - sage.plot Graphics3d Object """ diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index 9815645fbf8..c7ae4af2aaf 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -461,13 +461,13 @@ def plot(self, layout='tree', tree_root=0, tree_orientation='up', EXAMPLES:: sage: from sage.combinat.words.suffix_trees import SuffixTrie - sage: SuffixTrie(Word("cacao")).plot() + sage: SuffixTrie(Word("cacao")).plot() # optional - sage.plot Graphics object consisting of 38 graphics primitives TESTS:: sage: from sage.combinat.words.suffix_trees import SuffixTrie - sage: type(SuffixTrie(Word("cacao")).plot()) + sage: type(SuffixTrie(Word("cacao")).plot()) # optional - sage.plot """ tree = self.to_digraph() @@ -491,7 +491,7 @@ def show(self, *args, **kwds): sage: from sage.combinat.words.suffix_trees import SuffixTrie sage: w = Words("cao")("cac") sage: t = SuffixTrie(w) - sage: t.show() + sage: t.show() # optional - sage.plot """ self.plot(*args, **kwds).show() return @@ -865,17 +865,17 @@ def plot(self, word_labels=False, layout='tree', tree_root=0, EXAMPLES:: sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree - sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=True) + sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=True) # optional - sage.plot Graphics object consisting of 23 graphics primitives - sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=False) + sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=False) # optional - sage.plot Graphics object consisting of 23 graphics primitives TESTS:: sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree - sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=True)) + sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=True)) # optional - sage.plot - sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=False)) + sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=False)) # optional - sage.plot """ tree = self.to_digraph(word_labels=word_labels) @@ -904,8 +904,8 @@ def show(self, word_labels=None, *args, **kwds): sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree sage: w = Words("cao")("cacao") sage: t = ImplicitSuffixTree(w) - sage: t.show(word_labels=True) - sage: t.show(word_labels=False) + sage: t.show(word_labels=True) # optional - sage.plot + sage: t.show(word_labels=False) # optional - sage.plot """ self.plot(word_labels=word_labels, *args, **kwds).show() return diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index 3a0fb332d51..f046db3c46e 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -803,7 +803,7 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): The characteristic sturmian word of slope `(\sqrt{3}-1)/2`:: - sage: words.CharacteristicSturmianWord((sqrt(3)-1)/2) + sage: words.CharacteristicSturmianWord((sqrt(3)-1)/2) # optional - sage.symbolic word: 0100100101001001001010010010010100100101... The same word defined from the continued fraction expansion of @@ -846,17 +846,17 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): :: - sage: words.CharacteristicSturmianWord(1/golden_ratio^2) + sage: words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic word: 0100101001001010010100100101001001010010... - sage: _.length() + sage: _.length() # optional - sage.symbolic +Infinity :: - sage: a = words.LowerMechanicalWord(1/pi)[1:] - sage: b = words.UpperMechanicalWord(1/pi)[1:] - sage: c = words.CharacteristicSturmianWord(1/pi) - sage: n = 500; a[:n] == b[:n] == c[:n] + sage: a = words.LowerMechanicalWord(1/pi)[1:] # optional - sage.symbolic + sage: b = words.UpperMechanicalWord(1/pi)[1:] # optional - sage.symbolic + sage: c = words.CharacteristicSturmianWord(1/pi) # optional - sage.symbolic + sage: n = 500; a[:n] == b[:n] == c[:n] # optional - sage.symbolic True :: diff --git a/src/sage/combinat/yang_baxter_graph.py b/src/sage/combinat/yang_baxter_graph.py index 426095f6332..f5e5646c633 100644 --- a/src/sage/combinat/yang_baxter_graph.py +++ b/src/sage/combinat/yang_baxter_graph.py @@ -79,25 +79,25 @@ def YangBaxterGraph(partition=None, root=None, operators=None): sage: swappers = [SwapIncreasingOperator(i) for i in range(3)] sage: Y = YangBaxterGraph(root=(1,2,3,4), operators=swappers); Y Yang-Baxter graph with root vertex (1, 2, 3, 4) - sage: Y.plot() + sage: Y.plot() # optional - sage.plot Graphics object consisting of 97 graphics primitives The Cayley graph of a finite group can be realized as a Yang-Baxter graph:: sage: def left_multiplication_by(g): - ....: return lambda h : h*g + ....: return lambda h: h*g sage: G = CyclicPermutationGroup(4) sage: operators = [ left_multiplication_by(gen) for gen in G.gens() ] sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y Yang-Baxter graph with root vertex () - sage: Y.plot(edge_labels=False) + sage: Y.plot(edge_labels=False) # optional - sage.plot Graphics object consisting of 9 graphics primitives sage: G = SymmetricGroup(4) sage: operators = [left_multiplication_by(gen) for gen in G.gens()] sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y Yang-Baxter graph with root vertex () - sage: Y.plot(edge_labels=False) + sage: Y.plot(edge_labels=False) # optional - sage.plot Graphics object consisting of 96 graphics primitives AUTHORS: @@ -392,9 +392,9 @@ def plot(self, *args, **kwds): sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator sage: ops = [SwapIncreasingOperator(i) for i in range(4)] sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops) - sage: Y.plot() + sage: Y.plot() # optional - sage.plot Graphics object consisting of 16 graphics primitives - sage: Y.plot(edge_labels=False) + sage: Y.plot(edge_labels=False) # optional - sage.plot Graphics object consisting of 11 graphics primitives """ if "edge_labels" not in kwds: From 0cff99e0c898aac6d665c141e55d2459541c4779 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 17 May 2023 15:45:12 -0700 Subject: [PATCH 08/26] sage.combinat: More # optional --- .../finite_dimensional_algebras_with_basis.py | 24 +- src/sage/categories/group_algebras.py | 2 +- src/sage/categories/homset.py | 6 +- src/sage/categories/map.pyx | 2 + src/sage/categories/primer.py | 20 +- src/sage/categories/pushout.py | 20 +- src/sage/categories/quotient_fields.py | 20 +- src/sage/categories/rings.py | 2 +- src/sage/categories/sets_cat.py | 2 +- src/sage/categories/simplicial_sets.py | 2 +- src/sage/combinat/cartesian_product.py | 24 +- src/sage/combinat/designs/block_design.py | 4 +- src/sage/combinat/diagram_algebras.py | 40 ++-- .../finite_state_machine_generators.py | 144 ++++++------ src/sage/combinat/free_module.py | 207 +++++++++--------- src/sage/combinat/integer_lists/invlex.pyx | 2 +- src/sage/combinat/integer_vector.py | 79 ++++--- src/sage/combinat/ranker.py | 2 +- src/sage/combinat/tutorial.py | 2 +- 19 files changed, 311 insertions(+), 293 deletions(-) diff --git a/src/sage/categories/finite_dimensional_algebras_with_basis.py b/src/sage/categories/finite_dimensional_algebras_with_basis.py index ec4a65b8db1..ce2bf641d7f 100644 --- a/src/sage/categories/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_algebras_with_basis.py @@ -482,8 +482,8 @@ def orthogonal_idempotents_central_mod_radical(self): sage: Z12 = Monoids().Finite().example(); Z12 An example of a finite multiplicative monoid: the integers modulo 12 sage: A = Z12.algebra(QQ) - sage: idempotents = A.orthogonal_idempotents_central_mod_radical() - sage: sorted(idempotents, key=str) + sage: idempotents = A.orthogonal_idempotents_central_mod_radical() # optional - sage.rings.number_field + sage: sorted(idempotents, key=str) # optional - sage.rings.number_field [-B[0] + 1/2*B[4] + 1/2*B[8], 1/2*B[4] - 1/2*B[8], 1/2*B[9] + 1/2*B[3] - B[0], @@ -493,26 +493,26 @@ def orthogonal_idempotents_central_mod_radical(self): 1/4*B[1] - 1/2*B[9] - 1/2*B[3] + 1/4*B[11] + 1/4*B[5] + 1/4*B[7] + B[0] - 1/2*B[4] - 1/2*B[8], 1/4*B[1] - 1/4*B[5] + 1/4*B[7] - 1/4*B[11] - 1/2*B[4] + 1/2*B[8], B[0]] - sage: sum(idempotents) == 1 + sage: sum(idempotents) == 1 # optional - sage.rings.number_field True - sage: all(e*e == e for e in idempotents) + sage: all(e*e == e for e in idempotents) # optional - sage.rings.number_field True - sage: all(e*f == 0 and f*e == 0 + sage: all(e*f == 0 and f*e == 0 # optional - sage.rings.number_field ....: for e in idempotents for f in idempotents if e != f) True This is best tested with:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) + sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.rings.number_field True We construct orthogonal idempotents for the algebra of the `0`-Hecke monoid:: - sage: from sage.monoids.hecke_monoid import HeckeMonoid - sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) - sage: idempotents = A.orthogonal_idempotents_central_mod_radical() - sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) + sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups + sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) # optional - sage.groups + sage: idempotents = A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups + sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.groups True """ one = self.one() @@ -666,7 +666,7 @@ def cartan_invariants_matrix(self): sage: Z12 = Monoids().Finite().example(); Z12 An example of a finite multiplicative monoid: the integers modulo 12 sage: A = Z12.algebra(QQ) # optional - sage.modules - sage: A.cartan_invariants_matrix() # optional - sage.modules + sage: A.cartan_invariants_matrix() # optional - sage.modules sage.rings.number_fields [1 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0] [0 0 2 0 0 0 0 0 0] @@ -681,7 +681,7 @@ def cartan_invariants_matrix(self): sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups sage.modules sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) # optional - sage.groups sage.modules - sage: A.cartan_invariants_matrix() # optional - sage.groups sage.modules + sage: A.cartan_invariants_matrix() # optional - sage.groups sage.modules sage.rings.number_field [1 0 0 0 0 0 0 0] [0 2 1 0 1 1 0 0] [0 1 1 0 1 0 0 0] diff --git a/src/sage/categories/group_algebras.py b/src/sage/categories/group_algebras.py index 1bc40687c4f..36c7e069f34 100644 --- a/src/sage/categories/group_algebras.py +++ b/src/sage/categories/group_algebras.py @@ -315,7 +315,7 @@ def is_integral_domain(self, proof=True): sage: S2 = SymmetricGroup(2) # optional - sage.groups sage: GroupAlgebra(S2).is_integral_domain() # optional - sage.groups sage.modules False - sage: S1 = SymmetricGroup(1) + sage: S1 = SymmetricGroup(1) # optional - sage.groups sage: GroupAlgebra(S1).is_integral_domain() # optional - sage.groups sage.modules True sage: GroupAlgebra(S1, IntegerModRing(4)).is_integral_domain() # optional - sage.groups sage.modules diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index 6554c895ff4..a5a438f8727 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -584,10 +584,10 @@ class Homset(Set_generic): Homsets of unique parents are unique as well:: - sage: H = End(AffineSpace(2, names='x,y')) - sage: loads(dumps(AffineSpace(2, names='x,y'))) is AffineSpace(2, names='x,y') + sage: H = End(AffineSpace(2, names='x,y')) # optional - sage.modules + sage: loads(dumps(AffineSpace(2, names='x,y'))) is AffineSpace(2, names='x,y') # optional - sage.modules True - sage: loads(dumps(H)) is H + sage: loads(dumps(H)) is H # optional - sage.modules True Conversely, homsets of non-unique parents are non-unique:: diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index 39d37acc2ae..50853348b53 100644 --- a/src/sage/categories/map.pyx +++ b/src/sage/categories/map.pyx @@ -279,6 +279,7 @@ cdef class Map(Element): sage: import gc sage: _ = gc.collect() sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: x = None sage: numberQuadFields = len([x for x in gc.get_objects() # optional - sage.rings.number_field ....: if isinstance(x, C)]) sage: del Q, x # optional - sage.rings.number_field @@ -344,6 +345,7 @@ cdef class Map(Element): sage: import gc sage: _ = gc.collect() sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: x = None sage: numberQuadFields = len([x for x in gc.get_objects() # optional - sage.rings.number_field ....: if isinstance(x, C)]) sage: del Q, x # optional - sage.rings.number_field diff --git a/src/sage/categories/primer.py b/src/sage/categories/primer.py index 84ab37f34b7..8b71d5c3a94 100644 --- a/src/sage/categories/primer.py +++ b/src/sage/categories/primer.py @@ -82,8 +82,8 @@ 6 sage: A = random_matrix(ZZ, 6, 3, x=7) # optional - sage.modules - sage: L = LatticePolytope(A.rows()) # optional - sage.geometry.polyhedron - sage: L.npoints() # oops! # random # optional - sage.geometry.polyhedron + sage: L = LatticePolytope(A.rows()) # optional - sage.geometry.polyhedron sage.modules + sage: L.npoints() # oops! # random # optional - sage.geometry.polyhedron sage.modules 37 - How to ensure robustness? @@ -415,16 +415,16 @@ class implements: 6*(x + 1)^2 sage: R. = PolynomialRing(QQ, sparse=True) - sage: pQ = R ( p ) - sage: type(pQ) + sage: pQ = R(p) # optional - sage.symbolic + sage: type(pQ) # optional - sage.symbolic - sage: pQ.factor() + sage: pQ.factor() # optional - sage.symbolic (6) * (x + 1)^2 - sage: pZ = ZZ['x'] ( p ) - sage: type(pZ) + sage: pZ = ZZ['x'](p) # optional - sage.symbolic + sage: type(pZ) # optional - sage.symbolic - sage: pZ.factor() + sage: pZ.factor() # optional - sage.symbolic 2 * 3 * (x + 1)^2 Factoring integers, expressions, or polynomials are distinct tasks, @@ -444,9 +444,9 @@ class implements: sage: i._pow_.__module__ # not tested (Issue #24275) 'sage.categories.semigroups' - sage: pQ._mul_.__module__ + sage: pQ._mul_.__module__ # optional - sage.symbolic 'sage.rings.polynomial.polynomial_element_generic' - sage: pQ._pow_.__module__ # not tested (Issue #24275) + sage: pQ._pow_.__module__ # not tested (Issue #24275) # optional - sage.symbolic 'sage.categories.semigroups' We see that integers and polynomials have each their own diff --git a/src/sage/categories/pushout.py b/src/sage/categories/pushout.py index 69b936bb3ff..7f0a20bbd0a 100644 --- a/src/sage/categories/pushout.py +++ b/src/sage/categories/pushout.py @@ -1758,10 +1758,11 @@ def __init__(self, var, multi_variate=False): sage: F2 = LaurentPolynomialFunctor('s', multi_variate=True) sage: F3 = LaurentPolynomialFunctor(['s','t']) sage: F1(F2(QQ)) - Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in s over Rational Field - sage: F2(F1(QQ)) + Univariate Laurent Polynomial Ring in t over + Univariate Laurent Polynomial Ring in s over Rational Field + sage: F2(F1(QQ)) # optional - sage.modules Multivariate Laurent Polynomial Ring in t, s over Rational Field - sage: F3(QQ) + sage: F3(QQ) # optional - sage.modules Multivariate Laurent Polynomial Ring in s, t over Rational Field """ @@ -1782,10 +1783,11 @@ def _apply_functor(self, R): sage: F2 = LaurentPolynomialFunctor('s', multi_variate=True) sage: F3 = LaurentPolynomialFunctor(['s','t']) sage: F1(F2(QQ)) # indirect doctest - Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in s over Rational Field - sage: F2(F1(QQ)) + Univariate Laurent Polynomial Ring in t over + Univariate Laurent Polynomial Ring in s over Rational Field + sage: F2(F1(QQ)) # optional - sage.modules Multivariate Laurent Polynomial Ring in t, s over Rational Field - sage: F3(QQ) + sage: F3(QQ) # optional - sage.modules Multivariate Laurent Polynomial Ring in s, t over Rational Field """ @@ -3945,7 +3947,7 @@ def __init__(self, box): sage: from sage.categories.pushout import BlackBoxConstructionFunctor sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # optional - sage.symbolic + sage: FM == FG # optional - sage.libs.gap sage.symbolic False sage: FM == loads(dumps(FM)) # optional - sage.symbolic True @@ -3977,7 +3979,7 @@ def __eq__(self, other): sage: from sage.categories.pushout import BlackBoxConstructionFunctor sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # indirect doctest # optional - sage.symbolic + sage: FM == FG # indirect doctest # optional - sage.libs.gap sage.symbolic False sage: FM == loads(dumps(FM)) # optional - sage.symbolic True @@ -3996,7 +3998,7 @@ def __ne__(self, other): sage: from sage.categories.pushout import BlackBoxConstructionFunctor sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM != FG # indirect doctest # optional - sage.symbolic + sage: FM != FG # indirect doctest # optional - sage.libs.gap sage.symbolic True sage: FM != loads(dumps(FM)) # optional - sage.symbolic False diff --git a/src/sage/categories/quotient_fields.py b/src/sage/categories/quotient_fields.py index c62c79ee11f..181cd0ff611 100644 --- a/src/sage/categories/quotient_fields.py +++ b/src/sage/categories/quotient_fields.py @@ -408,9 +408,9 @@ def partial_fraction_decomposition(self, decompose_powers=True): We can decompose over a given algebraic extension:: - sage: R. = QQ[sqrt(2)][] # optional - sage.rings.number_field - sage: r = 1/(x^4+1) # optional - sage.rings.number_field - sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field + sage: R. = QQ[sqrt(2)][] # optional - sage.rings.number_field sage.symbolic + sage: r = 1/(x^4+1) # optional - sage.rings.number_field sage.symbolic + sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field sage.symbolic (0, [(-1/4*sqrt2*x + 1/2)/(x^2 - sqrt2*x + 1), (1/4*sqrt2*x + 1/2)/(x^2 + sqrt2*x + 1)]) @@ -425,8 +425,7 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = QQ[] sage: r = 1/(x^4+2) - sage: N = r.denominator().splitting_field('a') # optional - sage.rings.number_field - sage: N # optional - sage.rings.number_field + sage: N = r.denominator().splitting_field('a'); N # optional - sage.rings.number_field Number Field in a with defining polynomial x^8 - 8*x^6 + 28*x^4 + 16*x^2 + 36 sage: R1. = N[] # optional - sage.rings.number_field sage: r1 = 1/(x1^4+2) # optional - sage.rings.number_field @@ -452,11 +451,14 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = RealField(20)[] sage: q = 1/(x^2 + x + 2)^2 + 1/(x-1); q - (x^4 + 2.0000*x^3 + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) + (x^4 + 2.0000*x^3 + + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.rings.number_field - [1.0000/(x - 1.0000), 1.0000/(x^4 + 2.0000*x^3 + 5.0000*x^2 + 4.0000*x + 4.0000)] - sage: sum(parts) - (x^4 + 2.0000*x^3 + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) + [1.0000/(x - 1.0000), + 1.0000/(x^4 + 2.0000*x^3 + 5.0000*x^2 + 4.0000*x + 4.0000)] + sage: sum(parts) # optional - sage.rings.number_field + (x^4 + 2.0000*x^3 + + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) TESTS: diff --git a/src/sage/categories/rings.py b/src/sage/categories/rings.py index 07ffd95d02b..1449333d973 100644 --- a/src/sage/categories/rings.py +++ b/src/sage/categories/rings.py @@ -218,7 +218,7 @@ def extend_to_fraction_field(self): Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 - sage: g = f.extend_to_fraction_field(); g + sage: g = f.extend_to_fraction_field(); g # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 diff --git a/src/sage/categories/sets_cat.py b/src/sage/categories/sets_cat.py index 069ebc5337c..c2d87e43b0c 100644 --- a/src/sage/categories/sets_cat.py +++ b/src/sage/categories/sets_cat.py @@ -2796,7 +2796,7 @@ def _register_realization(self, realization): over Univariate Polynomial Ring in x over Rational Field sage: class ANewRealizationOfA(CombinatorialFreeModule): # optional - sage.combinat sage.modules ....: pass - sage: category = A.Realizations() & Algebras(QQ[x]).WithBasis() # optional - sage.combinat sage.modules + sage: category = A.Realizations() & Algebras(QQ['x']).WithBasis() # optional - sage.combinat sage.modules sage: R = ANewRealizationOfA(A.base_ring(), A.F().basis().keys(), # optional - sage.combinat sage.modules ....: category=category) sage: R in A.realizations() # indirect doctest # optional - sage.combinat sage.modules diff --git a/src/sage/categories/simplicial_sets.py b/src/sage/categories/simplicial_sets.py index 952053b907d..43a13dfe473 100644 --- a/src/sage/categories/simplicial_sets.py +++ b/src/sage/categories/simplicial_sets.py @@ -560,7 +560,7 @@ def universal_cover(self): (f * f, e): ((f, 1), s_0 (1, e), (f, e)), (f * f * f, 1): ((f * f, e), s_0 (f, 1), s_1 (f, 1), (f * f, 1)), (f * f * f, e): ((f * f, 1), s_0 (f, e), s_1 (f, e), (f * f, e))} - sage: C.fundamental_group() + sage: C.fundamental_group() # optional - sage.groups Finitely presented group < | > """ return self.universal_cover_map().domain() diff --git a/src/sage/combinat/cartesian_product.py b/src/sage/combinat/cartesian_product.py index b15185685c7..7ab49439557 100644 --- a/src/sage/combinat/cartesian_product.py +++ b/src/sage/combinat/cartesian_product.py @@ -51,27 +51,27 @@ class for ``cartesian_product``; sage: F1 = ['a', 'b'] sage: F2 = [1, 2, 3, 4] - sage: F3 = Permutations(3) + sage: F3 = Permutations(3) # optional - sage.combinat sage: from sage.combinat.cartesian_product import CartesianProduct_iters - sage: C = CartesianProduct_iters(F1, F2, F3) - sage: c = cartesian_product([F1, F2, F3]) + sage: C = CartesianProduct_iters(F1, F2, F3) # optional - sage.combinat + sage: c = cartesian_product([F1, F2, F3]) # optional - sage.combinat - sage: type(C.an_element()) + sage: type(C.an_element()) # optional - sage.combinat - sage: type(c.an_element()) + sage: type(c.an_element()) # optional - sage.combinat - sage: l = ['a', 1, Permutation([3,2,1])] - sage: l in C + sage: l = ['a', 1, Permutation([3,2,1])] # optional - sage.combinat + sage: l in C # optional - sage.combinat True - sage: l in c + sage: l in c # optional - sage.combinat False - sage: elt = c(l) - sage: elt + sage: elt = c(l) # optional - sage.combinat + sage: elt # optional - sage.combinat ('a', 1, [3, 2, 1]) - sage: elt in c + sage: elt in c # optional - sage.combinat True - sage: elt.parent() is c + sage: elt.parent() is c # optional - sage.combinat True """ diff --git a/src/sage/combinat/designs/block_design.py b/src/sage/combinat/designs/block_design.py index cb81f997f3d..1d189fdd409 100644 --- a/src/sage/combinat/designs/block_design.py +++ b/src/sage/combinat/designs/block_design.py @@ -401,7 +401,7 @@ def q3_minus_one_matrix(K): sage: from sage.combinat.designs.block_design import q3_minus_one_matrix sage: m = q3_minus_one_matrix(GF(3)) - sage: m.multiplicative_order() == 3**3 - 1 + sage: m.multiplicative_order() == 3**3 - 1 # optional - sage.symbolic True sage: m = q3_minus_one_matrix(GF(4, 'a')) # optional - sage.symbolic @@ -409,7 +409,7 @@ def q3_minus_one_matrix(K): True sage: m = q3_minus_one_matrix(GF(5)) - sage: m.multiplicative_order() == 5**3 - 1 + sage: m.multiplicative_order() == 5**3 - 1 # optional - sage.symbolic True sage: m = q3_minus_one_matrix(GF(9, 'a')) # optional - sage.symbolic diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py index 4909dc33f09..6dcba8094ec 100644 --- a/src/sage/combinat/diagram_algebras.py +++ b/src/sage/combinat/diagram_algebras.py @@ -2053,9 +2053,9 @@ def order(self): EXAMPLES:: - sage: q = var('q') - sage: PA = PartitionAlgebra(2, q) - sage: PA.order() + sage: q = var('q') # optional - sage.symbolic + sage: PA = PartitionAlgebra(2, q) # optional - sage.symbolic + sage: PA.order() # optional - sage.symbolic 2 """ return self._k @@ -2412,23 +2412,24 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): :: - sage: q = var('q') - sage: PA = PartitionAlgebra(2, q); PA + sage: q = var('q') # optional - sage.symbolic + sage: PA = PartitionAlgebra(2, q); PA # optional - sage.symbolic Partition Algebra of rank 2 with parameter q over Symbolic Ring - sage: PA([[1,2],[-2,-1]])^2 == q*PA([[1,2],[-2,-1]]) + sage: PA([[1,2],[-2,-1]])^2 == q*PA([[1,2],[-2,-1]]) # optional - sage.symbolic True - sage: (PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 == (4*q-4)*PA([[1, 2], [-2, -1]]) + PA([[2, -2], [1, -1]]) + sage: ((PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 # optional - sage.symbolic + ....: == (4*q-4)*PA([[1, 2], [-2, -1]]) + PA([[2, -2], [1, -1]])) True The identity element of the partition algebra is the set partition `\{\{1,-1\}, \{2,-2\}, \ldots, \{k,-k\}\}`:: - sage: P = PA.basis().list() - sage: PA.one() + sage: P = PA.basis().list() # optional - sage.symbolic + sage: PA.one() # optional - sage.symbolic P{{-2, 2}, {-1, 1}} - sage: PA.one() * P[7] == P[7] + sage: PA.one() * P[7] == P[7] # optional - sage.symbolic True - sage: P[7] * PA.one() == P[7] + sage: P[7] * PA.one() == P[7] # optional - sage.symbolic True We now give some further examples of the use of the other arguments. @@ -2445,21 +2446,22 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): sage: PA = PartitionAlgebra(2, 5, base_ring=ZZ, prefix='B') sage: PA Partition Algebra of rank 2 with parameter 5 over Integer Ring - sage: (PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 == 16*PA([[-2, -1], [1, 2]]) + PA([[2, -2], [1, -1]]) + sage: ((PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 + ....: == 16*PA([[-2, -1], [1, 2]]) + PA([[2, -2], [1, -1]])) True Symmetric group algebra elements and elements from other subalgebras of the partition algebra (e.g., ``BrauerAlgebra`` and ``TemperleyLiebAlgebra``) can also be coerced into the partition algebra:: - sage: S = SymmetricGroupAlgebra(SR, 2) - sage: B = BrauerAlgebra(2, x, SR) - sage: A = PartitionAlgebra(2, x, SR) - sage: S([2,1])*A([[1,-1],[2,-2]]) + sage: S = SymmetricGroupAlgebra(SR, 2) # optional - sage.symbolic + sage: B = BrauerAlgebra(2, x, SR) # optional - sage.symbolic + sage: A = PartitionAlgebra(2, x, SR) # optional - sage.symbolic + sage: S([2,1]) * A([[1,-1],[2,-2]]) # optional - sage.symbolic P{{-2, 1}, {-1, 2}} - sage: B([[-1,-2],[2,1]]) * A([[1],[-1],[2,-2]]) + sage: B([[-1,-2],[2,1]]) * A([[1],[-1],[2,-2]]) # optional - sage.symbolic P{{-2}, {-1}, {1, 2}} - sage: A([[1],[-1],[2,-2]]) * B([[-1,-2],[2,1]]) + sage: A([[1],[-1],[2,-2]]) * B([[-1,-2],[2,1]]) # optional - sage.symbolic P{{-2, -1}, {1}, {2}} The same is true if the elements come from a subalgebra of a partition @@ -2470,7 +2472,7 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): sage: S = SymmetricGroupAlgebra(ZZ, 2) sage: B = BrauerAlgebra(2, q, ZZ[q]) sage: A = PartitionAlgebra(3, q, R) - sage: S([2,1])*A([[1,-1],[2,-3],[3,-2]]) + sage: S([2,1]) * A([[1,-1],[2,-3],[3,-2]]) P{{-3, 1}, {-2, 3}, {-1, 2}} sage: A(B([[-1,-2],[2,1]])) P{{-3, 3}, {-2, -1}, {1, 2}} diff --git a/src/sage/combinat/finite_state_machine_generators.py b/src/sage/combinat/finite_state_machine_generators.py index ed5cca2588b..b5b8abbbd9e 100644 --- a/src/sage/combinat/finite_state_machine_generators.py +++ b/src/sage/combinat/finite_state_machine_generators.py @@ -1079,15 +1079,15 @@ def _parse_recursion_equation_(self, equation, base, function, var, EXAMPLES:: - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: transducers._parse_recursion_equation_( + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic ....: f(8*n + 7) == f(2*n + 3) + 5, ....: 2, f, n) RecursionRule(K=3, r=7, k=1, s=3, t=[5]) - sage: transducers._parse_recursion_equation_( + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic ....: f(42) == 5, ....: 2, f, n) {42: [5]} @@ -1096,14 +1096,14 @@ def _parse_recursion_equation_(self, equation, base, function, var, The following tests check that the equations are well-formed:: - sage: transducers._parse_recursion_equation_(f(4*n + 1), 2, f, n) + sage: transducers._parse_recursion_equation_(f(4*n + 1), 2, f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: f(4*n + 1) is not an equation with ==. :: - sage: transducers._parse_recursion_equation_(f(n) + 1 == f(2*n), + sage: transducers._parse_recursion_equation_(f(n) + 1 == f(2*n), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1111,7 +1111,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n, 5) == 3, + sage: transducers._parse_recursion_equation_(f(2*n, 5) == 3, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1119,7 +1119,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(1/n) == f(n) + 3, + sage: transducers._parse_recursion_equation_(f(1/n) == f(n) + 3, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1127,7 +1127,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(n^2 + 5) == 3, + sage: transducers._parse_recursion_equation_(f(n^2 + 5) == 3, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1135,7 +1135,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(3*n + 5) == f(n) + 7, + sage: transducers._parse_recursion_equation_(f(3*n + 5) == f(n) + 7, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1143,7 +1143,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(n + 5) == f(n) + 7, + sage: transducers._parse_recursion_equation_(f(n + 5) == f(n) + 7, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1151,7 +1151,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_( + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic ....: f(2*n + 1) == f(n + 1) + f(n) + 2, ....: 2, f, n) Traceback (most recent call last): @@ -1161,7 +1161,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n) + 2, + sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n) + 2, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1170,7 +1170,8 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n) + n + 2, + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + ....: f(2*n + 1) == f(n) + n + 2, ....: 2, f, n) Traceback (most recent call last): ... @@ -1178,7 +1179,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1186,7 +1187,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n, 2), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n, 2), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1194,7 +1195,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(1/n), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(1/n), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1202,7 +1203,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n^2 + 5), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n^2 + 5), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1210,7 +1211,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(3*n + 5), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(3*n + 5), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1218,7 +1219,8 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f((1/2)*n + 5), + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + ....: f(2*n + 1) == f((1/2)*n + 5), ....: QQ(2), f, n) Traceback (most recent call last): ... @@ -1226,7 +1228,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(2*n + 5), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(2*n + 5), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1432,17 +1434,17 @@ def Recursion(self, recursions, base, function=None, var=None, - The following example computes the Hamming weight of the ternary expansion of integers. :: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(3*n + 1) == f(n) + 1, ....: f(3*n + 2) == f(n) + 1, ....: f(3*n) == f(n), ....: f(0) == 0], ....: 3, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (0, 0): 1|1, Transition from (0, 0) to (0, 0): 2|1] @@ -1450,13 +1452,13 @@ def Recursion(self, recursions, base, function=None, var=None, To illustrate what this transducer does, we consider the example of `n=601`:: - sage: ternary_expansion = 601.digits(base=3) - sage: ternary_expansion + sage: ternary_expansion = 601.digits(base=3) # optional - sage.symbolic + sage: ternary_expansion # optional - sage.symbolic [1, 2, 0, 1, 1, 2] - sage: weight_sequence = T(ternary_expansion) - sage: weight_sequence + sage: weight_sequence = T(ternary_expansion) # optional - sage.symbolic + sage: weight_sequence # optional - sage.symbolic [1, 1, 1, 1, 1] - sage: sum(weight_sequence) + sage: sum(weight_sequence) # optional - sage.symbolic 5 Note that the digit zero does not show up in the output because @@ -1466,24 +1468,24 @@ def Recursion(self, recursions, base, function=None, var=None, - The following example computes the Hamming weight of the non-adjacent form, cf. the :wikipedia:`Non-adjacent_form`. :: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(4*n + 1) == f(n) + 1, ....: f(4*n - 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 0], ....: 2, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (0, 0): 0|1, Transition from (1, 1) to (1, 0): 1|1, Transition from (1, 0) to (1, 1): 0|-, Transition from (1, 0) to (1, 0): 1|-] - sage: [(s.label(), s.final_word_out) + sage: [(s.label(), s.final_word_out) # optional - sage.symbolic ....: for s in T.iter_final_states()] [((0, 0), []), ((1, 1), [1]), @@ -1505,9 +1507,9 @@ def Recursion(self, recursions, base, function=None, var=None, sage: binary_expansion = 29.digits(base=2) sage: binary_expansion [1, 0, 1, 1, 1] - sage: T(binary_expansion) + sage: T(binary_expansion) # optional - sage.symbolic [1, 1, 1] - sage: sum(T(binary_expansion)) + sage: sum(T(binary_expansion)) # optional - sage.symbolic 3 Indeed, the given non-adjacent form has three non-zero @@ -1533,11 +1535,11 @@ def Recursion(self, recursions, base, function=None, var=None, the point of view of this method---is a contradicting recursion. We override this by the parameter ``is_zero``. :: - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f w') + sage: function('f w') # optional - sage.symbolic (f, w) - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n) == f(n) + w(0), ....: f(4*n + 1) == f(n) + w(1, 0), ....: f(4*n - 1) == f(n) + w(-1, 0), @@ -1545,14 +1547,14 @@ def Recursion(self, recursions, base, function=None, var=None, ....: 2, f, n, ....: word_function=w, ....: is_zero=lambda x: sum(x).is_zero()) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|0, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (0, 0): 0|1,0, Transition from (1, 1) to (1, 0): 1|-1,0, Transition from (1, 0) to (1, 1): 0|-, Transition from (1, 0) to (1, 0): 1|0] - sage: for s in T.iter_states(): + sage: for s in T.iter_states(): # optional - sage.symbolic ....: print("{} {}".format(s, s.final_word_out)) (0, 0) [] (1, 1) [1, 0] @@ -1560,7 +1562,7 @@ def Recursion(self, recursions, base, function=None, var=None, We again consider the example of `n=29`:: - sage: T(29.digits(base=2)) + sage: T(29.digits(base=2)) # optional - sage.symbolic [1, 0, -1, 0, 0, 1, 0] The same transducer can also be entered bypassing the @@ -1574,22 +1576,22 @@ def Recursion(self, recursions, base, function=None, var=None, ....: (0, [])], ....: 2, ....: is_zero=lambda x: sum(x).is_zero()) - sage: TR == T + sage: TR == T # optional - sage.symbolic True - Here is an artificial example where some of the `s` are negative:: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n-1) + 1, ....: f(2*n) == f(n), ....: f(1) == 1, ....: f(0) == 0], 2, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (-1, 1): 0|1, @@ -1600,7 +1602,7 @@ def Recursion(self, recursions, base, function=None, var=None, Transition from (-1, 2) to (0, 0): 1|1, Transition from (1, 2) to (-1, 2): 0|1, Transition from (1, 2) to (1, 2): 1|1] - sage: [(s.label(), s.final_word_out) + sage: [(s.label(), s.final_word_out) # optional - sage.symbolic ....: for s in T.iter_final_states()] [((0, 0), []), ((1, 1), [1]), @@ -1611,7 +1613,7 @@ def Recursion(self, recursions, base, function=None, var=None, - Abelian complexity of the paperfolding sequence (cf. [HKP2015]_, Example 2.8):: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(4*n) == f(2*n), ....: f(4*n+2) == f(2*n+1)+1, ....: f(16*n+1) == f(8*n+1), @@ -1621,7 +1623,7 @@ def Recursion(self, recursions, base, function=None, var=None, ....: f(1) == 2, f(0) == 0] ....: + [f(16*n+jj) == f(2*n+1)+2 for jj in [3,7,9,13]], ....: 2, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 1): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (0, 1) to (0, 1): 0|-, @@ -1642,7 +1644,7 @@ def Recursion(self, recursions, base, function=None, var=None, Transition from (7, 3) to (2, 1): 1|1, Transition from (2, 1) to (1, 1): 0|1, Transition from (2, 1) to (2, 1): 1|-] - sage: for s in T.iter_states(): + sage: for s in T.iter_states(): # optional - sage.symbolic ....: print("{} {}".format(s, s.final_word_out)) (0, 0) [] (0, 1) [] @@ -1654,52 +1656,52 @@ def Recursion(self, recursions, base, function=None, var=None, (3, 3) [2, 2] (7, 3) [2, 2] (2, 1) [1, 2] - sage: list(sum(T(n.bits())) for n in srange(1, 21)) + sage: list(sum(T(n.bits())) for n in srange(1, 21)) # optional - sage.symbolic [2, 3, 4, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 4, 3, 4, 5, 6, 5] - We now demonstrate the use of the ``output_rings`` parameter. If no ``output_rings`` are specified, the output labels are converted into ``ZZ``:: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 2], ....: 2, f, n) - sage: for t in T.transitions(): + sage: for t in T.transitions(): # optional - sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Integer Ring] - sage: [x.parent() for x in T.states()[0].final_word_out] + sage: [x.parent() for x in T.states()[0].final_word_out] # optional - sage.symbolic [Integer Ring] In contrast, if ``output_rings`` is set to the empty list, the results are not converted:: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 2], ....: 2, f, n, output_rings=[]) - sage: for t in T.transitions(): + sage: for t in T.transitions(): # optional - sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Symbolic Ring] - sage: [x.parent() for x in T.states()[0].final_word_out] + sage: [x.parent() for x in T.states()[0].final_word_out] # optional - sage.symbolic [Symbolic Ring] Finally, we use a somewhat questionable conversion:: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.rings.finite_rings sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 0], ....: 2, f, n, output_rings=[GF(5)]) - sage: for t in T.transitions(): + sage: for t in T.transitions(): # optional - sage.rings.finite_rings sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Finite Field of size 5] @@ -1726,11 +1728,11 @@ def Recursion(self, recursions, base, function=None, var=None, The following tests fail due to missing or superfluous recursions or initial conditions. :: - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: transducers.Recursion([f(2*n) == f(n)], + sage: transducers.Recursion([f(2*n) == f(n)], # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1739,9 +1741,9 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n), + sage: transducers.Recursion([f(2*n + 1) == f(n), # optional - sage.symbolic ....: f(4*n) == f(2*n) + 1, - ....: f(2*n) == f(n) +1], + ....: f(2*n) == f(n) + 1], ....: 2, f, n) Traceback (most recent call last): ... @@ -1749,7 +1751,7 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, + sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # optional - sage.symbolic ....: f(2*n) == f(n), ....: f(0) == 0, ....: f(42) == 42], 2, f, n) @@ -1759,7 +1761,7 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, + sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # optional - sage.symbolic ....: f(2*n) == f(n - 2) + 4, ....: f(0) == 0], 2, f, n) Traceback (most recent call last): @@ -1769,7 +1771,7 @@ def Recursion(self, recursions, base, function=None, var=None, Here is an example of a transducer with a conflicting rule (it cannot hold for `n = 0`):: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n - 1), ....: f(2*n) == f(n) + 1, ....: f(1) == 1, diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py index 2db919f8931..4887720d1c1 100644 --- a/src/sage/combinat/free_module.py +++ b/src/sage/combinat/free_module.py @@ -151,7 +151,7 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): The constructed module is in the category of modules with basis over the base ring:: - sage: CombinatorialFreeModule(QQ, Partitions()).category() + sage: CombinatorialFreeModule(QQ, Partitions()).category() # optional - sage.combinat Category of vector spaces with basis over Rational Field If furthermore the index set is finite (i.e. in the category @@ -160,7 +160,7 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): sage: CombinatorialFreeModule(QQ, [1,2,3,4]).category() Category of finite dimensional vector spaces with basis over Rational Field - sage: CombinatorialFreeModule(QQ, Partitions(3), + sage: CombinatorialFreeModule(QQ, Partitions(3), # optional - sage.combinat ....: category=Algebras(QQ).WithBasis()).category() Category of finite dimensional algebras with basis over Rational Field @@ -288,16 +288,16 @@ def __classcall_private__(cls, base_ring, basis_keys=None, category=None, We check that the category is properly straightened:: sage: F = CombinatorialFreeModule(QQ, ['a','b']) - sage: F1 = CombinatorialFreeModule(QQ, ['a','b'], category = ModulesWithBasis(QQ)) - sage: F2 = CombinatorialFreeModule(QQ, ['a','b'], category = [ModulesWithBasis(QQ)]) - sage: F3 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),)) - sage: F4 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),CommutativeAdditiveSemigroups())) - sage: F5 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),Category.join((LeftModules(QQ), RightModules(QQ))))) + sage: F1 = CombinatorialFreeModule(QQ, ['a','b'], category=ModulesWithBasis(QQ)) + sage: F2 = CombinatorialFreeModule(QQ, ['a','b'], category=[ModulesWithBasis(QQ)]) + sage: F3 = CombinatorialFreeModule(QQ, ['a','b'], category=(ModulesWithBasis(QQ),)) + sage: F4 = CombinatorialFreeModule(QQ, ['a','b'], category=(ModulesWithBasis(QQ),CommutativeAdditiveSemigroups())) + sage: F5 = CombinatorialFreeModule(QQ, ['a','b'], category=(ModulesWithBasis(QQ),Category.join((LeftModules(QQ), RightModules(QQ))))) sage: F6 = CombinatorialFreeModule(QQ, ['a','b'], category=ModulesWithBasis(QQ).FiniteDimensional()) sage: F1 is F, F2 is F, F3 is F, F4 is F, F5 is F, F6 is F (True, True, True, True, True, True) - sage: G = CombinatorialFreeModule(QQ, ['a','b'], category = AlgebrasWithBasis(QQ)) + sage: G = CombinatorialFreeModule(QQ, ['a','b'], category=AlgebrasWithBasis(QQ)) sage: F is G False """ @@ -347,21 +347,21 @@ def element_class(self): EXAMPLES:: - sage: A = Algebras(QQ).WithBasis().example(); A + sage: A = Algebras(QQ).WithBasis().example(); A # optional - sage.combinat An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.element_class.mro() + sage: A.element_class.mro() # optional - sage.combinat [, , ...] - sage: a,b,c = A.algebra_generators() - sage: a * b + sage: a,b,c = A.algebra_generators() # optional - sage.combinat + sage: a * b # optional - sage.combinat B[word: ab] TESTS:: - sage: A.__class__.element_class.__module__ + sage: A.__class__.element_class.__module__ # optional - sage.combinat 'sage.combinat.free_module' """ return self.__make_element_class__(self.Element, @@ -385,12 +385,13 @@ def __init__(self, R, basis_keys=None, element_class=None, category=None, sage: F.category() Category of finite dimensional algebras with basis over Rational Field - sage: F = CombinatorialFreeModule(GF(3), ['a','b','c'], - ....: category=(Modules(GF(3)).WithBasis(), Semigroups())) - sage: F.category() - Join of Category of finite semigroups and Category of finite dimensional vector spaces with basis over Finite Field of size 3 + sage: F = CombinatorialFreeModule(GF(3), ['a','b','c'], # optional - sage.rings.finite_rings + ....: category=(Modules(GF(3)).WithBasis(), Semigroups())) + sage: F.category() # optional - sage.rings.finite_rings + Join of Category of finite semigroups + and Category of finite dimensional vector spaces with basis over Finite Field of size 3 - sage: F = CombinatorialFreeModule(QQ, ['a','b','c'], category = FiniteDimensionalModulesWithBasis(QQ)) + sage: F = CombinatorialFreeModule(QQ, ['a','b','c'], category=FiniteDimensionalModulesWithBasis(QQ)) sage: F.basis() Finite family {'a': B['a'], 'b': B['b'], 'c': B['c']} sage: F.category() @@ -518,8 +519,8 @@ def _ascii_art_term(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: ascii_art(R.one()) # indirect doctest + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: ascii_art(R.one()) # indirect doctest # optional - sage.combinat 1 """ try: @@ -535,8 +536,8 @@ def _unicode_art_term(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: unicode_art(R.one()) # indirect doctest + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: unicode_art(R.one()) # indirect doctest # optional - sage.combinat 1 """ try: @@ -620,26 +621,26 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ,["a", "b"]) + sage: F = CombinatorialFreeModule(QQ, ["a", "b"]) sage: F(F.monomial("a")) # indirect doctest B['a'] Do not rely on the following feature which may be removed in the future:: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) - sage: QS3([2,3,1]) # indirect doctest + sage: QS3 = SymmetricGroupAlgebra(QQ,3) # optional - sage.combinat + sage: QS3([2,3,1]) # indirect doctest # optional - sage.combinat [2, 3, 1] instead, use:: - sage: P = QS3.basis().keys() - sage: QS3.monomial(P([2,3,1])) # indirect doctest + sage: P = QS3.basis().keys() # optional - sage.combinat + sage: QS3.monomial(P([2,3,1])) # indirect doctest # optional - sage.combinat [2, 3, 1] or:: - sage: B = QS3.basis() - sage: B[P([2,3,1])] + sage: B = QS3.basis() # optional - sage.combinat + sage: B[P([2,3,1])] # optional - sage.combinat [2, 3, 1] TODO: The symmetric group algebra (and in general, @@ -691,17 +692,17 @@ def _element_constructor_(self, x): Here is a real life example illustrating that this yielded mathematically wrong results:: - sage: S = SymmetricFunctions(QQ) - sage: s = S.s(); p = S.p() - sage: ss = tensor([s,s]); pp = tensor([p,p]) - sage: a = tensor((s[2],s[2])) + sage: S = SymmetricFunctions(QQ) # optional - sage.combinat + sage: s = S.s(); p = S.p() # optional - sage.combinat + sage: ss = tensor([s,s]); pp = tensor([p,p]) # optional - sage.combinat + sage: a = tensor((s[2],s[2])) # optional - sage.combinat The following originally used to yield ``p[[2]] # p[[2]]``, and if there was no natural coercion between ``s`` and ``p``, this would raise a ``NotImplementedError``. Since :trac:`15305`, this takes the coercion between ``s`` and ``p`` and lifts it to the tensor product. :: - sage: pp(a) + sage: pp(a) # optional - sage.combinat 1/4*p[1, 1] # p[1, 1] + 1/4*p[1, 1] # p[2] + 1/4*p[2] # p[1, 1] + 1/4*p[2] # p[2] General extensions of the ground ring should probably be reintroduced @@ -715,8 +716,8 @@ def _element_constructor_(self, x): Conversion from the ground ring is implemented for algebras:: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) - sage: QS3(2) + sage: QS3 = SymmetricGroupAlgebra(QQ,3) # optional - sage.combinat + sage: QS3(2) # optional - sage.combinat 2*[1, 2, 3] """ R = self.base_ring() @@ -797,8 +798,8 @@ def _first_ngens(self, n): sage: C._first_ngens(3) (B[0], B[1], B[-1]) - sage: R. = FreeAlgebra(QQ, 2) - sage: x,y + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat + sage: x,y # optional - sage.combinat (x, y) """ try: @@ -834,13 +835,13 @@ def _coerce_map_from_(self, R): sage: C.has_coerce_map_from(CQ) False - sage: CF2 = CombinatorialFreeModule(GF(2), Set([1,2])) - sage: CF2.has_coerce_map_from(C) + sage: CF2 = CombinatorialFreeModule(GF(2), Set([1,2])) # optional - sage.rings.finite_rings + sage: CF2.has_coerce_map_from(C) # optional - sage.rings.finite_rings True - sage: c = C.monomial(1) - sage: CF2(2*c) + sage: c = C.monomial(1) # optional - sage.rings.finite_rings + sage: CF2(2*c) # optional - sage.rings.finite_rings 0 - sage: CF2(3*c) + sage: CF2(3*c) # optional - sage.rings.finite_rings B[1] """ if isinstance(R, CombinatorialFreeModule): @@ -876,8 +877,8 @@ def dimension(self): :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s.dimension() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s.dimension() # optional - sage.combinat +Infinity """ return self._indices.cardinality() @@ -892,11 +893,11 @@ def is_exact(self): EXAMPLES:: - sage: GroupAlgebra(GL(3, GF(7))).is_exact() + sage: GroupAlgebra(GL(3, GF(7))).is_exact() # optional - sage.groups sage.rings.finite_rings True - sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact() + sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact() # optional - sage.groups sage.rings.finite_rings False - sage: GroupAlgebra(GL(3, pAdicRing(7))).is_exact() # not implemented correctly (not my fault)! + sage: GroupAlgebra(GL(3, pAdicRing(7))).is_exact() # not implemented correctly (not my fault)! # optional - sage.groups sage.rings.padics False """ # The index set may not have a check for exactness @@ -926,11 +927,11 @@ def set_order(self, order): EXAMPLES:: - sage: QS2 = SymmetricGroupAlgebra(QQ,2) - sage: b = list(QS2.basis().keys()) - sage: b.reverse() - sage: QS2.set_order(b) - sage: QS2.get_order() + sage: QS2 = SymmetricGroupAlgebra(QQ,2) # optional - sage.combinat + sage: b = list(QS2.basis().keys()) # optional - sage.combinat + sage: b.reverse() # optional - sage.combinat + sage: QS2.set_order(b) # optional - sage.combinat + sage: QS2.get_order() # optional - sage.combinat [[2, 1], [1, 2]] """ self._order = order @@ -944,8 +945,8 @@ def get_order(self): EXAMPLES:: - sage: QS2 = SymmetricGroupAlgebra(QQ,2) - sage: QS2.get_order() # note: order changed on 2009-03-13 + sage: QS2 = SymmetricGroupAlgebra(QQ,2) # optional - sage.combinat + sage: QS2.get_order() # note: order changed on 2009-03-13 # optional - sage.combinat [[2, 1], [1, 2]] """ if self._order is None: @@ -1001,11 +1002,11 @@ def from_vector(self, vector, order=None, coerce=True): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) - sage: b = QS3.from_vector(vector((2, 0, 0, 0, 0, 4))); b + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat + sage: b = QS3.from_vector(vector((2, 0, 0, 0, 0, 4))); b # optional - sage.combinat 2*[1, 2, 3] + 4*[3, 2, 1] - sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) - sage: a == b + sage: a = 2*QS3([1,2,3]) + 4*QS3([3,2,1]) # optional - sage.combinat + sage: a == b # optional - sage.combinat True """ if order is None: @@ -1057,7 +1058,7 @@ def linear_combination(self, iter_of_elements_coeff, factor_on_left=True): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ,[1,2]) + sage: F = CombinatorialFreeModule(QQ, [1,2]) sage: f = F.an_element(); f 2*B[1] + 2*B[2] sage: F.linear_combination( (f,i) for i in range(5) ) @@ -1132,8 +1133,8 @@ def _sum_of_monomials(self, indices): sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) sage: F._sum_of_monomials(['a', 'b', 'b']) B['a'] + 2*B['b'] - sage: F = CombinatorialFreeModule(GF(3), ['a', 'b', 'c']) - sage: F._sum_of_monomials(['a', 'b', 'b', 'b']) + sage: F = CombinatorialFreeModule(GF(3), ['a', 'b', 'c']) # optional - sage.rings.finite_rings + sage: F._sum_of_monomials(['a', 'b', 'b', 'b']) # optional - sage.rings.finite_rings B['a'] """ R = self.base_ring() @@ -1208,26 +1209,26 @@ def _from_dict(self, d, coerce=False, remove_zeros=True): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).elementary() - sage: s = SymmetricFunctions(QQ).schur() - sage: a = e([2,1]) + e([1,1,1]); a + sage: e = SymmetricFunctions(QQ).elementary() # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: a = e([2,1]) + e([1,1,1]); a # optional - sage.combinat e[1, 1, 1] + e[2, 1] - sage: s._from_dict(a.monomial_coefficients()) + sage: s._from_dict(a.monomial_coefficients()) # optional - sage.combinat s[1, 1, 1] + s[2, 1] If the optional argument ``coerce`` is ``True``, then the coefficients are coerced into the base ring of ``self``:: - sage: part = Partition([2,1]) - sage: d = {part:1} - sage: a = s._from_dict(d,coerce=True); a + sage: part = Partition([2,1]) # optional - sage.combinat + sage: d = {part: 1} # optional - sage.combinat + sage: a = s._from_dict(d, coerce=True); a # optional - sage.combinat s[2, 1] - sage: a.coefficient(part).parent() + sage: a.coefficient(part).parent() # optional - sage.combinat Rational Field With ``remove_zeros=True``, zero coefficients are removed:: - sage: s._from_dict({part:0}) + sage: s._from_dict({part: 0}) # optional - sage.combinat 0 .. WARNING:: @@ -1236,7 +1237,7 @@ def _from_dict(self, d, coerce=False, remove_zeros=True): coefficient of the dictionary is zero. Otherwise, this may lead to illegal results:: - sage: list(s._from_dict({part:0}, remove_zeros=False)) + sage: list(s._from_dict({part: 0}, remove_zeros=False)) # optional - sage.combinat [([2, 1], 0)] """ assert isinstance(d, dict) @@ -1262,7 +1263,8 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): F # G sage: T.category() - Category of tensor products of finite dimensional modules with basis over Integer Ring + Category of tensor products of + finite dimensional modules with basis over Integer Ring sage: T.construction() # todo: not implemented [tensor, ] @@ -1275,7 +1277,8 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): The basis of T is indexed by tuples of basis indices of F and G:: sage: T.basis().keys() - Image of Cartesian product of {1, 2}, {3, 4} by The map from Cartesian product of {1, 2}, {3, 4} + Image of Cartesian product of {1, 2}, {3, 4} + by The map from Cartesian product of {1, 2}, {3, 4} sage: T.basis().keys().list() [(1, 3), (1, 4), (2, 3), (2, 4)] @@ -1424,9 +1427,9 @@ def _ascii_art_(self, term): """ TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: Partitions.options(diagram_str="#", convention="french") - sage: s = ascii_art(tensor((R[1,2], R[3,1,2]))); s + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: Partitions.options(diagram_str="#", convention="french") # optional - sage.combinat + sage: s = ascii_art(tensor((R[1,2], R[3,1,2]))); s # optional - sage.combinat R # R # ### ## # @@ -1434,7 +1437,7 @@ def _ascii_art_(self, term): Check that the breakpoints are correct (:trac:`29202`):: - sage: s._breakpoints + sage: s._breakpoints # optional - sage.combinat [6] """ if hasattr(self, "_print_options"): @@ -1453,9 +1456,9 @@ def _unicode_art_(self, term): """ TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: Partitions.options(diagram_str="#", convention="french") - sage: s = unicode_art(tensor((R[1,2], R[3,1,2]))); s + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: Partitions.options(diagram_str="#", convention="french") # optional - sage.combinat + sage: s = unicode_art(tensor((R[1,2], R[3,1,2]))); s # optional - sage.combinat R ⊗ R ┌┐ ┌┬┬┐ ├┼┐ └┴┼┤ @@ -1464,7 +1467,7 @@ def _unicode_art_(self, term): Check that the breakpoints are correct (:trac:`29202`):: - sage: s._breakpoints + sage: s._breakpoints # optional - sage.combinat [7] """ if hasattr(self, "_print_options"): @@ -1548,22 +1551,26 @@ def tensor_constructor(self, modules): sage: G = CombinatorialFreeModule(ZZ, [3,4]); G.rename("G") sage: H = CombinatorialFreeModule(ZZ, [5,6]); H.rename("H") - sage: f = F.monomial(1) + 2 * F.monomial(2) - sage: g = 2*G.monomial(3) + G.monomial(4) - sage: h = H.monomial(5) + H.monomial(6) - sage: FG = tensor([F, G ]) + sage: f = F.monomial(1) + 2*F.monomial(2) + sage: g = 2*G.monomial(3) + G.monomial(4) + sage: h = H.monomial(5) + H.monomial(6) + sage: FG = tensor([F, G]) sage: phi_fg = FG.tensor_constructor((F, G)) - sage: phi_fg(f,g) + sage: phi_fg(f, g) 2*B[1] # B[3] + B[1] # B[4] + 4*B[2] # B[3] + 2*B[2] # B[4] sage: FGH = tensor([F, G, H]) sage: phi_fgh = FGH.tensor_constructor((F, G, H)) sage: phi_fgh(f, g, h) - 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] + 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] sage: phi_fg_h = FGH.tensor_constructor((FG, H)) sage: phi_fg_h(phi_fg(f, g), h) - 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] + 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] """ assert(module in ModulesWithBasis(self.base_ring()) for module in modules) assert(tensor(modules) == self) @@ -1727,7 +1734,9 @@ class CombinatorialFreeModule_CartesianProduct(CombinatorialFreeModule): sage: S F (+) G sage: S.basis() - Lazy family (Term map from Disjoint union of Family ({4, 5}, {4, 6}) to F (+) G(i))_{i in Disjoint union of Family ({4, 5}, {4, 6})} + Lazy family (Term map + from Disjoint union of Family ({4, 5}, {4, 6}) + to F (+) G(i))_{i in Disjoint union of Family ({4, 5}, {4, 6})} Note that the indices of the basis elements of F and G intersect non trivially. This is handled by forcing the union to be disjoint:: @@ -1737,19 +1746,19 @@ class CombinatorialFreeModule_CartesianProduct(CombinatorialFreeModule): We now compute the Cartesian product of elements of free modules:: - sage: f = F.monomial(4) + 2 * F.monomial(5) - sage: g = 2*G.monomial(4) + G.monomial(6) - sage: h = H.monomial(4) + H.monomial(7) - sage: cartesian_product([f,g]) + sage: f = F.monomial(4) + 2*F.monomial(5) + sage: g = 2*G.monomial(4) + G.monomial(6) + sage: h = H.monomial(4) + H.monomial(7) + sage: cartesian_product([f, g]) B[(0, 4)] + 2*B[(0, 5)] + 2*B[(1, 4)] + B[(1, 6)] - sage: cartesian_product([f,g,h]) + sage: cartesian_product([f, g, h]) B[(0, 4)] + 2*B[(0, 5)] + 2*B[(1, 4)] + B[(1, 6)] + B[(2, 4)] + B[(2, 7)] - sage: cartesian_product([f,g,h]).parent() + sage: cartesian_product([f, g, h]).parent() F (+) G (+) H TODO: choose an appropriate semantic for Cartesian products of Cartesian products (associativity?):: - sage: S = cartesian_product([cartesian_product([F, G]), H]) # todo: not implemented + sage: S = cartesian_product([cartesian_product([F, G]), H]) # todo: not implemented F (+) G (+) H """ @@ -1881,8 +1890,8 @@ def _cartesian_product_of_elements(self, elements): sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") sage: S = cartesian_product([F, G]) - sage: f = F.monomial(4) + 2 * F.monomial(5) - sage: g = 2*G.monomial(4) + G.monomial(6) + sage: f = F.monomial(4) + 2*F.monomial(5) + sage: g = 2*G.monomial(4) + G.monomial(6) sage: S._cartesian_product_of_elements([f, g]) B[(0, 4)] + 2*B[(0, 5)] + 2*B[(1, 4)] + B[(1, 6)] sage: S._cartesian_product_of_elements([f, g]).parent() == S diff --git a/src/sage/combinat/integer_lists/invlex.pyx b/src/sage/combinat/integer_lists/invlex.pyx index a168491ede7..c94a024c040 100644 --- a/src/sage/combinat/integer_lists/invlex.pyx +++ b/src/sage/combinat/integer_lists/invlex.pyx @@ -560,7 +560,7 @@ class IntegerListsLex(IntegerLists, metaclass=ClasscallMetaclass): :: - sage: Partitions(2, max_slope=-1, length=2).list() + sage: Partitions(2, max_slope=-1, length=2).list() # optional - sage.combinat [] sage: list(IntegerListsLex(0, floor=ConstantFunction(1), min_slope=0)) [[]] diff --git a/src/sage/combinat/integer_vector.py b/src/sage/combinat/integer_vector.py index 9f01bfd787d..9e62a27d47f 100644 --- a/src/sage/combinat/integer_vector.py +++ b/src/sage/combinat/integer_vector.py @@ -92,11 +92,11 @@ def is_gale_ryser(r,s): EXAMPLES:: sage: from sage.combinat.integer_vector import is_gale_ryser - sage: is_gale_ryser([4,2,2],[3,3,1,1]) + sage: is_gale_ryser([4,2,2], [3,3,1,1]) # optional - sage.combinat True - sage: is_gale_ryser([4,2,1,1],[3,3,1,1]) + sage: is_gale_ryser([4,2,1,1], [3,3,1,1]) # optional - sage.combinat True - sage: is_gale_ryser([3,2,1,1],[3,3,1,1]) + sage: is_gale_ryser([3,2,1,1], [3,3,1,1]) # optional - sage.combinat False REMARK: In the literature, what we are calling a @@ -207,14 +207,14 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", sage: from sage.combinat.integer_vector import gale_ryser_theorem sage: p1 = [2,2,1] sage: p2 = [2,2,1] - sage: print(gale_ryser_theorem(p1, p2)) # not tested + sage: print(gale_ryser_theorem(p1, p2)) # not tested # optional - sage.combinat [1 1 0] [1 0 1] [0 1 0] - sage: A = gale_ryser_theorem(p1, p2) - sage: rs = [sum(x) for x in A.rows()] - sage: cs = [sum(x) for x in A.columns()] - sage: p1 == rs; p2 == cs + sage: A = gale_ryser_theorem(p1, p2) # optional - sage.combinat + sage: rs = [sum(x) for x in A.rows()] # optional - sage.combinat + sage: cs = [sum(x) for x in A.columns()] # optional - sage.combinat + sage: p1 == rs; p2 == cs # optional - sage.combinat True True @@ -224,27 +224,27 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", sage: from sage.combinat.integer_vector import gale_ryser_theorem sage: p1 = [3,3,1,1] sage: p2 = [3,3,1,1] - sage: gale_ryser_theorem(p1, p2, algorithm = "ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 0] [1 1 0 1] [1 0 0 0] [0 1 0 0] sage: p1 = [4,2,2] sage: p2 = [3,3,1,1] - sage: gale_ryser_theorem(p1, p2, algorithm = "ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 1] [1 1 0 0] [1 1 0 0] sage: p1 = [4,2,2,0] sage: p2 = [3,3,1,1,0,0] - sage: gale_ryser_theorem(p1, p2, algorithm = "ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 1 0 0] [1 1 0 0 0 0] [1 1 0 0 0 0] [0 0 0 0 0 0] sage: p1 = [3,3,2,1] sage: p2 = [3,2,2,1,1] - sage: print(gale_ryser_theorem(p1, p2, algorithm="gale")) # not tested + sage: print(gale_ryser_theorem(p1, p2, algorithm="gale")) # not tested # optional - sage.combinat [1 1 1 0 0] [1 1 0 0 1] [1 0 1 0 0] @@ -253,7 +253,7 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", With `0` in the sequences, and with unordered inputs:: sage: from sage.combinat.integer_vector import gale_ryser_theorem - sage: gale_ryser_theorem([3,3,0,1,1,0], [3,1,3,1,0], algorithm="ryser") + sage: gale_ryser_theorem([3,3,0,1,1,0], [3,1,3,1,0], algorithm="ryser") # optional - sage.combinat [1 1 1 0 0] [1 0 1 1 0] [0 0 0 0 0] @@ -261,7 +261,7 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", [0 0 1 0 0] [0 0 0 0 0] sage: p1 = [3,1,1,1,1]; p2 = [3,2,2,0] - sage: gale_ryser_theorem(p1, p2, algorithm="ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 0] [1 0 0 0] [1 0 0 0] @@ -288,17 +288,17 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", ....: print("Algorithm %s failed with this input:" % algorithm) ....: print(s1, s2) - sage: for algorithm in ["gale", "ryser"]: # long time + sage: for algorithm in ["gale", "ryser"]: # long time # optional - sage.combinat ....: for i in range(50): ....: test_algorithm(algorithm, 3, 10) Null matrix:: - sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="gale") + sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="gale") # optional - sage.combinat [0 0 0 0] [0 0 0 0] [0 0 0 0] - sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="ryser") + sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="ryser") # optional - sage.combinat [0 0 0 0] [0 0 0 0] [0 0 0 0] @@ -517,11 +517,10 @@ def specht_module(self, base_ring=None): EXAMPLES:: - sage: SM = IntegerVectors()([2,0,1,0,2]).specht_module(QQ) - sage: SM + sage: SM = IntegerVectors()([2,0,1,0,2]).specht_module(QQ); SM # optional - sage.combinat Specht module of [(0, 0), (0, 1), (2, 0), (4, 0), (4, 1)] over Rational Field - sage: s = SymmetricFunctions(QQ).s() - sage: s(SM.frobenius_image()) + sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat + sage: s(SM.frobenius_image()) # optional - sage.combinat s[2, 2, 1] """ from sage.combinat.specht_module import SpechtModule @@ -542,9 +541,9 @@ def specht_module_dimension(self, base_ring=None): EXAMPLES:: - sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension() + sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension() # optional - sage.combinat 5 - sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension(GF(2)) + sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension(GF(2)) # optional - sage.combinat sage.rings.finite_rings 5 """ from sage.combinat.specht_module import specht_module_rank @@ -595,7 +594,7 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): Note that trailing zeros are ignored so that ``[3, 0]`` does not show up in the following list (since ``[3]`` does):: - sage: IntegerVectors(3, max_length=2).list() + sage: IntegerVectors(3, max_length=2).list() # optional - sage.combinat [[3], [2, 1], [1, 2], [0, 3]] If ``n`` and ``k`` are both specified, then it returns the class @@ -614,9 +613,9 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): Further examples:: - sage: IntegerVectors(-1, 0, min_part = 1).list() + sage: IntegerVectors(-1, 0, min_part=1).list() [] - sage: IntegerVectors(-1, 2, min_part = 1).list() + sage: IntegerVectors(-1, 2, min_part=1).list() [] sage: IntegerVectors(0, 0, min_part=1).list() [[]] @@ -667,9 +666,9 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): An example showing the same output by using IntegerListsLex:: - sage: IntegerVectors(4, max_length=2).list() + sage: IntegerVectors(4, max_length=2).list() # optional - sage.combinat [[4], [3, 1], [2, 2], [1, 3], [0, 4]] - sage: list(IntegerListsLex(4, max_length=2)) + sage: list(IntegerListsLex(4, max_length=2)) # optional - sage.combinat [[4], [3, 1], [2, 2], [1, 3], [0, 4]] .. SEEALSO:: @@ -1392,12 +1391,12 @@ def __contains__(self, x): """ TESTS:: - sage: [3,2,2,1] in IntegerVectors(8,4, min_part = 1) + sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=1) # optional - sage.combinat True - sage: [3,2,2,1] in IntegerVectors(8,4, min_part = 2) + sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=2) # optional - sage.combinat False - sage: [0,3,0,1,2] in IntegerVectors(6, max_length=3) + sage: [0,3,0,1,2] in IntegerVectors(6, max_length=3) # optional - sage.combinat False """ if isinstance(x, IntegerVector) and x.parent() is self: @@ -1421,17 +1420,17 @@ def cardinality(self): EXAMPLES:: - sage: IntegerVectors(3, 3, min_part=1).cardinality() + sage: IntegerVectors(3, 3, min_part=1).cardinality() # optional - sage.combinat 1 - sage: IntegerVectors(5, 3, min_part=1).cardinality() + sage: IntegerVectors(5, 3, min_part=1).cardinality() # optional - sage.combinat 6 - sage: IntegerVectors(13, 4, max_part=4).cardinality() + sage: IntegerVectors(13, 4, max_part=4).cardinality() # optional - sage.combinat 20 - sage: IntegerVectors(k=4, max_part=3).cardinality() + sage: IntegerVectors(k=4, max_part=3).cardinality() # optional - sage.combinat 256 - sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality() + sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality() # optional - sage.combinat 27 - sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality() + sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality() # optional - sage.combinat 16 """ if self.k is None: @@ -1465,9 +1464,9 @@ def __iter__(self): """ EXAMPLES:: - sage: IntegerVectors(-1, 0, min_part = 1).list() + sage: IntegerVectors(-1, 0, min_part=1).list() [] - sage: IntegerVectors(-1, 2, min_part = 1).list() + sage: IntegerVectors(-1, 2, min_part=1).list() [] sage: IntegerVectors(0, 0, min_part=1).list() [[]] @@ -1512,7 +1511,7 @@ def __iter__(self): sage: all(map(lambda x: x.cardinality() == len(x.list()), iv)) True sage: essai = [[1,1,1], [2,5,6], [6,5,2]] - sage: iv = [ IntegerVectors(x[0], x[1], max_part = x[2]-1) for x in essai ] + sage: iv = [ IntegerVectors(x[0], x[1], max_part=x[2]-1) for x in essai ] sage: all(map(lambda x: x.cardinality() == len(x.list()), iv)) True """ diff --git a/src/sage/combinat/ranker.py b/src/sage/combinat/ranker.py index bcb5c967dcb..6d7fb2998a2 100644 --- a/src/sage/combinat/ranker.py +++ b/src/sage/combinat/ranker.py @@ -207,7 +207,7 @@ def unrank(L, i): Enumerated sets:: - sage: unrank(GF(7), 2) + sage: unrank(GF(7), 2) # optional - sage.rings.finite_rings 2 sage: unrank(IntegerModRing(29), 10) 10 diff --git a/src/sage/combinat/tutorial.py b/src/sage/combinat/tutorial.py index 904c7c3339c..afcdccc1729 100644 --- a/src/sage/combinat/tutorial.py +++ b/src/sage/combinat/tutorial.py @@ -360,7 +360,7 @@ Taking successive quotients:: - sage: [ (d(n+1) / d(n)) for n in range(1,17) ] + sage: [ (d(n+1) / d(n)) for n in range(1,17) ] # optional - sage.symbolic [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62] we observe that `d_n` satisfies the recurrence relation From f93a484eb4ee2a1709c05a99a83341962e7c2267 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 20 May 2023 15:35:26 -0700 Subject: [PATCH 09/26] sage.combinat: More # optional --- src/sage/combinat/root_system/plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/root_system/plot.py b/src/sage/combinat/root_system/plot.py index 2789540d238..90bab1e8ac0 100644 --- a/src/sage/combinat/root_system/plot.py +++ b/src/sage/combinat/root_system/plot.py @@ -754,10 +754,10 @@ sage: C = crystals.Tableaux(["A",2], shape=[4,2]) sage: L = C.weight_lattice_realization() - sage: plot_options = L.plot_parse_options() + sage: plot_options = L.plot_parse_options() # optional - sage.plot sage.symbolic sage: g = C.digraph() - sage: positions = {x: plot_options.projection(x.weight()) for x in C} + sage: positions = {x: plot_options.projection(x.weight()) for x in C} # optional - sage.plot sage.symbolic sage: p = L.plot() # optional - sage.plot sage.symbolic sage: p += g.plot(pos=positions, # optional - sage.plot sage.symbolic ....: color_by_label=plot_options.color, vertex_size=0) From 3ef1b0222af28492b161e29697ce0480aca7fbe5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 20 May 2023 22:37:59 -0700 Subject: [PATCH 10/26] sage.combinat: More # optional --- src/sage/combinat/tutorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/tutorial.py b/src/sage/combinat/tutorial.py index afcdccc1729..dfab1793474 100644 --- a/src/sage/combinat/tutorial.py +++ b/src/sage/combinat/tutorial.py @@ -474,7 +474,7 @@ `z` and `C(z)` to obtain an expression for `\frac{d}{dz}C(z)`:: - sage: fraction = fraction.lift(); fraction + sage: fraction = fraction.lift(); fraction # optional - sage.symbolic (1/2/(x - 1/4))*y - 1/4/(x - 1/4) sage: fraction(x=z, y=C) # optional - sage.symbolic 2*C(z)/(4*z - 1) - 1/(4*z - 1) From 1b5460881521a2fbbf805e30676c142e453310f7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 11:01:45 -0700 Subject: [PATCH 11/26] src/sage/combinat/k_regular_sequence.py: Fix alignment of # optional --- src/sage/combinat/k_regular_sequence.py | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sage/combinat/k_regular_sequence.py b/src/sage/combinat/k_regular_sequence.py index 74329d1f794..3a9afd84ddc 100644 --- a/src/sage/combinat/k_regular_sequence.py +++ b/src/sage/combinat/k_regular_sequence.py @@ -2718,11 +2718,11 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') # optional - sage.symbolic n - sage: function('f') # optional - sage.symbolic + sage: function('f') # optional - sage.symbolic f - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic ....: f(8*n) == -1*f(2*n - 1) + 1*f(2*n + 1), ....: f(8*n + 1) == -11*f(2*n - 1) + 10*f(2*n) + 11*f(2*n + 1), ....: f(8*n + 2) == -21*f(2*n - 1) + 20*f(2*n) + 21*f(2*n + 1), @@ -2733,9 +2733,9 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): ....: f(8*n + 7) == -71*f(2*n - 1) + 70*f(2*n) + 71*f(2*n + 1), ....: f(0) == 0, f(1) == 1, f(2) == 2, f(3) == 3, f(4) == 4, ....: f(5) == 5, f(6) == 6, f(7) == 7], f, n) - sage: rules = RP.parameters( # optional - sage.symbolic + sage: rules = RP.parameters( # optional - sage.symbolic ....: M, m, coeffs, initial_values, 0) - sage: RP.matrix(rules, 0, False) # optional - sage.symbolic + sage: RP.matrix(rules, 0, False) # optional - sage.symbolic [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] @@ -2753,7 +2753,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): [ 0 0 0 -31 30 31 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 -41 40 41 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 -51 50 51 0 0 0 0 0 0 0 0 0 0 0] - sage: RP.matrix(rules, 1, False) # optional - sage.symbolic + sage: RP.matrix(rules, 1, False) # optional - sage.symbolic [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0] @@ -2788,7 +2788,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -2802,9 +2802,9 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n) - sage: UB_rules = RP.parameters( # optional - sage.symbolic + sage: UB_rules = RP.parameters( # optional - sage.symbolic ....: M, m, coeffs, initial_values, 3) - sage: RP.matrix(UB_rules, 0) # optional - sage.symbolic + sage: RP.matrix(UB_rules, 0) # optional - sage.symbolic [ 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] @@ -2821,7 +2821,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): [ 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] - sage: RP.matrix(UB_rules, 1) # optional - sage.symbolic + sage: RP.matrix(UB_rules, 1) # optional - sage.symbolic [ 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] @@ -3015,9 +3015,9 @@ def right(self, recurrence_rules): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') # optional - sage.symbolic n - sage: function('f') # optional - sage.symbolic + sage: function('f') # optional - sage.symbolic f sage: SB_rules = RP.parameters( ....: 1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, @@ -3027,7 +3027,7 @@ def right(self, recurrence_rules): Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -3041,9 +3041,9 @@ def right(self, recurrence_rules): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n) - sage: UB_rules = RP.parameters( # optional - sage.symbolic + sage: UB_rules = RP.parameters( # optional - sage.symbolic ....: M, m, coeffs, initial_values, 3) - sage: RP.right(UB_rules) # optional - sage.symbolic + sage: RP.right(UB_rules) # optional - sage.symbolic (1, 1, 2, 1, 2, 2, 4, 2, 4, 6, 0, 4, 4, 1, 0, 0) """ from sage.modules.free_module_element import vector @@ -3079,12 +3079,12 @@ def __call__(self, *args, **kwds): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') # optional - sage.symbolic n - sage: function('f') # optional - sage.symbolic + sage: function('f') # optional - sage.symbolic f - sage: RP([f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic + sage: RP([f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic ....: f(0) == 0, f(1) == 1], f, n) ([ [1 0 0] [1 1 0] @@ -3094,7 +3094,7 @@ def __call__(self, *args, **kwds): (1, 0, 0), (0, 1, 1)) - sage: RP(equations=[f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic + sage: RP(equations=[f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic ....: f(0) == 0, f(1) == 1], function=f, var=n) ([ [1 0 0] [1 1 0] From d516993dd1d784966d99b32b74fd481cc4cbd504 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 11:21:57 -0700 Subject: [PATCH 12/26] src/sage/combinat/{k_regular_sequence,recognizable_series}.py: Add module level # optional --- src/sage/combinat/k_regular_sequence.py | 1 + src/sage/combinat/recognizable_series.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/sage/combinat/k_regular_sequence.py b/src/sage/combinat/k_regular_sequence.py index 3a9afd84ddc..a170582116f 100644 --- a/src/sage/combinat/k_regular_sequence.py +++ b/src/sage/combinat/k_regular_sequence.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.modules r""" `k`-regular Sequences diff --git a/src/sage/combinat/recognizable_series.py b/src/sage/combinat/recognizable_series.py index f717393edf0..c19b1cf680f 100644 --- a/src/sage/combinat/recognizable_series.py +++ b/src/sage/combinat/recognizable_series.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.modules r""" Recognizable Series From a2ceb72cdf6acf8260478cb5bb4dd5ba51e56d92 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 11:28:18 -0700 Subject: [PATCH 13/26] sage.combinat: More # optional --- .../combinat/binary_recurrence_sequences.py | 2 +- src/sage/combinat/binary_tree.py | 132 ++-- .../cluster_algebra_quiver/interact.py | 4 +- src/sage/combinat/combinat.py | 2 +- src/sage/combinat/combinat_cython.pyx | 2 +- src/sage/combinat/designs/bibd.py | 10 +- src/sage/combinat/designs/block_design.py | 132 ++-- src/sage/combinat/designs/database.py | 184 ++--- src/sage/combinat/designs/designs_pyx.pyx | 71 +- .../combinat/designs/difference_family.py | 253 +++---- .../designs/evenly_distributed_sets.pyx | 20 +- src/sage/combinat/designs/twographs.py | 40 +- src/sage/combinat/diagram.py | 12 +- src/sage/combinat/dlx.py | 16 +- src/sage/combinat/e_one_star.py | 18 +- .../combinat/integer_vectors_mod_permgroup.py | 1 + src/sage/combinat/interval_posets.py | 170 +++-- src/sage/combinat/matrices/dlxcpp.py | 16 +- .../multiset_partition_into_sets_ordered.py | 124 ++-- src/sage/combinat/ordered_tree.py | 38 +- src/sage/combinat/partition.py | 210 +++--- src/sage/combinat/perfect_matching.py | 22 +- src/sage/combinat/permutation.py | 96 +-- src/sage/combinat/posets/d_complete.py | 14 +- src/sage/combinat/posets/elements.py | 30 +- src/sage/combinat/posets/hasse_diagram.py | 336 ++++----- src/sage/combinat/posets/linear_extensions.py | 47 +- src/sage/combinat/posets/mobile.py | 8 +- src/sage/combinat/posets/poset_examples.py | 162 ++--- src/sage/combinat/posets/posets.py | 675 +++++++++--------- src/sage/combinat/quickref.py | 2 +- src/sage/combinat/rooted_tree.py | 14 +- src/sage/combinat/skew_partition.py | 12 +- src/sage/combinat/skew_tableau.py | 26 +- .../combinat/species/generating_series.py | 58 +- src/sage/combinat/subsets_hereditary.py | 12 +- src/sage/combinat/subword_complex.py | 14 +- src/sage/combinat/symmetric_group_algebra.py | 1 + .../symmetric_group_representations.py | 2 +- src/sage/combinat/tableau.py | 126 ++-- src/sage/combinat/tiling.py | 49 +- src/sage/combinat/triangles_FHM.py | 32 +- src/sage/combinat/tuple.py | 12 +- src/sage/combinat/tutorial.py | 4 +- src/sage/combinat/words/abstract_word.py | 10 +- src/sage/combinat/words/finite_word.py | 60 +- src/sage/combinat/words/morphic.py | 28 +- src/sage/combinat/words/morphism.py | 102 +-- src/sage/combinat/words/paths.py | 8 +- src/sage/combinat/words/suffix_trees.py | 16 +- src/sage/combinat/words/word.py | 2 +- src/sage/combinat/words/word_generators.py | 14 +- src/sage/combinat/words/words.py | 46 +- src/sage/combinat/yang_baxter_graph.py | 80 +-- 54 files changed, 1828 insertions(+), 1749 deletions(-) diff --git a/src/sage/combinat/binary_recurrence_sequences.py b/src/sage/combinat/binary_recurrence_sequences.py index 46c99fd24aa..49ddfe13fc0 100644 --- a/src/sage/combinat/binary_recurrence_sequences.py +++ b/src/sage/combinat/binary_recurrence_sequences.py @@ -1090,7 +1090,7 @@ def _find_cong1(p, R, ell): EXAMPLES:: sage: R = BinaryRecurrenceSequence(1,1) - sage: sage.combinat.binary_recurrence_sequences._find_cong1(7, R, 29) + sage: sage.combinat.binary_recurrence_sequences._find_cong1(7, R, 29) # optional - sage.rings.finite_rings ([0, 1, 2, 12, 13], 14) """ F = GF(ell) diff --git a/src/sage/combinat/binary_tree.py b/src/sage/combinat/binary_tree.py index 26923650782..8e876ab137a 100644 --- a/src/sage/combinat/binary_tree.py +++ b/src/sage/combinat/binary_tree.py @@ -988,13 +988,13 @@ def to_dyck_word_tamari(self): EXAMPLES:: - sage: BinaryTree().to_dyck_word_tamari() + sage: BinaryTree().to_dyck_word_tamari() # optional - sage.combinat [] - sage: BinaryTree([]).to_dyck_word_tamari() + sage: BinaryTree([]).to_dyck_word_tamari() # optional - sage.combinat [1, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word_tamari() + sage: BinaryTree([[None,[]],None]).to_dyck_word_tamari() # optional - sage.combinat [1, 1, 0, 0, 1, 0] - sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word_tamari() + sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word_tamari() # optional - sage.combinat [1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0] """ return self.to_dyck_word("L1R0") @@ -1128,7 +1128,9 @@ def tamari_join(self, other): ....: return True sage: all( test_uni_join(p, q) for p in BinaryTrees(3) for q in BinaryTrees(3) ) True - sage: p = BinaryTrees(6).random_element(); q = BinaryTrees(6).random_element(); test_uni_join(p, q) + sage: p = BinaryTrees(6).random_element() # optional - sage.combinat + sage: q = BinaryTrees(6).random_element() # optional - sage.combinat + sage: test_uni_join(p, q) # optional - sage.combinat True Border cases:: @@ -1215,7 +1217,9 @@ def tamari_meet(self, other, side="right"): ....: return True sage: all( test_uni_meet(p, q) for p in BinaryTrees(3) for q in BinaryTrees(3) ) True - sage: p = BinaryTrees(6).random_element(); q = BinaryTrees(6).random_element(); test_uni_meet(p, q) + sage: p = BinaryTrees(6).random_element() # optional - sage.combinat + sage: q = BinaryTrees(6).random_element() # optional - sage.combinat + sage: test_uni_meet(p, q) # optional - sage.combinat True Border cases:: @@ -1251,21 +1255,21 @@ def to_dyck_word(self, usemap="1L0R"): EXAMPLES:: - sage: BinaryTree().to_dyck_word() + sage: BinaryTree().to_dyck_word() # optional - sage.combinat [] - sage: BinaryTree([]).to_dyck_word() + sage: BinaryTree([]).to_dyck_word() # optional - sage.combinat [1, 0] - sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word() + sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word() # optional - sage.combinat [1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word() + sage: BinaryTree([[None,[]],None]).to_dyck_word() # optional - sage.combinat [1, 1, 0, 1, 0, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("1R0L") + sage: BinaryTree([[None,[]],None]).to_dyck_word("1R0L") # optional - sage.combinat [1, 0, 1, 1, 0, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("L1R0") + sage: BinaryTree([[None,[]],None]).to_dyck_word("L1R0") # optional - sage.combinat [1, 1, 0, 0, 1, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("R1L0") + sage: BinaryTree([[None,[]],None]).to_dyck_word("R1L0") # optional - sage.combinat [1, 1, 0, 1, 0, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("R10L") + sage: BinaryTree([[None,[]],None]).to_dyck_word("R10L") # optional - sage.combinat Traceback (most recent call last): ... ValueError: R10L is not a correct map @@ -1273,13 +1277,13 @@ def to_dyck_word(self, usemap="1L0R"): TESTS:: sage: bt = BinaryTree([[[], [[], None]], [[], []]]) - sage: bt == bt.to_dyck_word().to_binary_tree() + sage: bt == bt.to_dyck_word().to_binary_tree() # optional - sage.combinat True - sage: bt == bt.to_dyck_word("1R0L").to_binary_tree("1R0L") + sage: bt == bt.to_dyck_word("1R0L").to_binary_tree("1R0L") # optional - sage.combinat True - sage: bt == bt.to_dyck_word("L1R0").to_binary_tree("L1R0") + sage: bt == bt.to_dyck_word("L1R0").to_binary_tree("L1R0") # optional - sage.combinat True - sage: bt == bt.to_dyck_word("R1L0").to_binary_tree("R1L0") + sage: bt == bt.to_dyck_word("R1L0").to_binary_tree("R1L0") # optional - sage.combinat True """ from sage.combinat.dyck_word import DyckWord @@ -1443,9 +1447,9 @@ def tamari_sorting_tuple(self, reverse=False): ((1, 0, 0), 3), ((0, 0, 0), 3)] - sage: t = BinaryTrees(10).random_element() - sage: u = t.left_right_symmetry() - sage: t.tamari_sorting_tuple(True) == u.tamari_sorting_tuple() + sage: t = BinaryTrees(10).random_element() # optional - sage.combinat + sage: u = t.left_right_symmetry() # optional - sage.combinat + sage: t.tamari_sorting_tuple(True) == u.tamari_sorting_tuple() # optional - sage.combinat True REFERENCES: @@ -1612,8 +1616,9 @@ def to_tilting(self): [(0, 1), (2, 3), (4, 5), (6, 7), (4, 7), (8, 9), (10, 11), (8, 11), (4, 11), (12, 13), (4, 13), (2, 13), (0, 13)] - sage: t2 = DyckWord([1,1,1,1,0,1,1,0,0,0,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,0]).to_binary_tree() - sage: len(t2.to_tilting()) == t2.node_number() + sage: w = DyckWord([1,1,1,1,0,1,1,0,0,0,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,0]) # optional - sage.combinat + sage: t2 = w.to_binary_tree() # optional - sage.combinat + sage: len(t2.to_tilting()) == t2.node_number() # optional - sage.combinat True """ if not self: @@ -2827,36 +2832,36 @@ def q_hook_length_fraction(self, q=None, q_factor=False): only one vertex (which is a leaf):: sage: b = BinaryTree() - sage: b.q_hook_length_fraction() + sage: b.q_hook_length_fraction() # optional - sage.combinat 1 - sage: b.q_hook_length_fraction(q_factor=True) + sage: b.q_hook_length_fraction(q_factor=True) # optional - sage.combinat 1 Nothing different for a tree with one node and two leaves:: sage: b = BinaryTree([]); b [., .] - sage: b.q_hook_length_fraction() + sage: b.q_hook_length_fraction() # optional - sage.combinat 1 - sage: b.q_hook_length_fraction(q_factor=True) + sage: b.q_hook_length_fraction(q_factor=True) # optional - sage.combinat 1 Let us get to a more interesting tree:: sage: b = BinaryTree([[[],[]],[[],None]]); b [[[., .], [., .]], [[., .], .]] - sage: b.q_hook_length_fraction()(q=1) + sage: b.q_hook_length_fraction()(q=1) # optional - sage.combinat 20 - sage: b.q_hook_length_fraction() + sage: b.q_hook_length_fraction() # optional - sage.combinat q^7 + 2*q^6 + 3*q^5 + 4*q^4 + 4*q^3 + 3*q^2 + 2*q + 1 - sage: b.q_hook_length_fraction(q_factor=True) + sage: b.q_hook_length_fraction(q_factor=True) # optional - sage.combinat q^10 + 2*q^9 + 3*q^8 + 4*q^7 + 4*q^6 + 3*q^5 + 2*q^4 + q^3 - sage: b.q_hook_length_fraction(q=2) + sage: b.q_hook_length_fraction(q=2) # optional - sage.combinat 465 - sage: b.q_hook_length_fraction(q=2, q_factor=True) + sage: b.q_hook_length_fraction(q=2, q_factor=True) # optional - sage.combinat 3720 sage: q = PolynomialRing(ZZ, 'q').gen() - sage: b.q_hook_length_fraction(q=q**2) + sage: b.q_hook_length_fraction(q=q**2) # optional - sage.combinat q^14 + 2*q^12 + 3*q^10 + 4*q^8 + 4*q^6 + 3*q^4 + 2*q^2 + 1 Let us check the fact that `f_{q} (T)` is the generating function @@ -2875,7 +2880,7 @@ def q_hook_length_fraction(self, q=None, q_factor=False): ....: return all( q_hook_length_fraction_2(T) ....: == T.q_hook_length_fraction(q_factor=True) ....: for T in BinaryTrees(i) ) - sage: test_genfun(4) + sage: test_genfun(4) # optional - sage.combinat True """ from sage.combinat.q_analogues import q_binomial @@ -3394,29 +3399,29 @@ def dendriform_shuffle(self, other): sage: l = BinaryTree([g, u]) sage: r = BinaryTree([u, g]) - sage: list(g.dendriform_shuffle(g)) + sage: list(g.dendriform_shuffle(g)) # optional - sage.combinat [[[., .], .], [., [., .]]] - sage: list(l.dendriform_shuffle(l)) + sage: list(l.dendriform_shuffle(l)) # optional - sage.combinat [[[[[., .], .], .], .], [[[., .], [., .]], .], [[., .], [[., .], .]]] - sage: list(l.dendriform_shuffle(r)) + sage: list(l.dendriform_shuffle(r)) # optional - sage.combinat [[[[., .], .], [., .]], [[., .], [., [., .]]]] TESTS:: - sage: list(u.dendriform_shuffle(u)) + sage: list(u.dendriform_shuffle(u)) # optional - sage.combinat [.] - sage: list(u.dendriform_shuffle(g)) + sage: list(u.dendriform_shuffle(g)) # optional - sage.combinat [[., .]] - sage: list(u.dendriform_shuffle(l)) + sage: list(u.dendriform_shuffle(l)) # optional - sage.combinat [[[., .], .]] - sage: list(u.dendriform_shuffle(r)) + sage: list(u.dendriform_shuffle(r)) # optional - sage.combinat [[., [., .]]] - sage: list(r.dendriform_shuffle(u)) + sage: list(r.dendriform_shuffle(u)) # optional - sage.combinat [[., [., .]]] - sage: list(l.dendriform_shuffle(u)) + sage: list(l.dendriform_shuffle(u)) # optional - sage.combinat [[[., .], .]] """ from sage.combinat.words.shuffle_product import ShuffleProduct_w1w2 @@ -3526,32 +3531,32 @@ def sylvester_class(self, left_to_right=False): ....: if not BinaryTree(tree) == t: ....: return False ....: return True - sage: test_bst_of_sc(4, False) + sage: test_bst_of_sc(4, False) # optional - sage.combinat True - sage: test_bst_of_sc(5, False) # long time + sage: test_bst_of_sc(5, False) # long time # optional - sage.combinat True The same with the left-to-right version of binary search:: - sage: test_bst_of_sc(4, True) + sage: test_bst_of_sc(4, True) # optional - sage.combinat True - sage: test_bst_of_sc(5, True) # long time + sage: test_bst_of_sc(5, True) # long time # optional - sage.combinat True Checking that the sylvester class is the set of linear extensions of the poset of the tree:: - sage: all( sorted(t.canonical_labelling().sylvester_class()) + sage: all( sorted(t.canonical_labelling().sylvester_class()) # optional - sage.combinat ....: == sorted(list(v) for v in t.canonical_labelling().to_poset().linear_extensions()) ....: for t in BinaryTrees(4) ) True TESTS:: - sage: list(BinaryTree([[],[]]).sylvester_class()) + sage: list(BinaryTree([[],[]]).sylvester_class()) # optional - sage.combinat [[1, 3, 2], [3, 1, 2]] sage: bt = BinaryTree([[[],None],[[],[]]]) - sage: l = list(bt.sylvester_class()); l + sage: l = list(bt.sylvester_class()); l # optional - sage.combinat [[1, 2, 4, 6, 5, 3], [1, 4, 2, 6, 5, 3], [1, 4, 6, 2, 5, 3], @@ -3572,14 +3577,14 @@ def sylvester_class(self, left_to_right=False): [6, 4, 1, 2, 5, 3], [6, 4, 1, 5, 2, 3], [6, 4, 5, 1, 2, 3]] - sage: len(l) == Integer(bt.q_hook_length_fraction()(q=1)) + sage: len(l) == Integer(bt.q_hook_length_fraction()(q=1)) # optional - sage.combinat True Border cases:: - sage: list(BinaryTree().sylvester_class()) + sage: list(BinaryTree().sylvester_class()) # optional - sage.combinat [[]] - sage: list(BinaryTree([]).sylvester_class()) + sage: list(BinaryTree([]).sylvester_class()) # optional - sage.combinat [[1]] """ if self.is_empty(): @@ -4045,8 +4050,8 @@ def from_tamari_sorting_tuple(key): EXAMPLES:: sage: from sage.combinat.binary_tree import from_tamari_sorting_tuple - sage: t = BinaryTrees(60).random_element() - sage: from_tamari_sorting_tuple(t.tamari_sorting_tuple()[0]) == t + sage: t = BinaryTrees(60).random_element() # optional - sage.combinat + sage: from_tamari_sorting_tuple(t.tamari_sorting_tuple()[0]) == t # optional - sage.combinat True """ if not key: @@ -4250,16 +4255,17 @@ def random_element(self): EXAMPLES:: - sage: BinaryTrees(5).random_element() # random + sage: BinaryTrees(5).random_element() # random # optional - sage.combinat [., [., [., [., [., .]]]]] - sage: BinaryTrees(0).random_element() + sage: BinaryTrees(0).random_element() # optional - sage.combinat . - sage: BinaryTrees(1).random_element() + sage: BinaryTrees(1).random_element() # optional - sage.combinat [., .] TESTS:: - sage: all(BinaryTrees(10).random_element() in BinaryTrees(10) for i in range(20)) + sage: all(BinaryTrees(10).random_element() in BinaryTrees(10) # optional - sage.combinat + ....: for i in range(20)) True """ from sage.combinat.dyck_word import CompleteDyckWords_size @@ -4504,17 +4510,17 @@ def random_element(self): EXAMPLES:: - sage: BinaryTrees(5, full=True).random_element() # random + sage: BinaryTrees(5, full=True).random_element() # random # optional - sage.combinat [[], [[], []]] - sage: BinaryTrees(0, full=True).random_element() + sage: BinaryTrees(0, full=True).random_element() # optional - sage.combinat . - sage: BinaryTrees(1, full=True).random_element() + sage: BinaryTrees(1, full=True).random_element() # optional - sage.combinat [., .] TESTS:: sage: B = BinaryTrees(19, full=True) - sage: all(B.random_element() in B for i in range(20)) + sage: all(B.random_element() in B for i in range(20)) # optional - sage.combinat True """ from sage.combinat.dyck_word import CompleteDyckWords_size diff --git a/src/sage/combinat/cluster_algebra_quiver/interact.py b/src/sage/combinat/cluster_algebra_quiver/interact.py index f0225803be1..bf4bb87aba3 100644 --- a/src/sage/combinat/cluster_algebra_quiver/interact.py +++ b/src/sage/combinat/cluster_algebra_quiver/interact.py @@ -25,8 +25,8 @@ def cluster_interact(self, fig_size=1, circular=True, kind='seed'): TESTS:: - sage: S = ClusterSeed(['A',4]) - sage: S.interact() # indirect doctest # optional - sage.symbolic + sage: S = ClusterSeed(['A',4]) # optional - sage.graphs + sage: S.interact() # indirect doctest # optional - sage.graphs sage.symbolic ...VBox(children=... """ if kind not in ['seed', 'quiver']: diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 22a314d2636..1f43062827b 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -359,7 +359,7 @@ def bell_number(n, algorithm='flint', **options) -> Integer: sage: k = bell_number(30, 'mpmath', prec=15); k # optional - mpmath 846749014511809388871680 - sage: k == bell_number(30) # optional - mpmath + sage: k == bell_number(30) # optional - mpmath sage.libs.flint False TESTS:: diff --git a/src/sage/combinat/combinat_cython.pyx b/src/sage/combinat/combinat_cython.pyx index 1f8c56cc16d..af9c901e6a9 100644 --- a/src/sage/combinat/combinat_cython.pyx +++ b/src/sage/combinat/combinat_cython.pyx @@ -711,7 +711,7 @@ def set_partition_composition(tuple sp1, tuple sp2): sage: sp1 = ((1,-2),(2,-1)) sage: sp2 = ((1,-2),(2,-1)) sage: p, c = set_partition_composition(sp1, sp2) - sage: (SetPartition(p), c) == (SetPartition([[1,-1],[2,-2]]), 0) + sage: (SetPartition(p), c) == (SetPartition([[1,-1],[2,-2]]), 0) # optional - sage.combinat True """ cdef int num_loops = 0 # The number of loops removed diff --git a/src/sage/combinat/designs/bibd.py b/src/sage/combinat/designs/bibd.py index 2265e113040..2155f42be02 100644 --- a/src/sage/combinat/designs/bibd.py +++ b/src/sage/combinat/designs/bibd.py @@ -84,7 +84,7 @@ def biplane(n, existence=False): EXAMPLES:: - sage: designs.biplane(4) + sage: designs.biplane(4) # optional - sage.rings.finite_rings (16,6,2)-Balanced Incomplete Block Design sage: designs.biplane(7, existence=True) True @@ -1314,14 +1314,14 @@ def BIBD_from_arc_in_desarguesian_projective_plane(n,k,existence=False): sage: from sage.combinat.designs.bibd import BIBD_from_arc_in_desarguesian_projective_plane sage: from sage.combinat.designs.bibd import BalancedIncompleteBlockDesign - sage: D = BIBD_from_arc_in_desarguesian_projective_plane(232,8) - sage: BalancedIncompleteBlockDesign(232,D) + sage: D = BIBD_from_arc_in_desarguesian_projective_plane(232,8) # optional - sage.libs.gap sage.modules sage.rings.finite_rings + sage: BalancedIncompleteBlockDesign(232,D) # optional - sage.libs.gap sage.modules sage.rings.finite_rings (232,8,1)-Balanced Incomplete Block Design A `(120,8,1)`-BIBD:: - sage: D = BIBD_from_arc_in_desarguesian_projective_plane(120,8) - sage: BalancedIncompleteBlockDesign(120,D) + sage: D = BIBD_from_arc_in_desarguesian_projective_plane(120,8) # optional - sage.libs.gap sage.modules sage.rings.finite_rings + sage: BalancedIncompleteBlockDesign(120,D) # optional - sage.libs.gap sage.modules sage.rings.finite_rings (120,8,1)-Balanced Incomplete Block Design Other parameters:: diff --git a/src/sage/combinat/designs/block_design.py b/src/sage/combinat/designs/block_design.py index 1d189fdd409..6e618e36d89 100644 --- a/src/sage/combinat/designs/block_design.py +++ b/src/sage/combinat/designs/block_design.py @@ -318,15 +318,15 @@ def DesarguesianProjectivePlaneDesign(n, point_coordinates=True, check=True): EXAMPLES:: - sage: designs.DesarguesianProjectivePlaneDesign(2) + sage: designs.DesarguesianProjectivePlaneDesign(2) # optional - sage.rings.finite_rings (7,3,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(3) + sage: designs.DesarguesianProjectivePlaneDesign(3) # optional - sage.rings.finite_rings (13,4,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(4) + sage: designs.DesarguesianProjectivePlaneDesign(4) # optional - sage.rings.finite_rings (21,5,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(5) + sage: designs.DesarguesianProjectivePlaneDesign(5) # optional - sage.rings.finite_rings (31,6,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(6) + sage: designs.DesarguesianProjectivePlaneDesign(6) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the order of a finite field must be a prime power @@ -400,20 +400,20 @@ def q3_minus_one_matrix(K): EXAMPLES:: sage: from sage.combinat.designs.block_design import q3_minus_one_matrix - sage: m = q3_minus_one_matrix(GF(3)) - sage: m.multiplicative_order() == 3**3 - 1 # optional - sage.symbolic + sage: m = q3_minus_one_matrix(GF(3)) # optional - sage.rings.finite_rings + sage: m.multiplicative_order() == 3**3 - 1 # optional - sage.rings.finite_rings True - sage: m = q3_minus_one_matrix(GF(4, 'a')) # optional - sage.symbolic - sage: m.multiplicative_order() == 4**3 - 1 # optional - sage.symbolic + sage: m = q3_minus_one_matrix(GF(4, 'a')) # optional - sage.rings.finite_rings + sage: m.multiplicative_order() == 4**3 - 1 # optional - sage.rings.finite_rings True - sage: m = q3_minus_one_matrix(GF(5)) - sage: m.multiplicative_order() == 5**3 - 1 # optional - sage.symbolic + sage: m = q3_minus_one_matrix(GF(5)) # optional - sage.rings.finite_rings + sage: m.multiplicative_order() == 5**3 - 1 # optional - sage.rings.finite_rings True - sage: m = q3_minus_one_matrix(GF(9, 'a')) # optional - sage.symbolic - sage: m.multiplicative_order() == 9**3 - 1 # optional - sage.symbolic + sage: m = q3_minus_one_matrix(GF(9, 'a')) # optional - sage.rings.finite_rings + sage: m.multiplicative_order() == 9**3 - 1 # optional - sage.rings.finite_rings True """ q = K.cardinality() @@ -457,17 +457,17 @@ def normalize_hughes_plane_point(p, q): EXAMPLES:: sage: from sage.combinat.designs.block_design import normalize_hughes_plane_point - sage: K = FiniteField(9,'x') - sage: x = K.gen() - sage: normalize_hughes_plane_point((x, x+1, x), 9) + sage: K = FiniteField(9,'x') # optional - sage.rings.finite_rings + sage: x = K.gen() # optional - sage.rings.finite_rings + sage: normalize_hughes_plane_point((x, x+1, x), 9) # optional - sage.rings.finite_rings (1, x, 1) - sage: normalize_hughes_plane_point(vector((x,x,x)), 9) + sage: normalize_hughes_plane_point(vector((x,x,x)), 9) # optional - sage.rings.finite_rings (1, 1, 1) - sage: zero = K.zero() - sage: normalize_hughes_plane_point((2*x+2, zero, zero), 9) + sage: zero = K.zero() # optional - sage.rings.finite_rings + sage: normalize_hughes_plane_point((2*x+2, zero, zero), 9) # optional - sage.rings.finite_rings (1, 0, 0) - sage: one = K.one() - sage: normalize_hughes_plane_point((2*x, one, zero), 9) + sage: one = K.one() # optional - sage.rings.finite_rings + sage: normalize_hughes_plane_point((2*x, one, zero), 9) # optional - sage.rings.finite_rings (2*x, 1, 0) """ for i in [2,1,0]: @@ -526,8 +526,7 @@ def HughesPlane(q2, check=True): EXAMPLES:: - sage: H = designs.HughesPlane(9) - sage: H + sage: H = designs.HughesPlane(9); H # optional - sage.rings.finite_rings (91,10,1)-Balanced Incomplete Block Design We prove in the following computations that the Desarguesian plane ``H`` is @@ -536,45 +535,45 @@ def HughesPlane(q2, check=True): `D_{1,10} \cap D_{70,59}` and `D_{10,0} \cap D_{59,57}` are on the same line while `D_{0,70}`, `D_{1,59}` and `D_{10,57}` are not concurrent:: - sage: blocks = H.blocks() - sage: line = lambda p,q: next(b for b in blocks if p in b and q in b) + sage: blocks = H.blocks() # optional - sage.rings.finite_rings + sage: line = lambda p,q: next(b for b in blocks if p in b and q in b) # optional - sage.rings.finite_rings - sage: b_0_1 = line(0, 1) - sage: b_1_10 = line(1, 10) - sage: b_10_0 = line(10, 0) - sage: b_57_70 = line(57, 70) - sage: b_70_59 = line(70, 59) - sage: b_59_57 = line(59, 57) + sage: b_0_1 = line(0, 1) # optional - sage.rings.finite_rings + sage: b_1_10 = line(1, 10) # optional - sage.rings.finite_rings + sage: b_10_0 = line(10, 0) # optional - sage.rings.finite_rings + sage: b_57_70 = line(57, 70) # optional - sage.rings.finite_rings + sage: b_70_59 = line(70, 59) # optional - sage.rings.finite_rings + sage: b_59_57 = line(59, 57) # optional - sage.rings.finite_rings - sage: set(b_0_1).intersection(b_57_70) + sage: set(b_0_1).intersection(b_57_70) # optional - sage.rings.finite_rings {2} - sage: set(b_1_10).intersection(b_70_59) + sage: set(b_1_10).intersection(b_70_59) # optional - sage.rings.finite_rings {73} - sage: set(b_10_0).intersection(b_59_57) + sage: set(b_10_0).intersection(b_59_57) # optional - sage.rings.finite_rings {60} - sage: line(2, 73) == line(73, 60) + sage: line(2, 73) == line(73, 60) # optional - sage.rings.finite_rings True - sage: b_0_57 = line(0, 57) - sage: b_1_70 = line(1, 70) - sage: b_10_59 = line(10, 59) + sage: b_0_57 = line(0, 57) # optional - sage.rings.finite_rings + sage: b_1_70 = line(1, 70) # optional - sage.rings.finite_rings + sage: b_10_59 = line(10, 59) # optional - sage.rings.finite_rings - sage: p = set(b_0_57).intersection(b_1_70) - sage: q = set(b_1_70).intersection(b_10_59) - sage: p == q + sage: p = set(b_0_57).intersection(b_1_70) # optional - sage.rings.finite_rings + sage: q = set(b_1_70).intersection(b_10_59) # optional - sage.rings.finite_rings + sage: p == q # optional - sage.rings.finite_rings False TESTS: Some wrong input:: - sage: designs.HughesPlane(5) + sage: designs.HughesPlane(5) # optional - sage.rings.finite_rings Traceback (most recent call last): ... EmptySetError: No Hughes plane of non-square order exists. - sage: designs.HughesPlane(16) + sage: designs.HughesPlane(16) # optional - sage.rings.finite_rings Traceback (most recent call last): ... EmptySetError: No Hughes plane of even order exists. @@ -645,11 +644,13 @@ def projective_plane_to_OA(pplane, pt=None, check=True): EXAMPLES:: sage: from sage.combinat.designs.block_design import projective_plane_to_OA - sage: p2 = designs.DesarguesianProjectivePlaneDesign(2,point_coordinates=False) - sage: projective_plane_to_OA(p2) + sage: p2 = designs.DesarguesianProjectivePlaneDesign(2, # optional - sage.rings.finite_rings + ....: point_coordinates=False) + sage: projective_plane_to_OA(p2) # optional - sage.rings.finite_rings [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]] - sage: p3 = designs.DesarguesianProjectivePlaneDesign(3,point_coordinates=False) - sage: projective_plane_to_OA(p3) + sage: p3 = designs.DesarguesianProjectivePlaneDesign(3, # optional - sage.rings.finite_rings + ....: point_coordinates=False) + sage: projective_plane_to_OA(p3) # optional - sage.rings.finite_rings [[0, 0, 0, 0], [0, 1, 2, 1], [0, 2, 1, 2], @@ -660,10 +661,11 @@ def projective_plane_to_OA(pplane, pt=None, check=True): [2, 1, 0, 2], [2, 2, 2, 0]] - sage: pp = designs.DesarguesianProjectivePlaneDesign(16,point_coordinates=False) - sage: _ = projective_plane_to_OA(pp, pt=0) - sage: _ = projective_plane_to_OA(pp, pt=3) - sage: _ = projective_plane_to_OA(pp, pt=7) + sage: pp = designs.DesarguesianProjectivePlaneDesign(16, # optional - sage.rings.finite_rings + ....: point_coordinates=False) + sage: _ = projective_plane_to_OA(pp, pt=0) # optional - sage.rings.finite_rings + sage: _ = projective_plane_to_OA(pp, pt=3) # optional - sage.rings.finite_rings + sage: _ = projective_plane_to_OA(pp, pt=7) # optional - sage.rings.finite_rings """ from .bibd import _relabel_bibd pplane = pplane.blocks() @@ -811,27 +813,29 @@ def AffineGeometryDesign(n, d, F, point_coordinates=True, check=True): EXAMPLES:: - sage: BD = designs.AffineGeometryDesign(3, 1, GF(2)) - sage: BD.is_t_design(return_parameters=True) + sage: BD = designs.AffineGeometryDesign(3, 1, GF(2)) # optional - sage.rings.finite_rings + sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings (True, (2, 8, 2, 1)) - sage: BD = designs.AffineGeometryDesign(3, 2, GF(4)) - sage: BD.is_t_design(return_parameters=True) + sage: BD = designs.AffineGeometryDesign(3, 2, GF(4)) # optional - sage.rings.finite_rings + sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings (True, (2, 64, 16, 5)) - sage: BD = designs.AffineGeometryDesign(4, 2, GF(3)) - sage: BD.is_t_design(return_parameters=True) + sage: BD = designs.AffineGeometryDesign(4, 2, GF(3)) # optional - sage.rings.finite_rings + sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings (True, (2, 81, 9, 13)) With ``F`` an integer instead of a finite field:: - sage: BD = designs.AffineGeometryDesign(3, 2, 4) - sage: BD.is_t_design(return_parameters=True) + sage: BD = designs.AffineGeometryDesign(3, 2, 4) # optional - sage.rings.finite_rings + sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings (True, (2, 64, 16, 5)) Testing the option ``point_coordinates``:: - sage: designs.AffineGeometryDesign(3, 1, GF(2), point_coordinates=True).blocks()[0] + sage: designs.AffineGeometryDesign(3, 1, GF(2), # optional - sage.rings.finite_rings + ....: point_coordinates=True).blocks()[0] [(0, 0, 0), (0, 0, 1)] - sage: designs.AffineGeometryDesign(3, 1, GF(2), point_coordinates=False).blocks()[0] + sage: designs.AffineGeometryDesign(3, 1, GF(2), # optional - sage.rings.finite_rings + ....: point_coordinates=False).blocks()[0] [0, 1] """ try: @@ -894,10 +898,10 @@ def CremonaRichmondConfiguration(): EXAMPLES:: - sage: H = designs.CremonaRichmondConfiguration(); H + sage: H = designs.CremonaRichmondConfiguration(); H # optional - networkx Incidence structure with 15 points and 15 blocks - sage: g = graphs.TutteCoxeterGraph() - sage: H.incidence_graph().is_isomorphic(g) + sage: g = graphs.TutteCoxeterGraph() # optional - networkx + sage: H.incidence_graph().is_isomorphic(g) # optional - networkx True """ from sage.graphs.generators.smallgraphs import TutteCoxeterGraph diff --git a/src/sage/combinat/designs/database.py b/src/sage/combinat/designs/database.py index 57060962e69..21039998b45 100644 --- a/src/sage/combinat/designs/database.py +++ b/src/sage/combinat/designs/database.py @@ -81,7 +81,7 @@ def _MOLS_from_string(s,k): EXAMPLES:: - sage: _ = designs.mutually_orthogonal_latin_squares(2,10) # indirect doctest + sage: _ = designs.mutually_orthogonal_latin_squares(2,10) # indirect doctest # optional - sage.modules """ from sage.matrix.constructor import Matrix matrices = [[] for _ in range(k)] @@ -101,13 +101,13 @@ def MOLS_10_2(): sage: from sage.combinat.designs.latin_squares import are_mutually_orthogonal_latin_squares sage: from sage.combinat.designs.database import MOLS_10_2 - sage: MOLS = MOLS_10_2() - sage: print(are_mutually_orthogonal_latin_squares(MOLS)) + sage: MOLS = MOLS_10_2() # optional - sage.modules + sage: print(are_mutually_orthogonal_latin_squares(MOLS)) # optional - sage.modules True The design is available from the general constructor:: - sage: designs.orthogonal_arrays.is_available(2,10) + sage: designs.orthogonal_arrays.is_available(2,10) # optional - sage.modules True """ from sage.matrix.constructor import Matrix @@ -143,8 +143,8 @@ def MOLS_12_5(): sage: from sage.combinat.designs.latin_squares import are_mutually_orthogonal_latin_squares sage: from sage.combinat.designs.database import MOLS_12_5 - sage: MOLS = MOLS_12_5() - sage: print(are_mutually_orthogonal_latin_squares(MOLS)) + sage: MOLS = MOLS_12_5() # optional - sage.modules + sage: print(are_mutually_orthogonal_latin_squares(MOLS)) # optional - sage.modules True """ M = """ @@ -175,8 +175,8 @@ def MOLS_14_4(): sage: from sage.combinat.designs.latin_squares import are_mutually_orthogonal_latin_squares sage: from sage.combinat.designs.database import MOLS_14_4 - sage: MOLS = MOLS_14_4() - sage: print(are_mutually_orthogonal_latin_squares(MOLS)) + sage: MOLS = MOLS_14_4() # optional - sage.modules + sage: print(are_mutually_orthogonal_latin_squares(MOLS)) # optional - sage.modules True The design is available from the general constructor:: @@ -219,8 +219,8 @@ def MOLS_15_4(): sage: from sage.combinat.designs.latin_squares import are_mutually_orthogonal_latin_squares sage: from sage.combinat.designs.database import MOLS_15_4 - sage: MOLS = MOLS_15_4() - sage: print(are_mutually_orthogonal_latin_squares(MOLS)) + sage: MOLS = MOLS_15_4() # optional - sage.modules + sage: print(are_mutually_orthogonal_latin_squares(MOLS)) # optional - sage.modules True The design is available from the general constructor:: @@ -258,8 +258,8 @@ def MOLS_18_3(): sage: from sage.combinat.designs.latin_squares import are_mutually_orthogonal_latin_squares sage: from sage.combinat.designs.database import MOLS_18_3 - sage: MOLS = MOLS_18_3() - sage: print(are_mutually_orthogonal_latin_squares(MOLS)) + sage: MOLS = MOLS_18_3() # optional - sage.modules + sage: print(are_mutually_orthogonal_latin_squares(MOLS)) # optional - sage.modules True The design is available from the general constructor:: @@ -377,8 +377,8 @@ def OA_9_40(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_9_40 - sage: OA = OA_9_40() - sage: is_orthogonal_array(OA,9,40,2) + sage: OA = OA_9_40() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,9,40,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -676,8 +676,8 @@ def OA_11_80(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_11_80 - sage: OA = OA_11_80() - sage: is_orthogonal_array(OA,11,80,2) + sage: OA = OA_11_80() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,11,80,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -718,8 +718,8 @@ def OA_15_112(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_15_112 - sage: OA = OA_15_112() - sage: is_orthogonal_array(OA,15,112,2) + sage: OA = OA_15_112() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,15,112,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -768,8 +768,8 @@ def OA_9_120(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_9_120 - sage: OA = OA_9_120() - sage: is_orthogonal_array(OA,9,120,2) + sage: OA = OA_9_120() # optional - sage.modules + sage: is_orthogonal_array(OA,9,120,2) # optional - sage.modules True The design is available from the general constructor:: @@ -816,8 +816,8 @@ def OA_9_135(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_9_135 - sage: OA = OA_9_135() - sage: is_orthogonal_array(OA,9,135,2) + sage: OA = OA_9_135() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,9,135,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -896,8 +896,8 @@ def OA_11_160(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_11_160 - sage: OA = OA_11_160() - sage: is_orthogonal_array(OA,11,160,2) + sage: OA = OA_11_160() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,11,160,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -939,8 +939,8 @@ def OA_16_176(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_16_176 - sage: OA = OA_16_176() - sage: is_orthogonal_array(OA,16,176,2) + sage: OA = OA_16_176() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,16,176,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -998,8 +998,8 @@ def OA_11_185(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_11_185 - sage: OA = OA_11_185() - sage: is_orthogonal_array(OA,11,185,2) + sage: OA = OA_11_185() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,11,185,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1138,8 +1138,8 @@ def OA_16_208(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_16_208 - sage: OA = OA_16_208() # not tested -- too long - sage: is_orthogonal_array(OA,16,208,2) # not tested -- too long + sage: OA = OA_16_208() # not tested -- too long # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,16,208,2) # not tested -- too long # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1197,8 +1197,8 @@ def OA_15_224(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_15_224 - sage: OA = OA_15_224() # not tested -- too long - sage: is_orthogonal_array(OA,15,224,2) # not tested -- too long + sage: OA = OA_15_224() # not tested -- too long # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,15,224,2) # not tested -- too long # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1283,8 +1283,8 @@ def OA_20_352(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_20_352 - sage: OA = OA_20_352() # not tested (~25s) - sage: is_orthogonal_array(OA,20,352,2) # not tested (~25s) + sage: OA = OA_20_352() # not tested (~25s) # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,20,352,2) # not tested (~25s) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1342,8 +1342,8 @@ def OA_20_416(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_20_416 - sage: OA = OA_20_416() # not tested (~35s) - sage: is_orthogonal_array(OA,20,416,2) # not tested + sage: OA = OA_20_416() # not tested (~35s) # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,20,416,2) # not tested # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1402,8 +1402,8 @@ def OA_20_544(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_20_544 - sage: OA = OA_20_544() # not tested (too long ~1mn) - sage: is_orthogonal_array(OA,20,544,2) # not tested + sage: OA = OA_20_544() # not tested (too long ~1mn) # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,20,544,2) # not tested # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1466,8 +1466,8 @@ def OA_17_560(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_17_560 - sage: OA = OA_17_560() - sage: is_orthogonal_array(OA,17,560,2) + sage: OA = OA_17_560() # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,17,560,2) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1530,8 +1530,8 @@ def OA_11_640(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_11_640 - sage: OA = OA_11_640() # not tested (too long) - sage: is_orthogonal_array(OA,11,640,2) # not tested (too long) + sage: OA = OA_11_640() # not tested (too long) # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,11,640,2) # not tested (too long) # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -1857,8 +1857,8 @@ def OA_15_896(): sage: from sage.combinat.designs.designs_pyx import is_orthogonal_array sage: from sage.combinat.designs.database import OA_15_896 - sage: OA = OA_15_896() # not tested -- too long (~2min) - sage: is_orthogonal_array(OA,15,896,2) # not tested -- too long + sage: OA = OA_15_896() # not tested -- too long (~2min) # optional - sage.rings.finite_rings + sage: is_orthogonal_array(OA,15,896,2) # not tested -- too long # optional - sage.rings.finite_rings True The design is available from the general constructor:: @@ -2194,8 +2194,8 @@ def QDM_25_6_1_1_5(): sage: from sage.combinat.designs.database import QDM_25_6_1_1_5 sage: from sage.combinat.designs.designs_pyx import is_quasi_difference_matrix - sage: G,M = QDM_25_6_1_1_5() - sage: is_quasi_difference_matrix(M,G,6,1,1,5) + sage: G,M = QDM_25_6_1_1_5() # optional - sage.modules + sage: is_quasi_difference_matrix(M,G,6,1,1,5) # optional - sage.modules True """ M = [ @@ -2718,7 +2718,7 @@ def QDM_57_9_1_1_8(): sage: from sage.combinat.designs.designs_pyx import is_quasi_difference_matrix sage: from sage.combinat.designs.orthogonal_arrays import QDM_from_Vmt sage: from sage.combinat.designs.database import Vmt_vectors - sage: for (m,t),(vec,source) in sorted(Vmt_vectors.items()): + sage: for (m,t),(vec,source) in sorted(Vmt_vectors.items()): # optional - sage.rings.finite_rings ....: G,M = QDM_from_Vmt(m,t,vec) ....: if m*t < 600: ....: assert is_quasi_difference_matrix(M,G,m+2,1,1,t,verbose=1),(m,t) @@ -3147,7 +3147,7 @@ def DM_12_6_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(12,6) + sage: _ = designs.difference_matrix(12,6) # optional - sage.rings.finite_rings REFERENCES: @@ -3189,7 +3189,7 @@ def DM_21_6_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(21,6) + sage: _ = designs.difference_matrix(21,6) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.integer_mod_ring import IntegerModRing as AdditiveCyclic M = [[ 8, 17, 20, 2], @@ -3224,7 +3224,7 @@ def DM_24_8_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(24,8) + sage: _ = designs.difference_matrix(24,8) # optional - sage.rings.finite_rings """ M = ("0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 "+ "0000 0010 0100 0110 1000 1010 1100 1110 2000 2010 2100 2110 "+ @@ -3265,13 +3265,13 @@ def DM_28_6_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_28_6_1 - sage: G,M = DM_28_6_1() - sage: is_difference_matrix(M,G,6,1) + sage: G,M = DM_28_6_1() # optional - sage.modules + sage: is_difference_matrix(M,G,6,1) # optional - sage.modules True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(28,6) + sage: _ = designs.difference_matrix(28,6) # optional - sage.modules """ z=2 M = [ @@ -3314,7 +3314,7 @@ def DM_33_6_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(33,6) + sage: _ = designs.difference_matrix(33,6) # optional - sage.rings.finite_rings """ M = [ [ 0, 0, 0, 0, 0, 0], @@ -3356,7 +3356,7 @@ def DM_35_6_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(35,6) + sage: _ = designs.difference_matrix(35,6) # optional - sage.rings.finite_rings """ M = [ [ 0, 15, 30, 10, 25, 1, 16, 31, 11, 26, 2, 17, 32, 12, 6, 3, 18, 33, 27, 21, 4, 19, 13, 7, 22, 5, 34, 28, 8, 23, 20, 14, 29, 9, 24], @@ -3382,13 +3382,13 @@ def DM_36_9_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_36_9_1 - sage: G,M = DM_36_9_1() - sage: is_difference_matrix(M,G,9,1) + sage: G,M = DM_36_9_1() # optional - sage.modules + sage: is_difference_matrix(M,G,9,1) # optional - sage.modules True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(36,9) + sage: _ = designs.difference_matrix(36,9) # optional - sage.modules """ M = [ [(0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0)], @@ -3441,7 +3441,7 @@ def DM_39_6_1(): The design is available from the general constructor:: - sage: designs.difference_matrix(39,6,existence=True) + sage: designs.difference_matrix(39,6,existence=True) # optional - sage.rings.finite_rings True """ M = [ @@ -3485,7 +3485,7 @@ def DM_44_6_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(44,6) + sage: _ = designs.difference_matrix(44,6) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.integer_mod_ring import IntegerModRing as AdditiveCyclic from sage.categories.cartesian_product import cartesian_product @@ -3541,13 +3541,13 @@ def DM_45_7_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_45_7_1 - sage: G,M = DM_45_7_1() - sage: is_difference_matrix(M,G,7,1) + sage: G,M = DM_45_7_1() # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,G,7,1) # optional - sage.rings.finite_rings True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(45,7) + sage: _ = designs.difference_matrix(45,7) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.finite_field_constructor import FiniteField from sage.categories.cartesian_product import cartesian_product @@ -3594,13 +3594,13 @@ def DM_48_9_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_48_9_1 - sage: G,M = DM_48_9_1() - sage: is_difference_matrix(M,G,9,1) + sage: G,M = DM_48_9_1() # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,G,9,1) # optional - sage.rings.finite_rings True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(48,9) + sage: _ = designs.difference_matrix(48,9) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.finite_field_constructor import FiniteField F16 = FiniteField(16,'x') @@ -3649,7 +3649,7 @@ def DM_51_6_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(51,6) + sage: _ = designs.difference_matrix(51,6) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.integer_mod_ring import IntegerModRing as AdditiveCyclic G = AdditiveCyclic(51) @@ -3685,13 +3685,13 @@ def DM_52_6_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_52_6_1 - sage: G,M = DM_52_6_1() - sage: is_difference_matrix(M,G,6,1) + sage: G,M = DM_52_6_1() # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,G,6,1) # optional - sage.rings.finite_rings True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(52,6) + sage: _ = designs.difference_matrix(52,6) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.finite_field_constructor import FiniteField F4 = FiniteField(4,'z') @@ -3763,7 +3763,7 @@ def DM_55_7_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(55,7) + sage: _ = designs.difference_matrix(55,7) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.integer_mod_ring import IntegerModRing as AdditiveCyclic G = AdditiveCyclic(55) @@ -3796,13 +3796,13 @@ def DM_56_8_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_56_8_1 - sage: G,M = DM_56_8_1() - sage: is_difference_matrix(M,G,8,1) + sage: G,M = DM_56_8_1() # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,G,8,1) # optional - sage.rings.finite_rings True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(56,8) + sage: _ = designs.difference_matrix(56,8) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.finite_field_constructor import FiniteField F8 = FiniteField(8,'z') @@ -3843,13 +3843,13 @@ def DM_57_8_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_57_8_1 - sage: G,M = DM_57_8_1() - sage: is_difference_matrix(M,G,8,1) + sage: G,M = DM_57_8_1() # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,G,8,1) # optional - sage.rings.finite_rings True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(57,8) + sage: _ = designs.difference_matrix(57,8) # optional - sage.rings.finite_rings """ M = orthogonal_array(8,8) M = [R for R in M if any(x!=R[0] for x in R)] # removing the 0..0, 1..1, 7..7 rows. @@ -3887,7 +3887,7 @@ def DM_60_6_1(): Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(60,6) + sage: _ = designs.difference_matrix(60,6) # optional - sage.rings.finite_rings """ M60 = [[(0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)], [(1, 10), (1, 6), (0, 17), (0, 7), (1, 5), (0, 9), (0, 3), (1, 13), (1, 17), (0, 13)], @@ -3923,13 +3923,13 @@ def DM_75_8_1(): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: from sage.combinat.designs.database import DM_75_8_1 - sage: G,M = DM_75_8_1() - sage: is_difference_matrix(M,G,8,1) + sage: G,M = DM_75_8_1() # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,G,8,1) # optional - sage.rings.finite_rings True Can be obtained from the constructor:: - sage: _ = designs.difference_matrix(75,8) + sage: _ = designs.difference_matrix(75,8) # optional - sage.rings.finite_rings """ from sage.rings.finite_rings.finite_field_constructor import FiniteField from sage.categories.cartesian_product import cartesian_product @@ -4080,19 +4080,19 @@ def RBIBD_120_8_1(): sage: from sage.combinat.designs.database import RBIBD_120_8_1 sage: from sage.combinat.designs.bibd import is_pairwise_balanced_design - sage: RBIBD = RBIBD_120_8_1() - sage: is_pairwise_balanced_design(RBIBD,120,[8]) + sage: RBIBD = RBIBD_120_8_1() # optional - sage.modules + sage: is_pairwise_balanced_design(RBIBD,120,[8]) # optional - sage.modules True It is indeed resolvable, and the parallel classes are given by 17 slices of consecutive 15 blocks:: - sage: for i in range(17): + sage: for i in range(17): # optional - sage.modules ....: assert len(set(sum(RBIBD[i*15:(i+1)*15],[]))) == 120 The BIBD is available from the constructor:: - sage: _ = designs.balanced_incomplete_block_design(120,8) + sage: _ = designs.balanced_incomplete_block_design(120,8) # optional - sage.modules """ from .incidence_structures import IncidenceStructure n=273 @@ -4148,15 +4148,15 @@ def BIBD_45_9_8(from_code=False): sage: from sage.combinat.designs.database import BIBD_45_9_8 sage: from sage.combinat.designs.bibd import BalancedIncompleteBlockDesign - sage: B = BalancedIncompleteBlockDesign(45, BIBD_45_9_8(),lambd=8); B + sage: B = BalancedIncompleteBlockDesign(45, BIBD_45_9_8(), lambd=8); B # optional - sage.rings.finite_rings (45,9,8)-Balanced Incomplete Block Design TESTS: From the definition (takes around 12s):: - sage: B2 = Hypergraph(BIBD_45_9_8(from_code=True)) # not tested - sage: B2.is_isomorphic(B) # not tested + sage: B2 = Hypergraph(BIBD_45_9_8(from_code=True)) # not tested # optional - sage.rings.finite_rings + sage: B2.is_isomorphic(B) # not tested # optional - sage.rings.finite_rings True REFERENCE: @@ -4580,8 +4580,8 @@ def BIBD_79_13_2(): EXAMPLES: sage: from sage.combinat.designs.database import BIBD_79_13_2 - sage: D = IncidenceStructure(BIBD_79_13_2()) - sage: D.is_t_design(t=2, v=79, k=13, l=2) + sage: D = IncidenceStructure(BIBD_79_13_2()) # optional - sage.libs.gap + sage: D.is_t_design(t=2, v=79, k=13, l=2) # optional - sage.libs.gap True """ from sage.libs.gap.libgap import libgap @@ -4658,8 +4658,8 @@ def BIBD_56_11_2(): EXAMPLES: sage: from sage.combinat.designs.database import BIBD_56_11_2 - sage: D = IncidenceStructure(BIBD_56_11_2()) - sage: D.is_t_design(t=2, v=56, k=11, l=2) + sage: D = IncidenceStructure(BIBD_56_11_2()) # optional - sage.libs.gap + sage: D.is_t_design(t=2, v=56, k=11, l=2) # optional - sage.libs.gap True """ from sage.libs.gap.libgap import libgap diff --git a/src/sage/combinat/designs/designs_pyx.pyx b/src/sage/combinat/designs/designs_pyx.pyx index 8d3e63f7e0e..55cfbca19b1 100644 --- a/src/sage/combinat/designs/designs_pyx.pyx +++ b/src/sage/combinat/designs/designs_pyx.pyx @@ -183,16 +183,16 @@ def is_group_divisible_design(groups,blocks,v,G=None,K=None,lambd=1,verbose=Fals EXAMPLES:: sage: from sage.combinat.designs.designs_pyx import is_group_divisible_design - sage: TD = designs.transversal_design(4,10) - sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] - sage: is_group_divisible_design(groups,TD,40,lambd=1) + sage: TD = designs.transversal_design(4,10) # optional - sage.matrix + sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.matrix + sage: is_group_divisible_design(groups,TD,40,lambd=1) # optional - sage.matrix True TESTS:: - sage: TD = designs.transversal_design(4,10) - sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] - sage: is_group_divisible_design(groups,TD,40,lambd=2,verbose=True) + sage: TD = designs.transversal_design(4,10) # optional - sage.matrix + sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.matrix + sage: is_group_divisible_design(groups, TD, 40, lambd=2, verbose=True) # optional - sage.matrix the pair (0,10) has been seen 1 times but lambda=2 False sage: is_group_divisible_design([[1,2],[3,4]],[[1,2]],40,lambd=1,verbose=True) @@ -362,18 +362,18 @@ def is_pairwise_balanced_design(blocks,v,K=None,lambd=1,verbose=False): sage: sts = designs.steiner_triple_system(9) sage: is_pairwise_balanced_design(sts,9,[3],1) True - sage: TD = designs.transversal_design(4,10).blocks() - sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] - sage: is_pairwise_balanced_design(TD+groups,40,[4,10],1,verbose=True) + sage: TD = designs.transversal_design(4,10).blocks() # optional - sage.matrix + sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.matrix + sage: is_pairwise_balanced_design(TD + groups, 40, [4,10], 1, verbose=True) # optional - sage.matrix True TESTS:: sage: from sage.combinat.designs.designs_pyx import is_pairwise_balanced_design - sage: is_pairwise_balanced_design(TD+groups,40,[4,10],2,verbose=True) + sage: is_pairwise_balanced_design(TD + groups, 40, [4,10], 2, verbose=True) # optional - sage.matrix the pair (0,1) has been seen 1 times but lambda=2 False - sage: is_pairwise_balanced_design(TD+groups,40,[10],1,verbose=True) + sage: is_pairwise_balanced_design(TD + groups, 40, [10], 1, verbose=True) # optional - sage.matrix a block has size 4 while K=[10] False sage: is_pairwise_balanced_design([[2,2]],40,[2],1,verbose=True) @@ -486,39 +486,40 @@ def is_difference_matrix(M,G,k,lmbda=1,verbose=False): sage: from sage.combinat.designs.designs_pyx import is_difference_matrix sage: q = 3**3 - sage: F = GF(q,'x') - sage: M = [[x*y for y in F] for x in F] - sage: is_difference_matrix(M,F,q,verbose=1) + sage: F = GF(q,'x') # optional - sage.rings.finite_rings + sage: M = [[x*y for y in F] for x in F] # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,F,q,verbose=1) # optional - sage.rings.finite_rings True sage: B = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ....: [0, 1, 2, 3, 4, 2, 3, 4, 0, 1], ....: [0, 2, 4, 1, 3, 3, 0, 2, 4, 1]] - sage: G = GF(5) - sage: B = [[G(b) for b in R] for R in B] - sage: is_difference_matrix(list(zip(*B)),G,3,2) + sage: G = GF(5) # optional - sage.rings.finite_rings + sage: B = [[G(b) for b in R] for R in B] # optional - sage.rings.finite_rings + sage: is_difference_matrix(list(zip(*B)),G,3,2) # optional - sage.rings.finite_rings True Bad input:: - sage: for R in M: R.append(None) - sage: is_difference_matrix(M,F,q,verbose=1) + sage: for R in M: R.append(None) # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,F,q,verbose=1) # optional - sage.rings.finite_rings The matrix has 28 columns but k=27 False - sage: for R in M: _=R.pop(-1) - sage: M.append([None]*3**3) - sage: is_difference_matrix(M,F,q,verbose=1) + sage: for R in M: _=R.pop(-1) # optional - sage.rings.finite_rings + sage: M.append([None]*3**3) # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,F,q,verbose=1) # optional - sage.rings.finite_rings The matrix has 28 rows instead of lambda(|G|-1+2u)+mu=1(27-1+2.0)+1=27 False - sage: _= M.pop(-1) - sage: for R in M: R[-1] = 0 - sage: is_difference_matrix(M,F,q,verbose=1) + sage: _= M.pop(-1) # optional - sage.rings.finite_rings + sage: for R in M: R[-1] = 0 # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,F,q,verbose=1) # optional - sage.rings.finite_rings Columns 0 and 26 generate 0 exactly 27 times instead of the expected mu(=1) False - sage: for R in M: R[-1] = 1 - sage: M[-1][-1] = 0 - sage: is_difference_matrix(M,F,q,verbose=1) - Columns 0 and 26 do not generate all elements of G exactly lambda(=1) times. The element x appeared 0 times as a difference. + sage: for R in M: R[-1] = 1 # optional - sage.rings.finite_rings + sage: M[-1][-1] = 0 # optional - sage.rings.finite_rings + sage: is_difference_matrix(M,F,q,verbose=1) # optional - sage.rings.finite_rings + Columns 0 and 26 do not generate all elements of G exactly lambda(=1) times. + The element x appeared 0 times as a difference. False """ return is_quasi_difference_matrix(M,G,k,lmbda=lmbda,mu=lmbda,u=0,verbose=verbose) @@ -559,17 +560,17 @@ def is_quasi_difference_matrix(M,G,int k,int lmbda,int mu,int u,verbose=False): sage: from sage.combinat.designs.designs_pyx import is_quasi_difference_matrix sage: q = 3**3 - sage: F = GF(q,'x') - sage: M = [[x*y for y in F] for x in F] - sage: is_quasi_difference_matrix(M,F,q,1,1,0,verbose=1) + sage: F = GF(q,'x') # optional - sage.rings.finite_rings + sage: M = [[x*y for y in F] for x in F] # optional - sage.rings.finite_rings + sage: is_quasi_difference_matrix(M,F,q,1,1,0,verbose=1) # optional - sage.rings.finite_rings True sage: B = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ....: [0, 1, 2, 3, 4, 2, 3, 4, 0, 1], ....: [0, 2, 4, 1, 3, 3, 0, 2, 4, 1]] - sage: G = GF(5) - sage: B = [[G(b) for b in R] for R in B] - sage: is_quasi_difference_matrix(list(zip(*B)),G,3,2,2,0) + sage: G = GF(5) # optional - sage.rings.finite_rings + sage: B = [[G(b) for b in R] for R in B] # optional - sage.rings.finite_rings + sage: is_quasi_difference_matrix(list(zip(*B)),G,3,2,2,0) # optional - sage.rings.finite_rings True A quasi-difference matrix from the database:: diff --git a/src/sage/combinat/designs/difference_family.py b/src/sage/combinat/designs/difference_family.py index 51cbd1e0501..3001e912234 100644 --- a/src/sage/combinat/designs/difference_family.py +++ b/src/sage/combinat/designs/difference_family.py @@ -5,7 +5,7 @@ This module gathers everything related to difference families. One can build a difference family (or check that it can be built) with :func:`difference_family`:: - sage: G,F = designs.difference_family(13,4,1) + sage: G,F = designs.difference_family(13,4,1) # optional - sage.modules It defines the following functions: @@ -70,9 +70,9 @@ def group_law(G): sage: from sage.combinat.designs.difference_family import group_law sage: group_law(Zmod(3)) (0, , ) - sage: group_law(SymmetricGroup(5)) + sage: group_law(SymmetricGroup(5)) # optional - sage.groups ((), , ) - sage: group_law(VectorSpace(QQ,3)) + sage: group_law(VectorSpace(QQ, 3)) # optional - sage.modules ((0, 0, 0), , ) """ import operator @@ -176,13 +176,13 @@ def is_difference_family(G, D, v=None, k=None, l=None, verbose=False): sage: is_difference_family(G, D) True - sage: G = AdditiveAbelianGroup([3]*4) - sage: a,b,c,d = G.gens() - sage: D = [[d, -a+d, -c+d, a-b-d, b+c+d], + sage: G = AdditiveAbelianGroup([3]*4) # optional - sage.modules + sage: a,b,c,d = G.gens() # optional - sage.modules + sage: D = [[d, -a+d, -c+d, a-b-d, b+c+d], # optional - sage.modules ....: [c, a+b-d, -b+c, a-b+d, a+b+c], ....: [-a-b+c+d, a-b-c-d, -a+c-d, b-c+d, a+b], ....: [-b-d, a+b+d, a-b+c-d, a-b+c, -b+c+d]] - sage: is_difference_family(G, D) + sage: is_difference_family(G, D) # optional - sage.modules True The following example has a third block with a non-trivial stabilizer:: @@ -195,23 +195,23 @@ def is_difference_family(G, D, v=None, k=None, l=None, verbose=False): The function also supports multiplicative groups (non necessarily Abelian):: - sage: G = DihedralGroup(8) - sage: x,y = G.gens() - sage: i = G.one() - sage: D1 = [[i,x,x^4], [i,x^2, y*x], [i,x^5,y], [i,x^6,y*x^2], [i,x^7,y*x^5]] - sage: is_difference_family(G, D1, 16, 3, 2) + sage: G = DihedralGroup(8) # optional - sage.groups + sage: x,y = G.gens() # optional - sage.groups + sage: i = G.one() # optional - sage.groups + sage: D1 = [[i,x,x^4], [i,x^2, y*x], [i,x^5,y], [i,x^6,y*x^2], [i,x^7,y*x^5]] # optional - sage.groups + sage: is_difference_family(G, D1, 16, 3, 2) # optional - sage.groups True sage: from sage.combinat.designs.bibd import BIBD_from_difference_family - sage: bibd = BIBD_from_difference_family(G,D1,lambd=2) + sage: bibd = BIBD_from_difference_family(G, D1, lambd=2) # optional - sage.groups TESTS:: - sage: K = GF(3^2,'z') - sage: z = K.gen() - sage: D = [[1,z+1,2]] - sage: _ = is_difference_family(K, D, verbose=True) + sage: K = GF(3^2,'z') # optional - sage.rings.finite_rings + sage: z = K.gen() # optional - sage.rings.finite_rings + sage: D = [[1,z+1,2]] # optional - sage.rings.finite_rings + sage: _ = is_difference_family(K, D, verbose=True) # optional - sage.rings.finite_rings the number of differences (=6) must be a multiple of v-1=8 - sage: _ + sage: _ # optional - sage.rings.finite_rings False """ identity, mul, inv = group_law(G) @@ -353,23 +353,23 @@ def singer_difference_set(q,d): EXAMPLES:: sage: from sage.combinat.designs.difference_family import singer_difference_set, is_difference_family - sage: G,D = singer_difference_set(3,2) - sage: is_difference_family(G,D,verbose=True) + sage: G,D = singer_difference_set(3,2) # optional - sage.rings.finite_rings + sage: is_difference_family(G, D, verbose=True) # optional - sage.rings.finite_rings It is a (13,4,1)-difference family True - sage: G,D = singer_difference_set(4,2) - sage: is_difference_family(G,D,verbose=True) + sage: G,D = singer_difference_set(4,2) # optional - sage.rings.finite_rings + sage: is_difference_family(G, D, verbose=True) # optional - sage.rings.finite_rings It is a (21,5,1)-difference family True - sage: G,D = singer_difference_set(3,3) - sage: is_difference_family(G,D,verbose=True) + sage: G,D = singer_difference_set(3,3) # optional - sage.rings.finite_rings + sage: is_difference_family(G, D, verbose=True) # optional - sage.rings.finite_rings It is a (40,13,4)-difference family True - sage: G,D = singer_difference_set(9,3) - sage: is_difference_family(G,D,verbose=True) + sage: G,D = singer_difference_set(9,3) # optional - sage.rings.finite_rings + sage: is_difference_family(G, D, verbose=True) # optional - sage.rings.finite_rings It is a (820,91,10)-difference family True """ @@ -418,11 +418,12 @@ def df_q_6_1(K, existence=False, check=True): EXAMPLES:: sage: from sage.combinat.designs.difference_family import is_difference_family, df_q_6_1 - sage: prime_powers = [v for v in range(31,500,30) if is_prime_power(v)] - sage: parameters = [v for v in prime_powers if df_q_6_1(GF(v,'a'), existence=True) is True] - sage: parameters + sage: prime_powers = [v for v in range(31,500,30) if is_prime_power(v)] # optional - sage.rings.finite_rings + sage: parameters = [v for v in prime_powers # optional - sage.rings.finite_rings + ....: if df_q_6_1(GF(v,'a'), existence=True) is True] + sage: parameters # optional - sage.rings.finite_rings [31, 151, 181, 211, 241, 271, 331, 361, 421] - sage: for v in parameters: + sage: for v in parameters: # optional - sage.rings.finite_rings ....: K = GF(v, 'a') ....: df = df_q_6_1(K, check=True) ....: assert is_difference_family(K, df, v, 6, 1) @@ -478,13 +479,13 @@ def radical_difference_set(K, k, l=1, existence=False, check=True): sage: from sage.combinat.designs.difference_family import radical_difference_set - sage: D = radical_difference_set(GF(7), 3, 1); D + sage: D = radical_difference_set(GF(7), 3, 1); D # optional - sage.rings.finite_rings [[1, 2, 4]] - sage: sorted(x-y for x in D[0] for y in D[0] if x != y) + sage: sorted(x-y for x in D[0] for y in D[0] if x != y) # optional - sage.rings.finite_rings [1, 2, 3, 4, 5, 6] - sage: D = radical_difference_set(GF(16,'a'), 6, 2) - sage: sorted(x-y for x in D[0] for y in D[0] if x != y) + sage: D = radical_difference_set(GF(16,'a'), 6, 2) # optional - sage.rings.finite_rings + sage: sorted(x-y for x in D[0] for y in D[0] if x != y) # optional - sage.rings.finite_rings [1, 1, a, @@ -497,7 +498,7 @@ def radical_difference_set(K, k, l=1, existence=False, check=True): a^3 + a^2 + a + 1, a^3 + a^2 + a + 1] - sage: for k in range(2,50): + sage: for k in range(2,50): # optional - sage.rings.finite_rings ....: for l in reversed(divisors(k*(k-1))): ....: v = k*(k-1)//l + 1 ....: if is_prime_power(v) and radical_difference_set(GF(v,'a'),k,l,existence=True) is True: @@ -756,12 +757,12 @@ def one_radical_difference_family(K, k): ....: one_radical_difference_family, ....: is_difference_family) - sage: one_radical_difference_family(GF(13),4) + sage: one_radical_difference_family(GF(13),4) # optional - sage.rings.finite_rings [[0, 1, 3, 9]] The parameters that appear in [Bu95]_:: - sage: df = one_radical_difference_family(GF(449), 8); df + sage: df = one_radical_difference_family(GF(449), 8); df # optional - sage.rings.finite_rings [[0, 1, 18, 25, 176, 324, 359, 444], [0, 9, 88, 162, 222, 225, 237, 404], [0, 11, 140, 198, 275, 357, 394, 421], @@ -770,7 +771,7 @@ def one_radical_difference_family(K, k): [0, 70, 99, 197, 230, 362, 403, 435], [0, 121, 141, 193, 293, 331, 335, 382], [0, 191, 285, 295, 321, 371, 390, 392]] - sage: is_difference_family(GF(449), df, 449, 8, 1) + sage: is_difference_family(GF(449), df, 449, 8, 1) # optional - sage.rings.finite_rings True """ q = K.cardinality() @@ -842,10 +843,10 @@ def radical_difference_family(K, k, l=1, existence=False, check=True): sage: from sage.combinat.designs.difference_family import radical_difference_family - sage: radical_difference_family(GF(73),9) + sage: radical_difference_family(GF(73), 9) # optional - sage.rings.finite_rings [[1, 2, 4, 8, 16, 32, 37, 55, 64]] - sage: radical_difference_family(GF(281),5) + sage: radical_difference_family(GF(281), 5) # optional - sage.rings.finite_rings [[1, 86, 90, 153, 232], [4, 50, 63, 79, 85], [5, 36, 149, 169, 203], @@ -861,7 +862,7 @@ def radical_difference_family(K, k, l=1, existence=False, check=True): [111, 123, 155, 181, 273], [156, 209, 224, 264, 271]] - sage: for k in range(5,10): + sage: for k in range(5,10): # optional - sage.rings.finite_rings ....: print("k = {}".format(k)) ....: list_q = [] ....: for q in range(k*(k-1)+1, 2000, k*(k-1)): @@ -945,10 +946,10 @@ def twin_prime_powers_difference_set(p, check=True): EXAMPLES:: sage: from sage.combinat.designs.difference_family import twin_prime_powers_difference_set - sage: G,D = twin_prime_powers_difference_set(3) - sage: G + sage: G, D = twin_prime_powers_difference_set(3) # optional - sage.rings.finite_rings + sage: G # optional - sage.rings.finite_rings The Cartesian product of (Finite Field of size 3, Finite Field of size 5) - sage: D + sage: D # optional - sage.rings.finite_rings [[(1, 1), (1, 4), (2, 2), (2, 3), (0, 0), (1, 0), (2, 0)]] """ from sage.rings.finite_rings.finite_field_constructor import FiniteField @@ -997,19 +998,19 @@ def are_mcfarland_1973_parameters(v, k, lmbda, return_parameters=False): EXAMPLES:: sage: from sage.combinat.designs.difference_family import are_mcfarland_1973_parameters - sage: are_mcfarland_1973_parameters(64, 28, 12) + sage: are_mcfarland_1973_parameters(64, 28, 12) # optional - sage.rings.finite_rings True - sage: are_mcfarland_1973_parameters(64, 28, 12, return_parameters=True) + sage: are_mcfarland_1973_parameters(64, 28, 12, return_parameters=True) # optional - sage.rings.finite_rings (True, (2, 2)) - sage: are_mcfarland_1973_parameters(60, 13, 5) + sage: are_mcfarland_1973_parameters(60, 13, 5) # optional - sage.rings.finite_rings False - sage: are_mcfarland_1973_parameters(98125, 19500, 3875) + sage: are_mcfarland_1973_parameters(98125, 19500, 3875) # optional - sage.rings.finite_rings True - sage: are_mcfarland_1973_parameters(98125, 19500, 3875, True) + sage: are_mcfarland_1973_parameters(98125, 19500, 3875, True) # optional - sage.rings.finite_rings (True, (5, 3)) sage: from sage.combinat.designs.difference_family import are_mcfarland_1973_parameters - sage: for v in range(1, 100): + sage: for v in range(1, 100): # optional - sage.rings.finite_rings ....: for k in range(1,30): ....: for l in range(1,15): ....: if are_mcfarland_1973_parameters(v,k,l): @@ -1087,11 +1088,11 @@ def mcfarland_1973_construction(q, s): sage: from sage.combinat.designs.difference_family import ( ....: mcfarland_1973_construction, is_difference_family) - sage: G,D = mcfarland_1973_construction(3, 1) - sage: assert is_difference_family(G, D, 45, 12, 3) + sage: G,D = mcfarland_1973_construction(3, 1) # optional - sage.modules sage.rings.finite_rings + sage: assert is_difference_family(G, D, 45, 12, 3) # optional - sage.modules sage.rings.finite_rings - sage: G,D = mcfarland_1973_construction(2, 2) - sage: assert is_difference_family(G, D, 64, 28, 12) + sage: G,D = mcfarland_1973_construction(2, 2) # optional - sage.modules sage.rings.finite_rings + sage: assert is_difference_family(G, D, 64, 28, 12) # optional - sage.modules sage.rings.finite_rings """ from sage.rings.finite_rings.finite_field_constructor import GF from sage.modules.free_module import VectorSpace @@ -1150,7 +1151,7 @@ def hadamard_difference_set_product_parameters(N): EXAMPLES:: sage: from sage.combinat.designs.difference_family import hadamard_difference_set_product_parameters - sage: hadamard_difference_set_product_parameters(8) + sage: hadamard_difference_set_product_parameters(8) # optional - sage.rings.finite_rings (2, 2) """ if N % 2: @@ -1190,16 +1191,16 @@ def hadamard_difference_set_product(G1, D1, G2, D2): sage: from sage.combinat.designs.difference_family import hadamard_difference_set_product sage: from sage.combinat.designs.difference_family import is_difference_family - sage: G1,D1 = designs.difference_family(16,6,2) - sage: G2,D2 = designs.difference_family(36,15,6) + sage: G1,D1 = designs.difference_family(16,6,2) # optional - sage.rings.finite_rings + sage: G2,D2 = designs.difference_family(36,15,6) # optional - sage.rings.finite_rings - sage: G11,D11 = hadamard_difference_set_product(G1,D1,G1,D1) - sage: assert is_difference_family(G11, D11, 256, 120, 56) - sage: assert designs.difference_family(256, 120, 56, existence=True) is True + sage: G11,D11 = hadamard_difference_set_product(G1,D1,G1,D1) # optional - sage.rings.finite_rings + sage: assert is_difference_family(G11, D11, 256, 120, 56) # optional - sage.rings.finite_rings + sage: assert designs.difference_family(256, 120, 56, existence=True) is True # optional - sage.rings.finite_rings - sage: G12,D12 = hadamard_difference_set_product(G1,D1,G2,D2) - sage: assert is_difference_family(G12, D12, 576, 276, 132) - sage: assert designs.difference_family(576, 276, 132, existence=True) is True + sage: G12,D12 = hadamard_difference_set_product(G1,D1,G2,D2) # optional - sage.rings.finite_rings + sage: assert is_difference_family(G12, D12, 576, 276, 132) # optional - sage.rings.finite_rings + sage: assert designs.difference_family(576, 276, 132, existence=True) is True # optional - sage.rings.finite_rings """ from sage.categories.cartesian_product import cartesian_product @@ -1316,11 +1317,11 @@ def _create_m_sequence(q, n, check=True): EXAMPLES:: sage: from sage.combinat.designs.difference_family import _create_m_sequence - sage: _create_m_sequence(3, 2) #random + sage: _create_m_sequence(3, 2) # random # optional - sage.rings.finite_rings [1, 0, 1, 2, 2, 0, 2, 1] - sage: _create_m_sequence(4, 2, check=False) #random + sage: _create_m_sequence(4, 2, check=False) # random # optional - sage.rings.finite_rings [1, 0, a, a + 1, a, a, 0, a + 1, 1, a + 1, a + 1, 0, 1, a, 1] - sage: _create_m_sequence(6, 2) + sage: _create_m_sequence(6, 2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: q must be a prime power @@ -1371,11 +1372,11 @@ def _get_submodule_of_order(G, order): TESTS: sage: from sage.combinat.designs.difference_family import _get_submodule_of_order - sage: G = AdditiveAbelianGroup([48]) - sage: _get_submodule_of_order(G, 6).order() + sage: G = AdditiveAbelianGroup([48]) # optional - sage.modules + sage: _get_submodule_of_order(G, 6).order() # optional - sage.modules 6 - sage: G = AdditiveAbelianGroup([13^2-1]) - sage: _get_submodule_of_order(G, 12).order() + sage: G = AdditiveAbelianGroup([13^2 - 1]) # optional - sage.modules + sage: _get_submodule_of_order(G, 12).order() # optional - sage.modules 12 """ for el in G: @@ -1409,12 +1410,13 @@ def relative_difference_set_from_m_sequence(q, N, check=True, return_group=False EXAMPLES:: sage: from sage.combinat.designs.difference_family import relative_difference_set_from_m_sequence - sage: relative_difference_set_from_m_sequence(2, 4, return_group=True) #random + sage: relative_difference_set_from_m_sequence(2, 4, # random # optional - sage.modules sage.rings.finite_rings + ....: return_group=True) (Additive abelian group isomorphic to Z/15, [(0), (4), (5), (6), (7), (9), (11), (12)]) - sage: relative_difference_set_from_m_sequence(8, 2, check=False) #random + sage: relative_difference_set_from_m_sequence(8, 2, check=False) # random # optional - sage.modules sage.rings.finite_rings [(0), (6), (30), (40), (41), (44), (56), (61)] - sage: relative_difference_set_from_m_sequence(6, 2) + sage: relative_difference_set_from_m_sequence(6, 2) # optional - sage.modules sage.rings.finite_rings Traceback (most recent call last): ... ValueError: q must be a prime power @@ -1423,14 +1425,18 @@ def relative_difference_set_from_m_sequence(q, N, check=True, return_group=False sage: from sage.combinat.designs.difference_family import is_relative_difference_set, _get_submodule_of_order sage: q, N = 5, 3 - sage: G, D = relative_difference_set_from_m_sequence(q, N, check=False, return_group=True) - sage: H = _get_submodule_of_order(G, q-1) - sage: is_relative_difference_set(D, G, H, ((q^N-1)//(q-1), q-1, q^(N-1), q^(N-2))) + sage: G, D = relative_difference_set_from_m_sequence(q, N, check=False, # optional - sage.modules sage.rings.finite_rings + ....: return_group=True) + sage: H = _get_submodule_of_order(G, q-1) # optional - sage.modules sage.rings.finite_rings + sage: is_relative_difference_set(D, G, H, # optional - sage.modules sage.rings.finite_rings + ....: ((q^N-1)//(q-1), q-1, q^(N-1), q^(N-2))) True sage: q, N = 13, 2 - sage: G, D = relative_difference_set_from_m_sequence(q, N, check=False, return_group=True) - sage: H = _get_submodule_of_order(G, q-1) - sage: is_relative_difference_set(D, G, H, ((q^N-1)//(q-1), q-1, q^(N-1), q^(N-2))) + sage: G, D = relative_difference_set_from_m_sequence(q, N, check=False, # optional - sage.modules sage.rings.finite_rings + ....: return_group=True) + sage: H = _get_submodule_of_order(G, q-1) # optional - sage.modules sage.rings.finite_rings + sage: is_relative_difference_set(D, G, H, # optional - sage.modules sage.rings.finite_rings + ....: ((q^N-1)//(q-1), q-1, q^(N-1), q^(N-2))) True """ from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup @@ -1484,7 +1490,7 @@ def relative_difference_set_from_homomorphism(q, N, d, check=True, return_group= sage: relative_difference_set_from_homomorphism(9, 2, 4, check=False, return_group=True) #random (Additive abelian group isomorphic to Z/80, [(0), (4), (6), (13), (7), (12), (15), (8), (9)]) - sage: relative_difference_set_from_homomorphism(9, 2, 5) + sage: relative_difference_set_from_homomorphism(9, 2, 5) # optional - sage.modules sage.rings.finite_rings Traceback (most recent call last): ... ValueError: q-1 must be a multiple of d @@ -1493,14 +1499,18 @@ def relative_difference_set_from_homomorphism(q, N, d, check=True, return_group= sage: from sage.combinat.designs.difference_family import is_relative_difference_set, _get_submodule_of_order sage: q, N, d = 11, 2, 5 - sage: G, D = relative_difference_set_from_homomorphism(q, N, d, check=False, return_group=True) - sage: H = _get_submodule_of_order(G, (q-1)//d) - sage: is_relative_difference_set(D, G, H, ((q**N-1)//(q-1), (q-1)//d, q**(N-1), q**(N-2)*d)) + sage: G, D = relative_difference_set_from_homomorphism(q, N, d, check=False, # optional - sage.modules sage.rings.finite_rings + ....: return_group=True) + sage: H = _get_submodule_of_order(G, (q-1)//d) # optional - sage.modules sage.rings.finite_rings + sage: is_relative_difference_set(D, G, H, # optional - sage.modules sage.rings.finite_rings + ....: ((q**N-1)//(q-1), (q-1)//d, q**(N-1), q**(N-2)*d)) True sage: q, N, d = 9, 2, 4 - sage: G, D = relative_difference_set_from_homomorphism(q, N, d, check=False, return_group=True) - sage: H = _get_submodule_of_order(G, (q-1)//d) - sage: is_relative_difference_set(D, G, H, ((q**N-1)//(q-1), (q-1)//d, q**(N-1), q**(N-2)*d)) + sage: G, D = relative_difference_set_from_homomorphism(q, N, d, check=False, # optional - sage.modules sage.rings.finite_rings + ....: return_group=True) + sage: H = _get_submodule_of_order(G, (q-1)//d) # optional - sage.modules sage.rings.finite_rings + sage: is_relative_difference_set(D, G, H, # optional - sage.modules sage.rings.finite_rings + ....: ((q**N-1)//(q-1), (q-1)//d, q**(N-1), q**(N-2)*d)) True """ from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup @@ -1554,15 +1564,15 @@ def is_relative_difference_set(R, G, H, params, verbose=False): sage: from sage.combinat.designs.difference_family import _get_submodule_of_order, relative_difference_set_from_m_sequence, is_relative_difference_set sage: q, N = 5, 2 sage: params = ((q^N-1) // (q-1), q - 1, q^(N-1), q^(N-2)) - sage: G, R = relative_difference_set_from_m_sequence(q, N, return_group=True) - sage: H = _get_submodule_of_order(G, q - 1) - sage: is_relative_difference_set(R, G, H, params) + sage: G, R = relative_difference_set_from_m_sequence(q, N, return_group=True) # optional - sage.modules + sage: H = _get_submodule_of_order(G, q - 1) # optional - sage.modules + sage: is_relative_difference_set(R, G, H, params) # optional - sage.modules True If we pass the ``verbose`` argument, the function will explain why it failed:: - sage: R2 = [G[1], G[2], G[3], G[5], G[6]] - sage: is_relative_difference_set(R2, G, H, params, verbose=True) + sage: R2 = [G[1], G[2], G[3], G[5], G[6]] # optional - sage.modules + sage: is_relative_difference_set(R2, G, H, params, verbose=True) # optional - sage.modules There is a value in the difference set which is not repeated d times False """ @@ -1632,32 +1642,33 @@ def is_supplementary_difference_set(Ks, v=None, lmbda=None, G=None, verbose=Fals EXAMPLES:: sage: from sage.combinat.designs.difference_family import supplementary_difference_set_from_rel_diff_set, is_supplementary_difference_set - sage: G, [S1, S2, S3, S4] = supplementary_difference_set_from_rel_diff_set(17) - sage: is_supplementary_difference_set([S1, S2, S3, S4], lmbda=16, G=G) + sage: G, [S1, S2, S3, S4] = supplementary_difference_set_from_rel_diff_set(17) # optional - sage.modules sage.rings.finite_rings + sage: is_supplementary_difference_set([S1, S2, S3, S4], lmbda=16, G=G) # optional - sage.modules sage.rings.finite_rings True The parameter ``v`` can be given instead of ``G``:: - sage: is_supplementary_difference_set([S1, S2, S3, S4], v=16, lmbda=16) + sage: is_supplementary_difference_set([S1, S2, S3, S4], v=16, lmbda=16) # optional - sage.modules sage.rings.finite_rings True - sage: is_supplementary_difference_set([S1, S2, S3, S4], v=20, lmbda=16) + sage: is_supplementary_difference_set([S1, S2, S3, S4], v=20, lmbda=16) # optional - sage.modules sage.rings.finite_rings False If ``verbose=True``, the function will be verbose:: - sage: is_supplementary_difference_set([S1, S2, S3, S4], lmbda=14, G=G, verbose=True) + sage: is_supplementary_difference_set([S1, S2, S3, S4], lmbda=14, G=G, # optional - sage.modules sage.rings.finite_rings + ....: verbose=True) Number of pairs with difference (1) is 16, but lambda is 14 False TESTS:: - sage: is_supplementary_difference_set([[1], [1]], lmbda=0, G=Zmod(3)) + sage: is_supplementary_difference_set([[1], [1]], lmbda=0, G=Zmod(3)) # optional - sage.modules sage.rings.finite_rings True - sage: is_supplementary_difference_set([S1, S2, S3, S4], v=17, lmbda=16, G=G) + sage: is_supplementary_difference_set([S1, S2, S3, S4], v=17, lmbda=16, G=G) # optional - sage.modules sage.rings.finite_rings False - sage: is_supplementary_difference_set([S1, S2, S3, S4], G=G) + sage: is_supplementary_difference_set([S1, S2, S3, S4], G=G) # optional - sage.modules sage.rings.finite_rings True - sage: is_supplementary_difference_set([S1, S2, S3, S4], lmbda=16) + sage: is_supplementary_difference_set([S1, S2, S3, S4], lmbda=16) # optional - sage.modules sage.rings.finite_rings Traceback (most recent call last): ... ValueError: one of G or v must be specified @@ -1912,30 +1923,30 @@ def get_fixed_relative_difference_set(G, rel_diff_set, as_elements=False): EXAMPLES:: sage: from sage.combinat.designs.difference_family import relative_difference_set_from_m_sequence, get_fixed_relative_difference_set - sage: G, s1 = relative_difference_set_from_m_sequence(5, 2, return_group=True) - sage: get_fixed_relative_difference_set(G, s1) #random + sage: G, s1 = relative_difference_set_from_m_sequence(5, 2, return_group=True) # optional - sage.modules + sage: get_fixed_relative_difference_set(G, s1) # random # optional - sage.modules [2, 10, 19, 23, 0] If ``as_elements=True``, the result will contain elements of the group:: - sage: get_fixed_relative_difference_set(G, s1, as_elements=True) #random + sage: get_fixed_relative_difference_set(G, s1, as_elements=True) # random # optional - sage.modules [(2), (10), (19), (23), (0)] TESTS:: sage: from sage.combinat.designs.difference_family import is_fixed_relative_difference_set - sage: G, s1 = relative_difference_set_from_m_sequence(5, 2, return_group=True) - sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=True) - sage: is_fixed_relative_difference_set(s2, len(s2)) + sage: G, s1 = relative_difference_set_from_m_sequence(5, 2, return_group=True) # optional - sage.modules + sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=True) # optional - sage.modules + sage: is_fixed_relative_difference_set(s2, len(s2)) # optional - sage.modules True - sage: G, s1 = relative_difference_set_from_m_sequence(9, 2, return_group=True) - sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=True) - sage: is_fixed_relative_difference_set(s2, len(s2)) + sage: G, s1 = relative_difference_set_from_m_sequence(9, 2, return_group=True) # optional - sage.modules + sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=True) # optional - sage.modules + sage: is_fixed_relative_difference_set(s2, len(s2)) # optional - sage.modules True - sage: type(s2[0]) + sage: type(s2[0]) # optional - sage.modules - sage: s2 = get_fixed_relative_difference_set(G, s1) - sage: type(s2[0]) + sage: s2 = get_fixed_relative_difference_set(G, s1) # optional - sage.modules + sage: type(s2[0]) # optional - sage.modules """ q = len(rel_diff_set) @@ -1976,20 +1987,20 @@ def is_fixed_relative_difference_set(R, q): EXAMPLES:: sage: from sage.combinat.designs.difference_family import relative_difference_set_from_m_sequence, get_fixed_relative_difference_set, is_fixed_relative_difference_set - sage: G, s1 = relative_difference_set_from_m_sequence(7, 2, return_group=True) - sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=True) - sage: is_fixed_relative_difference_set(s2, len(s2)) + sage: G, s1 = relative_difference_set_from_m_sequence(7, 2, return_group=True) # optional - sage.modules + sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=True) # optional - sage.modules + sage: is_fixed_relative_difference_set(s2, len(s2)) # optional - sage.modules True - sage: G = AdditiveAbelianGroup([15]) - sage: s3 = [G[1], G[2], G[3], G[4]] - sage: is_fixed_relative_difference_set(s3, len(s3)) + sage: G = AdditiveAbelianGroup([15]) # optional - sage.modules + sage: s3 = [G[1], G[2], G[3], G[4]] # optional - sage.modules + sage: is_fixed_relative_difference_set(s3, len(s3)) # optional - sage.modules False If the relative difference set does not contain elements of the group, the method returns false:: - sage: G, s1 = relative_difference_set_from_m_sequence(7, 2, return_group=True) - sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=False) - sage: is_fixed_relative_difference_set(s2, len(s2)) + sage: G, s1 = relative_difference_set_from_m_sequence(7, 2, return_group=True) # optional - sage.modules + sage: s2 = get_fixed_relative_difference_set(G, s1, as_elements=False) # optional - sage.modules + sage: is_fixed_relative_difference_set(s2, len(s2)) # optional - sage.modules False """ for el in R: diff --git a/src/sage/combinat/designs/evenly_distributed_sets.pyx b/src/sage/combinat/designs/evenly_distributed_sets.pyx index 493d48d2ad5..a19267a4bdb 100644 --- a/src/sage/combinat/designs/evenly_distributed_sets.pyx +++ b/src/sage/combinat/designs/evenly_distributed_sets.pyx @@ -111,7 +111,7 @@ cdef class EvenlyDistributedSetsBacktracker: Or only count them:: - sage: for k in range(13, 200, 12): + sage: for k in range(13, 200, 12): # optional - sage.rings.finite_rings ....: if is_prime_power(k): ....: K = GF(k,'a') ....: E1 = EvenlyDistributedSetsBacktracker(K, 4, False) @@ -357,9 +357,10 @@ cdef class EvenlyDistributedSetsBacktracker: sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker - sage: EvenlyDistributedSetsBacktracker(GF(25,'a'), 4) + sage: EvenlyDistributedSetsBacktracker(GF(25,'a'), 4) # optional - sage.rings.finite_rings 4-evenly distributed sets (up to isomorphism) in Finite Field in a of size 5^2 - sage: EvenlyDistributedSetsBacktracker(GF(25,'a'), 4, up_to_isomorphism=False) + sage: EvenlyDistributedSetsBacktracker(GF(25,'a'), 4, # optional - sage.rings.finite_rings + ....: up_to_isomorphism=False) 4-evenly distributed sets in Finite Field in a of size 5^2 """ return "{}-evenly distributed sets {} in {}".format( @@ -378,14 +379,15 @@ cdef class EvenlyDistributedSetsBacktracker: sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker - sage: E = EvenlyDistributedSetsBacktracker(GF(25,'a'),4) - sage: E - 4-evenly distributed sets (up to isomorphism) in Finite Field in a of size 5^2 - sage: E.cardinality() + sage: E = EvenlyDistributedSetsBacktracker(GF(25,'a'), 4); E # optional - sage.rings.finite_rings + 4-evenly distributed sets (up to isomorphism) + in Finite Field in a of size 5^2 + sage: E.cardinality() # optional - sage.rings.finite_rings 4 - sage: E = EvenlyDistributedSetsBacktracker(GF(25,'a'), 4, up_to_isomorphism=False) - sage: E.cardinality() + sage: E = EvenlyDistributedSetsBacktracker(GF(25,'a'), 4, # optional - sage.rings.finite_rings + ....: up_to_isomorphism=False) + sage: E.cardinality() # optional - sage.rings.finite_rings 40 """ cdef n = 0 diff --git a/src/sage/combinat/designs/twographs.py b/src/sage/combinat/designs/twographs.py index 56c01c4bc5e..32a844083b9 100644 --- a/src/sage/combinat/designs/twographs.py +++ b/src/sage/combinat/designs/twographs.py @@ -84,8 +84,8 @@ def __init__(self, points=None, blocks=None, incidence_matrix=None, Traceback (most recent call last): ... AssertionError: the structure is not a 2-graph! - sage: p=graphs.PetersenGraph().twograph() - sage: TwoGraph(p, check=True) + sage: p = graphs.PetersenGraph().twograph() # optional - sage.modules + sage: TwoGraph(p, check=True) # optional - sage.modules Incidence structure with 10 points and 60 blocks """ IncidenceStructure.__init__(self, points=points, blocks=blocks, @@ -108,15 +108,15 @@ def is_regular_twograph(self, alpha=False): EXAMPLES:: - sage: p=graphs.PetersenGraph().twograph() - sage: p.is_regular_twograph(alpha=True) + sage: p = graphs.PetersenGraph().twograph() # optional - sage.modules + sage: p.is_regular_twograph(alpha=True) # optional - sage.modules 4 - sage: p.is_regular_twograph() + sage: p.is_regular_twograph() # optional - sage.modules True - sage: p=graphs.PathGraph(5).twograph() - sage: p.is_regular_twograph(alpha=True) + sage: p = graphs.PathGraph(5).twograph() # optional - sage.modules + sage: p.is_regular_twograph(alpha=True) # optional - sage.modules False - sage: p.is_regular_twograph() + sage: p.is_regular_twograph() # optional - sage.modules False """ r, (_, _, _, a) = self.is_t_design(t=2, k=3, return_parameters=True) @@ -139,8 +139,8 @@ def descendant(self, v): EXAMPLES:: - sage: p = graphs.PetersenGraph().twograph().descendant(0) - sage: p.is_strongly_regular(parameters=True) + sage: p = graphs.PetersenGraph().twograph().descendant(0) # optional - sage.modules + sage: p.is_strongly_regular(parameters=True) # optional - sage.modules (9, 4, 1, 2) """ from sage.graphs.graph import Graph @@ -159,14 +159,14 @@ def complement(self): EXAMPLES:: - sage: p = graphs.CompleteGraph(8).line_graph().twograph() - sage: pc = p.complement(); pc + sage: p = graphs.CompleteGraph(8).line_graph().twograph() # optional - sage.modules + sage: pc = p.complement(); pc # optional - sage.modules Incidence structure with 28 points and 1260 blocks TESTS:: sage: from sage.combinat.designs.twographs import is_twograph - sage: is_twograph(pc) + sage: is_twograph(pc) # optional - sage.modules True """ return super().complement(uniform=True) @@ -192,7 +192,7 @@ def taylor_twograph(q): EXAMPLES:: sage: from sage.combinat.designs.twographs import taylor_twograph - sage: T=taylor_twograph(3); T + sage: T = taylor_twograph(3); T # optional - sage.rings.finite_rings Incidence structure with 28 points and 1260 blocks """ from sage.graphs.generators.classical_geometries import TaylorTwographSRG @@ -211,13 +211,13 @@ def is_twograph(T): a two-graph from a graph:: sage: from sage.combinat.designs.twographs import (is_twograph, TwoGraph) - sage: p=graphs.PetersenGraph().twograph() - sage: is_twograph(p) + sage: p = graphs.PetersenGraph().twograph() # optional - sage.modules + sage: is_twograph(p) # optional - sage.modules True a non-regular 2-uniform hypergraph which is a two-graph:: - sage: is_twograph(TwoGraph([[1,2,3],[1,2,4]])) + sage: is_twograph(TwoGraph([[1,2,3],[1,2,4]])) # optional - sage.modules True TESTS: @@ -277,15 +277,15 @@ def twograph_descendant(G, v, name=None): one of s.r.g.'s from the :mod:`database `:: sage: from sage.combinat.designs.twographs import twograph_descendant - sage: A=graphs.strongly_regular_graph(280,135,70) # optional - gap_packages internet - sage: twograph_descendant(A, 0).is_strongly_regular(parameters=True) # optional - gap_packages internet + sage: A = graphs.strongly_regular_graph(280,135,70) # optional - gap_packages internet + sage: twograph_descendant(A, 0).is_strongly_regular(parameters=True) # optional - gap_packages internet (279, 150, 85, 75) TESTS:: sage: T8 = graphs.CompleteGraph(8).line_graph() sage: v = T8.vertices(sort=True)[0] - sage: twograph_descendant(T8, v)==T8.twograph().descendant(v) + sage: twograph_descendant(T8, v) == T8.twograph().descendant(v) # optional - sage.modules True sage: twograph_descendant(T8, v).is_strongly_regular(parameters=True) (27, 16, 10, 8) diff --git a/src/sage/combinat/diagram.py b/src/sage/combinat/diagram.py index dcde71bff63..e51b7b0f871 100644 --- a/src/sage/combinat/diagram.py +++ b/src/sage/combinat/diagram.py @@ -777,17 +777,17 @@ def from_zero_one_matrix(self, M, check=True): EXAMPLES:: - sage: M = matrix([[1,0,1,1],[0,1,1,0]]) + sage: M = matrix([[1,0,1,1],[0,1,1,0]]) # optional - sage.modules sage: from sage.combinat.diagram import Diagrams - sage: Diagrams()(M).pp() + sage: Diagrams()(M).pp() # optional - sage.modules O . O O . O O . - sage: Diagrams().from_zero_one_matrix(M).pp() + sage: Diagrams().from_zero_one_matrix(M).pp() # optional - sage.modules O . O O . O O . - sage: M = matrix([[1, 0, 0], [1, 0, 0], [0, 0, 0]]) - sage: Diagrams()(M).pp() + sage: M = matrix([[1, 0, 0], [1, 0, 0], [0, 0, 0]]) # optional - sage.modules + sage: Diagrams()(M).pp() # optional - sage.modules O . . O . . . . . @@ -1435,7 +1435,7 @@ def from_parallelogram_polyomino(self, p): EXAMPLES:: - sage: p = ParallelogramPolyomino([[0, 0, 1, 0, 0, 0, 1, 1], + sage: p = ParallelogramPolyomino([[0, 0, 1, 0, 0, 0, 1, 1], # optional - sage.modules ....: [1, 1, 0, 1, 0, 0, 0, 0]]) sage: from sage.combinat.diagram import NorthwestDiagrams sage: NorthwestDiagrams().from_parallelogram_polyomino(p).pp() diff --git a/src/sage/combinat/dlx.py b/src/sage/combinat/dlx.py index 6a6d0d15c11..d243abbc9c2 100644 --- a/src/sage/combinat/dlx.py +++ b/src/sage/combinat/dlx.py @@ -474,11 +474,11 @@ def AllExactCovers(M): EXAMPLES:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) #no exact covers - sage: for cover in AllExactCovers(M): + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers # optional - sage.modules + sage: for cover in AllExactCovers(M): # optional - sage.modules ....: print(cover) - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) #two exact covers - sage: for cover in AllExactCovers(M): + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers # optional - sage.modules + sage: for cover in AllExactCovers(M): # optional - sage.modules ....: print(cover) [(1, 1, 0), (0, 0, 1)] [(1, 0, 1), (0, 1, 0)] @@ -503,11 +503,11 @@ def OneExactCover(M): EXAMPLES:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers - sage: OneExactCover(M) + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers # optional - sage.modules + sage: OneExactCover(M) # optional - sage.modules - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers - sage: OneExactCover(M) + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers # optional - sage.modules + sage: OneExactCover(M) # optional - sage.modules [(1, 1, 0), (0, 0, 1)] """ for s in AllExactCovers(M): diff --git a/src/sage/combinat/e_one_star.py b/src/sage/combinat/e_one_star.py index 9bf37df14a6..a688cc04c4a 100644 --- a/src/sage/combinat/e_one_star.py +++ b/src/sage/combinat/e_one_star.py @@ -159,9 +159,9 @@ sage: P = Patch([Face([0,0], 1), Face([0,0], 2)]) sage: E = E1Star(WordMorphism({1:[1,2],2:[1]})) sage: F = E1Star(WordMorphism({1:[1,1,2],2:[2,1]})) - sage: E(P,5).plot() + sage: E(P,5).plot() # optional - sage.plot Graphics object consisting of 21 graphics primitives - sage: F(P,3).plot() + sage: F(P,3).plot() # optional - sage.plot Graphics object consisting of 34 graphics primitives Everything works in any dimension (except for the plotting features @@ -490,12 +490,12 @@ def _plot(self, projmat, face_contour, opacity) -> Graphics: sage: face_contour[1] = map(vector, [(0,0,0),(0,1,0),(0,1,1),(0,0,1)]) sage: face_contour[2] = map(vector, [(0,0,0),(0,0,1),(1,0,1),(1,0,0)]) sage: face_contour[3] = map(vector, [(0,0,0),(1,0,0),(1,1,0),(0,1,0)]) - sage: G = f._plot(projmat, face_contour, 0.75) + sage: G = f._plot(projmat, face_contour, 0.75) # optional - sage.plot :: sage: f = Face((0,0), 2) - sage: f._plot(None, None, 1) + sage: f._plot(None, None, 1) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ v = self.vector() @@ -1102,7 +1102,7 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: from sage.combinat.e_one_star import E1Star, Face, Patch sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) - sage: P.plot() + sage: P.plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives :: @@ -1111,7 +1111,7 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: E = E1Star(sigma) sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) sage: P = E(P, 5) - sage: P.plot() + sage: P.plot() # optional - sage.plot Graphics object consisting of 57 graphics primitives Plot with a different projection matrix:: @@ -1121,7 +1121,7 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) sage: M = matrix(2, 3, [1,0,-1,0.3,1,-3]) sage: P = E(P, 3) - sage: P.plot(projmat=M) + sage: P.plot(projmat=M) # optional - sage.plot Graphics object consisting of 17 graphics primitives Plot patches made of unit segments:: @@ -1129,9 +1129,9 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: P = Patch([Face([0,0], 1), Face([0,0], 2)]) sage: E = E1Star(WordMorphism({1:[1,2],2:[1]})) sage: F = E1Star(WordMorphism({1:[1,1,2],2:[2,1]})) - sage: E(P,5).plot() + sage: E(P,5).plot() # optional - sage.plot Graphics object consisting of 21 graphics primitives - sage: F(P,3).plot() + sage: F(P,3).plot() # optional - sage.plot Graphics object consisting of 34 graphics primitives """ if self.dimension() == 2: diff --git a/src/sage/combinat/integer_vectors_mod_permgroup.py b/src/sage/combinat/integer_vectors_mod_permgroup.py index 539fc59b9c0..490e809694c 100644 --- a/src/sage/combinat/integer_vectors_mod_permgroup.py +++ b/src/sage/combinat/integer_vectors_mod_permgroup.py @@ -1,3 +1,4 @@ +# optional - sage.combinat sage.groups r""" Integer vectors modulo the action of a permutation group """ diff --git a/src/sage/combinat/interval_posets.py b/src/sage/combinat/interval_posets.py index 346cd954e21..989548ba328 100644 --- a/src/sage/combinat/interval_posets.py +++ b/src/sage/combinat/interval_posets.py @@ -611,11 +611,11 @@ def factor(self) -> list[TamariIntervalPoset]: TESTS:: - sage: T = TamariIntervalPosets(20).random_element() - sage: facs = factor(T) - sage: all(U.is_connected() for U in facs) + sage: T = TamariIntervalPosets(20).random_element() # optional - sage.combinat + sage: facs = factor(T) # optional - sage.combinat + sage: all(U.is_connected() for U in facs) # optional - sage.combinat True - sage: T == prod(facs) + sage: T == prod(facs) # optional - sage.combinat True """ hasse = self.poset().hasse_diagram() @@ -1030,10 +1030,10 @@ def cubical_coordinates(self) -> tuple[int, ...]: sage: ip = TamariIntervalPoset(3,[]) sage: ip.cubical_coordinates() (0, 0) - sage: ip = TamariIntervalPosets(10).random_element() - sage: len(ip.cubical_coordinates()) + sage: ip = TamariIntervalPosets(10).random_element() # optional - sage.combinat + sage: len(ip.cubical_coordinates()) # optional - sage.combinat 9 - sage: sorted(ip.cubical_coordinates() for ip in TamariIntervalPosets(2)) + sage: sorted(ip.cubical_coordinates() for ip in TamariIntervalPosets(2)) # optional - sage.combinat [(-1,), (0,), (1,)] REFERENCES: @@ -1136,7 +1136,8 @@ def rise_contact_involution(self) -> TIP: (4, 3), (3, 2), (2, 1)] sage: t.rise_contact_involution() == tip True - sage: tip.lower_dyck_word().number_of_touch_points() == t.upper_dyck_word().number_of_initial_rises() + sage: (tip.lower_dyck_word().number_of_touch_points() # optional - sage.combinat + ....: == t.upper_dyck_word().number_of_initial_rises()) True sage: tip.number_of_tamari_inversions() == t.number_of_tamari_inversions() True @@ -1232,7 +1233,7 @@ def insertion(self, i) -> TIP: ....: print(T, i) ....: return False ....: return True - sage: test_equivalence(3) + sage: test_equivalence(3) # optional - sage.combinat True sage: ti = TamariIntervalPosets(3).an_element() @@ -1674,17 +1675,17 @@ def contains_dyck_word(self, dyck_word) -> bool: EXAMPLES:: sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]) - sage: ip.contains_dyck_word(DyckWord([1,1,1,0,0,0,1,0])) + sage: ip.contains_dyck_word(DyckWord([1,1,1,0,0,0,1,0])) # optional - sage.combinat True - sage: ip.contains_dyck_word(DyckWord([1,1,0,1,0,1,0,0])) + sage: ip.contains_dyck_word(DyckWord([1,1,0,1,0,1,0,0])) # optional - sage.combinat True - sage: ip.contains_dyck_word(DyckWord([1,0,1,1,0,1,0,0])) + sage: ip.contains_dyck_word(DyckWord([1,0,1,1,0,1,0,0])) # optional - sage.combinat False - sage: ip.contains_dyck_word(ip.lower_dyck_word()) + sage: ip.contains_dyck_word(ip.lower_dyck_word()) # optional - sage.combinat True - sage: ip.contains_dyck_word(ip.upper_dyck_word()) + sage: ip.contains_dyck_word(ip.upper_dyck_word()) # optional - sage.combinat True - sage: all(ip.contains_dyck_word(bt) for bt in ip.dyck_words()) + sage: all(ip.contains_dyck_word(bt) for bt in ip.dyck_words()) # optional - sage.combinat True """ return self.contains_binary_tree(dyck_word.to_binary_tree_tamari()) @@ -1779,14 +1780,16 @@ def is_initial_interval(self) -> bool: sage: ip = TamariIntervalPoset(4, [(1, 2), (2, 4), (3, 4)]) sage: ip.is_initial_interval() True - sage: ip.lower_dyck_word() + sage: ip.lower_dyck_word() # optional - sage.combinat [1, 0, 1, 0, 1, 0, 1, 0] sage: ip = TamariIntervalPoset(4, [(1, 2), (2, 4), (3, 4), (3, 2)]) sage: ip.is_initial_interval() False - sage: ip.lower_dyck_word() + sage: ip.lower_dyck_word() # optional - sage.combinat [1, 0, 1, 1, 0, 0, 1, 0] - sage: all(DyckWord([1,0,1,0,1,0]).tamari_interval(dw).is_initial_interval() for dw in DyckWords(3)) + sage: all(DyckWord([1,0,1,0,1,0]).tamari_interval(dw) # optional - sage.combinat + ....: .is_initial_interval() + ....: for dw in DyckWords(3)) True """ return not self.decreasing_cover_relations() @@ -1807,14 +1810,16 @@ def is_final_interval(self) -> bool: sage: ip = TamariIntervalPoset(4, [(4, 3), (3, 1), (2, 1)]) sage: ip.is_final_interval() True - sage: ip.upper_dyck_word() + sage: ip.upper_dyck_word() # optional - sage.combinat [1, 1, 1, 1, 0, 0, 0, 0] sage: ip = TamariIntervalPoset(4, [(4, 3), (3, 1), (2, 1), (2, 3)]) sage: ip.is_final_interval() False - sage: ip.upper_dyck_word() + sage: ip.upper_dyck_word() # optional - sage.combinat [1, 1, 0, 1, 1, 0, 0, 0] - sage: all(dw.tamari_interval(DyckWord([1, 1, 1, 0, 0, 0])).is_final_interval() for dw in DyckWords(3)) + sage: all(dw.tamari_interval(DyckWord([1, 1, 1, 0, 0, 0])) # optional - sage.combinat + ....: .is_final_interval() + ....: for dw in DyckWords(3)) True """ return not self.increasing_cover_relations() @@ -1854,13 +1859,16 @@ def lower_dyck_word(self): EXAMPLES:: - sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(4,5)]); ip - The Tamari interval of size 6 induced by relations [(1, 2), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] - sage: ip.lower_dyck_word() + sage: ip = TamariIntervalPoset(6, [(3,2),(4,3),(5,2),(6,5),(1,2),(4,5)]); ip + The Tamari interval of size 6 induced by relations + [(1, 2), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] + sage: ip.lower_dyck_word() # optional - sage.combinat [1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0] - sage: TamariIntervalPosets.final_forest(ip.lower_dyck_word()) == ip.final_forest() + sage: ldw_ff = TamariIntervalPosets.final_forest(ip.lower_dyck_word()) # optional - sage.combinat + sage: ldw_ff == ip.final_forest() # optional - sage.combinat True - sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(),ip.upper_dyck_word()) + sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(), # optional - sage.combinat + ....: ip.upper_dyck_word()) True """ return self.lower_binary_tree().to_dyck_word_tamari() @@ -1901,12 +1909,15 @@ def upper_dyck_word(self): EXAMPLES:: sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(4,5)]); ip - The Tamari interval of size 6 induced by relations [(1, 2), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] - sage: ip.upper_dyck_word() + The Tamari interval of size 6 induced by relations + [(1, 2), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] + sage: ip.upper_dyck_word() # optional - sage.combinat [1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0] - sage: TamariIntervalPosets.initial_forest(ip.upper_dyck_word()) == ip.initial_forest() + sage: udw_if = TamariIntervalPosets.initial_forest(ip.upper_dyck_word()) # optional - sage.combinat + sage: udw_if == ip.initial_forest() # optional - sage.combinat True - sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(),ip.upper_dyck_word()) + sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(), # optional - sage.combinat + ....: ip.upper_dyck_word()) True """ return self.upper_binary_tree().to_dyck_word_tamari() @@ -2074,11 +2085,11 @@ def linear_extensions(self) -> Iterator[Permutation]: EXAMPLES:: - sage: ip = TamariIntervalPoset(3,[(1,2),(3,2)]) - sage: list(ip.linear_extensions()) + sage: ip = TamariIntervalPoset(3, [(1,2),(3,2)]) + sage: list(ip.linear_extensions()) # optional - sage.rings.finite_rings sage.modules [[3, 1, 2], [1, 3, 2]] - sage: ip = TamariIntervalPoset(4,[(1,2),(2,3),(4,3)]) - sage: list(ip.linear_extensions()) + sage: ip = TamariIntervalPoset(4, [(1,2),(2,3),(4,3)]) + sage: list(ip.linear_extensions()) # optional - sage.rings.finite_rings sage.modules [[4, 1, 2, 3], [1, 2, 4, 3], [1, 4, 2, 3]] """ for ext in self._poset.linear_extensions(): @@ -2220,12 +2231,12 @@ def dyck_words(self) -> Iterator: EXAMPLES:: - sage: list(TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]).dyck_words()) + sage: list(TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]).dyck_words()) # optional - sage.combinat [[1, 1, 1, 0, 0, 1, 0, 0], [1, 1, 1, 0, 0, 0, 1, 0], [1, 1, 0, 1, 0, 1, 0, 0], [1, 1, 0, 1, 0, 0, 1, 0]] - sage: set(TamariIntervalPoset(4,[]).dyck_words()) == set(DyckWords(4)) + sage: set(TamariIntervalPoset(4,[]).dyck_words()) == set(DyckWords(4)) # optional - sage.combinat True """ for ip in self.lower_contained_intervals(): @@ -2302,10 +2313,10 @@ def maximal_chain_dyck_words(self) -> Iterator: EXAMPLES:: sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]) - sage: list(ip.maximal_chain_dyck_words()) + sage: list(ip.maximal_chain_dyck_words()) # optional - sage.combinat [[1, 1, 0, 1, 0, 0, 1, 0], [1, 1, 0, 1, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 0, 0]] sage: ip = TamariIntervalPoset(4,[]) - sage: list(ip.maximal_chain_dyck_words()) + sage: list(ip.maximal_chain_dyck_words()) # optional - sage.combinat [[1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 1, 0, 0, 1, 0], @@ -2371,9 +2382,13 @@ def tamari_inversions(self) -> list[tuple[int, int]]: sage: ip = TamariIntervalPoset(4,[]) sage: ip.tamari_inversions() [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] - sage: all(len(TamariIntervalPosets.from_binary_trees(bt,bt).tamari_inversions())==0 for bt in BinaryTrees(3)) + sage: all(not TamariIntervalPosets.from_binary_trees(bt,bt) # optional - sage.combinat + ....: .tamari_inversions() + ....: for bt in BinaryTrees(3)) True - sage: all(len(TamariIntervalPosets.from_binary_trees(bt,bt).tamari_inversions())==0 for bt in BinaryTrees(4)) + sage: all(not TamariIntervalPosets.from_binary_trees(bt,bt) # optional - sage.combinat + ....: .tamari_inversions() + ....: for bt in BinaryTrees(4)) True """ return list(self.tamari_inversions_iter()) @@ -2494,18 +2509,18 @@ def new_decomposition(self) -> list[TIP]: sage: ex = TamariIntervalPosets(4)[11] sage: ex.number_of_new_components() 3 - sage: ex.new_decomposition() + sage: ex.new_decomposition() # optional - sage.combinat [The Tamari interval of size 1 induced by relations [], The Tamari interval of size 2 induced by relations [], The Tamari interval of size 1 induced by relations []] TESTS:: - sage: ex = TamariIntervalPosets(4).random_element() - sage: dec = ex.new_decomposition() - sage: len(dec) == ex.number_of_new_components() + sage: ex = TamariIntervalPosets(4).random_element() # optional - sage.combinat + sage: dec = ex.new_decomposition() # optional - sage.combinat + sage: len(dec) == ex.number_of_new_components() # optional - sage.combinat True - sage: all(u.is_new() for u in dec) + sage: all(u.is_new() for u in dec) # optional - sage.combinat True """ from sage.combinat.binary_tree import BinaryTree @@ -3026,11 +3041,11 @@ def final_forest(element) -> TIP: From Dyck words:: - sage: dw = DyckWord([1,0]) - sage: TamariIntervalPosets.final_forest(dw) + sage: dw = DyckWord([1,0]) # optional - sage.combinat + sage: TamariIntervalPosets.final_forest(dw) # optional - sage.combinat The Tamari interval of size 1 induced by relations [] - sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) - sage: TamariIntervalPosets.final_forest(dw) + sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) # optional - sage.combinat + sage: TamariIntervalPosets.final_forest(dw) # optional - sage.combinat The Tamari interval of size 5 induced by relations [(5, 4), (3, 1), (2, 1)] TESTS:: @@ -3133,11 +3148,11 @@ def initial_forest(element) -> TIP: from Dyck words:: - sage: dw = DyckWord([1,0]) - sage: TamariIntervalPosets.initial_forest(dw) + sage: dw = DyckWord([1,0]) # optional - sage.combinat + sage: TamariIntervalPosets.initial_forest(dw) # optional - sage.combinat The Tamari interval of size 1 induced by relations [] - sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) - sage: TamariIntervalPosets.initial_forest(dw) + sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) # optional - sage.combinat + sage: TamariIntervalPosets.initial_forest(dw) # optional - sage.combinat The Tamari interval of size 5 induced by relations [(1, 4), (2, 3), (3, 4)] TESTS:: @@ -3252,26 +3267,27 @@ def from_dyck_words(dw1, dw2) -> TIP: EXAMPLES:: - sage: dw1 = DyckWord([1,0,1,0]) - sage: dw2 = DyckWord([1,1,0,0]) - sage: TamariIntervalPosets.from_dyck_words(dw1,dw2) + sage: dw1 = DyckWord([1,0,1,0]) # optional - sage.combinat + sage: dw2 = DyckWord([1,1,0,0]) # optional - sage.combinat + sage: TamariIntervalPosets.from_dyck_words(dw1, dw2) # optional - sage.combinat The Tamari interval of size 2 induced by relations [] - sage: TamariIntervalPosets.from_dyck_words(dw1,dw1) + sage: TamariIntervalPosets.from_dyck_words(dw1,dw1) # optional - sage.combinat The Tamari interval of size 2 induced by relations [(1, 2)] - sage: TamariIntervalPosets.from_dyck_words(dw2,dw2) + sage: TamariIntervalPosets.from_dyck_words(dw2,dw2) # optional - sage.combinat The Tamari interval of size 2 induced by relations [(2, 1)] - sage: dw1 = DyckWord([1,0,1,1,1,0,0,1,1,0,0,0]) - sage: dw2 = DyckWord([1,1,1,1,0,1,1,0,0,0,0,0]) - sage: TamariIntervalPosets.from_dyck_words(dw1,dw2) - The Tamari interval of size 6 induced by relations [(4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] + sage: dw1 = DyckWord([1,0,1,1,1,0,0,1,1,0,0,0]) # optional - sage.combinat + sage: dw2 = DyckWord([1,1,1,1,0,1,1,0,0,0,0,0]) # optional - sage.combinat + sage: TamariIntervalPosets.from_dyck_words(dw1,dw2) # optional - sage.combinat + The Tamari interval of size 6 induced by relations + [(4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] - sage: dw3 = DyckWord([1,1,1,0,1,1,1,0,0,0,0,0]) - sage: TamariIntervalPosets.from_dyck_words(dw1,dw3) + sage: dw3 = DyckWord([1,1,1,0,1,1,1,0,0,0,0,0]) # optional - sage.combinat + sage: TamariIntervalPosets.from_dyck_words(dw1,dw3) # optional - sage.combinat Traceback (most recent call last): ... ValueError: the two Dyck words are not comparable on the Tamari lattice - sage: TamariIntervalPosets.from_dyck_words(dw1,DyckWord([1,0])) + sage: TamariIntervalPosets.from_dyck_words(dw1,DyckWord([1,0])) # optional - sage.combinat Traceback (most recent call last): ... ValueError: the two Dyck words are not comparable on the Tamari lattice @@ -3380,7 +3396,7 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: TIP = TamariIntervalPosets sage: G = DiGraph([(0,-1,0),(0,-2,1),(0,-3,2)], format='list_of_edges') sage: G.set_embedding({-1:[0],-2:[0],-3:[0],0:[-1,-2,-3]}) - sage: TIP.from_minimal_schnyder_wood(G) + sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat The Tamari interval of size 1 induced by relations [] An example from page 14 of [BeBo2009]_:: @@ -3398,8 +3414,9 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: for k in range(6): ....: embed[k] = data_emb[k] sage: G.set_embedding(embed) - sage: TIP.from_minimal_schnyder_wood(G) - The Tamari interval of size 6 induced by relations [(1, 4), (2, 4), (3, 4), (5, 6), (6, 4), (5, 4), (3, 1), (2, 1)] + sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat + The Tamari interval of size 6 induced by relations + [(1, 4), (2, 4), (3, 4), (5, 6), (6, 4), (5, 4), (3, 1), (2, 1)] An example from page 18 of [BeBo2009]_:: @@ -3416,8 +3433,9 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: for k in range(6): ....: embed[k] = data_emb[k] sage: G.set_embedding(embed) - sage: TIP.from_minimal_schnyder_wood(G) - The Tamari interval of size 6 induced by relations [(1, 3), (2, 3), (4, 5), (5, 3), (4, 3), (2, 1)] + sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat + The Tamari interval of size 6 induced by relations + [(1, 3), (2, 3), (4, 5), (5, 3), (4, 3), (2, 1)] Another small example:: @@ -3433,7 +3451,7 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: for k in range(3): ....: embed[k] = data_emb[k] sage: G.set_embedding(embed) - sage: TIP.from_minimal_schnyder_wood(G) + sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat The Tamari interval of size 3 induced by relations [(2, 3), (2, 1)] """ from sage.combinat.dyck_word import DyckWord @@ -3797,14 +3815,14 @@ def random_element(self) -> TIP: EXAMPLES:: - sage: T = TamariIntervalPosets(4).random_element() - sage: T.parent() + sage: T = TamariIntervalPosets(4).random_element() # optional - sage.combinat + sage: T.parent() # optional - sage.combinat Interval-posets - sage: u = T.lower_dyck_word(); u # random + sage: u = T.lower_dyck_word(); u # random # optional - sage.combinat [1, 1, 0, 1, 0, 0, 1, 0] - sage: v = T.lower_dyck_word(); v # random + sage: v = T.lower_dyck_word(); v # random # optional - sage.combinat [1, 1, 0, 1, 0, 0, 1, 0] - sage: len(u) + sage: len(u) # optional - sage.combinat 8 """ from sage.graphs.schnyder import minimal_schnyder_wood diff --git a/src/sage/combinat/matrices/dlxcpp.py b/src/sage/combinat/matrices/dlxcpp.py index 4e12b98e325..e235f885188 100644 --- a/src/sage/combinat/matrices/dlxcpp.py +++ b/src/sage/combinat/matrices/dlxcpp.py @@ -92,14 +92,14 @@ def AllExactCovers(M): EXAMPLES: No exact covers:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) - sage: [cover for cover in AllExactCovers(M)] + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # optional - sage.modules + sage: [cover for cover in AllExactCovers(M)] # optional - sage.modules [] Two exact covers:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) - sage: [cover for cover in AllExactCovers(M)] + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # optional - sage.modules + sage: [cover for cover in AllExactCovers(M)] # optional - sage.modules [[(1, 1, 0), (0, 0, 1)], [(1, 0, 1), (0, 1, 0)]] """ rows = [] @@ -119,11 +119,11 @@ def OneExactCover(M): EXAMPLES:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) #no exact covers - sage: print(OneExactCover(M)) + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers # optional - sage.modules + sage: print(OneExactCover(M)) # optional - sage.modules None - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) #two exact covers - sage: OneExactCover(M) + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers # optional - sage.modules + sage: OneExactCover(M) # optional - sage.modules [(1, 1, 0), (0, 0, 1)] """ diff --git a/src/sage/combinat/multiset_partition_into_sets_ordered.py b/src/sage/combinat/multiset_partition_into_sets_ordered.py index 462b52cd447..7775f33ad93 100755 --- a/src/sage/combinat/multiset_partition_into_sets_ordered.py +++ b/src/sage/combinat/multiset_partition_into_sets_ordered.py @@ -45,7 +45,7 @@ Crystal of ordered multiset partitions into sets on the alphabet `\{1,2,3\}` with 4 letters divided into 2 blocks:: - sage: crystals.Minimaj(3, 4, 2).list() + sage: crystals.Minimaj(3, 4, 2).list() # optional - sage.modules [((2, 3, 1), (1,)), ((2, 3), (1, 2)), ((2, 3), (1, 3)), ((2, 1), (1, 2)), ((3, 1), (1, 2)), ((3, 1, 2), (2,)), ((3, 1), (1, 3)), ((3, 1), (2, 3)), ((3, 2), (2, 3)), ((2, 1), (1, 3)), ((2,), (1, 2, 3)), ((3,), (1, 2, 3)), @@ -3200,14 +3200,14 @@ class MinimajCrystal(UniqueRepresentation, Parent): EXAMPLES:: - sage: list(crystals.Minimaj(2,3,2)) + sage: list(crystals.Minimaj(2,3,2)) # optional - sage.modules [((2, 1), (1,)), ((2,), (1, 2)), ((1,), (1, 2)), ((1, 2), (2,))] - sage: b = crystals.Minimaj(3, 5, 2).an_element(); b + sage: b = crystals.Minimaj(3, 5, 2).an_element(); b # optional - sage.modules ((2, 3, 1), (1, 2)) - sage: b.f(2) + sage: b.f(2) # optional - sage.modules ((2, 3, 1), (1, 3)) - sage: b.e(2) + sage: b.e(2) # optional - sage.modules """ def __init__(self, n, ell, k): @@ -3216,17 +3216,17 @@ def __init__(self, n, ell, k): TESTS:: - sage: B = crystals.Minimaj(2,3,2) - sage: TestSuite(B).run() + sage: B = crystals.Minimaj(2,3,2) # optional - sage.modules + sage: TestSuite(B).run() # optional - sage.modules - sage: B = crystals.Minimaj(3, 5, 2) - sage: TestSuite(B).run() + sage: B = crystals.Minimaj(3, 5, 2) # optional - sage.modules + sage: TestSuite(B).run() # optional - sage.modules - sage: list(crystals.Minimaj(2,6,3)) + sage: list(crystals.Minimaj(2,6,3)) # optional - sage.modules [((1, 2), (2, 1), (1, 2))] - sage: list(crystals.Minimaj(2,5,2)) # blocks too fat for alphabet + sage: list(crystals.Minimaj(2,5,2)) # blocks too fat for alphabet # optional - sage.modules [] - sage: list(crystals.Minimaj(4,2,3)) # more blocks than letters + sage: list(crystals.Minimaj(4,2,3)) # more blocks than letters # optional - sage.modules Traceback (most recent call last): ... ValueError: n (=4), ell (=2), and k (=3) must all be positive integers @@ -3259,7 +3259,7 @@ def _repr_(self): EXAMPLES:: - sage: B = crystals.Minimaj(3,4,2); B + sage: B = crystals.Minimaj(3,4,2); B # optional - sage.modules Minimaj Crystal of type A_2 of words of length 4 into 2 blocks """ return ("Minimaj Crystal of type A_%s of words of length %s into %s blocks" @@ -3271,14 +3271,14 @@ def _an_element_(self): EXAMPLES:: - sage: B = crystals.Minimaj(4,5,3) - sage: B.an_element() + sage: B = crystals.Minimaj(4,5,3) # optional - sage.modules + sage: B.an_element() # optional - sage.modules ((2, 3, 1), (1,), (1,)) - sage: B = crystals.Minimaj(2,2,1) - sage: B.an_element() + sage: B = crystals.Minimaj(2,2,1) # optional - sage.modules + sage: B.an_element() # optional - sage.modules ((1, 2),) - sage: B = crystals.Minimaj(1,2,1) - sage: B.an_element() + sage: B = crystals.Minimaj(1,2,1) # optional - sage.modules + sage: B.an_element() # optional - sage.modules Traceback (most recent call last): ... EmptySetError @@ -3294,14 +3294,14 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: B1 = crystals.Minimaj(4,5,3); b = B1.an_element(); b + sage: B1 = crystals.Minimaj(4,5,3); b = B1.an_element(); b # optional - sage.modules ((2, 3, 1), (1,), (1,)) - sage: B1._element_constructor_(list(b)) + sage: B1._element_constructor_(list(b)) # optional - sage.modules ((2, 3, 1), (1,), (1,)) - sage: B1._element_constructor_([[1,2,3], [2], [2]]) + sage: B1._element_constructor_([[1,2,3], [2], [2]]) # optional - sage.modules ((3, 1, 2), (2,), (2,)) - sage: B2 = crystals.Minimaj(5,5,3) - sage: B2._element_constructor_(b) + sage: B2 = crystals.Minimaj(5,5,3) # optional - sage.modules + sage: B2._element_constructor_(b) # optional - sage.modules ((2, 3, 1), (1,), (1,)) """ # Allow ``x`` to be either of: @@ -3325,17 +3325,17 @@ def __contains__(self, x): EXAMPLES:: - sage: B1 = crystals.Minimaj(2,5,3); b1 = B1.an_element(); b1 + sage: B1 = crystals.Minimaj(2,5,3); b1 = B1.an_element(); b1 # optional - sage.modules ((1, 2), (2, 1), (1,)) - sage: B2 = crystals.Minimaj(5,5,3); b2 = B2.an_element(); b2 + sage: B2 = crystals.Minimaj(5,5,3); b2 = B2.an_element(); b2 # optional - sage.modules ((2, 3, 1), (1,), (1,)) - sage: b2a = B2(((1,2), (1,), (1,2))); b2a + sage: b2a = B2(((1,2), (1,), (1,2))); b2a # optional - sage.modules ((2, 1), (1,), (1, 2)) - sage: b1 in B2 + sage: b1 in B2 # optional - sage.modules True - sage: b2 in B1 + sage: b2 in B1 # optional - sage.modules False - sage: b2a in B1 + sage: b2a in B1 # optional - sage.modules True """ if isinstance(x, MinimajCrystal.Element): @@ -3356,24 +3356,24 @@ def from_tableau(self, t): EXAMPLES:: - sage: B = crystals.Minimaj(3,6,3) - sage: b = B.an_element(); b + sage: B = crystals.Minimaj(3,6,3) # optional - sage.modules + sage: b = B.an_element(); b # optional - sage.modules ((3, 1, 2), (2, 1), (1,)) - sage: t = b.to_tableaux_words(); t + sage: t = b.to_tableaux_words(); t # optional - sage.modules [[1], [2, 1], [], [3, 2, 1]] - sage: B.from_tableau(t) + sage: B.from_tableau(t) # optional - sage.modules ((3, 1, 2), (2, 1), (1,)) - sage: B.from_tableau(t) == b + sage: B.from_tableau(t) == b # optional - sage.modules True TESTS:: - sage: B = crystals.Minimaj(3,6,3) - sage: all(mu == B.from_tableau(mu.to_tableaux_words()) for mu in B) + sage: B = crystals.Minimaj(3,6,3) # optional - sage.modules + sage: all(mu == B.from_tableau(mu.to_tableaux_words()) for mu in B) # optional - sage.modules True - sage: t = B.an_element().to_tableaux_words() - sage: B1 = crystals.Minimaj(3,6,2) - sage: B1.from_tableau(t) + sage: t = B.an_element().to_tableaux_words() # optional - sage.modules + sage: B1 = crystals.Minimaj(3,6,2) # optional - sage.modules + sage: B1.from_tableau(t) # optional - sage.modules Traceback (most recent call last): ... ValueError: ((3, 1, 2), (2, 1), (1,)) is not an element of @@ -3393,8 +3393,8 @@ def val(self, q='q'): Verifying Example 4.5 from [BCHOPSY2017]_:: - sage: B = crystals.Minimaj(3, 4, 2) # for `Val_{4,1}^{(3)}` - sage: B.val() + sage: B = crystals.Minimaj(3, 4, 2) # for `Val_{4,1}^{(3)}` # optional - sage.modules + sage: B.val() # optional - sage.modules (q^2+q+1)*s[2, 1, 1] + q*s[2, 2] """ H = [self._OMPs(list(b)) for b in self.highest_weight_vectors()] @@ -3428,7 +3428,7 @@ def _repr_(self): EXAMPLES:: - sage: crystals.Minimaj(4,5,3).an_element() + sage: crystals.Minimaj(4,5,3).an_element() # optional - sage.modules ((2, 3, 1), (1,), (1,)) """ return repr(self._minimaj_blocks_from_word_pair()) @@ -3439,11 +3439,11 @@ def __iter__(self): EXAMPLES:: - sage: b = crystals.Minimaj(4,5,3).an_element(); b + sage: b = crystals.Minimaj(4,5,3).an_element(); b # optional - sage.modules ((2, 3, 1), (1,), (1,)) - sage: b.value + sage: b.value # optional - sage.modules ([1, 3, 2, 1, 1], (0, 1, 2, 5)) - sage: list(b) + sage: list(b) # optional - sage.modules [(2, 3, 1), (1,), (1,)] """ return self._minimaj_blocks_from_word_pair().__iter__() @@ -3454,9 +3454,9 @@ def _latex_(self): EXAMPLES:: - sage: b = crystals.Minimaj(4,5,3).an_element(); b + sage: b = crystals.Minimaj(4,5,3).an_element(); b # optional - sage.modules ((2, 3, 1), (1,), (1,)) - sage: latex(b) + sage: latex(b) # optional - sage.modules \left(\left(2, 3, 1\right), \left(1\right), \left(1\right)\right) """ return latex(self._minimaj_blocks_from_word_pair()) @@ -3468,10 +3468,10 @@ def _minimaj_blocks_from_word_pair(self): EXAMPLES:: - sage: B = crystals.Minimaj(4,5,3) - sage: b = B.an_element(); b.value + sage: B = crystals.Minimaj(4,5,3) # optional - sage.modules + sage: b = B.an_element(); b.value # optional - sage.modules ([1, 3, 2, 1, 1], (0, 1, 2, 5)) - sage: b._minimaj_blocks_from_word_pair() + sage: b._minimaj_blocks_from_word_pair() # optional - sage.modules ((2, 3, 1), (1,), (1,)) """ return _to_minimaj_blocks(self.to_tableaux_words()) @@ -3483,15 +3483,15 @@ def to_tableaux_words(self): EXAMPLES:: - sage: B = crystals.Minimaj(4,5,3) - sage: b = B.an_element(); b + sage: B = crystals.Minimaj(4,5,3) # optional - sage.modules + sage: b = B.an_element(); b # optional - sage.modules ((2, 3, 1), (1,), (1,)) - sage: b.to_tableaux_words() + sage: b.to_tableaux_words() # optional - sage.modules [[1], [3], [2, 1, 1]] - sage: b = B([[1,3,4], [3], [3]]); b + sage: b = B([[1,3,4], [3], [3]]); b # optional - sage.modules ((4, 1, 3), (3,), (3,)) - sage: b.to_tableaux_words() + sage: b.to_tableaux_words() # optional - sage.modules [[3, 1], [], [4, 3, 3]] """ w, breaks = self.value @@ -3504,10 +3504,10 @@ def e(self, i): EXAMPLES:: - sage: B = crystals.Minimaj(4,3,2) - sage: b = B([[2,3], [3]]); b + sage: B = crystals.Minimaj(4,3,2) # optional - sage.modules + sage: b = B([[2,3], [3]]); b # optional - sage.modules ((2, 3), (3,)) - sage: [b.e(i) for i in range(1,4)] + sage: [b.e(i) for i in range(1,4)] # optional - sage.modules [((1, 3), (3,)), ((2,), (2, 3)), None] """ P = self.parent() @@ -3523,10 +3523,10 @@ def f(self,i): EXAMPLES:: - sage: B = crystals.Minimaj(4,3,2) - sage: b = B([[2,3], [3]]); b + sage: B = crystals.Minimaj(4,3,2) # optional - sage.modules + sage: b = B([[2,3], [3]]); b # optional - sage.modules ((2, 3), (3,)) - sage: [b.f(i) for i in range(1,4)] + sage: [b.f(i) for i in range(1,4)] # optional - sage.modules [None, None, ((2, 3), (4,))] """ P = self.parent() diff --git a/src/sage/combinat/ordered_tree.py b/src/sage/combinat/ordered_tree.py index 6a8f1206ff7..8faea2f248b 100644 --- a/src/sage/combinat/ordered_tree.py +++ b/src/sage/combinat/ordered_tree.py @@ -360,19 +360,20 @@ def to_parallelogram_polyomino(self, bijection=None): EXAMPLES:: sage: T = OrderedTree([[[], [[], [[]]]], [], [[[],[]]], [], []]) - sage: T.to_parallelogram_polyomino( bijection='Boussicault-Socci' ) - [[0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0]] + sage: T.to_parallelogram_polyomino(bijection='Boussicault-Socci') # optional - sage.combinat + [[0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1], + [1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0]] sage: T = OrderedTree( [] ) - sage: T.to_parallelogram_polyomino() + sage: T.to_parallelogram_polyomino() # optional - sage.combinat [[1], [1]] sage: T = OrderedTree( [[]] ) - sage: T.to_parallelogram_polyomino() + sage: T.to_parallelogram_polyomino() # optional - sage.combinat [[0, 1], [1, 0]] sage: T = OrderedTree( [[],[]] ) - sage: T.to_parallelogram_polyomino() + sage: T.to_parallelogram_polyomino() # optional - sage.combinat [[0, 1, 1], [1, 1, 0]] sage: T = OrderedTree( [[[]]] ) - sage: T.to_parallelogram_polyomino() + sage: T.to_parallelogram_polyomino() # optional - sage.combinat [[0, 0, 1], [1, 0, 0]] """ if (bijection is None) or (bijection == 'Boussicault-Socci'): @@ -391,19 +392,19 @@ def _to_parallelogram_polyomino_Boussicault_Socci(self): sage: T = OrderedTree( ....: [[[], [[], [[]]]], [], [[[],[]]], [], []] ....: ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() + sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat [[0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0]] sage: T = OrderedTree( [] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() + sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat [[1], [1]] sage: T = OrderedTree( [[]] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() + sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat [[0, 1], [1, 0]] sage: T = OrderedTree( [[],[]] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() + sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat [[0, 1, 1], [1, 1, 0]] sage: T = OrderedTree( [[[]]] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() + sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat [[0, 0, 1], [1, 0, 0]] """ from sage.combinat.parallelogram_polyomino import ParallelogramPolyomino @@ -500,13 +501,13 @@ def to_dyck_word(self): EXAMPLES:: sage: T = OrderedTree([[],[]]) - sage: T.to_dyck_word() + sage: T.to_dyck_word() # optional - sage.combinat [1, 0, 1, 0] sage: T = OrderedTree([[],[[]]]) - sage: T.to_dyck_word() + sage: T.to_dyck_word() # optional - sage.combinat [1, 0, 1, 1, 0, 0] sage: T = OrderedTree([[], [[], []], [[], [[]]]]) - sage: T.to_dyck_word() + sage: T.to_dyck_word() # optional - sage.combinat [1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0] """ word = [] @@ -1087,18 +1088,19 @@ def random_element(self): EXAMPLES:: - sage: OrderedTrees(5).random_element() # random + sage: OrderedTrees(5).random_element() # random # optional - sage.combinat [[[], []], []] - sage: OrderedTrees(0).random_element() + sage: OrderedTrees(0).random_element() # optional - sage.combinat Traceback (most recent call last): ... EmptySetError: there are no ordered trees of size 0 - sage: OrderedTrees(1).random_element() + sage: OrderedTrees(1).random_element() # optional - sage.combinat [] TESTS:: - sage: all(OrderedTrees(10).random_element() in OrderedTrees(10) for i in range(20)) + sage: all(OrderedTrees(10).random_element() in OrderedTrees(10) # optional - sage.combinat + ....: for i in range(20)) True """ if self._size == 0: diff --git a/src/sage/combinat/partition.py b/src/sage/combinat/partition.py index 3470e41cc77..7ed1da6de1c 100644 --- a/src/sage/combinat/partition.py +++ b/src/sage/combinat/partition.py @@ -1088,15 +1088,14 @@ def power(self, k): Now let us compare this to the power map on `S_8`:: - sage: G = SymmetricGroup(8) - sage: g = G([(1,2,3,4,5),(6,7,8)]) - sage: g + sage: G = SymmetricGroup(8) # optional - sage.groups + sage: g = G([(1,2,3,4,5),(6,7,8)]); g # optional - sage.groups (1,2,3,4,5)(6,7,8) - sage: g^2 + sage: g^2 # optional - sage.groups (1,3,5,2,4)(6,8,7) - sage: g^3 + sage: g^3 # optional - sage.groups (1,4,2,5,3) - sage: g^4 + sage: g^4 # optional - sage.groups (1,5,4,3,2)(6,7,8) :: @@ -1215,10 +1214,10 @@ def sign(self): :: - sage: F = GF(11) - sage: a = F.multiplicative_generator();a + sage: F = GF(11) # optional - sage.rings.finite_rings + sage: a = F.multiplicative_generator();a # optional - sage.rings.finite_rings 2 - sage: plist = [int(a*F(x)) for x in range(1,11)]; plist + sage: plist = [int(a*F(x)) for x in range(1,11)]; plist # optional - sage.rings.finite_rings [2, 4, 6, 8, 10, 1, 3, 5, 7, 9] This corresponds to the permutation (1, 2, 4, 8, 5, 10, 9, 7, 3, 6) @@ -1227,8 +1226,8 @@ def sign(self): :: - sage: p = PermutationGroupElement('(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)') - sage: p.sign() + sage: p = PermutationGroupElement('(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)') # optional - sage.groups + sage: p.sign() # optional - sage.groups -1 sage: Partition([10]).sign() -1 @@ -1237,12 +1236,12 @@ def sign(self): Now replace `2` by `3`:: - sage: plist = [int(F(3*x)) for x in range(1,11)]; plist + sage: plist = [int(F(3*x)) for x in range(1,11)]; plist # optional - sage.rings.finite_rings [3, 6, 9, 1, 4, 7, 10, 2, 5, 8] sage: list(range(1, 11)) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - sage: p = PermutationGroupElement('(3,4,8,7,9)') - sage: p.sign() + sage: p = PermutationGroupElement('(3,4,8,7,9)') # optional - sage.groups + sage: p.sign() # optional - sage.groups 1 sage: kronecker_symbol(3,11) 1 @@ -1885,55 +1884,55 @@ def cell_poset(self, orientation="SE"): EXAMPLES:: sage: p = Partition([3,3,1]) - sage: Q = p.cell_poset(); Q + sage: Q = p.cell_poset(); Q # optional - sage.graphs Finite poset containing 7 elements - sage: sorted(Q) + sage: sorted(Q) # optional - sage.graphs [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] - sage: sorted(Q.maximal_elements()) + sage: sorted(Q.maximal_elements()) # optional - sage.graphs [(1, 2), (2, 0)] - sage: Q.minimal_elements() + sage: Q.minimal_elements() # optional - sage.graphs [(0, 0)] - sage: sorted(Q.upper_covers((1, 0))) + sage: sorted(Q.upper_covers((1, 0))) # optional - sage.graphs [(1, 1), (2, 0)] - sage: Q.upper_covers((1, 1)) + sage: Q.upper_covers((1, 1)) # optional - sage.graphs [(1, 2)] - sage: P = p.cell_poset(orientation="NW"); P + sage: P = p.cell_poset(orientation="NW"); P # optional - sage.graphs Finite poset containing 7 elements - sage: sorted(P) + sage: sorted(P) # optional - sage.graphs [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] - sage: sorted(P.minimal_elements()) + sage: sorted(P.minimal_elements()) # optional - sage.graphs [(1, 2), (2, 0)] - sage: P.maximal_elements() + sage: P.maximal_elements() # optional - sage.graphs [(0, 0)] - sage: P.upper_covers((2, 0)) + sage: P.upper_covers((2, 0)) # optional - sage.graphs [(1, 0)] - sage: sorted(P.upper_covers((1, 2))) + sage: sorted(P.upper_covers((1, 2))) # optional - sage.graphs [(0, 2), (1, 1)] - sage: sorted(P.upper_covers((1, 1))) + sage: sorted(P.upper_covers((1, 1))) # optional - sage.graphs [(0, 1), (1, 0)] - sage: sorted([len(P.upper_covers(v)) for v in P]) + sage: sorted([len(P.upper_covers(v)) for v in P]) # optional - sage.graphs [0, 1, 1, 1, 1, 2, 2] - sage: R = p.cell_poset(orientation="NE"); R + sage: R = p.cell_poset(orientation="NE"); R # optional - sage.graphs Finite poset containing 7 elements - sage: sorted(R) + sage: sorted(R) # optional - sage.graphs [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] - sage: R.maximal_elements() + sage: R.maximal_elements() # optional - sage.graphs [(0, 2)] - sage: R.minimal_elements() + sage: R.minimal_elements() # optional - sage.graphs [(2, 0)] - sage: sorted([len(R.upper_covers(v)) for v in R]) + sage: sorted([len(R.upper_covers(v)) for v in R]) # optional - sage.graphs [0, 1, 1, 1, 1, 2, 2] - sage: R.is_isomorphic(P) + sage: R.is_isomorphic(P) # optional - sage.graphs False - sage: R.is_isomorphic(P.dual()) + sage: R.is_isomorphic(P.dual()) # optional - sage.graphs False Linear extensions of ``p.cell_poset()`` are in 1-to-1 correspondence with standard Young tableaux of shape `p`:: - sage: all( len(p.cell_poset().linear_extensions()) + sage: all( len(p.cell_poset().linear_extensions()) # optional - sage.graphs ....: == len(p.standard_tableaux()) ....: for n in range(8) for p in Partitions(n) ) True @@ -1941,7 +1940,7 @@ def cell_poset(self, orientation="SE"): This is not the case for northeast orientation:: sage: q = Partition([3, 1]) - sage: q.cell_poset(orientation="NE").is_chain() + sage: q.cell_poset(orientation="NE").is_chain() # optional - sage.graphs True TESTS: @@ -1958,7 +1957,7 @@ def cell_poset(self, orientation="SE"): ....: and c[1] >= d[1]): ....: return False ....: return True - sage: all( check_NW(n) for n in range(8) ) + sage: all( check_NW(n) for n in range(8) ) # optional - sage.graphs True sage: def check_NE(n): @@ -1970,7 +1969,7 @@ def cell_poset(self, orientation="SE"): ....: and c[1] <= d[1]): ....: return False ....: return True - sage: all( check_NE(n) for n in range(8) ) + sage: all( check_NE(n) for n in range(8) ) # optional - sage.graphs True sage: def test_duality(n, ori1, ori2): @@ -1982,11 +1981,11 @@ def cell_poset(self, orientation="SE"): ....: if P.lt(c, d) != Q.lt(d, c): ....: return False ....: return True - sage: all( test_duality(n, "NW", "SE") for n in range(8) ) + sage: all( test_duality(n, "NW", "SE") for n in range(8) ) # optional - sage.graphs True - sage: all( test_duality(n, "NE", "SW") for n in range(8) ) + sage: all( test_duality(n, "NE", "SW") for n in range(8) ) # optional - sage.graphs True - sage: all( test_duality(n, "NE", "SE") for n in range(4) ) + sage: all( test_duality(n, "NE", "SE") for n in range(4) ) # optional - sage.graphs False """ from sage.combinat.posets.posets import Poset @@ -2853,7 +2852,7 @@ def young_subgroup(self): EXAMPLES:: - sage: Partition([4,2]).young_subgroup() + sage: Partition([4,2]).young_subgroup() # optional - sage.groups Permutation Group with generators [(), (5,6), (3,4), (2,3), (1,2)] """ gens=[] @@ -4623,12 +4622,12 @@ def from_kbounded_to_grassmannian(self, k): EXAMPLES:: sage: p = Partition([2,1,1]) - sage: p.from_kbounded_to_grassmannian(2) + sage: p.from_kbounded_to_grassmannian(2) # optional - sage.modules [-1 1 1] [-2 2 1] [-2 1 2] sage: p = Partition([]) - sage: p.from_kbounded_to_grassmannian(2) + sage: p.from_kbounded_to_grassmannian(2) # optional - sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -5069,15 +5068,15 @@ def jacobi_trudi(self): EXAMPLES:: sage: part = Partition([3,2,1]) - sage: jt = part.jacobi_trudi(); jt + sage: jt = part.jacobi_trudi(); jt # optional - sage.modules [h[3] h[1] 0] [h[4] h[2] h[]] [h[5] h[3] h[1]] - sage: s = SymmetricFunctions(QQ).schur() - sage: h = SymmetricFunctions(QQ).homogeneous() - sage: h( s(part) ) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.modules + sage: h = SymmetricFunctions(QQ).homogeneous() # optional - sage.modules + sage: h( s(part) ) # optional - sage.modules h[3, 2, 1] - h[3, 3] - h[4, 1, 1] + h[5, 1] - sage: jt.det() + sage: jt.det() # optional - sage.modules h[3, 2, 1] - h[3, 3] - h[4, 1, 1] + h[5, 1] """ return SkewPartition([ self, [] ]).jacobi_trudi() @@ -5108,11 +5107,11 @@ def character_polynomial(self): EXAMPLES:: - sage: Partition([1]).character_polynomial() + sage: Partition([1]).character_polynomial() # optional - sage.modules x - 1 - sage: Partition([1,1]).character_polynomial() + sage: Partition([1,1]).character_polynomial() # optional - sage.modules 1/2*x0^2 - 3/2*x0 - x1 + 1 - sage: Partition([2,1]).character_polynomial() + sage: Partition([2,1]).character_polynomial() # optional - sage.modules 1/3*x0^3 - 2*x0^2 + 8/3*x0 - x2 """ # Create the polynomial ring we will use @@ -5390,16 +5389,16 @@ def dual_equivalence_graph(self, directed=False, coloring=None): EXAMPLES:: sage: P = Partition([3,1,1]) - sage: G = P.dual_equivalence_graph() - sage: G.edges(sort=True) + sage: G = P.dual_equivalence_graph() # optional - sage.graphs + sage: G.edges(sort=True) # optional - sage.graphs [([[1, 2, 3], [4], [5]], [[1, 2, 4], [3], [5]], 3), ([[1, 2, 4], [3], [5]], [[1, 2, 5], [3], [4]], 4), ([[1, 2, 4], [3], [5]], [[1, 3, 4], [2], [5]], 2), ([[1, 2, 5], [3], [4]], [[1, 3, 5], [2], [4]], 2), ([[1, 3, 4], [2], [5]], [[1, 3, 5], [2], [4]], 4), ([[1, 3, 5], [2], [4]], [[1, 4, 5], [2], [3]], 3)] - sage: G = P.dual_equivalence_graph(directed=True) - sage: G.edges(sort=True) + sage: G = P.dual_equivalence_graph(directed=True) # optional - sage.graphs + sage: G.edges(sort=True) # optional - sage.graphs [([[1, 2, 4], [3], [5]], [[1, 2, 3], [4], [5]], 3), ([[1, 2, 5], [3], [4]], [[1, 2, 4], [3], [5]], 4), ([[1, 3, 4], [2], [5]], [[1, 2, 4], [3], [5]], 2), @@ -5409,19 +5408,20 @@ def dual_equivalence_graph(self, directed=False, coloring=None): TESTS:: - sage: G = Partition([1]).dual_equivalence_graph() - sage: G.vertices(sort=False) + sage: G = Partition([1]).dual_equivalence_graph() # optional - sage.graphs + sage: G.vertices(sort=False) # optional - sage.graphs [[[1]]] - sage: G = Partition([]).dual_equivalence_graph() - sage: G.vertices(sort=False) + sage: G = Partition([]).dual_equivalence_graph() # optional - sage.graphs + sage: G.vertices(sort=False) # optional - sage.graphs [[]] sage: P = Partition([3,1,1]) - sage: G = P.dual_equivalence_graph(coloring=lambda x: 'red') - sage: G2 = P.dual_equivalence_graph(coloring={2: 'black', 3: 'blue', 4: 'cyan', 5: 'grey'}) - sage: G is G2 + sage: G = P.dual_equivalence_graph(coloring=lambda x: 'red') # optional - sage.graphs + sage: G2 = P.dual_equivalence_graph(coloring={2: 'black', 3: 'blue', # optional - sage.graphs + ....: 4: 'cyan', 5: 'grey'}) + sage: G is G2 # optional - sage.graphs False - sage: G == G2 + sage: G == G2 # optional - sage.graphs True """ # We do some custom caching to not recreate the graph, but to make @@ -5490,11 +5490,10 @@ def specht_module(self, base_ring=None): EXAMPLES:: - sage: SM = Partition([2,2,1]).specht_module(QQ) - sage: SM + sage: SM = Partition([2,2,1]).specht_module(QQ); SM # optional - sage.modules Specht module of [(0, 0), (0, 1), (1, 0), (1, 1), (2, 0)] over Rational Field - sage: s = SymmetricFunctions(QQ).s() - sage: s(SM.frobenius_image()) + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: s(SM.frobenius_image()) # optional - sage.modules s[2, 2, 1] """ from sage.combinat.specht_module import SpechtModule @@ -5520,7 +5519,7 @@ def specht_module_dimension(self, base_ring=None): sage: Partition([2,2,1]).specht_module_dimension() 5 - sage: Partition([2,2,1]).specht_module_dimension(GF(2)) + sage: Partition([2,2,1]).specht_module_dimension(GF(2)) # optional - sage.rings.finite_rings 5 """ from sage.categories.fields import Fields @@ -5640,16 +5639,20 @@ class Partitions(UniqueRepresentation, Parent): The number of partitions of `n` into odd parts equals the number of partitions into distinct parts. Let's test that for `n` from 10 to 20:: - sage: test = lambda n: Partitions(n, max_slope=-1).cardinality() == Partitions(n, parts_in=[1,3..n]).cardinality() - sage: all(test(n) for n in [10..20]) + sage: def test(n): + ....: return (Partitions(n, max_slope=-1).cardinality() + ....: == Partitions(n, parts_in=[1,3..n]).cardinality()) + sage: all(test(n) for n in [10..20]) # optional - sage.libs.gap True The number of partitions of `n` into distinct parts that differ by at least 2 equals the number of partitions into parts that equal 1 or 4 modulo 5; this is one of the Rogers-Ramanujan identities:: - sage: test = lambda n: Partitions(n, max_slope=-2).cardinality() == Partitions(n, parts_in=([1,6..n] + [4,9..n])).cardinality() - sage: all(test(n) for n in [10..20]) + sage: def test(n): + ....: return (Partitions(n, max_slope=-2).cardinality() + ....: == Partitions(n, parts_in=([1,6..n] + [4,9..n])).cardinality()) + sage: all(test(n) for n in [10..20]) # optional - sage.libs.gap True Here are some more examples illustrating ``min_part``, ``max_part``, @@ -7113,7 +7116,7 @@ class Partitions_parts_in(Partitions): TESTS:: - sage: TestSuite( sage.combinat.partition.Partitions_parts_in(6, parts=[2,1]) ).run() + sage: TestSuite( sage.combinat.partition.Partitions_parts_in(6, parts=[2,1]) ).run() # optional - sage.libs.gap """ @staticmethod @@ -7137,7 +7140,7 @@ def __init__(self, n, parts): TESTS:: - sage: TestSuite(Partitions(5, parts_in=[1,2,3])).run() + sage: TestSuite(Partitions(5, parts_in=[1,2,3])).run() # optional - sage.libs.gap """ Partitions.__init__(self) self.n = n @@ -7172,12 +7175,13 @@ def cardinality(self): EXAMPLES:: - sage: Partitions(15, parts_in=[2,3,7]).cardinality() + sage: Partitions(15, parts_in=[2,3,7]).cardinality() # optional - sage.libs.gap 5 If you can use all parts 1 through `n`, we'd better get `p(n)`:: - sage: Partitions(20, parts_in=[1..20]).cardinality() == Partitions(20).cardinality() + sage: (Partitions(20, parts_in=[1..20]).cardinality() # optional - sage.libs.gap + ....: == Partitions(20).cardinality()) True TESTS: @@ -7186,19 +7190,19 @@ def cardinality(self): algorithm that actually generates the partitions:: sage: ps = Partitions(15, parts_in=[1,2,3]) - sage: ps.cardinality() == len(ps.list()) + sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap True sage: ps = Partitions(15, parts_in=[]) - sage: ps.cardinality() == len(ps.list()) + sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap True sage: ps = Partitions(3000, parts_in=[50,100,500,1000]) - sage: ps.cardinality() == len(ps.list()) + sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap True sage: ps = Partitions(10, parts_in=[3,6,9]) - sage: ps.cardinality() == len(ps.list()) + sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap True sage: ps = Partitions(0, parts_in=[1,2]) - sage: ps.cardinality() == len(ps.list()) + sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap True """ # GAP complains if you give it an empty list @@ -8361,16 +8365,16 @@ class OrderedPartitions(Partitions): sage: OrderedPartitions(3) Ordered partitions of 3 - sage: OrderedPartitions(3).list() + sage: OrderedPartitions(3).list() # optional - sage.libs.gap [[3], [2, 1], [1, 2], [1, 1, 1]] sage: OrderedPartitions(3,2) Ordered partitions of 3 of length 2 - sage: OrderedPartitions(3,2).list() + sage: OrderedPartitions(3,2).list() # optional - sage.libs.gap [[2, 1], [1, 2]] - sage: OrderedPartitions(10,k=2).list() + sage: OrderedPartitions(10, k=2).list() # optional - sage.libs.gap [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 6], [3, 7], [2, 8], [1, 9]] - sage: OrderedPartitions(4).list() + sage: OrderedPartitions(4).list() # optional - sage.libs.gap [[4], [3, 1], [2, 2], [2, 1, 1], [1, 3], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]] """ @@ -8401,7 +8405,7 @@ def __init__(self, n, k): TESTS:: - sage: TestSuite( OrderedPartitions(5,3) ).run() + sage: TestSuite( OrderedPartitions(5,3) ).run() # optional - sage.libs.gap """ Partitions.__init__(self) self.n = n @@ -8446,9 +8450,9 @@ def list(self): EXAMPLES:: - sage: OrderedPartitions(3).list() + sage: OrderedPartitions(3).list() # optional - sage.libs.gap [[3], [2, 1], [1, 2], [1, 1, 1]] - sage: OrderedPartitions(3,2).list() + sage: OrderedPartitions(3,2).list() # optional - sage.libs.gap [[2, 1], [1, 2]] """ from sage.libs.gap.libgap import libgap @@ -8468,13 +8472,13 @@ def cardinality(self): EXAMPLES:: - sage: OrderedPartitions(3).cardinality() + sage: OrderedPartitions(3).cardinality() # optional - sage.libs.gap 4 - sage: OrderedPartitions(3,2).cardinality() + sage: OrderedPartitions(3,2).cardinality() # optional - sage.libs.gap 2 - sage: OrderedPartitions(10,2).cardinality() + sage: OrderedPartitions(10,2).cardinality() # optional - sage.libs.gap 9 - sage: OrderedPartitions(15).cardinality() + sage: OrderedPartitions(15).cardinality() # optional - sage.libs.gap 16384 """ from sage.libs.gap.libgap import libgap @@ -8548,12 +8552,12 @@ def cardinality(self): EXAMPLES:: - sage: PartitionsGreatestLE(9, 5).cardinality() + sage: PartitionsGreatestLE(9, 5).cardinality() # optional - sage.libs.gap 23 TESTS:: - sage: all(PartitionsGreatestLE(n, a).cardinality() == + sage: all(PartitionsGreatestLE(n, a).cardinality() == # optional - sage.libs.gap ....: len(PartitionsGreatestLE(n, a).list()) ....: for n in range(20) for a in range(6)) True @@ -9064,19 +9068,19 @@ def number_of_partitions_length(n, k, algorithm='hybrid'): EXAMPLES:: sage: from sage.combinat.partition import number_of_partitions_length - sage: number_of_partitions_length(5, 2) + sage: number_of_partitions_length(5, 2) # optional - sage.libs.gap 2 - sage: number_of_partitions_length(10, 2) + sage: number_of_partitions_length(10, 2) # optional - sage.libs.gap 5 - sage: number_of_partitions_length(10, 4) + sage: number_of_partitions_length(10, 4) # optional - sage.libs.gap 9 - sage: number_of_partitions_length(10, 0) + sage: number_of_partitions_length(10, 0) # optional - sage.libs.gap 0 - sage: number_of_partitions_length(10, 1) + sage: number_of_partitions_length(10, 1) # optional - sage.libs.gap 1 - sage: number_of_partitions_length(0, 0) + sage: number_of_partitions_length(0, 0) # optional - sage.libs.gap 1 - sage: number_of_partitions_length(0, 1) + sage: number_of_partitions_length(0, 1) # optional - sage.libs.gap 0 """ if algorithm == 'hybrid': diff --git a/src/sage/combinat/perfect_matching.py b/src/sage/combinat/perfect_matching.py index 9d57f0b59ac..c663a689f31 100644 --- a/src/sage/combinat/perfect_matching.py +++ b/src/sage/combinat/perfect_matching.py @@ -224,7 +224,7 @@ def _latex_(self): EXAMPLES:: sage: P = PerfectMatching([(1,3),(2,5),(4,6)]) - sage: latex(P) # random + sage: latex(P) # random # optional - sage.graphs \begin{tikzpicture} ... \end{tikzpicture} @@ -234,7 +234,7 @@ def _latex_(self): Above we added ``random`` since warnings might be displayed once. The second time, there should be no warnings:: - sage: print(P._latex_()) + sage: print(P._latex_()) # optional - sage.graphs \begin{tikzpicture} ... \end{tikzpicture} @@ -377,10 +377,12 @@ def loops(self, other=None): sage: loops = sorted(loops, key=len) sage: sorted(loops[0]) ['d', 'f'] - sage: G = SymmetricGroup(4) - sage: g = G([(1,2,3,4)]) - sage: ((loops[1] in [permutation_action(g**i, ['a', 'e', 'c', 'b']) for i in range(4)]) - ....: or (loops[1] in [permutation_action(g**i, ['a', 'b', 'c', 'e']) for i in range(4)])) + sage: G = SymmetricGroup(4) # optional - sage.groups + sage: g = G([(1,2,3,4)]) # optional - sage.groups + sage: ((loops[1] in [permutation_action(g**i, ['a', 'e', 'c', 'b']) # optional - sage.groups + ....: for i in range(4)]) + ....: or (loops[1] in [permutation_action(g**i, ['a', 'b', 'c', 'e']) + ....: for i in range(4)])) True """ return list(self.loops_iterator(other)) @@ -475,11 +477,13 @@ def to_graph(self): EXAMPLES:: - sage: PerfectMatching([[1,3], [4,2]]).to_graph().edges(sort=True, labels=False) + sage: PerfectMatching([[1,3], [4,2]]).to_graph().edges(sort=True, # optional - sage.graphs + ....: labels=False) [(1, 3), (2, 4)] - sage: PerfectMatching([[1,4], [3,2]]).to_graph().edges(sort=True, labels=False) + sage: PerfectMatching([[1,4], [3,2]]).to_graph().edges(sort=True, # optional - sage.graphs + ....: labels=False) [(1, 4), (2, 3)] - sage: PerfectMatching([]).to_graph().edges(sort=True, labels=False) + sage: PerfectMatching([]).to_graph().edges(sort=True, labels=False) # optional - sage.graphs [] """ from sage.graphs.graph import Graph diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index b9c0be15ee6..babbc4d9def 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -4227,7 +4227,7 @@ def right_permutohedron_interval_iterator(self, other): EXAMPLES:: sage: p = Permutation([2, 1, 4, 5, 3]); q = Permutation([2, 5, 4, 1, 3]) - sage: p.right_permutohedron_interval(q) # indirect doctest # optional - sage.graphs + sage: p.right_permutohedron_interval(q) # indirect doctest # optional - sage.graphs sage.modules sage.rings.finite_rings [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] """ @@ -4254,27 +4254,27 @@ def right_permutohedron_interval(self, other): EXAMPLES:: sage: p = Permutation([2, 1, 4, 5, 3]); q = Permutation([2, 5, 4, 1, 3]) - sage: p.right_permutohedron_interval(q) # optional - sage.graphs + sage: p.right_permutohedron_interval(q) # optional - sage.graphs sage.modules sage.rings.finite_rings [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] TESTS:: - sage: Permutation([]).right_permutohedron_interval(Permutation([])) # optional - sage.graphs + sage: Permutation([]).right_permutohedron_interval(Permutation([])) # optional - sage.graphs sage.modules sage.rings.finite_rings [[]] - sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) # optional - sage.graphs + sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) # optional - sage.graphs sage.modules sage.rings.finite_rings [[3, 1, 2]] - sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) # optional - sage.graphs + sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) # optional - sage.graphs sage.modules sage.rings.finite_rings [[3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1], [1, 3, 4, 2], [1, 3, 2, 4], [3, 2, 4, 1], [3, 2, 1, 4], [3, 1, 2, 4]] - sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) # optional - sage.graphs + sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) # optional - sage.graphs sage.modules sage.rings.finite_rings [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] - sage: Permutation([2, 5, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs + sage: Permutation([2, 5, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs sage.modules sage.rings.finite_rings Traceback (most recent call last): ... ValueError: [2, 5, 4, 1, 3] must be lower or equal than [2, 1, 4, 5, 3] for the right permutohedron order - sage: Permutation([2, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs + sage: Permutation([2, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs sage.modules sage.rings.finite_rings Traceback (most recent call last): ... ValueError: len([2, 4, 1, 3]) and len([2, 1, 4, 5, 3]) must be equal @@ -4802,17 +4802,17 @@ def increasing_tree(self, compare=min): EXAMPLES:: - sage: Permutation([1,4,3,2]).increasing_tree() # optional - sage.combinat + sage: Permutation([1,4,3,2]).increasing_tree() # optional - sage.graphs 1[., 2[3[4[., .], .], .]] - sage: Permutation([4,1,3,2]).increasing_tree() # optional - sage.combinat + sage: Permutation([4,1,3,2]).increasing_tree() # optional - sage.graphs 1[4[., .], 2[3[., .], .]] By passing the option ``compare=max`` one can have the decreasing tree instead:: - sage: Permutation([2,3,4,1]).increasing_tree(max) # optional - sage.combinat + sage: Permutation([2,3,4,1]).increasing_tree(max) # optional - sage.graphs 4[3[2[., .], .], 1[., .]] - sage: Permutation([2,3,1,4]).increasing_tree(max) # optional - sage.combinat + sage: Permutation([2,3,1,4]).increasing_tree(max) # optional - sage.graphs 4[3[2[., .], 1[., .]], .] """ from sage.combinat.binary_tree import LabelledBinaryTree as LBT @@ -4833,17 +4833,17 @@ def increasing_tree_shape(self, compare=min): EXAMPLES:: - sage: Permutation([1,4,3,2]).increasing_tree_shape() # optional - sage.combinat + sage: Permutation([1,4,3,2]).increasing_tree_shape() # optional - sage.graphs [., [[[., .], .], .]] - sage: Permutation([4,1,3,2]).increasing_tree_shape() # optional - sage.combinat + sage: Permutation([4,1,3,2]).increasing_tree_shape() # optional - sage.graphs [[., .], [[., .], .]] By passing the option ``compare=max`` one can have the decreasing tree instead:: - sage: Permutation([2,3,4,1]).increasing_tree_shape(max) # optional - sage.combinat + sage: Permutation([2,3,4,1]).increasing_tree_shape(max) # optional - sage.graphs [[[., .], .], [., .]] - sage: Permutation([2,3,1,4]).increasing_tree_shape(max) # optional - sage.combinat + sage: Permutation([2,3,1,4]).increasing_tree_shape(max) # optional - sage.graphs [[[., .], [., .]], .] """ return self.increasing_tree(compare).shape() @@ -4869,22 +4869,22 @@ def binary_search_tree(self, left_to_right=True): EXAMPLES:: - sage: Permutation([1,4,3,2]).binary_search_tree() # optional - sage.combinat + sage: Permutation([1,4,3,2]).binary_search_tree() # optional - sage.graphs 1[., 4[3[2[., .], .], .]] - sage: Permutation([4,1,3,2]).binary_search_tree() # optional - sage.combinat + sage: Permutation([4,1,3,2]).binary_search_tree() # optional - sage.graphs 4[1[., 3[2[., .], .]], .] By passing the option ``left_to_right=False`` one can have the insertion going from right to left:: - sage: Permutation([1,4,3,2]).binary_search_tree(False) # optional - sage.combinat + sage: Permutation([1,4,3,2]).binary_search_tree(False) # optional - sage.graphs 2[1[., .], 3[., 4[., .]]] - sage: Permutation([4,1,3,2]).binary_search_tree(False) # optional - sage.combinat + sage: Permutation([4,1,3,2]).binary_search_tree(False) # optional - sage.graphs 2[1[., .], 3[., 4[., .]]] TESTS:: - sage: Permutation([]).binary_search_tree() # optional - sage.combinat + sage: Permutation([]).binary_search_tree() # optional - sage.graphs . """ from sage.combinat.binary_tree import LabelledBinaryTree as LBT @@ -4905,17 +4905,17 @@ def binary_search_tree_shape(self, left_to_right=True): EXAMPLES:: - sage: Permutation([1,4,3,2]).binary_search_tree_shape() # optional - sage.combinat + sage: Permutation([1,4,3,2]).binary_search_tree_shape() # optional - sage.graphs [., [[[., .], .], .]] - sage: Permutation([4,1,3,2]).binary_search_tree_shape() # optional - sage.combinat + sage: Permutation([4,1,3,2]).binary_search_tree_shape() # optional - sage.graphs [[., [[., .], .]], .] By passing the option ``left_to_right=False`` one can have the insertion going from right to left:: - sage: Permutation([1,4,3,2]).binary_search_tree_shape(False) # optional - sage.combinat + sage: Permutation([1,4,3,2]).binary_search_tree_shape(False) # optional - sage.graphs [[., .], [., [., .]]] - sage: Permutation([4,1,3,2]).binary_search_tree_shape(False) # optional - sage.combinat + sage: Permutation([4,1,3,2]).binary_search_tree_shape(False) # optional - sage.graphs [[., .], [., [., .]]] """ from sage.combinat.binary_tree import binary_search_tree_shape @@ -4974,20 +4974,20 @@ def sylvester_class(self, left_to_right=False): The sylvester class of a permutation `p` contains `p`:: - sage: all(p in p.sylvester_class() for p in Permutations(4)) # optional - sage.combinat + sage: all(p in p.sylvester_class() for p in Permutations(4)) # optional - sage.combinat sage.graphs True Small cases:: - sage: list(Permutation([]).sylvester_class()) # optional - sage.combinat + sage: list(Permutation([]).sylvester_class()) # optional - sage.combinat sage.graphs [[]] - sage: list(Permutation([1]).sylvester_class()) # optional - sage.combinat + sage: list(Permutation([1]).sylvester_class()) # optional - sage.combinat sage.graphs [[1]] The sylvester classes in `S_3`:: - sage: [sorted(p.sylvester_class()) for p in Permutations(3)] # optional - sage.combinat + sage: [sorted(p.sylvester_class()) for p in Permutations(3)] # optional - sage.combinat sage.graphs [[[1, 2, 3]], [[1, 3, 2], [3, 1, 2]], [[2, 1, 3]], @@ -4997,7 +4997,7 @@ def sylvester_class(self, left_to_right=False): The left sylvester classes in `S_3`:: - sage: [sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat + sage: [sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat sage.graphs ....: for p in Permutations(3)] [[[1, 2, 3]], [[1, 3, 2]], @@ -5009,7 +5009,7 @@ def sylvester_class(self, left_to_right=False): A left sylvester class in `S_5`:: sage: p = Permutation([4, 2, 1, 5, 3]) - sage: sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat + sage: sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat sage.graphs [[4, 2, 1, 3, 5], [4, 2, 1, 5, 3], [4, 2, 3, 1, 5], @@ -5342,21 +5342,21 @@ def shifted_shuffle(self, other): sage: Permutation([]).shifted_shuffle(Permutation([])) # optional - sage.graphs [[]] - sage: Permutation([1, 2, 3]).shifted_shuffle(Permutation([1])) # optional - sage.graphs + sage: Permutation([1, 2, 3]).shifted_shuffle(Permutation([1])) # optional - sage.graphs sage.modules sage.rings.finite_rings [[4, 1, 2, 3], [1, 2, 3, 4], [1, 2, 4, 3], [1, 4, 2, 3]] - sage: Permutation([1, 2]).shifted_shuffle(Permutation([2, 1])) # optional - sage.graphs + sage: Permutation([1, 2]).shifted_shuffle(Permutation([2, 1])) # optional - sage.graphs sage.modules sage.rings.finite_rings [[4, 1, 3, 2], [4, 3, 1, 2], [1, 4, 3, 2], [1, 4, 2, 3], [1, 2, 4, 3], [4, 1, 2, 3]] - sage: Permutation([1]).shifted_shuffle([1]) # optional - sage.graphs + sage: Permutation([1]).shifted_shuffle([1]) # optional - sage.graphs sage.modules sage.rings.finite_rings [[2, 1], [1, 2]] sage: p = Permutation([3, 1, 5, 4, 2]) - sage: len(p.shifted_shuffle(Permutation([2, 1, 4, 3]))) # optional - sage.graphs + sage: len(p.shifted_shuffle(Permutation([2, 1, 4, 3]))) # optional - sage.graphs sage.modules sage.rings.finite_rings 126 The shifted shuffle product is associative. We can test this on an admittedly toy example:: - sage: all( all( all( sorted(flatten([abs.shifted_shuffle(c) # optional - sage.graphs + sage: all( all( all( sorted(flatten([abs.shifted_shuffle(c) # optional - sage.graphs sage.modules sage.rings.finite_rings ....: for abs in a.shifted_shuffle(b)])) ....: == sorted(flatten([a.shifted_shuffle(bcs) ....: for bcs in b.shifted_shuffle(c)])) @@ -5369,7 +5369,7 @@ def shifted_shuffle(self, other): permutations as the ``shifted_shuffle`` method on words (but is faster):: - sage: all( all( sorted(p1.shifted_shuffle(p2)) # optional - sage.graphs + sage: all( all( sorted(p1.shifted_shuffle(p2)) # optional - sage.graphs sage.modules sage.rings.finite_rings ....: == sorted([Permutation(p) for p in ....: Word(p1).shifted_shuffle(Word(p2))]) ....: for p2 in Permutations(3) ) @@ -5499,7 +5499,7 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(descents=([1], 4)); p Standard permutations of 4 with descents [1] - sage: p.list() # optional - sage.graphs + sage: p.list() # optional - sage.graphs sage.modules sage.rings.finite_rings [[2, 4, 1, 3], [3, 4, 1, 2], [1, 4, 2, 3], [1, 3, 2, 4], [2, 3, 1, 4]] :: @@ -5522,7 +5522,7 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(recoils_finer=[2,1]); p Standard permutations whose recoils composition is finer than [2, 1] - sage: p.list() # optional - sage.graphs + sage: p.list() # optional - sage.graphs sage.modules sage.rings.finite_rings [[3, 1, 2], [1, 2, 3], [1, 3, 2]] :: @@ -7201,7 +7201,7 @@ def conjugacy_classes_iterator(self): EXAMPLES:: sage: G = Permutations(4) - sage: list(G.conjugacy_classes_iterator()) == G.conjugacy_classes() # optional - sage.combinat + sage: list(G.conjugacy_classes_iterator()) == G.conjugacy_classes() # optional - sage.combinat sage.graphs True """ from sage.combinat.partition import Partitions_n @@ -7216,7 +7216,7 @@ def conjugacy_classes(self): EXAMPLES:: sage: G = Permutations(4) - sage: G.conjugacy_classes() # optional - sage.combinat + sage: G.conjugacy_classes() # optional - sage.combinat sage.graphs [Conjugacy class of cycle type [1, 1, 1, 1] in Standard permutations of 4, Conjugacy class of cycle type [2, 1, 1] in Standard permutations of 4, Conjugacy class of cycle type [2, 2] in Standard permutations of 4, @@ -7237,9 +7237,9 @@ def conjugacy_class(self, g): sage: G = Permutations(5) sage: g = G([2,3,4,1,5]) - sage: G.conjugacy_class(g) # optional - sage.combinat + sage: G.conjugacy_class(g) # optional - sage.combinat sage.graphs Conjugacy class of cycle type [4, 1] in Standard permutations of 5 - sage: G.conjugacy_class(Partition([2, 1, 1, 1])) # optional - sage.combinat + sage: G.conjugacy_class(Partition([2, 1, 1, 1])) # optional - sage.combinat sage.graphs Conjugacy class of cycle type [2, 1, 1, 1] in Standard permutations of 5 """ from sage.groups.perm_gps.symgp_conjugacy_class import PermutationsConjugacyClass @@ -8061,7 +8061,7 @@ def cardinality(self): sage: def P(D, n): ....: return Permutations(descents=(D, n + 1)) - sage: all(P(D, n).cardinality() == len(P(D, n).list()) # optional - sage.graphs + sage: all(P(D, n).cardinality() == len(P(D, n).list()) # optional - sage.graphs sage.modules sage.rings.finite_rings ....: for n in range(5) for D in subsets(range(n))) True @@ -8126,7 +8126,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(descents=([2,0],5)).list() # optional - sage.graphs + sage: Permutations(descents=([2,0],5)).list() # optional - sage.graphs sage.modules sage.rings.finite_rings [[5, 2, 4, 1, 3], [5, 3, 4, 1, 2], [4, 3, 5, 1, 2], @@ -8155,7 +8155,7 @@ def descents_composition_list(dc): EXAMPLES:: sage: import sage.combinat.permutation as permutation - sage: permutation.descents_composition_list([1,2,2]) # optional - sage.graphs + sage: permutation.descents_composition_list([1,2,2]) # optional - sage.graphs sage.modules sage.rings.finite_rings [[5, 2, 4, 1, 3], [5, 3, 4, 1, 2], [4, 3, 5, 1, 2], @@ -8269,7 +8269,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils_finer=[2,2]).list() # optional - sage.graphs + sage: Permutations(recoils_finer=[2,2]).list() # optional - sage.graphs sage.modules sage.rings.finite_rings [[3, 1, 4, 2], [3, 4, 1, 2], [1, 3, 4, 2], @@ -8337,7 +8337,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils_fatter=[2,2]).list() # optional - sage.graphs + sage: Permutations(recoils_fatter=[2,2]).list() # optional - sage.graphs sage.modules sage.rings.finite_rings [[4, 3, 2, 1], [3, 2, 1, 4], [3, 2, 4, 1], diff --git a/src/sage/combinat/posets/d_complete.py b/src/sage/combinat/posets/d_complete.py index 210317f2b44..2b603aeac2b 100644 --- a/src/sage/combinat/posets/d_complete.py +++ b/src/sage/combinat/posets/d_complete.py @@ -59,8 +59,8 @@ def _hooks(self): sage: P._hooks {0: 1, 1: 2, 2: 2, 3: 3} sage: from sage.combinat.posets.poset_examples import Posets - sage: P = DCompletePoset(Posets.YoungDiagramPoset(Partition([3,2,1]))._hasse_diagram.reverse()) - sage: P._hooks + sage: P = DCompletePoset(Posets.YoungDiagramPoset(Partition([3,2,1]))._hasse_diagram.reverse()) # optional - sage.combinat + sage: P._hooks # optional - sage.combinat {0: 5, 1: 3, 2: 1, 3: 3, 4: 1, 5: 1} """ hooks = {} @@ -150,8 +150,9 @@ def get_hooks(self): sage: P.get_hooks() {0: 1, 1: 2, 2: 2, 3: 3} sage: from sage.combinat.posets.poset_examples import Posets - sage: P = DCompletePoset(Posets.YoungDiagramPoset(Partition([3,2,1]))._hasse_diagram.reverse()) - sage: P.get_hooks() + sage: YDP321 = Posets.YoungDiagramPoset(Partition([3,2,1])) # optional - sage.combinat + sage: P = DCompletePoset(YDP321)._hasse_diagram.reverse()) # optional - sage.combinat + sage: P.get_hooks() # optional - sage.combinat {0: 5, 1: 3, 2: 1, 3: 3, 4: 1, 5: 1} """ return dict(self._hooks) @@ -166,8 +167,9 @@ def hook_product(self): sage: P = DCompletePoset(DiGraph({0: [1, 2], 1: [3], 2: [3], 3: []})) sage: P.hook_product() 12 - sage: P = DCompletePoset(posets.YoungDiagramPoset(Partition([3,2,1]), dual=True)) - sage: P.hook_product() + sage: P = DCompletePoset(posets.YoungDiagramPoset(Partition([3,2,1]), # optional - sage.combinat + ....: dual=True)) + sage: P.hook_product() # optional - sage.combinat 45 """ if not self._hasse_diagram: diff --git a/src/sage/combinat/posets/elements.py b/src/sage/combinat/posets/elements.py index 00b0707d8e1..4788246cd1d 100644 --- a/src/sage/combinat/posets/elements.py +++ b/src/sage/combinat/posets/elements.py @@ -78,13 +78,13 @@ def _latex_(self): EXAMPLES:: - sage: m = matrix(2,[1,2,3,4]) - sage: m.set_immutable() - sage: P = Poset(([m],[]), facade = False) - sage: [e] = P - sage: type(e) + sage: m = matrix(2, [1,2,3,4]) # optional - sage.modules + sage: m.set_immutable() # optional - sage.modules + sage: P = Poset(([m],[]), facade=False) # optional - sage.modules + sage: [e] = P # optional - sage.modules + sage: type(e) # optional - sage.modules - sage: latex(e) #indirect doctest + sage: latex(e) #indirect doctest # optional - sage.modules \left(\begin{array}{rr} 1 & 2 \\ 3 & 4 @@ -243,14 +243,14 @@ def __mul__(self, other): EXAMPLES:: - sage: D = posets.DiamondPoset(5,facade=False) - sage: D(1) * D(2) + sage: D = posets.DiamondPoset(5, facade=False) + sage: D(1) * D(2) # optional - sage.modules 0 - sage: D(1) * D(1) + sage: D(1) * D(1) # optional - sage.modules 1 - sage: D(1) * D(0) + sage: D(1) * D(0) # optional - sage.modules 0 - sage: D(1) * D(4) + sage: D(1) * D(4) # optional - sage.modules 1 """ return self.parent().meet(self, other) @@ -264,13 +264,13 @@ def __add__(self, other): EXAMPLES:: sage: D = posets.DiamondPoset(5,facade=False) - sage: D(1) + D(2) + sage: D(1) + D(2) # optional - sage.modules 4 - sage: D(1) + D(1) + sage: D(1) + D(1) # optional - sage.modules 1 - sage: D(1) + D(4) + sage: D(1) + D(4) # optional - sage.modules 4 - sage: D(1) + D(0) + sage: D(1) + D(0) # optional - sage.modules 1 """ return self.parent().join(self, other) diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index 7e1f1c6e4c6..84364c149d7 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -123,7 +123,7 @@ def linear_extensions(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,2],1:[3],2:[3],3:[]}) - sage: list(H.linear_extensions()) + sage: list(H.linear_extensions()) # optional - sage.modules [[0, 1, 2, 3], [0, 2, 1, 3]] """ from sage.combinat.combinat_cython import linear_extension_iterator @@ -559,18 +559,18 @@ def dual(self): EXAMPLES:: - sage: P = posets.IntegerPartitions(4) - sage: H = P._hasse_diagram; H + sage: P = posets.IntegerPartitions(4) # optional - sage.combinat + sage: H = P._hasse_diagram; H # optional - sage.combinat Hasse diagram of a poset containing 5 elements - sage: H.dual() + sage: H.dual() # optional - sage.combinat Hasse diagram of a poset containing 5 elements TESTS:: - sage: H = posets.IntegerPartitions(4)._hasse_diagram - sage: H.is_isomorphic( H.dual().dual() ) + sage: H = posets.IntegerPartitions(4)._hasse_diagram # optional - sage.combinat + sage: H.is_isomorphic( H.dual().dual() ) # optional - sage.combinat True - sage: H.is_isomorphic( H.dual() ) + sage: H.is_isomorphic( H.dual() ) # optional - sage.combinat False """ H = self.reverse() @@ -588,11 +588,11 @@ def _precompute_intervals(self): EXAMPLES:: sage: B4 = posets.BooleanLattice(4) - sage: B4.is_isoform() # Slow + sage: B4.is_isoform() # Slow # optional - sage.combinat True sage: B4._hasse_diagram._precompute_intervals() sage: B4 = posets.BooleanLattice(4) - sage: B4.is_isoform() # Faster now + sage: B4.is_isoform() # Faster now # optional - sage.combinat True """ n = self.order() @@ -1057,7 +1057,7 @@ def moebius_function_matrix(self, algorithm='cython'): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,3,2],1:[4],2:[4,5,6],3:[6],4:[7],5:[7],6:[7],7:[]}) - sage: H.moebius_function_matrix() + sage: H.moebius_function_matrix() # optional - sage.libs.flint sage.modules [ 1 -1 -1 -1 1 0 1 0] [ 0 1 0 0 -1 0 0 0] [ 0 0 1 0 -1 -1 -1 2] @@ -1069,28 +1069,28 @@ def moebius_function_matrix(self, algorithm='cython'): TESTS:: - sage: H.moebius_function_matrix().is_immutable() + sage: H.moebius_function_matrix().is_immutable() # optional - sage.libs.flint sage.modules True - sage: hasattr(H,'_moebius_function_matrix') + sage: hasattr(H,'_moebius_function_matrix') # optional - sage.libs.flint sage.modules True - sage: H.moebius_function == H._moebius_function_from_matrix + sage: H.moebius_function == H._moebius_function_from_matrix # optional - sage.libs.flint sage.modules True sage: H = posets.TamariLattice(3)._hasse_diagram - sage: M = H.moebius_function_matrix('matrix'); M + sage: M = H.moebius_function_matrix('matrix'); M # optional - sage.modules [ 1 -1 -1 0 1] [ 0 1 0 0 -1] [ 0 0 1 -1 0] [ 0 0 0 1 -1] [ 0 0 0 0 1] - sage: _ = H.__dict__.pop('_moebius_function_matrix') - sage: H.moebius_function_matrix('cython') == M + sage: _ = H.__dict__.pop('_moebius_function_matrix') # optional - sage.modules + sage: H.moebius_function_matrix('cython') == M # optional - sage.libs.flint sage.modules True - sage: _ = H.__dict__.pop('_moebius_function_matrix') - sage: H.moebius_function_matrix('recursive') == M + sage: _ = H.__dict__.pop('_moebius_function_matrix') # optional - sage.libs.flint sage.modules + sage: H.moebius_function_matrix('recursive') == M # optional - sage.modules True - sage: _ = H.__dict__.pop('_moebius_function_matrix') + sage: _ = H.__dict__.pop('_moebius_function_matrix') # optional - sage.modules sage: H.moebius_function_matrix('banana') Traceback (most recent call last): ... @@ -1161,25 +1161,25 @@ def coxeter_transformation(self, algorithm='cython'): EXAMPLES:: - sage: P = posets.PentagonPoset()._hasse_diagram - sage: M = P.coxeter_transformation(); M + sage: P = posets.PentagonPoset()._hasse_diagram # optional - sage.modules + sage: M = P.coxeter_transformation(); M # optional - sage.libs.flint sage.modules [ 0 0 0 0 -1] [ 0 0 0 1 -1] [ 0 1 0 0 -1] [-1 1 1 0 -1] [-1 1 0 1 -1] - sage: P.__dict__['coxeter_transformation'].clear_cache() - sage: P.coxeter_transformation(algorithm="matrix") == M + sage: P.__dict__['coxeter_transformation'].clear_cache() # optional - sage.libs.flint sage.modules + sage: P.coxeter_transformation(algorithm="matrix") == M # optional - sage.modules True TESTS:: - sage: P = posets.PentagonPoset()._hasse_diagram - sage: M = P.coxeter_transformation() - sage: M**8 == 1 + sage: P = posets.PentagonPoset()._hasse_diagram # optional - sage.modules + sage: M = P.coxeter_transformation() # optional - sage.libs.flint sage.modules + sage: M**8 == 1 # optional - sage.libs.flint sage.modules True - sage: P.__dict__['coxeter_transformation'].clear_cache() - sage: P.coxeter_transformation(algorithm="banana") + sage: P.__dict__['coxeter_transformation'].clear_cache() # optional - sage.libs.flint sage.modules + sage: P.coxeter_transformation(algorithm="banana") # optional - sage.libs.flint sage.modules Traceback (most recent call last): ... ValueError: unknown algorithm @@ -1311,7 +1311,7 @@ def _leq_matrix_boolean(self): sage: P = Poset([[1,3,2],[4],[4,5,6],[6],[7],[7],[7],[]]) sage: H = P._hasse_diagram - sage: M = H._leq_matrix_boolean; M + sage: M = H._leq_matrix_boolean; M # optional - sage.modules sage.rings.finite_rings [1 1 1 1 1 1 1 1] [0 1 0 1 0 0 0 1] [0 0 1 1 1 0 1 1] @@ -1320,7 +1320,7 @@ def _leq_matrix_boolean(self): [0 0 0 0 0 1 1 1] [0 0 0 0 0 0 1 1] [0 0 0 0 0 0 0 1] - sage: M.base_ring() + sage: M.base_ring() # optional - sage.modules sage.rings.finite_rings Finite Field of size 2 """ n = self.order() @@ -1344,7 +1344,7 @@ def _leq_matrix(self): sage: P = Poset([[1,3,2],[4],[4,5,6],[6],[7],[7],[7],[]]) sage: H = P._hasse_diagram - sage: M = H._leq_matrix; M + sage: M = H._leq_matrix; M # optional - sage.modules [1 1 1 1 1 1 1 1] [0 1 0 1 0 0 0 1] [0 0 1 1 1 0 1 1] @@ -1353,7 +1353,7 @@ def _leq_matrix(self): [0 0 0 0 0 1 1 1] [0 0 0 0 0 0 1 1] [0 0 0 0 0 0 0 1] - sage: M.base_ring() + sage: M.base_ring() # optional - sage.modules Integer Ring """ n = self.order() @@ -1380,7 +1380,7 @@ def lequal_matrix(self, boolean=False): sage: P = Poset([[1,3,2],[4],[4,5,6],[6],[7],[7],[7],[]]) sage: H = P._hasse_diagram - sage: M = H.lequal_matrix(); M + sage: M = H.lequal_matrix(); M # optional - sage.modules [1 1 1 1 1 1 1 1] [0 1 0 1 0 0 0 1] [0 0 1 1 1 0 1 1] @@ -1389,18 +1389,18 @@ def lequal_matrix(self, boolean=False): [0 0 0 0 0 1 1 1] [0 0 0 0 0 0 1 1] [0 0 0 0 0 0 0 1] - sage: M.base_ring() + sage: M.base_ring() # optional - sage.modules Integer Ring sage: P = posets.DiamondPoset(6) sage: H = P._hasse_diagram - sage: M = H.lequal_matrix(boolean=True) - sage: M.base_ring() + sage: M = H.lequal_matrix(boolean=True) # optional - sage.modules sage.rings.finite_rings + sage: M.base_ring() # optional - sage.modules sage.rings.finite_rings Finite Field of size 2 TESTS:: - sage: H.lequal_matrix().is_immutable() + sage: H.lequal_matrix().is_immutable() # optional - sage.modules True """ if boolean: @@ -1422,7 +1422,7 @@ def _alternate_is_lequal(self, i, j): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[2], 1:[2], 2:[3], 3:[4], 4:[]}) - sage: H.lequal_matrix() + sage: H.lequal_matrix() # optional - sage.modules [1 0 1 1 1] [0 1 1 1 1] [0 0 1 1 1] @@ -1508,7 +1508,7 @@ def _meet(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,3,2],1:[4],2:[4,5,6],3:[6],4:[7],5:[7],6:[7],7:[]}) - sage: H._meet + sage: H._meet # optional - sage.modules [0 0 0 0 0 0 0 0] [0 1 0 0 1 0 0 1] [0 0 2 0 2 2 2 2] @@ -1519,14 +1519,14 @@ def _meet(self): [0 1 2 3 4 5 6 7] sage: H = HasseDiagram({0:[2,3],1:[2,3]}) - sage: H._meet + sage: H._meet # optional - sage.modules [ 0 -1 0 0] [-1 1 1 1] [ 0 1 2 -1] [ 0 1 -1 3] sage: H = HasseDiagram({0:[1,2],1:[3,4],2:[3,4]}) - sage: H._meet + sage: H._meet # optional - sage.modules [ 0 0 0 0 0] [ 0 1 0 1 1] [ 0 0 2 2 2] @@ -1536,9 +1536,9 @@ def _meet(self): TESTS:: sage: from sage.combinat.posets.hasse_diagram import HasseDiagram - sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) - sage: P = L.dual() - sage: P.meet(2,3) + sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # optional - sage.modules + sage: P = L.dual() # optional - sage.modules + sage: P.meet(2,3) # optional - sage.modules 4 """ self._meet_semilattice_failure = () @@ -1588,7 +1588,7 @@ def meet_matrix(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,3,2],1:[4],2:[4,5,6],3:[6],4:[7],5:[7],6:[7],7:[]}) - sage: H.meet_matrix() + sage: H.meet_matrix() # optional - sage.modules [0 0 0 0 0 0 0 0] [0 1 0 0 1 0 0 1] [0 0 2 0 2 2 2 2] @@ -1616,7 +1616,7 @@ def meet_matrix(self): ValueError: not a meet-semilattice: no bottom element sage: H = HasseDiagram({0:[1,2],1:[3,4],2:[3,4]}) - sage: H.meet_matrix() + sage: H.meet_matrix() # optional - sage.modules Traceback (most recent call last): ... LatticeError: no meet for ... @@ -1640,19 +1640,19 @@ def is_meet_semilattice(self) -> bool: sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,3,2],1:[4],2:[4,5,6],3:[6],4:[7],5:[7],6:[7],7:[]}) - sage: H.is_meet_semilattice() + sage: H.is_meet_semilattice() # optional - sage.modules True sage: H = HasseDiagram({0:[1,2],1:[3],2:[3],3:[]}) - sage: H.is_meet_semilattice() + sage: H.is_meet_semilattice() # optional - sage.modules True sage: H = HasseDiagram({0:[2,3],1:[2,3]}) - sage: H.is_meet_semilattice() + sage: H.is_meet_semilattice() # optional - sage.modules False sage: H = HasseDiagram({0:[1,2],1:[3,4],2:[3,4]}) - sage: H.is_meet_semilattice() + sage: H.is_meet_semilattice() # optional - sage.modules False """ try: @@ -1672,7 +1672,7 @@ def _join(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,3,2],1:[4],2:[4,5,6],3:[6],4:[7],5:[7],6:[7],7:[]}) - sage: H._join + sage: H._join # optional - sage.modules [0 1 2 3 4 5 6 7] [1 1 4 7 4 7 7 7] [2 4 2 6 4 5 6 7] @@ -1683,14 +1683,14 @@ def _join(self): [7 7 7 7 7 7 7 7] sage: H = HasseDiagram({0:[2,3],1:[2,3]}) - sage: H._join + sage: H._join # optional - sage.modules [ 0 -1 2 3] [-1 1 2 3] [ 2 2 2 -1] [ 3 3 -1 3] sage: H = HasseDiagram({0:[2,3],1:[2,3],2:[4],3:[4]}) - sage: H._join + sage: H._join # optional - sage.modules [ 0 -1 2 3 4] [-1 1 2 3 4] [ 2 2 2 4 4] @@ -1700,9 +1700,9 @@ def _join(self): TESTS:: sage: from sage.combinat.posets.hasse_diagram import HasseDiagram - sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) - sage: P = L.dual() - sage: P.join(2,3) + sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # optional - sage.modules + sage: P = L.dual() # optional - sage.modules + sage: P.join(2,3) # optional - sage.modules 0 """ self._join_semilattice_failure = () @@ -1753,7 +1753,7 @@ def join_matrix(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,3,2],1:[4],2:[4,5,6],3:[6],4:[7],5:[7],6:[7],7:[]}) - sage: H.join_matrix() + sage: H.join_matrix() # optional - sage.modules [0 1 2 3 4 5 6 7] [1 1 4 7 4 7 7 7] [2 4 2 6 4 5 6 7] @@ -1773,7 +1773,7 @@ def join_matrix(self): ValueError: not a join-semilattice: no top element sage: H = HasseDiagram({0:[2,3],1:[2,3],2:[4],3:[4]}) - sage: H.join_matrix() + sage: H.join_matrix() # optional - sage.modules Traceback (most recent call last): ... LatticeError: no join for ... @@ -1797,13 +1797,13 @@ def is_join_semilattice(self) -> bool: sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,3,2],1:[4],2:[4,5,6],3:[6],4:[7],5:[7],6:[7],7:[]}) - sage: H.is_join_semilattice() + sage: H.is_join_semilattice() # optional - sage.modules True sage: H = HasseDiagram({0:[2,3],1:[2,3]}) - sage: H.is_join_semilattice() + sage: H.is_join_semilattice() # optional - sage.modules False sage: H = HasseDiagram({0:[2,3],1:[2,3],2:[4],3:[4]}) - sage: H.is_join_semilattice() + sage: H.is_join_semilattice() # optional - sage.modules False """ try: @@ -1837,9 +1837,9 @@ def find_nonsemidistributive_elements(self, meet_or_join): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1, 2], 1:[3, 4], 2:[4, 5], 3:[6], ....: 4:[6], 5:[6]}) - sage: H.find_nonsemidistributive_elements('join') is None + sage: H.find_nonsemidistributive_elements('join') is None # optional - sage.modules False - sage: H.find_nonsemidistributive_elements('meet') is None + sage: H.find_nonsemidistributive_elements('meet') is None # optional - sage.modules True """ if meet_or_join == 'join': @@ -1924,11 +1924,11 @@ def is_complemented(self) -> int | None: sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1, 2], 1:[3], 2:[3], 3:[4]}) - sage: H.is_complemented() + sage: H.is_complemented() # optional - sage.modules 1 sage: H = HasseDiagram({0:[1, 2, 3], 1:[4], 2:[4], 3:[4]}) - sage: H.is_complemented() is None + sage: H.is_complemented() is None # optional - sage.modules True """ mt = self.meet_matrix() @@ -1969,11 +1969,11 @@ def pseudocomplement(self, element): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0: [1, 2], 1: [3], 2: [4], 3: [4]}) - sage: H.pseudocomplement(2) + sage: H.pseudocomplement(2) # optional - sage.modules 3 sage: H = HasseDiagram({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) - sage: H.pseudocomplement(2) is None + sage: H.pseudocomplement(2) is None # optional - sage.modules True """ e = self.order() - 1 @@ -2000,7 +2000,7 @@ def orthocomplementations_iterator(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,2], 1:[3,4], 3:[5], 4:[5], 2:[6,7], ....: 6:[8], 7:[8], 5:[9], 8:[9]}) - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [[9, 8, 5, 6, 7, 2, 3, 4, 1, 0], [9, 8, 5, 7, 6, 2, 4, 3, 1, 0]] ALGORITHM: @@ -2021,54 +2021,54 @@ def orthocomplementations_iterator(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram() # Empty - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [[]] sage: H = HasseDiagram({0:[]}) # One element - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [[0]] sage: H = HasseDiagram({0:[1]}) # Two elements - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [[1, 0]] Trivial cases: odd number of elements, not self-dual, not complemented:: sage: H = posets.DiamondPoset(5)._hasse_diagram - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [] sage: H = posets.ChainPoset(4)._hasse_diagram - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [] sage: H = HasseDiagram( ([[0, 1], [0, 2], [0, 3], [1, 4], [1, 8], [4, 6], [4, 7], [6, 9], [7, 9], [2, 5], [3, 5], [5, 8], [8, 9]]) ) - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [] sage: H = HasseDiagram({0:[1, 2, 3], 1: [4], 2:[4], 3: [5], 4:[5]}) - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [] Complemented, self-dual and even number of elements, but not orthocomplemented:: sage: H = HasseDiagram( ([[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [0, 6], [3, 7], [5, 7], [6, 7]]) ) - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [] Unique orthocomplementations; second is not uniquely complemented, but has only one orthocomplementation:: sage: H = posets.BooleanLattice(4)._hasse_diagram # Uniquely complemented - sage: len(list(H.orthocomplementations_iterator())) + sage: len(list(H.orthocomplementations_iterator())) # optional - sage.groups 1 sage: H = HasseDiagram({0:[1, 2], 1:[3], 2:[4], 3:[5], 4:[5]}) - sage: len([_ for _ in H.orthocomplementations_iterator()]) + sage: len([_ for _ in H.orthocomplementations_iterator()]) # optional - sage.groups 1 "Lengthening diamond" must keep the number of orthocomplementations:: sage: H = HasseDiagram( ([[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [2, 5], [3, 5], [4, 5]]) ) - sage: n = len([_ for _ in H.orthocomplementations_iterator()]); n + sage: n = len([_ for _ in H.orthocomplementations_iterator()]); n # optional - sage.groups 3 sage: H = HasseDiagram('M]??O?@??C??OA???OA??@?A??C?A??O??') - sage: len([_ for _ in H.orthocomplementations_iterator()]) == n + sage: len([_ for _ in H.orthocomplementations_iterator()]) == n # optional - sage.groups True This lattice has an unique "possible orthocomplement" for every @@ -2077,7 +2077,7 @@ def orthocomplementations_iterator(self): for chain 0-1-6-11 would be 11-7-8-0, which is not a chain:: sage: H = HasseDiagram('KTGG_?AAC?O?o?@?@?E?@?@??') - sage: list(H.orthocomplementations_iterator()) + sage: list(H.orthocomplementations_iterator()) # optional - sage.groups [] """ n = self.order() @@ -2223,30 +2223,30 @@ def antichains_iterator(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: H = P._hasse_diagram - sage: H.antichains_iterator() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: H = P._hasse_diagram # optional - sage.modules + sage: H.antichains_iterator() # optional - sage.modules - sage: list(H.antichains_iterator()) + sage: list(H.antichains_iterator()) # optional - sage.modules [[], [4], [3], [2], [1], [1, 3], [1, 2], [0]] sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0:[1,2],1:[4],2:[3],3:[4]}) - sage: list(H.antichains_iterator()) + sage: list(H.antichains_iterator()) # optional - sage.modules [[], [4], [3], [2], [1], [1, 3], [1, 2], [0]] sage: H = HasseDiagram({0:[],1:[],2:[]}) - sage: list(H.antichains_iterator()) + sage: list(H.antichains_iterator()) # optional - sage.modules [[], [2], [1], [1, 2], [0], [0, 2], [0, 1], [0, 1, 2]] sage: H = HasseDiagram({0:[1],1:[2],2:[3],3:[4]}) - sage: list(H.antichains_iterator()) + sage: list(H.antichains_iterator()) # optional - sage.modules [[], [4], [3], [2], [1], [0]] TESTS:: sage: H = Poset()._hasse_diagram - sage: list(H.antichains_iterator()) + sage: list(H.antichains_iterator()) # optional - sage.modules [[]] """ # NOTE: Ordering of antichains as a prefix tree is crucial for @@ -2280,12 +2280,12 @@ def are_incomparable(self, i, j): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: H = P._hasse_diagram - sage: H.are_incomparable(1,2) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: H = P._hasse_diagram # optional - sage.modules + sage: H.are_incomparable(1,2) # optional - sage.modules True - sage: V = H.vertices(sort=True) - sage: [ (i,j) for i in V for j in V if H.are_incomparable(i,j)] + sage: V = H.vertices(sort=True) # optional - sage.modules + sage: [ (i,j) for i in V for j in V if H.are_incomparable(i,j)] # optional - sage.modules [(1, 2), (1, 3), (2, 1), (3, 1)] """ if i == j: @@ -2305,13 +2305,15 @@ def are_comparable(self, i, j): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: H = P._hasse_diagram - sage: H.are_comparable(1,2) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: H = P._hasse_diagram # optional - sage.modules + sage: H.are_comparable(1,2) # optional - sage.modules False - sage: V = H.vertices(sort=True) - sage: [ (i,j) for i in V for j in V if H.are_comparable(i,j)] - [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1), (1, 4), (2, 0), (2, 2), (2, 3), (2, 4), (3, 0), (3, 2), (3, 3), (3, 4), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4)] + sage: V = H.vertices(sort=True) # optional - sage.modules + sage: [ (i,j) for i in V for j in V if H.are_comparable(i,j)] # optional - sage.modules + [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1), (1, 4), + (2, 0), (2, 2), (2, 3), (2, 4), (3, 0), (3, 2), (3, 3), (3, 4), + (4, 0), (4, 1), (4, 2), (4, 3), (4, 4)] """ if i == j: return True @@ -2330,26 +2332,26 @@ def antichains(self, element_class=list): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: H = P._hasse_diagram - sage: A = H.antichains() - sage: list(A) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: H = P._hasse_diagram # optional - sage.modules + sage: A = H.antichains() # optional - sage.modules + sage: list(A) # optional - sage.modules [[], [0], [1], [1, 2], [1, 3], [2], [3], [4]] - sage: A.cardinality() + sage: A.cardinality() # optional - sage.modules 8 - sage: [1,3] in A + sage: [1,3] in A # optional - sage.modules True - sage: [1,4] in A + sage: [1,4] in A # optional - sage.modules False TESTS:: - sage: TestSuite(A).run() + sage: TestSuite(A).run() # optional - sage.modules - sage: A = Poset()._hasse_diagram.antichains() - sage: list(A) + sage: A = Poset()._hasse_diagram.antichains() # optional - sage.modules + sage: list(A) # optional - sage.modules [[]] - sage: TestSuite(A).run() + sage: TestSuite(A).run() # optional - sage.modules """ from sage.combinat.subsets_pairwise import PairwiseCompatibleSubsets return PairwiseCompatibleSubsets(self.vertices(sort=True), @@ -2381,21 +2383,23 @@ def chains(self, element_class=list, exclude=None, conversion=None): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: H = P._hasse_diagram - sage: A = H.chains() - sage: list(A) - [[], [0], [0, 1], [0, 1, 4], [0, 2], [0, 2, 3], [0, 2, 3, 4], [0, 2, 4], [0, 3], [0, 3, 4], [0, 4], [1], [1, 4], [2], [2, 3], [2, 3, 4], [2, 4], [3], [3, 4], [4]] - sage: A.cardinality() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: H = P._hasse_diagram # optional - sage.modules + sage: A = H.chains() # optional - sage.modules + sage: list(A) # optional - sage.modules + [[], [0], [0, 1], [0, 1, 4], [0, 2], [0, 2, 3], [0, 2, 3, 4], [0, 2, 4], + [0, 3], [0, 3, 4], [0, 4], [1], [1, 4], [2], [2, 3], [2, 3, 4], [2, 4], + [3], [3, 4], [4]] + sage: A.cardinality() # optional - sage.modules 20 - sage: [1,3] in A + sage: [1,3] in A # optional - sage.modules False - sage: [1,4] in A + sage: [1,4] in A # optional - sage.modules True One can exclude some vertices:: - sage: list(H.chains(exclude=[4, 3])) + sage: list(H.chains(exclude=[4, 3])) # optional - sage.modules [[], [0], [0, 1], [0, 2], [1], [2]] The ``element_class`` keyword determines how the chains are @@ -2424,15 +2428,15 @@ def is_linear_interval(self, t_min, t_max) -> bool: EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: H = P._hasse_diagram - sage: H.is_linear_interval(0, 4) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: H = P._hasse_diagram # optional - sage.modules + sage: H.is_linear_interval(0, 4) # optional - sage.modules False - sage: H.is_linear_interval(0, 3) + sage: H.is_linear_interval(0, 3) # optional - sage.modules True - sage: H.is_linear_interval(1, 3) + sage: H.is_linear_interval(1, 3) # optional - sage.modules False - sage: H.is_linear_interval(1, 1) + sage: H.is_linear_interval(1, 1) # optional - sage.modules True TESTS:: @@ -2504,9 +2508,9 @@ def diamonds(self): sage: H.diamonds() ([(0, 1, 2, 3)], True) - sage: P = posets.YoungDiagramPoset(Partition([3, 2, 2])) - sage: H = P._hasse_diagram - sage: H.diamonds() + sage: P = posets.YoungDiagramPoset(Partition([3, 2, 2])) # optional - sage.combinat + sage: H = P._hasse_diagram # optional - sage.combinat + sage: H.diamonds() # optional - sage.combinat ([(0, 1, 3, 4), (3, 4, 5, 6)], False) """ diamonds = [] @@ -2534,8 +2538,8 @@ def common_upper_covers(self, vertices): [3] sage: from sage.combinat.posets.poset_examples import Posets - sage: H = Posets.YoungDiagramPoset(Partition([3, 2, 2]))._hasse_diagram - sage: H.common_upper_covers([4, 5]) + sage: H = Posets.YoungDiagramPoset(Partition([3, 2, 2]))._hasse_diagram # optional - sage.combinat + sage: H.common_upper_covers([4, 5]) # optional - sage.combinat [6] """ covers = set(self.neighbors_out(vertices.pop())) @@ -2555,8 +2559,8 @@ def common_lower_covers(self, vertices): [0] sage: from sage.combinat.posets.poset_examples import Posets - sage: H = Posets.YoungDiagramPoset(Partition([3, 2, 2]))._hasse_diagram - sage: H.common_lower_covers([4, 5]) + sage: H = Posets.YoungDiagramPoset(Partition([3, 2, 2]))._hasse_diagram # optional - sage.combinat + sage: H.common_lower_covers([4, 5]) # optional - sage.combinat [3] """ covers = set(self.neighbors_in(vertices.pop())) @@ -2632,9 +2636,9 @@ def sublattices_iterator(self, elms, min_e): sage: H = HasseDiagram({0: [1, 2], 1:[3], 2:[3]}) sage: it = H.sublattices_iterator(set(), 0); it - sage: next(it) + sage: next(it) # optional - sage.modules set() - sage: next(it) + sage: next(it) # optional - sage.modules {0} """ yield elms @@ -2664,9 +2668,9 @@ def maximal_sublattices(self): EXAMPLES:: - sage: L = posets.PentagonPoset() - sage: ms = L._hasse_diagram.maximal_sublattices() - sage: sorted(ms, key=sorted) + sage: L = posets.PentagonPoset() # optional - sage.modules + sage: ms = L._hasse_diagram.maximal_sublattices() # optional - sage.modules + sage: sorted(ms, key=sorted) # optional - sage.modules [{0, 1, 2, 4}, {0, 1, 3, 4}, {0, 2, 3, 4}] """ jn = self.join_matrix() @@ -2768,8 +2772,8 @@ def frattini_sublattice(self): EXAMPLES:: - sage: H = posets.PentagonPoset()._hasse_diagram - sage: H.frattini_sublattice() + sage: H = posets.PentagonPoset()._hasse_diagram # optional - sage.modules + sage: H.frattini_sublattice() # optional - sage.modules [0, 4] """ # Just a direct computation, no optimization at all. @@ -2853,7 +2857,7 @@ def skeleton(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0: [1, 2], 1: [3, 4], 2: [4], ....: 3: [5], 4: [5]}) - sage: H.skeleton() + sage: H.skeleton() # optional - sage.modules [5, 2, 0, 3] """ p_atoms = [] @@ -2945,8 +2949,8 @@ def neutral_elements(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0: [1, 2], 1: [4], 2: [3], 3: [4, 5], - ....: 4: [6], 5:[6]}) - sage: sorted(H.neutral_elements()) + ....: 4: [6], 5: [6]}) + sage: sorted(H.neutral_elements()) # optional - sage.modules [0, 4, 6] ALGORITHM: @@ -3093,10 +3097,10 @@ def atoms_of_congruence_lattice(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: N5 = HasseDiagram({0: [1, 2], 1: [4], 2: [3], 3:[4]}) - sage: N5.atoms_of_congruence_lattice() + sage: N5.atoms_of_congruence_lattice() # optional - sage.combinat [{{0}, {1}, {2, 3}, {4}}] sage: Hex = HasseDiagram({0: [1, 2], 1: [3], 2: [4], 3: [5], 4: [5]}) - sage: Hex.atoms_of_congruence_lattice() + sage: Hex.atoms_of_congruence_lattice() # optional - sage.combinat [{{0}, {1}, {2, 4}, {3}, {5}}, {{0}, {1, 3}, {2}, {4}, {5}}] ALGORITHM: @@ -3170,32 +3174,32 @@ def congruence(self, parts, start=None, stop_pairs=[]): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0: [1, 2], 1: [3], 2: [4], 3: [4]}) - sage: cong = H.congruence([[0, 1]]); cong + sage: cong = H.congruence([[0, 1]]); cong # optional - sage.modules {{0, 1, 3}, {2, 4}} - sage: H.congruence([[0, 2]], start=cong) + sage: H.congruence([[0, 2]], start=cong) # optional - sage.modules {{0, 1, 2, 3, 4}} - sage: H.congruence([[0, 1]], stop_pairs=[(1, 3)]) is None + sage: H.congruence([[0, 1]], stop_pairs=[(1, 3)]) is None # optional - sage.modules True TESTS:: sage: H = HasseDiagram('HT@O?GO?OE?G@??') - sage: H.congruence([[0, 1]]).number_of_subsets() + sage: H.congruence([[0, 1]]).number_of_subsets() # optional - sage.modules 1 sage: H = HasseDiagram('HW_oC?@@O@?O@??') - sage: H.congruence([[0, 1]]).number_of_subsets() + sage: H.congruence([[0, 1]]).number_of_subsets() # optional - sage.modules 1 Check :trac:`21861`:: sage: H = HasseDiagram({0: [1, 2], 1: [3], 2: [4], 3: [4]}) - sage: tmp = H.congruence([[1, 3]]) - sage: tmp.number_of_subsets() + sage: tmp = H.congruence([[1, 3]]) # optional - sage.modules + sage: tmp.number_of_subsets() # optional - sage.modules 4 - sage: H.congruence([[0, 1]], start=tmp).number_of_subsets() + sage: H.congruence([[0, 1]], start=tmp).number_of_subsets() # optional - sage.modules 2 - sage: tmp.number_of_subsets() + sage: tmp.number_of_subsets() # optional - sage.modules 4 """ from sage.sets.disjoint_set import DisjointSet @@ -3313,11 +3317,11 @@ def find_nontrivial_congruence(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram({0: [1, 2], 1: [5], 2: [3, 4], 3: [5], 4: [5]}) - sage: H.find_nontrivial_congruence() + sage: H.find_nontrivial_congruence() # optional - sage.modules {{0, 1}, {2, 3, 4, 5}} sage: H = HasseDiagram({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) - sage: H.find_nontrivial_congruence() is None + sage: H.find_nontrivial_congruence() is None # optional - sage.modules True ALGORITHM: @@ -3372,12 +3376,12 @@ def principal_congruences_poset(self): sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: N5 = HasseDiagram({0: [1, 2], 1: [4], 2: [3], 3: [4]}) - sage: P, D = N5.principal_congruences_poset() - sage: P + sage: P, D = N5.principal_congruences_poset() # optional - sage.combinat + sage: P # optional - sage.combinat Finite poset containing 3 elements - sage: P.bottom() + sage: P.bottom() # optional - sage.combinat (2, 3) - sage: D[(2, 3)] + sage: D[(2, 3)] # optional - sage.combinat {{0}, {1}, {2, 3}, {4}} """ from sage.combinat.set_partition import SetPartition, SetPartitions @@ -3419,7 +3423,7 @@ def congruences_iterator(self): sage: H = HasseDiagram('GY@OQ?OW@?O?') sage: it = H.congruences_iterator(); it - sage: sorted([cong.number_of_subsets() for cong in it]) + sage: sorted([cong.number_of_subsets() for cong in it]) # optional - sage.combinat [1, 2, 2, 2, 4, 4, 4, 8] """ from sage.sets.disjoint_set import DisjointSet @@ -3454,26 +3458,26 @@ def is_congruence_normal(self) -> bool: sage: from sage.combinat.posets.hasse_diagram import HasseDiagram sage: H = HasseDiagram('IX?Q@?AG?OG?W?O@??') - sage: H.is_congruence_normal() + sage: H.is_congruence_normal() # optional - sage.combinat True The 5-element diamond is the smallest non-example:: sage: H = HasseDiagram({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) - sage: H.is_congruence_normal() + sage: H.is_congruence_normal() # optional - sage.combinat False This is done by doubling a non-convex subset:: sage: H = HasseDiagram('OQC?a?@CO?G_C@?GA?O??_??@?BO?A_?G??C??_?@???') - sage: H.is_congruence_normal() + sage: H.is_congruence_normal() # optional - sage.combinat False TESTS:: - sage: HasseDiagram().is_congruence_normal() + sage: HasseDiagram().is_congruence_normal() # optional - sage.combinat True - sage: HasseDiagram({0: []}).is_congruence_normal() + sage: HasseDiagram({0: []}).is_congruence_normal() # optional - sage.combinat True ALGORITHM: diff --git a/src/sage/combinat/posets/linear_extensions.py b/src/sage/combinat/posets/linear_extensions.py index e14be386228..8982e94eacc 100644 --- a/src/sage/combinat/posets/linear_extensions.py +++ b/src/sage/combinat/posets/linear_extensions.py @@ -232,8 +232,8 @@ def is_greedy(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: for l in P.linear_extensions(): + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: for l in P.linear_extensions(): # optional - sage.modules ....: if not l.is_greedy(): ....: print(l) [0, 2, 1, 3, 4] @@ -274,16 +274,16 @@ def is_supergreedy(self): sage: X = [0,1,2,3,4,5,6] sage: Y = [[0,5],[1,4],[1,5],[3,6],[4,3],[5,6],[6,2]] - sage: P = Poset((X,Y), cover_relations = True, facade=False) - sage: for l in P.linear_extensions(): + sage: P = Poset((X,Y), cover_relations=True, facade=False) + sage: for l in P.linear_extensions(): # optional - sage.modules sage.rings.finite_rings ....: if l.is_supergreedy(): ....: print(l) [1, 4, 3, 0, 5, 6, 2] [0, 1, 4, 3, 5, 6, 2] [0, 1, 5, 4, 3, 6, 2] - sage: Q = posets.PentagonPoset() - sage: for l in Q.linear_extensions(): + sage: Q = posets.PentagonPoset() # optional - sage.modules + sage: for l in Q.linear_extensions(): # optional - sage.modules sage.rings.finite_rings ....: if not l.is_supergreedy(): ....: print(l) [0, 2, 1, 3, 4] @@ -332,7 +332,7 @@ def tau(self, i): [1, 2, 3, 4] sage: l.tau(1) [2, 1, 3, 4] - sage: for p in L: + sage: for p in L: # optional - sage.modules sage.rings.finite_rings ....: for i in range(1,4): ....: print("{} {} {}".format(i, p, p.tau(i))) 1 [1, 2, 3, 4] [2, 1, 3, 4] @@ -489,7 +489,7 @@ class LinearExtensionsOfPoset(UniqueRepresentation, Parent): The set of all linear extensions of Finite poset containing 4 elements with distinguished linear extension sage: L.cardinality() 5 - sage: L.list() + sage: L.list() # optional - sage.modules sage.rings.finite_rings [[1, 2, 3, 4], [2, 1, 3, 4], [2, 1, 4, 3], [1, 4, 2, 3], [1, 2, 4, 3]] sage: L.an_element() [1, 2, 3, 4] @@ -664,7 +664,7 @@ def __iter__(self): sage: rels = [[1,3],[1,4],[2,3]] sage: P = Poset((elms, rels), linear_extension=True) sage: L = P.linear_extensions() - sage: list(L) + sage: list(L) # optional - sage.modules sage.rings.finite_rings [[1, 2, 3, 4], [2, 1, 3, 4], [2, 1, 4, 3], [1, 4, 2, 3], [1, 2, 4, 3]] """ from sage.combinat.combinat_cython import linear_extension_iterator @@ -822,28 +822,28 @@ def markov_chain_transition_matrix(self, action='promotion', labeling='identity' sage: P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]), linear_extension = True) sage: L = P.linear_extensions() - sage: L.markov_chain_transition_matrix() + sage: L.markov_chain_transition_matrix() # optional - sage.modules [-x0 - x1 - x2 x2 x0 + x1 0 0] [ x1 + x2 -x0 - x1 - x2 0 x0 0] [ 0 x1 -x0 - x1 0 x0] [ 0 x0 0 -x0 - x1 - x2 x1 + x2] [ x0 0 0 x1 + x2 -x0 - x1 - x2] - sage: L.markov_chain_transition_matrix(labeling = 'source') + sage: L.markov_chain_transition_matrix(labeling='source') # optional - sage.modules [-x0 - x1 - x2 x3 x0 + x3 0 0] [ x1 + x2 -x0 - x1 - x3 0 x1 0] [ 0 x1 -x0 - x3 0 x1] [ 0 x0 0 -x0 - x1 - x2 x0 + x3] [ x0 0 0 x0 + x2 -x0 - x1 - x3] - sage: L.markov_chain_transition_matrix(action = 'tau') + sage: L.markov_chain_transition_matrix(action='tau') # optional - sage.modules [ -x0 - x2 x2 0 x0 0] [ x2 -x0 - x1 - x2 x1 0 x0] [ 0 x1 -x1 0 0] [ x0 0 0 -x0 - x2 x2] [ 0 x0 0 x2 -x0 - x2] - sage: L.markov_chain_transition_matrix(action = 'tau', labeling = 'source') + sage: L.markov_chain_transition_matrix(action='tau', labeling='source') # optional - sage.modules [ -x0 - x2 x3 0 x1 0] [ x2 -x0 - x1 - x3 x3 0 x1] [ 0 x1 -x3 0 0] @@ -922,8 +922,8 @@ def cardinality(self): EXAMPLES:: sage: from sage.combinat.posets.poset_examples import Posets - sage: P = Posets.YoungDiagramPoset(Partition([3,2]), dual=True) - sage: P.linear_extensions().cardinality() + sage: P = Posets.YoungDiagramPoset(Partition([3,2]), dual=True) # optional - sage.combinat + sage: P.linear_extensions().cardinality() # optional - sage.combinat sage.modules 5 """ num_elmts = self._poset.cardinality() @@ -949,11 +949,11 @@ def cardinality(self): sage: from sage.combinat.posets.forest import ForestPoset sage: from sage.combinat.posets.poset_examples import Posets sage: P = Poset({0: [2], 1: [2], 2: [3, 4], 3: [], 4: []}) - sage: P.linear_extensions().cardinality() + sage: P.linear_extensions().cardinality() # optional - sage.modules 4 sage: Q = Poset({0: [1], 1: [2, 3], 2: [], 3: [], 4: [5, 6], 5: [], 6: []}) - sage: Q.linear_extensions().cardinality() + sage: Q.linear_extensions().cardinality() # optional - sage.modules 140 """ return sum(self.atkinson(self._elements[0])) @@ -974,17 +974,18 @@ def cardinality(self): sage: from sage.combinat.posets.mobile import MobilePoset sage: M = MobilePoset(DiGraph([[0,1,2,3,4,5,6,7,8], [(1,0),(3,0),(2,1),(2,3),(4, ....: 3), (5,4),(5,6),(7,4),(7,8)]])) - sage: M.linear_extensions().cardinality() + sage: M.linear_extensions().cardinality() # optional - sage.modules 1098 sage: M1 = posets.RibbonPoset(6, [1,3]) - sage: M1.linear_extensions().cardinality() + sage: M1.linear_extensions().cardinality() # optional - sage.modules 61 - sage: P = posets.MobilePoset(posets.RibbonPoset(7, [1,3]), {1: - ....: [posets.YoungDiagramPoset([3, 2], dual=True)], 3: [posets.DoubleTailedDiamond(6)]}, - ....: anchor=(4, 2, posets.ChainPoset(6))) - sage: P.linear_extensions().cardinality() + sage: P = posets.MobilePoset(posets.RibbonPoset(7, [1,3]), # optional - sage.combinat + ....: {1: [posets.YoungDiagramPoset([3, 2], dual=True)], + ....: 3: [posets.DoubleTailedDiamond(6)]}, + ....: anchor=(4, 2, posets.ChainPoset(6))) + sage: P.linear_extensions().cardinality() # optional - sage.combinat sage.modules 361628701868606400 """ import sage.combinat.posets.d_complete as dc diff --git a/src/sage/combinat/posets/mobile.py b/src/sage/combinat/posets/mobile.py index 26e793c96d2..d09eb370fa7 100644 --- a/src/sage/combinat/posets/mobile.py +++ b/src/sage/combinat/posets/mobile.py @@ -28,13 +28,13 @@ class MobilePoset(FinitePoset): EXAMPLES:: - sage: P = posets.MobilePoset(posets.RibbonPoset(7, [1,3]), + sage: P = posets.MobilePoset(posets.RibbonPoset(7, [1,3]), # optional - sage.combinat ....: {1: [posets.YoungDiagramPoset([3, 2], dual=True)], ....: 3: [posets.DoubleTailedDiamond(6)]}, ....: anchor=(4, 2, posets.ChainPoset(6))) - sage: len(P._ribbon) + sage: len(P._ribbon) # optional - sage.combinat 8 - sage: P._anchor + sage: P._anchor # optional - sage.combinat (4, 5) This example is Example 5.9 in [GGMM2020]_:: @@ -53,7 +53,7 @@ class MobilePoset(FinitePoset): [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] sage: P2._anchor (8, (8, 0)) - sage: P2.linear_extensions().cardinality() + sage: P2.linear_extensions().cardinality() # optional - sage.modules 21399440939 sage: EP = posets.MobilePoset(posets.ChainPoset(0), {}) diff --git a/src/sage/combinat/posets/poset_examples.py b/src/sage/combinat/posets/poset_examples.py index f5b32cc30bd..f9a5d793dfa 100644 --- a/src/sage/combinat/posets/poset_examples.py +++ b/src/sage/combinat/posets/poset_examples.py @@ -3,7 +3,7 @@ Some common posets can be accessed through the ``posets.`` object:: - sage: posets.PentagonPoset() + sage: posets.PentagonPoset() # optional - sage.modules Finite lattice containing 5 elements Moreover, the set of all posets of order `n` is represented by ``Posets(n)``:: @@ -238,9 +238,9 @@ def BooleanLattice(n, facade=None, use_subsets=False): Check the corner cases:: - sage: list(posets.BooleanLattice(0, use_subsets=True)) + sage: list(posets.BooleanLattice(0, use_subsets=True)) # optional - sage.modules [{}] - sage: list(posets.BooleanLattice(1, use_subsets=True)) + sage: list(posets.BooleanLattice(1, use_subsets=True)) # optional - sage.modules [{}, {1}] """ n = check_int(n) @@ -382,22 +382,22 @@ def PentagonPoset(facade=None): EXAMPLES:: - sage: P = posets.PentagonPoset(); P + sage: P = posets.PentagonPoset(); P # optional - sage.modules Finite lattice containing 5 elements - sage: P.cover_relations() + sage: P.cover_relations() # optional - sage.modules [[0, 1], [0, 2], [1, 4], [2, 3], [3, 4]] TESTS: This is smallest lattice that is not modular:: - sage: P.is_modular() + sage: P.is_modular() # optional - sage.modules False This poset and the :meth:`DiamondPoset` are the two smallest lattices which are not distributive:: - sage: P.is_distributive() + sage: P.is_distributive() # optional - sage.modules False sage: posets.DiamondPoset(5).is_distributive() False @@ -535,9 +535,9 @@ def IntegerPartitions(n): EXAMPLES:: - sage: P = posets.IntegerPartitions(7); P + sage: P = posets.IntegerPartitions(7); P # optional - sage.combinat Finite poset containing 15 elements - sage: len(P.cover_relations()) + sage: len(P.cover_relations()) # optional - sage.combinat 28 """ def lower_covers(partition): @@ -573,9 +573,9 @@ def RestrictedIntegerPartitions(n): EXAMPLES:: - sage: P = posets.RestrictedIntegerPartitions(7); P + sage: P = posets.RestrictedIntegerPartitions(7); P # optional - sage.combinat Finite poset containing 15 elements - sage: len(P.cover_relations()) + sage: len(P.cover_relations()) # optional - sage.combinat 17 """ @@ -617,9 +617,9 @@ def IntegerPartitionsDominanceOrder(n): EXAMPLES:: - sage: P = posets.IntegerPartitionsDominanceOrder(6); P + sage: P = posets.IntegerPartitionsDominanceOrder(6); P # optional - sage.combinat Finite lattice containing 11 elements - sage: P.cover_relations() + sage: P.cover_relations() # optional - sage.combinat [[[1, 1, 1, 1, 1, 1], [2, 1, 1, 1, 1]], [[2, 1, 1, 1, 1], [2, 2, 1, 1]], [[2, 2, 1, 1], [2, 2, 2]], @@ -652,22 +652,22 @@ def PowerPoset(n): EXAMPLES:: - sage: P3 = posets.PowerPoset(3); P3 + sage: P3 = posets.PowerPoset(3); P3 # optional - sage.modules Finite meet-semilattice containing 19 elements - sage: all(P.is_chain() for P in P3.maximal_elements()) + sage: all(P.is_chain() for P in P3.maximal_elements()) # optional - sage.modules True TESTS:: - sage: P0 = posets.PowerPoset(0); P0 + sage: P0 = posets.PowerPoset(0); P0 # optional - sage.modules Finite meet-semilattice containing 1 elements - sage: P0[0] + sage: P0[0] # optional - sage.modules Finite poset containing 0 elements - sage: P1 = posets.PowerPoset(1); P1 + sage: P1 = posets.PowerPoset(1); P1 # optional - sage.modules Finite meet-semilattice containing 1 elements - sage: P1[0] + sage: P1[0] # optional - sage.modules Finite poset containing 1 elements - sage: P1[0][0] + sage: P1[0][0] # optional - sage.modules 0 """ # Todo: Make this faster. @@ -697,22 +697,22 @@ def ProductOfChains(chain_lengths, facade=None): EXAMPLES:: - sage: P = posets.ProductOfChains([2, 2]); P + sage: P = posets.ProductOfChains([2, 2]); P # optional - sage.modules Finite lattice containing 4 elements - sage: P.linear_extension() + sage: P.linear_extension() # optional - sage.modules [(0, 0), (0, 1), (1, 0), (1, 1)] - sage: P.upper_covers((0,0)) + sage: P.upper_covers((0,0)) # optional - sage.modules [(0, 1), (1, 0)] - sage: P.lower_covers((1,1)) + sage: P.lower_covers((1,1)) # optional - sage.modules [(0, 1), (1, 0)] TESTS:: - sage: P = posets.ProductOfChains([]); P + sage: P = posets.ProductOfChains([]); P # optional - sage.modules Finite lattice containing 0 elements - sage: P = posets.ProductOfChains([3, 0, 1]); P + sage: P = posets.ProductOfChains([3, 0, 1]); P # optional - sage.modules Finite lattice containing 0 elements - sage: P = posets.ProductOfChains([1,1,1,1]); P + sage: P = posets.ProductOfChains([1,1,1,1]); P # optional - sage.modules Finite lattice containing 1 elements """ try: @@ -831,12 +831,12 @@ def RandomLattice(n, p, properties=None): EXAMPLES:: sage: set_random_seed(0) # Results are reproducible - sage: L = posets.RandomLattice(8, 0.995); L + sage: L = posets.RandomLattice(8, 0.995); L # optional - sage.modules Finite lattice containing 8 elements - sage: L.cover_relations() + sage: L.cover_relations() # optional - sage.modules [[7, 6], [7, 3], [7, 1], ..., [5, 4], [2, 4], [1, 4], [0, 4]] - sage: L = posets.RandomLattice(10, 0, properties=['dismantlable']) - sage: L.is_dismantlable() + sage: L = posets.RandomLattice(10, 0, properties=['dismantlable']) # optional - sage.modules + sage: L.is_dismantlable() # optional - sage.modules True .. SEEALSO:: :meth:`RandomPoset` @@ -858,7 +858,7 @@ def RandomLattice(n, p, properties=None): ... ValueError: unknown value junk for 'properties' - sage: posets.RandomLattice(0, 0.5) + sage: posets.RandomLattice(0, 0.5) # optional - sage.modules Finite lattice containing 0 elements """ from copy import copy @@ -941,7 +941,7 @@ def SetPartitions(n): EXAMPLES:: - sage: posets.SetPartitions(4) + sage: posets.SetPartitions(4) # optional - sage.combinat Finite lattice containing 15 elements """ from sage.combinat.set_partition import SetPartitions @@ -981,19 +981,19 @@ def SSTPoset(s, f=None): EXAMPLES:: - sage: posets.SSTPoset([2,1]) + sage: posets.SSTPoset([2,1]) # optional - sage.combinat Finite lattice containing 8 elements - sage: posets.SSTPoset([2,1],4) + sage: posets.SSTPoset([2,1],4) # optional - sage.combinat Finite lattice containing 20 elements - sage: posets.SSTPoset([2,1],2).cover_relations() + sage: posets.SSTPoset([2,1],2).cover_relations() # optional - sage.combinat [[[[1, 1], [2]], [[1, 2], [2]]]] - sage: posets.SSTPoset([3,2]).bottom() # long time (6s on sage.math, 2012) + sage: posets.SSTPoset([3,2]).bottom() # long time (6s on sage.math, 2012) # optional - sage.combinat [[1, 1, 1], [2, 2]] - sage: posets.SSTPoset([3,2],4).maximal_elements() + sage: posets.SSTPoset([3,2],4).maximal_elements() # optional - sage.combinat [[[3, 3, 4], [4, 4]]] """ from sage.combinat.tableau import SemistandardTableaux @@ -1202,11 +1202,11 @@ def TetrahedralPoset(n, *colors, **labels): sage: posets.TetrahedralPoset(4,'green','red','yellow','silver','blue','orange', labels='integers') Finite poset containing 10 elements - sage: A = AlternatingSignMatrices(3) - sage: p = A.lattice() - sage: ji = p.join_irreducibles_poset() - sage: tet = posets.TetrahedralPoset(3, 'green','yellow','blue','orange') - sage: ji.is_isomorphic(tet) + sage: A = AlternatingSignMatrices(3) # optional - sage.combinat sage.modules + sage: p = A.lattice() # optional - sage.combinat sage.modules + sage: ji = p.join_irreducibles_poset() # optional - sage.combinat sage.modules + sage: tet = posets.TetrahedralPoset(3, 'green','yellow','blue','orange') # optional - sage.combinat sage.modules + sage: ji.is_isomorphic(tet) # optional - sage.combinat sage.modules True TESTS:: @@ -1276,12 +1276,12 @@ def CoxeterGroupAbsoluteOrderPoset(W, use_reduced_words=True): EXAMPLES:: - sage: W = CoxeterGroup(['B', 3]) - sage: posets.CoxeterGroupAbsoluteOrderPoset(W) + sage: W = CoxeterGroup(['B', 3]) # optional - sage.combinat sage.groups + sage: posets.CoxeterGroupAbsoluteOrderPoset(W) # optional - sage.combinat sage.groups Finite poset containing 48 elements - sage: W = WeylGroup(['B', 2], prefix='s') - sage: posets.CoxeterGroupAbsoluteOrderPoset(W, False) + sage: W = WeylGroup(['B', 2], prefix='s') # optional - sage.combinat sage.groups + sage: posets.CoxeterGroupAbsoluteOrderPoset(W, False) # optional - sage.combinat sage.groups Finite poset containing 8 elements """ if use_reduced_words: @@ -1300,12 +1300,12 @@ def NoncrossingPartitions(W): EXAMPLES:: - sage: W = CoxeterGroup(['A', 3]) - sage: posets.NoncrossingPartitions(W) + sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: posets.NoncrossingPartitions(W) # optional - sage.combinat sage.groups Finite lattice containing 14 elements - sage: W = WeylGroup(['B', 2], prefix='s') - sage: posets.NoncrossingPartitions(W) + sage: W = WeylGroup(['B', 2], prefix='s') # optional - sage.combinat sage.groups + sage: posets.NoncrossingPartitions(W) # optional - sage.combinat sage.groups Finite lattice containing 6 elements """ return W.noncrossing_partition_lattice() @@ -1331,11 +1331,11 @@ def SymmetricGroupAbsoluteOrderPoset(n, labels="permutations"): EXAMPLES:: - sage: posets.SymmetricGroupAbsoluteOrderPoset(4) + sage: posets.SymmetricGroupAbsoluteOrderPoset(4) # optional - sage.groups Finite poset containing 24 elements - sage: posets.SymmetricGroupAbsoluteOrderPoset(3, labels="cycles") + sage: posets.SymmetricGroupAbsoluteOrderPoset(3, labels="cycles") # optional - sage.groups Finite poset containing 6 elements - sage: posets.SymmetricGroupAbsoluteOrderPoset(3, labels="reduced_words") + sage: posets.SymmetricGroupAbsoluteOrderPoset(3, labels="reduced_words") # optional - sage.groups Finite poset containing 6 elements """ from sage.groups.perm_gps.permgroup_named import SymmetricGroup @@ -1380,7 +1380,7 @@ def UpDownPoset(n, m=1): Fibonacci numbers as the number of antichains of a poset:: - sage: [len(posets.UpDownPoset(n).antichains().list()) for n in range(6)] + sage: [len(posets.UpDownPoset(n).antichains().list()) for n in range(6)] # optional - sage.combinat [1, 2, 3, 5, 8, 13] TESTS:: @@ -1414,13 +1414,13 @@ def YoungDiagramPoset(lam, dual=False): EXAMPLES:: - sage: P = posets.YoungDiagramPoset(Partition([2, 2])); P + sage: P = posets.YoungDiagramPoset(Partition([2, 2])); P # optional - sage.combinat Finite meet-semilattice containing 4 elements - sage: sorted(P.cover_relations()) + sage: sorted(P.cover_relations()) # optional - sage.combinat [[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0), (1, 1)]] - sage: posets.YoungDiagramPoset([3, 2], dual=True) + sage: posets.YoungDiagramPoset([3, 2], dual=True) # optional - sage.combinat Finite join-semilattice containing 5 elements """ from sage.combinat.partition import Partition @@ -1460,9 +1460,9 @@ def YoungsLattice(n): EXAMPLES:: - sage: P = posets.YoungsLattice(3); P + sage: P = posets.YoungsLattice(3); P # optional - sage.combinat Finite meet-semilattice containing 7 elements - sage: P.cover_relations() + sage: P.cover_relations() # optional - sage.combinat [[[], [1]], [[1], [1, 1]], [[1], [2]], @@ -1488,10 +1488,10 @@ def YoungsLatticePrincipalOrderIdeal(lam): EXAMPLES:: - sage: P = posets.YoungsLatticePrincipalOrderIdeal(Partition([2,2])) - sage: P + sage: P = posets.YoungsLatticePrincipalOrderIdeal(Partition([2,2])) # optional - sage.combinat + sage: P # optional - sage.combinat Finite lattice containing 6 elements - sage: P.cover_relations() + sage: P.cover_relations() # optional - sage.combinat [[[], [1]], [[1], [1, 1]], [[1], [2]], @@ -1527,16 +1527,16 @@ def YoungFibonacci(n): EXAMPLES:: - sage: Y5 = posets.YoungFibonacci(5); Y5 + sage: Y5 = posets.YoungFibonacci(5); Y5 # optional - sage.combinat Finite meet-semilattice containing 20 elements - sage: sorted(Y5.upper_covers(Word('211'))) + sage: sorted(Y5.upper_covers(Word('211'))) # optional - sage.combinat [word: 1211, word: 2111, word: 221] TESTS:: - sage: posets.YoungFibonacci(0) + sage: posets.YoungFibonacci(0) # optional - sage.combinat Finite meet-semilattice containing 1 elements - sage: posets.YoungFibonacci(1) + sage: posets.YoungFibonacci(1) # optional - sage.combinat Finite meet-semilattice containing 2 elements """ from sage.combinat.posets.lattices import FiniteMeetSemilattice @@ -1616,9 +1616,9 @@ def PermutationPattern(n): EXAMPLES:: - sage: P4 = posets.PermutationPattern(4); P4 + sage: P4 = posets.PermutationPattern(4); P4 # optional - sage.combinat Finite poset containing 33 elements - sage: sorted(P4.lower_covers(Permutation([2,4,1,3]))) + sage: sorted(P4.lower_covers(Permutation([2,4,1,3]))) # optional - sage.combinat [[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2]] .. SEEALSO:: @@ -1627,9 +1627,9 @@ def PermutationPattern(n): TESTS:: - sage: posets.PermutationPattern(1) + sage: posets.PermutationPattern(1) # optional - sage.combinat Finite poset containing 1 elements - sage: posets.PermutationPattern(2) + sage: posets.PermutationPattern(2) # optional - sage.combinat Finite poset containing 3 elements """ n = check_int(n, 1) @@ -1660,9 +1660,9 @@ def PermutationPatternInterval(bottom, top): sage: t = Permutation([2,3,1]) sage: b = Permutation([4,6,2,3,5,1]) - sage: R = posets.PermutationPatternInterval(t, b); R + sage: R = posets.PermutationPatternInterval(t, b); R # optional - sage.combinat Finite poset containing 14 elements - sage: R.moebius_function(R.bottom(),R.top()) + sage: R.moebius_function(R.bottom(),R.top()) # optional - sage.combinat -4 .. SEEALSO:: @@ -1673,7 +1673,7 @@ def PermutationPatternInterval(bottom, top): TESTS:: sage: p = Permutation([1]) - sage: posets.PermutationPatternInterval(p, p) + sage: posets.PermutationPatternInterval(p, p) # optional - sage.combinat Finite poset containing 1 elements """ P = Permutations() @@ -1732,7 +1732,7 @@ def PermutationPatternOccurrenceInterval(bottom, top, pos): sage: t = Permutation([3,2,1]) sage: b = Permutation([6,3,4,5,2,1]) - sage: A = posets.PermutationPatternOccurrenceInterval(t, b, (0,2,4)); A + sage: A = posets.PermutationPatternOccurrenceInterval(t, b, (0,2,4)); A # optional - sage.combinat Finite poset containing 8 elements .. SEEALSO:: @@ -1818,11 +1818,11 @@ def MobilePoset(ribbon, hangers, anchor=None): sage: len(M.cover_relations()) 7 - sage: P = posets.MobilePoset(posets.RibbonPoset(7, [1,3]), + sage: P = posets.MobilePoset(posets.RibbonPoset(7, [1,3]), # optional - sage.combinat ....: {1: [posets.YoungDiagramPoset([3, 2], dual=True)], ....: 3: [posets.DoubleTailedDiamond(6)]}, ....: anchor=(4, 2, posets.ChainPoset(6))) - sage: len(P.cover_relations()) + sage: len(P.cover_relations()) # optional - sage.combinat 33 """ elements = [] @@ -2039,8 +2039,8 @@ def _random_distributive_lattice(n): EXAMPLES:: - sage: g = sage.combinat.posets.poset_examples._random_distributive_lattice(10) - sage: Poset(g).order_ideals_lattice(as_ideals=False).cardinality() + sage: g = sage.combinat.posets.poset_examples._random_distributive_lattice(10) # optional - sage.modules + sage: Poset(g).order_ideals_lattice(as_ideals=False).cardinality() # optional - sage.modules 10 ALGORITHM: @@ -2095,8 +2095,8 @@ def _random_stone_lattice(n): EXAMPLES:: - sage: g = sage.combinat.posets.poset_examples._random_stone_lattice(10) - sage: LatticePoset(g).is_stone() + sage: g = sage.combinat.posets.poset_examples._random_stone_lattice(10) # optional - sage.combinat + sage: LatticePoset(g).is_stone() # optional - sage.combinat True ALGORITHM: diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 0812da9a83c..65ad12be6bf 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -433,7 +433,7 @@ def Poset(data=None, element_labels=None, cover_relations=False, linear_extensio With a function that identifies the cover relations: the set partitions of `\{1, 2, 3\}` ordered by refinement:: - sage: elms = SetPartitions(3) + sage: elms = SetPartitions(3) # optional - sage.combinat sage: def fcn(A, B): ....: if len(A) != len(B)+1: ....: return False @@ -441,7 +441,7 @@ def Poset(data=None, element_labels=None, cover_relations=False, linear_extensio ....: if not any(set(a).issubset(b) for b in B): ....: return False ....: return True - sage: Poset((elms, fcn), cover_relations=True) + sage: Poset((elms, fcn), cover_relations=True) # optional - sage.combinat Finite poset containing 5 elements 3. A dictionary of upper covers:: @@ -1350,7 +1350,7 @@ def hasse_diagram(self): [1, 3, 5, 15] sage: H.edges(sort=True) [(1, 3, None), (1, 5, None), (3, 15, None), (5, 15, None)] - sage: H.set_latex_options(format="dot2tex") + sage: H.set_latex_options(format="dot2tex") # optional - sage.plot sage: view(H) # optional - dot2tex, not tested (opens external window) """ G = DiGraph(self._hasse_diagram).relabel(self._list, inplace=False) @@ -1396,8 +1396,8 @@ def _repr_(self): sage: P5._repr_() 'Finite poset containing 7 elements' - sage: M = MeetSemilattice([[1,2],[3],[3]]) - sage: M._repr_() + sage: M = MeetSemilattice([[1,2],[3],[3]]) # optional - sage.modules + sage: M._repr_() # optional - sage.modules 'Finite meet-semilattice containing 3 elements' """ s = "%s containing %s elements" % (self._desc, self._hasse_diagram.order()) @@ -1499,14 +1499,14 @@ def sorted(self, l, allow_incomparable=True, remove_duplicates=False): TESTS:: - sage: P = posets.PentagonPoset() - sage: P.sorted([], allow_incomparable=True, remove_duplicates=True) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.sorted([], allow_incomparable=True, remove_duplicates=True) # optional - sage.modules [] - sage: P.sorted([], allow_incomparable=False, remove_duplicates=True) + sage: P.sorted([], allow_incomparable=False, remove_duplicates=True) # optional - sage.modules [] - sage: P.sorted([], allow_incomparable=True, remove_duplicates=False) + sage: P.sorted([], allow_incomparable=True, remove_duplicates=False) # optional - sage.modules [] - sage: P.sorted([], allow_incomparable=False, remove_duplicates=False) + sage: P.sorted([], allow_incomparable=False, remove_duplicates=False) # optional - sage.modules [] """ v = [self._element_to_vertex(x) for x in l] @@ -1616,7 +1616,7 @@ def linear_extensions(self, facade=False): [1, 2, 3, 4, 6, 12] sage: L.cardinality() 5 - sage: L.list() + sage: L.list() # optional - sage.modules sage.rings.finite_rings [[1, 2, 3, 4, 6, 12], [1, 2, 4, 3, 6, 12], [1, 3, 2, 4, 6, 12], @@ -1630,9 +1630,9 @@ def linear_extensions(self, facade=False): With ``facade=True``, the elements of ``L`` are plain lists instead:: - sage: L = P.linear_extensions(facade=True) - sage: l = L.an_element() - sage: type(l) + sage: L = P.linear_extensions(facade=True) # optional - sage.modules sage.rings.finite_rings + sage: l = L.an_element() # optional - sage.modules sage.rings.finite_rings + sage: type(l) # optional - sage.modules sage.rings.finite_rings .. WARNING:: @@ -1640,13 +1640,13 @@ def linear_extensions(self, facade=False): In Sage <= 4.8, this function used to return a plain list of lists. To recover the previous functionality, please use:: - sage: L = list(P.linear_extensions(facade=True)); L + sage: L = list(P.linear_extensions(facade=True)); L # optional - sage.modules sage.rings.finite_rings [[1, 2, 3, 4, 6, 12], [1, 2, 4, 3, 6, 12], [1, 3, 2, 4, 6, 12], [1, 3, 2, 6, 4, 12], [1, 2, 3, 6, 4, 12]] - sage: type(L[0]) + sage: type(L[0]) # optional - sage.modules sage.rings.finite_rings .. SEEALSO:: :meth:`linear_extension`, :meth:`is_linear_extension` @@ -1654,7 +1654,7 @@ def linear_extensions(self, facade=False): TESTS:: sage: D = Poset({ 0:[1,2], 1:[3], 2:[3,4] }) - sage: list(D.linear_extensions()) + sage: list(D.linear_extensions()) # optional - sage.modules sage.rings.finite_rings [[0, 1, 2, 3, 4], [0, 2, 1, 3, 4], [0, 2, 1, 4, 3], [0, 2, 4, 1, 3], [0, 1, 2, 4, 3]] """ return self._lin_ext_type(self, facade=facade) @@ -1678,19 +1678,19 @@ def spectrum(self, a): EXAMPLES:: sage: P = posets.ChainPoset(5) - sage: P.spectrum(2) + sage: P.spectrum(2) # optional - sage.modules sage.rings.finite_rings [0, 0, 1, 0, 0] sage: P = posets.BooleanLattice(3) - sage: P.spectrum(5) + sage: P.spectrum(5) # optional - sage.modules sage.rings.finite_rings [0, 0, 0, 4, 12, 16, 16, 0] - sage: P = posets.YoungDiagramPoset(Partition([3,2,1])) - sage: P.spectrum((0,1)) + sage: P = posets.YoungDiagramPoset(Partition([3,2,1])) # optional - sage.combinat + sage: P.spectrum((0,1)) # optional - sage.combinat sage.modules sage.rings.finite_rings [0, 8, 6, 2, 0, 0] sage: P = posets.AntichainPoset(4) - sage: P.spectrum(3) + sage: P.spectrum(3) # optional - sage.modules sage.rings.finite_rings [6, 6, 6, 6] TESTS:: @@ -1826,7 +1826,7 @@ def is_linear_extension(self, l) -> bool: [1, 2, 4, 3, 6, 12], [1, 3, 2, 4, 6, 12], [1, 3, 2, 6, 4, 12]] - sage: list(P.linear_extensions()) + sage: list(P.linear_extensions()) # optional - sage.modules sage.rings.finite_rings [[1, 2, 3, 4, 6, 12], [1, 2, 4, 3, 6, 12], [1, 3, 2, 4, 6, 12], @@ -1954,13 +1954,14 @@ def plot(self, label_elements=True, element_labels=None, To emphasize some elements and show some options:: - sage: L = LatticePoset({0: [1, 2, 3, 4], 1: [12], 2: [6, 7], + sage: L = LatticePoset({0: [1, 2, 3, 4], 1: [12], 2: [6, 7], # optional - sage.modules ....: 3: [5, 9], 4: [5, 6, 10, 11], 5: [13], ....: 6: [12], 7: [12, 8, 9], 8: [13], 9: [13], ....: 10: [12], 11: [12], 12: [13]}) - sage: F = L.frattini_sublattice() - sage: F_internal = [c for c in F.cover_relations() if c in L.cover_relations()] - sage: L.plot(figsize=12, border=True, element_shape='s', # optional - sage.plot + sage: F = L.frattini_sublattice() # optional - sage.modules + sage: F_internal = [c for c in F.cover_relations() # optional - sage.modules + ....: if c in L.cover_relations()] + sage: L.plot(figsize=12, border=True, element_shape='s', # optional - sage.modules sage.plot ....: element_size=400, element_color='white', ....: element_colors={'blue': F, 'green': L.double_irreducibles()}, ....: cover_color='lightgray', cover_colors={'black': F_internal}, @@ -1976,21 +1977,21 @@ def plot(self, label_elements=True, element_labels=None, ....: if isinstance(t, sage.plot.text.Text)) sage: P1 = Poset({ 0:[1,2], 1:[3], 2:[3,4] }) sage: P2 = Poset({ 0:[1,2], 1:[3], 2:[3,4] }, facade=True) - sage: get_plot_labels(P1.plot(label_elements=False)) + sage: get_plot_labels(P1.plot(label_elements=False)) # optional - sage.plot [] - sage: get_plot_labels(P1.plot(label_elements=True)) + sage: get_plot_labels(P1.plot(label_elements=True)) # optional - sage.plot ['0', '1', '2', '3', '4'] sage: element_labels = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e'} - sage: get_plot_labels(P1.plot(element_labels=element_labels)) + sage: get_plot_labels(P1.plot(element_labels=element_labels)) # optional - sage.plot ['a', 'b', 'c', 'd', 'e'] - sage: get_plot_labels(P2.plot(element_labels=element_labels)) + sage: get_plot_labels(P2.plot(element_labels=element_labels)) # optional - sage.plot ['a', 'b', 'c', 'd', 'e'] The following checks that :trac:`18936` has been fixed and labels still work:: sage: P = Poset({0: [1,2], 1:[3]}) sage: heights = {1 : [0], 2 : [1], 3 : [2,3]} - sage: P.plot(heights=heights) + sage: P.plot(heights=heights) # optional - sage.plot Graphics object consisting of 8 graphics primitives sage: elem_labels = {0 : 'a', 1 : 'b', 2 : 'c', 3 : 'd'} sage: P.plot(element_labels=elem_labels, heights=heights) # optional - sage.plot @@ -2015,7 +2016,7 @@ def plot(self, label_elements=True, element_labels=None, Plot of the empty poset:: sage: P = Poset({}) - sage: P.plot() + sage: P.plot() # optional - sage.plot Graphics object consisting of 0 graphics primitives """ graph = self.hasse_diagram() @@ -2110,8 +2111,8 @@ def show(self, label_elements=True, element_labels=None, One more example with cover labels:: - sage: P = posets.PentagonPoset() - sage: P.show(cover_labels=lambda a, b: a - b) # optional - sage.plot + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.show(cover_labels=lambda a, b: a - b) # optional - sage.modules sage.plot """ # We split the arguments into those meant for plot() and those meant for show() @@ -2286,8 +2287,8 @@ def diamonds(self): sage: P.diamonds() ([(0, 1, 2, 3)], True) - sage: P = posets.YoungDiagramPoset(Partition([3, 2, 2])) - sage: P.diamonds() + sage: P = posets.YoungDiagramPoset(Partition([3, 2, 2])) # optional - sage.combinat + sage: P.diamonds() # optional - sage.combinat ([((0, 0), (0, 1), (1, 0), (1, 1)), ((1, 0), (1, 1), (2, 0), (2, 1))], False) """ diamonds, all_diamonds_completed = self._hasse_diagram.diamonds() @@ -2327,23 +2328,23 @@ def meet(self, x, y): EXAMPLES:: sage: D = Poset({1:[2,3], 2:[4], 3:[4]}) - sage: D.meet(2, 3) + sage: D.meet(2, 3) # optional - sage.modules 1 sage: P = Poset({'a':['b', 'c'], 'b':['e', 'f'], 'c':['f', 'g'], ....: 'd':['f', 'g']}) - sage: P.meet('a', 'b') + sage: P.meet('a', 'b') # optional - sage.modules 'a' - sage: P.meet('e', 'a') + sage: P.meet('e', 'a') # optional - sage.modules 'a' - sage: P.meet('c', 'b') + sage: P.meet('c', 'b') # optional - sage.modules 'a' - sage: P.meet('e', 'f') + sage: P.meet('e', 'f') # optional - sage.modules 'b' - sage: P.meet('e', 'g') + sage: P.meet('e', 'g') # optional - sage.modules 'a' - sage: P.meet('c', 'd') is None + sage: P.meet('c', 'd') is None # optional - sage.modules True - sage: P.meet('g', 'f') is None + sage: P.meet('g', 'f') is None # optional - sage.modules True """ i, j = map(self._element_to_vertex, (x, y)) @@ -2361,23 +2362,23 @@ def join(self, x, y): EXAMPLES:: sage: D = Poset({1:[2,3], 2:[4], 3:[4]}) - sage: D.join(2, 3) + sage: D.join(2, 3) # optional - sage.modules 4 sage: P = Poset({'e':['b'], 'f':['b', 'c', 'd'], 'g':['c', 'd'], ....: 'b':['a'], 'c':['a']}) - sage: P.join('a', 'b') + sage: P.join('a', 'b') # optional - sage.modules 'a' - sage: P.join('e', 'a') + sage: P.join('e', 'a') # optional - sage.modules 'a' - sage: P.join('c', 'b') + sage: P.join('c', 'b') # optional - sage.modules 'a' - sage: P.join('e', 'f') + sage: P.join('e', 'f') # optional - sage.modules 'b' - sage: P.join('e', 'g') + sage: P.join('e', 'g') # optional - sage.modules 'a' - sage: P.join('c', 'd') is None + sage: P.join('c', 'd') is None # optional - sage.modules True - sage: P.join('g', 'f') is None + sage: P.join('g', 'f') is None # optional - sage.modules True """ i, j = map(self._element_to_vertex, (x, y)) @@ -2415,8 +2416,8 @@ def is_d_complete(self) -> bool: sage: D.is_d_complete() False - sage: P = Posets.YoungDiagramPoset(Partition([3, 2, 2]), dual=True) - sage: P.is_d_complete() + sage: P = Posets.YoungDiagramPoset(Partition([3, 2, 2]), dual=True) # optional - sage.combinat + sage: P.is_d_complete() # optional - sage.combinat True """ min_diamond = {} # Maps max of double-tailed diamond to min of double-tailed diamond @@ -2534,8 +2535,8 @@ def intervals_poset(self): sage: P.intervals_poset() Finite poset containing 3 elements - sage: P = posets.PentagonPoset() - sage: P.intervals_poset() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.intervals_poset() # optional - sage.modules Finite lattice containing 13 elements TESTS:: @@ -2598,8 +2599,8 @@ def relations_iterator(self, strict=False): sage: next(it), next(it) ([1, 1], [1, 2]) - sage: P = posets.PentagonPoset() - sage: list(P.relations_iterator(strict=True)) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: list(P.relations_iterator(strict=True)) # optional - sage.modules [[0, 1], [0, 2], [0, 4], [0, 3], [1, 4], [2, 3], [2, 4], [3, 4]] .. SEEALSO:: @@ -2634,8 +2635,8 @@ def relations_number(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.relations_number() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.relations_number() # optional - sage.modules 13 sage: posets.TamariLattice(4).relations_number() @@ -2667,8 +2668,8 @@ def linear_intervals_count(self) -> List[int]: EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.linear_intervals_count() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.linear_intervals_count() # optional - sage.modules [5, 5, 2] sage: P = posets.TamariLattice(4) sage: P.linear_intervals_count() @@ -2713,12 +2714,12 @@ def is_linear_interval(self, x, y) -> bool: EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.is_linear_interval(0, 4) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.is_linear_interval(0, 4) # optional - sage.modules False - sage: P.is_linear_interval(0, 3) + sage: P.is_linear_interval(0, 3) # optional - sage.modules True - sage: P.is_linear_interval(1, 3) + sage: P.is_linear_interval(1, 3) # optional - sage.modules False """ a = self._element_to_vertex(x) @@ -2748,40 +2749,42 @@ def is_incomparable_chain_free(self, m, n=None) -> bool: EXAMPLES:: sage: B3 = posets.BooleanLattice(3) - sage: B3.is_incomparable_chain_free(1, 3) + sage: B3.is_incomparable_chain_free(1, 3) # optional - sage.modules True - sage: B3.is_incomparable_chain_free(2, 2) + sage: B3.is_incomparable_chain_free(2, 2) # optional - sage.modules False - sage: IP6 = posets.IntegerPartitions(6) - sage: IP6.is_incomparable_chain_free(1, 3) + sage: IP6 = posets.IntegerPartitions(6) # optional - sage.combinat + sage: IP6.is_incomparable_chain_free(1, 3) # optional - sage.combinat sage.modules False - sage: IP6.is_incomparable_chain_free(2, 2) + sage: IP6.is_incomparable_chain_free(2, 2) # optional - sage.combinat sage.modules True A list of pairs as an argument:: - sage: B3.is_incomparable_chain_free([[1, 3], [2, 2]]) + sage: B3.is_incomparable_chain_free([[1, 3], [2, 2]]) # optional - sage.modules False We show how to get an incomparable chain pair:: - sage: P = posets.PentagonPoset() - sage: chains_1_2 = Poset({0:[], 1:[2]}) - sage: incomps = P.isomorphic_subposets(chains_1_2)[0] - sage: sorted(incomps.list()), incomps.cover_relations() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: chains_1_2 = Poset({0:[], 1:[2]}) # optional - sage.modules + sage: incomps = P.isomorphic_subposets(chains_1_2)[0] # optional - sage.modules + sage: sorted(incomps.list()), incomps.cover_relations() # optional - sage.modules ([1, 2, 3], [[2, 3]]) TESTS:: - sage: Poset().is_incomparable_chain_free(1,1) # Test empty poset + sage: Poset().is_incomparable_chain_free(1,1) # Test empty poset # optional - sage.modules True - sage: [len([p for p in Posets(n) if p.is_incomparable_chain_free(((3, 1), (2, 2)))]) for n in range(6)] # long time + sage: [len([p for p in Posets(n) # long time # optional - sage.modules + ....: if p.is_incomparable_chain_free(((3, 1), (2, 2)))]) + ....: for n in range(6)] [1, 1, 2, 5, 14, 42] sage: Q = Poset({0:[2], 1:[2], 2:[3], 3:[4], 4:[]}) - sage: Q.is_incomparable_chain_free(2, 20/10) + sage: Q.is_incomparable_chain_free(2, 20/10) # optional - sage.modules True sage: Q.is_incomparable_chain_free(2, pi) # optional - sage.symbolic Traceback (most recent call last): @@ -2800,9 +2803,9 @@ def is_incomparable_chain_free(self, m, n=None) -> bool: Traceback (most recent call last): ... TypeError: [3, 1] and [2, 2] must be integers - sage: P.is_incomparable_chain_free([[3, 1], [2, 2]]) + sage: P.is_incomparable_chain_free([[3, 1], [2, 2]]) # optional - sage.modules True - sage: P.is_incomparable_chain_free(([3, 1], [2, 2])) + sage: P.is_incomparable_chain_free(([3, 1], [2, 2])) # optional - sage.modules True sage: P.is_incomparable_chain_free([3, 1], 2) Traceback (most recent call last): @@ -3137,7 +3140,7 @@ def height(self, certificate=False): sage: P = Poset({0: [1], 2: [3, 4], 4: [5, 6]}) sage: P.height() 3 - sage: posets.PentagonPoset().height(certificate=True) + sage: posets.PentagonPoset().height(certificate=True) # optional - sage.modules (4, [0, 2, 3, 4]) TESTS:: @@ -3183,14 +3186,14 @@ def has_isomorphic_subposet(self, other): sage: D = Poset({1:[2,3], 2:[4], 3:[4]}) sage: T = Poset({1:[2,3], 2:[4,5], 3:[6,7]}) - sage: N5 = posets.PentagonPoset() + sage: N5 = posets.PentagonPoset() # optional - sage.modules - sage: N5.has_isomorphic_subposet(T) + sage: N5.has_isomorphic_subposet(T) # optional - sage.modules False - sage: N5.has_isomorphic_subposet(D) + sage: N5.has_isomorphic_subposet(D) # optional - sage.modules True - sage: len([P for P in Posets(5) if P.has_isomorphic_subposet(D)]) + sage: len([P for P in Posets(5) if P.has_isomorphic_subposet(D)]) # optional - sage.modules 11 """ @@ -3338,17 +3341,17 @@ def is_antichain_of_poset(self, elms): TESTS:: - sage: P = posets.PentagonPoset() - sage: P.is_antichain_of_poset([]) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.is_antichain_of_poset([]) # optional - sage.modules True - sage: P.is_antichain_of_poset([0]) + sage: P.is_antichain_of_poset([0]) # optional - sage.modules True - sage: P.is_antichain_of_poset([1, 2, 1]) + sage: P.is_antichain_of_poset([1, 2, 1]) # optional - sage.modules True Check :trac:`19078`:: - sage: P.is_antichain_of_poset([0, 1, 'junk']) + sage: P.is_antichain_of_poset([0, 1, 'junk']) # optional - sage.modules Traceback (most recent call last): ... ValueError: element (=junk) not in poset @@ -3701,17 +3704,17 @@ def magnitude(self) -> Integer: EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.magnitude() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.magnitude() # optional - sage.libs.flint sage.modules 1 - sage: W = SymmetricGroup(4) - sage: P = W.noncrossing_partition_lattice().without_bounds() - sage: P.magnitude() + sage: W = SymmetricGroup(4) # optional - sage.groups + sage: P = W.noncrossing_partition_lattice().without_bounds() # optional - sage.groups + sage: P.magnitude() # optional - sage.groups sage.libs.flint sage.modules -4 sage: P = posets.TamariLattice(4).without_bounds() - sage: P.magnitude() + sage: P.magnitude() # optional - sage.libs.flint sage.modules 0 .. SEEALSO:: :meth:`order_complex` @@ -3720,18 +3723,18 @@ def magnitude(self) -> Integer: sage: P1 = posets.RandomPoset(20, 0.05) sage: P2 = posets.RandomPoset(20, 0.05) - sage: m1 = P1.magnitude() - sage: m2 = P2.magnitude() + sage: m1 = P1.magnitude() # optional - sage.libs.flint sage.modules + sage: m2 = P2.magnitude() # optional - sage.libs.flint sage.modules sage: U = P1.disjoint_union(P2) sage: P = P1.product(P2) - sage: U.magnitude() == m1 + m2 + sage: U.magnitude() == m1 + m2 # optional - sage.libs.flint sage.modules True - sage: P.magnitude() == m1*m2 + sage: P.magnitude() == m1*m2 # optional - sage.libs.flint sage.modules True - sage: Poset({}).magnitude() + sage: Poset({}).magnitude() # optional - sage.libs.flint sage.modules 0 - sage: Poset({1:[]}).magnitude() + sage: Poset({1:[]}).magnitude() # optional - sage.libs.flint sage.modules 1 """ H = self._hasse_diagram @@ -3862,10 +3865,10 @@ def is_jump_critical(self, certificate=False): sage: P.is_jump_critical() True - sage: P = posets.PentagonPoset() - sage: P.is_jump_critical() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.is_jump_critical() # optional - sage.modules False - sage: P.is_jump_critical(certificate=True) + sage: P.is_jump_critical(certificate=True) # optional - sage.modules (False, 3) .. SEEALSO:: :meth:`jump_number` @@ -4024,8 +4027,8 @@ def is_graded(self) -> bool: EXAMPLES:: - sage: P = posets.PentagonPoset() # Not even ranked - sage: P.is_graded() + sage: P = posets.PentagonPoset() # Not even ranked # optional - sage.modules + sage: P.is_graded() # optional - sage.modules False sage: P = Poset({1:[2, 3], 3:[4]}) # Ranked, but not graded @@ -4214,20 +4217,20 @@ def moebius_function_matrix(self, ring=ZZ, sparse=False): sage: x,y = (P.linear_extension()[0],P.linear_extension()[1]) sage: P.moebius_function(x,y) -1 - sage: M = P.moebius_function_matrix(); M + sage: M = P.moebius_function_matrix(); M # optional - sage.libs.flint sage.modules [ 1 -1 -1 -1 2] [ 0 1 0 0 -1] [ 0 0 1 0 -1] [ 0 0 0 1 -1] [ 0 0 0 0 1] - sage: M[0,4] + sage: M[0,4] # optional - sage.libs.flint sage.modules 2 - sage: M[0,1] + sage: M[0,1] # optional - sage.libs.flint sage.modules -1 We now demonstrate the usage of the optional parameters:: - sage: P.moebius_function_matrix(ring=QQ, sparse=False).parent() + sage: P.moebius_function_matrix(ring=QQ, sparse=False).parent() # optional - sage.libs.flint sage.modules Full MatrixSpace of 5 by 5 dense matrices over Rational Field """ M = self._hasse_diagram.moebius_function_matrix() @@ -4251,8 +4254,8 @@ def lequal_matrix(self, ring=ZZ, sparse=False): EXAMPLES:: - sage: P = Poset([[1,3,2],[4],[4,5,6],[6],[7],[7],[7],[]], facade = False) - sage: LEQM = P.lequal_matrix(); LEQM + sage: P = Poset([[1,3,2],[4],[4,5,6],[6],[7],[7],[7],[]], facade=False) + sage: LEQM = P.lequal_matrix(); LEQM # optional - sage.modules [1 1 1 1 1 1 1 1] [0 1 0 1 0 0 0 1] [0 0 1 1 1 0 1 1] @@ -4261,18 +4264,18 @@ def lequal_matrix(self, ring=ZZ, sparse=False): [0 0 0 0 0 1 1 1] [0 0 0 0 0 0 1 1] [0 0 0 0 0 0 0 1] - sage: LEQM[1,3] + sage: LEQM[1,3] # optional - sage.modules 1 sage: P.linear_extension()[1] < P.linear_extension()[3] True - sage: LEQM[2,5] + sage: LEQM[2,5] # optional - sage.modules 0 sage: P.linear_extension()[2] < P.linear_extension()[5] False We now demonstrate the usage of the optional parameters:: - sage: P.lequal_matrix(ring=QQ, sparse=False).parent() + sage: P.lequal_matrix(ring=QQ, sparse=False).parent() # optional - sage.libs.flint sage.modules Full MatrixSpace of 8 by 8 dense matrices over Rational Field """ M = self._hasse_diagram.lequal_matrix(boolean=False) @@ -4298,7 +4301,7 @@ def coxeter_transformation(self): EXAMPLES:: - sage: posets.PentagonPoset().coxeter_transformation() + sage: posets.PentagonPoset().coxeter_transformation() # optional - sage.modules [ 0 0 0 0 -1] [ 0 0 0 1 -1] [ 0 1 0 0 -1] @@ -4311,8 +4314,8 @@ def coxeter_transformation(self): TESTS:: - sage: M = posets.PentagonPoset().coxeter_transformation() - sage: M ** 8 == 1 + sage: M = posets.PentagonPoset().coxeter_transformation() # optional - sage.modules + sage: M ** 8 == 1 # optional - sage.modules True """ return self._hasse_diagram.coxeter_transformation() @@ -4331,12 +4334,12 @@ def coxeter_polynomial(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.coxeter_polynomial() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.coxeter_polynomial() # optional - sage.modules x^5 + x^4 + x + 1 - sage: p = posets.SymmetricGroupWeakOrderPoset(3) - sage: p.coxeter_polynomial() + sage: p = posets.SymmetricGroupWeakOrderPoset(3) # optional - sage.groups + sage: p.coxeter_polynomial() # optional - sage.groups sage.modules x^6 + x^5 - x^3 + x + 1 .. SEEALSO:: @@ -4371,28 +4374,28 @@ def coxeter_smith_form(self, algorithm='singular'): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.coxeter_smith_form() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.coxeter_smith_form() # optional - sage.modules sage.libs.singular [1, 1, 1, 1, x^5 + x^4 + x + 1] sage: P = posets.DiamondPoset(7) - sage: prod(P.coxeter_smith_form()) == P.coxeter_polynomial() + sage: prod(P.coxeter_smith_form()) == P.coxeter_polynomial() # optional - sage.modules sage.libs.singular True TESTS:: - sage: P = posets.PentagonPoset() - sage: P.coxeter_smith_form(algorithm='sage') + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.coxeter_smith_form(algorithm='sage') # optional - sage.modules [1, 1, 1, 1, x^5 + x^4 + x + 1] - sage: P.coxeter_smith_form(algorithm='gap') + sage: P.coxeter_smith_form(algorithm='gap') # optional - sage.libs.gap sage.modules [1, 1, 1, 1, x^5 + x^4 + x + 1] - sage: P.coxeter_smith_form(algorithm='pari') + sage: P.coxeter_smith_form(algorithm='pari') # optional - sage.libs.pari sage.modules [1, 1, 1, 1, x^5 + x^4 + x + 1] - sage: P.coxeter_smith_form(algorithm='fricas') # optional - fricas + sage: P.coxeter_smith_form(algorithm='fricas') # optional - fricas # optional - sage.modules [1, 1, 1, 1, x^5 + x^4 + x + 1] - sage: P.coxeter_smith_form(algorithm='maple') # optional - maple + sage: P.coxeter_smith_form(algorithm='maple') # optional - maple # optional - sage.modules [1, 1, 1, 1, x^5 + x^4 + x + 1] - sage: P.coxeter_smith_form(algorithm='magma') # optional - magma + sage: P.coxeter_smith_form(algorithm='magma') # optional - magma # optional - sage.modules [1, 1, 1, 1, x^5 + x^4 + x + 1] .. SEEALSO:: @@ -4468,15 +4471,15 @@ def is_meet_semilattice(self, certificate=False): EXAMPLES:: sage: P = Poset({1:[2, 3, 4], 2:[5, 6], 3:[6], 4:[6, 7]}) - sage: P.is_meet_semilattice() + sage: P.is_meet_semilattice() # optional - sage.modules True sage: Q = P.dual() - sage: Q.is_meet_semilattice() + sage: Q.is_meet_semilattice() # optional - sage.modules False - sage: V = posets.IntegerPartitions(5) - sage: V.is_meet_semilattice(certificate=True) + sage: V = posets.IntegerPartitions(5) # optional - sage.combinat + sage: V.is_meet_semilattice(certificate=True) # optional - sage.combinat sage.modules (False, ((2, 2, 1), (3, 1, 1))) .. SEEALSO:: @@ -4486,13 +4489,13 @@ def is_meet_semilattice(self, certificate=False): TESTS:: - sage: Poset().is_meet_semilattice() # Test empty lattice + sage: Poset().is_meet_semilattice() # Test empty lattice # optional - sage.modules True - sage: len([P for P in Posets(4) if P.is_meet_semilattice()]) + sage: len([P for P in Posets(4) if P.is_meet_semilattice()]) # optional - sage.modules 5 sage: P = Poset({1: [2], 3: []}) - sage: P.is_meet_semilattice(certificate=True) + sage: P.is_meet_semilattice(certificate=True) # optional - sage.modules (False, (3, 1)) """ from sage.combinat.posets.hasse_diagram import LatticeError @@ -4541,13 +4544,13 @@ def is_join_semilattice(self, certificate=False): EXAMPLES:: sage: P = Poset([[1,3,2], [4], [4,5,6], [6], [7], [7], [7], []]) - sage: P.is_join_semilattice() + sage: P.is_join_semilattice() # optional - sage.modules True sage: P = Poset({1:[3, 4], 2:[3, 4], 3:[5], 4:[5]}) - sage: P.is_join_semilattice() + sage: P.is_join_semilattice() # optional - sage.modules False - sage: P.is_join_semilattice(certificate=True) + sage: P.is_join_semilattice(certificate=True) # optional - sage.modules (False, (2, 1)) .. SEEALSO:: @@ -4557,13 +4560,13 @@ def is_join_semilattice(self, certificate=False): TESTS:: - sage: Poset().is_join_semilattice() # Test empty lattice + sage: Poset().is_join_semilattice() # Test empty lattice # optional - sage.modules True - sage: len([P for P in Posets(4) if P.is_join_semilattice()]) + sage: len([P for P in Posets(4) if P.is_join_semilattice()]) # optional - sage.modules 5 sage: X = Poset({1: [3], 2: [3], 3: [4, 5]}) - sage: X.is_join_semilattice(certificate=True) + sage: X.is_join_semilattice(certificate=True) # optional - sage.modules (False, (5, 4)) """ from sage.combinat.posets.hasse_diagram import LatticeError @@ -4631,8 +4634,8 @@ def isomorphic_subposets_iterator(self, other): EXAMPLES:: sage: D = Poset({1:[2,3], 2:[4], 3:[4]}) - sage: N5 = posets.PentagonPoset() - sage: for P in N5.isomorphic_subposets_iterator(D): + sage: N5 = posets.PentagonPoset() # optional - sage.modules + sage: for P in N5.isomorphic_subposets_iterator(D): # optional - sage.modules ....: print(P.cover_relations()) [[0, 1], [0, 2], [1, 4], [2, 4]] [[0, 1], [0, 3], [1, 4], [3, 4]] @@ -4671,15 +4674,15 @@ def isomorphic_subposets(self, other): sage: C2 = Poset({0:[1]}) sage: C3 = Poset({'a':['b'], 'b':['c']}) - sage: L = sorted(x.cover_relations() for x in C3.isomorphic_subposets(C2)) - sage: for x in L: print(x) + sage: L = sorted(x.cover_relations() for x in C3.isomorphic_subposets(C2)) # optional - sage.modules + sage: for x in L: print(x) # optional - sage.modules [['a', 'b']] [['a', 'c']] [['b', 'c']] sage: D = Poset({1:[2,3], 2:[4], 3:[4]}) - sage: N5 = posets.PentagonPoset() - sage: len(N5.isomorphic_subposets(D)) + sage: N5 = posets.PentagonPoset() # optional - sage.modules + sage: len(N5.isomorphic_subposets(D)) # optional - sage.modules 2 .. NOTE:: @@ -4716,19 +4719,19 @@ def antichains(self, element_constructor=type([])): EXAMPLES:: - sage: A = posets.PentagonPoset().antichains(); A + sage: A = posets.PentagonPoset().antichains(); A # optional - sage.modules Set of antichains of Finite lattice containing 5 elements - sage: list(A) + sage: list(A) # optional - sage.modules [[], [0], [1], [1, 2], [1, 3], [2], [3], [4]] - sage: A.cardinality() + sage: A.cardinality() # optional - sage.modules 8 - sage: A[3] + sage: A[3] # optional - sage.modules [1, 2] To get the antichains as, say, sets, one may use the ``element_constructor`` option:: - sage: list(posets.ChainPoset(3).antichains(element_constructor=set)) + sage: list(posets.ChainPoset(3).antichains(element_constructor=set)) # optional - sage.modules [set(), {0}, {1}, {2}] To get the antichains of a given size one can currently use:: @@ -4771,9 +4774,9 @@ def antichains_iterator(self): EXAMPLES:: - sage: it = posets.PentagonPoset().antichains_iterator(); it + sage: it = posets.PentagonPoset().antichains_iterator(); it # optional - sage.modules - sage: next(it), next(it) + sage: next(it), next(it) # optional - sage.modules ([], [4]) .. SEEALSO:: :meth:`antichains` @@ -4925,10 +4928,12 @@ def chains(self, element_constructor=type([]), exclude=None): EXAMPLES:: - sage: C = posets.PentagonPoset().chains(); C + sage: C = posets.PentagonPoset().chains(); C # optional - sage.modules Set of chains of Finite lattice containing 5 elements - sage: list(C) - [[], [0], [0, 1], [0, 1, 4], [0, 2], [0, 2, 3], [0, 2, 3, 4], [0, 2, 4], [0, 3], [0, 3, 4], [0, 4], [1], [1, 4], [2], [2, 3], [2, 3, 4], [2, 4], [3], [3, 4], [4]] + sage: list(C) # optional - sage.modules + [[], [0], [0, 1], [0, 1, 4], [0, 2], [0, 2, 3], [0, 2, 3, 4], [0, 2, 4], + [0, 3], [0, 3, 4], [0, 4], [1], [1, 4], [2], [2, 3], [2, 3, 4], [2, 4], + [3], [3, 4], [4]] Exclusion of elements, tuple (instead of list) as constructor:: @@ -4938,12 +4943,12 @@ def chains(self, element_constructor=type([]), exclude=None): To get the chains of a given size one can currently use:: - sage: list(C.elements_of_depth_iterator(2)) + sage: list(C.elements_of_depth_iterator(2)) # optional - sage.modules [[0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [2, 3], [2, 4], [3, 4]] Eventually the following syntax will be accepted:: - sage: C.subset(size = 2) # todo: not implemented + sage: C.subset(size = 2) # todo: not implemented # optional - sage.modules .. SEEALSO:: :meth:`maximal_chains`, :meth:`antichains` """ @@ -5107,23 +5112,23 @@ def product(self, other): sage: P = posets.ChainPoset(3) sage: Q = posets.ChainPoset(4) - sage: PQ = P.product(Q) ; PQ + sage: PQ = P.product(Q) ; PQ # optional - sage.modules Finite lattice containing 12 elements - sage: len(PQ.cover_relations()) + sage: len(PQ.cover_relations()) # optional - sage.modules 17 - sage: Q.product(P).is_isomorphic(PQ) + sage: Q.product(P).is_isomorphic(PQ) # optional - sage.modules True sage: P = posets.BooleanLattice(2) - sage: Q = P.product(P) - sage: Q.is_isomorphic(posets.BooleanLattice(4)) + sage: Q = P.product(P) # optional - sage.modules + sage: Q.is_isomorphic(posets.BooleanLattice(4)) # optional - sage.modules True One can also simply use `*`:: sage: P = posets.ChainPoset(2) sage: Q = posets.ChainPoset(3) - sage: P*Q + sage: P*Q # optional - sage.modules Finite lattice containing 6 elements .. SEEALSO:: @@ -5132,15 +5137,15 @@ def product(self, other): TESTS:: - sage: Poset({0: [1]}).product(Poset()) # Product with empty poset + sage: Poset({0: [1]}).product(Poset()) # Product with empty poset # optional - sage.modules Finite poset containing 0 elements - sage: Poset().product(Poset()) # Product of two empty poset + sage: Poset().product(Poset()) # Product of two empty poset # optional - sage.modules Finite poset containing 0 elements We check that :trac:`19113` is fixed:: - sage: L = LatticePoset({1: []}) - sage: type(L) == type(L.product(L)) + sage: L = LatticePoset({1: []}) # optional - sage.modules + sage: type(L) == type(L.product(L)) # optional - sage.modules True """ from sage.combinat.posets.lattices import LatticePoset, \ @@ -5230,9 +5235,9 @@ def factor(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: Q = P*P - sage: Q.factor() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: Q = P*P # optional - sage.modules + sage: Q.factor() # optional - sage.modules [Finite poset containing 5 elements, Finite poset containing 5 elements] @@ -5240,12 +5245,12 @@ def factor(self): sage: P2 = posets.ChainPoset(7) sage: P1.factor() [Finite lattice containing 3 elements] - sage: (P1 * P2).factor() + sage: (P1 * P2).factor() # optional - sage.modules [Finite poset containing 7 elements, Finite poset containing 3 elements] sage: P = posets.TamariLattice(4) - sage: (P*P).factor() + sage: (P*P).factor() # optional - sage.modules [Finite poset containing 14 elements, Finite poset containing 14 elements] @@ -5367,9 +5372,9 @@ def disjoint_union(self, other, labels='pairs'): sage: P.cover_relations() [[2, 3], [0, 1]] - sage: N5 = posets.PentagonPoset(); N5 + sage: N5 = posets.PentagonPoset(); N5 # optional - sage.modules Finite lattice containing 5 elements - sage: N5.disjoint_union(N5) # Union of lattices is not a lattice + sage: N5.disjoint_union(N5) # Union of lattices is not a lattice # optional - sage.modules Finite poset containing 10 elements We show how to get literally direct sum with elements untouched:: @@ -5382,9 +5387,9 @@ def disjoint_union(self, other, labels='pairs'): TESTS:: - sage: N5 = posets.PentagonPoset() + sage: N5 = posets.PentagonPoset() # optional - sage.modules sage: P0 = Poset() - sage: N5.disjoint_union(P0).is_isomorphic(N5) + sage: N5.disjoint_union(P0).is_isomorphic(N5) # optional - sage.modules True sage: P0.disjoint_union(P0) Finite poset containing 0 elements @@ -5446,11 +5451,11 @@ def ordinal_product(self, other, labels='pairs'): ... ValueError: labels must be either 'pairs' or 'integers' - sage: N5 = posets.PentagonPoset() + sage: N5 = posets.PentagonPoset() # optional - sage.modules sage: P0 = Poset() - sage: N5.ordinal_product(P0) == P0 + sage: N5.ordinal_product(P0) == P0 # optional - sage.modules True - sage: P0.ordinal_product(N5) == P0 + sage: P0.ordinal_product(N5) == P0 # optional - sage.modules True sage: P0.ordinal_product(P0) == P0 True @@ -5464,7 +5469,7 @@ def ordinal_product(self, other, labels='pairs'): sage: C3 = posets.ChainPoset(3) sage: C4 = posets.ChainPoset(4) sage: C12 = posets.ChainPoset(12) - sage: C3.ordinal_product(C4).is_isomorphic(C12) + sage: C3.ordinal_product(C4).is_isomorphic(C12) # optional - sage.modules True """ from sage.combinat.posets.lattices import LatticePoset, \ @@ -5541,15 +5546,15 @@ def ordinal_sum(self, other, labels='pairs'): sage: P = Poset({1:[2]}); P Finite poset containing 2 elements - sage: JL = JoinSemilattice({1:[2]}); JL + sage: JL = JoinSemilattice({1:[2]}); JL # optional - sage.modules Finite join-semilattice containing 2 elements - sage: L = LatticePoset({1:[2]}); L + sage: L = LatticePoset({1:[2]}); L # optional - sage.modules Finite lattice containing 2 elements - sage: P.ordinal_sum(L) + sage: P.ordinal_sum(L) # optional - sage.modules Finite poset containing 4 elements - sage: L.ordinal_sum(JL) + sage: L.ordinal_sum(JL) # optional - sage.modules Finite join-semilattice containing 4 elements - sage: L.ordinal_sum(L) + sage: L.ordinal_sum(L) # optional - sage.modules Finite lattice containing 4 elements .. SEEALSO:: @@ -5559,11 +5564,11 @@ def ordinal_sum(self, other, labels='pairs'): TESTS:: - sage: N5 = posets.PentagonPoset() + sage: N5 = posets.PentagonPoset() # optional - sage.modules sage: P0 = LatticePoset({}) - sage: N5.ordinal_sum(P0).is_isomorphic(N5) + sage: N5.ordinal_sum(P0).is_isomorphic(N5) # optional - sage.modules True - sage: P0.ordinal_sum(P0) + sage: P0.ordinal_sum(P0) # optional - sage.modules Finite lattice containing 0 elements """ from sage.combinat.posets.lattices import LatticePoset, \ @@ -5630,7 +5635,7 @@ def star_product(self, other, labels='pairs'): sage: B3 = posets.BooleanLattice(3) sage: P = B2.star_product(B3); P Finite poset containing 10 elements - sage: P.is_eulerian() + sage: P.is_eulerian() # optional - sage.libs.flint sage.modules True We can get elements as pairs or as integers:: @@ -5721,10 +5726,11 @@ def lexicographic_sum(self, P): EXAMPLES:: sage: N = Poset({1: [3, 4], 2: [4]}) - sage: P = {1: posets.PentagonPoset(), 2: N, 3: posets.ChainPoset(3), 4: posets.AntichainPoset(4)} - sage: NP = N.lexicographic_sum(P); NP + sage: P = {1: posets.PentagonPoset(), 2: N, # optional - sage.modules + ....: 3: posets.ChainPoset(3), 4: posets.AntichainPoset(4)} + sage: NP = N.lexicographic_sum(P); NP # optional - sage.modules Finite poset containing 16 elements - sage: sorted(NP.minimal_elements()) + sage: sorted(NP.minimal_elements()) # optional - sage.modules [(1, 0), (2, 1), (2, 2)] TESTS:: @@ -5807,10 +5813,10 @@ def dual(self): join-semilattice and vice versa. Also the dual of a (non-)facade poset is again (non-)facade:: - sage: V = MeetSemilattice({1: [2, 3]}, facade=False) - sage: A = V.dual(); A + sage: V = MeetSemilattice({1: [2, 3]}, facade=False) # optional - sage.modules + sage: A = V.dual(); A # optional - sage.modules Finite join-semilattice containing 3 elements - sage: A(2) < A(1) + sage: A(2) < A(1) # optional - sage.modules True .. SEEALSO:: :meth:`~sage.categories.finite_posets.FinitePosets.ParentMethods.is_self_dual` @@ -5863,12 +5869,12 @@ def with_bounds(self, labels=('bottom', 'top')): sage: Y.cover_relations() [[-1, 0], [0, 1], [0, 2]] - sage: P = posets.PentagonPoset() # A lattice - sage: P.with_bounds() + sage: P = posets.PentagonPoset() # A lattice # optional - sage.modules + sage: P.with_bounds() # optional - sage.modules Finite lattice containing 7 elements - sage: P = posets.PentagonPoset(facade=False) - sage: P.with_bounds() + sage: P = posets.PentagonPoset(facade=False) # optional - sage.modules + sage: P.with_bounds() # optional - sage.modules Finite lattice containing 7 elements .. SEEALSO:: @@ -5881,58 +5887,58 @@ def with_bounds(self, labels=('bottom', 'top')): sage: P.cover_relations() [['bottom', 'top']] - sage: L = LatticePoset({}).with_bounds(); L + sage: L = LatticePoset({}).with_bounds(); L # optional - sage.modules Finite lattice containing 2 elements - sage: L.meet_irreducibles() # Issue 21543 + sage: L.meet_irreducibles() # Issue 21543 # optional - sage.modules ['bottom'] sage: Poset().with_bounds((None, 1)) Finite poset containing 1 elements - sage: LatticePoset().with_bounds((None, 1)) + sage: LatticePoset().with_bounds((None, 1)) # optional - sage.modules Finite lattice containing 1 elements - sage: MeetSemilattice().with_bounds((None, 1)) + sage: MeetSemilattice().with_bounds((None, 1)) # optional - sage.modules Finite lattice containing 1 elements - sage: JoinSemilattice().with_bounds((None, 1)) + sage: JoinSemilattice().with_bounds((None, 1)) # optional - sage.modules Finite join-semilattice containing 1 elements sage: Poset().with_bounds((1, None)) Finite poset containing 1 elements - sage: LatticePoset().with_bounds((1, None)) + sage: LatticePoset().with_bounds((1, None)) # optional - sage.modules Finite lattice containing 1 elements - sage: MeetSemilattice().with_bounds((1, None)) + sage: MeetSemilattice().with_bounds((1, None)) # optional - sage.modules Finite meet-semilattice containing 1 elements - sage: JoinSemilattice().with_bounds((1, None)) + sage: JoinSemilattice().with_bounds((1, None)) # optional - sage.modules Finite lattice containing 1 elements sage: P = Poset({0: []}) - sage: L = LatticePoset({0: []}) - sage: ML = MeetSemilattice({0: []}) - sage: JL = JoinSemilattice({0: []}) + sage: L = LatticePoset({0: []}) # optional - sage.modules + sage: ML = MeetSemilattice({0: []}) # optional - sage.modules + sage: JL = JoinSemilattice({0: []}) # optional - sage.modules sage: P.with_bounds((None, None)) Finite poset containing 1 elements - sage: L.with_bounds((None, None)) + sage: L.with_bounds((None, None)) # optional - sage.modules Finite lattice containing 1 elements - sage: ML.with_bounds((None, None)) + sage: ML.with_bounds((None, None)) # optional - sage.modules Finite meet-semilattice containing 1 elements - sage: JL.with_bounds((None, None)) + sage: JL.with_bounds((None, None)) # optional - sage.modules Finite join-semilattice containing 1 elements sage: P.with_bounds((1, None)) Finite poset containing 2 elements - sage: L.with_bounds((1, None)) + sage: L.with_bounds((1, None)) # optional - sage.modules Finite lattice containing 2 elements - sage: ML.with_bounds((1, None)) + sage: ML.with_bounds((1, None)) # optional - sage.modules Finite meet-semilattice containing 2 elements - sage: JL.with_bounds((1, None)) + sage: JL.with_bounds((1, None)) # optional - sage.modules Finite lattice containing 2 elements sage: P.with_bounds((None, 1)) Finite poset containing 2 elements - sage: L.with_bounds((None, 1)) + sage: L.with_bounds((None, 1)) # optional - sage.modules Finite lattice containing 2 elements - sage: ML.with_bounds((None, 1)) + sage: ML.with_bounds((None, 1)) # optional - sage.modules Finite lattice containing 2 elements - sage: JL.with_bounds((None, 1)) + sage: JL.with_bounds((None, 1)) # optional - sage.modules Finite join-semilattice containing 2 elements - sage: posets.PentagonPoset().with_bounds(labels=(4, 5)) + sage: posets.PentagonPoset().with_bounds(labels=(4, 5)) # optional - sage.modules Traceback (most recent call last): ... ValueError: the poset already has element 4 @@ -5991,10 +5997,10 @@ def without_bounds(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: Q = P.without_bounds(); Q + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: Q = P.without_bounds(); Q # optional - sage.modules Finite poset containing 3 elements - sage: Q.cover_relations() + sage: Q.cover_relations() # optional - sage.modules [[2, 3]] sage: P = posets.DiamondPoset(5) @@ -6086,27 +6092,27 @@ def relabel(self, relabeling=None): Relabeling using a list:: - sage: P = posets.PentagonPoset() - sage: list(P) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: list(P) # optional - sage.modules [0, 1, 2, 3, 4] - sage: P.cover_relations() + sage: P.cover_relations() # optional - sage.modules [[0, 1], [0, 2], [1, 4], [2, 3], [3, 4]] - sage: Q = P.relabel(list('abcde')) - sage: Q.cover_relations() + sage: Q = P.relabel(list('abcde')) # optional - sage.modules + sage: Q.cover_relations() # optional - sage.modules [['a', 'b'], ['a', 'c'], ['b', 'e'], ['c', 'd'], ['d', 'e']] Default behaviour is increasing relabeling:: sage: a2 = posets.ChainPoset(2) - sage: P = a2 * a2 - sage: Q = P.relabel() - sage: Q.cover_relations() + sage: P = a2 * a2 # optional - sage.modules + sage: Q = P.relabel() # optional - sage.modules + sage: Q.cover_relations() # optional - sage.modules [[0, 1], [0, 2], [1, 3], [2, 3]] Relabeling a (semi)lattice gives a (semi)lattice:: - sage: P = JoinSemilattice({0: [1]}) - sage: P.relabel(lambda n: n+1) + sage: P = JoinSemilattice({0: [1]}) # optional - sage.modules + sage: P.relabel(lambda n: n+1) # optional - sage.modules Finite join-semilattice containing 2 elements .. NOTE:: @@ -6207,10 +6213,10 @@ def canonical_label(self, algorithm=None): sage: D = DiGraph({'a':['b','c']}) sage: P = Poset(D) - sage: ML = MeetSemilattice(D) + sage: ML = MeetSemilattice(D) # optional - sage.modules sage: P.canonical_label() Finite poset containing 3 elements - sage: ML.canonical_label() + sage: ML.canonical_label() # optional - sage.modules Finite meet-semilattice containing 3 elements .. SEEALSO:: @@ -6287,8 +6293,8 @@ def with_linear_extension(self, linear_extension): (Semi)lattice remains (semi)lattice with new linear extension:: - sage: L = LatticePoset(P) - sage: Q = L.with_linear_extension([1,3,2,6,4,12]); Q + sage: L = LatticePoset(P) # optional - sage.modules + sage: Q = L.with_linear_extension([1,3,2,6,4,12]); Q # optional - sage.modules Finite lattice containing 6 elements with distinguished linear extension .. NOTE:: @@ -6348,9 +6354,9 @@ def subposet(self, elements): A subposet of a non-facade poset is again a non-facade poset:: - sage: P = posets.PentagonPoset(facade=False) - sage: Q = P.subposet([0, 1, 2, 4]) - sage: Q(1) < Q(2) + sage: P = posets.PentagonPoset(facade=False) # optional - sage.modules + sage: Q = P.subposet([0, 1, 2, 4]) # optional - sage.modules + sage: Q(1) < Q(2) # optional - sage.modules False TESTS:: @@ -6407,8 +6413,8 @@ def random_subposet(self, p): TESTS:: - sage: P = posets.IntegerPartitions(4) - sage: P.random_subposet(1) == P + sage: P = posets.IntegerPartitions(4) # optional - sage.combinat + sage: P.random_subposet(1) == P # optional - sage.combinat True """ from sage.misc.randstate import current_randstate @@ -6899,25 +6905,25 @@ def linear_extensions_graph(self): EXAMPLES:: sage: N = Poset({1: [3, 4], 2: [4]}) - sage: G = N.linear_extensions_graph(); G + sage: G = N.linear_extensions_graph(); G # optional - sage.modules Graph on 5 vertices - sage: G.neighbors(N.linear_extension([1,2,3,4])) + sage: G.neighbors(N.linear_extension([1,2,3,4])) # optional - sage.modules [[2, 1, 3, 4], [1, 3, 2, 4], [1, 2, 4, 3]] sage: chevron = Poset({1: [2, 6], 2: [3], 4: [3, 5], 6: [5]}) - sage: G = chevron.linear_extensions_graph(); G + sage: G = chevron.linear_extensions_graph(); G # optional - sage.modules Graph on 22 vertices - sage: G.size() + sage: G.size() # optional - sage.modules 36 TESTS:: - sage: Poset().linear_extensions_graph() + sage: Poset().linear_extensions_graph() # optional - sage.modules Graph on 1 vertex sage: A4 = posets.AntichainPoset(4) - sage: G = A4.linear_extensions_graph() - sage: G.is_regular() + sage: G = A4.linear_extensions_graph() # optional - sage.modules + sage: G.is_regular() # optional - sage.modules True """ from sage.graphs.graph import Graph @@ -6946,7 +6952,7 @@ def maximal_antichains(self): sage: [sorted(anti) for anti in P.maximal_antichains()] [['a'], ['b', 'c'], ['c', 'd', 'e']] - sage: posets.PentagonPoset().maximal_antichains() + sage: posets.PentagonPoset().maximal_antichains() # optional - sage.modules [[0], [1, 2], [1, 3], [4]] .. SEEALSO:: :meth:`antichains`, :meth:`maximal_chains` @@ -7081,10 +7087,10 @@ def order_complex(self, on_ints=False): Simplicial complex with vertex set (0, 1, 2, 3, 4, 5, 6, 7) and 6 facets sage: S.f_vector() [1, 8, 19, 18, 6] - sage: S.homology() # S is contractible + sage: S.homology() # S is contractible # optional - sage.modules {0: 0, 1: 0, 2: 0, 3: 0} sage: Q = P.subposet([1,2,3,4,5,6]) - sage: Q.order_complex().homology() # a circle + sage: Q.order_complex().homology() # a circle # optional - sage.modules {0: 0, 1: Z} sage: P = Poset((divisors(15), attrcall("divides")), facade = True) @@ -7138,17 +7144,17 @@ def order_polytope(self): EXAMPLES:: sage: P = posets.AntichainPoset(3) - sage: Q = P.order_polytope();Q + sage: Q = P.order_polytope(); Q # optional - sage.geometry.polyhedron A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices - sage: P = posets.PentagonPoset() - sage: Q = P.order_polytope();Q + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: Q = P.order_polytope(); Q # optional - sage.modules sage.geometry.polyhedron A 5-dimensional polyhedron in ZZ^5 defined as the convex hull of 8 vertices sage: P = Poset([[1,2,3],[[1,2],[1,3]]]) - sage: Q = P.order_polytope() - sage: Q.contains((1,0,0)) + sage: Q = P.order_polytope() # optional - sage.geometry.polyhedron + sage: Q.contains((1,0,0)) # optional - sage.geometry.polyhedron False - sage: Q.contains((0,1,1)) + sage: Q.contains((0,1,1)) # optional - sage.geometry.polyhedron True """ from sage.geometry.polyhedron.constructor import Polyhedron @@ -7184,10 +7190,10 @@ def chain_polytope(self): EXAMPLES:: sage: P = posets.AntichainPoset(3) - sage: Q = P.chain_polytope();Q + sage: Q = P.chain_polytope();Q # optional - sage.geometry.polyhedron A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices - sage: P = posets.PentagonPoset() - sage: Q = P.chain_polytope();Q + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: Q = P.chain_polytope();Q # optional - sage.modules sage.geometry.polyhedron A 5-dimensional polyhedron in ZZ^5 defined as the convex hull of 8 vertices """ from sage.geometry.polyhedron.constructor import Polyhedron @@ -7228,8 +7234,8 @@ def zeta_polynomial(self): sage: posets.ChainPoset(3).zeta_polynomial() 1/2*q^2 + 1/2*q - sage: P = posets.PentagonPoset() - sage: P.zeta_polynomial() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.zeta_polynomial() # optional - sage.modules 1/6*q^3 + q^2 - 1/6*q sage: P = posets.DiamondPoset(5) @@ -7280,13 +7286,13 @@ def M_triangle(self): EXAMPLES:: sage: P = posets.DiamondPoset(5) - sage: P.M_triangle() + sage: P.M_triangle() # optional - sage.combinat M: x^2*y^2 - 3*x*y^2 + 3*x*y + 2*y^2 - 3*y + 1 TESTS:: - sage: P = posets.PentagonPoset() - sage: P.M_triangle() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.M_triangle() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: the poset is not graded @@ -7392,8 +7398,8 @@ def h_polynomial(self): EXAMPLES:: - sage: P = posets.AntichainPoset(3).order_ideals_lattice() - sage: P.h_polynomial() + sage: P = posets.AntichainPoset(3).order_ideals_lattice() # optional - sage.modules + sage: P.h_polynomial() # optional - sage.modules q^3 + 4*q^2 + q sage: P = posets.DiamondPoset(5) sage: P.h_polynomial() @@ -7693,13 +7699,13 @@ def order_polynomial(self): EXAMPLES:: sage: P = posets.AntichainPoset(3) - sage: P.order_polynomial() + sage: P.order_polynomial() # optional - sage.modules sage.rings.finite_rings q^3 sage: P = posets.ChainPoset(3) - sage: f = P.order_polynomial(); f + sage: f = P.order_polynomial(); f # optional - sage.modules sage.rings.finite_rings 1/6*q^3 + 1/2*q^2 + 1/3*q - sage: [f(i) for i in range(4)] + sage: [f(i) for i in range(4)] # optional - sage.modules sage.rings.finite_rings [0, 1, 4, 10] .. SEEALSO:: :meth:`order_polytope` @@ -7725,8 +7731,8 @@ def degree_polynomial(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.degree_polynomial() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.degree_polynomial() # optional - sage.modules x^2 + 3*x*y + y^2 sage: P = posets.BooleanLattice(4) @@ -7968,17 +7974,17 @@ def is_slender(self, certificate=False): sage: P.is_slender() False - sage: W = WeylGroup(['A', 2]) - sage: G = W.bruhat_poset() - sage: G.is_slender() + sage: W = WeylGroup(['A', 2]) # optional - sage.groups + sage: G = W.bruhat_poset() # optional - sage.groups + sage: G.is_slender() # optional - sage.groups True - sage: W = WeylGroup(['A', 3]) - sage: G = W.bruhat_poset() - sage: G.is_slender() + sage: W = WeylGroup(['A', 3]) # optional - sage.groups + sage: G = W.bruhat_poset() # optional - sage.groups + sage: G.is_slender() # optional - sage.groups True - sage: P = posets.IntegerPartitions(6) - sage: P.is_slender(certificate=True) + sage: P = posets.IntegerPartitions(6) # optional - sage.combinat + sage: P.is_slender(certificate=True) # optional - sage.combinat (False, ((6,), (3, 2, 1))) TESTS:: @@ -8022,7 +8028,7 @@ def is_sperner(self): EXAMPLES:: - sage: posets.SetPartitions(3).is_sperner() + sage: posets.SetPartitions(3).is_sperner() # optional - sage.combinat True sage: P = Poset({0:[3,4,5],1:[5],2:[5]}) @@ -8031,7 +8037,7 @@ def is_sperner(self): TESTS:: - sage: posets.PentagonPoset().is_sperner() + sage: posets.PentagonPoset().is_sperner() # optional - sage.modules Traceback (most recent call last): ... ValueError: the poset is not ranked @@ -8078,33 +8084,33 @@ def is_eulerian(self, k=None, certificate=False): sage: P = Poset({0: [1, 2, 3], 1: [4, 5], 2: [4, 6], 3: [5, 6], ....: 4: [7, 8], 5: [7, 8], 6: [7, 8], 7: [9], 8: [9]}) - sage: P.is_eulerian() + sage: P.is_eulerian() # optional - sage.modules sage.rings.finite_rings True sage: P = Poset({0: [1, 2, 3], 1: [4, 5, 6], 2: [4, 6], 3: [5,6], ....: 4: [7], 5:[7], 6:[7]}) - sage: P.is_eulerian() + sage: P.is_eulerian() # optional - sage.modules sage.rings.finite_rings False Canonical examples of Eulerian posets are the face lattices of convex polytopes:: - sage: P = polytopes.cube().face_lattice() - sage: P.is_eulerian() + sage: P = polytopes.cube().face_lattice() # optional - sage.geometry.polyhedron + sage: P.is_eulerian() # optional - sage.geometry.polyhedron sage.rings.finite_rings True A poset that is 3- but not 4-eulerian:: sage: P = Poset(DiGraph('MWW@_?W?@_?W??@??O@_?W?@_?W?@??O??')); P Finite poset containing 14 elements - sage: P.is_eulerian(k=3) + sage: P.is_eulerian(k=3) # optional - sage.modules True - sage: P.is_eulerian(k=4) + sage: P.is_eulerian(k=4) # optional - sage.modules False Getting an interval that is not Eulerian:: sage: P = posets.DivisorLattice(12) - sage: P.is_eulerian(certificate=True) + sage: P.is_eulerian(certificate=True) # optional - sage.modules (False, (1, 4)) TESTS:: @@ -8114,15 +8120,15 @@ def is_eulerian(self, k=None, certificate=False): ... ValueError: the poset is not bounded - sage: Poset({1: []}).is_eulerian() + sage: Poset({1: []}).is_eulerian() # optional - sage.modules True - sage: posets.PentagonPoset().is_eulerian() + sage: posets.PentagonPoset().is_eulerian() # optional - sage.modules Traceback (most recent call last): ... ValueError: the poset is not graded - sage: posets.BooleanLattice(3).is_eulerian(k=123, certificate=True) + sage: posets.BooleanLattice(3).is_eulerian(k=123, certificate=True) # optional - sage.modules (True, None) """ if k is not None: @@ -8368,17 +8374,18 @@ def greene_shape(self): EXAMPLES:: - sage: P = Poset([[3,2,1],[[3,1],[2,1]]]) - sage: P.greene_shape() + sage: P = Poset([[3,2,1], [[3,1],[2,1]]]) + sage: P.greene_shape() # optional - sage.combinat [2, 1] - sage: P = Poset([[1,2,3,4],[[1,4],[2,4],[4,3]]]) - sage: P.greene_shape() + sage: P = Poset([[1,2,3,4], [[1,4],[2,4],[4,3]]]) + sage: P.greene_shape() # optional - sage.combinat [3, 1] - sage: P = Poset([[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],[[1,4],[2,4],[4,3]]]) - sage: P.greene_shape() + sage: P = Poset([[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22], + ....: [[1,4],[2,4],[4,3]]]) + sage: P.greene_shape() # optional - sage.combinat [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] sage: P = Poset([[],[]]) - sage: P.greene_shape() + sage: P.greene_shape() # optional - sage.combinat [] AUTHOR: @@ -8461,34 +8468,42 @@ def p_partition_enumerator(self, tup, R, weights=None, check=False): EXAMPLES:: sage: P = Poset([[1,2,3,4],[[1,4],[2,4],[4,3]]]) - sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, check=True); FP + sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, check=True); FP # optional - sage.combinat 2*M[1, 1, 1, 1] + 2*M[1, 2, 1] + M[2, 1, 1] + M[3, 1] - sage: expansion = FP.expand(5) - sage: xs = expansion.parent().gens() - sage: expansion == sum([xs[a]*xs[b]*xs[c]*xs[d] for a in range(5) for b in range(5) for c in range(5) for d in range(5) if a <= b and c <= b and b < d]) + sage: expansion = FP.expand(5) # optional - sage.combinat + sage: xs = expansion.parent().gens() # optional - sage.combinat + sage: expansion == sum(xs[a]*xs[b]*xs[c]*xs[d] # optional - sage.combinat + ....: for a in range(5) for b in range(5) + ....: for c in range(5) for d in range(5) + ....: if a <= b and c <= b and b < d) True sage: P = Poset([[],[]]) - sage: FP = P.p_partition_enumerator((), QQ, check=True); FP + sage: FP = P.p_partition_enumerator((), QQ, check=True); FP # optional - sage.combinat M[] With the ``weights`` parameter:: sage: P = Poset([[1,2,3,4],[[1,4],[2,4],[4,3]]]) - sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, weights={1: 1, 2: 2, 3: 1, 4: 1}, check=True); FP + sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, # optional - sage.combinat + ....: weights={1: 1, 2: 2, 3: 1, 4: 1}, check=True); FP M[1, 2, 1, 1] + M[1, 3, 1] + M[2, 1, 1, 1] + M[2, 2, 1] + M[3, 1, 1] + M[4, 1] - sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, weights={2: 2}, check=True); FP + sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, # optional - sage.combinat + ....: weights={2: 2}, check=True); FP M[1, 2, 1, 1] + M[1, 3, 1] + M[2, 1, 1, 1] + M[2, 2, 1] + M[3, 1, 1] + M[4, 1] sage: P = Poset([['a','b','c'], [['a','b'], ['a','c']]]) - sage: FP = P.p_partition_enumerator(('b','c','a'), QQ, weights={'a': 3, 'b': 5, 'c': 7}, check=True); FP + sage: FP = P.p_partition_enumerator(('b','c','a'), QQ, # optional - sage.combinat + ....: weights={'a': 3, 'b': 5, 'c': 7}, check=True); FP M[3, 5, 7] + M[3, 7, 5] + M[3, 12] sage: P = Poset([['a','b','c'], [['a','c'], ['b','c']]]) - sage: FP = P.p_partition_enumerator(('b','c','a'), QQ, weights={'a': 3, 'b': 5, 'c': 7}, check=True); FP + sage: FP = P.p_partition_enumerator(('b','c','a'), QQ, # optional - sage.combinat + ....: weights={'a': 3, 'b': 5, 'c': 7}, check=True); FP M[3, 5, 7] + M[3, 12] + M[5, 3, 7] + M[8, 7] - sage: FP = P.p_partition_enumerator(('a','b','c'), QQ, weights={'a': 3, 'b': 5, 'c': 7}, check=True); FP + sage: FP = P.p_partition_enumerator(('a','b','c'), QQ, # optional - sage.combinat + ....: weights={'a': 3, 'b': 5, 'c': 7}, check=True); FP M[3, 5, 7] + M[3, 12] + M[5, 3, 7] + M[5, 10] + M[8, 7] + M[15] """ if check: @@ -8570,18 +8585,18 @@ def completion_by_cuts(self): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P.completion_by_cuts().is_isomorphic(P) + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P.completion_by_cuts().is_isomorphic(P) # optional - sage.modules True sage: Y = Poset({1: [2], 2: [3, 4]}) - sage: trafficsign = LatticePoset({1: [2], 2: [3, 4], 3: [5], 4: [5]}) - sage: L = Y.completion_by_cuts() - sage: L.is_isomorphic(trafficsign) + sage: trafficsign = LatticePoset({1: [2], 2: [3, 4], 3: [5], 4: [5]}) # optional - sage.modules + sage: L = Y.completion_by_cuts() # optional - sage.modules + sage: L.is_isomorphic(trafficsign) # optional - sage.modules True sage: P = posets.SymmetricGroupBruhatOrderPoset(3) - sage: Q = P.completion_by_cuts(); Q + sage: Q = P.completion_by_cuts(); Q # optional - sage.modules Finite lattice containing 7 elements .. SEEALSO:: @@ -8610,7 +8625,7 @@ def incidence_algebra(self, R, prefix='I'): EXAMPLES:: sage: P = posets.BooleanLattice(4) - sage: P.incidence_algebra(QQ) + sage: P.incidence_algebra(QQ) # optional - sage.modules Incidence algebra of Finite lattice containing 16 elements over Rational Field """ @@ -8834,8 +8849,8 @@ def _macaulay2_init_(self, macaulay2=None): EXAMPLES:: - sage: P = posets.PentagonPoset() - sage: P._macaulay2_init_() + sage: P = posets.PentagonPoset() # optional - sage.modules + sage: P._macaulay2_init_() # optional - sage.modules 'needsPackage "Posets";poset({0,1,2,3,4},{{0,1},{0,2},{1,4},{2,3},{3,4}})' sage: P = Poset({1:[2],2:[]}) @@ -8904,9 +8919,9 @@ def __contains__(self, P): """ EXAMPLES:: - sage: posets.PentagonPoset() in Posets(5) + sage: posets.PentagonPoset() in Posets(5) # optional - sage.modules True - sage: posets.PentagonPoset() in Posets(3) + sage: posets.PentagonPoset() in Posets(3) # optional - sage.modules False sage: 1 in Posets(3) False diff --git a/src/sage/combinat/quickref.py b/src/sage/combinat/quickref.py index ea2aba8915a..351563cec6c 100644 --- a/src/sage/combinat/quickref.py +++ b/src/sage/combinat/quickref.py @@ -46,7 +46,7 @@ sage: points = random_matrix(ZZ, 6, 3, x=7).rows() sage: L = LatticePolytope(points) - sage: L.npoints(); L.plot3d() # random + sage: L.npoints(); L.plot3d() # random # optional - sage.plot :ref:`Root systems, Coxeter and Weyl groups `:: diff --git a/src/sage/combinat/rooted_tree.py b/src/sage/combinat/rooted_tree.py index abb96594d2a..e8a44b1b163 100644 --- a/src/sage/combinat/rooted_tree.py +++ b/src/sage/combinat/rooted_tree.py @@ -625,14 +625,14 @@ class RootedTrees_size(RootedTrees): TESTS:: sage: from sage.combinat.rooted_tree import RootedTrees_size - sage: for i in range(1, 6): TestSuite(RootedTrees_size(i)).run() + sage: for i in range(1, 6): TestSuite(RootedTrees_size(i)).run() # optional - sage.combinat """ def __init__(self, n): """ TESTS:: - sage: for i in range(1, 6): + sage: for i in range(1, 6): # optional - sage.combinat ....: TestSuite(RootedTrees(i)).run() """ super().__init__(category=FiniteEnumeratedSets()) @@ -663,7 +663,7 @@ def _an_element_(self): """ TESTS:: - sage: RootedTrees(4).an_element() # indirect doctest + sage: RootedTrees(4).an_element() # indirect doctest # optional - sage.combinat [[[[]]]] """ return self.first() @@ -681,11 +681,11 @@ def __iter__(self): sage: from sage.combinat.rooted_tree import * sage: RootedTrees(1).list() [[]] - sage: RootedTrees(2).list() + sage: RootedTrees(2).list() # optional - sage.combinat [[[]]] - sage: RootedTrees(3).list() + sage: RootedTrees(3).list() # optional - sage.combinat [[[[]]], [[], []]] - sage: RootedTrees(4).list() + sage: RootedTrees(4).list() # optional - sage.combinat [[[[[]]]], [[[], []]], [[], [[]]], [[], [], []]] """ if self._n == 1: @@ -757,7 +757,7 @@ def element_class(self): sage: S = RootedTrees(3) sage: S.element_class - sage: S.first().__class__ == RootedTrees().first().__class__ + sage: S.first().__class__ == RootedTrees().first().__class__ # optional - sage.combinat True """ return self._parent_for.element_class diff --git a/src/sage/combinat/skew_partition.py b/src/sage/combinat/skew_partition.py index dd66961a807..a16e0ceaf75 100644 --- a/src/sage/combinat/skew_partition.py +++ b/src/sage/combinat/skew_partition.py @@ -1068,18 +1068,18 @@ def to_dag(self, format="string"): EXAMPLES:: - sage: dag = SkewPartition([[3, 3, 1], [1, 1]]).to_dag() - sage: dag.edges(sort=True) + sage: dag = SkewPartition([[3, 3, 1], [1, 1]]).to_dag() # optional - sage.graphs + sage: dag.edges(sort=True) # optional - sage.graphs [('0,1', '0,2', None), ('0,1', '1,1', None), ('0,2', '1,2', None), ('1,1', '1,2', None)] - sage: dag.vertices(sort=True) + sage: dag.vertices(sort=True) # optional - sage.graphs ['0,1', '0,2', '1,1', '1,2', '2,0'] - sage: dag = SkewPartition([[3, 2, 1], [1, 1]]).to_dag(format="tuple") - sage: dag.edges(sort=True) + sage: dag = SkewPartition([[3, 2, 1], [1, 1]]).to_dag(format="tuple") # optional - sage.graphs + sage: dag.edges(sort=True) # optional - sage.graphs [((0, 1), (0, 2), None), ((0, 1), (1, 1), None)] - sage: dag.vertices(sort=True) + sage: dag.vertices(sort=True) # optional - sage.graphs [(0, 1), (0, 2), (1, 1), (2, 0)] """ outer = list(self.outer()) diff --git a/src/sage/combinat/skew_tableau.py b/src/sage/combinat/skew_tableau.py index e7269bc7ce7..fdb5f030790 100644 --- a/src/sage/combinat/skew_tableau.py +++ b/src/sage/combinat/skew_tableau.py @@ -1950,7 +1950,7 @@ class StandardSkewTableaux(SkewTableaux): sage: S = StandardSkewTableaux(2); S Standard skew tableaux of size 2 - sage: S.cardinality() + sage: S.cardinality() # optional - sage.modules 4 :: @@ -2015,7 +2015,7 @@ def __init__(self): EXAMPLES:: sage: s = StandardSkewTableaux() - sage: TestSuite(s).run() + sage: TestSuite(s).run() # optional - sage.graphs """ StandardSkewTableaux.__init__(self, category=InfiniteEnumeratedSets()) @@ -2037,7 +2037,7 @@ def __iter__(self): EXAMPLES:: sage: it = StandardSkewTableaux().__iter__() - sage: [next(it) for x in range(10)] + sage: [next(it) for x in range(10)] # optional - sage.graphs [[], [[1]], [[1, 2]], [[1], [2]], [[None, 2], [1]], [[None, 1], [2]], @@ -2060,7 +2060,7 @@ def __init__(self, n): EXAMPLES:: sage: S = StandardSkewTableaux(3) - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.graphs """ self.n = n StandardSkewTableaux.__init__(self, category=FiniteEnumeratedSets()) @@ -2078,13 +2078,13 @@ def cardinality(self): """ EXAMPLES:: - sage: StandardSkewTableaux(1).cardinality() + sage: StandardSkewTableaux(1).cardinality() # optional - sage.modules 1 - sage: StandardSkewTableaux(2).cardinality() + sage: StandardSkewTableaux(2).cardinality() # optional - sage.modules 4 - sage: StandardSkewTableaux(3).cardinality() + sage: StandardSkewTableaux(3).cardinality() # optional - sage.modules 24 - sage: StandardSkewTableaux(4).cardinality() + sage: StandardSkewTableaux(4).cardinality() # optional - sage.modules 194 """ count = 0 @@ -2101,10 +2101,10 @@ def __iter__(self): EXAMPLES:: - sage: StandardSkewTableaux(2).list() + sage: StandardSkewTableaux(2).list() # optional - sage.graphs [[[1, 2]], [[1], [2]], [[None, 2], [1]], [[None, 1], [2]]] - sage: StandardSkewTableaux(3).list() + sage: StandardSkewTableaux(3).list() # optional - sage.graphs [[[1, 2, 3]], [[1, 2], [3]], [[1, 3], [2]], [[None, 2, 3], [1]], [[None, 1, 2], [3]], [[None, 1, 3], [2]], @@ -2149,7 +2149,7 @@ def __init__(self, skp): TESTS:: sage: S = StandardSkewTableaux([[3, 2, 1], [1, 1]]) - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.graphs sage.modules """ self.skp = skp StandardSkewTableaux.__init__(self, category=FiniteEnumeratedSets()) @@ -2173,7 +2173,7 @@ def cardinality(self): EXAMPLES:: - sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).cardinality() + sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).cardinality() # optional - sage.modules 8 """ outer, inner = self.skp @@ -2200,7 +2200,7 @@ def __iter__(self): EXAMPLES:: - sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).list() + sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).list() # optional - sage.graphs [[[None, 2, 3], [None, 4], [1]], [[None, 1, 2], [None, 3], [4]], [[None, 1, 2], [None, 4], [3]], diff --git a/src/sage/combinat/species/generating_series.py b/src/sage/combinat/species/generating_series.py index 9d63ce27691..e7f7c8ee978 100644 --- a/src/sage/combinat/species/generating_series.py +++ b/src/sage/combinat/species/generating_series.py @@ -16,18 +16,18 @@ TESTS:: sage: from sage.combinat.species.generating_series import CycleIndexSeriesRing - sage: p = SymmetricFunctions(QQ).power() + sage: p = SymmetricFunctions(QQ).power() # optional - sage.modules sage: CIS = CycleIndexSeriesRing(QQ) - sage: geo1 = CIS(lambda i: p([1])^i) - sage: geo2 = CIS(lambda i: p([2])^(i // 2) if is_even(i) else 0) - sage: s = geo1 * geo2 - sage: s[0] + sage: geo1 = CIS(lambda i: p([1])^i) # optional - sage.modules + sage: geo2 = CIS(lambda i: p([2])^(i // 2) if is_even(i) else 0) # optional - sage.modules + sage: s = geo1 * geo2 # optional - sage.modules + sage: s[0] # optional - sage.modules p[] - sage: s[1] + sage: s[1] # optional - sage.modules p[1] - sage: s[2] + sage: s[2] # optional - sage.modules p[1, 1] + p[2] - sage: s[3] + sage: s[3] # optional - sage.modules p[1, 1, 1] + p[2, 1] REFERENCES: @@ -292,14 +292,14 @@ def count(self, t): EXAMPLES:: sage: from sage.combinat.species.generating_series import CycleIndexSeriesRing - sage: p = SymmetricFunctions(QQ).power() + sage: p = SymmetricFunctions(QQ).power() # optional - sage.modules sage: CIS = CycleIndexSeriesRing(QQ) - sage: f = CIS([0, p([1]), 2*p([1,1]), 3*p([2,1])]) - sage: f.count([1]) + sage: f = CIS([0, p([1]), 2*p([1,1]), 3*p([2,1])]) # optional - sage.modules + sage: f.count([1]) # optional - sage.modules 1 - sage: f.count([1,1]) + sage: f.count([1,1]) # optional - sage.modules 4 - sage: f.count([2,1]) + sage: f.count([2,1]) # optional - sage.modules 6 """ t = Partition(t) @@ -312,14 +312,14 @@ def coefficient_cycle_type(self, t): EXAMPLES:: sage: from sage.combinat.species.generating_series import CycleIndexSeriesRing - sage: p = SymmetricFunctions(QQ).power() + sage: p = SymmetricFunctions(QQ).power() # optional - sage.modules sage: CIS = CycleIndexSeriesRing(QQ) - sage: f = CIS([0, p([1]), 2*p([1,1]),3*p([2,1])]) - sage: f.coefficient_cycle_type([1]) + sage: f = CIS([0, p([1]), 2*p([1,1]),3*p([2,1])]) # optional - sage.modules + sage: f.coefficient_cycle_type([1]) # optional - sage.modules 1 - sage: f.coefficient_cycle_type([1,1]) + sage: f.coefficient_cycle_type([1,1]) # optional - sage.modules 2 - sage: f.coefficient_cycle_type([2,1]) + sage: f.coefficient_cycle_type([2,1]) # optional - sage.modules 3 """ t = Partition(t) @@ -535,10 +535,10 @@ class CycleIndexSeriesRing(LazySymmetricFunctions): EXAMPLES:: sage: from sage.combinat.species.generating_series import CycleIndexSeriesRing - sage: R = CycleIndexSeriesRing(QQ); R + sage: R = CycleIndexSeriesRing(QQ); R # optional - sage.modules Cycle Index Series Ring over Rational Field - sage: p = SymmetricFunctions(QQ).p() - sage: R(lambda n: p[n]) + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: R(lambda n: p[n]) # optional - sage.modules p[] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + O^7 TESTS: @@ -558,8 +558,8 @@ def __init__(self, base_ring, sparse=True): sage: from sage.combinat.species.generating_series import CycleIndexSeriesRing sage: CycleIndexSeriesRing.options.halting_precision(12) - sage: R = CycleIndexSeriesRing(QQ) - sage: TestSuite(R).run() + sage: R = CycleIndexSeriesRing(QQ) # optional - sage.modules + sage: TestSuite(R).run() # optional - sage.modules sage: CycleIndexSeriesRing.options._reset() # reset options """ @@ -573,7 +573,7 @@ def _repr_(self): EXAMPLES:: sage: from sage.combinat.species.generating_series import CycleIndexSeriesRing - sage: CycleIndexSeriesRing(QQ) + sage: CycleIndexSeriesRing(QQ) # optional - sage.modules Cycle Index Series Ring over Rational Field """ return "Cycle Index Series Ring over %s" % self.base_ring() @@ -588,7 +588,7 @@ def _exp_term(n, R=QQ): EXAMPLES:: sage: from sage.combinat.species.generating_series import _exp_term - sage: [_exp_term(i) for i in range(4)] + sage: [_exp_term(i) for i in range(4)] # optional - sage.modules [p[], p[1], 1/2*p[1, 1] + 1/2*p[2], 1/6*p[1, 1, 1] + 1/2*p[2, 1] + 1/3*p[3]] """ p = SymmetricFunctions(R).power() @@ -610,7 +610,7 @@ def ExponentialCycleIndexSeries(R=QQ): EXAMPLES:: sage: from sage.combinat.species.generating_series import ExponentialCycleIndexSeries - sage: ExponentialCycleIndexSeries()[:5] + sage: ExponentialCycleIndexSeries()[:5] # optional - sage.modules [p[], p[1], 1/2*p[1, 1] + 1/2*p[2], 1/6*p[1, 1, 1] + 1/2*p[2, 1] + 1/3*p[3], 1/24*p[1, 1, 1, 1] + 1/4*p[2, 1, 1] + 1/8*p[2, 2] + 1/3*p[3, 1] + 1/4*p[4]] @@ -629,7 +629,7 @@ def _cl_term(n, R=QQ): EXAMPLES:: sage: from sage.combinat.species.generating_series import _cl_term - sage: [_cl_term(i) for i in range(4)] + sage: [_cl_term(i) for i in range(4)] # optional - sage.modules [0, p[1], -1/2*p[1, 1] - 1/2*p[2], 1/3*p[1, 1, 1] - 1/3*p[3]] """ n = Integer(n) # check that n is an integer @@ -661,7 +661,7 @@ def LogarithmCycleIndexSeries(R=QQ): its cycle index has negative coefficients:: sage: from sage.combinat.species.generating_series import LogarithmCycleIndexSeries - sage: LogarithmCycleIndexSeries()[0:4] + sage: LogarithmCycleIndexSeries()[0:4] # optional - sage.modules [0, p[1], -1/2*p[1, 1] - 1/2*p[2], 1/3*p[1, 1, 1] - 1/3*p[3]] Its defining property is that `\Omega \circ E^{+} = E^{+} \circ \Omega = X` @@ -669,7 +669,7 @@ def LogarithmCycleIndexSeries(R=QQ): multiplicative identity `X`):: sage: Eplus = sage.combinat.species.set_species.SetSpecies(min=1).cycle_index_series() - sage: LogarithmCycleIndexSeries()(Eplus)[0:4] + sage: LogarithmCycleIndexSeries()(Eplus)[0:4] # optional - sage.modules [0, p[1], 0, 0] """ CIS = CycleIndexSeriesRing(R) diff --git a/src/sage/combinat/subsets_hereditary.py b/src/sage/combinat/subsets_hereditary.py index 68fe53e98ea..3ff251a2394 100644 --- a/src/sage/combinat/subsets_hereditary.py +++ b/src/sage/combinat/subsets_hereditary.py @@ -73,22 +73,22 @@ def subsets_with_hereditary_property(f,X,max_obstruction_size=None,ncpus=1): number of calls to `f` from 91 to 56:: sage: num_calls = 0 - sage: g = graphs.PetersenGraph() + sage: g = graphs.PetersenGraph() # optional - sage.graphs sage: def is_independent_set(S): ....: global num_calls ....: num_calls += 1 ....: return g.subgraph(S).size() == 0 - sage: l1 = list(subsets_with_hereditary_property(is_independent_set, + sage: l1 = list(subsets_with_hereditary_property(is_independent_set, # optional - sage.graphs ....: g.vertices(sort=False))) - sage: num_calls + sage: num_calls # optional - sage.graphs 91 sage: num_calls = 0 - sage: l2 = list(subsets_with_hereditary_property(is_independent_set, + sage: l2 = list(subsets_with_hereditary_property(is_independent_set, # optional - sage.graphs ....: g.vertices(sort=False), ....: max_obstruction_size=2)) - sage: num_calls + sage: num_calls # optional - sage.graphs 56 - sage: l1 == l2 + sage: l1 == l2 # optional - sage.graphs True TESTS:: diff --git a/src/sage/combinat/subword_complex.py b/src/sage/combinat/subword_complex.py index b5455260aaa..b7489bdf754 100644 --- a/src/sage/combinat/subword_complex.py +++ b/src/sage/combinat/subword_complex.py @@ -83,13 +83,13 @@ sage: W = CoxeterGroup(['A',3]); I = list(W.index_set()) sage: Q = I + W.w0.coxeter_sorting_word(I) sage: S = SubwordComplex(Q,W.w0) - sage: S.brick_polytope() + sage: S.brick_polytope() # optional - sage.geometry.polyhedron A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 14 vertices sage: W = CoxeterGroup(['H',3]); I = list(W.index_set()) sage: Q = I + W.w0.coxeter_sorting_word(I) sage: S = SubwordComplex(Q,W.w0) - sage: S.brick_polytope() + sage: S.brick_polytope() # optional - sage.geometry.polyhedron doctest:...: RuntimeWarning: the polytope is built with rational vertices A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 32 vertices @@ -754,20 +754,20 @@ def plot(self, list_colors=None, labels=[], thickness=3, fontsize=14, sage: W = ReflectionGroup(['A',2]) # optional - gap3 sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F.plot() # optional - gap3 + sage: F = SC([1,2]); F.plot() # optional - gap3 sage.plot Graphics object consisting of 26 graphics primitives sage: W = CoxeterGroup(['A',2]) sage: w = W.from_reduced_word([1,2,1]) sage: SC = SubwordComplex([1,2,1,2,1],w) - sage: F = SC([1,2]); F.plot() + sage: F = SC([1,2]); F.plot() # optional - sage.plot Graphics object consisting of 26 graphics primitives sage: W = ReflectionGroup(['B',3]) # optional - gap3 sage: c = W.from_reduced_word([1,2,3]) # optional - gap3 sage: Q = c.reduced_word()*2 + W.w0.coxeter_sorting_word(c) # optional - gap3 sage: SC = SubwordComplex(Q, W.w0) # optional - gap3 - sage: F = SC[15]; F.plot() # optional - gap3 + sage: F = SC[15]; F.plot() # optional - gap3 sage.plot Graphics object consisting of 53 graphics primitives TESTS:: @@ -776,7 +776,7 @@ def plot(self, list_colors=None, labels=[], thickness=3, fontsize=14, sage: c = W.from_reduced_word([1,2,3,4]) # optional - gap3 sage: Q = c.reduced_word() + W.w0.coxeter_sorting_word(c) # optional - gap3 sage: SC = SubwordComplex(Q, W.w0) # optional - gap3 - sage: F = SC[1]; F.plot() # optional - gap3 + sage: F = SC[1]; F.plot() # optional - gap3 sage.plot Traceback (most recent call last): ... ValueError: plotting is currently only implemented for irreducibles types A, B, and C. @@ -785,7 +785,7 @@ def plot(self, list_colors=None, labels=[], thickness=3, fontsize=14, sage: c = W.from_reduced_word([1,2,3,4]) sage: Q = c.reduced_word() + W.w0.coxeter_sorting_word(c) sage: SC = SubwordComplex(Q, W.w0) - sage: F = SC[1]; F.plot() + sage: F = SC[1]; F.plot() # optional - sage.plot Traceback (most recent call last): ... ValueError: plotting is currently only implemented for irreducibles types A, B, and C. diff --git a/src/sage/combinat/symmetric_group_algebra.py b/src/sage/combinat/symmetric_group_algebra.py index ef328aff704..3884747f825 100644 --- a/src/sage/combinat/symmetric_group_algebra.py +++ b/src/sage/combinat/symmetric_group_algebra.py @@ -1,3 +1,4 @@ +# optional - sage.combinat sage.modules sage.groups r""" Symmetric Group Algebra """ diff --git a/src/sage/combinat/symmetric_group_representations.py b/src/sage/combinat/symmetric_group_representations.py index 23f310b89ea..5799fa03bcc 100644 --- a/src/sage/combinat/symmetric_group_representations.py +++ b/src/sage/combinat/symmetric_group_representations.py @@ -815,7 +815,7 @@ def _repr_(self): EXAMPLES:: sage: from sage.combinat.symmetric_group_representations import YoungRepresentations_Orthogonal - sage: YoungRepresentations_Orthogonal(3) + sage: YoungRepresentations_Orthogonal(3) # optional - sage.symbolic Orthogonal representations of the symmetric group of order 3! over Symbolic Ring """ return "Orthogonal representations of the symmetric group of order %s! over %s" % (self._n, self._ring) diff --git a/src/sage/combinat/tableau.py b/src/sage/combinat/tableau.py index 719f2260608..ed500a32c3c 100644 --- a/src/sage/combinat/tableau.py +++ b/src/sage/combinat/tableau.py @@ -1129,19 +1129,19 @@ def to_sign_matrix(self, max_entry=None): EXAMPLES:: sage: t = SemistandardTableau([[1,1,1,2,4],[3,3,4],[4,5],[6,6]]) - sage: t.to_sign_matrix(6) + sage: t.to_sign_matrix(6) # optional - sage.modules [ 0 0 0 1 0 0] [ 0 1 0 -1 0 0] [ 1 -1 0 1 0 0] [ 0 0 1 -1 1 1] [ 0 0 0 1 -1 0] sage: t = Tableau([[1,2,4],[3,5]]) - sage: t.to_sign_matrix(7) + sage: t.to_sign_matrix(7) # optional - sage.modules [ 0 0 0 1 0 0 0] [ 0 1 0 -1 1 0 0] [ 1 -1 1 0 -1 0 0] sage: t = Tableau([(4,5,4,3),(2,1,3)]) - sage: t.to_sign_matrix(5) + sage: t.to_sign_matrix(5) # optional - sage.modules [ 0 0 1 0 0] [ 0 0 0 1 0] [ 1 0 -1 -1 1] @@ -2795,26 +2795,26 @@ def row_stabilizer(self): EXAMPLES:: - sage: rs = Tableau([[1,2,3],[4,5]]).row_stabilizer() - sage: rs.order() == factorial(3)*factorial(2) + sage: rs = Tableau([[1,2,3],[4,5]]).row_stabilizer() # optional - sage.groups + sage: rs.order() == factorial(3)*factorial(2) # optional - sage.groups True - sage: PermutationGroupElement([(1,3,2),(4,5)]) in rs + sage: PermutationGroupElement([(1,3,2),(4,5)]) in rs # optional - sage.groups True - sage: PermutationGroupElement([(1,4)]) in rs + sage: PermutationGroupElement([(1,4)]) in rs # optional - sage.groups False - sage: rs = Tableau([[1, 2],[3]]).row_stabilizer() - sage: PermutationGroupElement([(1,2),(3,)]) in rs + sage: rs = Tableau([[1, 2],[3]]).row_stabilizer() # optional - sage.groups + sage: PermutationGroupElement([(1,2),(3,)]) in rs # optional - sage.groups True - sage: rs.one().domain() + sage: rs.one().domain() # optional - sage.groups [1, 2, 3] - sage: rs = Tableau([[1],[2],[3]]).row_stabilizer() - sage: rs.order() + sage: rs = Tableau([[1],[2],[3]]).row_stabilizer() # optional - sage.groups + sage: rs.order() # optional - sage.groups 1 - sage: rs = Tableau([[2,4,5],[1,3]]).row_stabilizer() - sage: rs.order() + sage: rs = Tableau([[2,4,5],[1,3]]).row_stabilizer() # optional - sage.groups + sage: rs.order() # optional - sage.groups 12 - sage: rs = Tableau([]).row_stabilizer() - sage: rs.order() + sage: rs = Tableau([]).row_stabilizer() # optional - sage.groups + sage: rs.order() # optional - sage.groups 1 """ # Ensure that the permutations involve all elements of the @@ -2836,12 +2836,12 @@ def column_stabilizer(self): EXAMPLES:: - sage: cs = Tableau([[1,2,3],[4,5]]).column_stabilizer() - sage: cs.order() == factorial(2)*factorial(2) + sage: cs = Tableau([[1,2,3],[4,5]]).column_stabilizer() # optional - sage.groups + sage: cs.order() == factorial(2)*factorial(2) # optional - sage.groups True - sage: PermutationGroupElement([(1,3,2),(4,5)]) in cs + sage: PermutationGroupElement([(1,3,2),(4,5)]) in cs # optional - sage.groups False - sage: PermutationGroupElement([(1,4)]) in cs + sage: PermutationGroupElement([(1,4)]) in cs # optional - sage.groups True """ return self.conjugate().row_stabilizer() @@ -2898,7 +2898,7 @@ def last_letter_lequal(self, tab2): sage: st = StandardTableaux([3,2]) sage: f = lambda b: 1 if b else 0 - sage: matrix( [ [ f(t1.last_letter_lequal(t2)) for t2 in st] for t1 in st] ) + sage: matrix([[f(t1.last_letter_lequal(t2)) for t2 in st] for t1 in st]) # optional - sage.modules [1 1 1 1 1] [0 1 1 1 1] [0 0 1 1 1] @@ -3659,9 +3659,9 @@ def _segments(self): sage: sorted(t._segments().items()) [((0, 2), 2), ((0, 3), 3), ((0, 5), 4), ((1, 3), 1), ((1, 5), 2), ((2, 4), 1)] - sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) - sage: t = B[31].to_tableau() - sage: sorted(t._segments().items()) + sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # optional - sage.modules + sage: t = B[31].to_tableau() # optional - sage.modules + sage: sorted(t._segments().items()) # optional - sage.modules [((0, 5), 3), ((1, 4), 2), ((2, 4), 1)] """ segments = {} @@ -3691,9 +3691,9 @@ def seg(self): sage: t.seg() 6 - sage: B = crystals.Tableaux("A4",shape=[4,3,2,1]) - sage: t = B[31].to_tableau() - sage: t.seg() + sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # optional - sage.modules + sage: t = B[31].to_tableau() # optional - sage.modules + sage: t.seg() # optional - sage.modules 3 """ return len(self._segments()) @@ -3719,9 +3719,9 @@ def flush(self): sage: t.flush() 3 - sage: B = crystals.Tableaux("A4",shape=[4,3,2,1]) - sage: t = B[32].to_tableau() - sage: t.flush() + sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # optional - sage.modules + sage: t = B[32].to_tableau() # optional - sage.modules + sage: t.flush() # optional - sage.modules 4 """ for i in range(len(self)-1): @@ -3844,11 +3844,11 @@ def residue_sequence(self, e, multicharge=(0,)): EXAMPLES:: - sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(2) + sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(2) # optional - sage.groups 2-residue sequence (0,1,1,0) with multicharge (0) - sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(3) + sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(3) # optional - sage.groups 3-residue sequence (0,1,2,0) with multicharge (0) - sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(4) + sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(4) # optional - sage.groups 4-residue sequence (0,1,3,0) with multicharge (0) """ res = [0] * self.size() @@ -3882,9 +3882,9 @@ def degree(self, e, multicharge=(0,)): EXAMPLES:: - sage: StandardTableau([[1,2,5],[3,4]]).degree(3) + sage: StandardTableau([[1,2,5],[3,4]]).degree(3) # optional - sage.groups 0 - sage: StandardTableau([[1,2,5],[3,4]]).degree(4) + sage: StandardTableau([[1,2,5],[3,4]]).degree(4) # optional - sage.groups 1 """ n = self.size() @@ -3927,11 +3927,11 @@ def codegree(self, e, multicharge=(0,)): EXAMPLES:: - sage: StandardTableau([[1,3,5],[2,4]]).codegree(3) + sage: StandardTableau([[1,3,5],[2,4]]).codegree(3) # optional - sage.groups 0 - sage: StandardTableau([[1,2,5],[3,4]]).codegree(3) + sage: StandardTableau([[1,2,5],[3,4]]).codegree(3) # optional - sage.groups 1 - sage: StandardTableau([[1,2,5],[3,4]]).codegree(4) + sage: StandardTableau([[1,2,5],[3,4]]).codegree(4) # optional - sage.groups 0 """ if not self: # the trivial case @@ -6464,9 +6464,9 @@ def random_element(self): EXAMPLES:: - sage: SemistandardTableaux(6).random_element() # random + sage: SemistandardTableaux(6).random_element() # random # optional - sage.modules [[1, 1, 2], [3, 5, 5]] - sage: SemistandardTableaux(6, max_entry=7).random_element() # random + sage: SemistandardTableaux(6, max_entry=7).random_element() # random # optional - sage.modules [[2, 4, 4, 6, 6, 6]] """ from sage.rings.integer_ring import ZZ @@ -7015,13 +7015,13 @@ class RowStandardTableaux(Tableaux): sage: ST = RowStandardTableaux(3); ST Row standard tableaux of size 3 - sage: ST.first() + sage: ST.first() # optional - sage.graphs [[1, 2, 3]] - sage: ST.last() + sage: ST.last() # optional - sage.graphs [[3], [1], [2]] - sage: ST.cardinality() + sage: ST.cardinality() # optional - sage.graphs 10 - sage: ST.list() + sage: ST.list() # optional - sage.graphs [[[1, 2, 3]], [[2, 3], [1]], [[1, 2], [3]], @@ -7048,13 +7048,13 @@ class RowStandardTableaux(Tableaux): [] sage: ST = RowStandardTableaux([2,2]); ST Row standard tableaux of shape [2, 2] - sage: ST.first() + sage: ST.first() # optional - sage.graphs [[2, 4], [1, 3]] - sage: ST.last() + sage: ST.last() # optional - sage.graphs [[2, 3], [1, 4]] - sage: ST.cardinality() + sage: ST.cardinality() # optional - sage.graphs 6 - sage: ST.list() + sage: ST.list() # optional - sage.graphs [[[2, 4], [1, 3]], [[3, 4], [1, 2]], [[1, 4], [2, 3]], @@ -7189,11 +7189,11 @@ class RowStandardTableaux_size(RowStandardTableaux, DisjointUnionEnumeratedSets) EXAMPLES:: - sage: [ t for t in RowStandardTableaux(1) ] + sage: [t for t in RowStandardTableaux(1)] # optional - sage.graphs [[[1]]] - sage: [ t for t in RowStandardTableaux(2) ] + sage: [t for t in RowStandardTableaux(2)] # optional - sage.graphs [[[1, 2]], [[2], [1]], [[1], [2]]] - sage: list(RowStandardTableaux(3)) + sage: list(RowStandardTableaux(3)) # optional - sage.graphs [[[1, 2, 3]], [[2, 3], [1]], [[1, 2], [3]], @@ -7213,7 +7213,7 @@ class RowStandardTableaux_size(RowStandardTableaux, DisjointUnionEnumeratedSets) 10 sage: ns = [1,2,3,4,5,6] sage: sts = [RowStandardTableaux(n) for n in ns] - sage: all(st.cardinality() == len(st.list()) for st in sts) + sage: all(st.cardinality() == len(st.list()) for st in sts) # optional - sage.graphs True sage: RowStandardTableaux(40).cardinality() # not tested, too long 2063837185739279909309355007659204891024472174278 @@ -7230,8 +7230,8 @@ def __init__(self, n): TESTS:: - sage: TestSuite( RowStandardTableaux(0) ).run() - sage: TestSuite( RowStandardTableaux(3) ).run() + sage: TestSuite(RowStandardTableaux(0)).run() # optional - sage.graphs + sage: TestSuite(RowStandardTableaux(3)).run() # optional - sage.graphs """ RowStandardTableaux.__init__(self) from sage.combinat.partition import Partitions_n @@ -7254,10 +7254,10 @@ def __contains__(self, x): TESTS:: sage: ST3 = RowStandardTableaux(3) - sage: all(st in ST3 for st in ST3) + sage: all(st in ST3 for st in ST3) # optional - sage.graphs True sage: ST4 = RowStandardTableaux(4) - sage: [x for x in ST4 if x in ST3] + sage: [x for x in ST4 if x in ST3] # optional - sage.graphs [] Check that :trac:`14145` is fixed:: @@ -7300,7 +7300,7 @@ def __init__(self, p): TESTS:: - sage: TestSuite( RowStandardTableaux([2,1,1]) ).run() + sage: TestSuite( RowStandardTableaux([2,1,1]) ).run() # optional - sage.graphs """ super().__init__(category=FiniteEnumeratedSets()) self.shape = p @@ -7310,9 +7310,9 @@ def __contains__(self, x): EXAMPLES:: sage: ST = RowStandardTableaux([2,1,1]) - sage: all(st in ST for st in ST) + sage: all(st in ST for st in ST) # optional - sage.graphs True - sage: len([x for x in RowStandardTableaux(4) if x in ST]) + sage: len([x for x in RowStandardTableaux(4) if x in ST]) # optional - sage.graphs 12 sage: ST.cardinality() 12 @@ -7335,14 +7335,14 @@ def __iter__(self): EXAMPLES:: - sage: [t for t in RowStandardTableaux([2,2])] + sage: [t for t in RowStandardTableaux([2,2])] # optional - sage.graphs [[[2, 4], [1, 3]], [[3, 4], [1, 2]], [[1, 4], [2, 3]], [[1, 3], [2, 4]], [[1, 2], [3, 4]], [[2, 3], [1, 4]]] - sage: [t for t in RowStandardTableaux([3,2])] + sage: [t for t in RowStandardTableaux([3,2])] # optional - sage.graphs [[[2, 4, 5], [1, 3]], [[3, 4, 5], [1, 2]], [[1, 4, 5], [2, 3]], @@ -7354,7 +7354,7 @@ def __iter__(self): [[2, 3, 4], [1, 5]], [[2, 3, 5], [1, 4]]] sage: st = RowStandardTableaux([2,1]) - sage: st[0].parent() is st + sage: st[0].parent() is st # optional - sage.graphs True """ partial_sums = [sum(self.shape[:i]) for i in range(len(self.shape)+1)] @@ -7461,7 +7461,7 @@ class StandardTableaux(SemistandardTableaux): 2 sage: ST.list() [[[1, 3], [2, 4]], [[1, 2], [3, 4]]] - sage: StandardTableau([[1,2,3],[4,5]]).residue_sequence(3).standard_tableaux() + sage: StandardTableau([[1,2,3],[4,5]]).residue_sequence(3).standard_tableaux() # optional - sage.groups Standard tableaux with 3-residue sequence (0,1,2,2,0) and multicharge (0) """ @staticmethod diff --git a/src/sage/combinat/tiling.py b/src/sage/combinat/tiling.py index 640f1c6d096..6cb44cd99c8 100644 --- a/src/sage/combinat/tiling.py +++ b/src/sage/combinat/tiling.py @@ -109,8 +109,8 @@ Showing one solution:: sage: solution = next(T.solve()) # long time - sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time - sage: G.show(aspect_ratio=1, axes=False) # long time + sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time # optional - sage.plot + sage: G.show(aspect_ratio=1, axes=False) # long time # optional - sage.plot 1d Easy Example --------------- @@ -162,8 +162,8 @@ sage: T = TilingSolver(L, box=(8,8), reflection=True) sage: solution = next(T.solve()) # long time (7s) - sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time (<1s) - sage: G.show(aspect_ratio=1, axes=False) # long time (2s) + sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time (<1s) # optional - sage.plot + sage: G.show(aspect_ratio=1, axes=False) # long time (2s) # optional - sage.plot Compute the number of solutions:: @@ -218,8 +218,8 @@ sage: T.number_of_solutions() 10 sage: solution = next(T.solve()) - sage: G = sum([p.show2d() for p in solution], Graphics()) - sage: G.show(aspect_ratio=1) # long time (2s) + sage: G = sum([p.show2d() for p in solution], Graphics()) # optional - sage.plot + sage: G.show(aspect_ratio=1) # long time (2s) # optional - sage.plot :: @@ -240,16 +240,15 @@ sage: from sage.combinat.tiling import Polyomino, TilingSolver sage: Y = Polyomino([(0,0),(1,0),(2,0),(3,0),(2,1)], color='yellow') sage: T = TilingSolver([Y], box=(15,15), reusable=True, reflection=True) - sage: a = T.animate(stop=40) # long time # optional -- ImageMagick - sage: a # long time # optional -- ImageMagick + sage: a = T.animate(stop=40); a # long time # optional -- ImageMagick sage.plot Animation with 40 frames Incremental animation of the solutions (one piece is removed/added at a time):: - sage: a = T.animate('incremental', stop=40) # long time # optional -- ImageMagick - sage: a # long time # optional -- ImageMagick + sage: a = T.animate('incremental', stop=40) # long time # optional -- ImageMagick sage.plot + sage: a # long time # optional -- ImageMagick sage.plot Animation with 40 frames - sage: a.show(delay=50, iterations=1) # long time # optional -- ImageMagick + sage: a.show(delay=50, iterations=1) # long time # optional -- ImageMagick sage.plot 5d Easy Example --------------- @@ -1389,7 +1388,7 @@ def show3d(self, size=1): sage: from sage.combinat.tiling import Polyomino sage: p = Polyomino([(0,0,0), (0,1,0), (1,1,0), (1,1,1)], color='blue') - sage: p.show3d() # long time (2s) + sage: p.show3d() # long time (2s) # optional -- sage.plot Graphics3d Object """ assert self._dimension == 3, "Dimension of the polyomino must be 3." @@ -1422,7 +1421,7 @@ def show2d(self, size=0.7, color='black', thickness=1): sage: from sage.combinat.tiling import Polyomino sage: p = Polyomino([(0,0),(1,0),(1,1),(1,2)], color='deeppink') - sage: p.show2d() # long time (0.5s) + sage: p.show2d() # long time (0.5s) # optional -- sage.plot Graphics object consisting of 17 graphics primitives """ assert self._dimension == 2, "Dimension of the polyomino must be 2." @@ -1473,12 +1472,12 @@ def self_surrounding(self, radius, remove_incomplete_copies=True, ....: (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (2, 0), (2, 2), ....: (2, 3), (2, 5), (2, 6), (2, 8)]) sage: solution = H.self_surrounding(8) - sage: G = sum([p.show2d() for p in solution], Graphics()) + sage: G = sum([p.show2d() for p in solution], Graphics()) # optional - sage.plot :: sage: solution = H.self_surrounding(8, remove_incomplete_copies=False) - sage: G = sum([p.show2d() for p in solution], Graphics()) + sage: G = sum([p.show2d() for p in solution], Graphics()) # optional - sage.plot """ # Define the box to tile @@ -2425,38 +2424,38 @@ def animate(self, partial=None, stop=None, size=0.75, axes=False): sage: from sage.combinat.tiling import Polyomino, TilingSolver sage: y = Polyomino([(0,0),(1,0),(2,0),(3,0),(2,1)], color='cyan') sage: T = TilingSolver([y], box=(5,10), reusable=True, reflection=True) - sage: a = T.animate() - sage: a # optional -- ImageMagick # long time + sage: a = T.animate() # optional - sage.plot + sage: a # optional -- ImageMagick # long time # optional - sage.plot Animation with 10 frames Include partial solutions (common prefix between two consecutive solutions):: - sage: a = T.animate('common_prefix') - sage: a # optional -- ImageMagick # long time + sage: a = T.animate('common_prefix') # optional - sage.plot + sage: a # optional -- ImageMagick # long time # optional - sage.plot Animation with 19 frames Incremental solutions (one piece removed or added at a time):: - sage: a = T.animate('incremental') # long time (2s) - sage: a # long time (2s) # optional -- ImageMagick + sage: a = T.animate('incremental') # long time (2s) # optional - sage.plot + sage: a # long time (2s) # optional -- ImageMagick sage.plot Animation with 123 frames :: - sage: a.show() # optional -- ImageMagick # long time + sage: a.show() # optional -- ImageMagick # long time # optional - sage.plot The ``show`` function takes arguments to specify the delay between frames (measured in hundredths of a second, default value 20) and the number of iterations (default value 0, which means to iterate forever). To iterate 4 times with half a second between each frame:: - sage: a.show(delay=50, iterations=4) # optional -- ImageMagick # long time + sage: a.show(delay=50, iterations=4) # optional -- ImageMagick # long time # optional - sage.plot Limit the number of frames:: - sage: a = T.animate('incremental', stop=13) # not tested - sage: a # not tested + sage: a = T.animate('incremental', stop=13) # not tested # optional - sage.plot + sage: a # not tested # optional - sage.plot Animation with 13 frames """ dimension = self._box._dimension diff --git a/src/sage/combinat/triangles_FHM.py b/src/sage/combinat/triangles_FHM.py index 7fca1bd0252..43f2947a51b 100644 --- a/src/sage/combinat/triangles_FHM.py +++ b/src/sage/combinat/triangles_FHM.py @@ -12,11 +12,11 @@ The M-triangle class is motivated by the generating series of Möbius numbers for graded posets. A typical example is:: - sage: W = SymmetricGroup(4) - sage: posets.NoncrossingPartitions(W).M_triangle() + sage: W = SymmetricGroup(4) # optional - sage.groups + sage: posets.NoncrossingPartitions(W).M_triangle() # optional - sage.graphs sage.groups M: x^3*y^3 - 6*x^2*y^3 + 6*x^2*y^2 + 10*x*y^3 - 16*x*y^2 - 5*y^3 + 6*x*y + 10*y^2 - 6*y + 1 - sage: unicode_art(_) + sage: unicode_art(_) # optional - sage.graphs sage.modules sage.groups ⎛ -5 10 -6 1⎞ ⎜ 10 -16 6 0⎟ ⎜ -6 6 0 0⎟ @@ -31,7 +31,7 @@ sage: f = C.greedy_facet() sage: C.F_triangle(f) F: 5*x^3 + 5*x^2*y + 3*x*y^2 + y^3 + 10*x^2 + 8*x*y + 3*y^2 + 6*x + 3*y + 1 - sage: unicode_art(_) + sage: unicode_art(_) # optional - sage.modules ⎛ 1 0 0 0⎞ ⎜ 3 3 0 0⎟ ⎜ 3 8 5 0⎟ @@ -67,7 +67,7 @@ def _matrix_display(self, variables=None): sage: from sage.combinat.triangles_FHM import _matrix_display sage: x, y = PolynomialRing(QQ,['x', 'y']).gens() - sage: _matrix_display(x**2+x*y+y**3) + sage: _matrix_display(x**2+x*y+y**3) # optional - sage.modules [1 0 0] [0 0 0] [0 1 0] @@ -76,10 +76,10 @@ def _matrix_display(self, variables=None): With a specific choice of variables:: sage: x, y, z = PolynomialRing(QQ,['x','y','z']).gens() - sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[y,z]) + sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[y,z]) # optional - sage.modules [ x x 0 1] [x^2 0 0 0] - sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[x,z]) + sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[x,z]) # optional - sage.modules [ y^3 y + 1 0] [ 0 0 1] """ @@ -124,7 +124,7 @@ class Triangle(SageObject): sage: from sage.combinat.triangles_FHM import Triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = Triangle(1+4*x+2*x*y) - sage: unicode_art(ht) + sage: unicode_art(ht) # optional - sage.modules ⎛0 2⎞ ⎝1 4⎠ """ @@ -136,7 +136,7 @@ def __init__(self, poly, variables=None): sage: from sage.combinat.triangles_FHM import Triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = Triangle(1+2*x*y) - sage: unicode_art(ht) + sage: unicode_art(ht) # optional - sage.modules ⎛0 2⎞ ⎝1 0⎠ """ @@ -156,7 +156,7 @@ def _ascii_art_(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = H_triangle(1+2*x*y) - sage: ascii_art(ht) + sage: ascii_art(ht) # optional - sage.modules [0 2] [1 0] """ @@ -171,7 +171,7 @@ def _unicode_art_(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = H_triangle(1+2*x*y) - sage: unicode_art(ht) + sage: unicode_art(ht) # optional - sage.modules ⎛0 2⎞ ⎝1 0⎠ """ @@ -200,7 +200,7 @@ def _latex_(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = H_triangle(1+2*x*y) - sage: latex(ht) + sage: latex(ht) # optional - sage.modules \left(\begin{array}{rr} 0 & 2 \\ 1 & 0 @@ -296,7 +296,7 @@ def matrix(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: h = H_triangle(1+2*x*y) - sage: h.matrix() + sage: h.matrix() # optional - sage.modules [0 2] [1 0] """ @@ -557,9 +557,9 @@ def gamma(self): sage: H_triangle(ht).gamma() Γ: y^2 + x - sage: W = SymmetricGroup(5) - sage: P = posets.NoncrossingPartitions(W) - sage: P.M_triangle().h().gamma() + sage: W = SymmetricGroup(5) # optional - sage.groups + sage: P = posets.NoncrossingPartitions(W) # optional - sage.graphs + sage: P.M_triangle().h().gamma() # optional - sage.graphs sage.groups Γ: y^4 + 3*x*y^2 + 2*x^2 + 2*x*y + x """ x, y = self._vars diff --git a/src/sage/combinat/tuple.py b/src/sage/combinat/tuple.py index 7e7f85c61ef..26c1b4ec074 100644 --- a/src/sage/combinat/tuple.py +++ b/src/sage/combinat/tuple.py @@ -47,9 +47,9 @@ class Tuples(Parent, UniqueRepresentation): :: - sage: K. = GF(4, 'a') - sage: mset = [x for x in K if x != 0] - sage: Tuples(mset,2).list() + sage: K. = GF(4, 'a') # optional - sage.rings.finite_rings + sage: mset = [x for x in K if x != 0] # optional - sage.rings.finite_rings + sage: Tuples(mset,2).list() # optional - sage.rings.finite_rings [[a, a], [a + 1, a], [1, a], [a, a + 1], [a + 1, a + 1], [1, a + 1], [a, 1], [a + 1, 1], [1, 1]] """ @@ -127,10 +127,10 @@ def cardinality(self): EXAMPLES:: sage: S = [1,2,3,4,5] - sage: Tuples(S,2).cardinality() + sage: Tuples(S,2).cardinality() # optional - sage.libs.gap 25 sage: S = [1,1,2,3,4,5] - sage: Tuples(S,2).cardinality() + sage: Tuples(S,2).cardinality() # optional - sage.libs.gap 25 """ return ZZ(libgap.NrTuples(self._index_list, ZZ(self.k))) @@ -210,7 +210,7 @@ def cardinality(self): EXAMPLES:: sage: S = [1,2,3,4,5] - sage: UnorderedTuples(S,2).cardinality() + sage: UnorderedTuples(S,2).cardinality() # optional - sage.libs.gap 15 """ return ZZ(libgap.NrUnorderedTuples(self._index_list, ZZ(self.k))) diff --git a/src/sage/combinat/tutorial.py b/src/sage/combinat/tutorial.py index dfab1793474..b8c4fde4386 100644 --- a/src/sage/combinat/tutorial.py +++ b/src/sage/combinat/tutorial.py @@ -447,7 +447,7 @@ sage: Qx = QQ['x'].fraction_field() sage: Qxy = Qx['y'] - sage: R = Qxy.quo(P); R + sage: R = Qxy.quo(P); R # optional - sage.symbolic Univariate Quotient Polynomial Ring in ybar over Fraction Field of Univariate Polynomial Ring in x over Rational Field with modulus y^2 - y + x @@ -458,7 +458,7 @@ We continue the calculation of this fraction in `R`:: - sage: fraction = - R(Px) / R(Py); fraction + sage: fraction = - R(Px) / R(Py); fraction # optional - sage.symbolic (1/2/(x - 1/4))*ybar - 1/4/(x - 1/4) .. note:: diff --git a/src/sage/combinat/words/abstract_word.py b/src/sage/combinat/words/abstract_word.py index ff3be9930ad..cfff867d67d 100644 --- a/src/sage/combinat/words/abstract_word.py +++ b/src/sage/combinat/words/abstract_word.py @@ -1478,24 +1478,24 @@ def sum_digits(self, base=2, mod=None): Sum of digits modulo 2 of the prime numbers written in base 2:: - sage: Word(primes(1000)).sum_digits() + sage: Word(primes(1000)).sum_digits() # optional - sage.libs.pari word: 1001110100111010111011001011101110011011... Sum of digits modulo 3 of the prime numbers written in base 3:: - sage: Word(primes(1000)).sum_digits(base=3) + sage: Word(primes(1000)).sum_digits(base=3) # optional - sage.libs.pari word: 2100002020002221222121022221022122111022... - sage: Word(primes(1000)).sum_digits(base=3, mod=3) + sage: Word(primes(1000)).sum_digits(base=3, mod=3) # optional - sage.libs.pari word: 2100002020002221222121022221022122111022... Sum of digits modulo 2 of the prime numbers written in base 3:: - sage: Word(primes(1000)).sum_digits(base=3, mod=2) + sage: Word(primes(1000)).sum_digits(base=3, mod=2) # optional - sage.libs.pari word: 0111111111111111111111111111111111111111... Sum of digits modulo 7 of the prime numbers written in base 10:: - sage: Word(primes(1000)).sum_digits(base=10, mod=7) + sage: Word(primes(1000)).sum_digits(base=10, mod=7) # optional - sage.libs.pari word: 2350241354435041006132432241353546006304... Negative entries:: diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index 53e04002cf6..05f6233e8bc 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -190,9 +190,9 @@ Rauzy graphs:: sage: f = words.FibonacciWord()[:30] - sage: f.rauzy_graph(4) + sage: f.rauzy_graph(4) # optional - sage.graphs Looped digraph on 5 vertices - sage: f.reduced_rauzy_graph(4) + sage: f.reduced_rauzy_graph(4) # optional - sage.graphs Looped multi-digraph on 2 vertices Left-special and bispecial factors:: @@ -1522,12 +1522,12 @@ def rauzy_graph(self, n): sage: w = Word(range(10)); w word: 0123456789 - sage: g = w.rauzy_graph(3); g + sage: g = w.rauzy_graph(3); g # optional - sage.graphs Looped digraph on 8 vertices sage: WordOptions(identifier='') - sage: g.vertices(sort=True) + sage: g.vertices(sort=True) # optional - sage.graphs [012, 123, 234, 345, 456, 567, 678, 789] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [(012, 123, 3), (123, 234, 4), (234, 345, 5), @@ -1540,20 +1540,20 @@ def rauzy_graph(self, n): :: sage: f = words.FibonacciWord()[:100] - sage: f.rauzy_graph(8) + sage: f.rauzy_graph(8) # optional - sage.graphs Looped digraph on 9 vertices :: sage: w = Word('1111111') - sage: g = w.rauzy_graph(3) - sage: g.edges(sort=True) + sage: g = w.rauzy_graph(3) # optional - sage.graphs + sage: g.edges(sort=True) # optional - sage.graphs [(word: 111, word: 111, word: 1)] :: sage: w = Word('111') - sage: for i in range(5) : w.rauzy_graph(i) + sage: for i in range(5): w.rauzy_graph(i) # optional - sage.graphs Looped multi-digraph on 1 vertex Looped digraph on 1 vertex Looped digraph on 1 vertex @@ -1564,9 +1564,9 @@ def rauzy_graph(self, n): sage: W = Words('abcde') sage: w = W('abc') - sage: w.rauzy_graph(0) + sage: w.rauzy_graph(0) # optional - sage.graphs Looped multi-digraph on 1 vertex - sage: _.edges(sort=True) + sage: _.edges(sort=True) # optional - sage.graphs [(word: , word: , word: a), (word: , word: , word: b), (word: , word: , word: c)] @@ -1633,35 +1633,37 @@ def reduced_rauzy_graph(self, n): sage: w = Word(range(10)); w word: 0123456789 - sage: g = w.reduced_rauzy_graph(3); g + sage: g = w.reduced_rauzy_graph(3); g # optional - sage.graphs Looped multi-digraph on 2 vertices - sage: g.vertices(sort=True) + sage: g.vertices(sort=True) # optional - sage.graphs [word: 012, word: 789] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [(word: 012, word: 789, word: 3456789)] For the Fibonacci word:: sage: f = words.FibonacciWord()[:100] - sage: g = f.reduced_rauzy_graph(8);g + sage: g = f.reduced_rauzy_graph(8);g # optional - sage.graphs Looped multi-digraph on 2 vertices - sage: g.vertices(sort=True) + sage: g.vertices(sort=True) # optional - sage.graphs [word: 01001010, word: 01010010] - sage: g.edges(sort=True) - [(word: 01001010, word: 01010010, word: 010), (word: 01010010, word: 01001010, word: 01010), (word: 01010010, word: 01001010, word: 10)] + sage: g.edges(sort=True) # optional - sage.graphs + [(word: 01001010, word: 01010010, word: 010), + (word: 01010010, word: 01001010, word: 01010), + (word: 01010010, word: 01001010, word: 10)] For periodic words:: sage: from itertools import cycle sage: w = Word(cycle('abcd'))[:100] - sage: g = w.reduced_rauzy_graph(3) - sage: g.edges(sort=True) + sage: g = w.reduced_rauzy_graph(3) # optional - sage.graphs + sage: g.edges(sort=True) # optional - sage.graphs [(word: abc, word: abc, word: dabc)] :: sage: w = Word('111') - sage: for i in range(5) : w.reduced_rauzy_graph(i) + sage: for i in range(5): w.reduced_rauzy_graph(i) # optional - sage.graphs Looped digraph on 1 vertex Looped digraph on 1 vertex Looped digraph on 1 vertex @@ -1673,10 +1675,10 @@ def reduced_rauzy_graph(self, n): sage: sigma = WordMorphism('a->abcd,b->cd,c->cd,d->cd') sage: w = sigma.fixed_point('a')[:100]; w word: abcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd... - sage: g = w.reduced_rauzy_graph(5) - sage: g.vertices(sort=True) + sage: g = w.reduced_rauzy_graph(5) # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs [word: abcdc, word: cdcdc] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [(word: abcdc, word: cdcdc, word: dc), (word: cdcdc, word: cdcdc, word: dc)] AUTHOR: @@ -3097,9 +3099,9 @@ def defect(self, f=None): sage: sa = WordMorphism('a->ab,b->b') sage: sb = WordMorphism('a->a,b->ba') sage: w = (sa*sb*sb*sa*sa*sa*sb).fixed_point('a') - sage: w[:30].defect() + sage: w[:30].defect() # optional - sage.modules 0 - sage: w[110:140].defect() + sage: w[110:140].defect() # optional - sage.modules 0 It is even conjectured that the defect of an aperiodic word which is @@ -3107,11 +3109,11 @@ def defect(self, f=None): (see [BBGL2008]_):: sage: w = words.ThueMorseWord() - sage: w[:50].defect() + sage: w[:50].defect() # optional - sage.modules 12 - sage: w[:100].defect() + sage: w[:100].defect() # optional - sage.modules 16 - sage: w[:300].defect() + sage: w[:300].defect() # optional - sage.modules 52 For generalized defect with an involution different from the identity, diff --git a/src/sage/combinat/words/morphic.py b/src/sage/combinat/words/morphic.py index 6cca2834ee5..221ad94a310 100644 --- a/src/sage/combinat/words/morphic.py +++ b/src/sage/combinat/words/morphic.py @@ -24,7 +24,7 @@ abstract numeration system associated to the morphism and the starting letter, see chapter 3 of the book [BR2010b]_:: - sage: w[10000000] + sage: w[10000000] # optional - sage.modules 'b' """ @@ -57,7 +57,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity): sage: w = m.fixed_point('a') sage: w word: abaababaabaababaababaabaababaabaababaaba... - sage: w[555:1000] + sage: w[555:1000] # optional - sage.modules word: abaababaabaababaababaabaababaabaababaaba... sage: w.length() +Infinity @@ -68,11 +68,11 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity): sage: m.fixed_point('a') word: abcbabacababaabcbabaabccaabcbabaabcbabaa... sage: w = m.fixed_point('a') - sage: w[7] + sage: w[7] # optional - sage.modules 'c' - sage: w[2:7] + sage: w[2:7] # optional - sage.modules word: cbaba - sage: w[500:503] + sage: w[500:503] # optional - sage.modules word: caa When the morphic word is finite:: @@ -81,7 +81,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity): sage: w = m.fixed_point("a") sage: w word: ab - sage: w[0] + sage: w[0] # optional - sage.modules 'a' sage: w.length() 2 @@ -93,7 +93,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity): sage: from sage.combinat.words.morphic import WordDatatype_morphic sage: coding = {'a':'x', 'b':'y'} sage: w = WordDatatype_morphic(W, m, 'a', coding=coding) - sage: [w[i] for i in range(10)] + sage: [w[i] for i in range(10)] # optional - sage.modules ['x', 'y', 'x', 'x', 'y', 'x', 'y', 'x', 'x', 'y'] TESTS:: @@ -104,9 +104,9 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity): sage: for _ in range(10000): _ = next(it) sage: L = [next(it) for _ in range(10)]; L ['d', 'd', 'd', 'c', 'd', 'd', 'd', 'c', 'b', 'a'] - sage: w[10000:10010] + sage: w[10000:10010] # optional - sage.modules word: dddcdddcba - sage: list(w[10000:10010]) == L + sage: list(w[10000:10010]) == L # optional - sage.modules True """ @@ -177,18 +177,18 @@ def representation(self, n): sage: m = WordMorphism('a->ab,b->a') sage: w = m.fixed_point('a') - sage: w.representation(5) + sage: w.representation(5) # optional - sage.modules [1, 0, 0, 0] When the morphic word is finite:: sage: m = WordMorphism("a->ab,b->,c->cdab,d->dcab") sage: w = m.fixed_point("a") - sage: w.representation(0) + sage: w.representation(0) # optional - sage.modules [] - sage: w.representation(1) + sage: w.representation(1) # optional - sage.modules [1] - sage: w.representation(2) + sage: w.representation(2) # optional - sage.modules Traceback (most recent call last): ... IndexError: index (=2) out of range, the fixed point is finite and has length 2 @@ -204,7 +204,7 @@ def representation(self, n): sage: w = WordDatatype_morphic(W, m, 'a') sage: type(w) - sage: w.representation(5) + sage: w.representation(5) # optional - sage.modules [1, 0, 0, 0] """ letters_to_int = {a:i for (i,a) in enumerate(self._alphabet)} diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 33a76127699..af43487a574 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -66,7 +66,7 @@ Incidence matrix:: - sage: matrix(m) + sage: matrix(m) # optional - sage.modules [2 3 1] [1 3 0] [1 1 1] @@ -612,7 +612,7 @@ def __str__(self) -> str: :: sage: s = WordMorphism({1:[1,2],2:[1]}) - sage: s.dual_map() + sage: s.dual_map() # optional - sage.modules E_1^*(1->12, 2->1) TESTS:: @@ -1099,21 +1099,21 @@ def _matrix_(self, R=None): sage: fibo = WordMorphism('a->ab,b->a') sage: tm = WordMorphism('a->ab,b->ba') - sage: Mfibo = matrix(fibo); Mfibo # indirect doctest + sage: Mfibo = matrix(fibo); Mfibo # indirect doctest # optional - sage.modules [1 1] [1 0] - sage: Mtm = matrix(tm); Mtm + sage: Mtm = matrix(tm); Mtm # optional - sage.modules [1 1] [1 1] - sage: Mtm * Mfibo == matrix(tm*fibo) # indirect doctest + sage: Mtm * Mfibo == matrix(tm*fibo) # indirect doctest # optional - sage.modules True - sage: Mfibo * Mtm == matrix(fibo*tm) # indirect doctest + sage: Mfibo * Mtm == matrix(fibo*tm) # indirect doctest # optional - sage.modules True - sage: Mfibo.parent() + sage: Mfibo.parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: p = Mfibo.charpoly(); p + sage: p = Mfibo.charpoly(); p # optional - sage.modules x^2 - x - 1 - sage: p.roots(ring=RR, multiplicities=False) + sage: p.roots(ring=RR, multiplicities=False) # optional - sage.modules [-0.618033988749895, 1.61803398874989] """ if R is None: @@ -1134,12 +1134,12 @@ def incidence_matrix(self): EXAMPLES:: sage: m = WordMorphism('a->abc,b->a,c->c') - sage: m.incidence_matrix() + sage: m.incidence_matrix() # optional - sage.modules [1 1 0] [1 0 0] [1 0 1] sage: m = WordMorphism('a->abc,b->a,c->c,d->abbccccabca,e->abc') - sage: m.incidence_matrix() + sage: m.incidence_matrix() # optional - sage.modules [1 1 0 3 1] [1 0 0 3 1] [1 0 1 5 1] @@ -1202,9 +1202,10 @@ def is_endomorphism(self): We check that :trac:`8674` is fixed:: - sage: P = WordPaths('abcd') - sage: m = WordMorphism('a->adab,b->ab,c->cbcd,d->cd', domain=P, codomain=P) - sage: m.is_endomorphism() + sage: P = WordPaths('abcd') # optional - sage.modules + sage: m = WordMorphism('a->adab,b->ab,c->cbcd,d->cd', # optional - sage.modules + ....: domain=P, codomain=P) + sage: m.is_endomorphism() # optional - sage.modules True """ return self.codomain() == self.domain() @@ -1493,11 +1494,11 @@ def pisot_eigenvector_right(self): EXAMPLES:: sage: m = WordMorphism('a->aaaabbc,b->aaabbc,c->aabc') - sage: matrix(m) + sage: matrix(m) # optional - sage.modules [4 3 2] [2 2 1] [1 1 1] - sage: m.pisot_eigenvector_right() + sage: m.pisot_eigenvector_right() # optional - sage.modules sage.rings.number_field (1, 0.5436890126920763?, 0.2955977425220848?) """ eig = self.incidence_matrix().eigenvectors_right() @@ -1523,11 +1524,11 @@ def pisot_eigenvector_left(self): EXAMPLES:: sage: m = WordMorphism('a->aaaabbc,b->aaabbc,c->aabc') - sage: matrix(m) + sage: matrix(m) # optional - sage.modules [4 3 2] [2 2 1] [1 1 1] - sage: m.pisot_eigenvector_left() + sage: m.pisot_eigenvector_left() # optional - sage.modules sage.rings.number_field (1, 0.8392867552141611?, 0.5436890126920763?) """ eig = self.incidence_matrix().eigenvectors_left() @@ -2072,12 +2073,12 @@ def language(self, n, u=None): The fibonacci morphism:: - sage: s = WordMorphism({0: [0,1], 1:[0]}) - sage: sorted(s.language(3)) + sage: s = WordMorphism({0: [0,1], 1: [0]}) + sage: sorted(s.language(3)) # optional - sage.modules [word: 001, word: 010, word: 100, word: 101] - sage: len(s.language(1000)) + sage: len(s.language(1000)) # optional - sage.modules 1001 - sage: all(len(s.language(n)) == n+1 for n in range(100)) + sage: all(len(s.language(n)) == n+1 for n in range(100)) # optional - sage.modules True A growing but non-primitive example. The DOL-languages generated @@ -2087,14 +2088,14 @@ def language(self, n, u=None): sage: u = s.fixed_point(0) sage: A0 = u[:200].factor_set(5) - sage: B0 = s.language(5, [0]) - sage: set(A0) == B0 + sage: B0 = s.language(5, [0]) # optional - sage.modules + sage: set(A0) == B0 # optional - sage.modules True sage: v = s.fixed_point(2) sage: A2 = v[:200].factor_set(5) - sage: B2 = s.language(5, [2]) - sage: set(A2) == B2 + sage: B2 = s.language(5, [2]) # optional - sage.modules + sage: set(A2) == B2 # optional - sage.modules True sage: len(A0), len(A2) @@ -2103,7 +2104,7 @@ def language(self, n, u=None): The Chacon transformation (non-primitive):: sage: s = WordMorphism({0: [0,0,1,0], 1:[1]}) - sage: sorted(s.language(10)) + sage: sorted(s.language(10)) # optional - sage.modules [word: 0001000101, word: 0001010010, ... @@ -2457,8 +2458,8 @@ def dual_map(self, k=1): EXAMPLES:: - sage: sigma = WordMorphism({1:[2],2:[3],3:[1,2]}) - sage: sigma.dual_map() + sage: sigma = WordMorphism({1: [2], 2: [3], 3: [1,2]}) + sage: sigma.dual_map() # optional - sage.modules E_1^*(1->2, 2->3, 3->12) :: @@ -2512,7 +2513,7 @@ def rauzy_fractal_projection(self, eig=None, prec=53): is:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: s.rauzy_fractal_projection() + sage: s.rauzy_fractal_projection() # optional - sage.modules {'1': (1.00000000000000, 0.000000000000000), '2': (-1.41964337760708, -0.606290729207199), '3': (-0.771844506346038, 1.11514250803994)} @@ -2520,9 +2521,9 @@ def rauzy_fractal_projection(self, eig=None, prec=53): TESTS:: sage: t = WordMorphism('1->12,2->3,3->45,4->5,5->6,6->7,7->8,8->1') - sage: E = t.incidence_matrix().eigenvalues() - sage: x = [x for x in E if -0.8 < x < -0.7][0] - sage: t.rauzy_fractal_projection(prec=10) + sage: E = t.incidence_matrix().eigenvalues() # optional - sage.modules + sage: x = [x for x in E if -0.8 < x < -0.7][0] # optional - sage.modules + sage: t.rauzy_fractal_projection(prec=10) # optional - sage.modules {'1': (1.0, 0.00), '2': (-1.7, -0.56), '3': (0.79, 1.3), @@ -2531,7 +2532,7 @@ def rauzy_fractal_projection(self, eig=None, prec=53): '6': (0.79, 1.3), '7': (0.21, -1.3), '8': (-0.88, 0.74)} - sage: t.rauzy_fractal_projection(eig=x, prec=10) + sage: t.rauzy_fractal_projection(eig=x, prec=10) # optional - sage.modules {'1': (1.0, 0.00), '2': (-0.12, -0.74), '3': (-0.66, -0.56), @@ -2616,19 +2617,20 @@ def rauzy_fractal_points(self, n=None, exchange=False, eig=None, translate=None, and ``'3'`` are respectively:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: D = s.rauzy_fractal_points(n=100) - sage: len(D['1']) + sage: D = s.rauzy_fractal_points(n=100) # optional - sage.modules + sage: len(D['1']) # optional - sage.modules 54 - sage: len(D['2']) + sage: len(D['2']) # optional - sage.modules 30 - sage: len(D['3']) + sage: len(D['3']) # optional - sage.modules 16 TESTS:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: D = s.rauzy_fractal_points(n=100, exchange=True, translate=[(3,1,-2), (5,-33,8)], prec=40) - sage: len(D['1']) + sage: D = s.rauzy_fractal_points(n=100, exchange=True, # optional - sage.modules + ....: translate=[(3,1,-2), (5,-33,8)], prec=40) + sage: len(D['1']) # optional - sage.modules 108 AUTHOR: @@ -2839,8 +2841,8 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, #. Different fractals can be obtained by choosing another (non-Pisot) eigenvalue:: sage: s = WordMorphism('1->12,2->3,3->45,4->5,5->6,6->7,7->8,8->1') - sage: E = s.incidence_matrix().eigenvalues() - sage: x = [x for x in E if -0.8 < x < -0.7][0] + sage: E = s.incidence_matrix().eigenvalues() # optional - sage.modules + sage: x = [x for x in E if -0.8 < x < -0.7][0] # optional - sage.modules sage: s.rauzy_fractal_plot() # not tested (> 1 second) sage: s.rauzy_fractal_plot(eig=x) # not tested (> 1 second) @@ -2883,7 +2885,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, :: sage: t = WordMorphism("a->aC,b->d,C->de,d->a,e->ab") # substitution found by Julien Bernat - sage: V = [vector((0,0,1,0,-1)), vector((0,0,1,-1,0))] + sage: V = [vector((0,0,1,0,-1)), vector((0,0,1,-1,0))] # optional - sage.modules sage: S = set(map(tuple, [i*V[0] + j*V[1] ....: for i in [-1,0,1] for j in [-1,0,1]])) sage: t.rauzy_fractal_plot(n=10000, # not tested (> 1 second) @@ -2907,7 +2909,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, TESTS:: sage: s = WordMorphism('a->ab,b->c,c->d,d->e,e->a') - sage: s.rauzy_fractal_plot(n=1000, colormap='Set1', # optional - sage.plot + sage: s.rauzy_fractal_plot(n=1000, colormap='Set1', # optional - sage.modules sage.plot ....: opacity={'a':0.5,'b':1,'c':0.7,'d':0,'e':0.2}, ....: plot_origin=(100,"black"), plot_basis=True, ....: point_size=2.5) @@ -3327,24 +3329,24 @@ def abelian_rotation_subspace(self): EXAMPLES:: - sage: WordMorphism('0->1,1->0').abelian_rotation_subspace() + sage: WordMorphism('0->1,1->0').abelian_rotation_subspace() # optional - sage.modules Vector space of degree 2 and dimension 2 over Rational Field Basis matrix: [1 0] [0 1] - sage: WordMorphism('0->01,1->10').abelian_rotation_subspace() + sage: WordMorphism('0->01,1->10').abelian_rotation_subspace() # optional - sage.modules Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: [] - sage: WordMorphism('0->01,1->1').abelian_rotation_subspace() + sage: WordMorphism('0->01,1->1').abelian_rotation_subspace() # optional - sage.modules Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [0 1] - sage: WordMorphism('1->122,2->211').abelian_rotation_subspace() + sage: WordMorphism('1->122,2->211').abelian_rotation_subspace() # optional - sage.modules Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 -1] - sage: WordMorphism('0->1,1->102,2->3,3->4,4->2').abelian_rotation_subspace() + sage: WordMorphism('0->1,1->102,2->3,3->4,4->2').abelian_rotation_subspace() # optional - sage.modules Vector space of degree 5 and dimension 3 over Rational Field Basis matrix: [0 0 1 0 0] @@ -3353,7 +3355,7 @@ def abelian_rotation_subspace(self): The domain needs to be equal to the codomain:: - sage: WordMorphism('0->1,1->',codomain=Words('01')).abelian_rotation_subspace() + sage: WordMorphism('0->1,1->',codomain=Words('01')).abelian_rotation_subspace() # optional - sage.modules Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: [] diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index a924eb45c03..19bef31c3c5 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -104,14 +104,14 @@ Finite Dyck paths sage: d = D('()()()(())'); d Path: ()()()(()) - sage: d.plot() + sage: d.plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives :: sage: P = WordPaths('abcdef', steps='triangle_grid') sage: p = P('babaddefadabcadefaadfafabacdefa') - sage: p.plot() + sage: p.plot() # optional - sage.plot Graphics object consisting of 3 graphics primitives Vector steps may be in more than 2 dimensions:: @@ -120,7 +120,7 @@ sage: P = WordPaths(alphabet='abc', steps=d); P Word Paths over 3 steps sage: p = P('abcabcabcabcaabacabcababcacbabacacabcaccbcac') - sage: p.plot() + sage: p.plot() # optional - sage.plot Graphics3d Object :: @@ -137,7 +137,7 @@ sage: CubePaths = WordPaths('abcABC', steps='cube_grid'); CubePaths Word Paths on the cube grid - sage: CubePaths('abcabaabcabAAAAA').plot() + sage: CubePaths('abcabaabcabAAAAA').plot() # optional - sage.plot Graphics3d Object The input data may be a str, a list, a tuple, diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index c7ae4af2aaf..c3646a36907 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -437,9 +437,9 @@ def to_digraph(self): sage: from sage.combinat.words.suffix_trees import SuffixTrie sage: w = Words("cao")("cac") sage: t = SuffixTrie(w) - sage: d = t.to_digraph(); d + sage: d = t.to_digraph(); d # optional - sage.graphs Digraph on 6 vertices - sage: d.adjacency_matrix() + sage: d.adjacency_matrix() # optional - sage.graphs sage.modules [0 1 0 1 0 0] [0 0 1 0 0 0] [0 0 0 0 1 0] @@ -829,7 +829,7 @@ def to_digraph(self, word_labels=False): sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree sage: W = Words([0,1,2]) sage: t = ImplicitSuffixTree(W([0,1,0,1,2])) - sage: t.to_digraph() + sage: t.to_digraph() # optional - sage.graphs Digraph on 8 vertices """ if not self._letters: @@ -865,17 +865,17 @@ def plot(self, word_labels=False, layout='tree', tree_root=0, EXAMPLES:: sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree - sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=True) # optional - sage.plot + sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=True) # optional - sage.graphs sage.plot Graphics object consisting of 23 graphics primitives - sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=False) # optional - sage.plot + sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=False) # optional - sage.graphs sage.plot Graphics object consisting of 23 graphics primitives TESTS:: sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree - sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=True)) # optional - sage.plot + sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=True)) # optional - sage.graphs sage.plot - sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=False)) # optional - sage.plot + sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=False)) # optional - sage.graphs sage.plot """ tree = self.to_digraph(word_labels=word_labels) @@ -1506,7 +1506,7 @@ def uncompactify(self): sage: abbab = Words("ab")("abbab") sage: s = SuffixTrie(abbab) sage: t = ImplicitSuffixTree(abbab) - sage: t.uncompactify().is_isomorphic(s.to_digraph()) + sage: t.uncompactify().is_isomorphic(s.to_digraph()) # optional - sage.graphs True """ tree = self.to_digraph(word_labels=True) diff --git a/src/sage/combinat/words/word.py b/src/sage/combinat/words/word.py index 051d0a1a702..4555c2df762 100644 --- a/src/sage/combinat/words/word.py +++ b/src/sage/combinat/words/word.py @@ -263,7 +263,7 @@ class FiniteWord_char(WordDatatype_char, FiniteWord_class): sage: len(w.factor_set()) 127 - sage: w.rauzy_graph(5) + sage: w.rauzy_graph(5) # optional - sage.graphs Looped digraph on 9 vertices sage: u = W([1,2,3]) diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index f046db3c46e..5790a56e440 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -241,10 +241,10 @@ def markoff_number(self): sage: w0 = words.LowerChristoffelWord(4,7) sage: w1, w2 = w0.standard_factorization() - sage: (m0,m1,m2) = (w.markoff_number() for w in (w0,w1,w2)) - sage: (m0,m1,m2) + sage: (m0,m1,m2) = (w.markoff_number() for w in (w0,w1,w2)) # optional - sage.modules + sage: (m0,m1,m2) # optional - sage.modules (294685, 13, 7561) - sage: m0**2 + m1**2 + m2**2 == 3*m0*m1*m2 + sage: m0**2 + m1**2 + m2**2 == 3*m0*m1*m2 # optional - sage.modules True """ from sage.matrix.constructor import matrix @@ -640,7 +640,7 @@ def FixedPointOfMorphism(self, morphism, first_letter): sage: tm = words.FixedPointOfMorphism(mu,0); tm word: 0110100110010110100101100110100110010110... sage: TM = words.ThueMorseWord() - sage: tm[:1000] == TM[:1000] + sage: tm[:1000] == TM[:1000] # optional - sage.modules True :: @@ -650,7 +650,7 @@ def FixedPointOfMorphism(self, morphism, first_letter): word: 0100101001001010010100100101001001010010... sage: F = words.FibonacciWord(); F word: 0100101001001010010100100101001001010010... - sage: f[:1000] == F[:1000] + sage: f[:1000] == F[:1000] # optional - sage.modules True :: @@ -1520,7 +1520,7 @@ def fibonacci_tile(self, n): EXAMPLES:: - sage: for i in range(3): words.fibonacci_tile(i) + sage: for i in range(3): words.fibonacci_tile(i) # optional - sage.modules Path: 3210 Path: 323030101212 Path: 3230301030323212323032321210121232121010... @@ -1538,7 +1538,7 @@ def dual_fibonacci_tile(self, n): EXAMPLES:: - sage: for i in range(4): words.dual_fibonacci_tile(i) + sage: for i in range(4): words.dual_fibonacci_tile(i) # optional - sage.modules Path: 3210 Path: 32123032301030121012 Path: 3212303230103230321232101232123032123210... diff --git a/src/sage/combinat/words/words.py b/src/sage/combinat/words/words.py index c0a4457df85..50cb3db11e8 100644 --- a/src/sage/combinat/words/words.py +++ b/src/sage/combinat/words/words.py @@ -705,9 +705,9 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr Construction of a word path from a finite word:: sage: W = FiniteWords('abcd') - sage: P = WordPaths('abcd') + sage: P = WordPaths('abcd') # optional - sage.modules sage: w = W('aaab') - sage: P(w) + sage: P(w) # optional - sage.modules Path: aaab Construction of a word path from a Christoffel word:: @@ -715,8 +715,8 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.ChristoffelWord(5,8) sage: w word: 0010010100101 - sage: P = WordPaths([0,1,2,3]) - sage: P(w) + sage: P = WordPaths([0,1,2,3]) # optional - sage.modules + sage: P(w) # optional - sage.modules Path: 0010010100101 Construction of a word represented by a list from a word @@ -744,19 +744,19 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.FibonacciWord() sage: f = w[:100] - sage: P = WordPaths([0,1,2,3]) - sage: p = P(f); p + sage: P = WordPaths([0,1,2,3]) # optional - sage.modules + sage: p = P(f); p # optional - sage.modules Path: 0100101001001010010100100101001001010010... - sage: p.length() + sage: p.length() # optional - sage.modules 100 Creation of a word path from a FiniteWord_callable:: sage: g = W(lambda n:n%2, length = 100) - sage: P = WordPaths([0,1,2,3]) - sage: p = P(g); p + sage: P = WordPaths([0,1,2,3]) # optional - sage.modules + sage: p = P(g); p # optional - sage.modules Path: 0101010101010101010101010101010101010101... - sage: p.length() + sage: p.length() # optional - sage.modules 100 Creation of a word from a pickled function:: @@ -1018,7 +1018,7 @@ def random_element(self, length=None, *args, **kwds): TESTS:: - sage: _ = FiniteWords(GF(5)).random_element() + sage: _ = FiniteWords(GF(5)).random_element() # optional - sage.rings.finite_rings """ if length is None: length = ZZ.random_element(0, 10) @@ -1928,9 +1928,9 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr Construction of a word path from a finite word:: sage: W = Words('abcd') - sage: P = WordPaths('abcd') + sage: P = WordPaths('abcd') # optional - sage.modules sage: w = W('aaab') - sage: P(w) + sage: P(w) # optional - sage.modules Path: aaab Construction of a word path from a Christoffel word:: @@ -1938,8 +1938,8 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.ChristoffelWord(5,8) sage: w word: 0010010100101 - sage: P = WordPaths([0,1,2,3]) - sage: P(w) + sage: P = WordPaths([0,1,2,3]) # optional - sage.modules + sage: P(w) # optional - sage.modules Path: 0010010100101 Construction of a word represented by a list from a word @@ -1967,19 +1967,19 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.FibonacciWord() sage: f = w[:100] - sage: P = WordPaths([0,1,2,3]) - sage: p = P(f); p + sage: P = WordPaths([0,1,2,3]) # optional - sage.modules + sage: p = P(f); p # optional - sage.modules Path: 0100101001001010010100100101001001010010... - sage: p.length() + sage: p.length() # optional - sage.modules 100 Creation of a word path from a FiniteWord_callable:: - sage: g = Word(lambda n:n%2, length = 100) - sage: P = WordPaths([0,1,2,3]) - sage: p = P(g); p + sage: g = Word(lambda n: n%2, length=100) + sage: P = WordPaths([0,1,2,3]) # optional - sage.modules + sage: p = P(g); p # optional - sage.modules Path: 0101010101010101010101010101010101010101... - sage: p.length() + sage: p.length() # optional - sage.modules 100 Creation of a word from a pickled function:: @@ -2215,7 +2215,7 @@ def random_element(self, *args, **kwds): TESTS:: - sage: _ = Words(GF(5),4).random_element() + sage: _ = Words(GF(5),4).random_element() # optional - sage.rings.finite_rings Check that :trac:`18283` is fixed:: diff --git a/src/sage/combinat/yang_baxter_graph.py b/src/sage/combinat/yang_baxter_graph.py index f5e5646c633..cfacceda6e1 100644 --- a/src/sage/combinat/yang_baxter_graph.py +++ b/src/sage/combinat/yang_baxter_graph.py @@ -68,7 +68,7 @@ def YangBaxterGraph(partition=None, root=None, operators=None): The ``partition`` keyword is a shorthand for the above construction:: - sage: Y = YangBaxterGraph(partition=[3,1]); Y + sage: Y = YangBaxterGraph(partition=[3,1]); Y # optional - sage.combinat Yang-Baxter graph of [3, 1], with top vertex (0, 2, 1, 0) sage: Y.vertices(sort=True) [(0, 2, 1, 0), (2, 0, 1, 0), (2, 1, 0, 0)] @@ -86,18 +86,18 @@ def YangBaxterGraph(partition=None, root=None, operators=None): sage: def left_multiplication_by(g): ....: return lambda h: h*g - sage: G = CyclicPermutationGroup(4) - sage: operators = [ left_multiplication_by(gen) for gen in G.gens() ] - sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y + sage: G = CyclicPermutationGroup(4) # optional - sage.groups + sage: operators = [ left_multiplication_by(gen) for gen in G.gens() ] # optional - sage.groups + sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y # optional - sage.groups Yang-Baxter graph with root vertex () - sage: Y.plot(edge_labels=False) # optional - sage.plot + sage: Y.plot(edge_labels=False) # optional - sage.groups sage.plot Graphics object consisting of 9 graphics primitives - sage: G = SymmetricGroup(4) - sage: operators = [left_multiplication_by(gen) for gen in G.gens()] - sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y + sage: G = SymmetricGroup(4) # optional - sage.groups + sage: operators = [left_multiplication_by(gen) for gen in G.gens()] # optional - sage.groups + sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y # optional - sage.groups Yang-Baxter graph with root vertex () - sage: Y.plot(edge_labels=False) # optional - sage.plot + sage: Y.plot(edge_labels=False) # optional - sage.groups sage.plot Graphics object consisting of 96 graphics primitives AUTHORS: @@ -361,7 +361,7 @@ def root(self): sage: Y = YangBaxterGraph(root=(1,0,3,2,1,0), operators=ops) sage: Y.root() (1, 0, 3, 2, 1, 0) - sage: Y = YangBaxterGraph(partition=[3,2]) + sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat sage: Y.root() (1, 0, 2, 1, 0) """ @@ -572,9 +572,9 @@ def __init__(self, partition): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2,1]); Y + sage: Y = YangBaxterGraph(partition=[3,2,1]); Y # optional - sage.combinat Yang-Baxter graph of [3, 2, 1], with top vertex (0, 1, 0, 2, 1, 0) - sage: loads(dumps(Y)) == Y + sage: loads(dumps(Y)) == Y # optional - sage.combinat True AUTHORS: @@ -592,8 +592,8 @@ def __repr__(self): r""" EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]) - sage: Y.__repr__() + sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat + sage: Y.__repr__() # optional - sage.combinat 'Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0)' """ return "Yang-Baxter graph of %s, with top vertex %s" % (self._partition, self._root) @@ -604,13 +604,13 @@ def __copy__(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]); Y + sage: Y = YangBaxterGraph(partition=[3,2]); Y # optional - sage.combinat Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0) - sage: B = copy(Y); B + sage: B = copy(Y); B # optional - sage.combinat Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0) - sage: Y is B + sage: Y is B # optional - sage.combinat False - sage: Y == B + sage: Y == B # optional - sage.combinat True """ from copy import copy @@ -626,10 +626,10 @@ def _digraph(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[2,1]) - sage: Y._digraph + sage: Y = YangBaxterGraph(partition=[2,1]) # optional - sage.combinat + sage: Y._digraph # optional - sage.combinat Digraph on 2 vertices - sage: Y.edges() + sage: Y.edges() # optional - sage.combinat [((0, 1, 0), (1, 0, 0), Swap positions 0 and 1)] """ digraph = super()._digraph @@ -645,8 +645,8 @@ def _vertex_ordering(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]) - sage: Y._vertex_ordering + sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat + sage: Y._vertex_ordering # optional - sage.combinat [(1, 0, 2, 1, 0), (1, 2, 0, 1, 0), (1, 2, 1, 0, 0), (2, 1, 0, 1, 0), (2, 1, 1, 0, 0)] """ return self._digraph.vertices(sort=True) @@ -661,8 +661,8 @@ def __iter__(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]) - sage: list(Y.__iter__()) + sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat + sage: list(Y.__iter__()) # optional - sage.combinat [(1, 0, 2, 1, 0), (1, 2, 0, 1, 0), (1, 2, 1, 0, 0), (2, 1, 0, 1, 0), (2, 1, 1, 0, 0)] """ for v in self._vertex_ordering: @@ -680,14 +680,14 @@ def _swap_operator(self, operator, u): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,1]) - sage: from sage.combinat.yang_baxter_graph import SwapOperator - sage: ops = [SwapOperator(i) for i in range(3)] - sage: [Y._swap_operator(op, (1,2,3,4)) for op in ops] + sage: Y = YangBaxterGraph(partition=[3,1]) # optional - sage.combinat + sage: from sage.combinat.yang_baxter_graph import SwapOperator # optional - sage.combinat + sage: ops = [SwapOperator(i) for i in range(3)] # optional - sage.combinat + sage: [Y._swap_operator(op, (1,2,3,4)) for op in ops] # optional - sage.combinat [(2, 1, 3, 4), (1, 3, 2, 4), (1, 2, 4, 3)] - sage: [Y._swap_operator(op, [4,3,2,1]) for op in ops] + sage: [Y._swap_operator(op, [4,3,2,1]) for op in ops] # optional - sage.combinat [[3, 4, 2, 1], [4, 2, 3, 1], [4, 3, 1, 2]] - sage: [Y._swap_operator(op, Permutation([1,2,3,4])) for op in ops] + sage: [Y._swap_operator(op, Permutation([1,2,3,4])) for op in ops] # optional - sage.combinat [[2, 1, 3, 4], [1, 3, 2, 4], [1, 2, 4, 3]] """ return operator(u) @@ -710,12 +710,12 @@ def vertex_relabelling_dict(self, v): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,1]) - sage: Y.vertex_relabelling_dict((1,2,3,4)) + sage: Y = YangBaxterGraph(partition=[3,1]) # optional - sage.combinat + sage: Y.vertex_relabelling_dict((1,2,3,4)) # optional - sage.combinat {(0, 2, 1, 0): (1, 2, 3, 4), (2, 0, 1, 0): (2, 1, 3, 4), (2, 1, 0, 0): (2, 3, 1, 4)} - sage: Y.vertex_relabelling_dict((4,3,2,1)) + sage: Y.vertex_relabelling_dict((4,3,2,1)) # optional - sage.combinat {(0, 2, 1, 0): (4, 3, 2, 1), (2, 0, 1, 0): (3, 4, 2, 1), (2, 1, 0, 0): (3, 2, 4, 1)} @@ -737,14 +737,14 @@ def relabel_vertices(self, v, inplace=True): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,1]); Y + sage: Y = YangBaxterGraph(partition=[3,1]); Y # optional - sage.combinat Yang-Baxter graph of [3, 1], with top vertex (0, 2, 1, 0) - sage: d = Y.relabel_vertices((1,2,3,4), inplace=False); d + sage: d = Y.relabel_vertices((1,2,3,4), inplace=False); d # optional - sage.combinat Digraph on 3 vertices - sage: Y.vertices(sort=True) + sage: Y.vertices(sort=True) # optional - sage.combinat [(0, 2, 1, 0), (2, 0, 1, 0), (2, 1, 0, 0)] - sage: e = Y.relabel_vertices((1,2,3,4)); e - sage: Y.vertices(sort=True) + sage: e = Y.relabel_vertices((1,2,3,4)); e # optional - sage.combinat + sage: Y.vertices(sort=True) # optional - sage.combinat [(1, 2, 3, 4), (2, 1, 3, 4), (2, 3, 1, 4)] """ relabelling = self.vertex_relabelling_dict(v) @@ -911,7 +911,7 @@ def __call__(self, u): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[2,2]) + sage: Y = YangBaxterGraph(partition=[2,2]) # optional - sage.combinat sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator sage: operators = [SwapIncreasingOperator(i) for i in range(3)] sage: [op((1,2,3,4)) for op in operators] From 1380e8ef236aacfd90d16b6b23729d0292440096 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 3 Jun 2023 19:51:55 -0700 Subject: [PATCH 14/26] Remove stray file --- src/sage/rings/polynomial/all__sagemath_polyhedra.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/sage/rings/polynomial/all__sagemath_polyhedra.py diff --git a/src/sage/rings/polynomial/all__sagemath_polyhedra.py b/src/sage/rings/polynomial/all__sagemath_polyhedra.py deleted file mode 100644 index e69de29bb2d..00000000000 From a8dbc7062c0d88893f99997b34c03066b3fbd289 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 11:36:07 -0700 Subject: [PATCH 15/26] sage.categories: More # optional --- src/sage/categories/homset.py | 12 ++++---- src/sage/categories/quotient_fields.py | 26 ++++++++--------- src/sage/categories/simplicial_sets.py | 40 +++++++++++++------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index a5a438f8727..46c9de2ab04 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -592,15 +592,15 @@ class Homset(Set_generic): Conversely, homsets of non-unique parents are non-unique:: - sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) - sage: H = End(P11) - sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) + sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes + sage: H = End(P11) # optional - sage.schemes + sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes False - sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) + sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes True - sage: loads(dumps(H)) is H + sage: loads(dumps(H)) is H # optional - sage.schemes False - sage: loads(dumps(H)) == H + sage: loads(dumps(H)) == H # optional - sage.schemes True """ def __init__(self, X, Y, category=None, base=None, check=True): diff --git a/src/sage/categories/quotient_fields.py b/src/sage/categories/quotient_fields.py index 181cd0ff611..2a79049bd62 100644 --- a/src/sage/categories/quotient_fields.py +++ b/src/sage/categories/quotient_fields.py @@ -496,7 +496,7 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: S. = QQ[] sage: r = t / (t^3+1)^5 - sage: r.partial_fraction_decomposition() + sage: r.partial_fraction_decomposition() # optional - sage.libs.pari (0, [-35/729/(t + 1), -35/729/(t^2 + 2*t + 1), @@ -508,37 +508,37 @@ def partial_fraction_decomposition(self, decompose_powers=True): (-1/81*t + 5/81)/(t^6 - 3*t^5 + 6*t^4 - 7*t^3 + 6*t^2 - 3*t + 1), (-2/27*t + 1/9)/(t^8 - 4*t^7 + 10*t^6 - 16*t^5 + 19*t^4 - 16*t^3 + 10*t^2 - 4*t + 1), (-2/27*t + 1/27)/(t^10 - 5*t^9 + 15*t^8 - 30*t^7 + 45*t^6 - 51*t^5 + 45*t^4 - 30*t^3 + 15*t^2 - 5*t + 1)]) - sage: sum(r.partial_fraction_decomposition()[1]) == r + sage: sum(r.partial_fraction_decomposition()[1]) == r # optional - sage.libs.pari True Some special cases:: sage: R = Frac(QQ['x']); x = R.gen() - sage: x.partial_fraction_decomposition() + sage: x.partial_fraction_decomposition() # optional - sage.libs.pari (x, []) - sage: R(0).partial_fraction_decomposition() + sage: R(0).partial_fraction_decomposition() # optional - sage.libs.pari (0, []) - sage: R(1).partial_fraction_decomposition() + sage: R(1).partial_fraction_decomposition() # optional - sage.libs.pari (1, []) - sage: (1/x).partial_fraction_decomposition() + sage: (1/x).partial_fraction_decomposition() # optional - sage.libs.pari (0, [1/x]) - sage: (1/x+1/x^3).partial_fraction_decomposition() + sage: (1/x+1/x^3).partial_fraction_decomposition() # optional - sage.libs.pari (0, [1/x, 1/x^3]) This was fixed in :trac:`16240`:: sage: R. = QQ['x'] sage: p = 1/(-x + 1) - sage: whole,parts = p.partial_fraction_decomposition() - sage: p == sum(parts) + sage: whole,parts = p.partial_fraction_decomposition() # optional - sage.libs.pari + sage: p == sum(parts) # optional - sage.libs.pari True sage: p = 3/(-x^4 + 1) - sage: whole,parts = p.partial_fraction_decomposition() - sage: p == sum(parts) + sage: whole,parts = p.partial_fraction_decomposition() # optional - sage.libs.pari + sage: p == sum(parts) # optional - sage.libs.pari True sage: p = (6*x^2 - 9*x + 5)/(-x^3 + 3*x^2 - 3*x + 1) - sage: whole,parts = p.partial_fraction_decomposition() - sage: p == sum(parts) + sage: whole,parts = p.partial_fraction_decomposition() # optional - sage.libs.pari + sage: p == sum(parts) # optional - sage.libs.pari True """ denom = self.denominator() diff --git a/src/sage/categories/simplicial_sets.py b/src/sage/categories/simplicial_sets.py index 43a13dfe473..72c49da833c 100644 --- a/src/sage/categories/simplicial_sets.py +++ b/src/sage/categories/simplicial_sets.py @@ -236,11 +236,11 @@ def base_point_map(self, domain=None): sage: g = S3.base_point_map() # optional - sage.graphs sage: f.domain() == g.domain() # optional - sage.graphs True - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs - sage: temp = simplicial_sets.Simplex(0) # optional - sage.graphs - sage: pt = temp.set_base_point(temp.n_cells(0)[0]) # optional - sage.graphs - sage: h = RP3.base_point_map(domain=pt) # optional - sage.graphs - sage: f.domain() == h.domain() # optional - sage.graphs + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs sage.groups + sage: temp = simplicial_sets.Simplex(0) # optional - sage.graphs sage.groups + sage: pt = temp.set_base_point(temp.n_cells(0)[0]) # optional - sage.graphs sage.groups + sage: h = RP3.base_point_map(domain=pt) # optional - sage.graphs sage.groups + sage: f.domain() == h.domain() # optional - sage.graphs sage.groups False sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups @@ -304,7 +304,7 @@ def fundamental_group(self, simplify=True): sage: X_1.fundamental_group().is_abelian() # optional - sage.graphs sage.groups False - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs sage.groups sage: RP3.fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < e | e^2 > @@ -431,7 +431,7 @@ def covering_map(self, character): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) + sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs sage: W = S1.wedge(S1) # optional - sage.graphs sage: G = CyclicPermutationGroup(3) # optional - sage.groups sage: a, b = W.n_cells(1) # optional - sage.graphs @@ -518,7 +518,7 @@ def cover(self, character): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) + sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs sage: W = S1.wedge(S1) # optional - sage.graphs sage: G = CyclicPermutationGroup(3) # optional - sage.groups sage: (a, b) = W.n_cells(1) # optional - sage.graphs @@ -580,20 +580,20 @@ def is_simply_connected(self): EXAMPLES:: sage: T = simplicial_sets.Torus() # optional - sage.graphs - sage: T.is_simply_connected() # optional - sage.graphs + sage: T.is_simply_connected() # optional - sage.graphs sage.groups False - sage: T.suspension().is_simply_connected() # optional - sage.graphs + sage: T.suspension().is_simply_connected() # optional - sage.graphs sage.groups True - sage: simplicial_sets.KleinBottle().is_simply_connected() # optional - sage.graphs + sage: simplicial_sets.KleinBottle().is_simply_connected() # optional - sage.graphs sage.groups False sage: S2 = simplicial_sets.Sphere(2) # optional - sage.graphs sage: S3 = simplicial_sets.Sphere(3) # optional - sage.graphs - sage: (S2.wedge(S3)).is_simply_connected() # optional - sage.graphs + sage: (S2.wedge(S3)).is_simply_connected() # optional - sage.graphs sage.groups True sage: X = S2.disjoint_union(S3) # optional - sage.graphs sage: X = X.set_base_point(X.n_cells(0)[0]) # optional - sage.graphs - sage: X.is_simply_connected() # optional - sage.graphs + sage: X.is_simply_connected() # optional - sage.graphs sage.groups False sage: C3 = groups.misc.MultiplicativeAbelian([3]) # optional - sage.graphs sage.groups @@ -642,16 +642,16 @@ def connectivity(self, max_dim=None): EXAMPLES:: - sage: simplicial_sets.Sphere(3).connectivity() # optional - sage.graphs + sage: simplicial_sets.Sphere(3).connectivity() # optional - sage.graphs sage.groups 2 - sage: simplicial_sets.Sphere(0).connectivity() # optional - sage.graphs + sage: simplicial_sets.Sphere(0).connectivity() # optional - sage.graphs sage.groups -1 sage: K = simplicial_sets.Simplex(4) # optional - sage.graphs sage: K = K.set_base_point(K.n_cells(0)[0]) # optional - sage.graphs - sage: K.connectivity() # optional - sage.graphs + sage: K.connectivity() # optional - sage.graphs sage.groups +Infinity sage: X = simplicial_sets.Torus().suspension(2) # optional - sage.graphs - sage: X.connectivity() # optional - sage.graphs + sage: X.connectivity() # optional - sage.graphs sage.groups 2 sage: C2 = groups.misc.MultiplicativeAbelian([2]) # optional - sage.graphs sage.groups @@ -747,9 +747,9 @@ def smash_product(self, *others): EXAMPLES:: sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs - sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # optional - sage.graphs - sage: X = S1.smash_product(RP2) # optional - sage.graphs - sage: X.homology(base_ring=GF(2)) # optional - sage.graphs sage.modules + sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # optional - sage.graphs sage.groups + sage: X = S1.smash_product(RP2) # optional - sage.graphs sage.groups + sage: X.homology(base_ring=GF(2)) # optional - sage.graphs sage.groups sage.modules sage.rings.finite_rings {0: Vector space of dimension 0 over Finite Field of size 2, 1: Vector space of dimension 0 over Finite Field of size 2, 2: Vector space of dimension 1 over Finite Field of size 2, From 314343129c3b02be1ece2d98a386dd26c4e6f9e1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 12:14:35 -0700 Subject: [PATCH 16/26] src/sage/combinat/cluster_algebra_quiver/cluster_seed.py: Wrap some lines of excessive length --- .../cluster_algebra_quiver/cluster_seed.py | 429 +++++++++++------- 1 file changed, 272 insertions(+), 157 deletions(-) diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index 8f8a2a9fb3c..cdfea6ab767 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -2,7 +2,7 @@ r""" ClusterSeed -A *cluster seed* is a pair `(B,\mathbf{x})` with `B` being a *skew-symmetrizable* `(n+m \times n)` *-matrix* +A *cluster seed* is a pair `(B,\mathbf{x})` with `B` being a *skew-symmetrizable* `(n+m) \times n` *-matrix* and with `\mathbf{x}` being an `n`-tuple of *independent elements* in the field of rational functions in `n` variables. For the compendium on the cluster algebra and quiver package see @@ -67,7 +67,8 @@ class ClusterSeed(SageObject): - ``data`` -- can be any of the following:: * :class:`QuiverMutationType` - * :class:`str` -- a string representing a :class:`QuiverMutationType` or a common quiver type (see Examples) + * :class:`str` -- a string representing a :class:`QuiverMutationType` + or a common quiver type (see Examples) * :class:`ClusterQuiver` * :class:`Matrix` -- a skew-symmetrizable matrix * :class:`DiGraph` -- must be the input data for a quiver @@ -130,46 +131,61 @@ class ClusterSeed(SageObject): def __init__(self, data, frozen=None, is_principal=False, user_labels=None, user_labels_prefix='x'): r""" - - Initializes the ClusterSeed ``self`` with the following range of possible attributes: - - * self._n - the number of mutable elements of the cluster seed. - * self._m - the number of immutable elements of the cluster seed. - * self._nlist - a list of mutable elements of the cluster seed. - * self._mlist - a list of immutable elements of the cluster seed. - * self._M - the 'n + m' x 'n' exchange matrix associated to the cluster seed. - * self._B - the mutable part of self._M. - * self._b_initial - the initial exchange matrix - * self._description - the description of the ClusterSeed - * self._use_fpolys - a boolean tracking whether F-polynomials and cluster variables will be tracked as part of every mutation. - * self._cluster - a list tracking the current names of cluster elements. - * self._user_labels_prefix - the prefix for every named cluster element. Defaults to 'x'. - * self._user_labels - an optional dictionary or list of user - defined names for all cluster elements. Defaults to ``'x_i'`` - for mutable elements and ``'y_i'`` for immutable elements. - All labels should be integers or alphanumeric strings. - * self._init_vars - an internal list for defining ambient the algebraic setting and naming quiver vertices. - * self._init_exch - the dictionary storing the initial mutable cluster variable names. - * self._U - the coefficient tuple of the initial cluster seed. - * self._F - the dictionary of F-polynomials. - * self._R - the ambient polynomial ring. - * self._y - the coefficient tuple for the current cluster seed. - * self._yhat - the mixed coefficient tuple appearing in Proposition 3.9 of [FZ2007] - * self._use_g_vec - a boolean stating if g-vectors for the cluster seed are being tracked. User input overridden as needed. - * self._G - the matrix containing all g-vectors. - * self._use_d_vec - a boolean stating if d-vectors for the cluster seed are being tracked. - * self._D - the matrix containing all d-vectors. - * self._bot_is_c - a boolean stating if the c-vectors are stored on the bottom of the exchange matrix M. - * self._use_c_vec - a boolean stating if c-vectors for the cluster seed are being tracked. User input overridden as needed. - * self._C - the matrix containing all c-vectors. - * self._BC - an extended matrix involving the B and C matrices used for simplifying mutation calculations. - * self._is_principal - a boolean tracking whether the ClusterSeed contains immutable elements coming from a principal extension of the mutable vertices. To be deprecated in future versions. - - * self._quiver - the ClusterQuiver corresponding to the exchange matrix self._M . - * self._mutation_type - the mutation type of self._quiver . - - * self._track_mut - a boolean tracking whether the ClusterSeed's mutation path is being recorded. - * self._mut_path - the list of integers recording the mutation path of a seed - with consecutive repeats deleted since mutations is an involution. + Initialize the ClusterSeed ``self`` with the following range of possible attributes: + + * self._n - the number of mutable elements of the cluster seed. + * self._m - the number of immutable elements of the cluster seed. + * self._nlist - a list of mutable elements of the cluster seed. + * self._mlist - a list of immutable elements of the cluster seed. + * self._M - the 'n + m' x 'n' exchange matrix associated to the cluster seed. + * self._B - the mutable part of self._M. + * self._b_initial - the initial exchange matrix + * self._description - the description of the ClusterSeed + * self._use_fpolys - a boolean tracking whether F-polynomials and cluster + variables will be tracked as part of every mutation. + * self._cluster - a list tracking the current names of cluster elements. + * self._user_labels_prefix - the prefix for every named cluster element. + Defaults to 'x'. + * self._user_labels - an optional dictionary or list of user + defined names for all cluster elements. Defaults to ``'x_i'`` + for mutable elements and ``'y_i'`` for immutable elements. + All labels should be integers or alphanumeric strings. + * self._init_vars - an internal list for defining ambient + the algebraic setting and naming quiver vertices. + * self._init_exch - the dictionary storing the initial + mutable cluster variable names. + * self._U - the coefficient tuple of the initial cluster seed. + * self._F - the dictionary of F-polynomials. + * self._R - the ambient polynomial ring. + * self._y - the coefficient tuple for the current cluster seed. + * self._yhat - the mixed coefficient tuple appearing in + Proposition 3.9 of [FZ2007] + * self._use_g_vec - a boolean stating if g-vectors for the cluster seed + are being tracked. User input overridden as needed. + * self._G - the matrix containing all g-vectors. + * self._use_d_vec - a boolean stating if d-vectors for the cluster seed + are being tracked. + * self._D - the matrix containing all d-vectors. + * self._bot_is_c - a boolean stating if the c-vectors are stored + on the bottom of the exchange matrix M. + * self._use_c_vec - a boolean stating if c-vectors for the cluster seed + are being tracked. User input overridden as needed. + * self._C - the matrix containing all c-vectors. + * self._BC - an extended matrix involving the B and C matrices used + for simplifying mutation calculations. + * self._is_principal - a boolean tracking whether the ClusterSeed + contains immutable elements coming from a principal extension + of the mutable vertices. To be deprecated in future versions. + + * self._quiver - the ClusterQuiver corresponding to the + exchange matrix ``self._M``. + * self._mutation_type - the mutation type of self._quiver . + + * self._track_mut - a boolean tracking whether the ClusterSeed's + mutation path is being recorded. + * self._mut_path - the list of integers recording the mutation path of + a seed - with consecutive repeats deleted since mutations + is an involution. TESTS:: @@ -371,16 +387,20 @@ def use_c_vectors(self, use=True, bot_is_c=False, force=False): INPUT: - ``use`` -- (default: ``True``) If ``True``, will use c-vectors - - ``bot_is_c`` -- (default: ``False``) If ``True`` and :class:`ClusterSeed` ``self`` has ``self._m == self._n``, - then will assume bottom half of the extended exchange matrix is the c-matrix. - If ``True``, lets the :class:`ClusterSeed` know c-vectors can be calculated. + - ``bot_is_c`` -- (default: ``False``) If ``True`` and + :class:`ClusterSeed` ``self`` has ``self._m == self._n``, then will + assume bottom half of the extended exchange matrix is the c-matrix. + If ``True``, lets the :class:`ClusterSeed` know c-vectors can be + calculated. EXAMPLES:: sage: S = ClusterSeed(['A',4]) - sage: S.use_c_vectors(False); S.use_g_vectors(False); S.use_fpolys(False); S.track_mutations(False) + sage: S.use_c_vectors(False); S.use_g_vectors(False) + sage: S.use_fpolys(False); S.track_mutations(False) sage: S.use_c_vectors(True) - Warning: Initializing c-vectors at this point could lead to inconsistent seed data. + Warning: Initializing c-vectors at this point + could lead to inconsistent seed data. sage: S.use_c_vectors(True, force=True) sage: S.c_matrix() @@ -390,7 +410,8 @@ def use_c_vectors(self, use=True, bot_is_c=False, force=False): [0 0 0 1] sage: S = ClusterSeed(['A',4]) - sage: S.use_c_vectors(False); S.use_g_vectors(False); S.use_fpolys(False); S.track_mutations(False) + sage: S.use_c_vectors(False); S.use_g_vectors(False) + sage: S.use_fpolys(False); S.track_mutations(False) sage: S.mutate(1) sage: S.use_c_vectors(True, force=True) sage: S.c_matrix() @@ -444,7 +465,9 @@ def use_g_vectors(self, use=True, force=False): r""" Reconstruct g-vectors from other data or initialize if no usable data exists. - Warning: Initialization may lead to inconsistent data. + .. warning:: + + Initialization may lead to inconsistent data. INPUT: @@ -485,7 +508,8 @@ def use_g_vectors(self, use=True, force=False): sage: S.mutate(1) sage: S.use_c_vectors(False) sage: S.use_g_vectors(True) - Warning: Initializing g-vectors at this point could lead to inconsistent seed data. + Warning: Initializing g-vectors at this point + could lead to inconsistent seed data. sage: S.use_g_vectors(True, force=True) sage: S.g_matrix() @@ -525,7 +549,9 @@ def use_d_vectors(self, use=True, force=False): r""" Reconstruct d-vectors from other data or initialize if no usable data exists. - Warning: Initialization may lead to inconsistent data. + .. warning:: + + Initialization may lead to inconsistent data. INPUT: @@ -576,7 +602,8 @@ def use_d_vectors(self, use=True, force=False): [ 0 1 0 0] [ 0 0 -1 0] [ 0 0 0 -1] - sage: S = ClusterSeed(['A',4]); S.use_d_vectors(True); S.mutate(1); S.d_matrix() + sage: S = ClusterSeed(['A',4]) + sage: S.use_d_vectors(True); S.mutate(1); S.d_matrix() [-1 0 0 0] [ 0 1 0 0] [ 0 0 -1 0] @@ -608,13 +635,16 @@ def use_fpolys(self, use=True, user_labels=None, user_labels_prefix=None): r""" Use F-polynomials in our Cluster Seed - Note: This will automatically try to recompute the cluster variables if possible + Note: This will automatically try to recompute the cluster variables + if possible INPUT: - ``use`` -- (default: ``True``) If ``True``, will use F-polynomials - - ``user_labels`` -- (default: ``None``) If set, will overwrite the default cluster variable labels - - ``user_labels_prefix`` -- (default: ``None``) If set, will overwrite the default + - ``user_labels`` -- (default: ``None``) If set, will overwrite the + default cluster variable labels + - ``user_labels_prefix`` -- (default: ``None``) If set, will overwrite + the default EXAMPLES:: @@ -700,9 +730,12 @@ def use_fpolys(self, use=True, user_labels=None, user_labels_prefix=None): def track_mutations(self, use=True): r""" - Begins tracking the mutation path. + Begin tracking the mutation path. + + .. warning:: - Warning: May initialize all other data to ensure that all c-, d-, and g-vectors agree on the start of mutations. + May initialize all other data to ensure that all + c-, d-, and g-vectors agree on the start of mutations. INPUT: @@ -762,7 +795,8 @@ def _sanitize_init_vars(self, user_labels, user_labels_prefix='x'): INPUT: - ``user_labels`` -- The labels that need sanitizing - - ``user_labels_prefix`` -- (default: ``'x'``) The prefix to use for labels if integers given for labels + - ``user_labels_prefix`` -- (default: ``'x'``) The prefix to use + for labels if integers given for labels EXAMPLES:: @@ -985,12 +1019,18 @@ def plot(self, circular=False, mark=None, save_pos=False, force_c=False, with_gr INPUT: - - ``circular`` -- (default: ``False``) if ``True``, the circular plot is chosen, otherwise >>spring<< is used. - - ``mark`` -- (default: ``None``) if set to i, the vertex i is highlighted. - - ``save_pos`` -- (default: ``False``) if ``True``, the positions of the vertices are saved. - - ``force_c`` -- (default: ``False``) if ``True``, will show the frozen vertices even if they were never initialized - - ``with_greens`` -- (default: ``False``) if ``True``, will display the green vertices in green - - ``add_labels`` -- (default: ``False``) if ``True``, will use the initial variables as labels + - ``circular`` -- (default: ``False``) if ``True``, the circular plot + is chosen, otherwise >>spring<< is used. + - ``mark`` -- (default: ``None``) if set to i, the vertex i is + highlighted. + - ``save_pos`` -- (default: ``False``) if ``True``, the positions + of the vertices are saved. + - ``force_c`` -- (default: ``False``) if ``True``, will show the frozen + vertices even if they were never initialized + - ``with_greens`` -- (default: ``False``) if ``True``, will display + the green vertices in green + - ``add_labels`` -- (default: ``False``) if ``True``, will use the + initial variables as labels EXAMPLES:: @@ -1023,13 +1063,20 @@ def show(self, fig_size=1, circular=False, mark=None, save_pos=False, force_c=Fa INPUT: - - ``fig_size`` -- (default: 1) factor by which the size of the plot is multiplied. - - ``circular`` -- (default: ``False``) if ``True``, the circular plot is chosen, otherwise >>spring<< is used. - - ``mark`` -- (default: ``None``) if set to i, the vertex i is highlighted. - - ``save_pos`` -- (default: ``False``) if ``True``, the positions of the vertices are saved. - - ``force_c`` -- (default: ``False``) if ``True``, will show the frozen vertices even if they were never initialized - - ``with_greens`` -- (default: ``False``) if ``True``, will display the green vertices in green - - ``add_labels`` -- (default: ``False``) if ``True``, will use the initial variables as labels + - ``fig_size`` -- (default: 1) factor by which the size of the plot + is multiplied. + - ``circular`` -- (default: ``False``) if ``True``, the circular plot + is chosen, otherwise >>spring<< is used. + - ``mark`` -- (default: ``None``) if set to i, the vertex i is + highlighted. + - ``save_pos`` -- (default: ``False``) if ``True``, the positions + of the vertices are saved. + - ``force_c`` -- (default: ``False``) if ``True``, will show the frozen + vertices even if they were never initialized + - ``with_greens`` -- (default: ``False``) if ``True``, will display the + green vertices in green + - ``add_labels`` -- (default: ``False``) if ``True``, will use the + initial variables as labels TESTS:: @@ -1080,9 +1127,11 @@ def save_image(self, filename, circular=False, mark=None, save_pos=False): INPUT: - ``filename`` -- the filename the image is saved to. - - ``circular`` -- (default: ``False``) if ``True``, the circular plot is chosen, otherwise >>spring<< is used. + - ``circular`` -- (default: ``False``) if ``True``, the circular plot + is chosen, otherwise >>spring<< is used. - ``mark`` -- (default: ``None``) if set to i, the vertex i is highlighted. - - ``save_pos`` -- (default: ``False``) if ``True``, the positions of the vertices are saved. + - ``save_pos`` -- (default: ``False``) if ``True``, the positions + of the vertices are saved. EXAMPLES:: @@ -1416,9 +1465,11 @@ def f_polynomial(self, k): Return the ``k``-th *F-polynomial* of ``self``. It is obtained from the ``k``-th cluster variable by setting all `x_i` to `1`. - Warning: this method assumes the sign-coherence conjecture and that the - input seed is sign-coherent (has an exchange matrix with columns of like signs). - Otherwise, computational errors might arise. + .. warning:: + + This method assumes the sign-coherence conjecture and that the + input seed is sign-coherent (has an exchange matrix with columns of like signs). + Otherwise, computational errors might arise. EXAMPLES:: @@ -1463,9 +1514,11 @@ def f_polynomials(self): Return all *F-polynomials* of ``self``. These are obtained from the cluster variables by setting all `x_i`'s to `1`. - Warning: this method assumes the sign-coherence conjecture and that the - input seed is sign-coherent (has an exchange matrix with columns of like signs). - Otherwise, computational errors might arise. + .. warning:: + + This method assumes the sign-coherence conjecture and that the + input seed is sign-coherent (has an exchange matrix with columns of like signs). + Otherwise, computational errors might arise. EXAMPLES:: @@ -1482,9 +1535,11 @@ def g_vector(self, k): Return the ``k``-th *g-vector* of ``self``. This is the degree vector of the ``k``-th cluster variable after setting all `y_i`'s to `0`. - Warning: this method assumes the sign-coherence conjecture and that the - input seed is sign-coherent (has an exchange matrix with columns of like signs). - Otherwise, computational errors might arise. + .. warning:: + + This method assumes the sign-coherence conjecture and that the + input seed is sign-coherent (has an exchange matrix with columns of like signs). + Otherwise, computational errors might arise. EXAMPLES:: @@ -1520,9 +1575,11 @@ def g_matrix(self, show_warnings=True): Return the matrix of all *g-vectors* of ``self``. These are the degree vectors of the cluster variables after setting all `y_i`'s to `0`. - Warning: this method assumes the sign-coherence conjecture and that the - input seed is sign-coherent (has an exchange matrix with columns of like signs). - Otherwise, computational errors might arise. + .. warning:: + + This method assumes the sign-coherence conjecture and that the + input seed is sign-coherent (has an exchange matrix with columns of like signs). + Otherwise, computational errors might arise. EXAMPLES:: @@ -1622,9 +1679,11 @@ def c_vector(self, k): ``k``-th column vector of the bottom part of the ``B``-matrix of ``self``. - Warning: this method assumes the sign-coherence conjecture and that the - input seed is sign-coherent (has an exchange matrix with columns of like signs). - Otherwise, computational errors might arise. + .. warning:: + + This method assumes the sign-coherence conjecture and that the + input seed is sign-coherent (has an exchange matrix with columns of like signs). + Otherwise, computational errors might arise. EXAMPLES:: @@ -1657,9 +1716,11 @@ def c_matrix(self, show_warnings=True): r""" Return all *c-vectors* of ``self``. - Warning: this method assumes the sign-coherence conjecture and that the - input seed is sign-coherent (has an exchange matrix with columns of like signs). - Otherwise, computational errors might arise. + .. warning:: + + This method assumes the sign-coherence conjecture and that the + input seed is sign-coherent (has an exchange matrix with columns of like signs). + Otherwise, computational errors might arise. EXAMPLES:: @@ -1892,7 +1953,8 @@ def is_bipartite(self, return_bipartition=False): INPUT: - - ``return_bipartition`` -- (default: ``False``) if ``True``, the bipartition is returned in the case of ``self`` being bipartite. + - ``return_bipartition`` -- (default: ``False``) if ``True``, the + bipartition is returned in the case of ``self`` being bipartite. EXAMPLES:: @@ -2221,7 +2283,8 @@ def mutate(self, sequence, inplace=True, input_type=None): - ``"green"``: mutates at the first green vertex, - ``"red"``: mutates at the first red vertex, - ``"urban_renewal"`` or ``"urban"``: mutates at first urban renewal vertex, - - ``"all_urban_renewals"`` or ``"all_urban"``: mutates at all urban renewal vertices. + - ``"all_urban_renewals"`` or ``"all_urban"``: mutates at all + urban renewal vertices. For ``input_type``, if no value is given, preference will be given to vertex names, then indices, then cluster variables. @@ -2643,13 +2706,18 @@ def mutation_sequence(self, sequence, show_sequence=False, INPUT: - ``sequence`` -- an iterable of vertices of self. - - ``show_sequence`` -- (default: ``False``) if ``True``, a png containing the associated quivers is shown. - - ``fig_size`` -- (default: 1.2) factor by which the size of the plot is multiplied. - - ``return_output`` -- (default: 'seed') determines what output is to be returned:: - - * if ``'seed'``, outputs all the cluster seeds obtained by the ``sequence`` of mutations. + - ``show_sequence`` -- (default: ``False``) if ``True``, a png + containing the associated quivers is shown. + - ``fig_size`` -- (default: 1.2) factor by which the size of + the plot is multiplied. + - ``return_output`` -- (default: 'seed') determines what output + is to be returned:: + + * if ``'seed'``, outputs all the cluster seeds obtained + by the ``sequence`` of mutations. * if ``'matrix'``, outputs a list of exchange matrices. - * if ``'var'``, outputs a list of new cluster variables obtained at each step. + * if ``'var'``, outputs a list of new cluster variables obtained + at each step. EXAMPLES:: @@ -2693,11 +2761,14 @@ def mutation_analysis(self, options=['all'], filter=None): r""" Runs an analysis of all potential mutation options. Note that this might take a long time on large seeds. - Notes: Edges are only returned if we have a non-valued quiver. Green and red vertices are only returned if the cluster is principal. + .. note:: + + Edges are only returned if we have a non-valued quiver. + Green and red vertices are only returned if the cluster is principal. INPUT: - - ``options`` -- (default: [``'all'``]) a list of mutation options. + - ``options`` -- (default: ``['all']``) a list of mutation options. - ``filter`` -- (default: ``None``) A vertex or interval of vertices to limit our search to Possible options are: @@ -3140,14 +3211,17 @@ def reorient(self, data): Reorients ``self`` with respect to the given total order, or with respect to an iterator of ordered pairs. - WARNING: + .. warning:: - - This operation might change the mutation type of ``self``. - - Ignores ordered pairs `(i,j)` for which neither `(i,j)` nor `(j,i)` is an edge of ``self``. + - This operation might change the mutation type of ``self``. + - Ignores ordered pairs `(i,j)` for which neither `(i,j)` nor `(j,i)` + is an edge of ``self``. INPUT: - - ``data`` -- an iterator defining a total order on ``self.vertices()``, or an iterator of ordered pairs in ``self`` defining the new orientation of these edges. + - ``data`` -- an iterator defining a total order on ``self.vertices()``, + or an iterator of ordered pairs in ``self`` defining the new + orientation of these edges. EXAMPLES:: @@ -3178,7 +3252,9 @@ def set_cluster(self, cluster, force=False): r""" Sets the cluster for ``self`` to ``cluster``. - Warning: Initialization may lead to inconsistent data. + .. warning:: + + Initialization may lead to inconsistent data. INPUT: @@ -3274,9 +3350,13 @@ def reset_coefficients(self): r""" Reset the coefficients of ``self`` to the frozen variables but keep the current cluster. - This raises an error if the number of frozen variables is different than the number of exchangeable variables. + This raises an error if the number of frozen variables is different + from the number of exchangeable variables. - WARNING: This command to be phased out since :meth:`use_c_vectors` does this more effectively. + .. warning:: + + This command to be phased out since :meth:`use_c_vectors` + does this more effectively. EXAMPLES:: @@ -3330,11 +3410,17 @@ def mutation_class_iter(self, depth=infinity, show_depth=False, INPUT: - - ``depth`` -- (default: infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned. - - ``show_depth`` -- (default: ``False``) if ``True``, the current depth of the mutation is shown while computing. - - ``return_paths`` -- (default: ``False``) if ``True``, a shortest path of mutations from ``self`` to the given quiver is returned as well. - - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only one seed up to simultaneous permutation of rows and columns of the exchange matrix is recorded. - - ``sink_source`` -- (default: ``False``) if ``True``, only mutations at sinks and sources are applied. + - ``depth`` -- (default: infinity) integer or infinity, only seeds with + distance at most ``depth`` from ``self`` are returned. + - ``show_depth`` -- (default: ``False``) if ``True``, the current depth + of the mutation is shown while computing. + - ``return_paths`` -- (default: ``False``) if ``True``, a shortest path + of mutations from ``self`` to the given quiver is returned as well. + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only one + seed up to simultaneous permutation of rows and columns of the + exchange matrix is recorded. + - ``sink_source`` -- (default: ``False``) if ``True``, only mutations + at sinks and sources are applied. EXAMPLES: @@ -3559,9 +3645,13 @@ def cluster_class_iter(self, depth=infinity, show_depth=False, up_to_equivalence INPUT: - - ``depth`` -- (default: infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned - - ``show_depth`` -- (default: ``False``) if ``True``, ignored if ``depth`` is set; returns the depth of the mutation class, i.e., the maximal distance from ``self`` of an element in the mutation class - - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only clusters up to equivalence are considered. + - ``depth`` -- (default: infinity) integer or infinity, only seeds with + distance at most ``depth`` from ``self`` are returned + - ``show_depth`` -- (default: ``False``) if ``True``, ignored if + ``depth`` is set; returns the depth of the mutation class, i.e., the + maximal distance from ``self`` of an element in the mutation class + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only + clusters up to equivalence are considered. EXAMPLES: @@ -3655,9 +3745,13 @@ def cluster_class(self, depth=infinity, show_depth=False, up_to_equivalence=True INPUT: - - ``depth`` -- (default: infinity) integer, only seeds with distance at most ``depth`` from ``self`` are returned - - ``return_depth`` -- (default: ``False``) - if ``True``, ignored if ``depth`` is set; returns the depth of the mutation class, i.e., the maximal distance from ``self`` of an element in the mutation class - - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only clusters up to equivalence are considered. + - ``depth`` -- (default: infinity) integer, only seeds with distance + at most ``depth`` from ``self`` are returned + - ``return_depth`` -- (default: ``False``) - if ``True``, ignored if + ``depth`` is set; returns the depth of the mutation class, i.e., + the maximal distance from ``self`` of an element in the mutation class + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only + clusters up to equivalence are considered. EXAMPLES: @@ -3678,8 +3772,10 @@ def b_matrix_class_iter(self, depth=infinity, up_to_equivalence=True): INPUT: - - ``depth`` -- (default:infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned - - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only `B`-matrices up to equivalence are considered. + - ``depth`` -- (default:infinity) integer or infinity, only seeds + with distance at most ``depth`` from ``self`` are returned + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only + `B`-matrices up to equivalence are considered. EXAMPLES: @@ -3782,8 +3878,10 @@ def b_matrix_class(self, depth=infinity, up_to_equivalence=True): INPUT: - - ``depth`` -- (default: infinity) integer or infinity, only seeds with distance at most ``depth`` from ``self`` are returned - - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only `B`-matrices up to equivalence are considered. + - ``depth`` -- (default: infinity) integer or infinity, only seeds + with distance at most ``depth`` from ``self`` are returned + - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only + `B`-matrices up to equivalence are considered. EXAMPLES: @@ -3805,8 +3903,10 @@ def variable_class_iter(self, depth=infinity, ignore_bipartite_belt=False): INPUT: - - ``depth`` -- (default: infinity) integer, only seeds with distance at most ``depth`` from ``self`` are returned - - ``ignore_bipartite_belt`` -- (default: ``False``) if ``True``, the algorithm does not use the bipartite belt + - ``depth`` -- (default: infinity) integer, only seeds with distance + at most ``depth`` from ``self`` are returned + - ``ignore_bipartite_belt`` -- (default: ``False``) if ``True``, + the algorithm does not use the bipartite belt EXAMPLES: @@ -3829,7 +3929,8 @@ def variable_class_iter(self, depth=infinity, ignore_bipartite_belt=False): sage: it = S.variable_class_iter(depth=1) sage: for T in it: print(T) - Found a bipartite seed - restarting the depth counter at zero and constructing the variable class using its bipartite belt. + Found a bipartite seed - restarting the depth counter at zero + and constructing the variable class using its bipartite belt. x0 x1 x2 @@ -3840,9 +3941,10 @@ def variable_class_iter(self, depth=infinity, ignore_bipartite_belt=False): (x0*x2 + 1)/x1 (x0*x2 + x1 + 1)/(x1*x2) - Note that the notion of *depth* depends on whether a bipartite seed is found or not, or if it is manually ignored:: + Note that the notion of *depth* depends on whether a bipartite seed + is found or not, or if it is manually ignored:: - sage: it = S.variable_class_iter(depth=1,ignore_bipartite_belt=True) + sage: it = S.variable_class_iter(depth=1, ignore_bipartite_belt=True) sage: for T in it: print(T) x0 x1 @@ -3866,7 +3968,8 @@ def variable_class_iter(self, depth=infinity, ignore_bipartite_belt=False): sage: S = ClusterSeed(['A',[1,1],1]) sage: it = S.variable_class_iter(depth=2) sage: for T in it: print(T) - Found a bipartite seed - restarting the depth counter at zero and constructing the variable class using its bipartite belt. + Found a bipartite seed - restarting the depth counter at zero + and constructing the variable class using its bipartite belt. x0 x1 (x1^2 + 1)/x0 @@ -3931,8 +4034,10 @@ def variable_class(self, depth=infinity, ignore_bipartite_belt=False): INPUT: - - ``depth`` -- (default: infinity) integer, only seeds with distance at most ``depth`` from ``self`` are returned - - ``ignore_bipartite_belt`` -- (default: ``False``) if ``True``, the algorithms does not use the bipartite belt + - ``depth`` -- (default: infinity) integer, only seeds with distance + at most ``depth`` from ``self`` are returned + - ``ignore_bipartite_belt`` -- (default: ``False``) if ``True``, the + algorithm does not use the bipartite belt EXAMPLES: @@ -3980,18 +4085,21 @@ def is_mutation_finite(self, nr_of_checks=None, return_path=False): INPUT: - - ``nr_of_checks`` -- (default: ``None``) number of mutations applied. Standard is 500*(number of vertices of ``self``). - - ``return_path`` -- (default: ``False``) if ``True``, in case of ``self`` not being mutation finite, - a path from ``self`` to a quiver with an edge label `(a,-b)` and `a*b > 4` is returned. + - ``nr_of_checks`` -- (default: ``None``) number of mutations applied. + Standard is 500 times the number of vertices of ``self``. + - ``return_path`` -- (default: ``False``) if ``True``, in case of + ``self`` not being mutation finite, a path from ``self`` to a quiver + with an edge label `(a,-b)` and `a*b > 4` is returned. ALGORITHM: - - A cluster seed is mutation infinite if and only if every `b_{ij}*b_{ji} > -4`. Thus, we apply random mutations in random directions + - A cluster seed is mutation infinite if and only if every + `b_{ij}*b_{ji} > -4`. Thus, we apply random mutations in random directions - WARNING: + .. warning:: - - Uses a non-deterministic method by random mutations in various directions. - - In theory, it can return a wrong True. + - Uses a non-deterministic method by random mutations in various directions. + - In theory, it can return a wrong ``True``. EXAMPLES:: @@ -4012,18 +4120,21 @@ def is_mutation_finite(self, nr_of_checks=None, return_path=False): def mutation_type(self): r""" - Return the mutation_type of each connected component of ``self``, if it can be determined. + Return the mutation type of each connected component of ``self``, if it can be determined. + Otherwise, the mutation type of this component is set to be unknown. The mutation types of the components are ordered by vertex labels. - WARNING: + .. warning:: - - All finite types can be detected, - - All affine types can be detected, EXCEPT affine type D (the algorithm is not yet implemented) - - All exceptional types can be detected. + - All finite types can be detected, + - All affine types can be detected, **except** affine type D + (the algorithm is not yet implemented) + - All exceptional types can be detected. - - Might fail to work if it is used within different Sage processes simultaneously (that happened in the doctesting). + - Might fail to work if it is used within different Sage processes + simultaneously (that happened in the doctesting). EXAMPLES: @@ -4168,8 +4279,7 @@ def greedy(self, a1, a2, algorithm='by_recursion'): def oriented_exchange_graph(self): """ - Return the oriented exchange graph of ``self`` as a directed - graph. + Return the oriented exchange graph of ``self`` as a directed graph. The seed must be a cluster seed for a cluster algebra of finite type with principal coefficients (the corresponding @@ -4352,7 +4462,8 @@ def get_upper_cluster_algebra_element(self,a): INPUT: - - `B` -- a skew-symmetric matrix. Must have the same number of columns as the length of the vectors in `vd`. + - ``B`` -- a skew-symmetric matrix. Must have the same number of columns + as the length of the vectors in `vd`. - ``a`` -- a vector in `\ZZ^n` where `n` is the number of columns in `B`. OUTPUT: @@ -4401,7 +4512,7 @@ def LLM_gen_set(self, size_limit=-1): INPUT: - - `B` -- a skew-symmetric matrix. + - ``B`` -- a skew-symmetric matrix. - ``size_limit`` -- a limit on how many vectors you want the function to return. @@ -4444,9 +4555,11 @@ def _compute_compatible_vectors(self, vd): INPUT: - - `B` -- a skew-symmetric matrix. Must have the same number of columns as the length of the vectors in ``vd``. + - ``B`` -- a skew-symmetric matrix. Must have the same number of columns + as the length of the vectors in ``vd``. - ``vd`` -- a collection of tuples `(v,z)` with `v \in \{0,1\}^n` and `z \in \ZZ`. - `n` must be the number of columns in `B`. Taken from the output of vector_decomposition. + `n` must be the number of columns in `B`. Taken from the output of + :func:`_vector_decomposition`. OUTPUT: @@ -4651,11 +4764,12 @@ def coeff_recurs(p, q, a1, a2, b, c): def PathSubset(n, m): r""" - Encodes a *maximal* Dyck path from (0,0) to (n,m) (for n >= m >= 0) as a subset of {0,1,2,..., 2n-1}. + Encode a *maximal* Dyck path from `(0,0)` to `(n,m)` (for `n \geq m \geq 0`) as a subset of `\{0,1,2,..., 2n-1\}`. + The encoding is given by indexing horizontal edges by odd numbers and vertical edges by evens. - The horizontal between (i,j) and (i+1,j) is indexed by the odd number 2*i+1. - The vertical between (i,j) and (i,j+1) is indexed by the even number 2*j. + The horizontal between `(i,j)` and `(i+1,j)` is indexed by the odd number `2*i+1`. + The vertical between `(i,j)` and `(i,j+1)` is indexed by the even number `2*j`. EXAMPLES:: @@ -4681,7 +4795,7 @@ def PathSubset(n, m): def SetToPath(T): r""" - Rearranges the encoding for a *maximal* Dyck path (as a set) so that it is a list in the proper order of the edges. + Rearrange the encoding for a *maximal* Dyck path (as a set) so that it is a list in the proper order of the edges. EXAMPLES:: @@ -4711,8 +4825,7 @@ def SetToPath(T): def is_LeeLiZel_allowable(T,n,m,b,c): """ - Check if the subset T contributes to the computation of the greedy - element x[m,n] in the rank two (b,c)-cluster algebra. + Check if the subset `T` contributes to the computation of the greedy element `x[m,n]` in the rank two `(b,c)`-cluster algebra. This uses the conditions of Lee-Li-Zelevinsky's paper [LLZ2014]_. @@ -4772,7 +4885,9 @@ def is_LeeLiZel_allowable(T,n,m,b,c): def get_green_vertices(C): r""" - Get the green vertices from a matrix. Will go through each column and return + Get the green vertices from a matrix. + + Will go through each column and return the ones where no entry is greater than 0. INPUT: From c5568c2ee9ca26f7709dd0aa6baf36695f052f26 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 13:22:20 -0700 Subject: [PATCH 17/26] src/sage/combinat/cluster_algebra_quiver/cluster_seed.py: Fix markup --- src/sage/combinat/cluster_algebra_quiver/cluster_seed.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index cdfea6ab767..b3719392b7c 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -67,11 +67,16 @@ class ClusterSeed(SageObject): - ``data`` -- can be any of the following:: * :class:`QuiverMutationType` + * :class:`str` -- a string representing a :class:`QuiverMutationType` or a common quiver type (see Examples) + * :class:`ClusterQuiver` + * :class:`Matrix` -- a skew-symmetrizable matrix + * :class:`DiGraph` -- must be the input data for a quiver + * List of edges -- must be the edge list of a digraph for a quiver EXAMPLES:: From 0f18153d2c105d6fc7e9a77eccbdfc424b9f2948 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 17:44:20 -0700 Subject: [PATCH 18/26] src/sage/combinat/posets: Fix # optional --- src/sage/combinat/posets/d_complete.py | 2 +- src/sage/combinat/posets/hasse_diagram.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/combinat/posets/d_complete.py b/src/sage/combinat/posets/d_complete.py index 2b603aeac2b..efd9b36b335 100644 --- a/src/sage/combinat/posets/d_complete.py +++ b/src/sage/combinat/posets/d_complete.py @@ -151,7 +151,7 @@ def get_hooks(self): {0: 1, 1: 2, 2: 2, 3: 3} sage: from sage.combinat.posets.poset_examples import Posets sage: YDP321 = Posets.YoungDiagramPoset(Partition([3,2,1])) # optional - sage.combinat - sage: P = DCompletePoset(YDP321)._hasse_diagram.reverse()) # optional - sage.combinat + sage: P = DCompletePoset(YDP321)._hasse_diagram.reverse() # optional - sage.combinat sage: P.get_hooks() # optional - sage.combinat {0: 5, 1: 3, 2: 1, 3: 3, 4: 1, 5: 1} """ diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index 84364c149d7..eb223bb1036 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -1169,7 +1169,7 @@ def coxeter_transformation(self, algorithm='cython'): [-1 1 1 0 -1] [-1 1 0 1 -1] sage: P.__dict__['coxeter_transformation'].clear_cache() # optional - sage.libs.flint sage.modules - sage: P.coxeter_transformation(algorithm="matrix") == M # optional - sage.modules + sage: P.coxeter_transformation(algorithm="matrix") == M # optional - sage.libs.flint sage.modules True TESTS:: @@ -2167,7 +2167,7 @@ def find_nonsemimodular_pair(self, upper): INPUT: - - upper, a Boolean -- if ``True``, test whether the lattice is + - ``upper``, a Boolean -- if ``True``, test whether the lattice is upper semimodular; otherwise test whether the lattice is lower semimodular. From 0b50e1a654f0f2e588b80a7e5cc0894a9bce0777 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 17:51:32 -0700 Subject: [PATCH 19/26] src/sage/combinat/root_system/plot.py: Fix doctest --- src/sage/combinat/root_system/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/root_system/plot.py b/src/sage/combinat/root_system/plot.py index 90bab1e8ac0..be6626e40fc 100644 --- a/src/sage/combinat/root_system/plot.py +++ b/src/sage/combinat/root_system/plot.py @@ -592,7 +592,7 @@ sage: L = RootSystem(["B",3,1]).ambient_space() sage: w3 = [0,2,1,3,2,0,2,1,0,2,3,1,2,1,3,2,0,2,0,1,2,0] sage: (L.plot_fundamental_weights() # optional - sage.plot sage.symbolic - ....: + L.plot_reflection_hyperplanes(bounding_box=2) + L.plot_alcove_walk(w3) + ....: + L.plot_reflection_hyperplanes(bounding_box=2) + L.plot_alcove_walk(w3)) Graphics3d Object .. PLOT:: From 2710137a94f627cba76846f690da442a63320b33 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 19:04:12 -0700 Subject: [PATCH 20/26] src/sage/combinat/cluster_algebra_quiver/cluster_seed.py: Fix markup --- src/sage/combinat/cluster_algebra_quiver/cluster_seed.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index b3719392b7c..ae93b3e67af 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -2711,16 +2711,21 @@ def mutation_sequence(self, sequence, show_sequence=False, INPUT: - ``sequence`` -- an iterable of vertices of self. + - ``show_sequence`` -- (default: ``False``) if ``True``, a png containing the associated quivers is shown. + - ``fig_size`` -- (default: 1.2) factor by which the size of the plot is multiplied. - - ``return_output`` -- (default: 'seed') determines what output - is to be returned:: + + - ``return_output`` -- (default: ``'seed'``) determines what output + is to be returned: * if ``'seed'``, outputs all the cluster seeds obtained by the ``sequence`` of mutations. + * if ``'matrix'``, outputs a list of exchange matrices. + * if ``'var'``, outputs a list of new cluster variables obtained at each step. From 2b0992da4ecf5db0f7630d0c642a4c2b382ce961 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 8 Jun 2023 09:20:09 -0700 Subject: [PATCH 21/26] src/sage/combinat/posets/d_complete.py: Fix up doctest --- src/sage/combinat/posets/d_complete.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/posets/d_complete.py b/src/sage/combinat/posets/d_complete.py index efd9b36b335..80cff74eb5c 100644 --- a/src/sage/combinat/posets/d_complete.py +++ b/src/sage/combinat/posets/d_complete.py @@ -151,7 +151,7 @@ def get_hooks(self): {0: 1, 1: 2, 2: 2, 3: 3} sage: from sage.combinat.posets.poset_examples import Posets sage: YDP321 = Posets.YoungDiagramPoset(Partition([3,2,1])) # optional - sage.combinat - sage: P = DCompletePoset(YDP321)._hasse_diagram.reverse() # optional - sage.combinat + sage: P = DCompletePoset(YDP321._hasse_diagram.reverse()) # optional - sage.combinat sage: P.get_hooks() # optional - sage.combinat {0: 5, 1: 3, 2: 1, 3: 3, 4: 1, 5: 1} """ From 6b97c825c90a5d658ccfb085fed999195073ac5d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 09:18:06 -0700 Subject: [PATCH 22/26] src/sage/combinat/k_regular_sequence.py: Use file-level annotation for # optional - sage.symbolic --- src/sage/combinat/k_regular_sequence.py | 252 ++++++++++++------------ 1 file changed, 126 insertions(+), 126 deletions(-) diff --git a/src/sage/combinat/k_regular_sequence.py b/src/sage/combinat/k_regular_sequence.py index a170582116f..454e064868b 100644 --- a/src/sage/combinat/k_regular_sequence.py +++ b/src/sage/combinat/k_regular_sequence.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.modules +# sage.doctest: optional - sage.combinat sage.modules sage.symbolic r""" `k`-regular Sequences @@ -331,17 +331,17 @@ def subsequence(self, a, b): We check if the linear representation of the subsequences above indeed represent the correct vector valued sequences:: - sage: var('n') # optional - sage.symbolic + sage: var('n') n sage: def v(n): ....: return vector([3*n + 1, 6*n + 1]) - sage: S31.mu[0] * v(n) == v(2*n) # optional - sage.symbolic + sage: S31.mu[0] * v(n) == v(2*n) True - sage: S31.mu[1] * v(n) == v(2*n + 1) # optional - sage.symbolic + sage: S31.mu[1] * v(n) == v(2*n + 1) True - sage: function('delta_0') # optional - sage.symbolic + sage: function('delta_0') delta_0 sage: def simplify_delta(expr): @@ -349,17 +349,17 @@ def subsequence(self, a, b): sage: def v(n): ....: return vector([n -1 + delta_0(n), 2*n - 1 + delta_0(n), 4*n + 1]) - sage: simplify_delta(v(2*n) - Srs.mu[0]*v(n)).is_zero() # optional - sage.symbolic + sage: simplify_delta(v(2*n) - Srs.mu[0]*v(n)).is_zero() True - sage: simplify_delta(v(2*n + 1) - Srs.mu[1]*v(n)).is_zero() # optional - sage.symbolic + sage: simplify_delta(v(2*n + 1) - Srs.mu[1]*v(n)).is_zero() True sage: def v(n): ....: return vector([1 - delta_0(n), 1]) - sage: simplify_delta(v(2*n) - Sbd.mu[0]*v(n)).is_zero() # optional - sage.symbolic + sage: simplify_delta(v(2*n) - Sbd.mu[0]*v(n)).is_zero() True - sage: simplify_delta(v(2*n + 1) - Sbd.mu[1]*v(n)).is_zero() # optional - sage.symbolic + sage: simplify_delta(v(2*n + 1) - Sbd.mu[1]*v(n)).is_zero() True We check some corner-cases:: @@ -934,11 +934,11 @@ def from_recurrence(self, *args, **kwds): :: sage: Seq2 = kRegularSequenceSpace(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f - sage: Seq2.from_recurrence([ # optional - sage.symbolic + sage: Seq2.from_recurrence([ ....: f(2*n) == 2*f(n), f(2*n + 1) == 3*f(n) + 4*f(n - 1), ....: f(0) == 0, f(1) == 1], f, n) 2-regular sequence 0, 0, 0, 1, 2, 3, 4, 10, 6, 17, ... @@ -1022,26 +1022,26 @@ def from_recurrence(self, *args, **kwds): Stern--Brocot Sequence:: sage: Seq2 = kRegularSequenceSpace(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f - sage: SB = Seq2.from_recurrence([ # optional - sage.symbolic + sage: SB = Seq2.from_recurrence([ ....: f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], f, n) - sage: SB # optional - sage.symbolic + sage: SB 2-regular sequence 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, ... Number of Odd Entries in Pascal's Triangle:: - sage: Seq2.from_recurrence([ # optional - sage.symbolic + sage: Seq2.from_recurrence([ ....: f(2*n) == 3*f(n), f(2*n + 1) == 2*f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], f, n) 2-regular sequence 0, 1, 3, 5, 9, 11, 15, 19, 27, 29, ... Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: UB = Seq2.from_recurrence([ # optional - sage.symbolic + sage: UB = Seq2.from_recurrence([ ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -1055,20 +1055,20 @@ def from_recurrence(self, *args, **kwds): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3) - sage: UB # optional - sage.symbolic + sage: UB 2-regular sequence 1, 2, 2, 4, 2, 4, 6, 0, 4, 4, ... Binary sum of digits `S(n)`, characterized by the recurrence relations `S(4n) = S(2n)`, `S(4n + 1) = S(2n + 1)`, `S(4n + 2) = S(2n + 1)` and `S(4n + 3) = -S(2n) + 2S(2n + 1)`:: - sage: S = Seq2.from_recurrence([ # optional - sage.symbolic + sage: S = Seq2.from_recurrence([ ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n + 1), ....: f(4*n + 2) == f(2*n + 1), ....: f(4*n + 3) == -f(2*n) + 2*f(2*n + 1), ....: f(0) == 0, f(1) == 1], f, n) - sage: S # optional - sage.symbolic + sage: S 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ... In order to check if this sequence is indeed the binary sum of digits, @@ -1078,7 +1078,7 @@ def from_recurrence(self, *args, **kwds): sage: S2 = Seq2( ....: (Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [1, 1]])), ....: left=vector([0, 1]), right=vector([1, 0])) - sage: (S - S2).is_trivial_zero() # optional - sage.symbolic + sage: (S - S2).is_trivial_zero() True Alternatively, we can also use the simpler but inhomogeneous recurrence relations @@ -1096,13 +1096,13 @@ def from_recurrence(self, *args, **kwds): Number of Non-Zero Elements in the Generalized Pascal's Triangle (see [LRS2017]_):: sage: Seq2 = kRegularSequenceSpace(2, QQ) - sage: P = Seq2.from_recurrence([ # optional - sage.symbolic + sage: P = Seq2.from_recurrence([ ....: f(4*n) == 5/3*f(2*n) - 1/3*f(2*n + 1), ....: f(4*n + 1) == 4/3*f(2*n) + 1/3*f(2*n + 1), ....: f(4*n + 2) == 1/3*f(2*n) + 4/3*f(2*n + 1), ....: f(4*n + 3) == -1/3*f(2*n) + 5/3*f(2*n + 1), ....: f(0) == 1, f(1) == 2], f, n) - sage: P # optional - sage.symbolic + sage: P 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ... Finally, the same sequence can also be obtained via direct parameters @@ -1118,7 +1118,7 @@ def from_recurrence(self, *args, **kwds): TESTS:: - sage: Seq2.from_recurrence([ # long time # optional - sage.symbolic + sage: Seq2.from_recurrence([ # long time ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n), ....: f(4*n + 2) == f(2*n), @@ -1130,7 +1130,7 @@ def from_recurrence(self, *args, **kwds): :: - sage: S = Seq2.from_recurrence([ # optional - sage.symbolic + sage: S = Seq2.from_recurrence([ ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n), ....: f(4*n + 2) == f(2*n), @@ -1139,7 +1139,7 @@ def from_recurrence(self, *args, **kwds): ....: f(5) == 5, f(6) == 6, f(7) == 7, f(16) == 4, f(18) == 4, ....: f(20) == 4, f(22) == 4, f(24) == 6, f(26) == 6, f(28) == 6], ....: f, n, offset=2) - sage: all([S[4*i] == S[2*i] and # optional - sage.symbolic + sage: all([S[4*i] == S[2*i] and ....: S[4*i + 1] == S[2*i] and ....: S[4*i + 2] == S[2*i] and ....: S[4*i + 3] == S[2*i + 16] for i in srange(2, 100)]) @@ -1147,7 +1147,7 @@ def from_recurrence(self, *args, **kwds): :: - sage: S = Seq2.from_recurrence([ # optional - sage.symbolic + sage: S = Seq2.from_recurrence([ ....: f(4*n) == f(2*n), ....: f(4*n + 1) == f(2*n), ....: f(4*n + 2) == f(2*n), @@ -1160,7 +1160,7 @@ def from_recurrence(self, *args, **kwds): ....: f(22) == 22, f(23) == 23, f(24) == 24, f(25) == 25, ....: f(26) == 26, f(27) == 27, f(28) == 28, f(29) == 29, ....: f(30) == 30, f(31) == 31], f, n, offset=8) - sage: all([S[4*i] == S[2*i] and # optional - sage.symbolic + sage: all([S[4*i] == S[2*i] and ....: S[4*i + 1] == S[2*i] and ....: S[4*i + 2] == S[2*i] and ....: S[4*i + 3] == S[2*i - 16] for i in srange(8, 100)]) @@ -1168,11 +1168,11 @@ def from_recurrence(self, *args, **kwds): Same test with different variable and function names:: - sage: var('m') # optional - sage.symbolic + sage: var('m') m - sage: function('g') # optional - sage.symbolic + sage: function('g') g - sage: T = Seq2.from_recurrence([ # optional - sage.symbolic + sage: T = Seq2.from_recurrence([ ....: g(4*m) == g(2*m), ....: g(4*m + 1) == g(2*m), ....: g(4*m + 2) == g(2*m), @@ -1185,12 +1185,12 @@ def from_recurrence(self, *args, **kwds): ....: g(22) == 22, g(23) == 23, g(24) == 24, g(25) == 25, ....: g(26) == 26, g(27) == 27, g(28) == 28, g(29) == 29, ....: g(30) == 30, g(31) == 31], g, m, offset=8) - sage: (S - T).is_trivial_zero() # long time # optional - sage.symbolic + sage: (S - T).is_trivial_zero() # long time True Zero-sequence with non-zero initial values:: - sage: Seq2.from_recurrence([ # optional - sage.symbolic + sage: Seq2.from_recurrence([ ....: f(2*n) == 0, f(2*n + 1) == 0, ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n) Traceback (most recent call last): @@ -1199,14 +1199,14 @@ def from_recurrence(self, *args, **kwds): :: - sage: Seq2.from_recurrence([ # optional - sage.symbolic + sage: Seq2.from_recurrence([ ....: f(2*n) == 0, f(2*n + 1) == 0, ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n, offset=2) 2-regular sequence 1, 1, 2, 3, 0, 0, 0, 0, 0, 0, ... Check if inhomogeneities `0` do not change the sequence:: - sage: Seq2.from_recurrence([ # optional - sage.symbolic + sage: Seq2.from_recurrence([ ....: f(2*n) == 0, f(2*n + 1) == 0, ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n, offset=2, ....: inhomogeneities={0: 0, 1: Seq2.zero()}) @@ -1229,26 +1229,26 @@ def from_recurrence(self, *args, **kwds): of non-zero elements in the generalized Pascal's triangle (see [LRS2017]_):: - sage: U = Seq2.from_recurrence(M=1, m=0, # optional - sage.symbolic + sage: U = Seq2.from_recurrence(M=1, m=0, ....: coeffs={(0, 0): 1}, ....: initial_values={0: 0, 1: 1}, ....: inhomogeneities={1: P}) - sage: (U - Seq2(SB)).is_trivial_zero() # optional - sage.symbolic + sage: (U - Seq2(SB)).is_trivial_zero() True :: - sage: U = Seq2.from_recurrence(M=1, m=0, # optional - sage.symbolic + sage: U = Seq2.from_recurrence(M=1, m=0, ....: coeffs={}, ....: initial_values={0: 0, 1: 1}, ....: inhomogeneities={0: SB, 1: P}) - sage: (U - Seq2(SB)).is_trivial_zero() # optional - sage.symbolic + sage: (U - Seq2(SB)).is_trivial_zero() True Number of Unbordered Factors in the Thue--Morse Sequence, but partly encoded with inhomogeneities:: - sage: UB2 = Seq2.from_recurrence([ # optional - sage.symbolic + sage: UB2 = Seq2.from_recurrence([ ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1), @@ -1264,7 +1264,7 @@ def from_recurrence(self, *args, **kwds): ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3, ....: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1), ....: 6: UB.subsequence(4, 2) + UB.subsequence(4, 3)}) - sage: (UB2 - Seq2(UB)).is_trivial_zero() # optional - sage.symbolic + sage: (UB2 - Seq2(UB)).is_trivial_zero() True """ RP = RecurrenceParser(self.k, self.coefficient_ring()) @@ -1325,11 +1325,11 @@ def parse_recurrence(self, equations, function, var): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f - sage: RP.parse_recurrence([ # optional - sage.symbolic + sage: RP.parse_recurrence([ ....: f(4*n) == f(2*n) + 2*f(2*n + 1) + 3*f(2*n - 2), ....: f(4*n + 1) == 4*f(2*n) + 5*f(2*n + 1) + 6*f(2*n - 2), ....: f(4*n + 2) == 7*f(2*n) + 8*f(2*n + 1) + 9*f(2*n - 2), @@ -1341,7 +1341,7 @@ def parse_recurrence(self, equations, function, var): Stern--Brocot Sequence:: - sage: RP.parse_recurrence([ # optional - sage.symbolic + sage: RP.parse_recurrence([ ....: f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], f, n) (1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, {0: 0, 1: 1}) @@ -1354,28 +1354,28 @@ def parse_recurrence(self, equations, function, var): The following tests check that the equations are well-formed:: - sage: RP.parse_recurrence([], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([], f, n) Traceback (most recent call last): ... ValueError: List of recurrence equations is empty. :: - sage: RP.parse_recurrence([f(4*n + 1)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(4*n + 1)], f, n) Traceback (most recent call last): ... ValueError: f(4*n + 1) is not an equation with ==. :: - sage: RP.parse_recurrence([42], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([42], f, n) Traceback (most recent call last): ... ValueError: 42 is not a symbolic expression. :: - sage: RP.parse_recurrence([f(2*n) + 1 == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) + 1 == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(2*n) + 1 in the equation f(2*n) + 1 == f(n) is @@ -1383,7 +1383,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n, 5) == 3], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n, 5) == 3], f, n) Traceback (most recent call last): ... ValueError: Term f(2*n, 5) in the equation f(2*n, 5) == 3 does not @@ -1391,7 +1391,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f() == 3], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f() == 3], f, n) Traceback (most recent call last): ... ValueError: Term f() in the equation f() == 3 does not have one @@ -1399,7 +1399,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(1/n + 1) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(1/n + 1) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(1/n + 1) in the equation f(1/n + 1) == f(n): @@ -1407,7 +1407,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n + 1/2) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n + 1/2) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(2*n + 1/2) in the equation f(2*n + 1/2) == f(n): @@ -1415,7 +1415,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n^2) == f(2*n^2)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(4*n^2) == f(2*n^2)], f, n) Traceback (most recent call last): ... ValueError: Term f(4*n^2) in the equation f(4*n^2) == f(2*n^2): @@ -1423,7 +1423,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(42) == 1/2], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(42) == 1/2], f, n) Traceback (most recent call last): ... ValueError: Initial value 1/2 given by the equation f(42) == (1/2) @@ -1431,14 +1431,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(42) == 0, f(42) == 1], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(42) == 0, f(42) == 1], f, n) Traceback (most recent call last): ... ValueError: Initial value f(42) is given twice. :: - sage: RP.parse_recurrence([f(42) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(42) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Initial value f(n) given by the equation f(42) == f(n) @@ -1446,7 +1446,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(n), f(2*n) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(4*n) == f(n), f(2*n) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(2*n) in the equation f(2*n) == f(n): 2 does not @@ -1455,7 +1455,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(3*n + 1) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(3*n + 1) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(3*n + 1) in the equation f(3*n + 1) == f(n): @@ -1463,7 +1463,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(n + 1) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(n + 1) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(n + 1) in the equation f(n + 1) == f(n): @@ -1471,14 +1471,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n), f(2*n) == 0], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(n), f(2*n) == 0], f, n) Traceback (most recent call last): ... ValueError: There are more than one recurrence relation for f(2*n). :: - sage: RP.parse_recurrence([f(2*n + 2) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n + 2) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(2*n + 2) in the equation f(2*n + 2) == f(n): @@ -1486,7 +1486,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n - 1) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n - 1) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(2*n - 1) in the equation f(2*n - 1) == f(n): @@ -1494,7 +1494,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 2*n], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 2*n], f, n) Traceback (most recent call last): ... ValueError: Term 2*n in the equation f(2*n) == 2*n does not @@ -1502,7 +1502,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 1/2*f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 1/2*f(n)], f, n) Traceback (most recent call last): ... ValueError: Term 1/2*f(n) in the equation f(2*n) == 1/2*f(n): @@ -1510,21 +1510,21 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 1/f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 1/f(n)], f, n) Traceback (most recent call last): ... ValueError: 1/f(n) is not a valid right hand side. :: - sage: RP.parse_recurrence([f(2*n) == 2*n*f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 2*n*f(n)], f, n) Traceback (most recent call last): ... ValueError: 2*n*f(n) is not a valid right hand side. :: - sage: RP.parse_recurrence([f(2*n) == 2*f(n, 5)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 2*f(n, 5)], f, n) Traceback (most recent call last): ... ValueError: Term f(n, 5) in the equation f(2*n) == 2*f(n, 5) @@ -1532,14 +1532,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 2*f()], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 2*f()], f, n) Traceback (most recent call last): ... ValueError: Term f() in the equation f(2*n) == 2*f() has no argument. :: - sage: RP.parse_recurrence([f(2*n) == 1/f(n) + 2*f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 1/f(n) + 2*f(n)], f, n) Traceback (most recent call last): ... ValueError: Term 1/f(n) in the equation f(2*n) == 1/f(n) + 2*f(n) @@ -1547,7 +1547,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == 2*f(1/n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 2*f(1/n)], f, n) Traceback (most recent call last): ... ValueError: Term f(1/n) in the equation f(2*n) == 2*f(1/n): @@ -1555,7 +1555,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n + 1/2)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(n + 1/2)], f, n) Traceback (most recent call last): ... ValueError: Term f(n + 1/2) in the equation f(2*n) == f(n + 1/2): @@ -1563,7 +1563,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(1/2*n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(1/2*n)], f, n) Traceback (most recent call last): ... ValueError: Term f(1/2*n) in the equation f(2*n) == f(1/2*n): @@ -1571,7 +1571,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n^2 + 1)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(n^2 + 1)], f, n) Traceback (most recent call last): ... ValueError: Term f(n^2 + 1) in the equation f(2*n) == f(n^2 + 1): @@ -1579,7 +1579,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(1)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(1)], f, n) Traceback (most recent call last): ... ValueError: Term f(1) in the equation f(2*n) == f(1): @@ -1587,7 +1587,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(2*n) + f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(4*n) == f(2*n) + f(n)], f, n) Traceback (most recent call last): ... ValueError: Term f(n) in the equation f(4*n) == f(2*n) + f(n): @@ -1596,7 +1596,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(2*n), f(4*n + 1) == f(n)], # optional - sage.symbolic + sage: RP.parse_recurrence([f(4*n) == f(2*n), f(4*n + 1) == f(n)], ....: f, n) Traceback (most recent call last): ... @@ -1606,7 +1606,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(4*n) == f(3*n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(4*n) == f(3*n)], f, n) Traceback (most recent call last): ... ValueError: Term f(3*n) in the equation f(4*n) == f(3*n): 3 is not @@ -1614,7 +1614,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(4*n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(4*n)], f, n) Traceback (most recent call last): ... ValueError: Term f(4*n) in the equation f(2*n) == f(4*n): @@ -1622,7 +1622,7 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(2*n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(2*n)], f, n) Traceback (most recent call last): ... ValueError: Term f(2*n) in the equation f(2*n) == f(2*n): @@ -1630,14 +1630,14 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(2*n) == f(n)], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == f(n)], f, n) Traceback (most recent call last): ... ValueError: Recurrence relations for [f(2*n + 1)] are missing. :: - sage: RP.parse_recurrence([f(4*n) == f(n), f(4*n + 3) == 0], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(4*n) == f(n), f(4*n + 3) == 0], f, n) Traceback (most recent call last): ... ValueError: Recurrence relations for [f(4*n + 1), f(4*n + 2)] @@ -1645,20 +1645,20 @@ def parse_recurrence(self, equations, function, var): :: - sage: RP.parse_recurrence([f(42) == 0], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(42) == 0], f, n) Traceback (most recent call last): ... ValueError: No recurrence relations are given. :: - sage: RP.parse_recurrence( # optional - sage.symbolic + sage: RP.parse_recurrence( ....: [f(4*n + r) == f(n) for r in srange(4)], f, n) (2, 0, {(0, 0): 1, (1, 0): 1, (2, 0): 1, (3, 0): 1}, {}) :: - sage: RP.parse_recurrence( # optional - sage.symbolic + sage: RP.parse_recurrence( ....: [f(8*n) == f(n)] + ....: [f(8*n + r) == f(2*n) for r in srange(1,8)], f, n) Traceback (most recent call last): @@ -1669,35 +1669,35 @@ def parse_recurrence(self, equations, function, var): Finally, also for the zero-sequence the output is as expected:: - sage: RP.parse_recurrence([f(2*n) == 0, f(2*n + 1) == 0], f, n) # optional - sage.symbolic + sage: RP.parse_recurrence([f(2*n) == 0, f(2*n + 1) == 0], f, n) (1, 0, {}, {}) We check that the output is of the correct type (:trac:`33158`):: sage: RP = RecurrenceParser(2, QQ) - sage: equations = [ # optional - sage.symbolic + sage: equations = [ ....: f(4*n) == 5/3*f(2*n) - 1/3*f(2*n + 1), ....: f(4*n + 1) == 4/3*f(2*n) + 1/3*f(2*n + 1), ....: f(4*n + 2) == 1/3*f(2*n) + 4/3*f(2*n + 1), ....: f(4*n + 3) == -1/3*f(2*n) + 5/3*f(2*n + 1), ....: f(0) == 1, f(1) == 2] - sage: M, m, coeffs, initial_values = RP.parse_recurrence(equations, f, n) # optional - sage.symbolic - sage: M.parent() # optional - sage.symbolic + sage: M, m, coeffs, initial_values = RP.parse_recurrence(equations, f, n) + sage: M.parent() Integer Ring - sage: m.parent() # optional - sage.symbolic + sage: m.parent() Integer Ring - sage: all(v.parent() == QQ for v in coeffs.values()) # optional - sage.symbolic + sage: all(v.parent() == QQ for v in coeffs.values()) True - sage: all(v.parent() == QQ for v in initial_values.values()) # optional - sage.symbolic + sage: all(v.parent() == QQ for v in initial_values.values()) True This results in giving the correct (see :trac:`33158`) minimization in:: sage: Seq2 = kRegularSequenceSpace(2, QQ) - sage: P = Seq2.from_recurrence(equations, f, n) # optional - sage.symbolic - sage: P # optional - sage.symbolic + sage: P = Seq2.from_recurrence(equations, f, n) + sage: P 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ... - sage: P.minimized() # optional - sage.symbolic + sage: P.minimized() 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ... """ from sage.arith.srange import srange @@ -2119,9 +2119,9 @@ def parameters(self, M, m, coeffs, initial_values, offset=0, inhomogeneities={}) TESTS:: - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, # optional - sage.symbolic + sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, ....: {-1: 0, 1: 0, 10: 0, I: 0, n: 0}) Traceback (most recent call last): ... @@ -2130,7 +2130,7 @@ def parameters(self, M, m, coeffs, initial_values, offset=0, inhomogeneities={}) :: - sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, # optional - sage.symbolic + sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0, ....: {0: n}) Traceback (most recent call last): ... @@ -2585,11 +2585,11 @@ def shifted_inhomogeneities(self, recurrence_rules): TESTS:: sage: Seq2 = kRegularSequenceSpace(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f - sage: UB = Seq2.from_recurrence([ # optional - sage.symbolic + sage: UB = Seq2.from_recurrence([ ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -2603,16 +2603,16 @@ def shifted_inhomogeneities(self, recurrence_rules): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3) - sage: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1), # optional - sage.symbolic + sage: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1), ....: 6: UB.subsequence(4, 2) + UB.subsequence(4, 3)} - sage: recurrence_rules_UB = RR(M=3, m=2, ll=0, uu=9, # optional - sage.symbolic + sage: recurrence_rules_UB = RR(M=3, m=2, ll=0, uu=9, ....: inhomogeneities=inhomogeneities) - sage: shifted_inhomog = RP.shifted_inhomogeneities(recurrence_rules_UB) # optional - sage.symbolic - sage: shifted_inhomog # optional - sage.symbolic + sage: shifted_inhomog = RP.shifted_inhomogeneities(recurrence_rules_UB) + sage: shifted_inhomog {2: 2-regular sequence 8, 8, 8, 12, 12, 16, 12, 16, 12, 24, ..., 3: 2-regular sequence -10, -8, -8, -8, -8, -8, -8, -8, -8, -12, ..., 6: 2-regular sequence 20, 22, 24, 28, 28, 32, 28, 32, 32, 48, ...} - sage: shifted_inhomog[2].mu[0].ncols() == 3*inhomogeneities[2].mu[0].ncols() # optional - sage.symbolic + sage: shifted_inhomog[2].mu[0].ncols() == 3*inhomogeneities[2].mu[0].ncols() True .. SEEALSO:: @@ -2719,11 +2719,11 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ ....: f(8*n) == -1*f(2*n - 1) + 1*f(2*n + 1), ....: f(8*n + 1) == -11*f(2*n - 1) + 10*f(2*n) + 11*f(2*n + 1), ....: f(8*n + 2) == -21*f(2*n - 1) + 20*f(2*n) + 21*f(2*n + 1), @@ -2734,9 +2734,9 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): ....: f(8*n + 7) == -71*f(2*n - 1) + 70*f(2*n) + 71*f(2*n + 1), ....: f(0) == 0, f(1) == 1, f(2) == 2, f(3) == 3, f(4) == 4, ....: f(5) == 5, f(6) == 6, f(7) == 7], f, n) - sage: rules = RP.parameters( # optional - sage.symbolic + sage: rules = RP.parameters( ....: M, m, coeffs, initial_values, 0) - sage: RP.matrix(rules, 0, False) # optional - sage.symbolic + sage: RP.matrix(rules, 0, False) [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] @@ -2754,7 +2754,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): [ 0 0 0 -31 30 31 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 -41 40 41 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 -51 50 51 0 0 0 0 0 0 0 0 0 0 0] - sage: RP.matrix(rules, 1, False) # optional - sage.symbolic + sage: RP.matrix(rules, 1, False) [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0] @@ -2789,7 +2789,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -2803,9 +2803,9 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n) - sage: UB_rules = RP.parameters( # optional - sage.symbolic + sage: UB_rules = RP.parameters( ....: M, m, coeffs, initial_values, 3) - sage: RP.matrix(UB_rules, 0) # optional - sage.symbolic + sage: RP.matrix(UB_rules, 0) [ 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] @@ -2822,7 +2822,7 @@ def matrix(self, recurrence_rules, rem, correct_offset=True): [ 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] - sage: RP.matrix(UB_rules, 1) # optional - sage.symbolic + sage: RP.matrix(UB_rules, 1) [ 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] @@ -3016,9 +3016,9 @@ def right(self, recurrence_rules): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f sage: SB_rules = RP.parameters( ....: 1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, @@ -3028,7 +3028,7 @@ def right(self, recurrence_rules): Number of Unbordered Factors in the Thue--Morse Sequence:: - sage: M, m, coeffs, initial_values = RP.parse_recurrence([ # optional - sage.symbolic + sage: M, m, coeffs, initial_values = RP.parse_recurrence([ ....: f(8*n) == 2*f(4*n), ....: f(8*n + 1) == f(4*n + 1), ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3), @@ -3042,9 +3042,9 @@ def right(self, recurrence_rules): ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4, ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0, ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n) - sage: UB_rules = RP.parameters( # optional - sage.symbolic + sage: UB_rules = RP.parameters( ....: M, m, coeffs, initial_values, 3) - sage: RP.right(UB_rules) # optional - sage.symbolic + sage: RP.right(UB_rules) (1, 1, 2, 1, 2, 2, 4, 2, 4, 6, 0, 4, 4, 1, 0, 0) """ from sage.modules.free_module_element import vector @@ -3080,12 +3080,12 @@ def __call__(self, *args, **kwds): sage: from sage.combinat.k_regular_sequence import RecurrenceParser sage: RP = RecurrenceParser(2, ZZ) - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f - sage: RP([f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic + sage: RP([f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], f, n) ([ [1 0 0] [1 1 0] @@ -3095,7 +3095,7 @@ def __call__(self, *args, **kwds): (1, 0, 0), (0, 1, 1)) - sage: RP(equations=[f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), # optional - sage.symbolic + sage: RP(equations=[f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1), ....: f(0) == 0, f(1) == 1], function=f, var=n) ([ [1 0 0] [1 1 0] From d15a157ea97a53f5331a17f732d6aa265c2ad5c4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 09:55:38 -0700 Subject: [PATCH 23/26] src/sage/combinat/root_system/root_lattice_realizations.py: Docstring cosmetics --- .../root_system/root_lattice_realizations.py | 353 ++++++++++-------- 1 file changed, 195 insertions(+), 158 deletions(-) diff --git a/src/sage/combinat/root_system/root_lattice_realizations.py b/src/sage/combinat/root_system/root_lattice_realizations.py index e7f0e87807f..e8d63867f09 100644 --- a/src/sage/combinat/root_system/root_lattice_realizations.py +++ b/src/sage/combinat/root_system/root_lattice_realizations.py @@ -107,7 +107,8 @@ class RootLatticeRealizations(Category_over_base_ring): sage: L(x) Traceback (most recent call last): ... - TypeError: do not know how to make x (= alpha[2] + 1/2*alpha[5]) an element of self (=Weight lattice of the Root system of type ['A', 7]) + TypeError: do not know how to make x (= alpha[2] + 1/2*alpha[5]) + an element of self (=Weight lattice of the Root system of type ['A', 7]) If `K_1` is a subring of `K_2`, then one could in theory have an embedding from the root space over `K_1` to any root @@ -125,7 +126,9 @@ class RootLatticeRealizations(Category_over_base_ring): sage: L(alpha[1]) Traceback (most recent call last): ... - TypeError: do not know how to make x (= alpha[1]) an element of self (=Weight space over the Univariate Polynomial Ring in q over Rational Field of the Root system of type ['A', 7]) + TypeError: do not know how to make x (= alpha[1]) an element of self + (=Weight space over the Univariate Polynomial Ring in q + over Rational Field of the Root system of type ['A', 7]) By a slight abuse, the embedding of the root lattice is not actually required to be faithful. Typically for an affine root system, the @@ -277,7 +280,7 @@ def _name_string_helper(self, name, capitalize=True, base_ring=True, type=True, def some_elements(self): """ - Return some elements of this root lattice realization + Return some elements of this root lattice realization. EXAMPLES:: @@ -299,7 +302,7 @@ def some_elements(self): def _test_root_lattice_realization(self, **options): """ - Runs sanity checks on this root lattice realization + Run sanity checks on this root lattice realization - embedding of the root lattice - embedding of the root space over the same base ring @@ -369,7 +372,7 @@ def _test_root_lattice_realization(self, **options): @cached_method def highest_root(self): """ - Returns the highest root (for an irreducible finite root system) + Return the highest root (for an irreducible finite root system). EXAMPLES:: @@ -389,23 +392,27 @@ def highest_root(self): @cached_method def a_long_simple_root(self): """ - Returns a long simple root, corresponding to the highest outgoing edge + Return a long simple root, corresponding to the highest outgoing edge in the Dynkin diagram. - Caveat: this may be break in affine type `A_{2n}^{(2)}` + .. warning:: + + This may be broken in affine type `A_{2n}^{(2)}` - Caveat: meaningful/broken for non irreducible? + Is it meaningful/broken for non irreducible? - TODO: implement CartanType.nodes_by_length as in - MuPAD-Combinat (using CartanType.symmetrizer), and use it - here. + .. TODO:: + + implement CartanType.nodes_by_length as in + MuPAD-Combinat (using CartanType.symmetrizer), and use it + here. TESTS:: - sage: X=RootSystem(['A',1]).weight_space() + sage: X = RootSystem(['A',1]).weight_space() sage: X.a_long_simple_root() 2*Lambda[1] - sage: X=RootSystem(['A',5]).weight_space() + sage: X = RootSystem(['A',5]).weight_space() sage: X.a_long_simple_root() 2*Lambda[1] - Lambda[2] """ @@ -424,7 +431,7 @@ def a_long_simple_root(self): @abstract_method def simple_root(self, i): """ - Returns the `i^{th}` simple root. + Return the `i`-th simple root. This should be overridden by any subclass, and typically implemented as a cached method for efficiency. @@ -446,7 +453,7 @@ def simple_root(self, i): @cached_method def simple_roots(self): r""" - Returns the family `(\alpha_i)_{i\in I}` of the simple roots. + Return the family `(\alpha_i)_{i\in I}` of the simple roots. EXAMPLES:: @@ -570,7 +577,8 @@ def roots(self): This matches with :wikipedia:`Root_systems`:: sage: for T in CartanType.samples(finite = True, crystallographic = True): - ....: print("%s %3s %3s"%(T, len(RootSystem(T).root_lattice().roots()), len(RootSystem(T).weight_lattice().roots()))) + ....: print("%s %3s %3s"%(T, len(RootSystem(T).root_lattice().roots()), + ....: len(RootSystem(T).weight_lattice().roots()))) ['A', 1] 2 2 ['A', 5] 30 30 ['B', 1] 2 2 @@ -698,7 +706,7 @@ def nonparabolic_positive_roots(self, index_set = None): Return the positive roots of ``self`` that are not in the parabolic subsystem indicated by ``index_set``. - If ``index_set`` is None, as in :meth:`positive_roots` + If ``index_set`` is ``None``, as in :meth:`positive_roots` it is assumed to be the entire Dynkin node set. Then the parabolic subsystem consists of all positive roots and the empty list is returned. @@ -711,7 +719,8 @@ def nonparabolic_positive_roots(self, index_set = None): sage: sorted(L.nonparabolic_positive_roots((1,2))) [alpha[1] + alpha[2] + alpha[3], alpha[2] + alpha[3], alpha[3]] sage: sorted(L.nonparabolic_positive_roots(())) - [alpha[1], alpha[1] + alpha[2], alpha[1] + alpha[2] + alpha[3], alpha[2], alpha[2] + alpha[3], alpha[3]] + [alpha[1], alpha[1] + alpha[2], alpha[1] + alpha[2] + alpha[3], + alpha[2], alpha[2] + alpha[3], alpha[3]] """ if not self.cartan_type().is_finite(): @@ -871,7 +880,7 @@ def positive_imaginary_roots(self): @cached_method def positive_roots_by_height(self, increasing = True): r""" - Returns a list of positive roots in increasing order by height. + Return a list of positive roots in increasing order by height. If ``increasing`` is False, returns them in decreasing order. @@ -912,17 +921,20 @@ def positive_roots_parabolic(self, index_set = None): INPUT: - - ``index_set`` -- (default:None) the Dynkin node set of the parabolic subsystem. It should be a tuple. The default value implies the entire Dynkin node set + - ``index_set`` -- (default: ``None``) the Dynkin node set of the + parabolic subsystem. It should be a tuple. The default value + implies the entire Dynkin node set EXAMPLES:: - sage: lattice = RootSystem(['A',3]).root_lattice() + sage: lattice = RootSystem(['A',3]).root_lattice() sage: sorted(lattice.positive_roots_parabolic((1,3)), key=str) [alpha[1], alpha[3]] sage: sorted(lattice.positive_roots_parabolic((2,3)), key=str) [alpha[2], alpha[2] + alpha[3], alpha[3]] sage: sorted(lattice.positive_roots_parabolic(), key=str) - [alpha[1], alpha[1] + alpha[2], alpha[1] + alpha[2] + alpha[3], alpha[2], alpha[2] + alpha[3], alpha[3]] + [alpha[1], alpha[1] + alpha[2], alpha[1] + alpha[2] + alpha[3], + alpha[2], alpha[2] + alpha[3], alpha[3]] .. WARNING:: @@ -943,15 +955,17 @@ def parabolic_covers(alpha): @cached_method def positive_roots_nonparabolic(self, index_set = None): r""" - Returns the set of positive roots outside the parabolic subsystem with Dynkin node set ``index_set``. + Return the set of positive roots outside the parabolic subsystem with Dynkin node set ``index_set``. INPUT: - - ``index_set`` -- (default:None) the Dynkin node set of the parabolic subsystem. It should be a tuple. The default value implies the entire Dynkin node set + - ``index_set`` -- (default: ``None``) the Dynkin node set of the + parabolic subsystem. It should be a tuple. The default value + implies the entire Dynkin node set EXAMPLES:: - sage: lattice = RootSystem(['A',3]).root_lattice() + sage: lattice = RootSystem(['A',3]).root_lattice() sage: sorted(lattice.positive_roots_nonparabolic((1,3)), key=str) [alpha[1] + alpha[2], alpha[1] + alpha[2] + alpha[3], alpha[2], alpha[2] + alpha[3]] sage: sorted(lattice.positive_roots_nonparabolic((2,3)), key=str) @@ -975,11 +989,13 @@ def positive_roots_nonparabolic(self, index_set = None): @cached_method def positive_roots_nonparabolic_sum(self, index_set = None): r""" - Returns the sum of positive roots outside the parabolic subsystem with Dynkin node set ``index_set``. + Return the sum of positive roots outside the parabolic subsystem with Dynkin node set ``index_set``. INPUT: - - ``index_set`` -- (default:None) the Dynkin node set of the parabolic subsystem. It should be a tuple. The default value implies the entire Dynkin node set + - ``index_set`` -- (default: ``None``) the Dynkin node set of the + parabolic subsystem. It should be a tuple. The default value + implies the entire Dynkin node set EXAMPLES:: @@ -1009,37 +1025,38 @@ def positive_roots_nonparabolic_sum(self, index_set = None): def root_poset(self, restricted=False, facade=False): r""" - Returns the (restricted) root poset associated to ``self``. + Return the (restricted) root poset associated to ``self``. The elements are given by the positive roots (resp. non-simple, positive roots), and `\alpha \leq \beta` iff `\beta - \alpha` is a non-negative linear combination of simple roots. INPUT: - - ``restricted`` -- (default:False) if True, only non-simple roots are considered. - - ``facade`` -- (default:False) passes facade option to the poset generator. + - ``restricted`` -- (default: ``False``) if ``True``, only non-simple roots are considered. + - ``facade`` -- (default: ``False``) passes facade option to the poset generator. EXAMPLES:: - sage: Phi = RootSystem(['A',1]).root_poset(); Phi + sage: Phi = RootSystem(['A',1]).root_poset(); Phi # optional - sage.graphs Finite poset containing 1 elements - sage: Phi.cover_relations() + sage: Phi.cover_relations() # optional - sage.graphs [] - sage: Phi = RootSystem(['A',2]).root_poset(); Phi + sage: Phi = RootSystem(['A',2]).root_poset(); Phi # optional - sage.graphs Finite poset containing 3 elements - sage: sorted(Phi.cover_relations(), key=str) + sage: sorted(Phi.cover_relations(), key=str) # optional - sage.graphs [[alpha[1], alpha[1] + alpha[2]], [alpha[2], alpha[1] + alpha[2]]] - sage: Phi = RootSystem(['A',3]).root_poset(restricted=True); Phi + sage: Phi = RootSystem(['A',3]).root_poset(restricted=True); Phi # optional - sage.graphs Finite poset containing 3 elements - sage: sorted(Phi.cover_relations(), key=str) - [[alpha[1] + alpha[2], alpha[1] + alpha[2] + alpha[3]], [alpha[2] + alpha[3], alpha[1] + alpha[2] + alpha[3]]] + sage: sorted(Phi.cover_relations(), key=str) # optional - sage.graphs + [[alpha[1] + alpha[2], alpha[1] + alpha[2] + alpha[3]], + [alpha[2] + alpha[3], alpha[1] + alpha[2] + alpha[3]]] - sage: Phi = RootSystem(['B',2]).root_poset(); Phi + sage: Phi = RootSystem(['B',2]).root_poset(); Phi # optional - sage.graphs Finite poset containing 4 elements - sage: sorted(Phi.cover_relations(), key=str) + sage: sorted(Phi.cover_relations(), key=str) # optional - sage.graphs [[alpha[1] + alpha[2], alpha[1] + 2*alpha[2]], [alpha[1], alpha[1] + alpha[2]], [alpha[2], alpha[1] + alpha[2]]] @@ -1048,7 +1065,7 @@ def root_poset(self, restricted=False, facade=False): Check that :trac:`17982` is fixed:: - sage: RootSystem(['A', 2]).ambient_space().root_poset() + sage: RootSystem(['A', 2]).ambient_space().root_poset() # optional - sage.graphs Finite poset containing 3 elements """ from sage.combinat.posets.posets import Poset @@ -1066,7 +1083,7 @@ def root_poset(self, restricted=False, facade=False): def nonnesting_partition_lattice(self, facade=False): r""" - Return the lattice of nonnesting partitions + Return the lattice of nonnesting partitions. This is the lattice of order ideals of the root poset. @@ -1080,16 +1097,16 @@ def nonnesting_partition_lattice(self, facade=False): sage: R = RootSystem(['A', 3]) sage: RS = R.root_lattice() - sage: P = RS.nonnesting_partition_lattice(); P + sage: P = RS.nonnesting_partition_lattice(); P # optional - sage.graphs Finite lattice containing 14 elements - sage: P.coxeter_transformation()**10 == 1 + sage: P.coxeter_transformation()**10 == 1 # optional - sage.graphs True - sage: R = RootSystem(['B', 3]) - sage: RS = R.root_lattice() - sage: P = RS.nonnesting_partition_lattice(); P + sage: R = RootSystem(['B', 3]) # optional - sage.graphs + sage: RS = R.root_lattice() # optional - sage.graphs + sage: P = RS.nonnesting_partition_lattice(); P # optional - sage.graphs Finite lattice containing 20 elements - sage: P.coxeter_transformation()**7 == 1 + sage: P.coxeter_transformation()**7 == 1 # optional - sage.graphs True REFERENCES: @@ -1103,7 +1120,7 @@ def nonnesting_partition_lattice(self, facade=False): def generalized_nonnesting_partition_lattice(self, m, facade=False): r""" - Return the lattice of `m`-nonnesting partitions + Return the lattice of `m`-nonnesting partitions. This has been defined by Athanasiadis, see chapter 5 of [Arm06]_. @@ -1119,9 +1136,9 @@ def generalized_nonnesting_partition_lattice(self, m, facade=False): sage: R = RootSystem(['A', 2]) sage: RS = R.root_lattice() - sage: P = RS.generalized_nonnesting_partition_lattice(2); P + sage: P = RS.generalized_nonnesting_partition_lattice(2); P # optional - sage.graphs Finite lattice containing 12 elements - sage: P.coxeter_transformation()**20 == 1 + sage: P.coxeter_transformation()**20 == 1 # optional - sage.graphs True """ Phi_plus = self.positive_roots() @@ -1163,7 +1180,7 @@ def is_componentwise_subset(chain1, chain2): def almost_positive_roots(self): r""" - Returns the almost positive roots of ``self`` + Return the almost positive roots of ``self``. These are the positive roots together with the simple negative roots. @@ -1181,7 +1198,7 @@ def almost_positive_roots(self): def negative_roots(self): r""" - Returns the negative roots of self. + Return the negative roots of ``self``. EXAMPLES:: @@ -1202,7 +1219,7 @@ def negative_roots(self): def coroot_lattice(self): """ - Returns the coroot lattice. + Return the coroot lattice. EXAMPLES:: @@ -1226,7 +1243,8 @@ def coroot_space(self, base_ring = QQ): Coroot space over the Rational Field of the Root system of type ['A', 2] sage: RootSystem(['A',2]).root_lattice().coroot_space(QQ['q']) - Coroot space over the Univariate Polynomial Ring in q over Rational Field of the Root system of type ['A', 2] + Coroot space over the Univariate Polynomial Ring in q over Rational Field + of the Root system of type ['A', 2] """ return self.root_system.coroot_space(base_ring = base_ring) @@ -1300,7 +1318,7 @@ def alphacheck(self): @cached_method def cohighest_root(self): """ - Returns the associated coroot of the highest root. + Return the associated coroot of the highest root. .. note:: this is usually not the highest coroot. @@ -1318,9 +1336,11 @@ def cohighest_root(self): @cached_method def null_root(self): """ - Returns the null root of self. The null root is the smallest - non trivial positive root which is orthogonal to all simple - coroots. It exists for any affine root system. + Return the null root of ``self``. + + The null root is the smallest non trivial positive root which is + orthogonal to all simple coroots. It exists for any affine root + system. EXAMPLES:: @@ -1342,20 +1362,22 @@ def null_root(self): @cached_method def null_coroot(self): """ - Returns the null coroot of self. + Return the null coroot of ``self``. - The null coroot is the smallest non trivial positive - coroot which is orthogonal to all simple roots. It exists - for any affine root system. + The null coroot is the smallest non trivial positive coroot which is + orthogonal to all simple roots. It exists for any affine root + system. EXAMPLES:: sage: RootSystem(['C',2,1]).root_lattice().null_coroot() alphacheck[0] + alphacheck[1] + alphacheck[2] sage: RootSystem(['D',4,1]).root_lattice().null_coroot() - alphacheck[0] + alphacheck[1] + 2*alphacheck[2] + alphacheck[3] + alphacheck[4] + alphacheck[0] + alphacheck[1] + 2*alphacheck[2] + + alphacheck[3] + alphacheck[4] sage: RootSystem(['F',4,1]).root_lattice().null_coroot() - alphacheck[0] + 2*alphacheck[1] + 3*alphacheck[2] + 2*alphacheck[3] + alphacheck[4] + alphacheck[0] + 2*alphacheck[1] + 3*alphacheck[2] + + 2*alphacheck[3] + alphacheck[4] """ if not self.cartan_type().is_affine(): raise ValueError("%s is not an affine Cartan type" % (self.cartan_type())) @@ -1409,7 +1431,8 @@ def fundamental_weights_from_simple_roots(self): sage: L.fundamental_weights_from_simple_roots() Traceback (most recent call last): ... - ValueError: The fundamental weights do not live in this realization of the root lattice + ValueError: The fundamental weights do not live in this realization + of the root lattice Beware of the usual `GL_n` vs `SL_n` catch in type `A`:: @@ -1417,13 +1440,16 @@ def fundamental_weights_from_simple_roots(self): sage: L.fundamental_weights() Finite family {1: (1, 0, 0, 0), 2: (1, 1, 0, 0), 3: (1, 1, 1, 0)} sage: L.fundamental_weights_from_simple_roots() - Finite family {1: (3/4, -1/4, -1/4, -1/4), 2: (1/2, 1/2, -1/2, -1/2), 3: (1/4, 1/4, 1/4, -3/4)} + Finite family {1: (3/4, -1/4, -1/4, -1/4), + 2: (1/2, 1/2, -1/2, -1/2), + 3: (1/4, 1/4, 1/4, -3/4)} sage: L = RootSystem(["A",3]).ambient_lattice() sage: L.fundamental_weights_from_simple_roots() Traceback (most recent call last): ... - ValueError: The fundamental weights do not live in this realization of the root lattice + ValueError: The fundamental weights do not live in this realization + of the root lattice """ # We first scale the inverse of the Cartan matrix to be # with integer coefficients; then the linear combination @@ -1448,15 +1474,14 @@ def fundamental_weights_from_simple_roots(self): def reflection(self, root, coroot=None): """ - Returns the reflection along the root, and across the - hyperplane define by coroot, as a function from - self to self. + Return the reflection along the ``root``, and across the hyperplane + defined by ``coroot``, as a function from ``self`` to ``self``. EXAMPLES:: sage: space = RootSystem(['A',2]).weight_lattice() - sage: x=space.simple_roots()[1] - sage: y=space.simple_coroots()[1] + sage: x = space.simple_roots()[1] + sage: y = space.simple_coroots()[1] sage: s = space.reflection(x,y) sage: x 2*Lambda[1] - Lambda[2] @@ -1472,12 +1497,12 @@ def reflection(self, root, coroot=None): @cached_method def simple_reflection(self, i): """ - Returns the `i^{th}` simple reflection, as a function from - self to self. + Return the `i`-th simple reflection, as a function from + ``self`` to ``self``. INPUT: - - ``i`` - i is in self's index set + - ``i`` -- an element of the index set of ``self`` EXAMPLES:: @@ -1522,19 +1547,21 @@ def simple_reflections(self): def projection(self, root, coroot=None, to_negative=True): r""" - Returns the projection along the root, and across the - hyperplane define by coroot, as a function `\pi` from self to - self. `\pi` is a half-linear map which stabilizes the negative - half space, and acts by reflection on the positive half space. + Return the projection along the ``root``, and across the + hyperplane defined by ``coroot``, as a function `\pi` from ``self`` to + ``self``. - If to_negative is False, then this project onto the positive + `\pi` is a half-linear map which stabilizes the negative + half space and acts by reflection on the positive half space. + + If ``to_negative`` is ``False``, then project onto the positive half space instead. EXAMPLES:: sage: space = RootSystem(['A',2]).weight_lattice() - sage: x=space.simple_roots()[1] - sage: y=space.simple_coroots()[1] + sage: x = space.simple_roots()[1] + sage: y = space.simple_coroots()[1] sage: pi = space.projection(x,y) sage: x 2*Lambda[1] - Lambda[2] @@ -1554,13 +1581,13 @@ def projection(self, root, coroot=None, to_negative=True): @cached_method def simple_projection(self, i, to_negative=True): """ - Returns the projection along the `i^{th}` simple root, and across the - hyperplane define by the `i^{th}` simple coroot, as a function from - self to self. + Return the projection along the `i`-th simple root, and across the + hyperplane define by the `i`-th simple coroot, as a function from + ``self`` to ``self``. INPUT: - - ``i`` - i is in self's index set + - ``i`` -- an element of the index set of ``self`` EXAMPLES:: @@ -1582,8 +1609,8 @@ def simple_projection(self, i, to_negative=True): @cached_method def simple_projections(self, to_negative=True): r""" - Returns the family `(s_i)_{i\in I}` of the simple projections - of this root system + Return the family `(s_i)_{i\in I}` of the simple projections + of this root system. EXAMPLES:: @@ -1611,7 +1638,7 @@ def simple_projections(self, to_negative=True): def weyl_group(self, prefix=None): """ - Returns the Weyl group associated to self. + Return the Weyl group associated to ``self``. EXAMPLES:: @@ -1634,7 +1661,7 @@ def weyl_group(self, prefix=None): # create conflicts def tau_epsilon_operator_on_almost_positive_roots(self, J): r""" - The `\tau_\epsilon` operator on almost positive roots + The `\tau_\epsilon` operator on almost positive roots. Given a subset `J` of non adjacent vertices of the Dynkin diagram, this constructs the operator on the almost positive @@ -1717,7 +1744,7 @@ def tau_epsilon(alpha): def tau_plus_minus(self): r""" - Returns the `\tau^+` and `\tau^-` piecewise linear operators on ``self`` + Return the `\tau^+` and `\tau^-` piecewise linear operators on ``self``. Those operators are induced by the bipartition `\{L,R\}` of the simple roots of ``self``, and stabilize the almost @@ -1742,7 +1769,8 @@ def tau_plus_minus(self): sage: S = RootSystem(['A',2]).root_lattice() sage: taup, taum = S.tau_plus_minus() - sage: for beta in S.almost_positive_roots(): print("{} , {} , {}".format(beta, taup(beta), taum(beta))) + sage: for beta in S.almost_positive_roots(): + ....: print("{} , {} , {}".format(beta, taup(beta), taum(beta))) -alpha[1] , alpha[1] , -alpha[1] alpha[1] , -alpha[1] , alpha[1] + alpha[2] alpha[1] + alpha[2] , alpha[2] , alpha[1] @@ -1755,7 +1783,7 @@ def tau_plus_minus(self): def almost_positive_roots_decomposition(self): r""" - Returns the decomposition of the almost positive roots of ``self`` + Return the decomposition of the almost positive roots of ``self``. This is the list of the orbits of the almost positive roots under the action of the dihedral group generated by the @@ -1772,11 +1800,13 @@ def almost_positive_roots_decomposition(self): [[-alpha[1], alpha[1], alpha[1] + alpha[2], alpha[2], -alpha[2]]] sage: RootSystem(['B',2]).root_lattice().almost_positive_roots_decomposition() - [[-alpha[1], alpha[1], alpha[1] + 2*alpha[2]], [-alpha[2], alpha[2], alpha[1] + alpha[2]]] + [[-alpha[1], alpha[1], alpha[1] + 2*alpha[2]], + [-alpha[2], alpha[2], alpha[1] + alpha[2]]] sage: RootSystem(['D',4]).root_lattice().almost_positive_roots_decomposition() [[-alpha[1], alpha[1], alpha[1] + alpha[2], alpha[2] + alpha[3] + alpha[4]], - [-alpha[2], alpha[2], alpha[1] + alpha[2] + alpha[3] + alpha[4], alpha[1] + 2*alpha[2] + alpha[3] + alpha[4]], + [-alpha[2], alpha[2], alpha[1] + alpha[2] + alpha[3] + alpha[4], + alpha[1] + 2*alpha[2] + alpha[3] + alpha[4]], [-alpha[3], alpha[3], alpha[2] + alpha[3], alpha[1] + alpha[2] + alpha[4]], [-alpha[4], alpha[4], alpha[2] + alpha[4], alpha[1] + alpha[2] + alpha[3]]] """ @@ -2029,7 +2059,7 @@ def plot(self, EXAMPLES:: - sage: L = RootSystem(["A",2,1]).ambient_space().plot() # long time + sage: L = RootSystem(["A",2,1]).ambient_space().plot() # long time # optional - sage.plot sage.symbolic .. SEEALSO:: @@ -3220,7 +3250,7 @@ def plot_crystal(self, crystal, @cached_method def dual_type_cospace(self): r""" - Returns the cospace of dual type. + Return the cospace of dual type. For example, if invoked on the root lattice of type `['B',2]`, returns the coroot lattice of type `['C',2]`. @@ -3399,7 +3429,7 @@ def norm_squared(self): def simple_reflection(self, i): r""" - Returns the image of ``self`` by the `i`-th simple reflection. + Return the image of ``self`` by the `i`-th simple reflection. EXAMPLES:: @@ -3407,7 +3437,7 @@ def simple_reflection(self, i): sage: alpha[1].simple_reflection(2) alpha[1] + alpha[2] - sage: Q = RootSystem(['A', 3, 1]).weight_lattice(extended = True) + sage: Q = RootSystem(['A', 3, 1]).weight_lattice(extended=True) sage: Lambda = Q.fundamental_weights() sage: L = Lambda[0] + Q.null_root() sage: L.simple_reflection(0) @@ -3418,7 +3448,7 @@ def simple_reflection(self, i): def simple_reflections(self): """ - The images of self by all the simple reflections + The images of ``self`` by all the simple reflections EXAMPLES:: @@ -3557,7 +3587,7 @@ def dot_orbit(self): @abstract_method(optional=True) def associated_coroot(self): """ - Returns the coroot associated to this root + Return the coroot associated to this root. EXAMPLES:: @@ -3568,9 +3598,9 @@ def associated_coroot(self): def reflection(self, root, use_coroot = False): r""" - Reflects ``self`` across the hyperplane orthogonal to ``root``. + Reflect ``self`` across the hyperplane orthogonal to ``root``. - If ``use_coroot`` is True, ``root`` is interpreted as a coroot. + If ``use_coroot`` is ``True``, ``root`` is interpreted as a coroot. EXAMPLES:: @@ -3597,17 +3627,17 @@ def reflection(self, root, use_coroot = False): def has_descent(self, i, positive=False): """ - Test if self has a descent at position `i`, that is if self is - on the strict negative side of the `i^{th}` simple reflection + Test if ``self`` has a descent at position `i`, that is, if ``self`` is + on the strict negative side of the `i`-th simple reflection hyperplane. - If positive if True, tests if it is on the strict positive + If positive is ``True``, tests if it is on the strict positive side instead. EXAMPLES:: - sage: space=RootSystem(['A',5]).weight_space() - sage: alpha=RootSystem(['A',5]).weight_space().simple_roots() + sage: space = RootSystem(['A',5]).weight_space() + sage: alpha = RootSystem(['A',5]).weight_space().simple_roots() sage: [alpha[i].has_descent(1) for i in space.index_set()] [False, True, False, False, False] sage: [(-alpha[i]).has_descent(1) for i in space.index_set()] @@ -3631,15 +3661,15 @@ def has_descent(self, i, positive=False): def first_descent(self, index_set=None, positive=False): """ - Returns the first descent of pt + Return the first descent of pt - One can use the index_set option to restrict to the parabolic - subgroup indexed by index_set. + One can use the ``index_set`` option to restrict to the parabolic + subgroup indexed by ``index_set``. EXAMPLES:: - sage: space=RootSystem(['A',5]).weight_space() - sage: alpha=space.simple_roots() + sage: space = RootSystem(['A',5]).weight_space() + sage: alpha = space.simple_roots() sage: (alpha[1]+alpha[2]+alpha[4]).first_descent() 3 sage: (alpha[1]+alpha[2]+alpha[4]).first_descent([1,2,5]) @@ -3656,12 +3686,12 @@ def first_descent(self, index_set=None, positive=False): def descents(self, index_set=None, positive=False): """ - Returns the descents of pt + Return the descents of pt EXAMPLES:: - sage: space=RootSystem(['A',5]).weight_space() - sage: alpha=space.simple_roots() + sage: space = RootSystem(['A',5]).weight_space() + sage: alpha = space.simple_roots() sage: (alpha[1]+alpha[2]+alpha[4]).descents() [3, 5] """ @@ -3671,14 +3701,14 @@ def descents(self, index_set=None, positive=False): def to_dominant_chamber(self, index_set = None, positive = True, reduced_word = False): r""" - Returns the unique dominant element in the Weyl group orbit of the vector ``self``. + Return the unique dominant element in the Weyl group orbit of the vector ``self``. - If ``positive`` is False, returns the antidominant orbit element. + If ``positive`` is ``False``, returns the antidominant orbit element. With the ``index_set`` optional parameter, this is done with respect to the corresponding parabolic subgroup. - If ``reduced_word`` is True, returns the 2-tuple (``weight``, ``direction``) + If ``reduced_word`` is ``True``, returns the 2-tuple (``weight``, ``direction``) where ``weight`` is the (anti)dominant orbit element and ``direction`` is a reduced word for the Weyl group element sending ``weight`` to ``self``. @@ -3698,15 +3728,15 @@ def to_dominant_chamber(self, index_set = None, positive = True, reduced_word = EXAMPLES:: - sage: space=RootSystem(['A',5]).weight_space() - sage: alpha=RootSystem(['A',5]).weight_space().simple_roots() + sage: space = RootSystem(['A',5]).weight_space() + sage: alpha = RootSystem(['A',5]).weight_space().simple_roots() sage: alpha[1].to_dominant_chamber() Lambda[1] + Lambda[5] sage: alpha[1].to_dominant_chamber([1,2]) Lambda[1] + Lambda[2] - Lambda[3] - sage: wl=RootSystem(['A',2,1]).weight_lattice(extended=True) - sage: mu=wl.from_vector(vector([1,-3,0])) - sage: mu.to_dominant_chamber(positive=False, reduced_word = True) + sage: wl = RootSystem(['A',2,1]).weight_lattice(extended=True) + sage: mu = wl.from_vector(vector([1,-3,0])) + sage: mu.to_dominant_chamber(positive=False, reduced_word=True) (-Lambda[1] - Lambda[2] - delta, [0, 2]) sage: R = RootSystem(['A',1,1]) @@ -3765,7 +3795,7 @@ def to_dominant_chamber(self, index_set = None, positive = True, reduced_word = def reduced_word(self, index_set = None, positive = True): r""" - Returns a reduced word for the inverse of the shortest Weyl group element that sends the vector ``self`` into the dominant chamber. + Return a reduced word for the inverse of the shortest Weyl group element that sends the vector ``self`` into the dominant chamber. With the ``index_set`` optional parameter, this is done with respect to the corresponding parabolic subgroup. @@ -3774,8 +3804,8 @@ def reduced_word(self, index_set = None, positive = True): EXAMPLES:: - sage: space=RootSystem(['A',5]).weight_space() - sage: alpha=RootSystem(['A',5]).weight_space().simple_roots() + sage: space = RootSystem(['A',5]).weight_space() + sage: alpha = RootSystem(['A',5]).weight_space().simple_roots() sage: alpha[1].reduced_word() [2, 3, 4, 5] sage: alpha[1].reduced_word([1,2]) @@ -3786,11 +3816,11 @@ def reduced_word(self, index_set = None, positive = True): def is_dominant(self, index_set = None, positive = True): r""" - Returns whether self is dominant. + Return whether ``self`` is dominant. - This is done with respect to the subrootsystem indicated by the subset of Dynkin nodes - index_set. If index_set is None then the entire Dynkin node set is used. - If positive is False then the dominance condition is replaced by antidominance. + This is done with respect to the sub--root system indicated by the subset of Dynkin nodes + ``index_set``. If ``index_set`` is ``None``, then the entire Dynkin node set is used. + If positive is ``False``, then the dominance condition is replaced by antidominance. EXAMPLES:: @@ -3857,7 +3887,7 @@ def succ(self, index_set=None): INPUT: - - ``index_set`` - a subset (as a list or iterable) of the + - ``index_set`` -- a subset (as a list or iterable) of the nodes of the Dynkin diagram; (default: ``None`` for all of them) If ``index_set`` is specified, the successors for the @@ -3870,7 +3900,9 @@ def succ(self, index_set=None): sage: Lambda[1].succ() [-Lambda[1] + Lambda[2]] sage: L.rho().succ() - [-Lambda[1] + 2*Lambda[2] + Lambda[3], 2*Lambda[1] - Lambda[2] + 2*Lambda[3], Lambda[1] + 2*Lambda[2] - Lambda[3]] + [-Lambda[1] + 2*Lambda[2] + Lambda[3], + 2*Lambda[1] - Lambda[2] + 2*Lambda[3], + Lambda[1] + 2*Lambda[2] - Lambda[3]] sage: (-L.rho()).succ() [] sage: L.rho().succ(index_set=[1]) @@ -3886,7 +3918,7 @@ def pred(self, index_set=None): INPUT: - - ``index_set`` - a subset (as a list or iterable) of the + - ``index_set`` -- a subset (as a list or iterable) of the nodes of the Dynkin diagram; (default: ``None`` for all of them) If ``index_set`` is specified, the successors for the @@ -3901,7 +3933,9 @@ def pred(self, index_set=None): sage: L.rho().pred() [] sage: (-L.rho()).pred() - [Lambda[1] - 2*Lambda[2] - Lambda[3], -2*Lambda[1] + Lambda[2] - 2*Lambda[3], -Lambda[1] - 2*Lambda[2] + Lambda[3]] + [Lambda[1] - 2*Lambda[2] - Lambda[3], + -2*Lambda[1] + Lambda[2] - 2*Lambda[3], + -Lambda[1] - 2*Lambda[2] + Lambda[3]] sage: (-L.rho()).pred(index_set=[1]) [Lambda[1] - 2*Lambda[2] - Lambda[3]] """ @@ -3909,8 +3943,8 @@ def pred(self, index_set=None): def greater(self): r""" - Returns the elements in the orbit of self which are - greater than self in the weak order. + Return the elements in the orbit of ``self`` which are + greater than ``self`` in the weak order. EXAMPLES:: @@ -3930,8 +3964,8 @@ def greater(self): def smaller(self): r""" - Returns the elements in the orbit of self which are - smaller than self in the weak order. + Return the elements in the orbit of ``self`` which are + smaller than ``self`` in the weak order. EXAMPLES:: @@ -4023,7 +4057,7 @@ def to_simple_root(self, reduced_word=False): OUTPUT: - The index `i` of a simple root `\alpha_i`. - If ``reduced_word`` is True, this returns instead a pair + If ``reduced_word`` is ``True``, this returns instead a pair ``(i, word)``, where word is a sequence of reflections mapping `\alpha_i` up the root poset to ``self``. @@ -4098,15 +4132,16 @@ def to_simple_root(self, reduced_word=False): @cached_in_parent_method def associated_reflection(self): r""" - Given a positive root ``self``, returns a reduced word for the reflection orthogonal to ``self``. + Given a positive root ``self``, return a reduced word for the reflection orthogonal to ``self``. Since the answer is cached, it is a tuple instead of a list. EXAMPLES:: - sage: RootSystem(['C',3]).root_lattice().simple_root(3).weyl_action([1,2]).associated_reflection() + sage: C3_rl = RootSystem(['C',3]).root_lattice() + sage: C3_rl.simple_root(3).weyl_action([1,2]).associated_reflection() (1, 2, 3, 2, 1) - sage: RootSystem(['C',3]).root_lattice().simple_root(2).associated_reflection() + sage: C3_rl.simple_root(2).associated_reflection() (2,) """ @@ -4115,13 +4150,13 @@ def associated_reflection(self): def translation(self, x): """ + Return `x` translated by `t`, that is, `x+level(x) t`. + INPUT: - ``self`` -- an element `t` at level `0` - ``x`` -- an element of the same space - Returns `x` translated by `t`, that is `x+level(x) t` - EXAMPLES:: sage: L = RootSystem(['A',2,1]).weight_lattice() @@ -4177,7 +4212,7 @@ def weyl_action(self, element, inverse=False): sage: mu = wl.from_vector(vector([1,0,-2])) sage: mu Lambda[1] - 2*Lambda[3] - sage: mudom, rw = mu.to_dominant_chamber(positive=False, reduced_word = True) + sage: mudom, rw = mu.to_dominant_chamber(positive=False, reduced_word=True) sage: mudom, rw (-Lambda[2] - Lambda[3], [1, 2]) @@ -4234,15 +4269,15 @@ def weyl_action(self, element, inverse=False): def weyl_stabilizer(self, index_set=None): r""" - Returns the subset of Dynkin nodes whose reflections fix ``self``. + Return the subset of Dynkin nodes whose reflections fix ``self``. - If ``index_set`` is not None, only consider nodes in this set. + If ``index_set`` is not ``None``, only consider nodes in this set. Note that if ``self`` is dominant or antidominant, then its stabilizer is the parabolic subgroup defined by the returned node set. EXAMPLES:: - sage: wl = RootSystem(['A',2,1]).weight_lattice(extended = True) + sage: wl = RootSystem(['A',2,1]).weight_lattice(extended=True) sage: al = wl.null_root() sage: al.weyl_stabilizer() [0, 1, 2] @@ -4254,7 +4289,6 @@ def weyl_stabilizer(self, index_set=None): [3] """ - if index_set is None: index_set = self.parent().cartan_type().index_set() alphavee = self.parent().coroot_lattice().basis() @@ -4309,7 +4343,9 @@ def dot_action(self, w, inverse=False): def is_parabolic_root(self, index_set): r""" - Supposing that ``self`` is a root, is it in the parabolic subsystem with Dynkin nodes ``index_set``? + Return whether ``root`` is in the parabolic subsystem with Dynkin nodes ``index_set``. + + This assumes that ``self`` is a root. INPUT: @@ -4337,7 +4373,7 @@ def is_short_root(self): r""" Return ``True`` if ``self`` is a short (real) root. - Returns False unless the parent is an irreducible root system of finite type + Returns ``False`` unless the parent is an irreducible root system of finite type having two root lengths and ``self`` is of the shorter length. There is no check of whether ``self`` is actually a root. @@ -4439,19 +4475,20 @@ def to_ambient(self): EXAMPLES:: - sage: alpha = CartanType(['B',4]).root_system().root_lattice().an_element(); alpha + sage: B4_rs = CartanType(['B',4]).root_system() + sage: alpha = B4_rs.root_lattice().an_element(); alpha 2*alpha[1] + 2*alpha[2] + 3*alpha[3] sage: alpha.to_ambient() (2, 0, 1, -3) - sage: mu = CartanType(['B',4]).root_system().weight_lattice().an_element(); mu + sage: mu = B4_rs.weight_lattice().an_element(); mu 2*Lambda[1] + 2*Lambda[2] + 3*Lambda[3] sage: mu.to_ambient() (7, 5, 3, 0) - sage: v = CartanType(['B',4]).root_system().ambient_space().an_element(); v + sage: v = B4_rs.ambient_space().an_element(); v (2, 2, 3, 0) sage: v.to_ambient() (2, 2, 3, 0) - sage: alphavee = CartanType(['B',4]).root_system().coroot_lattice().an_element(); alphavee + sage: alphavee = B4_rs.coroot_lattice().an_element(); alphavee 2*alphacheck[1] + 2*alphacheck[2] + 3*alphacheck[3] sage: alphavee.to_ambient() (2, 0, 1, -3) @@ -4482,7 +4519,7 @@ def is_imaginary_root(self): r""" Return ``True`` if ``self`` is an imaginary root. - A root `\alpha` is imaginary if it is not `W` conjugate + A root `\alpha` is imaginary if it is not `W`-conjugate to a simple root where `W` is the corresponding Weyl group. EXAMPLES:: @@ -4501,7 +4538,7 @@ def is_real_root(self): r""" Return ``True`` if ``self`` is a real root. - A root `\alpha` is real if it is `W` conjugate to a simple + A root `\alpha` is real if it is `W`-conjugate to a simple root where `W` is the corresponding Weyl group. EXAMPLES:: From 3178ccbd96966127b0488967f9d5ff46dc1bf3d1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 10:08:56 -0700 Subject: [PATCH 24/26] src/sage/combinat/ordered_tree.py: Docstring cosmetics --- src/sage/combinat/ordered_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/ordered_tree.py b/src/sage/combinat/ordered_tree.py index 8faea2f248b..0b2fa87e3c7 100644 --- a/src/sage/combinat/ordered_tree.py +++ b/src/sage/combinat/ordered_tree.py @@ -353,7 +353,7 @@ def to_parallelogram_polyomino(self, bijection=None): INPUT: - - ``bijection`` -- (default:``'Boussicault-Socci'``) is the name of the + - ``bijection`` -- (default: ``'Boussicault-Socci'``) is the name of the bijection to use. Possible values are ``'Boussicault-Socci'``, ``'via dyck and Delest-Viennot'``. From 62d3d48d42499a387a716efea1be40f7580dfe5a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 10:31:51 -0700 Subject: [PATCH 25/26] src/sage/combinat/designs/block_design.py: Doctest/docstring cosmetics, use file-level # optional - sage.rings.finite_rings, add some # optional - sage.modules --- src/sage/combinat/designs/block_design.py | 196 +++++++++++----------- 1 file changed, 99 insertions(+), 97 deletions(-) diff --git a/src/sage/combinat/designs/block_design.py b/src/sage/combinat/designs/block_design.py index 6e618e36d89..28f3746ad88 100644 --- a/src/sage/combinat/designs/block_design.py +++ b/src/sage/combinat/designs/block_design.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.rings.finite_rings r""" Block designs @@ -75,7 +75,7 @@ def tdesign_params(t, v, k, L): EXAMPLES:: - sage: BD = BlockDesign(7,[[0,1,2],[0,3,4],[0,5,6],[1,3,5],[1,4,6],[2,3,6],[2,4,5]]) + sage: BD = BlockDesign(7, [[0,1,2],[0,3,4],[0,5,6],[1,3,5],[1,4,6],[2,3,6],[2,4,5]]) sage: from sage.combinat.designs.block_design import tdesign_params sage: tdesign_params(2,7,3,1) (2, 7, 7, 3, 3, 1) @@ -114,17 +114,19 @@ def are_hyperplanes_in_projective_geometry_parameters(v, k, lmbda, return_parame EXAMPLES:: sage: from sage.combinat.designs.block_design import are_hyperplanes_in_projective_geometry_parameters - sage: are_hyperplanes_in_projective_geometry_parameters(40,13,4) + sage: are_hyperplanes_in_projective_geometry_parameters(40, 13, 4) True - sage: are_hyperplanes_in_projective_geometry_parameters(40,13,4,return_parameters=True) + sage: are_hyperplanes_in_projective_geometry_parameters(40, 13, 4, + ....: return_parameters=True) (True, (3, 3)) - sage: PG = designs.ProjectiveGeometryDesign(3,2,GF(3)) + sage: PG = designs.ProjectiveGeometryDesign(3, 2, GF(3)) sage: PG.is_t_design(return_parameters=True) (True, (2, 40, 13, 4)) - sage: are_hyperplanes_in_projective_geometry_parameters(15,3,1) + sage: are_hyperplanes_in_projective_geometry_parameters(15, 3, 1) False - sage: are_hyperplanes_in_projective_geometry_parameters(15,3,1,return_parameters=True) + sage: are_hyperplanes_in_projective_geometry_parameters(15, 3, 1, + ....: return_parameters=True) (False, (None, None)) TESTS:: @@ -167,7 +169,7 @@ def ProjectiveGeometryDesign(n, d, F, algorithm=None, point_coordinates=True, ch Return a projective geometry design. The projective geometry design `PG_d(n,q)` has for points the lines of - `\GF{q}^{n+1}`, and for blocks the `d+1`-dimensional subspaces of + `\GF{q}^{n+1}`, and for blocks the `(d+1)`-dimensional subspaces of `\GF{q}^{n+1}`, each of which contains `\frac {|\GF{q}|^{d+1}-1} {|\GF{q}|-1}` lines. It is a `2`-design with parameters @@ -189,9 +191,9 @@ def ProjectiveGeometryDesign(n, d, F, algorithm=None, point_coordinates=True, ch INPUT: - - ``n`` is the projective dimension + - ``n`` -- the projective dimension - - ``d`` is the dimension of the subspaces which make up the blocks. + - ``d`` -- the dimension of the subspaces which make up the blocks. - ``F`` -- a finite field or a prime power. @@ -236,14 +238,14 @@ def ProjectiveGeometryDesign(n, d, F, algorithm=None, point_coordinates=True, ch Use indexing by integers:: - sage: PG = designs.ProjectiveGeometryDesign(2,1,GF(3),point_coordinates=0) + sage: PG = designs.ProjectiveGeometryDesign(2, 1, GF(3), point_coordinates=0) sage: PG.blocks()[0] [0, 1, 2, 12] Check that the constructor using gap also works:: - sage: BD = designs.ProjectiveGeometryDesign(2, 1, GF(2), algorithm="gap") # optional - gap_packages (design package) - sage: BD.is_t_design(return_parameters=True) # optional - gap_packages (design package) + sage: BD = designs.ProjectiveGeometryDesign(2, 1, GF(2), algorithm="gap") # optional - gap_packages (design package) + sage: BD.is_t_design(return_parameters=True) # optional - gap_packages (design package) (True, (2, 7, 3, 1)) """ try: @@ -304,7 +306,7 @@ def DesarguesianProjectivePlaneDesign(n, point_coordinates=True, check=True): - ``n`` -- an integer which must be a power of a prime number - - ``point_coordinates`` (boolean) -- whether to label the points with their + - ``point_coordinates`` -- (boolean) whether to label the points with their homogeneous coordinates (default) or with integers. - ``check`` -- (boolean) Whether to check that output is correct before @@ -318,15 +320,15 @@ def DesarguesianProjectivePlaneDesign(n, point_coordinates=True, check=True): EXAMPLES:: - sage: designs.DesarguesianProjectivePlaneDesign(2) # optional - sage.rings.finite_rings + sage: designs.DesarguesianProjectivePlaneDesign(2) (7,3,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(3) # optional - sage.rings.finite_rings + sage: designs.DesarguesianProjectivePlaneDesign(3) (13,4,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(4) # optional - sage.rings.finite_rings + sage: designs.DesarguesianProjectivePlaneDesign(4) (21,5,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(5) # optional - sage.rings.finite_rings + sage: designs.DesarguesianProjectivePlaneDesign(5) (31,6,1)-Balanced Incomplete Block Design - sage: designs.DesarguesianProjectivePlaneDesign(6) # optional - sage.rings.finite_rings + sage: designs.DesarguesianProjectivePlaneDesign(6) Traceback (most recent call last): ... ValueError: the order of a finite field must be a prime power @@ -395,25 +397,25 @@ def q3_minus_one_matrix(K): r""" Return a companion matrix in `GL(3, K)` whose multiplicative order is `q^3 - 1`. - This function is used in :func:`HughesPlane` + This function is used in :func:`HughesPlane`. EXAMPLES:: sage: from sage.combinat.designs.block_design import q3_minus_one_matrix - sage: m = q3_minus_one_matrix(GF(3)) # optional - sage.rings.finite_rings - sage: m.multiplicative_order() == 3**3 - 1 # optional - sage.rings.finite_rings + sage: m = q3_minus_one_matrix(GF(3)) + sage: m.multiplicative_order() == 3**3 - 1 True - sage: m = q3_minus_one_matrix(GF(4, 'a')) # optional - sage.rings.finite_rings - sage: m.multiplicative_order() == 4**3 - 1 # optional - sage.rings.finite_rings + sage: m = q3_minus_one_matrix(GF(4, 'a')) + sage: m.multiplicative_order() == 4**3 - 1 True - sage: m = q3_minus_one_matrix(GF(5)) # optional - sage.rings.finite_rings - sage: m.multiplicative_order() == 5**3 - 1 # optional - sage.rings.finite_rings + sage: m = q3_minus_one_matrix(GF(5)) + sage: m.multiplicative_order() == 5**3 - 1 True - sage: m = q3_minus_one_matrix(GF(9, 'a')) # optional - sage.rings.finite_rings - sage: m.multiplicative_order() == 9**3 - 1 # optional - sage.rings.finite_rings + sage: m = q3_minus_one_matrix(GF(9, 'a')) + sage: m.multiplicative_order() == 9**3 - 1 True """ q = K.cardinality() @@ -450,24 +452,24 @@ def normalize_hughes_plane_point(p, q): INPUT: - - ``p`` - point with the coordinates (x,y,z) (a list, a vector, a tuple...) + - ``p`` -- point with the coordinates `(x,y,z)` (a list, a vector, a tuple...) - - ``q`` - cardinality of the underlying finite field + - ``q`` -- cardinality of the underlying finite field EXAMPLES:: sage: from sage.combinat.designs.block_design import normalize_hughes_plane_point - sage: K = FiniteField(9,'x') # optional - sage.rings.finite_rings - sage: x = K.gen() # optional - sage.rings.finite_rings - sage: normalize_hughes_plane_point((x, x+1, x), 9) # optional - sage.rings.finite_rings + sage: K = FiniteField(9,'x') + sage: x = K.gen() + sage: normalize_hughes_plane_point((x, x + 1, x), 9) (1, x, 1) - sage: normalize_hughes_plane_point(vector((x,x,x)), 9) # optional - sage.rings.finite_rings + sage: normalize_hughes_plane_point(vector((x,x,x)), 9) (1, 1, 1) - sage: zero = K.zero() # optional - sage.rings.finite_rings - sage: normalize_hughes_plane_point((2*x+2, zero, zero), 9) # optional - sage.rings.finite_rings + sage: zero = K.zero() + sage: normalize_hughes_plane_point((2*x + 2, zero, zero), 9) (1, 0, 0) - sage: one = K.one() # optional - sage.rings.finite_rings - sage: normalize_hughes_plane_point((2*x, one, zero), 9) # optional - sage.rings.finite_rings + sage: one = K.one() + sage: normalize_hughes_plane_point((2*x, one, zero), 9) (2*x, 1, 0) """ for i in [2,1,0]: @@ -526,7 +528,7 @@ def HughesPlane(q2, check=True): EXAMPLES:: - sage: H = designs.HughesPlane(9); H # optional - sage.rings.finite_rings + sage: H = designs.HughesPlane(9); H (91,10,1)-Balanced Incomplete Block Design We prove in the following computations that the Desarguesian plane ``H`` is @@ -535,45 +537,45 @@ def HughesPlane(q2, check=True): `D_{1,10} \cap D_{70,59}` and `D_{10,0} \cap D_{59,57}` are on the same line while `D_{0,70}`, `D_{1,59}` and `D_{10,57}` are not concurrent:: - sage: blocks = H.blocks() # optional - sage.rings.finite_rings - sage: line = lambda p,q: next(b for b in blocks if p in b and q in b) # optional - sage.rings.finite_rings + sage: blocks = H.blocks() + sage: line = lambda p,q: next(b for b in blocks if p in b and q in b) - sage: b_0_1 = line(0, 1) # optional - sage.rings.finite_rings - sage: b_1_10 = line(1, 10) # optional - sage.rings.finite_rings - sage: b_10_0 = line(10, 0) # optional - sage.rings.finite_rings - sage: b_57_70 = line(57, 70) # optional - sage.rings.finite_rings - sage: b_70_59 = line(70, 59) # optional - sage.rings.finite_rings - sage: b_59_57 = line(59, 57) # optional - sage.rings.finite_rings + sage: b_0_1 = line(0, 1) + sage: b_1_10 = line(1, 10) + sage: b_10_0 = line(10, 0) + sage: b_57_70 = line(57, 70) + sage: b_70_59 = line(70, 59) + sage: b_59_57 = line(59, 57) - sage: set(b_0_1).intersection(b_57_70) # optional - sage.rings.finite_rings + sage: set(b_0_1).intersection(b_57_70) {2} - sage: set(b_1_10).intersection(b_70_59) # optional - sage.rings.finite_rings + sage: set(b_1_10).intersection(b_70_59) {73} - sage: set(b_10_0).intersection(b_59_57) # optional - sage.rings.finite_rings + sage: set(b_10_0).intersection(b_59_57) {60} - sage: line(2, 73) == line(73, 60) # optional - sage.rings.finite_rings + sage: line(2, 73) == line(73, 60) True - sage: b_0_57 = line(0, 57) # optional - sage.rings.finite_rings - sage: b_1_70 = line(1, 70) # optional - sage.rings.finite_rings - sage: b_10_59 = line(10, 59) # optional - sage.rings.finite_rings + sage: b_0_57 = line(0, 57) + sage: b_1_70 = line(1, 70) + sage: b_10_59 = line(10, 59) - sage: p = set(b_0_57).intersection(b_1_70) # optional - sage.rings.finite_rings - sage: q = set(b_1_70).intersection(b_10_59) # optional - sage.rings.finite_rings - sage: p == q # optional - sage.rings.finite_rings + sage: p = set(b_0_57).intersection(b_1_70) + sage: q = set(b_1_70).intersection(b_10_59) + sage: p == q False TESTS: Some wrong input:: - sage: designs.HughesPlane(5) # optional - sage.rings.finite_rings + sage: designs.HughesPlane(5) Traceback (most recent call last): ... EmptySetError: No Hughes plane of non-square order exists. - sage: designs.HughesPlane(16) # optional - sage.rings.finite_rings + sage: designs.HughesPlane(16) Traceback (most recent call last): ... EmptySetError: No Hughes plane of even order exists. @@ -631,9 +633,9 @@ def projective_plane_to_OA(pplane, pt=None, check=True): INPUT: - - ``pplane`` - a projective plane as a 2-design + - ``pplane`` -- a projective plane as a 2-design - - ``pt`` - a point in the projective plane ``pplane``. If it is not provided + - ``pt`` -- a point in the projective plane ``pplane``. If it is not provided, then it is set to `n^2 + n`. - ``check`` -- (boolean) Whether to check that output is correct before @@ -644,13 +646,11 @@ def projective_plane_to_OA(pplane, pt=None, check=True): EXAMPLES:: sage: from sage.combinat.designs.block_design import projective_plane_to_OA - sage: p2 = designs.DesarguesianProjectivePlaneDesign(2, # optional - sage.rings.finite_rings - ....: point_coordinates=False) - sage: projective_plane_to_OA(p2) # optional - sage.rings.finite_rings + sage: p2 = designs.DesarguesianProjectivePlaneDesign(2, point_coordinates=False) + sage: projective_plane_to_OA(p2) [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]] - sage: p3 = designs.DesarguesianProjectivePlaneDesign(3, # optional - sage.rings.finite_rings - ....: point_coordinates=False) - sage: projective_plane_to_OA(p3) # optional - sage.rings.finite_rings + sage: p3 = designs.DesarguesianProjectivePlaneDesign(3, point_coordinates=False) + sage: projective_plane_to_OA(p3) [[0, 0, 0, 0], [0, 1, 2, 1], [0, 2, 1, 2], @@ -661,11 +661,10 @@ def projective_plane_to_OA(pplane, pt=None, check=True): [2, 1, 0, 2], [2, 2, 2, 0]] - sage: pp = designs.DesarguesianProjectivePlaneDesign(16, # optional - sage.rings.finite_rings - ....: point_coordinates=False) - sage: _ = projective_plane_to_OA(pp, pt=0) # optional - sage.rings.finite_rings - sage: _ = projective_plane_to_OA(pp, pt=3) # optional - sage.rings.finite_rings - sage: _ = projective_plane_to_OA(pp, pt=7) # optional - sage.rings.finite_rings + sage: pp = designs.DesarguesianProjectivePlaneDesign(16, point_coordinates=False) + sage: _ = projective_plane_to_OA(pp, pt=0) + sage: _ = projective_plane_to_OA(pp, pt=3) + sage: _ = projective_plane_to_OA(pp, pt=7) """ from .bibd import _relabel_bibd pplane = pplane.blocks() @@ -697,9 +696,9 @@ def projective_plane(n, check=True, existence=False): `n^2+n+1` points. For more information on finite projective planes, see the :wikipedia:`Projective_plane#Finite_projective_planes`. - If no construction is possible, then the function raises a ``EmptySetError`` - whereas if no construction is available the function raises a - ``NotImplementedError``. + If no construction is possible, then the function raises a :class:`EmptySetError`, + whereas if no construction is available, the function raises a + :class:`NotImplementedError`. INPUT: @@ -722,11 +721,14 @@ def projective_plane(n, check=True, existence=False): sage: designs.projective_plane(10) Traceback (most recent call last): ... - EmptySetError: No projective plane of order 10 exists by C. Lam, L. Thiel and S. Swiercz "The nonexistence of finite projective planes of order 10" (1989), Canad. J. Math. + EmptySetError: No projective plane of order 10 exists by + C. Lam, L. Thiel and S. Swiercz "The nonexistence of finite + projective planes of order 10" (1989), Canad. J. Math. sage: designs.projective_plane(12) Traceback (most recent call last): ... - NotImplementedError: If such a projective plane exists, we do not know how to build it. + NotImplementedError: If such a projective plane exists, + we do not know how to build it. sage: designs.projective_plane(14) Traceback (most recent call last): ... @@ -813,28 +815,28 @@ def AffineGeometryDesign(n, d, F, point_coordinates=True, check=True): EXAMPLES:: - sage: BD = designs.AffineGeometryDesign(3, 1, GF(2)) # optional - sage.rings.finite_rings - sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings + sage: BD = designs.AffineGeometryDesign(3, 1, GF(2)) + sage: BD.is_t_design(return_parameters=True) (True, (2, 8, 2, 1)) - sage: BD = designs.AffineGeometryDesign(3, 2, GF(4)) # optional - sage.rings.finite_rings - sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings + sage: BD = designs.AffineGeometryDesign(3, 2, GF(4)) + sage: BD.is_t_design(return_parameters=True) (True, (2, 64, 16, 5)) - sage: BD = designs.AffineGeometryDesign(4, 2, GF(3)) # optional - sage.rings.finite_rings - sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings + sage: BD = designs.AffineGeometryDesign(4, 2, GF(3)) + sage: BD.is_t_design(return_parameters=True) (True, (2, 81, 9, 13)) With ``F`` an integer instead of a finite field:: - sage: BD = designs.AffineGeometryDesign(3, 2, 4) # optional - sage.rings.finite_rings - sage: BD.is_t_design(return_parameters=True) # optional - sage.rings.finite_rings + sage: BD = designs.AffineGeometryDesign(3, 2, 4) + sage: BD.is_t_design(return_parameters=True) (True, (2, 64, 16, 5)) Testing the option ``point_coordinates``:: - sage: designs.AffineGeometryDesign(3, 1, GF(2), # optional - sage.rings.finite_rings + sage: designs.AffineGeometryDesign(3, 1, GF(2), ....: point_coordinates=True).blocks()[0] [(0, 0, 0), (0, 0, 1)] - sage: designs.AffineGeometryDesign(3, 1, GF(2), # optional - sage.rings.finite_rings + sage: designs.AffineGeometryDesign(3, 1, GF(2), ....: point_coordinates=False).blocks()[0] [0, 1] """ @@ -886,7 +888,7 @@ def AffineGeometryDesign(n, d, F, point_coordinates=True, check=True): def CremonaRichmondConfiguration(): r""" - Return the Cremona-Richmond configuration + Return the Cremona-Richmond configuration. The Cremona-Richmond configuration is a set system whose incidence graph is equal to the @@ -954,16 +956,16 @@ def HadamardDesign(n): EXAMPLES:: - sage: designs.HadamardDesign(7) + sage: designs.HadamardDesign(7) # optional - sage.modules Incidence structure with 7 points and 7 blocks - sage: print(designs.HadamardDesign(7)) + sage: print(designs.HadamardDesign(7)) # optional - sage.modules Incidence structure with 7 points and 7 blocks - For example, the Hadamard 2-design with `n = 11` is a design whose parameters are 2-(11, 5, 2). + For example, the Hadamard 2-design with `n = 11` is a design whose parameters are `2-(11, 5, 2)`. We verify that `NJ = 5J` for this design. :: - sage: D = designs.HadamardDesign(11); N = D.incidence_matrix() - sage: J = matrix(ZZ, 11, 11, [1]*11*11); N*J + sage: D = designs.HadamardDesign(11); N = D.incidence_matrix() # optional - sage.modules + sage: J = matrix(ZZ, 11, 11, [1]*11*11); N*J # optional - sage.modules [5 5 5 5 5 5 5 5 5 5 5] [5 5 5 5 5 5 5 5 5 5 5] [5 5 5 5 5 5 5 5 5 5 5] @@ -1007,7 +1009,7 @@ def Hadamard3Design(n): EXAMPLES:: - sage: designs.Hadamard3Design(12) + sage: designs.Hadamard3Design(12) # optional - sage.modules Incidence structure with 12 points and 22 blocks We verify that any two blocks of the Hadamard `3`-design `3-(8, 4, 1)` @@ -1017,9 +1019,9 @@ def Hadamard3Design(n): :: - sage: D = designs.Hadamard3Design(8) - sage: N = D.incidence_matrix() - sage: N.transpose()*N + sage: D = designs.Hadamard3Design(8) # optional - sage.modules + sage: N = D.incidence_matrix() # optional - sage.modules + sage: N.transpose()*N # optional - sage.modules [4 2 2 2 2 2 2 2 2 2 2 2 2 0] [2 4 2 2 2 2 2 2 2 2 2 2 0 2] [2 2 4 2 2 2 2 2 2 2 2 0 2 2] From e5fd4e13a18ad36d367170acf861d38fbb2c066c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 10:37:01 -0700 Subject: [PATCH 26/26] Fix typo of # optional - sage.modules --- src/sage/categories/magmas.py | 22 +++++++++++----------- src/sage/combinat/designs/designs_pyx.pyx | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/sage/categories/magmas.py b/src/sage/categories/magmas.py index e80088548a9..178361b2961 100644 --- a/src/sage/categories/magmas.py +++ b/src/sage/categories/magmas.py @@ -902,10 +902,10 @@ def multiplication_table(self, names='letters', elements=None): sage: from sage.categories.examples.finite_semigroups import LeftRegularBand sage: L = LeftRegularBand(('a', 'b')) - sage: T = L.multiplication_table(names='digits') # optional - sage.matrix - sage: T.column_keys() # optional - sage.matrix + sage: T = L.multiplication_table(names='digits') # optional - sage.modules + sage: T.column_keys() # optional - sage.modules ('a', 'ab', 'b', 'ba') - sage: T # optional - sage.matrix + sage: T # optional - sage.modules * 0 1 2 3 +-------- 0| 0 1 1 1 @@ -918,7 +918,7 @@ def multiplication_table(self, names='letters', elements=None): sage: L = LeftRegularBand(('a', 'b', 'c')) sage: elts = sorted(L.list()) - sage: L.multiplication_table(elements=elts) # optional - sage.matrix + sage: L.multiplication_table(elements=elts) # optional - sage.modules * a b c d e f g h i j k l m n o +------------------------------ a| a b c d e b b c c c d d e e e @@ -947,7 +947,7 @@ def multiplication_table(self, names='letters', elements=None): sage: L = LeftRegularBand(('a','b','c')) sage: elts=['a', 'c', 'ac', 'ca'] - sage: L.multiplication_table(names='elements', elements=elts) # optional - sage.matrix + sage: L.multiplication_table(names='elements', elements=elts) # optional - sage.modules * 'a' 'c' 'ac' 'ca' +-------------------- 'a'| 'a' 'ac' 'ac' 'ac' @@ -961,15 +961,15 @@ def multiplication_table(self, names='letters', elements=None): comprehensive documentation. :: sage: G = AlternatingGroup(3) # optional - sage.groups - sage: T = G.multiplication_table() # optional - sage.groups sage.matrix - sage: T.column_keys() # optional - sage.groups sage.matrix + sage: T = G.multiplication_table() # optional - sage.groups sage.modules + sage: T.column_keys() # optional - sage.groups sage.modules ((), (1,2,3), (1,3,2)) - sage: T.translation() # optional - sage.groups sage.matrix + sage: T.translation() # optional - sage.groups sage.modules {'a': (), 'b': (1,2,3), 'c': (1,3,2)} - sage: T.change_names(['x', 'y', 'z']) # optional - sage.groups sage.matrix - sage: T.translation() # optional - sage.groups sage.matrix + sage: T.change_names(['x', 'y', 'z']) # optional - sage.groups sage.modules + sage: T.translation() # optional - sage.groups sage.modules {'x': (), 'y': (1,2,3), 'z': (1,3,2)} - sage: T # optional - sage.groups sage.matrix + sage: T # optional - sage.groups sage.modules * x y z +------ x| x y z diff --git a/src/sage/combinat/designs/designs_pyx.pyx b/src/sage/combinat/designs/designs_pyx.pyx index 55cfbca19b1..be8745f2acb 100644 --- a/src/sage/combinat/designs/designs_pyx.pyx +++ b/src/sage/combinat/designs/designs_pyx.pyx @@ -183,16 +183,16 @@ def is_group_divisible_design(groups,blocks,v,G=None,K=None,lambd=1,verbose=Fals EXAMPLES:: sage: from sage.combinat.designs.designs_pyx import is_group_divisible_design - sage: TD = designs.transversal_design(4,10) # optional - sage.matrix - sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.matrix - sage: is_group_divisible_design(groups,TD,40,lambd=1) # optional - sage.matrix + sage: TD = designs.transversal_design(4,10) # optional - sage.modules + sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.modules + sage: is_group_divisible_design(groups,TD,40,lambd=1) # optional - sage.modules True TESTS:: - sage: TD = designs.transversal_design(4,10) # optional - sage.matrix - sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.matrix - sage: is_group_divisible_design(groups, TD, 40, lambd=2, verbose=True) # optional - sage.matrix + sage: TD = designs.transversal_design(4,10) # optional - sage.modules + sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.modules + sage: is_group_divisible_design(groups, TD, 40, lambd=2, verbose=True) # optional - sage.modules the pair (0,10) has been seen 1 times but lambda=2 False sage: is_group_divisible_design([[1,2],[3,4]],[[1,2]],40,lambd=1,verbose=True) @@ -362,18 +362,18 @@ def is_pairwise_balanced_design(blocks,v,K=None,lambd=1,verbose=False): sage: sts = designs.steiner_triple_system(9) sage: is_pairwise_balanced_design(sts,9,[3],1) True - sage: TD = designs.transversal_design(4,10).blocks() # optional - sage.matrix - sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.matrix - sage: is_pairwise_balanced_design(TD + groups, 40, [4,10], 1, verbose=True) # optional - sage.matrix + sage: TD = designs.transversal_design(4,10).blocks() # optional - sage.modules + sage: groups = [list(range(i*10,(i+1)*10)) for i in range(4)] # optional - sage.modules + sage: is_pairwise_balanced_design(TD + groups, 40, [4,10], 1, verbose=True) # optional - sage.modules True TESTS:: sage: from sage.combinat.designs.designs_pyx import is_pairwise_balanced_design - sage: is_pairwise_balanced_design(TD + groups, 40, [4,10], 2, verbose=True) # optional - sage.matrix + sage: is_pairwise_balanced_design(TD + groups, 40, [4,10], 2, verbose=True) # optional - sage.modules the pair (0,1) has been seen 1 times but lambda=2 False - sage: is_pairwise_balanced_design(TD + groups, 40, [10], 1, verbose=True) # optional - sage.matrix + sage: is_pairwise_balanced_design(TD + groups, 40, [10], 1, verbose=True) # optional - sage.modules a block has size 4 while K=[10] False sage: is_pairwise_balanced_design([[2,2]],40,[2],1,verbose=True)