Module complementation
source code
Given a machine machine which recognizes a regular
language L, return another machine, complement,
which recognizes the complement of L. The complement language C of a
language L is defined as
C = { s | s ∉ L and s ∈ Σ* }
where Σ is the alphabet for L. So the alphabet over which L and
its complement C are defined is the same.
The following should be true, if M1 is set to the sheep language
machine.
>>> C = complement_machine (M1)
>>> simple_det_recognize(C,'baa!')
False
>>> simple_det_recognize(C,'baa')
True
>>> simple_det_recognize(C,'ba')
True
>>> simple_det_recognize(C,'b')
True
>>> simple_det_recognize(C,'')
True
>>> simple_det_recognize(C,'a')
True
>>> simple_det_recognize(C,'baaaaaa!')
False
>>> simple_det_recognize(C,'aaaaaa!')
True
>>> simple_det_recognize(C,'aaaaad!')
False
|
machine
|
complement_machine(machine)
Given machine, an FSA defining a regular language L,
return an FSA defining the complement of L (same alphabet). |
source code
|
|
|
|
M1 = ('ab!', [{'b': 1}, {'a': 2}, {'a': 3}, {'!': 4, 'a': 3}, ...
|
|
|
finals1 = (4)
|
|
|
table1 = [{'b': 1}, {'a': 2}, {'a': 3}, {'!': 4, 'a': 3}, {}]
|
|
Given machine, an FSA defining a regular language L,
return an FSA defining the complement of L (same alphabet).
- Parameters:
machine (Machine) - The machine defining L
- Returns: machine
|
M1
- Value:
('ab!', [{'b': 1}, {'a': 2}, {'a': 3}, {'!': 4, 'a': 3}, {}], (4))
|
|