def check_coproduct_embedding2(): """ A + B == A + B """ A = FinitePoset(set(['a1', 'a2', 'a3']), []) B = FinitePoset(set(['b1', 'b2']), []) P1 = PosetCoproduct((A, B)) P2 = PosetCoproduct((A, B)) tu = get_types_universe() tu.check_equal(P1, P2) tu.check_leq(P1, P2) tu.check_leq(P2, P1)
def check_coproduct_embedding3(): """ A + B != B + A, but A + B ~= B + A """ A = FinitePoset(set(['a1', 'a2', 'a3']), []) B = FinitePoset(set(['b1', 'b2']), []) P1 = PosetCoproduct((A, B)) P2 = PosetCoproduct((B, A)) tu = get_types_universe() tu.check_leq(P1, P2) tu.check_leq(P2, P1) A_to_B1, B_to_A1 = tu.get_embedding(A, B) # @UnusedVariable B_to_A2, A_to_B2 = tu.get_embedding(B, A) # @UnusedVariable
def check_coproduct_embedding1(): A = FinitePoset(set(['a1', 'a2', 'a3']), []) B = FinitePoset(set(['b1', 'b2']), []) P = PosetCoproduct((A, B)) a = 'a1' A.belongs(a) p = express_value_in_isomorphic_space(A, a, P) # a2 = express_value_in_isomorphic_space(P, p, A) # A.belongs(a2) print p
def eval_space_finite_poset(r, context): # @UnusedVariable if r.keyword.keyword == 'finite_poset': # pragma: no cover msg ='We now prefer "poset" to "finite_poset".' warn_language(r.keyword, MCDPWarnings.LANGUAGE_CONSTRUCT_DEPRECATED, msg, context) chains = unwrap_list(r.chains) universe = set() relations = set() for c in chains: check_isinstance(c, (CDP.FinitePosetChainLEQ, CDP.FinitePosetChainGEQ)) allops = unwrap_list(c.ops) ops = get_odd_ops(allops) elements = [_.identifier for _ in ops] if len(elements) == 1: e = elements[0] if e in universe: msg = 'Repeated element %r.' % e raise DPSemanticError(msg, where=allops[0].where) universe.update(elements) if isinstance(c, CDP.FinitePosetChainLEQ): leq = True elif isinstance(c, CDP.FinitePosetChainGEQ): leq = False else: assert False for a, b in zip(elements, elements[1:]): if leq: relations.add((a, b)) else: relations.add((b, a)) return FinitePoset(universe=universe, relations=relations)
def eval_space_addbottom(r, context): check_isinstance(r, CDP.AddBottom) poset = eval_space(r.poset, context) if not isinstance(poset, FinitePoset): msg = 'You can use add_bottom only on a FinitePoset.' raise_desc(DPSemanticError, msg, where=r.keyword.where) elements = poset.elements relations = poset.relations bot = '⊥' if bot in elements: msg = 'Poset already has the "%s" element.' % bot raise DPSemanticError(msg, where=r.where) elements2 = set() elements2.update(elements) elements2.add(bot) relations2 = set() relations2.update(relations) for e in elements: relations2.add((bot, e)) fp = FinitePoset(elements2, relations2) return fp
def eval_space_single_element_poset(r, context): # @UnusedVariable assert isinstance(r, CDP.SingleElementPoset) tag = r.tag.value universe = set([tag]) return FinitePoset(universe=universe, relations=[])
def check_lang_singlespace2(): P = parse_poset('S(singleton)') assert P == FinitePoset(set(['singleton']), []) c = parse_constant('S(singleton):*') assert c.value == 'singleton'