Skip to content

Commit

Permalink
Trac #15875: Add is_induced_subposet
Browse files Browse the repository at this point in the history
Add `is_induced_subposet()` method to Posets to check if a subposet is
an (induced) subposet of another.

URL: http://trac.sagemath.org/15875
Reported by: csar
Ticket author(s): Jori Mäntysalo
Reviewer(s): Travis Scrimshaw, Nathann Cohen
  • Loading branch information
Release Manager authored and vbraun committed Oct 28, 2015
2 parents 670bde4 + c7db822 commit c6faddc
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion src/sage/combinat/posets/posets.py
Expand Up @@ -140,6 +140,7 @@
:delim: |
:meth:`~FinitePoset.is_isomorphic` | Return ``True`` if both posets are isomorphic.
:meth:`~FinitePoset.is_induced_subposet` | Return ``True`` if given poset is an induced subposet of this poset.
**Polynomials**
Expand Down Expand Up @@ -3494,7 +3495,7 @@ def dilworth_decomposition(self):
union of chains.
According to Dilworth's theorem, the number of chains is equal to
`\alpha` (the posets' width).
`\alpha` (the posets' width).
EXAMPLES::
Expand Down Expand Up @@ -5883,6 +5884,64 @@ def kazhdan_lusztig_polynomial(self, x=None, y=None, q=None, canonical_labels=No
poly = self._kl_poly(x, y, canonical_labels)
return poly(q=q)

def is_induced_subposet(self, other):
r"""
Return ``True`` if the poset is an induced subposet of ``other``, and
``False`` otherwise.
A poset `P` is an induced subposet of `Q` if every element
of `P` is an element of `Q`, and `x \le_P y` iff `x \le_Q y`.
Note that "induced" here has somewhat different meaning compared
to that of graphs.
INPUT:
- ``other``, a poset.
.. NOTE::
This method does not check whether the poset is a
*isomorphic* (i.e., up to relabeling) subposet of ``other``,
but only if ``other`` directly contains the poset as an
induced subposet. For isomorphic subposets see
:meth:`has_isomorphic_subposet`.
EXAMPLES::
sage: P = Poset({1:[2, 3]})
sage: Q = Poset({1:[2, 4], 2:[3]})
sage: P.is_induced_subposet(Q)
False
sage: R = Poset({0:[1], 1:[3, 4], 3:[5], 4:[2]})
sage: P.is_induced_subposet(R)
True
TESTS::
sage: P = Poset({2:[1]})
sage: Poset().is_induced_subposet(P)
True
sage: Poset().is_induced_subposet(Poset())
True
sage: P.is_induced_subposet(Poset())
False
Bad input::
sage: Poset().is_induced_subposet('junk')
Traceback (most recent call last):
...
AttributeError: 'str' object has no attribute 'subposet'
"""
if (not self._is_facade or
(isinstance(other, FinitePoset) and not other._is_facade)):
raise TypeError('the function is not defined on non-facade posets')
# TODO: When we have decided if
# Poset({'x':[42]}) == LatticePoset({'x':[42]})
# or not, either remove this note or remove .hasse_diagram() below.
return (set(self).issubset(set(other)) and
other.subposet(self).hasse_diagram() == self.hasse_diagram())

FinitePoset._dual_class = FinitePoset

##### Posets #####
Expand Down

0 comments on commit c6faddc

Please sign in to comment.