3

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...

roccia
  • 179
  • 11
  • Well in the example you gave you just remove the `∨` and `∧` symbols and replace `¬` with `!`... easy... – Niet the Dark Absol Nov 06 '11 at 03:40
  • 1
    This question requires [tag:artificial-intelligence] in order to guess what the questioner _really_ wants to know. – A.H. Nov 06 '11 at 08:02
  • You have phrased your question badly. Your example doesn't make sense as an as an answer to the question posed. You will need to learn to write down a description of your problem more clearly, or you won't get useful answers. – Ira Baxter Nov 07 '11 at 01:00

2 Answers2

3

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.

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 1
    Would you mind re-reading my answer again? You need to *draw* the trees on paper for both and see how they look. And you have likely some kind of mistake in ((a (not b) ...) because you don't treat the contents of (...) consistently: at the top level, you are treating this as AND, at lower levels as OR; your operator is implicit in tree height. You can make that work but its unconventional because it is easy to forget that rule. I suggest you get the basics right on paper before you worry about coding in Java. – Ira Baxter Nov 06 '11 at 06:52
1

In java (assuming a, b, c and d are booleans):

¬ is equivalent to !

is equivalent to &&

is equivalent to ||

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417