Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Boolean Literal Simplification to Conjunction & Disjunction
  • Loading branch information
rcosta358 committed Nov 13, 2025
commit 17c1d65a5bcdc9fa651abfb082a8b5945f9a9841
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,25 @@ public ValDerivationNode simplify() {
return ExpressionSimplifier.simplify(exp.clone());
}

private static boolean isBooleanLiteral(Expression expr, boolean value) {
return expr instanceof LiteralBoolean && ((LiteralBoolean) expr).isBooleanTrue() == value;
}

public static Predicate createConjunction(Predicate c1, Predicate c2) {
// simplification: (true && x) = x, (false && x) = false
if (isBooleanLiteral(c1.getExpression(), true)) return c2;
if (isBooleanLiteral(c2.getExpression(), true)) return c1;
if (isBooleanLiteral(c1.getExpression(), false)) return c1;
if (isBooleanLiteral(c2.getExpression(), false)) return c2;
return new Predicate(new BinaryExpression(c1.getExpression(), Ops.AND, c2.getExpression()));
}

public static Predicate createDisjunction(Predicate c1, Predicate c2) {
// simplification: (false || x) = x, (true || x) = true
if (isBooleanLiteral(c1.getExpression(), false)) return c2;
if (isBooleanLiteral(c2.getExpression(), false)) return c1;
if (isBooleanLiteral(c1.getExpression(), true)) return c1;
if (isBooleanLiteral(c2.getExpression(), true)) return c2;
return new Predicate(new BinaryExpression(c1.getExpression(), Ops.OR, c2.getExpression()));
}

Expand Down