diff --git a/DFA.fs b/DFA.fs index 3f662dd..1717209 100644 --- a/DFA.fs +++ b/DFA.fs @@ -69,4 +69,14 @@ let rec processCharArray (dfa: DFA) (state: String) (charArr: Char list) = /// Returns whether the DFA accepts this word let acceptsWord (dfa: DFA) (word: String) = dfa.acceptingStates - |> List.contains (processCharArray dfa dfa.beginState (Seq.toList word)) \ No newline at end of file + |> List.contains (processCharArray dfa dfa.beginState (Seq.toList word)) + +let complement (dfa: DFA) : DFA = + { + sigma = dfa.sigma; + states = dfa.states; + delta = dfa.delta; + beginState = dfa.beginState; + acceptingStates = dfa.states + |> List.filter (fun x -> not (List.contains x dfa.acceptingStates)) + }