diff --git a/bindings/python/libmata/nfa/nfa.pxd b/bindings/python/libmata/nfa/nfa.pxd index 674829971..b484dcab8 100644 --- a/bindings/python/libmata/nfa/nfa.pxd +++ b/bindings/python/libmata/nfa/nfa.pxd @@ -196,7 +196,7 @@ cdef extern from "mata/nfa/plumbing.hh" namespace "mata::nfa::plumbing": cdef void get_elements(StateSet*, CBoolVector) cdef void c_determinize "mata::nfa::plumbing::determinize" (CNfa*, CNfa&, umap[StateSet, State]*) cdef void c_uni "mata::nfa::plumbing::uni" (CNfa*, CNfa&, CNfa&) - cdef void c_intersection "mata::nfa::plumbing::intersection" (CNfa*, CNfa&, CNfa&, bool, umap[pair[State, State], State]*) + cdef void c_intersection "mata::nfa::plumbing::intersection" (CNfa*, CNfa&, CNfa&, Symbol, umap[pair[State, State], State]*) cdef void c_concatenate "mata::nfa::plumbing::concatenate" (CNfa*, CNfa&, CNfa&, bool, StateRenaming*, StateRenaming*) cdef void c_complement "mata::nfa::plumbing::complement" (CNfa*, CNfa&, CAlphabet&, ParameterMap&) except + cdef void c_revert "mata::nfa::plumbing::revert" (CNfa*, CNfa&) diff --git a/bindings/python/libmata/nfa/nfa.pyx b/bindings/python/libmata/nfa/nfa.pyx index 941e2fc89..f000087be 100644 --- a/bindings/python/libmata/nfa/nfa.pyx +++ b/bindings/python/libmata/nfa/nfa.pyx @@ -815,7 +815,7 @@ def union(Nfa lhs, Nfa rhs): ) return result -def intersection(Nfa lhs, Nfa rhs, preserve_epsilon: bool = False): +def intersection(Nfa lhs, Nfa rhs, Symbol first_epsilon = CEPSILON): """Performs intersection of lhs and rhs. Supports epsilon symbols when preserve_epsilon is set to True. @@ -827,18 +827,18 @@ def intersection(Nfa lhs, Nfa rhs, preserve_epsilon: bool = False): Automata must share alphabets. - :param preserve_epsilon: Whether to compute intersection preserving epsilon transitions. :param Nfa lhs: First automaton. :param Nfa rhs: Second automaton. + :param Symbol first_epsilon: the smallest epsilon. :return: Intersection of lhs and rhs. """ result = Nfa() mata_nfa.c_intersection( - result.thisptr.get(), dereference(lhs.thisptr.get()), dereference(rhs.thisptr.get()), preserve_epsilon, NULL + result.thisptr.get(), dereference(lhs.thisptr.get()), dereference(rhs.thisptr.get()), first_epsilon, NULL ) return result -def intersection_with_product_map(Nfa lhs, Nfa rhs, preserve_epsilon: bool = False): +def intersection_with_product_map(Nfa lhs, Nfa rhs, Symbol first_epsilon = CEPSILON): """Performs intersection of lhs and rhs. Supports epsilon symbols when preserve_epsilon is set to True. @@ -858,9 +858,7 @@ def intersection_with_product_map(Nfa lhs, Nfa rhs, preserve_epsilon: bool = Fal result = Nfa() cdef umap[pair[State, State], State] c_product_map mata_nfa.c_intersection( - result.thisptr.get(), dereference(lhs.thisptr.get()), dereference(rhs.thisptr.get()), preserve_epsilon, - &c_product_map - ) + result.thisptr.get(), dereference(lhs.thisptr.get()), dereference(rhs.thisptr.get()), first_epsilon, &c_product_map) return result, {tuple(k): v for k, v in c_product_map} def concatenate(Nfa lhs, Nfa rhs, use_epsilon: bool = False) -> Nfa: diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 165bacf68..3e5b8a049 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -127,6 +127,7 @@ def get_version(): return version_handle.read().split()[0] else: version, _ = run_safely_external_command("git describe --tags --abbrev=0 HEAD") + print(version) assert re.match(r"\d+\.\d+\.\d+(.*)", version) return version.strip() diff --git a/bindings/python/tests/test_nfa.py b/bindings/python/tests/test_nfa.py index b7b237ea6..9a2a088b0 100644 --- a/bindings/python/tests/test_nfa.py +++ b/bindings/python/tests/test_nfa.py @@ -469,7 +469,7 @@ def test_intersection_preserving_epsilon_transitions(): b.add_transition(6, ord('a'), 9) b.add_transition(6, ord('b'), 7) - result, product_map = mata_nfa.intersection_with_product_map(a, b, True) + result, product_map = mata_nfa.intersection_with_product_map(a, b) # Check states. assert result.num_of_states() == 13 @@ -496,7 +496,7 @@ def test_intersection_preserving_epsilon_transitions(): assert len(result.final_states) == 4 # Check transitions. - assert result.get_num_of_transitions() == 15 + assert result.get_num_of_transitions() == 14 assert result.has_transition(product_map[(0, 0)], mata_nfa.epsilon(), product_map[(1, 0)]) assert len(result.get_trans_from_state_as_sequence(product_map[(0, 0)])) == 1 @@ -519,8 +519,8 @@ def test_intersection_preserving_epsilon_transitions(): assert result.has_transition(product_map[(2, 5)], mata_nfa.epsilon(), product_map[(3, 5)]) assert result.has_transition(product_map[(2, 5)], mata_nfa.epsilon(), product_map[(2, 6)]) - assert result.has_transition(product_map[(2, 5)], mata_nfa.epsilon(), product_map[(3, 6)]) - assert len(result.get_trans_from_state_as_sequence(product_map[(2, 5)])) == 3 + assert not result.has_transition(product_map[(2, 5)], mata_nfa.epsilon(), product_map[(3, 6)]) + assert len(result.get_trans_from_state_as_sequence(product_map[(2, 5)])) == 2 assert result.has_transition(product_map[(3, 5)], ord('a'), product_map[(5, 8)]) assert result.has_transition(product_map[(3, 5)], mata_nfa.epsilon(), product_map[(3, 6)]) diff --git a/include/mata/nfa/plumbing.hh b/include/mata/nfa/plumbing.hh index 35ad8c230..b42f4b48f 100644 --- a/include/mata/nfa/plumbing.hh +++ b/include/mata/nfa/plumbing.hh @@ -85,10 +85,10 @@ inline void uni(Nfa *unionAutomaton, const Nfa &lhs, const Nfa &rhs) { *unionAut * * Automata must share alphabets. */ -inline void intersection(Nfa* res, const Nfa& lhs, const Nfa& rhs, +inline void intersection(Nfa* res, const Nfa& lhs, const Nfa& rhs, Symbol first_epsilon = EPSILON, std::unordered_map, State> *prod_map = nullptr) { //TODO: first_epsilon should also be a parameter, optional parameter? - *res = intersection(lhs, rhs, EPSILON, prod_map); + *res = intersection(lhs, rhs, first_epsilon, prod_map); } /**