diff --git a/spot/tl/contain.cc b/spot/tl/contain.cc index a977edb35..f787c9906 100644 --- a/spot/tl/contain.cc +++ b/spot/tl/contain.cc @@ -24,6 +24,7 @@ #include #include #include +#include namespace spot { @@ -104,6 +105,12 @@ namespace spot bool language_containment_checker::equal(formula l, formula g) { + if (l == g) + return true; + record_* rl = register_formula_(l); + record_* rg = register_formula_(g); + if (isomorphism_checker::are_isomorphic(rl->translation, rg->translation)) + return true; return contained(l, g) && contained(g, l); } diff --git a/spot/twaalgos/are_isomorphic.cc b/spot/twaalgos/are_isomorphic.cc index a53106fa0..751f804a3 100644 --- a/spot/twaalgos/are_isomorphic.cc +++ b/spot/twaalgos/are_isomorphic.cc @@ -123,29 +123,40 @@ namespace spot } bool - isomorphism_checker::is_isomorphic(const const_twa_graph_ptr aut) + isomorphism_checker::is_isomorphic_(const const_twa_graph_ptr aut) { - if (trivially_different(ref_, aut)) - return false; - + bool autdet = aut->prop_deterministic(); if (ref_deterministic_) { - if (aut->prop_deterministic() || spot::is_deterministic(aut)) - { - return are_isomorphic_det(ref_, aut); - } + if (autdet || spot::is_deterministic(aut)) + return are_isomorphic_det(ref_, aut); } else { - if (aut->prop_deterministic() || - nondet_states_ != spot::count_nondet_states(aut)) - { - return false; - } + if (autdet || nondet_states_ != spot::count_nondet_states(aut)) + return false; } auto tmp = make_twa_graph(aut, twa::prop_set::all()); spot::canonicalize(tmp); return *tmp == *ref_; } + + bool + isomorphism_checker::is_isomorphic(const const_twa_graph_ptr aut) + { + if (trivially_different(ref_, aut)) + return false; + return is_isomorphic_(aut); + } + + bool + isomorphism_checker::are_isomorphic(const const_twa_graph_ptr ref, + const const_twa_graph_ptr aut) + { + if (trivially_different(ref, aut)) + return false; + isomorphism_checker c(ref); + return c.is_isomorphic_(aut); + } } diff --git a/spot/twaalgos/are_isomorphic.hh b/spot/twaalgos/are_isomorphic.hh index f9f25eb7a..cb48d03da 100644 --- a/spot/twaalgos/are_isomorphic.hh +++ b/spot/twaalgos/are_isomorphic.hh @@ -25,7 +25,7 @@ namespace spot { /// Check if two automata are isomorphic. - class SPOT_API isomorphism_checker + class SPOT_API isomorphism_checker final { public: isomorphism_checker(const const_twa_graph_ptr ref); @@ -45,7 +45,14 @@ namespace spot bool is_isomorphic(const const_twa_graph_ptr aut); + + /// \ingroup twa_misc + /// \brief Check whether two automata are isomorphic. + static bool are_isomorphic(const const_twa_graph_ptr ref, + const const_twa_graph_ptr aut); + private: + bool is_isomorphic_(const const_twa_graph_ptr aut); twa_graph_ptr ref_; bool ref_deterministic_ = false; unsigned nondet_states_ = 0;