def __init__(self, parent, children = None, check = True): """ TESTS:: sage: BinaryTree([None, None]).parent() Binary trees sage: BinaryTree("[., [., [., .]]]") [., [., [., .]]] sage: BinaryTree("[.,.,.]") Traceback (most recent call last): ... ValueError: this is not a binary tree sage: all(BinaryTree(repr(bt)) == bt for i in range(6) for bt in BinaryTrees(i)) True """ if (type(children) is str): # if the input is the repr of a binary tree children = children.replace(".","None") from ast import literal_eval children = literal_eval(children) if children is None: children = [] elif (children == [] or children == () or isinstance(children, (Integer, int))): children = [None, None] if (children.__class__ is self.__class__ and children.parent() == parent): children = list(children) else: children = [self.__class__(parent, x) for x in children] ClonableArray.__init__(self, parent, children, check=check)
def __init__(self, parent, s, check=True, sort=True): """ Initialize ``self``. TESTS:: sage: PM = PerfectMatchings(6) sage: x = PM.element_class(PM, [[5,6],[3,4],[1,2]]) Use the ``sort`` argument when you do not care if the result is sorted. Be careful with its use as you can get inconsistent results when then input is not sorted:: sage: y = PM.element_class(PM, [[5,6],[3,4],[1,2]], sort=False) sage: y [(5, 6), (3, 4), (1, 2)] sage: x == y False """ self._latex_options = {} if sort: data = sorted(map(frozenset, s), key=min) else: data = list(map(frozenset, s)) ClonableArray.__init__(self, parent, data, check=check)
def __init__(self, parent, pi, check=True): """ Initialize ``self``. EXAMPLES:: sage: S = DecoratedPermutations(3) sage: elt = S([2, 1, -3]) sage: TestSuite(elt).run() """ ClonableArray.__init__(self, parent, pi, check=check)
def __init__(self, parent, s): """ Initialize ``self``. EXAMPLES:: sage: OS = OrderedSetPartitions(4) sage: s = OS([[1, 3], [2, 4]]) sage: TestSuite(s).run() """ ClonableArray.__init__(self, parent, map(Set, s))
def __init__(self, parent, s): """ Initialize ``self``. EXAMPLES:: sage: OS = OrderedSetPartitions(4) sage: s = OS([[1, 3], [2, 4]]) sage: TestSuite(s).run() """ ClonableArray.__init__(self, parent, [Set(_) for _ in s])
def __init__(self, parent, s): """ Initialize ``self``. EXAMPLES:: sage: OS = OrderedSetPartitions(4) sage: s = OS([[1, 3], [2, 4]]) sage: TestSuite(s).run() """ self._base_set = reduce(lambda x, y: x.union(y), map(Set, s), Set([])) ClonableArray.__init__(self, parent, [Set(_) for _ in s])
def __init__(self, parent, s): """ Initialize ``self``. EXAMPLES:: sage: OS = OrderedSetPartitions(4) sage: s = OS([[1, 3], [2, 4]]) sage: TestSuite(s).run() """ self._base_set = reduce(lambda x,y: x.union(y), map(Set, s), Set([])) ClonableArray.__init__(self, parent, [Set(_) for _ in s])
def __init__(self, parent, s): """ Initialize ``self``. EXAMPLES:: sage: S = SetPartitions(4) sage: s = S([[1,3],[2,4]]) sage: TestSuite(s).run() sage: SetPartition([]) {} """ ClonableArray.__init__(self, parent, sorted(map(Set, s), key=min))
def __init__(self, parent, lst, check=True, immutable=True): """ Initialize ``self``. EXAMPLES:: sage: SP = SuperPartition([[1],[1]]) sage: TestSuite(SP).run() """ if check and lst not in parent: raise ValueError("%s not in %s" % (lst, parent)) lst = [tuple(lst[0]), tuple(lst[1])] ClonableArray.__init__(self, parent, lst, False, immutable)
def __init__(self, parent, PP, check=True): """ Initialize ``self``. EXAMPLES:: sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) sage: TestSuite(PP).run() """ ClonableArray.__init__(self, parent, PP, check=check) self._max_x = parent._box[0] self._max_y = parent._box[1] self._max_z = parent._box[2]
def __init__(self, parent=None, children=[], check=True): """ TESTS:: sage: t1 = OrderedTrees(4)([[],[[]]]) sage: TestSuite(t1).run() sage: OrderedTrees()("[]") # indirect doctest [] sage: all(OrderedTree(repr(tr)) == tr for i in range(6) for tr in OrderedTrees(i)) True """ if isinstance(children, str): children = eval(children) if children.__class__ is self.__class__ and children.parent() == parent: children = list(children) else: children = [self.__class__(parent, x) for x in children] ClonableArray.__init__(self, parent, children, check=check)
def __init__(self, parent=None, children=[], check=True): """ TESTS:: sage: t1 = OrderedTrees(4)([[],[[]]]) sage: TestSuite(t1).run() sage: OrderedTrees()("[]") # indirect doctest [] sage: all(OrderedTree(repr(tr)) == tr for i in range(6) for tr in OrderedTrees(i)) True """ if isinstance(children, str): children = eval(children) if (children.__class__ is self.__class__ and children.parent() == parent): children = list(children) else: children = [self.__class__(parent, x) for x in children] ClonableArray.__init__(self, parent, children, check=check)
def __init__(self, parent, blocks): ClonableArray.__init__(self, parent,blocks)
def __init__(self, parent, rigged_partitions=[], **options): r""" Construct a rigged configuration element. EXAMPLES:: sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]]) sage: RC(partition_list=[[], [], [], []]) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: RC(partition_list=[[1], [1], [], []]) <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: elt = RC(partition_list=[[1], [1], [], []], rigging_list=[[-1], [0], [], []]); elt <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: TestSuite(elt).run() """ if "KT_constructor" in options: # Used only by the Kleber tree # Not recommended to be called by the user since it avoids safety # checks for speed data = options["KT_constructor"] shape_data = data[0] rigging_data = data[1] vac_data = data[2] nu = [] for i in range(parent._cartan_type.classical().rank()): nu.append(RiggedPartition(shape_data[i], rigging_data[i], vac_data[i])) # Special display case if parent.cartan_type().type() == "B": nu[-1] = RiggedPartitionTypeB(nu[-1]) ClonableArray.__init__(self, parent, nu) return elif "partition_list" in options: data = options["partition_list"] n = parent._cartan_type.classical().rank() if len(data) == 0: # Create a size n array of empty rigged tableau since no tableau # were given nu = [] for i in range(n): nu.append(RiggedPartition()) else: if len(data) != n: # otherwise n should be equal to the number of tableaux raise ValueError("Incorrect number of partitions") nu = [] if "rigging_list" in options: rigging_data = options["rigging_list"] if len(rigging_data) != n: raise ValueError("Incorrect number of riggings") for i in range(n): nu.append(RiggedPartition(tuple(data[i]), list(rigging_data[i]))) else: for partition_data in data: nu.append(RiggedPartition(tuple(partition_data))) elif parent._cartan_type.classical().rank() == len(rigged_partitions) and isinstance( rigged_partitions[0], RiggedPartition ): # The isinstance check is to make sure we are not in the n == 1 special case because # Parent's __call__ always passes at least 1 argument to the element constructor # Special display case if parent.cartan_type().type() == "B": rigged_partitions[-1] = RiggedPartitionTypeB(rigged_partitions[-1]) ClonableArray.__init__(self, parent, rigged_partitions) return else: # Otherwise we did not receive any info, create a size n array of # empty rigged partitions nu = [] for i in range(parent._cartan_type.classical().rank()): nu.append(RiggedPartition()) # raise ValueError("Invalid input") # raise ValueError("Incorrect number of rigged partitions") # Set the vacancy numbers for a, partition in enumerate(nu): # If the partition is empty, there's nothing to do if len(partition) <= 0: continue # Setup the first block block_len = partition[0] vac_num = parent._calc_vacancy_number(nu, a, 0) for i, row_len in enumerate(partition): # If we've gone to a different sized block, then update the # values which change when moving to a new block size if block_len != row_len: vac_num = parent._calc_vacancy_number(nu, a, i) block_len = row_len partition.vacancy_numbers[i] = vac_num if partition.rigging[i] is None: partition.rigging[i] = partition.vacancy_numbers[i] # Special display case if parent.cartan_type().type() == "B": nu[-1] = RiggedPartitionTypeB(nu[-1]) ClonableArray.__init__(self, parent, nu)
def __init__(self, parent, *rigged_partitions, **options): r""" Construct a rigged configuration element. INPUT: - ``parent`` -- The parent of this element - ``rigged_partitions`` -- A list of rigged partitions There are two optional arguments to explicitly construct a rigged configuration. The first is **partition_list** which gives a list of partitions, and the second is **rigging_list** which is a list of corresponding lists of riggings. If only partition_list is specified, then it sets the rigging equal to the calculated vacancy numbers. EXAMPLES:: sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]]) sage: RC(partition_list=[[], [], [], []]) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: RC(partition_list=[[1], [1], [], []]) <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: elt = RC(partition_list=[[1], [1], [], []], rigging_list=[[-1], [0], [], []]); elt <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: TestSuite(elt).run() """ if "partition_list" in options: data = options["partition_list"] n = parent._cartan_type.n if len(data) == 0: # Create a size n array of empty rigged tableau since no tableau # were given nu = [] for i in range(parent._cartan_type.n): nu.append(RiggedPartition()) else: if len( data ) != n: # otherwise n should be equal to the number of tableaux raise ValueError nu = [] if "rigging_list" in options: rigging_data = options["rigging_list"] if len(rigging_data) != n: raise ValueError for i in range(parent._cartan_type.n): nu.append(RiggedPartition(tuple(data[i]), \ list(rigging_data[i]))) else: for partition_data in data: nu.append(RiggedPartition(tuple(partition_data))) elif len(list(rigged_partitions)) == 0: # Create a size n array of empty rigged tableau since no tableau # were given nu = [] for i in range(parent._cartan_type.n): nu.append(RiggedPartition()) elif "KT_constructor" in options: # Used only by the Kleber tree # Not recommended to be called by the user since it avoids safety # checks for speed data = options["KT_constructor"] shape_data = data[0] rigging_data = data[1] vac_data = data[2] nu = [] for i in range(parent._cartan_type.n): nu.append( RiggedPartition(shape_data[i], rigging_data[i], vac_data[i])) ClonableArray.__init__(self, parent, nu) return elif parent._cartan_type.n == len(list(rigged_partitions)): ClonableArray.__init__(self, parent, list(rigged_partitions)) return else: # Otherwise we did not receive any info, create a size n array of # empty rigged partitions nu = [] for i in range(parent._cartan_type.n): nu.append(RiggedPartition()) # Set the vacancy numbers for a, partition in enumerate(nu): # If the partition is empty, there's nothing to do if len(partition) <= 0: continue # Setup the first block block_len = partition[0] vac_num = parent._calc_vacancy_number(nu, a, 0) for i, row_len in enumerate(partition): # If we've gone to a different sized block, then update the # values which change when moving to a new block size if block_len != row_len: vac_num = parent._calc_vacancy_number(nu, a, i) block_len = row_len partition.vacancy_numbers[i] = vac_num if partition.rigging[i] is None: partition.rigging[i] = partition.vacancy_numbers[i] ClonableArray.__init__(self, parent, nu)
def __init__(self, parent, blocks): self._number_of_blocks = len(blocks) self._n = parent._n if not SetPartitions(self._n)(blocks).is_noncrossing(): raise ValueError("{} is not noncrossing".format(blocks)) ClonableArray.__init__(self, parent,blocks)
def __init__(self, parent, rigged_partitions=[], **options): r""" Construct a rigged configuration element. EXAMPLES:: sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]]) sage: RC(partition_list=[[], [], [], []]) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: RC(partition_list=[[1], [1], [], []]) <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: elt = RC(partition_list=[[1], [1], [], []], rigging_list=[[-1], [0], [], []]); elt <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: TestSuite(elt).run() """ if "KT_constructor" in options: # Used only by the Kleber tree # Not recommended to be called by the user since it avoids safety # checks for speed data = options["KT_constructor"] shape_data = data[0] rigging_data = data[1] vac_data = data[2] nu = [] for i in range(parent._cartan_type.classical().rank()): nu.append(RiggedPartition(shape_data[i], rigging_data[i], vac_data[i])) # Special display case if parent.cartan_type().type() == 'B': nu[-1] = RiggedPartitionTypeB(nu[-1]) ClonableArray.__init__(self, parent, nu) return elif "partition_list" in options: data = options["partition_list"] n = parent._cartan_type.classical().rank() if len(data) == 0: # Create a size n array of empty rigged tableau since no tableau # were given nu = [] for i in range(n): nu.append(RiggedPartition()) else: if len(data) != n: # otherwise n should be equal to the number of tableaux raise ValueError("Incorrect number of partitions") nu = [] if "rigging_list" in options: rigging_data = options["rigging_list"] if len(rigging_data) != n: raise ValueError("Incorrect number of riggings") for i in range(n): nu.append(RiggedPartition(tuple(data[i]), \ list(rigging_data[i]))) else: for partition_data in data: nu.append(RiggedPartition(tuple(partition_data))) elif parent._cartan_type.classical().rank() == len(rigged_partitions) and \ isinstance(rigged_partitions[0], RiggedPartition): # The isinstance check is to make sure we are not in the n == 1 special case because # Parent's __call__ always passes at least 1 argument to the element constructor # Special display case if parent.cartan_type().type() == 'B': rigged_partitions[-1] = RiggedPartitionTypeB(rigged_partitions[-1]) ClonableArray.__init__(self, parent, rigged_partitions) return else: # Otherwise we did not receive any info, create a size n array of # empty rigged partitions nu = [] for i in range(parent._cartan_type.classical().rank()): nu.append(RiggedPartition()) #raise ValueError("Invalid input") #raise ValueError("Incorrect number of rigged partitions") # Set the vacancy numbers for a, partition in enumerate(nu): # If the partition is empty, there's nothing to do if len(partition) <= 0: continue # Setup the first block block_len = partition[0] vac_num = parent._calc_vacancy_number(nu, a, 0) for i, row_len in enumerate(partition): # If we've gone to a different sized block, then update the # values which change when moving to a new block size if block_len != row_len: vac_num = parent._calc_vacancy_number(nu, a, i) block_len = row_len partition.vacancy_numbers[i] = vac_num if partition.rigging[i] is None: partition.rigging[i] = partition.vacancy_numbers[i] # Special display case if parent.cartan_type().type() == 'B': nu[-1] = RiggedPartitionTypeB(nu[-1]) ClonableArray.__init__(self, parent, nu)
def __init__(self, parent, *rigged_partitions, **options): r""" Construct a rigged configuration element. INPUT: - ``parent`` -- The parent of this element - ``rigged_partitions`` -- A list of rigged partitions There are two optional arguments to explicitly construct a rigged configuration. The first is **partition_list** which gives a list of partitions, and the second is **rigging_list** which is a list of corresponding lists of riggings. If only partition_list is specified, then it sets the rigging equal to the calculated vacancy numbers. EXAMPLES:: sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]]) sage: RC(partition_list=[[], [], [], []]) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: RC(partition_list=[[1], [1], [], []]) <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: elt = RC(partition_list=[[1], [1], [], []], rigging_list=[[-1], [0], [], []]); elt <BLANKLINE> -1[ ]-1 <BLANKLINE> 0[ ]0 <BLANKLINE> (/) <BLANKLINE> (/) <BLANKLINE> sage: TestSuite(elt).run() """ if "partition_list" in options: data = options["partition_list"] n = parent._cartan_type.n if len(data) == 0: # Create a size n array of empty rigged tableau since no tableau # were given nu = [] for i in range(parent._cartan_type.n): nu.append(RiggedPartition()) else: if len(data) != n: # otherwise n should be equal to the number of tableaux raise ValueError nu = [] if "rigging_list" in options: rigging_data = options["rigging_list"] if len(rigging_data) != n: raise ValueError for i in range(parent._cartan_type.n): nu.append(RiggedPartition(tuple(data[i]), \ list(rigging_data[i]))) else: for partition_data in data: nu.append(RiggedPartition(tuple(partition_data))) elif len(list(rigged_partitions)) == 0: # Create a size n array of empty rigged tableau since no tableau # were given nu = [] for i in range(parent._cartan_type.n): nu.append(RiggedPartition()) elif "KT_constructor" in options: # Used only by the Kleber tree # Not recommended to be called by the user since it avoids safety # checks for speed data = options["KT_constructor"] shape_data = data[0] rigging_data = data[1] vac_data = data[2] nu = [] for i in range(parent._cartan_type.n): nu.append(RiggedPartition(shape_data[i], rigging_data[i], vac_data[i])) ClonableArray.__init__(self, parent, nu) return elif parent._cartan_type.n == len(list(rigged_partitions)): ClonableArray.__init__(self, parent, list(rigged_partitions)) return else: # Otherwise we did not receive any info, create a size n array of # empty rigged partitions nu = [] for i in range(parent._cartan_type.n): nu.append(RiggedPartition()) # Set the vacancy numbers for a, partition in enumerate(nu): # If the partition is empty, there's nothing to do if len(partition) <= 0: continue # Setup the first block block_len = partition[0] vac_num = parent._calc_vacancy_number(nu, a, 0) for i, row_len in enumerate(partition): # If we've gone to a different sized block, then update the # values which change when moving to a new block size if block_len != row_len: vac_num = parent._calc_vacancy_number(nu, a, i) block_len = row_len partition.vacancy_numbers[i] = vac_num if partition.rigging[i] is None: partition.rigging[i] = partition.vacancy_numbers[i] ClonableArray.__init__(self, parent, nu)
def __init__(self, parent, blocks): ClonableArray.__init__(self, parent, blocks)
def __init__(self, parent, blocks): if not SetPartitions(parent._n)(blocks).is_noncrossing(): raise ValueError("{} is not noncrossing".format(blocks)) ClonableArray.__init__(self, parent, blocks)
def __init__(self, parent, blocks): if not SetPartitions(parent._n)(blocks).is_noncrossing(): raise ValueError("{} is not noncrossing".format(blocks)) ClonableArray.__init__(self, parent,blocks)