How to represent CNF (a ∨ ¬b ∨ c) ∧ (¬a ∨ d) as a list or string in JAVA


For example (a ∨ ¬b ∨ c) ∧ (¬a ∨ d) to "(a !b c) (!a d)" or ((a (not b) c) ((not a) d))

I may not make my question clear.. I mean how can I elimiante ! && || by just using

((a (not b) c) ((not a) d)) instead of (a || !b || c) && (!a || d)

Sorry for the mistake..

Hope someone can give me an example or a link about this. Thanks...

Unicode has all these characters. You could simply store this as a character string, containing exactly the characters you show.

However, it isn't clear that's what you really want to know... the real question about "how to represent X" depends on what you want to do efficiently do with X.

If you don't have a computation that requires efficient processing, then pretty much any way to represent it is fine, including my Unicode suggestion above.

If the problem is "How can I evaluate this formula in nanoseconds given boolean values for a, b, c, d, the text solution is completely wrong. In the latter case, you probably want to represent it ultimately as a series of machine instructions that can be directly executed by a CPU.

There's lots of in between variations, with a popular one being Abstract Syntax Trees (AST), which are good at representing expressions. Such a tree has operator nodes containing operator types (not, and, or), leaf nodes representing variables a, b, c, d. Operator nodes are linked to children nodes, which may be other operators, or leaves; thus you build a tree. (List S-expressions are a funny way to write down such a tree).

You make AST nodes in Java by using classes that represent operators and operands. Operator nodes have members that are objects referring to other operator nodes or leaf nodes. You can see an example here: Java tree data-structure?

ASTs are useful for both doing medium speed analysis of the formula, and being a first step towards producing that machine code if needed.