Skip to content

De Morgan's Laws

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Simplifies conditional logic using De Morgan’s laws

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 laws to simplify code by removing double negatives or pushing negations deeper into statements.