Full Version: Logic Operators and how they are interpreted
Dream.In.Code > Programming Tutorials > Software Development Tutorials
polymath
The attached file is a tutorial on Logic Operators.

I used some elements that i didn't know how to use in BBcode, such as tables, so if anyone could tell me how to make a table for my tutorials, that would be appreciated. For now, here it is in Rich Text (hope you can open it).

smile.gif
mikeblas
Unfortunately, BBCode doesn't support any sort of tables.
NickDMax
Well, what you can do is use some creative work to create tables.

First set you font to a fixed width font (courier or new courier work well).

Next layout your table as you would like it using ascii art.

Then use your text editor (something that has RegEx replaces works best -- I use ProgrammersNotepad) to replaces spaces with a period (or other small character).

Then replace all of the instances of that character with [color=#FFFFFF](spaces char here)[/color]

I use Programmer's Notepad's RegEx replace to do this. It works well. but since Dream In Code's background is not exactly white the characters are still visible but barely, and if someone copies your text then they get all of those characters.

example:

+---------+---------+----------+
|````X````|````Y````|`(X`&&`Y)`|
+---------+---------+----------+
|`Flase```|`False```|`False````|
+---------+---------+----------+
|`False```|`True````|`False````|
+---------+---------+----------+
|`True````|`False```|`False````|
+---------+---------+----------+
|`True````|`True````|`True`````|
+---------+---------+----------+


CODE
[font=Courier New]+---------+---------+----------+
|[color=#FFFFFF]````[/color]X[color=#FFFFFF]````[/color]|[color=#FFFFFF]````[/color]Y[color=#FFFFFF]````[/color]|[color=#FFFFFF]`[/color](X[color=#FFFFFF]`[/color]&&[color=#FFFFFF]`[/color]Y)[color=#FFFFFF]`[/color]|
+---------+---------+----------+
|[color=#FFFFFF]`[/color]Flase[color=#FFFFFF]```[/color]|[color=#FFFFFF]`[/color]False[color=#FFFFFF]```[/color]|[color=#FFFFFF]`[/color]False[color=#FFFFFF]````[/color]|
+---------+---------+----------+
|[color=#FFFFFF]`[/color]False[color=#FFFFFF]```[/color]|[color=#FFFFFF]`[/color]True[color=#FFFFFF]````[/color]|[color=#FFFFFF]`[/color]False[color=#FFFFFF]````[/color]|
+---------+---------+----------+
|[color=#FFFFFF]`[/color]True[color=#FFFFFF]````[/color]|[color=#FFFFFF]`[/color]False[color=#FFFFFF]```[/color]|[color=#FFFFFF]`[/color]False[color=#FFFFFF]````[/color]|
+---------+---------+----------+
|[color=#FFFFFF]`[/color]True[color=#FFFFFF]````[/color]|[color=#FFFFFF]`[/color]True[color=#FFFFFF]````[/color]|[color=#FFFFFF]`[/color]True[color=#FFFFFF]`````[/color]|
+---------+---------+----------+[/font]
herefishyfishy
I'd just like to comment on your distributive property of logic.

There IS a way to simplify !(A&&B). It's the same as !A||!B.

Likewise, !(A||B) is logically equivalent to !A&&!B.

It's called De Morgan's law. (Yes, I am such a nerd. I know.)
KYA
Nice! I also like math theory go De Morgan!
baavgai
QUOTE(herefishyfishy @ 2 Jun, 2008 - 09:07 PM) *

There IS a way to simplify !(A&&B). It's the same as !A||!B.


Good point. From a computer standpoint, !A||!B might be preferable to !(A&&B).

The reason is that if !A is true, the compiler doesn't have to resolve !B and usually won't. For A&&B the same thing, If !A is can just stop. However, further logic is to be applied, it would have to resolve the entire thing. That's assuming the compiler doesn't distribute the logic first, but it's something to be aware of.
polymath
I heard about DeMorgan's Law, but thought that the tutorial was already a lot to swallow for a total beginner. Most of my tutorials (actually, i think at this point all of them) are aimed twoard beginners. Thats what i think is the most rewarding thing about writing tutorials: helping people who aren't as good as you yet. Anyway if i edit the tutorial post i will include DeMorgan's Law. Thanks for reminding me about that one thing. Also, thanks to all of you for your help.
polymath
Whats the need for the small char instead of spaces?
NickDMax
The forum software will compress multiple spaces into a single space. So to keep the spacing for the table you have to insert some character in there. Then to ensure that that character is not displayed you need to mask it to the background color (which not really white, but I find that it is close enough for me).
herefishyfishy
Another comment on the supposedly nonexistent distributive property of logic...

There is a property which states that A||(B&&C)==(A||B)&&(A||C). Likewise, A&&(B||C)==(A&&B)||(A&&C).

This property just happens to be called the distributive property.

I could tell you lots of stuff...
  1. A||A==A
  2. A&&A==A
  3. A||(!A)==true
  4. A&&(!A)==false
  5. A&&(A||B)==A
  6. A||(A&&B)==A
  7. A||B==B||A
  8. A&&B==B&&A
  9. (A||B)||C==A||(B||C)
  10. (A&&B)&&C==A&&(B&&C)
  11. !(!A)==A
  12. A||(B&&C)==(A||B)&&(A||C)
  13. A&&(B||C)==(A&&B)||(A&&C)
  14. !(A&&B)==!A||!B
  15. !(A||B)==!A&&!B
  16. A||true==true
  17. A&&true==A
  18. A||false==A
  19. A&&false==false
The list goes on and on...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.