/// <summary> /// Returns a (deterministic) automaton that accepts the intersection of the /// language of <paramref name="a1"/> and the complement of the language of /// <paramref name="a2"/>. As a side-effect, the automata may be determinized, if not /// already deterministic. /// <para/> /// Complexity: quadratic in number of states (if already deterministic). /// </summary> public static Automaton Minus(Automaton a1, Automaton a2) { if (BasicOperations.IsEmpty(a1) || a1 == a2) { return(BasicAutomata.MakeEmpty()); } if (BasicOperations.IsEmpty(a2)) { return(a1.CloneIfRequired()); } if (a1.IsSingleton) { if (BasicOperations.Run(a2, a1.singleton)) { return(BasicAutomata.MakeEmpty()); } else { return(a1.CloneIfRequired()); } } return(Intersection(a1, a2.Complement())); }