Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Global options as class attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewMathas committed Jun 26, 2016
1 parent 9313ce8 commit 11a13f4
Show file tree
Hide file tree
Showing 13 changed files with 829 additions and 781 deletions.
99 changes: 53 additions & 46 deletions src/sage/combinat/crystals/tensor_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
import operator
from sage.misc.latex import latex
from sage.misc.cachefunc import cached_method, cached_in_parent_method
from sage.misc.superseded import deprecated_function_alias
from sage.structure.parent import Parent
from sage.structure.element import parent
from sage.structure.global_options import AddOptionsToClass
from sage.structure.global_options import GlobalOptions
from sage.categories.category import Category
from sage.categories.cartesian_product import cartesian_product
from sage.categories.classical_crystals import ClassicalCrystals
Expand Down Expand Up @@ -666,6 +667,56 @@ def __classcall_private__(cls, *crystals, **options):
return FullTensorProductOfRegularCrystals(tp, cartan_type=cartan_type)
return FullTensorProductOfCrystals(tp, cartan_type=cartan_type)

# add options to class
options=GlobalOptions('TensorProductOfCrystals',
doc=r"""
Sets the global options for tensor products of crystals. The default is to
use the anti-Kashiwara convention.
There are two conventions for how `e_i` and `f_i` act on tensor products,
and the difference between the two is the order of the tensor factors
are reversed. This affects both the input and output. See the example
below.
""",
end_doc=r"""
.. NOTE::
Changing the ``convention`` also changes how the input is handled.
.. WARNING::
Internally, the crystals are always stored using the anti-Kashiwara
convention.
If no parameters are set, then the function returns a copy of the
options dictionary.
EXAMPLES::
sage: C = crystals.Letters(['A',2])
sage: T = crystals.TensorProduct(C,C)
sage: elt = T(C(1), C(2)); elt
[1, 2]
sage: crystals.TensorProduct.options.convention = "Kashiwara"
sage: elt
[2, 1]
sage: T(C(1), C(2)) == elt
False
sage: T(C(2), C(1)) == elt
True
sage: crystals.TensorProduct.options._reset()
""",
convention=dict(default="antiKashiwara",
description='Sets the convention used for displaying/inputting tensor product of crystals',
values=dict(antiKashiwara='use the anti-Kashiwara convention',
Kashiwara='use the Kashiwara convention'),
alias=dict(anti="antiKashiwara", opposite="antiKashiwara"),
case_sensitive=False)
)

global_options=deprecated_function_alias(18555, options)

def _element_constructor_(self, *crystalElements):
"""
EXAMPLES::
Expand All @@ -684,52 +735,8 @@ def _element_constructor_(self, *crystalElements):
crystalElements = reversed(crystalElements)
return self.element_class(self, list(crystalElements))

AddOptionsToClass(TensorProductOfCrystals,
doc=r"""
Sets the global options for tensor products of crystals. The default is to
use the anti-Kashiwara convention.
There are two conventions for how `e_i` and `f_i` act on tensor products,
and the difference between the two is the order of the tensor factors
are reversed. This affects both the input and output. See the example
below.
""",
end_doc=r"""
.. NOTE::
Changing the ``convention`` also changes how the input is handled.
.. WARNING::
Internally, the crystals are always stored using the anti-Kashiwara
convention.
If no parameters are set, then the function returns a copy of the
options dictionary.

EXAMPLES::
sage: C = crystals.Letters(['A',2])
sage: T = crystals.TensorProduct(C,C)
sage: elt = T(C(1), C(2)); elt
[1, 2]
sage: crystals.TensorProduct.options.convention = "Kashiwara"
sage: elt
[2, 1]
sage: T(C(1), C(2)) == elt
False
sage: T(C(2), C(1)) == elt
True
sage: crystals.TensorProduct.options._reset()
""",
convention=dict(default="antiKashiwara",
description='Sets the convention used for displaying/inputting tensor product of crystals',
values=dict(antiKashiwara='use the anti-Kashiwara convention',
Kashiwara='use the Kashiwara convention'),
alias=dict(anti="antiKashiwara", opposite="antiKashiwara"),
case_sensitive=False)
)
TensorProductOfCrystalsOptions=deprecated_function_alias(18555, TensorProductOfCrystals.options)

class TensorProductOfCrystalsWithGenerators(TensorProductOfCrystals):
"""
Expand Down
65 changes: 35 additions & 30 deletions src/sage/combinat/diagram_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.combinat.combinat import bell_number, catalan_number
from sage.structure.global_options import AddOptionsToClass
from sage.structure.global_options import GlobalOptions
from sage.combinat.set_partition import SetPartitions, SetPartition
from sage.combinat.partition import Partitions
from sage.combinat.symmetric_group_algebra import SymmetricGroupAlgebra_n
Expand Down Expand Up @@ -1878,6 +1878,39 @@ def __init__(self, k, q, base_ring, prefix):
"""
SubPartitionAlgebra.__init__(self, k, q, base_ring, prefix, BrauerDiagrams(k))

# add options to class
options=GlobalOptions('BrauerAlgebra',
doc=r"""
Set and display the global options for Brauer diagram (algebras). If no
parameters are set, then the function returns a copy of the options
dictionary.
The ``options`` to diagram algebras can be accessed as the method
:obj:`BrauerAlgebra.options` of :class:`BrauerAlgebra` and
related classes.
""",
end_doc=r"""
EXAMPLES::
sage: R.<q> = QQ[]
sage: BA = BrauerAlgebra(2, q)
sage: E = BA([[1,2],[-1,-2]])
sage: E
B{{-2, -1}, {1, 2}}
sage: BrauerAlgebra.options(display="compact")
sage: E
B[12/12;]
sage: BrauerAlgebra.options._reset()
""",
display=dict(default="normal",
description='Specifies how the Brauer diagrams should be printed',
values=dict(normal="Using the normal representation",
compact="Using the compact representation"),
case_sensitive=False),
)

global_options=deprecated_function_alias(18555, options)

def _repr_(self):
"""
Return a string representation of ``self``.
Expand Down Expand Up @@ -1978,35 +2011,7 @@ def jucys_murphy(self, j):
d[I([[i,j],[-i,-j]])] = -one
return self._from_dict(d, remove_zeros=True)

AddOptionsToClass(BrauerAlgebra,
doc=r"""
Set and display the global options for Brauer diagram (algebras). If no
parameters are set, then the function returns a copy of the options
dictionary.
The ``options`` to diagram algebras can be accessed as the method
:obj:`BrauerAlgebra.options` of :class:`BrauerAlgebra` and
related classes.
""",
end_doc=r"""
EXAMPLES::
sage: R.<q> = QQ[]
sage: BA = BrauerAlgebra(2, q)
sage: E = BA([[1,2],[-1,-2]])
sage: E
B{{-2, -1}, {1, 2}}
sage: BrauerAlgebra.options(display="compact")
sage: E
B[12/12;]
sage: BrauerAlgebra.options._reset()
""",
display=dict(default="normal",
description='Specifies how the Brauer diagrams should be printed',
values=dict(normal="Using the normal representation",
compact="Using the compact representation"),
case_sensitive=False),
)
BrauerAlgberaOptions=deprecated_function_alias(18555, BrauerAlgebra.options)

class TemperleyLiebAlgebra(SubPartitionAlgebra):
r"""
Expand Down
142 changes: 73 additions & 69 deletions src/sage/combinat/dyck_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from sage.combinat.combinatorial_map import combinatorial_map
from backtrack import GenericBacktracker

from sage.structure.global_options import AddOptionsToClass
from sage.structure.global_options import GlobalOptions
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
Expand All @@ -74,6 +74,7 @@
from sage.combinat.words.word import Word
from sage.combinat.alternating_sign_matrix import AlternatingSignMatrices
from sage.misc.latex import latex
from sage.misc.superseded import deprecated_function_alias

open_symbol = 1
close_symbol = 0
Expand Down Expand Up @@ -3064,6 +3065,76 @@ def __classcall_private__(cls, k1=None, k2=None, complete=True):

Element = DyckWord

# add options to class
options=GlobalOptions('DyckWords',
doc=r"""
Set and display the options for Dyck words. If no parameters
are set, then the function returns a copy of the options dictionary.
The ``options`` to Dyck words can be accessed as the method
:meth:`DyckWords.options` of :class:`DyckWords` and
related parent classes.
""",
end_doc=r"""
EXAMPLES::
sage: D = DyckWord([1, 1, 0, 1, 0, 0])
sage: D
[1, 1, 0, 1, 0, 0]
sage: DyckWords.options(display="lattice")
sage: D
___
_| x
| x .
| . .
sage: DyckWords.options(diagram_style="line")
sage: D
/\/\
/ \
sage: DyckWords.options._reset()
""",
display=dict(default="list",
description='Specifies how Dyck words should be printed',
values=dict(list='displayed as a list',
lattice='displayed on the lattice defined by ``diagram_style``'),
case_sensitive=False),
ascii_art=dict(default="path",
description='Specifies how the ascii art of Dyck words should be printed',
values=dict(path="Using the path string",
pretty_output="Using pretty printing"),
alias=dict(pretty_print="pretty_output", path_string="path"),
case_sensitive=False),
diagram_style=dict(default="grid",
values=dict(grid='printing as paths on a grid using N and E steps',
line='printing as paths on a line using NE and SE steps',),
alias={'N-E': 'grid', 'NE-SE': 'line'},
case_sensitive=False),
latex_tikz_scale=dict(default=1,
description='The default value for the tikz scale when latexed',
checker=lambda x: True), # More trouble than it's worth to check
latex_diagonal=dict(default=False,
description='The default value for displaying the diagonal when latexed',
checker=lambda x: isinstance(x, bool)),
latex_line_width_scalar=dict(default=2,
description='The default value for the line width as a'
'multiple of the tikz scale when latexed',
checker=lambda x: True), # More trouble than it's worth to check
latex_color=dict(default="black",
description='The default value for the color when latexed',
checker=lambda x: isinstance(x, str)),
latex_bounce_path=dict(default=False,
description='The default value for displaying the bounce path when latexed',
checker=lambda x: isinstance(x, bool)),
latex_peaks=dict(default=False,
description='The default value for displaying the peaks when latexed',
checker=lambda x: isinstance(x, bool)),
latex_valleys=dict(default=False,
description='The default value for displaying the valleys when latexed',
checker=lambda x: isinstance(x, bool)),
)

global_options=deprecated_function_alias(18555, options)

def _element_constructor_(self, word):
"""
Construct an element of ``self``.
Expand Down Expand Up @@ -3229,74 +3300,7 @@ def min_from_heights(self, heights):
heights[i-1] = heights[i] - 1
return self.from_heights(heights)

AddOptionsToClass(DyckWords,
doc=r"""
Set and display the options for Dyck words. If no parameters
are set, then the function returns a copy of the options dictionary.
The ``options`` to Dyck words can be accessed as the method
:meth:`DyckWords.options` of :class:`DyckWords` and
related parent classes.
""",
end_doc=r"""
EXAMPLES::
sage: D = DyckWord([1, 1, 0, 1, 0, 0])
sage: D
[1, 1, 0, 1, 0, 0]
sage: DyckWords.options(display="lattice")
sage: D
___
_| x
| x .
| . .
sage: DyckWords.options(diagram_style="line")
sage: D
/\/\
/ \
sage: DyckWords.options._reset()
""",
display=dict(default="list",
description='Specifies how Dyck words should be printed',
values=dict(list='displayed as a list',
lattice='displayed on the lattice defined by ``diagram_style``'),
case_sensitive=False),
ascii_art=dict(default="path",
description='Specifies how the ascii art of Dyck words should be printed',
values=dict(path="Using the path string",
pretty_output="Using pretty printing"),
alias=dict(pretty_print="pretty_output", path_string="path"),
case_sensitive=False),
diagram_style=dict(default="grid",
values=dict(grid='printing as paths on a grid using N and E steps',
line='printing as paths on a line using NE and SE steps',),
alias={'N-E': 'grid', 'NE-SE': 'line'},
case_sensitive=False),
latex_tikz_scale=dict(default=1,
description='The default value for the tikz scale when latexed',
checker=lambda x: True), # More trouble than it's worth to check
latex_diagonal=dict(default=False,
description='The default value for displaying the diagonal when latexed',
checker=lambda x: isinstance(x, bool)),
latex_line_width_scalar=dict(default=2,
description='The default value for the line width as a'
'multiple of the tikz scale when latexed',
checker=lambda x: True), # More trouble than it's worth to check
latex_color=dict(default="black",
description='The default value for the color when latexed',
checker=lambda x: isinstance(x, str)),
latex_bounce_path=dict(default=False,
description='The default value for displaying the bounce path when latexed',
checker=lambda x: isinstance(x, bool)),
latex_peaks=dict(default=False,
description='The default value for displaying the peaks when latexed',
checker=lambda x: isinstance(x, bool)),
latex_valleys=dict(default=False,
description='The default value for displaying the valleys when latexed',
checker=lambda x: isinstance(x, bool)),
)


DyckWordOptions = deprecated_function_alias(18555, DyckWords.options)

class DyckWords_all(DyckWords):
"""
Expand Down

0 comments on commit 11a13f4

Please sign in to comment.