summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2023-11-05 11:36:00 +0100
committerNao Pross <np@0hm.ch>2023-11-05 11:36:00 +0100
commitd4f2e37c5b0a6541c2b253ac46b6f2c56c0eef86 (patch)
tree395ab4e139f28dd67b549fa318d09173fe901300
parentFix (new) bug in MyFiniteSetProduct to pass TestFiniteMapRepresentation (diff)
downloadact4e-d4f2e37c5b0a6541c2b253ac46b6f2c56c0eef86.tar.gz
act4e-d4f2e37c5b0a6541c2b253ac46b6f2c56c0eef86.zip
Pass TestFiniteMonotoneMapProperties
Diffstat (limited to '')
-rw-r--r--Homeworks.md4
-rw-r--r--src/act4e_solutions/posets_bounds.py10
-rw-r--r--src/act4e_solutions/posets_map.py13
3 files changed, 22 insertions, 5 deletions
diff --git a/Homeworks.md b/Homeworks.md
index 1aefcb4..f730c5f 100644
--- a/Homeworks.md
+++ b/Homeworks.md
@@ -44,11 +44,11 @@ $ make docker-check
- [?] TestFinitePosetMeasurement
- [X] TestFinitePosetConstructionProduct
- [?] TestFinitePosetConstructionSum
-- [?] TestFinitePosetConstructionOpposite
+- [X] TestFinitePosetConstructionOpposite
- [?] TestFinitePosetConstructionTwisted
- [?] TestFinitePosetConstructionArrow
-- [ ] TestFiniteMonotoneMapProperties
+- [X] TestFiniteMonotoneMapProperties
## Exercises for Nov. 20
diff --git a/src/act4e_solutions/posets_bounds.py b/src/act4e_solutions/posets_bounds.py
index c1c6310..05f818f 100644
--- a/src/act4e_solutions/posets_bounds.py
+++ b/src/act4e_solutions/posets_bounds.py
@@ -2,6 +2,8 @@ from typing import Any, List, Optional, overload, TypeVar
from itertools import product
from functools import cmp_to_key
+from .posets_representation import MyFinitePoset
+
import act4e_interfaces as I
E = TypeVar("E")
@@ -17,7 +19,13 @@ class SolFinitePosetMeasurement(I.FinitePosetMeasurement):
class SolFinitePosetConstructionOpposite(I.FinitePosetConstructionOpposite):
def opposite(self, p: I.FinitePoset[X]) -> I.FinitePoset[X]:
- raise NotImplementedError() # implement here
+ e = p.carrier().elements()
+ values = []
+ for a, b in product(e, e):
+ if p.holds(a, b):
+ # then the opposite holds(b, a)
+ values.append((b, a))
+ return MyFinitePoset(p.carrier(), values)
class SolFinitePosetSubsetProperties(I.FinitePosetSubsetProperties):
diff --git a/src/act4e_solutions/posets_map.py b/src/act4e_solutions/posets_map.py
index a91d4d8..8d28c62 100644
--- a/src/act4e_solutions/posets_map.py
+++ b/src/act4e_solutions/posets_map.py
@@ -1,5 +1,8 @@
from typing import TypeVar
+from itertools import product
+from .posets_bounds import SolFinitePosetConstructionOpposite
+
import act4e_interfaces as I
A = TypeVar("A")
@@ -9,7 +12,13 @@ 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:
- raise NotImplementedError()
+ 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:
- raise NotImplementedError()
+ opp = SolFinitePosetConstructionOpposite()
+ return self.is_monotone(opp.opposite(p1), p2, m)