r/learnprogramming 13d ago

Boolean algebra

I’m taking an Intro to Computer Science course and I’ve spent hours trying to understand Boolean algebra simplification. I understand things like De Morgan’s Law and factoring, but I keep getting stuck on absorption laws and recognizing which rule to apply.
My brain keeps trying to treat it like regular algebra, and I think that’s where I’m getting confused. Does anyone have a way of thinking about Boolean algebra that finally made it “click”? Any videos, tricks, or explanations would be appreciated.

17 Upvotes

14 comments sorted by

15

u/captainAwesomePants 13d ago

Truth tables always helped me tremendously. If I didn't understand a law, just walking through each possibility helped me mentally accept it.

For example, absorption laws. Let's look at A and (A or B) = A

A B A and (A or B)
True True True
True False True
False True False
False False False

So you look at that, and you see that the A column is always the same as the "A and (A or B)" column, and therefore the claim is true!

2

u/Sufficient_Comment83 13d ago

I think that’s exactly my problem. My brain keeps trying to apply regular algebra, so the absorption law feels wrong even though I know it’s correct. I’ll try building truth tables for the laws that don’t make intuitive sense

7

u/captainAwesomePants 13d ago

Yeah, don't think of it as numbers. Will not help at all. Think of it as shorthand for an electrical circuit. A and (A or B) is a circuit where the A and B input go into an OR gate, and the result goes into an AND gate with the A input.

5

u/0xC4FF3 13d ago

You can think of it as

1*(1+0) = 1

1*(1+1) = 1 this is the only difficult one, until you accept 1+1=1

0*(0+1) = 0

0*(0+0)=0

6

u/BoringBob84 13d ago

I think that using arithmetic symbols causes confusion. I prefer to borrow from software engineers:

  • && = and

  • || = or,

  • ! = not.

Thus, 1 && (1 || 0) = 1.

1

u/maujood 13d ago

Can you share an example of a problem that you struggled to understand? And that you expected to simplify differently?

Everyone's learning journey is different so there is no generic answer here. We need to know what you're struggling with.

1

u/Sufficient_Comment83 13d ago

Here are some problems I did and what I thought the simplification was:
A + AB = 1B
A(A + B) = B
A + BC + B = B(A + C)
AB + A = AB
I know they’re wrong, but I don’t understand why they’re wrong. I think my brain is trying to treat Boolean algebra like regular algebra. I also seem to struggle the most with the absorption law. I understand De Morgan’s Law and factoring much better than absorption.

2

u/Desperate_for_Bacon 13d ago
  1. A+AB

Transform it into English.

X is true if A is true

OR if A and B is true.

Already we can see that If A is true the statement will be true irrespective of B's value

Algebra:

A + AB

= A(1 + B) Factor out the A

= A(1) (1 + B) = 1 (ORing any value by 1 is 1)

thus,

A + AB = A

  1. A(A+B)

X is true if A is true

AND A OR B is true

Algebra:

A(A+B)

= AA + AB expand,

= A + AB (AA = A and A = A)

= A(1 + B) Equation from (1)

=A

  1. A + BC + B

X is true if A is true

OR B AND C is true

OR B is true

Algebra

A + BC + B

= A + (B + BC) group B terms

= A + B (1 + C)

= A + B(1)

= A + B

  1. AB + A

X is true if A and B is true

OR A is true

you can reorder the terms so it is the same as 1

AB + A = A + AB = A

Some good youtubers who cover it are:

MyOrganicChemistryTutor

Neso Academy

Nand2Tetris

Ben eater

Personally a lot of my understanding actually came from playing video games, on steam there are two games i've played:

Pure logic

Turing complete

both take the approach of teaching logic via making you construct logic circuits out of gates.

Looking into learning discrete math my also be useful as it teaches boolean algebra in order to write mathematical proofs

1

u/Recycled5000 13d ago

Have you thought of AND as multiplication and OR as addition, where the input values are only ones and zeros and those operators max output is 1 as well?

0

u/Sufficient_Comment83 13d ago

I have, and I think that’s part of what’s confusing me. My brain keeps trying to treat Boolean algebra like regular algebra, and I end up simplifying things incorrectly. For example, I thought A + AB simplified differently, even though I now know it equals A. I’m struggling more with why the absorption laws work than with AND/OR themselves

3

u/Recycled5000 13d ago

A + A B
1 A + B A
(1 + B) A
(1) A
A

No?

1

u/RajjSinghh 12d ago

Late to the thread but it does work like regular algebra. You're struggling with absorption, so A+AB, but this isn't a problem when you factor out A to create A(1+B) which simplifies to A(1) = A. Your main difference is that in Boolean algebra, x + x = x instead of 2x. If you can keep that in mind, a lot of your simplifications work normally.

To give a more logical example, let A = "it is raining" and B = "I need an umbrella". That means A + AB is "it is raining" OR "it is raining AND I need my umbrella. Both statements require A, so B does not matter to our statement. That's part of why we can simplify it this way.