This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
/
interval_posets.py
3627 lines (2998 loc) · 133 KB
/
interval_posets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
r"""
Tamari Interval-posets
This module implements Tamari interval-posets: combinatorial objects which
represent intervals of the Tamari order. They have been introduced in
[ChP2015]_ and allow for many combinatorial operations on Tamari intervals.
In particular, they are linked to :class:`DyckWords` and :class:`BinaryTrees`.
An introduction into Tamari interval-posets is given in Chapter 7
of [Pons2013]_.
The Tamari lattice can be defined as a lattice structure on either of several
classes of Catalan objects, especially binary trees and Dyck paths
[TamBrack1962]_ [HuangTamari1972]_ [Sta-EC2]_. An interval can be seen as
a pair of comparable elements. The number of intervals has been given in
[ChapTamari08]_.
REFERENCES:
.. [ChP2015] Grégory Châtel and Viviane Pons.
*Counting smaller elements in the tamari and m-tamari lattices*.
Journal of Combinatorial Theory, Series A. (2015). :arxiv:`1311.3922`.
.. [Pons2013] Viviane Pons,
*Combinatoire algébrique liée aux ordres sur les permutations*.
PhD Thesis. (2013). :arxiv:`1310.1805v1`.
.. [TamBrack1962] Dov Tamari.
*The algebra of bracketings and their enumeration*.
Nieuw Arch. Wisk. (1962).
.. [HuangTamari1972] Samuel Huang and Dov Tamari.
*Problems of associativity: A simple proof for the lattice property
of systems ordered by a semi-associative law*.
J. Combinatorial Theory Ser. A. (1972).
http://www.sciencedirect.com/science/article/pii/0097316572900039 .
.. [ChapTamari08] Frédéric Chapoton.
*Sur le nombre d'intervalles dans les treillis de Tamari*.
Sem. Lothar. Combin. (2008).
:arxiv:`math/0602368v1`.
.. [FPR15] Wenjie Fang and Louis-François Préville-Ratelle,
*From generalized Tamari intervals to non-separable planar maps*.
:arxiv:`1511.05937`
.. [Pons2018] Viviane Pons,
*The Rise-Contact involution on Tamari intervals*
.. [Rog2018] Baptiste Rognerud,
*Exceptional and modern intervals of the Tamari lattice*.
:arxiv:`1801.04097`
AUTHORS:
- Viviane Pons 2014: initial implementation
- Frédéric Chapoton 2014: review
- Darij Grinberg 2014: review
- Travis Scrimshaw 2014: review
"""
# ****************************************************************************
# Copyright (C) 2013 Viviane Pons <viviane.pons@univie.ac.at>,
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import print_function
from six.moves import range
from six import add_metaclass
from sage.categories.enumerated_sets import EnumeratedSets
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.categories.posets import Posets
from sage.combinat.posets.posets import Poset, FinitePoset
from sage.categories.finite_posets import FinitePosets
from sage.combinat.binary_tree import BinaryTrees
from sage.combinat.binary_tree import LabelledBinaryTrees, LabelledBinaryTree
from sage.combinat.dyck_word import DyckWords
from sage.combinat.permutation import Permutation
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
from sage.misc.cachefunc import cached_method
from sage.misc.latex import latex
from sage.misc.lazy_attribute import lazy_attribute
from sage.rings.integer import Integer
from sage.rings.all import NN
from sage.sets.non_negative_integers import NonNegativeIntegers
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.family import Family
from sage.structure.element import Element
from sage.structure.global_options import GlobalOptions
from sage.structure.parent import Parent
from sage.structure.richcmp import op_NE, op_EQ, op_LT, op_LE, op_GT, op_GE
from sage.structure.unique_representation import UniqueRepresentation
from sage.graphs.digraph import DiGraph
@add_metaclass(InheritComparisonClasscallMetaclass)
class TamariIntervalPoset(Element):
r"""
The class of Tamari interval-posets.
An interval-poset is a labelled poset of size `n`, with labels
`1, 2, \ldots, n`, satisfying the following conditions:
- if `a < c` (as integers) and `a` precedes `c` in the poset, then,
for all `b` such that `a < b < c`, `b` precedes `c`,
- if `a < c` (as integers) and `c` precedes `a` in the poset, then,
for all `b` such that `a < b < c`, `b` precedes `a`.
We use the word "precedes" here to distinguish the poset order and
the natural order on numbers. "Precedes" means "is smaller than
with respect to the poset structure"; this does not imply a
covering relation.
Interval-posets of size `n` are in bijection with intervals of
the Tamari lattice of binary trees of size `n`. Specifically, if
`P` is an interval-poset of size `n`, then the set of linear
extensions of `P` (as permutations in `S_n`) is an interval in the
right weak order (see
:meth:`~sage.combinat.permutation.Permutation.permutohedron_lequal`),
and is in fact the preimage of an interval in the Tamari lattice (of
binary trees of size `n`) under the operation which sends a
permutation to its right-to-left binary search tree
(:meth:`~sage.combinat.permutation.Permutation.binary_search_tree`
with the ``left_to_right`` variable set to ``False``)
without its labelling.
INPUT:
- ``size`` -- an integer, the size of the interval-posets (number of
vertices)
- ``relations`` -- a list (or tuple) of pairs ``(a,b)`` (themselves
lists or tuples), each representing a relation of the form
'`a` precedes `b`' in the poset.
- ``check`` -- (default: ``True``) whether to check the interval-poset
condition or not.
.. WARNING::
The ``relations`` input can be a list or tuple, but not an
iterator (nor should its entries be iterators).
NOTATION:
Here and in the following, the signs `<` and `>` always refer to
the natural ordering on integers, whereas the word "precedes" refers
to the order of the interval-poset. "Minimal" and "maximal" refer
to the natural ordering on integers.
The *increasing relations* of an interval-poset `P` mean the pairs
`(a, b)` of elements of `P` such that `a < b` as integers and `a`
precedes `b` in `P`. The *initial forest* of `P` is the poset
obtained by imposing (only) the increasing relations on the ground
set of `P`. It is a sub-interval poset of `P`, and is a forest with
its roots on top. This forest is usually given the structure of a
planar forest by ordering brother nodes by their labels; it then has
the property that if its nodes are traversed in post-order
(see :meth:`~sage.combinat.abstract_tree.AbstractTree.post_order_traversal`,
and traverse the trees of the forest from left to right as well),
then the labels encountered are `1, 2, \ldots, n` in this order.
The *decreasing relations* of an interval-poset `P` mean the pairs
`(a, b)` of elements of `P` such that `b < a` as integers and `a`
precedes `b` in `P`. The *final forest* of `P` is the poset
obtained by imposing (only) the decreasing relations on the ground
set of `P`. It is a sub-interval poset of `P`, and is a forest with
its roots on top. This forest is usually given the structure of a
planar forest by ordering brother nodes by their labels; it then has
the property that if its nodes are traversed in pre-order
(see :meth:`~sage.combinat.abstract_tree.AbstractTree.pre_order_traversal`,
and traverse the trees of the forest from left to right as well),
then the labels encountered are `1, 2, \ldots, n` in this order.
EXAMPLES::
sage: TamariIntervalPoset(0,[])
The Tamari interval of size 0 induced by relations []
sage: TamariIntervalPoset(3,[])
The Tamari interval of size 3 induced by relations []
sage: TamariIntervalPoset(3,[(1,2)])
The Tamari interval of size 3 induced by relations [(1, 2)]
sage: TamariIntervalPoset(3,[(1,2),(2,3)])
The Tamari interval of size 3 induced by relations [(1, 2), (2, 3)]
sage: TamariIntervalPoset(3,[(1,2),(2,3),(1,3)])
The Tamari interval of size 3 induced by relations [(1, 2), (2, 3)]
sage: TamariIntervalPoset(3,[(1,2),(3,2)])
The Tamari interval of size 3 induced by relations [(1, 2), (3, 2)]
sage: TamariIntervalPoset(3,[[1,2],[2,3]])
The Tamari interval of size 3 induced by relations [(1, 2), (2, 3)]
sage: TamariIntervalPoset(3,[[1,2],[2,3],[1,2],[1,3]])
The Tamari interval of size 3 induced by relations [(1, 2), (2, 3)]
sage: TamariIntervalPoset(3,[(3,4)])
Traceback (most recent call last):
...
ValueError: The relations do not correspond to the size of the poset.
sage: TamariIntervalPoset(2,[(2,1),(1,2)])
Traceback (most recent call last):
...
ValueError: The graph is not directed acyclic
sage: TamariIntervalPoset(3,[(1,3)])
Traceback (most recent call last):
...
ValueError: This does not satisfy the Tamari interval-poset condition.
It is also possible to transform a poset directly into an interval-poset::
sage: TIP = TamariIntervalPosets()
sage: p = Poset(([1,2,3], [(1,2)]))
sage: TIP(p)
The Tamari interval of size 3 induced by relations [(1, 2)]
sage: TIP(Poset({1: []}))
The Tamari interval of size 1 induced by relations []
sage: TIP(Poset({}))
The Tamari interval of size 0 induced by relations []
"""
@staticmethod
def __classcall_private__(cls, *args, **opts):
r"""
Ensure that interval-posets created by the enumerated sets and
directly are the same and that they are instances of
:class:`TamariIntervalPoset`.
TESTS::
sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)])
sage: ip.parent()
Interval-posets
sage: type(ip)
<class 'sage.combinat.interval_posets.TamariIntervalPosets_all_with_category.element_class'>
sage: ip2 = TamariIntervalPosets()(4,[(2,4),(3,4),(2,1),(3,1)])
sage: ip2.parent() is ip.parent()
True
sage: type(ip) is type(ip2)
True
sage: ip3 = TamariIntervalPosets(4)([(2,4),(3,4),(2,1),(3,1)])
sage: ip3.parent() is ip.parent()
False
sage: type(ip3) is type(ip)
True
"""
P = TamariIntervalPosets_all()
return P.element_class(P, *args, **opts)
def __init__(self, parent, size, relations, check=True):
r"""
TESTS::
sage: TamariIntervalPoset(3,[(1,2),(3,2)]).parent()
Interval-posets
"""
self._size = size
self._poset = Poset((list(range(1, size + 1)), relations))
if self._poset.cardinality() != size:
# This can happen as the Poset constructor automatically adds
# in elements from the relations.
raise ValueError("The relations do not correspond to the size of the poset.")
if check and not TamariIntervalPosets.check_poset(self._poset):
raise ValueError("This does not satisfy the Tamari interval-poset condition.")
Element.__init__(self, parent)
self._cover_relations = tuple(self._poset.cover_relations())
self._latex_options = dict()
def set_latex_options(self, D):
r"""
Set the latex options for use in the ``_latex_`` function. The
default values are set in the ``__init__`` function.
- ``tikz_scale`` -- (default: 1) scale for use with the tikz package
- ``line_width`` -- (default: 1 * ``tikz_scale``) value representing the
line width
- ``color_decreasing`` -- (default: red) the color for decreasing
relations
- ``color_increasing`` -- (default: blue) the color for increasing
relations
- ``hspace`` -- (default: 1) the difference between horizontal
coordinates of adjacent vertices
- ``vspace`` -- (default: 1) the difference between vertical
coordinates of adjacent vertices
INPUT:
- ``D`` -- a dictionary with a list of latex parameters to change
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)])
sage: ip.latex_options()["color_decreasing"]
'red'
sage: ip.set_latex_options({"color_decreasing":'green'})
sage: ip.latex_options()["color_decreasing"]
'green'
sage: ip.set_latex_options({"color_increasing":'black'})
sage: ip.latex_options()["color_increasing"]
'black'
To change the default options for all interval-posets, use the
parent's latex options::
sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)])
sage: ip2 = TamariIntervalPoset(4,[(1,2),(2,3)])
sage: ip.latex_options()["color_decreasing"]
'red'
sage: ip2.latex_options()["color_decreasing"]
'red'
sage: TamariIntervalPosets.options(latex_color_decreasing='green')
sage: ip.latex_options()["color_decreasing"]
'green'
sage: ip2.latex_options()["color_decreasing"]
'green'
Next we set a local latex option and show the global option does not
override it::
sage: ip.set_latex_options({"color_decreasing": 'black'})
sage: ip.latex_options()["color_decreasing"]
'black'
sage: TamariIntervalPosets.options(latex_color_decreasing='blue')
sage: ip.latex_options()["color_decreasing"]
'black'
sage: ip2.latex_options()["color_decreasing"]
'blue'
sage: TamariIntervalPosets.options._reset()
"""
for opt in D:
self._latex_options[opt] = D[opt]
def latex_options(self):
r"""
Return the latex options for use in the ``_latex_`` function as a
dictionary. The default values are set using the options.
- ``tikz_scale`` -- (default: 1) scale for use with the tikz package
- ``line_width`` -- (default: 1) value representing the line width
(additionally scaled by ``tikz_scale``)
- ``color_decreasing`` -- (default: ``'red'``) the color for
decreasing relations
- ``color_increasing`` -- (default: ``'blue'``) the color for
increasing relations
- ``hspace`` -- (default: 1) the difference between horizontal
coordinates of adjacent vertices
- ``vspace`` -- (default: 1) the difference between vertical
coordinates of adjacent vertices
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)])
sage: ip.latex_options()['color_decreasing']
'red'
sage: ip.latex_options()['hspace']
1
"""
d = self._latex_options.copy()
if "tikz_scale" not in d:
d["tikz_scale"] = self.parent().options["latex_tikz_scale"]
if "line_width" not in d:
d["line_width"] = self.parent().options["latex_line_width_scalar"] * d["tikz_scale"]
if "color_decreasing" not in d:
d["color_decreasing"] = self.parent().options["latex_color_decreasing"]
if "color_increasing" not in d:
d["color_increasing"] = self.parent().options["latex_color_increasing"]
if "hspace" not in d:
d["hspace"] = self.parent().options["latex_hspace"]
if "vspace" not in d:
d["vspace"] = self.parent().options["latex_vspace"]
return d
def _find_node_positions(self, hspace=1, vspace=1):
"""
Compute a nice embedding.
If `x` precedes `y`, then `y` will always be placed on top of `x`
and/or to the right of `x`.
Decreasing relations tend to be drawn vertically and increasing
relations horizontally.
The algorithm tries to avoid superposition but on big
interval-posets, it might happen.
OUTPUT:
a dictionary {vertex: (x,y)}
EXAMPLES::
sage: ti = TamariIntervalPosets(4)[2]
sage: list(ti._find_node_positions().values())
[[0, 0], [0, -1], [0, -2], [1, -2]]
"""
node_positions = {}
to_draw = [(1, 0)]
current_parent = [self.increasing_parent(1)]
parenty = [0]
x = 0
y = 0
for i in range(2, self.size() + 1):
decreasing_parent = self.decreasing_parent(i)
increasing_parent = self.increasing_parent(i)
while to_draw and (decreasing_parent is None or
decreasing_parent < to_draw[-1][0]):
n = to_draw.pop()
node_positions[n[0]] = [x, n[1]]
if i != current_parent[-1]:
if (not self.le(i, i - 1) and decreasing_parent is not None):
x += hspace
if current_parent[-1] is not None:
y -= vspace
else:
y -= vspace
if increasing_parent != current_parent[-1]:
current_parent.append(increasing_parent)
parenty.append(y)
nodey = y
else:
current_parent.pop()
x += hspace
nodey = parenty.pop()
if not current_parent or increasing_parent != current_parent[-1]:
current_parent.append(increasing_parent)
parenty.append(nodey)
to_draw.append((i, nodey))
for n in to_draw:
node_positions[n[0]] = [x, n[1]]
return node_positions
def plot(self, **kwds):
"""
Return a picture.
The picture represents the Hasse diagram, where the covers are
colored in blue if they are increasing and in red if they are
decreasing.
This uses the same coordinates as the latex view.
EXAMPLES::
sage: ti = TamariIntervalPosets(4)[2]
sage: ti.plot()
Graphics object consisting of 6 graphics primitives
"""
c0 = 'blue' # self.latex_options()["color_increasing"]
c1 = 'red' # self.latex_options()["color_decreasing"]
G = self.poset().hasse_diagram()
G.set_pos(self._find_node_positions())
for a, b, c in G.edges():
if a < b:
G.set_edge_label(a, b, 0)
else:
G.set_edge_label(a, b, 1)
return G.plot(color_by_label={0: c0, 1: c1}, **kwds)
def _latex_(self):
r"""
A latex representation of ``self`` using the tikzpicture package.
This picture shows the union of the Hasse diagrams of the
initial and final forests.
If `x` precedes `y`, then `y` will always be placed on top of `x`
and/or to the right of `x`.
Decreasing relations tend to be drawn vertically and increasing
relations horizontally.
The algorithm tries to avoid superposition but on big
interval-posets, it might happen.
You can use ``self.set_latex_options()`` to change default latex
options. Or you can use the parent's options.
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)])
sage: print(ip._latex_())
\begin{tikzpicture}[scale=1]
\node(T1) at (1,0) {1};
\node(T2) at (0,-1) {2};
\node(T3) at (1,-2) {3};
\node(T4) at (2,-1) {4};
\draw[line width = 0.5, color=red] (T3) -- (T1);
\draw[line width = 0.5, color=red] (T2) -- (T1);
\draw[line width = 0.5, color=blue] (T2) -- (T4);
\draw[line width = 0.5, color=blue] (T3) -- (T4);
\end{tikzpicture}
"""
latex.add_package_to_preamble_if_available("tikz")
latex_options = self.latex_options()
start = "\\begin{tikzpicture}[scale=" + str(latex_options['tikz_scale']) + "]\n"
end = "\\end{tikzpicture}"
vspace = latex_options["vspace"]
hspace = latex_options["hspace"]
def draw_node(j, x, y):
r"""
Internal method to draw vertices
"""
return "\\node(T" + str(j) + ") at (" + str(x) + "," + str(y) + ") {" + str(j) + "};\n"
def draw_increasing(i, j):
r"""
Internal method to draw increasing relations
"""
return "\\draw[line width = " + str(latex_options["line_width"]) + ", color=" + latex_options["color_increasing"] + "] (T" + str(i) + ") -- (T" + str(j) + ");\n"
def draw_decreasing(i, j):
r"""
Internal method to draw decreasing relations
"""
return "\\draw[line width = " + str(latex_options["line_width"]) + ", color=" + latex_options["color_decreasing"] + "] (T" + str(i) + ") -- (T" + str(j) + ");\n"
if self.size() == 0:
nodes = "\\node(T0) at (0,0){$\\emptyset$};"
relations = ""
else:
positions = self._find_node_positions(hspace, vspace)
nodes = "" # latex for node declarations
relations = "" # latex for drawing relations
for i in range(1, self.size() + 1):
nodes += draw_node(i, *positions[i])
for i, j in self.decreasing_cover_relations():
relations += draw_decreasing(i, j)
for i, j in self.increasing_cover_relations():
relations += draw_increasing(i, j)
return start + nodes + relations + end
def poset(self):
r"""
Return ``self`` as a labelled poset.
An interval-poset is indeed constructed from a labelled poset which
is stored internally. This method allows to access the poset and
all the associated methods.
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(1,2),(3,2),(2,4),(3,4)])
sage: pos = ip.poset(); pos
Finite poset containing 4 elements
sage: pos.maximal_chains()
[[3, 2, 4], [1, 2, 4]]
sage: pos.maximal_elements()
[4]
sage: pos.is_lattice()
False
"""
return self._poset
def __hash__(self):
"""
Return the hash of ``self``.
EXAMPLES::
sage: len(set(hash(u) for u in TamariIntervalPosets(4)))
68
"""
pair = (self.size(), tuple(tuple(e) for e in self._cover_relations))
return hash(pair)
@cached_method
def increasing_cover_relations(self):
r"""
Return the cover relations of the initial forest of ``self``
(the poset formed by keeping only the relations of the form
`a` precedes `b` with `a < b`).
The initial forest of ``self`` is a forest with its roots
being on top. It is also called the increasing poset of ``self``.
.. WARNING::
This method computes the cover relations of the initial
forest. This is not identical with the cover relations of
``self`` which happen to be increasing!
.. SEEALSO::
:meth:`initial_forest`
EXAMPLES::
sage: TamariIntervalPoset(4,[(1,2),(3,2),(2,4),(3,4)]).increasing_cover_relations()
[(1, 2), (2, 4), (3, 4)]
sage: TamariIntervalPoset(3,[(1,2),(1,3),(2,3)]).increasing_cover_relations()
[(1, 2), (2, 3)]
"""
relations = []
size = self.size()
for i in range(1, size):
for j in range(i + 1, size + 1):
if self.le(i, j):
relations.append((i, j))
break
return relations
def increasing_roots(self):
r"""
Return the root vertices of the initial forest of ``self``,
i.e., the vertices `a` of ``self`` such that there is no
`b > a` with `a` precedes `b`.
OUTPUT:
The list of all roots of the initial forest of ``self``, in
decreasing order.
EXAMPLES::
sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(3,5),(4,5)]); ip
The Tamari interval of size 6 induced by relations [(1, 2), (3, 5), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)]
sage: ip.increasing_roots()
[6, 5, 2]
sage: ip.initial_forest().increasing_roots()
[6, 5, 2]
"""
size = self.size()
if size == 0:
return []
roots = [size]
root = size
for i in range(size - 1, 0, -1):
if not self.le(i, root):
roots.append(i)
root = i
return roots
def increasing_children(self, v):
r"""
Return the children of ``v`` in the initial forest of ``self``.
INPUT:
- ``v`` -- an integer representing a vertex of ``self``
(between 1 and ``size``)
OUTPUT:
The list of all children of ``v`` in the initial forest of
``self``, in decreasing order.
EXAMPLES::
sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(3,5),(4,5)]); ip
The Tamari interval of size 6 induced by relations [(1, 2), (3, 5), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)]
sage: ip.increasing_children(2)
[1]
sage: ip.increasing_children(5)
[4, 3]
sage: ip.increasing_children(1)
[]
"""
children = []
root = None
for i in range(v - 1, 0, -1):
if not self.le(i, v):
break
if root is None or not self.le(i, root):
children.append(i)
root = i
return children
def increasing_parent(self, v):
r"""
Return the vertex parent of ``v`` in the initial forest of ``self``.
This is the lowest (as integer!) vertex `b > v` such that `v`
precedes `b`. If there is no such vertex (that is, `v` is an
increasing root), then ``None`` is returned.
INPUT:
- ``v`` -- an integer representing a vertex of ``self``
(between 1 and ``size``)
EXAMPLES::
sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(3,5),(4,5)]); ip
The Tamari interval of size 6 induced by relations [(1, 2), (3, 5), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)]
sage: ip.increasing_parent(1)
2
sage: ip.increasing_parent(3)
5
sage: ip.increasing_parent(4)
5
sage: ip.increasing_parent(5) is None
True
"""
parent = None
for i in range(self.size(), v, -1):
if self.le(v, i):
parent = i
return parent
@cached_method
def decreasing_cover_relations(self):
r"""
Return the cover relations of the final forest of ``self``
(the poset formed by keeping only the relations of the form
`a` precedes `b` with `a > b`).
The final forest of ``self`` is a forest with its roots
being on top. It is also called the decreasing poset of ``self``.
.. WARNING::
This method computes the cover relations of the final
forest. This is not identical with the cover relations of
``self`` which happen to be decreasing!
.. SEEALSO::
:meth:`final_forest`
EXAMPLES::
sage: TamariIntervalPoset(4,[(2,1),(3,2),(3,4),(4,2)]).decreasing_cover_relations()
[(4, 2), (3, 2), (2, 1)]
sage: TamariIntervalPoset(4,[(2,1),(4,3),(2,3)]).decreasing_cover_relations()
[(4, 3), (2, 1)]
sage: TamariIntervalPoset(3,[(2,1),(3,1),(3,2)]).decreasing_cover_relations()
[(3, 2), (2, 1)]
"""
relations = []
for i in range(self.size(), 1, -1):
for j in range(i - 1, 0, -1):
if self.le(i, j):
relations.append((i, j))
break
return relations
def decreasing_roots(self):
r"""
Return the root vertices of the final forest of ``self``,
i.e., the vertices `b` such that there is no `a < b` with `b`
preceding `a`.
OUTPUT:
The list of all roots of the final forest of ``self``, in
increasing order.
EXAMPLES::
sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(3,5),(4,5)]); ip
The Tamari interval of size 6 induced by relations [(1, 2), (3, 5), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)]
sage: ip.decreasing_roots()
[1, 2]
sage: ip.final_forest().decreasing_roots()
[1, 2]
"""
if self.size() == 0:
return []
roots = [1]
root = 1
for i in range(2, self.size() + 1):
if not self.le(i, root):
roots.append(i)
root = i
return roots
def decreasing_children(self, v):
r"""
Return the children of ``v`` in the final forest of ``self``.
INPUT:
- ``v`` -- an integer representing a vertex of ``self``
(between 1 and ``size``)
OUTPUT:
The list of all children of ``v`` in the final forest of ``self``,
in increasing order.
EXAMPLES::
sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(3,5),(4,5)]); ip
The Tamari interval of size 6 induced by relations [(1, 2), (3, 5), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)]
sage: ip.decreasing_children(2)
[3, 5]
sage: ip.decreasing_children(3)
[4]
sage: ip.decreasing_children(1)
[]
"""
children = []
root = None
for i in range(v + 1, self.size() + 1):
if not self.le(i, v):
break
if root is None or not self.le(i, root):
children.append(i)
root = i
return children
def decreasing_parent(self, v):
r"""
Return the vertex parent of ``v`` in the final forest of ``self``.
This is the highest (as integer!) vertex `a < v` such that ``v``
precedes ``a``. If there is no such vertex (that is, `v` is a
decreasing root), then ``None`` is returned.
INPUT:
- ``v`` -- an integer representing a vertex of ``self`` (between
1 and ``size``)
EXAMPLES::
sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(3,5),(4,5)]); ip
The Tamari interval of size 6 induced by relations [(1, 2), (3, 5), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)]
sage: ip.decreasing_parent(4)
3
sage: ip.decreasing_parent(3)
2
sage: ip.decreasing_parent(5)
2
sage: ip.decreasing_parent(2) is None
True
"""
parent = None
for i in range(1, v):
if self.le(v, i):
parent = i
return parent
def le(self, e1, e2):
r"""
Return whether ``e1`` precedes or equals ``e2`` in ``self``.
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(1,2),(2,3)])
sage: ip.le(1,2)
True
sage: ip.le(1,3)
True
sage: ip.le(2,3)
True
sage: ip.le(3,4)
False
sage: ip.le(1,1)
True
"""
return self._poset.le(e1, e2)
def lt(self, e1, e2):
r"""
Return whether ``e1`` strictly precedes ``e2`` in ``self``.
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(1,2),(2,3)])
sage: ip.lt(1,2)
True
sage: ip.lt(1,3)
True
sage: ip.lt(2,3)
True
sage: ip.lt(3,4)
False
sage: ip.lt(1,1)
False
"""
return self._poset.lt(e1, e2)
def ge(self, e1, e2):
r"""
Return whether ``e2`` precedes or equals ``e1`` in ``self``.
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(1,2),(2,3)])
sage: ip.ge(2,1)
True
sage: ip.ge(3,1)
True
sage: ip.ge(3,2)
True
sage: ip.ge(4,3)
False
sage: ip.ge(1,1)
True
"""
return self._poset.ge(e1, e2)
def gt(self, e1, e2):
r"""
Return whether ``e2`` strictly precedes ``e1`` in ``self``.
EXAMPLES::
sage: ip = TamariIntervalPoset(4,[(1,2),(2,3)])
sage: ip.gt(2,1)
True
sage: ip.gt(3,1)
True
sage: ip.gt(3,2)
True
sage: ip.gt(4,3)
False
sage: ip.gt(1,1)
False
"""
return self._poset.gt(e1, e2)
def size(self):
r"""
Return the size (number of vertices) of the interval-poset.
EXAMPLES::
sage: TamariIntervalPoset(3,[(2,1),(3,1)]).size()
3
"""
return self._size
def complement(self):
r"""
Return the complement of the interval-poset ``self``.
If `P` is a Tamari interval-poset of size `n`, then the
*complement* of `P` is defined as the interval-poset `Q` whose
base set is `[n] = \{1, 2, \ldots, n\}` (just as for `P`), but
whose order relation has `a` precede `b` if and only if
`n + 1 - a` precedes `n + 1 - b` in `P`.
In terms of the Tamari lattice, the *complement* is the symmetric
of ``self``. It is formed from the left-right symmeterized of
the binary trees of the interval (switching left and right
subtrees, see
:meth:`~sage.combinat.binary_tree.BinaryTree.left_right_symmetry`).
In particular, initial intervals are sent to final intervals and
vice-versa.
EXAMPLES::
sage: TamariIntervalPoset(3, [(2, 1), (3, 1)]).complement()
The Tamari interval of size 3 induced by relations [(1, 3), (2, 3)]
sage: TamariIntervalPoset(0, []).complement()
The Tamari interval of size 0 induced by relations []
sage: ip = TamariIntervalPoset(4, [(1, 2), (2, 4), (3, 4)])
sage: ip.complement() == TamariIntervalPoset(4, [(2, 1), (3, 1), (4, 3)])
True
sage: ip.lower_binary_tree() == ip.complement().upper_binary_tree().left_right_symmetry()
True
sage: ip.upper_binary_tree() == ip.complement().lower_binary_tree().left_right_symmetry()
True
sage: ip.is_initial_interval()
True
sage: ip.complement().is_final_interval()
True
"""
N = self._size + 1
new_covers = [[N - i[0], N - i[1]]
for i in self._poset.cover_relations_iterator()]
return TamariIntervalPoset(N - 1, new_covers, check=False)
def left_branch_involution(self):
"""
Return the image of ``self`` by the left-branch involution.
OUTPUT: an interval-poset
.. SEEALSO:: :meth:`rise_contact_involution`
EXAMPLES::
sage: tip = TamariIntervalPoset(8, [(1,2), (2,4), (3,4), (6,7), (3,2), (5,4), (6,4), (8,7)])
sage: t = tip.left_branch_involution(); t
The Tamari interval of size 8 induced by relations [(1, 6), (2, 6),
(3, 5), (4, 5), (5, 6), (6, 8), (7, 8), (7, 6), (4, 3), (3, 1),
(2, 1)]
sage: t.left_branch_involution() == tip
True
REFERENCES: