passagemath-polyhedra 10.6.37__cp314-cp314-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_polyhedra/__init__.py +3 -0
- passagemath_polyhedra-10.6.37.dist-info/METADATA +367 -0
- passagemath_polyhedra-10.6.37.dist-info/METADATA.bak +369 -0
- passagemath_polyhedra-10.6.37.dist-info/RECORD +209 -0
- passagemath_polyhedra-10.6.37.dist-info/WHEEL +5 -0
- passagemath_polyhedra-10.6.37.dist-info/top_level.txt +3 -0
- passagemath_polyhedra.libs/libgcc_s-0cd532bd.so.1 +0 -0
- passagemath_polyhedra.libs/libgmp-0e7fc84e.so.10.5.0 +0 -0
- passagemath_polyhedra.libs/libgomp-8949ffbe.so.1.0.0 +0 -0
- passagemath_polyhedra.libs/libstdc++-5d72f927.so.6.0.33 +0 -0
- sage/all__sagemath_polyhedra.py +50 -0
- sage/game_theory/all.py +8 -0
- sage/game_theory/catalog.py +6 -0
- sage/game_theory/catalog_normal_form_games.py +923 -0
- sage/game_theory/cooperative_game.py +844 -0
- sage/game_theory/matching_game.py +1181 -0
- sage/game_theory/normal_form_game.py +2697 -0
- sage/game_theory/parser.py +275 -0
- sage/geometry/all__sagemath_polyhedra.py +22 -0
- sage/geometry/cone.py +6940 -0
- sage/geometry/cone_catalog.py +847 -0
- sage/geometry/cone_critical_angles.py +1027 -0
- sage/geometry/convex_set.py +1119 -0
- sage/geometry/fan.py +3743 -0
- sage/geometry/fan_isomorphism.py +389 -0
- sage/geometry/fan_morphism.py +1884 -0
- sage/geometry/hasse_diagram.py +202 -0
- sage/geometry/hyperplane_arrangement/affine_subspace.py +390 -0
- sage/geometry/hyperplane_arrangement/all.py +1 -0
- sage/geometry/hyperplane_arrangement/arrangement.py +3905 -0
- sage/geometry/hyperplane_arrangement/check_freeness.py +145 -0
- sage/geometry/hyperplane_arrangement/hyperplane.py +773 -0
- sage/geometry/hyperplane_arrangement/library.py +825 -0
- sage/geometry/hyperplane_arrangement/ordered_arrangement.py +642 -0
- sage/geometry/hyperplane_arrangement/plot.py +520 -0
- sage/geometry/integral_points.py +35 -0
- sage/geometry/integral_points_generic_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/integral_points_generic_dense.pyx +7 -0
- sage/geometry/lattice_polytope.py +5894 -0
- sage/geometry/linear_expression.py +773 -0
- sage/geometry/newton_polygon.py +767 -0
- sage/geometry/point_collection.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/point_collection.pyx +1008 -0
- sage/geometry/polyhedral_complex.py +2616 -0
- sage/geometry/polyhedron/all.py +8 -0
- sage/geometry/polyhedron/backend_cdd.py +460 -0
- sage/geometry/polyhedron/backend_cdd_rdf.py +231 -0
- sage/geometry/polyhedron/backend_field.py +347 -0
- sage/geometry/polyhedron/backend_normaliz.py +2503 -0
- sage/geometry/polyhedron/backend_number_field.py +168 -0
- sage/geometry/polyhedron/backend_polymake.py +765 -0
- sage/geometry/polyhedron/backend_ppl.py +582 -0
- sage/geometry/polyhedron/base.py +1206 -0
- sage/geometry/polyhedron/base0.py +1444 -0
- sage/geometry/polyhedron/base1.py +886 -0
- sage/geometry/polyhedron/base2.py +812 -0
- sage/geometry/polyhedron/base3.py +1845 -0
- sage/geometry/polyhedron/base4.py +1262 -0
- sage/geometry/polyhedron/base5.py +2700 -0
- sage/geometry/polyhedron/base6.py +1741 -0
- sage/geometry/polyhedron/base7.py +997 -0
- sage/geometry/polyhedron/base_QQ.py +1258 -0
- sage/geometry/polyhedron/base_RDF.py +98 -0
- sage/geometry/polyhedron/base_ZZ.py +934 -0
- sage/geometry/polyhedron/base_mutable.py +215 -0
- sage/geometry/polyhedron/base_number_field.py +122 -0
- sage/geometry/polyhedron/cdd_file_format.py +155 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/all.py +1 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/base.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd +76 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx +3859 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd +39 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx +1038 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/conversions.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pxd +9 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx +501 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_data_structure.pxd +207 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd +102 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx +2274 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pxd +370 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pyx +84 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pxd +31 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx +587 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pxd +52 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx +560 -0
- sage/geometry/polyhedron/constructor.py +773 -0
- sage/geometry/polyhedron/double_description.py +753 -0
- sage/geometry/polyhedron/double_description_inhomogeneous.py +564 -0
- sage/geometry/polyhedron/face.py +1060 -0
- sage/geometry/polyhedron/generating_function.py +1810 -0
- sage/geometry/polyhedron/lattice_euclidean_group_element.py +178 -0
- sage/geometry/polyhedron/library.py +3502 -0
- sage/geometry/polyhedron/misc.py +121 -0
- sage/geometry/polyhedron/modules/all.py +1 -0
- sage/geometry/polyhedron/modules/formal_polyhedra_module.py +155 -0
- sage/geometry/polyhedron/palp_database.py +447 -0
- sage/geometry/polyhedron/parent.py +1279 -0
- sage/geometry/polyhedron/plot.py +1986 -0
- sage/geometry/polyhedron/ppl_lattice_polygon.py +556 -0
- sage/geometry/polyhedron/ppl_lattice_polytope.py +1257 -0
- sage/geometry/polyhedron/representation.py +1723 -0
- sage/geometry/pseudolines.py +515 -0
- sage/geometry/relative_interior.py +445 -0
- sage/geometry/toric_plotter.py +1103 -0
- sage/geometry/triangulation/all.py +2 -0
- sage/geometry/triangulation/base.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/triangulation/base.pyx +963 -0
- sage/geometry/triangulation/data.h +147 -0
- sage/geometry/triangulation/data.pxd +4 -0
- sage/geometry/triangulation/element.py +914 -0
- sage/geometry/triangulation/functions.h +10 -0
- sage/geometry/triangulation/functions.pxd +4 -0
- sage/geometry/triangulation/point_configuration.py +2256 -0
- sage/geometry/triangulation/triangulations.h +49 -0
- sage/geometry/triangulation/triangulations.pxd +7 -0
- sage/geometry/voronoi_diagram.py +319 -0
- sage/interfaces/all__sagemath_polyhedra.py +1 -0
- sage/interfaces/polymake.py +2028 -0
- sage/numerical/all.py +13 -0
- sage/numerical/all__sagemath_polyhedra.py +11 -0
- sage/numerical/backends/all.py +1 -0
- sage/numerical/backends/all__sagemath_polyhedra.py +1 -0
- sage/numerical/backends/cvxopt_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/cvxopt_backend.pyx +1006 -0
- sage/numerical/backends/cvxopt_backend_test.py +19 -0
- sage/numerical/backends/cvxopt_sdp_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/cvxopt_sdp_backend.pyx +382 -0
- sage/numerical/backends/cvxpy_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/cvxpy_backend.pxd +41 -0
- sage/numerical/backends/cvxpy_backend.pyx +934 -0
- sage/numerical/backends/cvxpy_backend_test.py +13 -0
- sage/numerical/backends/generic_backend_test.py +24 -0
- sage/numerical/backends/interactivelp_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/interactivelp_backend.pxd +36 -0
- sage/numerical/backends/interactivelp_backend.pyx +1231 -0
- sage/numerical/backends/interactivelp_backend_test.py +12 -0
- sage/numerical/backends/logging_backend.py +391 -0
- sage/numerical/backends/matrix_sdp_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/matrix_sdp_backend.pxd +15 -0
- sage/numerical/backends/matrix_sdp_backend.pyx +478 -0
- sage/numerical/backends/ppl_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/ppl_backend.pyx +1126 -0
- sage/numerical/backends/ppl_backend_test.py +13 -0
- sage/numerical/backends/scip_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/scip_backend.pxd +22 -0
- sage/numerical/backends/scip_backend.pyx +1289 -0
- sage/numerical/backends/scip_backend_test.py +13 -0
- sage/numerical/interactive_simplex_method.py +5338 -0
- sage/numerical/knapsack.py +665 -0
- sage/numerical/linear_functions.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/linear_functions.pxd +31 -0
- sage/numerical/linear_functions.pyx +1648 -0
- sage/numerical/linear_tensor.py +470 -0
- sage/numerical/linear_tensor_constraints.py +448 -0
- sage/numerical/linear_tensor_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/linear_tensor_element.pxd +6 -0
- sage/numerical/linear_tensor_element.pyx +459 -0
- sage/numerical/mip.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/mip.pxd +40 -0
- sage/numerical/mip.pyx +3667 -0
- sage/numerical/sdp.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/sdp.pxd +39 -0
- sage/numerical/sdp.pyx +1433 -0
- sage/rings/all__sagemath_polyhedra.py +3 -0
- sage/rings/polynomial/all__sagemath_polyhedra.py +10 -0
- sage/rings/polynomial/omega.py +982 -0
- sage/schemes/all__sagemath_polyhedra.py +2 -0
- sage/schemes/toric/all.py +10 -0
- sage/schemes/toric/chow_group.py +1248 -0
- sage/schemes/toric/divisor.py +2082 -0
- sage/schemes/toric/divisor_class.cpython-314-x86_64-linux-musl.so +0 -0
- sage/schemes/toric/divisor_class.pyx +322 -0
- sage/schemes/toric/fano_variety.py +1606 -0
- sage/schemes/toric/homset.py +650 -0
- sage/schemes/toric/ideal.py +451 -0
- sage/schemes/toric/library.py +1322 -0
- sage/schemes/toric/morphism.py +1958 -0
- sage/schemes/toric/points.py +1032 -0
- sage/schemes/toric/sheaf/all.py +1 -0
- sage/schemes/toric/sheaf/constructor.py +302 -0
- sage/schemes/toric/sheaf/klyachko.py +921 -0
- sage/schemes/toric/toric_subscheme.py +905 -0
- sage/schemes/toric/variety.py +3460 -0
- sage/schemes/toric/weierstrass.py +1078 -0
- sage/schemes/toric/weierstrass_covering.py +457 -0
- sage/schemes/toric/weierstrass_higher.py +288 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.info +10 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v03 +0 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v04 +0 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v05 +1 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v06 +1 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.info +22 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v04 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v05 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v06 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v07 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v08 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v09 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v10 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v11 +1 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v12 +1 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v13 +1 -0
- sage_wheels/share/reflexive_polytopes/reflexive_polytopes_2d +80 -0
- sage_wheels/share/reflexive_polytopes/reflexive_polytopes_3d +37977 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
r"""
|
|
3
|
+
Pseudolines
|
|
4
|
+
|
|
5
|
+
This module gathers everything that has to do with pseudolines, and for a start
|
|
6
|
+
a :class:`PseudolineArrangement` class that can be used to describe an
|
|
7
|
+
arrangement of pseudolines in several different ways, and to translate one
|
|
8
|
+
description into another, as well as to display *Wiring diagrams* via the
|
|
9
|
+
:meth:`show <sage.geometry.pseudolines.PseudolineArrangement.show>` method.
|
|
10
|
+
|
|
11
|
+
In the following, we try to stick to the terminology given in [Fe1997]_, which
|
|
12
|
+
can be checked in case of doubt. And please fix this module's documentation
|
|
13
|
+
afterwards :-)
|
|
14
|
+
|
|
15
|
+
**Definition**
|
|
16
|
+
|
|
17
|
+
A *pseudoline* can not be defined by itself, though it can be thought of as a
|
|
18
|
+
`x`-monotone curve in the plane. A *set* of pseudolines, however, represents a
|
|
19
|
+
set of such curves that pairwise intersect exactly once (and hence mimic the
|
|
20
|
+
behaviour of straight lines in general position). We also assume that those
|
|
21
|
+
pseudolines are in general position, that is that no three of them cross at the
|
|
22
|
+
same point.
|
|
23
|
+
|
|
24
|
+
The present class is made to deal with a combinatorial encoding of a pseudolines
|
|
25
|
+
arrangement, that is the ordering in which a pseudoline `l_i` of an arrangement
|
|
26
|
+
`l_0, ..., l_{n-1}` crosses the `n-1` other lines.
|
|
27
|
+
|
|
28
|
+
.. WARNING::
|
|
29
|
+
|
|
30
|
+
It is assumed through all the methods that the given lines are numbered
|
|
31
|
+
according to their `y`-coordinate on the vertical line `x=-\infty`.
|
|
32
|
+
For instance, it is not possible that the first transposition be ``(0,2)``
|
|
33
|
+
(or equivalently that the first line `l_0` crosses is `l_2` and conversely),
|
|
34
|
+
because one of them would have to cross `l_1` first.
|
|
35
|
+
|
|
36
|
+
Encodings
|
|
37
|
+
----------
|
|
38
|
+
|
|
39
|
+
**Permutations**
|
|
40
|
+
|
|
41
|
+
An arrangement of pseudolines can be described by a sequence of `n` lists of
|
|
42
|
+
length `n-1`, where the `i` list is a permutation of `\{0, ..., n-1\} \backslash
|
|
43
|
+
i` representing the ordering in which the `i` th pseudoline meets the other
|
|
44
|
+
ones.
|
|
45
|
+
|
|
46
|
+
::
|
|
47
|
+
|
|
48
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
49
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
50
|
+
sage: p = PseudolineArrangement(permutations)
|
|
51
|
+
sage: p
|
|
52
|
+
Arrangement of pseudolines of size 4
|
|
53
|
+
sage: p.show() # needs sage.plot
|
|
54
|
+
|
|
55
|
+
**Sequence of transpositions**
|
|
56
|
+
|
|
57
|
+
An arrangement of pseudolines can also be described as a sequence of `\binom n
|
|
58
|
+
2` transpositions (permutations of two elements). In this sequence, the
|
|
59
|
+
transposition `(2,3)` appears before `(8, 2)` if `l_2` crosses `l_3` before it
|
|
60
|
+
crosses `l_8`. This encoding is easy to obtain by reading the wiring diagram
|
|
61
|
+
from left to right (see the :meth:`show
|
|
62
|
+
<sage.geometry.pseudolines.PseudolineArrangement.show>` method).
|
|
63
|
+
|
|
64
|
+
::
|
|
65
|
+
|
|
66
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
67
|
+
sage: transpositions = [(3, 2), (3, 1), (0, 3), (2, 1), (0, 2), (0, 1)]
|
|
68
|
+
sage: p = PseudolineArrangement(transpositions)
|
|
69
|
+
sage: p
|
|
70
|
+
Arrangement of pseudolines of size 4
|
|
71
|
+
sage: p.show() # needs sage.plot
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Note that this ordering is not necessarily unique.
|
|
75
|
+
|
|
76
|
+
**Felsner's Matrix**
|
|
77
|
+
|
|
78
|
+
Felser gave an encoding of an arrangement of pseudolines that takes `n^2` bits
|
|
79
|
+
instead of the `n^2\log(n)` bits required by the two previous encodings.
|
|
80
|
+
|
|
81
|
+
Instead of storing the permutation ``[3, 2, 1]`` to remember that line `l_0`
|
|
82
|
+
crosses `l_3` then `l_2` then `l_1`, it is sufficient to remember the positions
|
|
83
|
+
for which each line `l_i` meets a line `l_j` with `j < i`. As `l_0` -- the first
|
|
84
|
+
of the lines -- can only meet pseudolines with higher index, we can store ``[0,
|
|
85
|
+
0, 0]`` instead of ``[3, 2, 1]`` stored previously. For `l_1`'s permutation
|
|
86
|
+
``[3, 2, 0]`` we only need to remember that `l_1` first crosses 2 pseudolines of
|
|
87
|
+
higher index, and then a pseudoline with smaller index, which yields the bit
|
|
88
|
+
vector ``[0, 0, 1]``. Hence we can transform the list of permutations above into
|
|
89
|
+
a list of `n` bit vectors of length `n-1`, that is
|
|
90
|
+
|
|
91
|
+
.. MATH::
|
|
92
|
+
|
|
93
|
+
\begin{array}{ccc}
|
|
94
|
+
3 & 2 & 1\\
|
|
95
|
+
3 & 2 & 0\\
|
|
96
|
+
3 & 1 & 0\\
|
|
97
|
+
2 & 1 & 0\\
|
|
98
|
+
\end{array}
|
|
99
|
+
\Rightarrow
|
|
100
|
+
\begin{array}{ccc}
|
|
101
|
+
0 & 0 & 0\\
|
|
102
|
+
0 & 0 & 1\\
|
|
103
|
+
0 & 1 & 1\\
|
|
104
|
+
1 & 1 & 1\\
|
|
105
|
+
\end{array}
|
|
106
|
+
|
|
107
|
+
In order to go back from Felsner's matrix to an encoding by a sequence of
|
|
108
|
+
transpositions, it is sufficient to look for occurrences of
|
|
109
|
+
`\begin{array}{c}0\\1\end{array}` in the first column of the matrix, as it
|
|
110
|
+
corresponds in the wiring diagram to a line going up while the line immediately
|
|
111
|
+
above it goes down -- those two lines cross. Each time such a pattern is found
|
|
112
|
+
it yields a new transposition, and the matrix can be updated so that this
|
|
113
|
+
pattern disappears. A more detailed description of this algorithm is given in
|
|
114
|
+
[Fe1997]_.
|
|
115
|
+
|
|
116
|
+
::
|
|
117
|
+
|
|
118
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
119
|
+
sage: felsner_matrix = [[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1]]
|
|
120
|
+
sage: p = PseudolineArrangement(felsner_matrix)
|
|
121
|
+
sage: p
|
|
122
|
+
Arrangement of pseudolines of size 4
|
|
123
|
+
|
|
124
|
+
Example
|
|
125
|
+
-------
|
|
126
|
+
|
|
127
|
+
Let us define in the plane several lines `l_i` of equation `y = a x+b` by
|
|
128
|
+
picking a coefficient `a` and `b` for each of them. We make sure that no two of
|
|
129
|
+
them are parallel by making sure all of the `a` chosen are different, and we
|
|
130
|
+
avoid a common crossing of three lines by adding a random noise to `b`::
|
|
131
|
+
|
|
132
|
+
sage: n = 20
|
|
133
|
+
sage: l = sorted(zip(Subsets(20*n, n).random_element(),
|
|
134
|
+
....: [randint(0, 20*n) + random() for i in range(n)]))
|
|
135
|
+
sage: print(l[:5]) # not tested # needs sage.combinat
|
|
136
|
+
[(96, 278.0130613051349), (74, 332.92512282478714), (13, 155.65820951249867),
|
|
137
|
+
(209, 34.753946221755307), (147, 193.51376457741441)]
|
|
138
|
+
|
|
139
|
+
We can now compute for each `i` the order in which line `i` meets the other lines::
|
|
140
|
+
|
|
141
|
+
sage: permutations = [[0..i-1] + [i+1..n-1] for i in range(n)]
|
|
142
|
+
sage: def a(x): return l[x][0]
|
|
143
|
+
sage: def b(x): return l[x][1]
|
|
144
|
+
sage: for i, perm in enumerate(permutations):
|
|
145
|
+
....: perm.sort(key=lambda j: (b(j)-b(i))/(a(i)-a(j)))
|
|
146
|
+
|
|
147
|
+
And finally build the line arrangement::
|
|
148
|
+
|
|
149
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
150
|
+
sage: p = PseudolineArrangement(permutations)
|
|
151
|
+
sage: print(p)
|
|
152
|
+
Arrangement of pseudolines of size 20
|
|
153
|
+
sage: p.show(figsize=[20,8]) # needs sage.combinat sage.plot
|
|
154
|
+
|
|
155
|
+
Author
|
|
156
|
+
^^^^^^
|
|
157
|
+
Nathann Cohen
|
|
158
|
+
|
|
159
|
+
Methods
|
|
160
|
+
-------
|
|
161
|
+
"""
|
|
162
|
+
##############################################################################
|
|
163
|
+
# Copyright (C) 2011 Nathann Cohen <nathann.cohen@gmail.com>
|
|
164
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
165
|
+
# The full text of the GPL is available at:
|
|
166
|
+
# https://www.gnu.org/licenses/
|
|
167
|
+
##############################################################################
|
|
168
|
+
|
|
169
|
+
from copy import deepcopy
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class PseudolineArrangement:
|
|
173
|
+
|
|
174
|
+
def __init__(self, seq, encoding='auto'):
|
|
175
|
+
r"""
|
|
176
|
+
Create an arrangement of pseudolines.
|
|
177
|
+
|
|
178
|
+
INPUT:
|
|
179
|
+
|
|
180
|
+
- ``seq`` -- a sequence describing the line arrangement. It can be:
|
|
181
|
+
|
|
182
|
+
- A list of `n` permutations of size `n-1`.
|
|
183
|
+
- A list of `\binom n 2` transpositions
|
|
184
|
+
- A Felsner matrix, given as a sequence of `n` binary vectors of
|
|
185
|
+
length `n-1`.
|
|
186
|
+
|
|
187
|
+
- ``encoding`` -- information on how the data should be interpreted, and
|
|
188
|
+
can assume any value among 'transpositions', 'permutations', 'Felsner'
|
|
189
|
+
or 'auto'. In the latter case, the type will be guessed (default
|
|
190
|
+
behaviour).
|
|
191
|
+
|
|
192
|
+
.. NOTE::
|
|
193
|
+
|
|
194
|
+
* The pseudolines are assumed to be integers `0,\dots,n-1`.
|
|
195
|
+
|
|
196
|
+
* For more information on the different encodings, see the
|
|
197
|
+
:mod:`pseudolines module <sage.geometry.pseudolines>`'s
|
|
198
|
+
documentation.
|
|
199
|
+
|
|
200
|
+
TESTS:
|
|
201
|
+
|
|
202
|
+
From permutations::
|
|
203
|
+
|
|
204
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
205
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
206
|
+
sage: PseudolineArrangement(permutations)
|
|
207
|
+
Arrangement of pseudolines of size 4
|
|
208
|
+
|
|
209
|
+
From transpositions ::
|
|
210
|
+
|
|
211
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
212
|
+
sage: transpositions = [(3, 2), (3, 1), (0, 3), (2, 1), (0, 2), (0, 1)]
|
|
213
|
+
sage: PseudolineArrangement(transpositions)
|
|
214
|
+
Arrangement of pseudolines of size 4
|
|
215
|
+
|
|
216
|
+
From a Felsner matrix::
|
|
217
|
+
|
|
218
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
219
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
220
|
+
sage: p = PseudolineArrangement(permutations)
|
|
221
|
+
sage: matrix = p.felsner_matrix()
|
|
222
|
+
sage: PseudolineArrangement(matrix) == p
|
|
223
|
+
True
|
|
224
|
+
|
|
225
|
+
Wrong input::
|
|
226
|
+
|
|
227
|
+
sage: PseudolineArrangement([[5, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]])
|
|
228
|
+
Traceback (most recent call last):
|
|
229
|
+
...
|
|
230
|
+
ValueError: Are the lines really numbered from 0 to n-1?
|
|
231
|
+
sage: PseudolineArrangement([(3, 2), (3, 1), (0, 3), (2, 1), (0, 2)])
|
|
232
|
+
Traceback (most recent call last):
|
|
233
|
+
...
|
|
234
|
+
ValueError: A line is numbered 3 but the number of transpositions ...
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
# Sequence of transpositions
|
|
238
|
+
if (encoding == "transpositions" or
|
|
239
|
+
(encoding == "auto" and len(seq[0]) == 2 and len(seq) > 3)):
|
|
240
|
+
|
|
241
|
+
self._n = max(map(max, seq)) + 1
|
|
242
|
+
if (self._n * (self._n-1))/2 != len(seq):
|
|
243
|
+
raise ValueError(
|
|
244
|
+
"A line is numbered "+str(self._n-1)+" but the number" +
|
|
245
|
+
" of transpositions is different from binomial(" +
|
|
246
|
+
str(self._n-1)+",2). Are the lines numbered from 0 to n-1?" +
|
|
247
|
+
" Are they really non-parallel? Please check the documentation.")
|
|
248
|
+
|
|
249
|
+
self._permutations = [[] for i in range(self._n)]
|
|
250
|
+
|
|
251
|
+
for i,j in seq:
|
|
252
|
+
self._permutations[i].append(j)
|
|
253
|
+
self._permutations[j].append(i)
|
|
254
|
+
|
|
255
|
+
# Sequence of permutations
|
|
256
|
+
elif (encoding == "permutations" or
|
|
257
|
+
(encoding == "auto" and (len(seq[0]) == len(seq)-1) and max(seq[0]) > 1)):
|
|
258
|
+
|
|
259
|
+
self._n = len(seq)
|
|
260
|
+
self._permutations = [list(_) for _ in seq]
|
|
261
|
+
|
|
262
|
+
if max(map(max, seq)) != self._n - 1 :
|
|
263
|
+
raise ValueError("Are the lines really numbered from 0 to n-1?")
|
|
264
|
+
|
|
265
|
+
# Felsner encoding
|
|
266
|
+
elif (encoding == "Felsner" or
|
|
267
|
+
(encoding == "auto" and len(seq[0]) == len(seq) - 1)):
|
|
268
|
+
|
|
269
|
+
seq = deepcopy(seq)
|
|
270
|
+
self._n = len(seq)
|
|
271
|
+
ordering = list(range(self._n))
|
|
272
|
+
|
|
273
|
+
self._permutations = [[] for i in range(self._n)]
|
|
274
|
+
|
|
275
|
+
crossings = (self._n * (self._n-1))/2
|
|
276
|
+
|
|
277
|
+
i = 0
|
|
278
|
+
while crossings > 0:
|
|
279
|
+
if (seq[i] and
|
|
280
|
+
(seq[i][0] == 0 and
|
|
281
|
+
seq[i+1][0] == 1)):
|
|
282
|
+
|
|
283
|
+
crossings -= 1
|
|
284
|
+
|
|
285
|
+
self._permutations[ordering[i]].append(ordering[i+1])
|
|
286
|
+
self._permutations[ordering[i+1]].append(ordering[i])
|
|
287
|
+
|
|
288
|
+
ordering[i], ordering[i+1] = ordering[i+1], ordering[i]
|
|
289
|
+
seq[i], seq[i+1] = seq[i+1], seq[i]
|
|
290
|
+
|
|
291
|
+
seq[i].pop(0)
|
|
292
|
+
seq[i+1].pop(0)
|
|
293
|
+
|
|
294
|
+
if i > 0 and seq[i - 1]:
|
|
295
|
+
i -= 1
|
|
296
|
+
else:
|
|
297
|
+
i += 1
|
|
298
|
+
else:
|
|
299
|
+
i += 1
|
|
300
|
+
else:
|
|
301
|
+
|
|
302
|
+
if encoding != "auto":
|
|
303
|
+
raise ValueError("The value of encoding must be one of 'transpositions', 'permutations', 'Felsner' or 'auto'.")
|
|
304
|
+
|
|
305
|
+
raise ValueError("The encoding you used could not be guessed. Your input string is probably badly formatted, or you have at most 3 lines and we cannot distinguish the encoding. Please specify the encoding you used.")
|
|
306
|
+
|
|
307
|
+
def transpositions(self):
|
|
308
|
+
r"""
|
|
309
|
+
Return the arrangement as `\binom n 2` transpositions.
|
|
310
|
+
|
|
311
|
+
See the :mod:`pseudolines module <sage.geometry.pseudolines>`'s
|
|
312
|
+
documentation for more information on this encoding.
|
|
313
|
+
|
|
314
|
+
EXAMPLES::
|
|
315
|
+
|
|
316
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
317
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
318
|
+
sage: p1 = PseudolineArrangement(permutations)
|
|
319
|
+
sage: transpositions = [(3, 2), (3, 1), (0, 3), (2, 1), (0, 2), (0, 1)]
|
|
320
|
+
sage: p2 = PseudolineArrangement(transpositions)
|
|
321
|
+
sage: p1 == p2
|
|
322
|
+
True
|
|
323
|
+
sage: p1.transpositions()
|
|
324
|
+
[(3, 2), (3, 1), (0, 3), (2, 1), (0, 2), (0, 1)]
|
|
325
|
+
sage: p2.transpositions()
|
|
326
|
+
[(3, 2), (3, 1), (0, 3), (2, 1), (0, 2), (0, 1)]
|
|
327
|
+
"""
|
|
328
|
+
t = []
|
|
329
|
+
perm = deepcopy(self._permutations)
|
|
330
|
+
|
|
331
|
+
crossings = (self._n * (self._n-1))/2
|
|
332
|
+
|
|
333
|
+
while crossings > 0:
|
|
334
|
+
|
|
335
|
+
i = 0
|
|
336
|
+
|
|
337
|
+
while perm[i] == []:
|
|
338
|
+
i += 1
|
|
339
|
+
|
|
340
|
+
k = 0
|
|
341
|
+
while i != perm[perm[i][0]][0]:
|
|
342
|
+
i = perm[i][0]
|
|
343
|
+
k += 1
|
|
344
|
+
|
|
345
|
+
if k > self._n:
|
|
346
|
+
raise ValueError(
|
|
347
|
+
"It looks like the data does not correspond to a" +
|
|
348
|
+
"pseudoline arrangement. We have found k>2 lines" +
|
|
349
|
+
"such that the ith line meets the (i+1)th before" +
|
|
350
|
+
" the (i-1)th (this creates a cyclic dependency)" +
|
|
351
|
+
" which is totally impossible.")
|
|
352
|
+
|
|
353
|
+
t.append((i, perm[i][0]))
|
|
354
|
+
perm[perm[i][0]].pop(0)
|
|
355
|
+
perm[i].pop(0)
|
|
356
|
+
|
|
357
|
+
crossings -= 1
|
|
358
|
+
|
|
359
|
+
if max(map(len, perm)) != 0:
|
|
360
|
+
raise ValueError("There has been an error while computing the transpositions.")
|
|
361
|
+
|
|
362
|
+
return t
|
|
363
|
+
|
|
364
|
+
def permutations(self):
|
|
365
|
+
r"""
|
|
366
|
+
Return the arrangements as `n` permutations of size `n-1`.
|
|
367
|
+
|
|
368
|
+
See the :mod:`pseudolines module <sage.geometry.pseudolines>`'s
|
|
369
|
+
documentation for more information on this encoding.
|
|
370
|
+
|
|
371
|
+
EXAMPLES::
|
|
372
|
+
|
|
373
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
374
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
375
|
+
sage: p = PseudolineArrangement(permutations)
|
|
376
|
+
sage: p.permutations()
|
|
377
|
+
[[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
378
|
+
"""
|
|
379
|
+
return deepcopy(self._permutations)
|
|
380
|
+
|
|
381
|
+
def felsner_matrix(self):
|
|
382
|
+
r"""
|
|
383
|
+
Return a Felsner matrix describing the arrangement.
|
|
384
|
+
|
|
385
|
+
See the :mod:`pseudolines module <sage.geometry.pseudolines>`'s
|
|
386
|
+
documentation for more information on this encoding.
|
|
387
|
+
|
|
388
|
+
EXAMPLES::
|
|
389
|
+
|
|
390
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
391
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
392
|
+
sage: p = PseudolineArrangement(permutations)
|
|
393
|
+
sage: p.felsner_matrix()
|
|
394
|
+
[[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1]]
|
|
395
|
+
"""
|
|
396
|
+
|
|
397
|
+
m = [[] for i in range(self._n)]
|
|
398
|
+
|
|
399
|
+
for i,j in self.transpositions():
|
|
400
|
+
if i < j:
|
|
401
|
+
i, j = j, i
|
|
402
|
+
|
|
403
|
+
m[j].append(0)
|
|
404
|
+
m[i].append(1)
|
|
405
|
+
|
|
406
|
+
return m
|
|
407
|
+
|
|
408
|
+
def show(self, **args):
|
|
409
|
+
r"""
|
|
410
|
+
Displays the pseudoline arrangement as a wiring diagram.
|
|
411
|
+
|
|
412
|
+
INPUT:
|
|
413
|
+
|
|
414
|
+
- ``**args`` -- any arguments to be forwarded to the ``show`` method. In
|
|
415
|
+
particular, to tune the dimensions, use the ``figsize`` argument
|
|
416
|
+
(example below).
|
|
417
|
+
|
|
418
|
+
EXAMPLES::
|
|
419
|
+
|
|
420
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
421
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
422
|
+
sage: p = PseudolineArrangement(permutations)
|
|
423
|
+
sage: p.show(figsize=[7,5]) # needs sage.plot
|
|
424
|
+
|
|
425
|
+
TESTS::
|
|
426
|
+
|
|
427
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
428
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 0, 1], [2, 0, 1]]
|
|
429
|
+
sage: p = PseudolineArrangement(permutations)
|
|
430
|
+
sage: p.show() # needs sage.plot
|
|
431
|
+
Traceback (most recent call last):
|
|
432
|
+
...
|
|
433
|
+
ValueError: There has been a problem while plotting the figure...
|
|
434
|
+
"""
|
|
435
|
+
x = 1
|
|
436
|
+
from sage.plot.line import line
|
|
437
|
+
from sage.plot.text import text
|
|
438
|
+
|
|
439
|
+
lines = [[(0,self._n-1-i)] for i in range(self._n)]
|
|
440
|
+
|
|
441
|
+
for i,j in self.transpositions():
|
|
442
|
+
iy = lines[i][-1][1]
|
|
443
|
+
jy = lines[j][-1][1]
|
|
444
|
+
|
|
445
|
+
lines[i].append((x, iy))
|
|
446
|
+
lines[j].append((x, jy))
|
|
447
|
+
|
|
448
|
+
if abs(iy-jy) != 1:
|
|
449
|
+
raise ValueError(
|
|
450
|
+
"There has been a problem while plotting the figure. It " +
|
|
451
|
+
"seems that the lines are not correctly ordered. Please " +
|
|
452
|
+
"check the pseudolines modules documentation, there is a "
|
|
453
|
+
+ "warning about that. ")
|
|
454
|
+
|
|
455
|
+
lines[i].append((x+2,jy))
|
|
456
|
+
lines[j].append((x+2,iy))
|
|
457
|
+
|
|
458
|
+
x += 2
|
|
459
|
+
|
|
460
|
+
L = line([(1,1)])
|
|
461
|
+
|
|
462
|
+
for i, l in enumerate(lines):
|
|
463
|
+
l.append((x+2, l[-1][1]))
|
|
464
|
+
L += line(l)
|
|
465
|
+
|
|
466
|
+
L += text(str(i), (0, l[0][1]+.3), horizontal_alignment='right')
|
|
467
|
+
L += text(str(i), (x+2, l[-1][1]+.3), horizontal_alignment='left')
|
|
468
|
+
|
|
469
|
+
return L.show(axes=False, **args)
|
|
470
|
+
|
|
471
|
+
def __repr__(self):
|
|
472
|
+
r"""
|
|
473
|
+
A short txt description of the pseudoline arrangement.
|
|
474
|
+
|
|
475
|
+
EXAMPLES::
|
|
476
|
+
|
|
477
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
478
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
479
|
+
sage: p = PseudolineArrangement(permutations)
|
|
480
|
+
sage: p
|
|
481
|
+
Arrangement of pseudolines of size 4
|
|
482
|
+
"""
|
|
483
|
+
return "Arrangement of pseudolines of size " + str(self._n)
|
|
484
|
+
|
|
485
|
+
def __eq__(self, other):
|
|
486
|
+
r"""
|
|
487
|
+
Test of equality.
|
|
488
|
+
|
|
489
|
+
TESTS::
|
|
490
|
+
|
|
491
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
492
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
493
|
+
sage: p1 = PseudolineArrangement(permutations)
|
|
494
|
+
sage: transpositions = [(3, 2), (3, 1), (0, 3), (2, 1), (0, 2), (0, 1)]
|
|
495
|
+
sage: p2 = PseudolineArrangement(transpositions)
|
|
496
|
+
sage: p1 == p2
|
|
497
|
+
True
|
|
498
|
+
"""
|
|
499
|
+
return (self._n == other._n) and (self._permutations == other._permutations)
|
|
500
|
+
|
|
501
|
+
def __ne__(self, other):
|
|
502
|
+
"""
|
|
503
|
+
Test for non-equality.
|
|
504
|
+
|
|
505
|
+
TESTS::
|
|
506
|
+
|
|
507
|
+
sage: from sage.geometry.pseudolines import PseudolineArrangement
|
|
508
|
+
sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]]
|
|
509
|
+
sage: p1 = PseudolineArrangement(permutations)
|
|
510
|
+
sage: transpositions = [(3, 2), (3, 1), (0, 3), (2, 1), (0, 2), (0, 1)]
|
|
511
|
+
sage: p2 = PseudolineArrangement(transpositions)
|
|
512
|
+
sage: p1 != p2
|
|
513
|
+
False
|
|
514
|
+
"""
|
|
515
|
+
return not (self == other)
|