com.bpodgursky.jbool_expressions.example.ExampleRunner Maven / Gradle / Ivy
package com.bpodgursky.jbool_expressions.example;
import com.bpodgursky.jbool_expressions.*;
import com.bpodgursky.jbool_expressions.parsers.ExprParser;
import com.bpodgursky.jbool_expressions.rules.RuleSet;
import java.util.Collections;
public class ExampleRunner {
public static void main(String[] args) {
Expression expr = And.of(Variable.of("A"),
Variable.of("B"),
Or.of(Variable.of("C"), Not.of(Variable.of("C"))));
System.out.println(expr);
// ((!C | C) & A & B)
Expression simplified = RuleSet.simplify(expr);
System.out.println(simplified);
// (A & B)
Expression halfAssigned = RuleSet.assign(simplified, Collections.singletonMap("A", true));
System.out.println(halfAssigned);
// B
Expression resolved = RuleSet.assign(halfAssigned, Collections.singletonMap("B", true));
System.out.println(resolved);
// true
System.out.println(expr);
// ((!C | C) & A & B)
Expression parsedExpression = RuleSet.simplify(ExprParser.parse("( ( (! C) | C) & A & B)"));
System.out.println(parsedExpression);
System.out.println(parsedExpression.equals(simplified));
// (A & B)
// true
Expression nonStandard = ExprParser.parse("( ( A | B) & ( C | D))");
System.out.println(nonStandard);
// ((A | B) & (C | D))
Expression sopForm = RuleSet.toSop(nonStandard);
System.out.println(sopForm);
// ((A & C) | (A & D) | (B & C) | (B & D))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy