Is `1 XOR 1 OR 1` ambiguous in Boolean algebra? - math

Using boolean algebra (not a specific language implementation), can we evaluate 1 ^ 1 + 1 (or 1 XOR 1 OR 1) unambiguously?
I can derive two evaluations:
[I]: (1 ^ 1) + 1 = 0 + 1 = 1
[II]: 1 ^ (1 + 1) = 1 ^ 1 = 0
Perhaps there's some stated order of operations, or of a left-to-right evaluation? Or is this not defined in Boolean algebra?

We can use the rules of boolean algebra to attempt to evaluate the expression 1 XOR 1 OR 1.
Now:
XOR is derived from OR such that A XOR B = (¬A AND B) OR (¬B AND A);
Associativity tells us that A OR (B OR C) = (A OR B) OR C;
Associativity also tells us that A AND (B AND C) = (A AND B) AND C
So, taking either of the possible interpretations of evaluation order:
(1 XOR 1) OR 1 1 XOR (1 OR 1)
Even though we have no left-to-right "evaluation order" defined, these rules are all we need to show that the two possible interpretations are not equivalent:
= (¬1 AND 1) OR (¬1 AND 1) OR 1 = (¬1 AND (1 OR 1)) OR (¬(1 OR 1) AND 1)
= (0 AND 1) OR (0 AND 1) OR 1 = (0 AND 1) OR (0 AND 1)
= 0 OR 0 OR 1 = 0 OR 0
= 1 = 0
Unless I'm forgetting some crucially pertinent axiom, I've confirmed that you need more context to evaluate the given expression.
(And, of course, examining the expression A XOR B OR C ∀A,B,C is of course substantially more tricky! But if the expression is ambiguous for just one value of all three inputs, then why bother checking for any others?)
This context is usually provided in language-specific evaluation-order rules. C-type languages give XOR a low precedence (something Richie came to dislike); by contrast, mathematical convention dictates a left-to-right associativity where no other axiom can be applied and an ambiguity is otherwise present.
So, basically, since we're ignoring language-specific rules, you'd probably go with [I].

Most languages would do XOR then OR; experienced coders will put parentheses in anyway just to make the intent clear.
Many more modern languages do what's called fast- or short-circuit- evaluation, so 0 & ? is always 0, so ? will not be evaluated; same with 1 + ?.

I don't think there is a generally agreed upon order of precedence with logical operators. The evaluation would be entirely specific to a language.

In c# for instance, the Operator precedence for bitwise operators is:
AND
XOR
OR
But this might be different for another language. If the precedence is the same, then the operations are executed from left to right. There is no logical XOR operator, but you can use NOT EQUAL (!=) instead.

Related

Why does Julia return different results for equivalent expressions? 6÷2(1+2) and 6÷2*(1+2)

I typed the following in Julia's REPL:
julia> 6÷2(1+2)
1
julia> 6÷2*(1+2)
9
Why are the different results output?
Presh Talwalkar says 9 is correct in the movie
6÷2(1+2) = ? Mathematician Explains The Correct Answer - YouTube
YouTube notwithstanding, there is no correct answer. Which answer you get depends on what precedence convention you use to interpret the problem. Many of these viral "riddles" that go around periodically are contentious precisely because they are intentionally ambiguous. Not a math puzzle really, it's just a parsing problem. It's no deeper than someone saying a sentence with two interpretations. What do you do in that case in real life? You just ask which one they meant. This is no different. For this very reason, the ÷ symbol isn't often used in real mathematical notation—fraction notation is used instead, which clearly disambiguates this as either:
6
- (1 + 2) = 9
2
or as
6
--------- = 1
2 (1 + 2)
Regarding Julia specifically, this precedence behavior is documented here:
https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/#man-numeric-literal-coefficients
Specifically:
The precedence of numeric literal coefficients is slightly lower than that of unary operators such as negation. So -2x is parsed as (-2) * x and √2x is parsed as (√2) * x. However, numeric literal coefficients parse similarly to unary operators when combined with exponentiation. For example 2^3x is parsed as 2^(3x), and 2x^3 is parsed as 2*(x^3).
and the note:
The precedence of numeric literal coefficients used for implicit multiplication is higher than other binary operators such as multiplication (*), and division (/, \, and //). This means, for example, that 1 / 2im equals -0.5im and 6 // 2(2 + 1) equals 1 // 1.

Is Exclusive in XOR really appropriate for more than two inputs?

What does Exclusive in XOR really mean for more than two inputs? Doesn't word Exclusive suggest only one input must be true and not odd number of inputs. Note that the inputs are in sequence.
This may seem like duplicate question but all similar questions answer for only two inputs and hence causes me confusion.
Exclusive OR is defined for two operands only, like e.g. addition. Just like an addition, it happens to be associative. This means
(a xor b) xor c = a xor (b xor c)
for all inputs a, b and c.
For associative operations, it is customary to drop parentheses because they cannot change meaning of an expression:
(a + b) + c = a + (b + c) = a + b + c
(a xor b) xor c = a xor (b xor c) = a xor b xor c
One can loosely speak of xor-ing together a bunch of values, but the underlying operation always takes two operands.

Solve logical and mathematical Equation

I would like to solve following equation:
x^2-bitxor(2,x)=0
Is it possible ?
bitxor(2,x) wil either add 2 or subtract 2 to/from x, so you have to solve both:
x^2 - x + 2 = 0
and:
x^2 - x - 2 = 0
and then test to see if the any of the solutions work in the original expression.
In the first case the roots are complex, in the second case the roots are -1 and +2.
Substituting back into the original equation:
x = -1 => (-1^2) - bitxor(2, -1) = 1 - (-3) = 4
x = 2 => (2^2) - bitxor(2, 2) = 4 - 0 = 4
So apparently there is no real integer solution.
There are solutions in modular arithmetic, which is precisely the arithmetic that most computers use for unsigned integers. For example, consider the case of modulo 256 arithmetic. In C and C++, this is the arithmetic of unsigned char. Here we have two solutions, 91 and 166. (See http://www.wolframalpha.com/input/?i=x%5E2+mod+256+%3D+x+-+2%2C+x+%3E+0%2C+x%3C+256 ).
In fact, for any modulo 2^N system, there will be two solutions that sum to 1 (modulo 2^N).

Find the Simplified Sum of Products of a Boolean expression

Just having some problems with a simple simplification. I am doing a simplification for the majority decoder with 3 inputs A, B and C. Its output Y assumes 1 if 2 or all 3 inputs assume 1. Y assumes 0 otherwise. Select its correct switching function Y=f(A,B,C).
So, after doing out a truth table I found the Canonical Sum of Products comes to
NOT(A).B.C + A.NOT(B).C + A.B.NOT(C) + A.B.C
This, simplified, apparently comes to Y = A * B + B * C + A * C
What are the steps taken to simply an expression like this? How is it done? How was this value gotten in this case?
First, note that for a Boolean expression:
A= A + A
Now, see that
NOT(A).B.C + A.NOT(B).C + A.B.NOT(C) + A.B.C
= NOT(A).B.C + A.NOT(B).C + A.B.NOT(C) + A.B.C + A.B.C + A.B.C
= (NOT(A)+A).B.C + A.(NOT(B)+B).C + A.B.(NOT(C)+C)
= B.C + A.C + A.B
Incidentally WolframAlpha is great for doing (checking) Boolean maths in which case the format for your example is:
~A && B && C || A && ~B && C || A && B && ~C || A && B && C
Also your specific expression is actually on this page as an example, done differently to the other answer given.
You would benefit from understanding some basic logic concepts:
De Morgan's Laws explain how to translate ANDed terms into ORed terms (and vice versa). This is a very powerful concept worth learning, it allows the translation of a logic expression into pure NAND or pure NOR form for which there are very good reasons
A Karnaugh map can be used to visually translate logic expressions into their first canonical form. Using a Karnaugh map is impractical in many real life cases but a really great learning technique
One straightforward way of finding the first canonical form for any logic expression is to generate the appropriate truth table and then examine the inputs that result in an output of 1.
For each row in a truth table where the output is 1, you can relatively easily form a logic expression for that row only. The full logic expression comes from ORing all the expressions for each row. This will be a minimal expression (there may be others, none will be more minimal).
Another explanation.
We have (1):
(not(A) and B and C ) or (A and not(B) and C) or (A and B and not C) or (A and B and C).
We know that:
A = A or A.
So we can rewrite (1) to (2):
(not(A) and B and C ) or (A and B and C) or
(A and not(B) and C) or (A and B and C) or
(A and B and not C) or (A and B and C)
We also know that:
(A and B) or (A and not B) = A and (B or not B) = A
So we can rewrite (2) to (3):
(B and C) or (A and C) or (A and B)
The idea is to find groups that can be (partially) eliminated to simplify the equation.

What does a circled plus mean?

I cannot understand the calculation "66 ⊕ fa = 9c".
The sum is clearly over "ff", so I am confused.
The topic is simple encryption algorithm.
What does a circled plus mean?
People are saying that the symbol doesn't mean addition. This is true, but doesn't explain why a plus-like symbol is used for something that isn't addition.
The answer is that for modulo addition of 1-bit values, 0+0 == 1+1 == 0, and 0+1 == 1+0 == 1. Those are the same values as XOR.
So, plus in a circle in this context means "bitwise addition modulo-2". Which is, as everyone says, XOR for integers. It's common in mathematics to use plus in a circle for an operation which is a sort of addition, but isn't regular integer addition.
This is not an plus, but the sign for the binary operator XOR
a b a XOR b
0 0 0
0 1 1
1 0 1
1 1 0
It's not an addition, but an exclusive OR operation. At least the output confirms to the same.
That's the XOR operator, not the PLUS operator
XOR works bit by bit, without carrying over like PLUS does
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 0 = 0
0 XOR 1 = 1
Hope this layout works, take it to the binary representation with an XOR:
66h = 102 decimal = 01100110 binary
FAh = 250 decimal = 11111010 binary
------------------------------------
10011100 binary <------ that's 9Ch/156 decimal
XOR rules are basically:
1 XOR 1 = 0 false
1 XOR 0 = 1 true
0 XOR 0 = 0 false
but the wiki I linked earlier will give you more details if needed...thats what it looks like they are doing in the screenshot you provided
The plus-symbol in a circle does not denote addition. It is a XOR operation.
It's an exclusive or (XOR). If I remember correctly, when doing bitwise mathematics the dot (.) means AND and the plus (+) means OR. Putting a circle around the plus to mean XOR is consistent with the style used for OR.
I used the logic in the replies by rampion and schnaader. I will summarise how I confirmed the results. I changed the numbers to binary and then used the XOR-operation. Alternatively, you can use the Hexadecimal tables: Click here!
It is XOR. Another name for the XOR function is addition without carry. I suppose that's how the symbol might make sense.

Resources