0

Is there any open source Java Library or java source code to simplify Boolean expression like

!((A.B+C).(!A+BC))

Where,

! - represents NOT
+ - represents OR
. - represents AND

Your help would be greatly appreciated in this regard

Sirko
  • 72,589
  • 19
  • 149
  • 183
Farman Khan
  • 393
  • 1
  • 6
  • 14
  • 1
    possible duplicate of [Simplify boolean expression algorithm](http://stackoverflow.com/questions/5311099/simplify-boolean-expression-algorithm) – assylias Jun 29 '12 at 11:08
  • See also http://stackoverflow.com/questions/5104207/simplification-of-boolean-expression-in-java and http://stackoverflow.com/questions/767437/tool-to-refactor-boolean-expressions – assylias Jun 29 '12 at 11:09
  • I wouldn't say that's a dupe because in this case the input material is not a valid boolean expression – Sean Patrick Floyd Jun 29 '12 at 11:13

4 Answers4

1

No, I don't think so, but it should be pretty simple to write a parser for such a language using ANTLR (declarative) or JParsec (programmatic)

For ANTLR, use the First Order Logic Grammar as starting point.

For JParsec, the JParceC calculator tutorial gets close to what you need.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
1

Smells like SQL? You could trivialy translate the !,.,+ into NOT, AND, OR, filter out certain magic keywords, then pass them on to a traditional JDBC back-end. "SELECT 1 WHERE " + expression

Otherwise, it sounds like you need a full logical AST+parser (antlr), since simply constructing a DOM representing the expression isn't going to be terribly useful (and consequently, there aren't that many tools that generally take an expression object-graph and apply generic axioms).. There are some HIGHLY specialized variants of this - lookup rule engines like drools. But I'm guessing that isn't doing exactly what you want.

M. Maraist
  • 432
  • 4
  • 7
0

I am not aware of any API in java. However, you can split your expression and build a predicates for each part. You might be interested to take a look on this

aviad
  • 8,229
  • 9
  • 50
  • 98
0

First of all let me confirm if I get your question correctly - are you looking at ability to code the given expression in simplified manner?

If yes then you can try Xtend : http://eclipse.org/xtend/ and Xtext http://www.eclipse.org/Xtext/

Xtend is a statically-typed programming language which compiles to comprehensible Java source code. Xtend is developed using Xtext.

Xtext is a framework for development of programming languages and domain specific languages.

Above info is not applicable if you are looking at algorithm to simply the given expression.

Hope the information is useful to you.

Rutesh Makhijani
  • 17,065
  • 2
  • 26
  • 22