Wolfram Alpha and Logic - NOR transformation - logic

i have some difficulties interpret some WolframAlpha logic.
I have this logical expression: !(a || b || c)
WA says, that it's minimal NOR-Form ist a NOR b NOR c.
But if you type it in, the truth tables are different.
However if you search for this (!a nor b) nor c
you'll get the correct answer.
Is this an WolframAlpha bug or do I just misinterpret the result?
Here are the links:
!(a || b || c) http://www.wolframalpha.com/input/?i=!%28a+||+b+||+c%29
a NOR b NOR c http://www.wolframalpha.com/input/?i=a+nor+b+nor+c
Thanks!

If we consider NOR as a binary operator, then we need to treat an expression like a NOR b NOR c as either (a NOR b) NOR c or a NOR (b NOR c). Either way, it's not the same as !(a || b || c). This is in fact how WA treats the formula when you ask it about a NOR b NOR c.
However, suppose we consider NOR as a “variable” arity operator, that takes any number of arguments. Thus we treat a NOR b NOR c as NOR(a, b, c), where the NOR function returns true if and only if all of its arguments are false. Then a NOR b NOR c is the same as !(a || b || c). This seems to be what WA thinks when you ask it about !(a || b || c).
It does seem like a bug in Wolfram Alpha that it uses different definitions of a NOR b NOR c in these two cases.

Related

Why are "not greater/less" (e.g. "!>" or "!<") operators not used in most programming languages

I understand that you can get the same behavior by using <= or !(x > y) but I usually rather think in terms of not greater instead of less than or equal, so having something like !> and !< would actually be really neat to have for me and would match the != operator perfectly.
The !(x > y) syntax requires more characters and reads: not: x is greater than y, which is unhandy and very unlike natural speech.
I have never seen !< or !> operators anywhere, but have been wondering ever since I started programming why they are not supported. Are there any reasons why not?
Using the least number of logical and comparison operators, and those the most closest to classic math and logic makes it simpler to reason about conditions.
There were programming languages like Natural and COBOL with operators like NOT LESS THAN, but reasoning about (a !< b) when thinking over a complex condition is much more difficult than !(a < b), which is equivalent to (a >= b).
An example:
!(!(a < b) && !(a > c))
Is equivalent to:
!((a >= b) && (a <= c))
which translates to:
(a < b) || (a > c)
There's nothing to gain from !((a !< b) && (a !> c))?

How to turn these expressions into Reverse Polish Notation?

I am working with Odoo 8 and I want to set a couple of domains. I thought I understood reverse Polish notation but domains are not working so I guess I am wrong.
The domains I want to achieve using reverse Polish notation are:
A and B and C and (D or (E and F)): I tried to implement it with the expression A B C or D E F, but it did not work.
A and B and (C or D or (E and F)): I tried to implement it with the expression A B or or C D E F, but it did work neither.
Note: I am not writing ANDs in domains (if you do not specify anything
in Odoo, it is supposed to use &).
My domains are wrong because I always get no record.
Can anyone help me, please?
I have the answer. Despite if you do not specify anything, Odoo takes an AND by default, you must write ANDs when there are expressions which must be executed before other and Odoo does not know which are because you have a complex and long expression.
In my cases, E and F must be executed before any other expression, so we cannot leave them without AND, so:
A and B and C and (D or (E and F)): The solution is A B C or D and E F.
A and B and (C or D or (E and F)): The solution is A B or or C D and E F.
In an XML domain in Odoo, these domains will be:
[A, B, C, '|', D, '&', E, F].
[A, B, '|', '|', C, D, '&', E, F].
Where each letter will be an expression like ('field', 'operator', 'value').
Note: ampersands must be escaped.
EDIT
I have answered a question here:
I don´t understand Normal Polish Notation (NPN or PN). How to build a complex domain in Odoo?
In which I explain with details a great method to resolve complex domains. I hope it helps to someone.

Is it possible to represent a context-free grammar with first-order logic?

Briefly, I have a EBNF grammar and so a parse-tree, but I do not know if there is a procedure to translate it in First Order Logic.
For example:
DR ::= E and P
P ::= B | (and P)* | (or P)*
B ::= L | P (and L P)
L ::= a
Yes, there is. The general pattern for translating a production of the form
A ::= B C ... D
is to paraphrase is declaratively as saying
A sequence of terminals s is an A (or: A generates the sequence s, if you prefer that formulation) if:
s is the concatenation of s_1, s_2, ... s_n, and
s_1 is a B / B generates the sequence s_1, and
s_2 is a C / C generates the sequence s_2, and
...
s_n is a D / D generates the sequence s_n.
Assuming we write these in the obvious way using a generates predicate, and that we can write concatenation using a || operator, your first rule becomes (if I am right to guess that E and P are non-terminals and "and" is a terminal symbol) something like
generates(DR,s) ⊃ generates(E,s1)
∧ generates(and,s2)
∧ generates(P,s3)
∧ s = s1 || s2 || s3
To establish the consequent (i.e. prove that s is an A), prove the antecedents. As long as the grammar does actually generate some sentences, and as long as you have some premises defining the "generates" relation for terminal symbols, the proof will be straightforward.
Prolog definite-clause grammars are a beautiful instantiation of this pattern. It takes some of us a while to understand and appreciate the use of difference lists in DCGs, but they handle the partitioning of s into subsequences and the association of the subsequences with the different parts of the right hand side much more elegantly than the simple translation into logic given above.

NOR-conjunction within OR-conjunctions

Let's save I have the logical expression
a OR b NOR c OR d
Is this interpreted as (a OR b) NOR (c OR d) or as a OR (b NOR c) OR d ?
It is a specific programming problem I face, thus the question on stackoverflow.
As far as I know, it would be interpreted as:
A or b or (Not c) or d

complex logical operation

Given this logical operation :
(A AND B) OR (C AND D)
Is there a way to write a similar expression without using any parentheses and giving the same result ? Usage of logical operators AND, OR, NOT are allowed.
Yes:
A and B or C and D
In most programming languages, and is taken to have higher precedence than or (this stems from the equivalence of and and or to * and +, respectively).
Of course, if your original expression had been:
(A or B) and (C or D)
you couldn't simply remove the parentheses. In this instance, you'd have to "multiply out" the factors:
A and C or B and C or A and D or B and D
How about A AND B OR C AND D? It's the same because AND takes precedence over OR.
Just don't put any parentheses, it is the same...
It can be written in two ways
A & B | C & D
Type as it is mentioned in question just remove the parenthesis it will show the same result.
We can use & for AND to multiply and | for OR to divide. Also simply you can write them without any parenthesis

Resources