summaryrefslogtreecommitdiffstats
path: root/src/act4e_solutions/posets_map.py
blob: 8d28c62f78298fa0b8676538cd4152909d0c6488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from typing import TypeVar

from itertools import product
from .posets_bounds import SolFinitePosetConstructionOpposite

import act4e_interfaces as I

A = TypeVar("A")
B = TypeVar("B")
X = TypeVar("X")


class SolFiniteMonotoneMapProperties(I.FiniteMonotoneMapProperties):
    def is_monotone(self, p1: I.FinitePoset[A], p2: I.FinitePoset[B], m: I.FiniteMap[A, B]) -> bool:
        A = p1.carrier().elements()
        for x, y in product(A, A):
            if p1.holds(x, y):
                if not p2.holds(m(x), m(y)):
                    return False
        return True

    def is_antitone(self, p1: I.FinitePoset[A], p2: I.FinitePoset[B], m: I.FiniteMap[A, B]) -> bool:
        opp = SolFinitePosetConstructionOpposite()
        return self.is_monotone(opp.opposite(p1), p2, m)