Skip to content

De Morgan Identity

Sourcery refactoring id: de-morgan


Simplifies conditional logic using De Morgan's Identity


if not not p:
    a = 1
if not a is b:
    a = 1
if not (p == 1 and q == 2):
    a = 1


if p:
    a = 1
if a is not b:
    a = 1
if p != 1 or q != 2:
    a = 1


When reading logical statements it is important for them to be as simple as possible. This proposal applies De Morgan's identity to simplify code by removing double negatives or pushing negations deeper into statements.

Back to top