# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1354453591 -3600
# Node ID f62a40d61d1a3b9987b7de659bb9631718656186
# Parent 5fbca18f0f90bcefcf1d37f87d6069855b63cc3c
Change default behaviour of Poset to facade = True -- removing ".element" everywhere
diff --git a/sage/categories/coxeter_groups.py b/sage/categories/coxeter_groups.py
a
|
b
|
|
1434 | 1434 | |
1435 | 1435 | sage: W = WeylGroup(["B",3]) |
1436 | 1436 | sage: P = W.bruhat_poset() # This is built from bruhat_lower_covers |
1437 | | sage: Q = Poset((W, attrcall("bruhat_le"))) # long time (10s) |
1438 | | sage: all( u.bruhat_le(v) == (P(u) <= P(v)) for u in W for v in W ) # long time (7s) |
| 1437 | sage: Q = Poset((W, attrcall("bruhat_le"))) # long time (10s) |
| 1438 | sage: all( u.bruhat_le(v) == P.is_lequal(u,v) for u in W for v in W ) # long time (7s) |
1439 | 1439 | True |
1440 | | sage: all((P(u) <= P(v)) == (Q(u) <= Q(v)) for u in W for v in W) # long time (9s) |
| 1440 | sage: all( P.is_lequal(u,v) == Q.is_lequal(u,v) for u in W for v in W) # long time (9s) |
1441 | 1441 | True |
1442 | 1442 | |
1443 | 1443 | """ |
diff --git a/sage/categories/finite_lattice_posets.py b/sage/categories/finite_lattice_posets.py
a
|
b
|
|
110 | 110 | |
111 | 111 | sage: D = LatticePoset((divisors(60), attrcall("divides"))) |
112 | 112 | sage: B = LatticePoset((Subsets([2,2,3]), attrcall("issubset"))) |
113 | | sage: def f(b): return D(5*prod(b.element)) |
| 113 | sage: def f(b): return D(5*prod(b)) |
114 | 114 | sage: B.is_lattice_morphism(f, D) |
115 | 115 | True |
116 | 116 | |
diff --git a/sage/categories/finite_posets.py b/sage/categories/finite_posets.py
a
|
b
|
|
115 | 115 | |
116 | 116 | sage: D = Poset((divisors(30), attrcall("divides"))) |
117 | 117 | sage: B = Poset(([frozenset(s) for s in Subsets([2,3,5])], attrcall("issubset"))) |
118 | | sage: def f(b): return D(prod(b.element)) |
| 118 | sage: def f(b): return D(prod(b)) |
119 | 119 | sage: B.is_poset_isomorphism(f, D) |
120 | 120 | True |
121 | 121 | |
… |
… |
|
123 | 123 | of divisors of 30, ordered by usual comparison:: |
124 | 124 | |
125 | 125 | sage: P = Poset((divisors(30), operator.le)) |
126 | | sage: def f(b): return P(prod(b.element)) |
| 126 | sage: def f(b): return P(prod(b)) |
127 | 127 | sage: B.is_poset_isomorphism(f, P) |
128 | 128 | False |
129 | 129 | |
130 | 130 | A non surjective case:: |
131 | 131 | |
132 | 132 | sage: B = Poset(([frozenset(s) for s in Subsets([2,3])], attrcall("issubset"))) |
133 | | sage: def f(b): return D(prod(b.element)) |
| 133 | sage: def f(b): return D(prod(b)) |
134 | 134 | sage: B.is_poset_isomorphism(f, D) |
135 | 135 | False |
136 | 136 | |
137 | 137 | A non injective case:: |
138 | 138 | |
139 | 139 | sage: B = Poset(([frozenset(s) for s in Subsets([2,3,5,6])], attrcall("issubset"))) |
140 | | sage: def f(b): return D(gcd(prod(b.element), 30)) |
| 140 | sage: def f(b): return D(gcd(prod(b), 30)) |
141 | 141 | sage: B.is_poset_isomorphism(f, D) |
142 | 142 | False |
143 | 143 | |
… |
… |
|
180 | 180 | |
181 | 181 | sage: D = Poset((divisors(30), attrcall("divides"))) |
182 | 182 | sage: B = Poset(([frozenset(s) for s in Subsets([2,3,5,6])], attrcall("issubset"))) |
183 | | sage: def f(b): return D(gcd(prod(b.element), 30)) |
| 183 | sage: def f(b): return D(gcd(prod(b), 30)) |
184 | 184 | sage: B.is_poset_morphism(f, D) |
185 | 185 | True |
186 | 186 | |
… |
… |
|
192 | 192 | of 30, ordered by usual comparison:: |
193 | 193 | |
194 | 194 | sage: P = Poset((divisors(30), operator.le)) |
195 | | sage: def f(b): return P(gcd(prod(b.element), 30)) |
| 195 | sage: def f(b): return P(gcd(prod(b), 30)) |
196 | 196 | sage: B.is_poset_morphism(f, P) |
197 | 197 | True |
198 | 198 | |
… |
… |
|
206 | 206 | |
207 | 207 | sage: P = Posets.ChainPoset(2) |
208 | 208 | sage: Q = Posets.AntichainPoset(2) |
209 | | sage: f = lambda x: 1-x.element |
| 209 | sage: f = lambda x: 1-x |
210 | 210 | sage: P.is_poset_morphism(f, P) |
211 | 211 | False |
212 | 212 | sage: P.is_poset_morphism(f, Q) |
… |
… |
|
338 | 338 | |
339 | 339 | sage: P = Poset( ( [1,2,3], [ [1,3], [2,3] ] ) ) |
340 | 340 | sage: P.panyushev_orbits() |
341 | | [[set([3]), set([]), set([1, 2])], [set([2]), set([1])]] |
| 341 | [[set([2]), set([1])], [set([]), set([1, 2]), set([3])]] |
342 | 342 | """ |
343 | 343 | # TODO: implement a generic function taking a set and |
344 | 344 | # bijections on this set, and returning the orbits. |
diff --git a/sage/categories/posets.py b/sage/categories/posets.py
a
|
b
|
|
53 | 53 | Unless the poset is a facade (see :class:`Sets.Facades`), one can |
54 | 54 | compare directly its elements using the usual Python operators:: |
55 | 55 | |
56 | | sage: D = Poset((divisors(30), attrcall("divides"))) |
| 56 | sage: D = Poset((divisors(30), attrcall("divides")), facade = False) |
57 | 57 | sage: D(3) <= D(6) |
58 | 58 | True |
59 | 59 | sage: D(3) <= D(3) |
diff --git a/sage/geometry/cone.py b/sage/geometry/cone.py
a
|
b
|
|
148 | 148 | sage: map(len, L.level_sets()) |
149 | 149 | [1, 4, 4, 1] |
150 | 150 | sage: face = L.level_sets()[2][0] |
151 | | sage: face.element.rays() |
| 151 | sage: face.rays() |
152 | 152 | N(1, 1, 1), |
153 | 153 | N(1, -1, 1) |
154 | 154 | in 3-d lattice N |
… |
… |
|
1805 | 1805 | adjacent.update(L.open_interval(facet, superface)) |
1806 | 1806 | if adjacent: |
1807 | 1807 | adjacent.remove(L(self)) |
1808 | | return self._sort_faces(face.element for face in adjacent) |
| 1808 | return self._sort_faces(iter(adjacent)) |
1809 | 1809 | elif self.dim() == self._ambient.dim(): |
1810 | 1810 | # Special treatment relevant for fans |
1811 | 1811 | for facet in facets: |
… |
… |
|
2106 | 2106 | 1-d face of 2-d cone in 2-d lattice N] |
2107 | 2107 | [2-d cone in 2-d lattice N] |
2108 | 2108 | |
2109 | | To work with a particular face of a particular dimension it is not |
2110 | | enough to do just :: |
| 2109 | Now you can look at the rays of this face... :: |
2111 | 2110 | |
2112 | 2111 | sage: face = L.level_sets()[1][0] |
2113 | | sage: face |
2114 | | 1-d face of 2-d cone in 2-d lattice N |
2115 | | sage: face.rays() |
2116 | | Traceback (most recent call last): |
2117 | | ... |
2118 | | AttributeError: 'FinitePoset_with_category.element_class' object |
2119 | | has no attribute 'rays' |
2120 | | |
2121 | | To get the actual face you need one more step:: |
2122 | | |
2123 | | sage: face = face.element |
2124 | | |
2125 | | Now you can look at the actual rays of this face... :: |
2126 | | |
2127 | 2112 | sage: face.rays() |
2128 | 2113 | N(1, 0) |
2129 | 2114 | in 2-d lattice N |
… |
… |
|
2148 | 2133 | sage: face = L.level_sets()[1][0] |
2149 | 2134 | sage: D = L.hasse_diagram() |
2150 | 2135 | sage: D.neighbors(face) |
2151 | | [0-d face of 2-d cone in 2-d lattice N, |
2152 | | 2-d cone in 2-d lattice N] |
| 2136 | [2-d cone in 2-d lattice N, |
| 2137 | 0-d face of 2-d cone in 2-d lattice N] |
2153 | 2138 | |
2154 | 2139 | However, you can achieve some of this functionality using |
2155 | 2140 | :meth:`facets`, :meth:`facet_of`, and :meth:`adjacent` methods:: |
… |
… |
|
2188 | 2173 | 0-d face of 4-d cone in 4-d lattice N |
2189 | 2174 | sage: cone.face_lattice().top() |
2190 | 2175 | 3-d face of 4-d cone in 4-d lattice N |
2191 | | sage: cone.face_lattice().top().element == cone |
| 2176 | sage: cone.face_lattice().top() == cone |
2192 | 2177 | True |
2193 | 2178 | |
2194 | 2179 | TESTS:: |
… |
… |
|
2265 | 2250 | allowed_indices = frozenset(self._ambient_ray_indices) |
2266 | 2251 | L = DiGraph() |
2267 | 2252 | origin = \ |
2268 | | self._ambient._face_lattice_function().bottom().element |
| 2253 | self._ambient._face_lattice_function().bottom() |
2269 | 2254 | L.add_vertex(0) # In case it is the only one |
2270 | 2255 | dfaces = [origin] |
2271 | 2256 | faces = [origin] |
… |
… |
|
2420 | 2405 | "dimension and codimension cannot be specified together!") |
2421 | 2406 | dim = self.dim() - codim if codim is not None else dim |
2422 | 2407 | if "_faces" not in self.__dict__: |
2423 | | self._faces = tuple(self._sort_faces(e.element for e in level) |
| 2408 | self._faces = tuple(self._sort_faces(iter(level)) |
2424 | 2409 | for level in self.face_lattice().level_sets()) |
2425 | 2410 | # To avoid duplication and ensure order consistency |
2426 | 2411 | if len(self._faces) > 1: |
… |
… |
|
2565 | 2550 | if "_facet_of" not in self.__dict__: |
2566 | 2551 | L = self._ambient._face_lattice_function() |
2567 | 2552 | H = L.hasse_diagram() |
2568 | | self._facet_of = self._sort_faces(f.element |
2569 | | for f in H.neighbors_out(L(self)) if is_Cone(f.element)) |
| 2553 | self._facet_of = self._sort_faces(f |
| 2554 | for f in H.neighbors_out(L(self)) if is_Cone(f)) |
2570 | 2555 | return self._facet_of |
2571 | 2556 | |
2572 | 2557 | def facets(self): |
… |
… |
|
2587 | 2572 | if "_facets" not in self.__dict__: |
2588 | 2573 | L = self._ambient._face_lattice_function() |
2589 | 2574 | H = L.hasse_diagram() |
2590 | | self._facets = self._sort_faces(tuple( |
2591 | | f.element for f in H.neighbors_in(L(self)))) |
| 2575 | self._facets = self._sort_faces(tuple(H.neighbors_in(L(self)))) |
2592 | 2576 | return self._facets |
2593 | 2577 | |
2594 | 2578 | def intersection(self, other): |
… |
… |
|
3607 | 3591 | sage: rho = Cone([(1,1,1,3),(1,-1,1,3),(-1,-1,1,3),(-1,1,1,3)]) |
3608 | 3592 | sage: rho.orthogonal_sublattice() |
3609 | 3593 | Sublattice <M(0, 0, 3, -1)> |
3610 | | sage: sigma = rho.facets()[1] |
| 3594 | sage: sigma = rho.facets()[2] |
3611 | 3595 | sage: sigma.orthogonal_sublattice() |
3612 | 3596 | Sublattice <M(0, 1, 1, 0), M(0, 3, 0, 1)> |
3613 | 3597 | sage: sigma.is_face_of(rho) |
diff --git a/sage/geometry/fan.py b/sage/geometry/fan.py
a
|
b
|
|
156 | 156 | sage: cone |
157 | 157 | 2-d cone of Rational polyhedral fan in 3-d lattice N |
158 | 158 | sage: L.hasse_diagram().neighbors(cone) |
159 | | [3-d cone of Rational polyhedral fan in 3-d lattice N, |
| 159 | [1-d cone of Rational polyhedral fan in 3-d lattice N, |
160 | 160 | 3-d cone of Rational polyhedral fan in 3-d lattice N, |
161 | 161 | 1-d cone of Rational polyhedral fan in 3-d lattice N, |
162 | | 1-d cone of Rational polyhedral fan in 3-d lattice N] |
163 | | |
164 | | Note, that while ``cone`` above seems to be a "cone", it is not:: |
165 | | |
166 | | sage: cone.rays() |
167 | | Traceback (most recent call last): |
168 | | ... |
169 | | AttributeError: 'FinitePoset_with_category.element_class' object |
170 | | has no attribute 'rays' |
171 | | |
172 | | To get your hands on the "real" cone, you need to do one more step:: |
173 | | |
174 | | sage: cone = cone.element |
175 | | sage: cone.rays() |
176 | | N(1, 0, 0), |
177 | | N(0, 1, 0) |
178 | | in 3-d lattice N |
| 162 | 3-d cone of Rational polyhedral fan in 3-d lattice N] |
179 | 163 | |
180 | 164 | You can check how "good" a fan is:: |
181 | 165 | |
… |
… |
|
1313 | 1297 | L_cone = Cone(cone.rays(), lattice=self.lattice(), |
1314 | 1298 | check=False, normalize=False).face_lattice() |
1315 | 1299 | for f in L_cone: |
1316 | | f = f.element |
1317 | 1300 | f_rays = tuple(cone.ambient_ray_indices()[ray] |
1318 | 1301 | for ray in f.ambient_ray_indices()) |
1319 | 1302 | face_to_rays[f] = f_rays |
… |
… |
|
1327 | 1310 | index_to_cones.append([i]) |
1328 | 1311 | # Add all relations between faces of cone to L |
1329 | 1312 | for f,g in L_cone.cover_relations_iterator(): |
1330 | | L.add_edge(rays_to_index[face_to_rays[f.element]], |
1331 | | rays_to_index[face_to_rays[g.element]]) |
| 1313 | L.add_edge(rays_to_index[face_to_rays[f]], |
| 1314 | rays_to_index[face_to_rays[g]]) |
1332 | 1315 | # Add the inclusion of cone into the fan itself |
1333 | 1316 | L.add_edge( |
1334 | | rays_to_index[face_to_rays[L_cone.top().element]], 0) |
| 1317 | rays_to_index[face_to_rays[L_cone.top()]], 0) |
1335 | 1318 | |
1336 | 1319 | # Enumeration of graph vertices must be a linear extension of the |
1337 | 1320 | # poset |
… |
… |
|
1891 | 1874 | largest face, you should be a little bit careful with this last |
1892 | 1875 | element:: |
1893 | 1876 | |
1894 | | sage: for face in L: print face.element.ambient_ray_indices() |
| 1877 | sage: for face in L: print face.ambient_ray_indices() |
1895 | 1878 | Traceback (most recent call last): |
1896 | 1879 | ... |
1897 | 1880 | AttributeError: 'RationalPolyhedralFan' |
… |
… |
|
1902 | 1885 | For example, you can do :: |
1903 | 1886 | |
1904 | 1887 | sage: for l in L.level_sets()[:-1]: |
1905 | | ... print [f.element.ambient_ray_indices() for f in l] |
| 1888 | ... print [f.ambient_ray_indices() for f in l] |
1906 | 1889 | [()] |
1907 | 1890 | [(0,), (1,), (2,)] |
1908 | 1891 | [(0, 1)] |
… |
… |
|
1914 | 1897 | sage: fan = FaceFan(lattice_polytope.octahedron(2)) |
1915 | 1898 | sage: L = fan.cone_lattice() |
1916 | 1899 | sage: for l in L.level_sets()[:-1]: |
1917 | | ... print [f.element.ambient_ray_indices() for f in l] |
| 1900 | ... print [f.ambient_ray_indices() for f in l] |
1918 | 1901 | [()] |
1919 | 1902 | [(0,), (1,), (2,), (3,)] |
1920 | 1903 | [(0, 1), (1, 2), (0, 3), (2, 3)] |
… |
… |
|
2002 | 1985 | (2-d cone of Rational polyhedral fan in 2-d lattice N,) |
2003 | 1986 | |
2004 | 1987 | You cannot specify both dimension and codimension, even if they |
2005 | | "agree":: |
| 1988 | 'agree':: |
2006 | 1989 | |
2007 | 1990 | sage: fan(dim=1, codim=1) |
2008 | 1991 | Traceback (most recent call last): |
… |
… |
|
2020 | 2003 | () |
2021 | 2004 | """ |
2022 | 2005 | if "_cones" not in self.__dict__: |
2023 | | levels = [(e.element for e in level) # Generators |
2024 | | for level in self.cone_lattice().level_sets()] |
| 2006 | levels = map(iter,self.cone_lattice().level_sets()) # generators |
| 2007 | |
2025 | 2008 | levels.pop() # The very last level is this FAN, not cone. |
2026 | 2009 | # It seems that there is no reason to believe that the order of |
2027 | 2010 | # faces in level sets has anything to do with the order of |
diff --git a/sage/geometry/polyhedron/base.py b/sage/geometry/polyhedron/base.py
a
|
b
|
|
239 | 239 | |
240 | 240 | face_lattice = self.face_lattice() |
241 | 241 | for face in face_lattice: |
242 | | Hrep = face.element.ambient_Hrepresentation() |
| 242 | Hrep = face.ambient_Hrepresentation() |
243 | 243 | if len(Hrep) == 2: |
244 | 244 | set_adjacent(Hrep[0], Hrep[1]) |
245 | 245 | return M |
… |
… |
|
2297 | 2297 | sage: list(_) |
2298 | 2298 | [<>, <0>, <1>, <2>, <3>, <0,1>, <0,2>, <2,3>, <1,3>, <0,1,2,3>] |
2299 | 2299 | sage: poset_element = _[6] |
2300 | | sage: a_face = poset_element.element |
| 2300 | sage: a_face = poset_element |
2301 | 2301 | sage: a_face |
2302 | 2302 | <0,2> |
2303 | 2303 | sage: a_face.dim() |
… |
… |
|
2322 | 2322 | face in the face lattice:: |
2323 | 2323 | |
2324 | 2324 | sage: line = Polyhedron(vertices=[(0,)], lines=[(1,)]) |
2325 | | sage: [ fl.element.dim() for fl in line.face_lattice() ] |
| 2325 | sage: [ fl.dim() for fl in line.face_lattice() ] |
2326 | 2326 | [-1, 1] |
2327 | 2327 | |
2328 | 2328 | TESTS:: |