@@ -223,11 +223,25 @@ public ValDerivationNode simplify() {
223223 return ExpressionSimplifier .simplify (exp .clone ());
224224 }
225225
226+ private static boolean isBooleanLiteral (Expression expr , boolean value ) {
227+ return expr instanceof LiteralBoolean && ((LiteralBoolean ) expr ).isBooleanTrue () == value ;
228+ }
229+
226230 public static Predicate createConjunction (Predicate c1 , Predicate c2 ) {
231+ // simplification: (true && x) = x, (false && x) = false
232+ if (isBooleanLiteral (c1 .getExpression (), true )) return c2 ;
233+ if (isBooleanLiteral (c2 .getExpression (), true )) return c1 ;
234+ if (isBooleanLiteral (c1 .getExpression (), false )) return c1 ;
235+ if (isBooleanLiteral (c2 .getExpression (), false )) return c2 ;
227236 return new Predicate (new BinaryExpression (c1 .getExpression (), Ops .AND , c2 .getExpression ()));
228237 }
229238
230239 public static Predicate createDisjunction (Predicate c1 , Predicate c2 ) {
240+ // simplification: (false || x) = x, (true || x) = true
241+ if (isBooleanLiteral (c1 .getExpression (), false )) return c2 ;
242+ if (isBooleanLiteral (c2 .getExpression (), false )) return c1 ;
243+ if (isBooleanLiteral (c1 .getExpression (), true )) return c1 ;
244+ if (isBooleanLiteral (c2 .getExpression (), true )) return c2 ;
231245 return new Predicate (new BinaryExpression (c1 .getExpression (), Ops .OR , c2 .getExpression ()));
232246 }
233247
0 commit comments