Question

I have tried Javaluator which helped me in evaluating the expressions like (A OR B) AND C . But now I only want to expand the expression (A OR B) AND C to A AND C OR A AND B can any body tell me how can I do this in Java any API or any other help?

Was it helpful?

Solution

If you don't need to do it yourself, you may use Wolfram|Alpha API, it has a plenty of boolean-algebra-related features, like converting to various normal forms and so on. If that's a homework and you should invent your own wheel, you may use some parsing tools (or invent your wheel, again) to tokenize the string and then apply the set ob boolean algebra rules: http://mathworld.wolfram.com/BooleanAlgebra.html

I think I should make this more concrete - you can't solve this problem in general case without writing that set of rules in your code (hardcoding it). The most concise way is to use something like ANTLR to produce a boolean-rules-constrained language and then just feed your inputs to it.

OTHER TIPS

This is called The De Morgan rules. I think the best option is to use a Karnaugh Map to do this. This truth table generator will help you on your way.

(A OR B) AND C to A AND C OR A AND B

This is false.... (A or B) and C is equals to (a and c) or (B and C)........

If number of variables is not very big you may test expression for every set of variables. And if it's true on set A = true, B = false, C = true add to result OR (A and !B and C)

This form is called "Full disjunctive normal form"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top