Optimization
py-predicate can optimize predicates in many ways.
For example:
from predicate import always_false_p, ge_p, optimize
ge_2 = ge_p(2)
lt_2 = ~ge_2
predicate = ge_2 & lt_2
# Optimize
optimized = optimize(predicate)
assert optimized == always_false_p
When visualized this looks like this:
digraph { graph [label="" labelloc=t] node [shape=rectangle] subgraph cluster_original { color=lightgrey style=filled label="Original predicate" and_0 [label="∧"] ge_1 [label="x ≥ 2"] ge_2 [label="x ≥ 2"] not_3 [label="¬"] not_3 -> ge_2 and_0 -> ge_1 and_0 -> not_3 } subgraph cluster_optimized { color=lightgrey style=filled label="Optimized predicate" F_4 [label=false] } }