Something I discovered doing logic

  • Thread starter vin300
  • Start date
  • Tags
    Logic
In summary, performing an "AND" and "OR" operation on two numbers involves creating a binary number with "1" at specific positions based on the logical condition, and then adding the results of both operations numerically. This results in the same sum as adding the original numbers. This can be seen as a simplified version of the binary arithmetic rules where the only possible operations are adding "1" and carrying 1 to the next more significant bit.
  • #1
vin300
603
4
I haven't known about a law that says so. Step 1: using two numbers in any format: binary, octa, hexa, do an AND operation. Step 2: Perform OR operation on the same numbers. Step 3: Add the results of step 1 and 2 numerically. The result comes out to be the same as the sum of original numbers.
 
Physics news on Phys.org
  • #2
Give an example to explain what you mean by performing an "AND" and an "OR" operation on two numbers. Show an example in ordinary base 10 representation.
 
  • #3
Hmm I wonder if "X and Y" simply means min(X,Y) and "X or Y" means max(X,Y), when applied to numbers. If so, what vin300 has discovered is just that min(X,Y)+max(X,Y)=X+Y, which is easy to see.
 
  • #4
vin300 said:
I haven't known about a law that says so. Step 1: using two numbers in any format: binary, octa, hexa, do an AND operation. Step 2: Perform OR operation on the same numbers. Step 3: Add the results of step 1 and 2 numerically. The result comes out to be the same as the sum of original numbers.

What you "discovered" is that P&Q added to P|Q is equal to P+Q, right?

Here's a short explanation of what's really happening. Using the bitwise operator "&" for the logical operator "AND" and the bitwise operator "|" for the logical operator "OR", evaluating the expression P&Q basically creates a binary number with "1" at each position where both numbers have a "1" and puts zeros elsewhere; the expression P|Q does the same thing but puts a "1" at each position where at least one of the two numbers has a "1" and also puts zeros elsewhere. So when you add both expressions P|Q and P&Q, you're basically adding P and Q and the remainders, which gives you P+Q. This works under binary arithmetic since the only possible operations we have for addition are:
  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 0, and carry 1 to the next more significant bit, i.e. in this direction ←
In other words, when you evaluate P&Q or P|Q, every position where P and Q both had zeros will remain zero; likewise, every position where at least P or Q or both had "1" will remain the same. Since in the last case one event is included in the other, this assures you under the arithmetic rules we agreed on that adding P&Q and P|Q is equivalent to add P and Q.

Here is an example with P=5 and Q=6:
Code:
Expression     Result     Binary Description
P              5          00000101
Q              6          00000110
P & Q          4          00000101 & 00000110 = 00000100
P | Q          7          00000101 | 00000110 = 00000111

When you add P&Q and P|Q, you have:
Code:
      1
  00000100 = P & Q
+ 00000111 = P | Q
----------
  00001011 = (P & Q) + (P | Q)
And when you add P and Q, you have:
Code:
      1
  00000101 = P
+ 00000110 = Q
----------
  00001011 = P + Q
We can see that both expressions are equal. Of course the mathematical representation of bitwise operations can get messier depending of what we're using, e.g. if P and Q are not positive and/or integers, but that's the general procedure used to handle these operations, and basically every programming language that I know of does that.
 
  • Like
Likes micromass and berkeman

FAQ: Something I discovered doing logic

What is logic?

Logic is the study of reasoning and argumentation. It involves understanding how to construct valid arguments, identify fallacies, and evaluate the soundness of arguments.

How does logic apply to everyday life?

Logic is used in everyday life to make decisions, solve problems, and communicate effectively. It helps us analyze and evaluate information, think critically, and make logical conclusions.

What are the different types of logic?

The main types of logic are deductive, inductive, and abductive. Deductive logic uses general principles to reach specific conclusions. Inductive logic uses specific observations to draw general conclusions. Abductive logic involves making the best inference based on the available evidence.

What are the benefits of studying logic?

Studying logic can improve critical thinking skills, decision-making abilities, and problem-solving skills. It can also enhance communication and argumentation skills, as well as increase one's ability to analyze and evaluate information.

How can I improve my logical reasoning skills?

To improve logical reasoning skills, one can practice identifying and constructing arguments, learn about different types of fallacies, and engage in critical thinking activities. It can also be helpful to study formal logic and familiarize oneself with logical symbols and notation.

Similar threads

Replies
45
Views
4K
Replies
40
Views
7K
Replies
6
Views
1K
Replies
5
Views
3K
Replies
1
Views
629
Replies
2
Views
1K
Back
Top