Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,208 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,292 people online right now. Registration is fast and FREE... Join Now!




Boolean Algebra

2 Pages V  1 2 >  
Reply to this topicStart new topic

Boolean Algebra

kckc314
27 May, 2008 - 08:35 PM
Post #1

D.I.C Head
**

Joined: 5 Apr, 2008
Posts: 128

what are the first and second algebra means? by the C syntax i can tell what it means NOT, OR, AND? but when it combines together to evaluate a solution i don't know what it means. thanks in advance.

1st algebra ( Andrew && (!Nancy && !Andrew) ) || ( !Andrew && !(!Nancy && !Andrew) )

2nd algebra ( Bill && (!Bill || !Hilary) ) || (!Bill && !(!Bill || !Hilary) )
User is offlineProfile CardPM
+Quote Post

skaoth
RE: Boolean Algebra
27 May, 2008 - 09:18 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 344



Thanked: 10 times
Dream Kudos: 100
My Contributions
My response is in the attached text.
The editor doesn't like extra white space.

Edit: Fixed ! Typo. Thanks baavgai

This post has been edited by skaoth: 28 May, 2008 - 08:05 AM


Attached File(s)
Attached File  truthtable.txt ( 2.28k ) Number of downloads: 30
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Boolean Algebra
28 May, 2008 - 04:29 AM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,047



Thanked: 106 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
You should throw that in a tutorial or something, I think a lot of people are daunted by the logical operators. Also, your NOT has a typo.

User is offlineProfile CardPM
+Quote Post

lnc12
RE: Boolean Algebra
28 May, 2008 - 06:35 AM
Post #4

New D.I.C Head
*

Joined: 20 May, 2008
Posts: 11


My Contributions
QUOTE(skaoth @ 27 May, 2008 - 10:18 PM) *

My response is in the attached text.
The editor doesn't like extra white space.


I also would have done it that way it's similarly to a ruby code

know i speak in ruby an soon in C
CODE

puts (1 +2) // on your screen 1 2 whit a space will appear


in C
CODE

read 1_+2 // on your screen 1 2 whit a space will appear

I can only say it work whit Borland Builder 6

sorry for 2 post but my computer was shutting down needed some power

but whit the algebra you need to make a choice somethin
if somthing=1
{
"what you want"
}
User is offlineProfile CardPM
+Quote Post

kckc314
RE: Boolean Algebra
28 May, 2008 - 07:54 PM
Post #5

D.I.C Head
**

Joined: 5 Apr, 2008
Posts: 128

QUOTE(skaoth @ 27 May, 2008 - 10:18 PM) *

My response is in the attached text.
The editor doesn't like extra white space.

Edit: Fixed ! Typo. Thanks baavgai

i have some questions which are also in the attached file just in case the editor doesn't like white space. the info in your previous file make sense to me. thanks in advance.


Attached File(s)
Attached File  truthtable1.txt ( 2.53k ) Number of downloads: 33
User is offlineProfile CardPM
+Quote Post

KYA
RE: Boolean Algebra
29 May, 2008 - 02:35 AM
Post #6

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,053



Thanked: 124 times
Dream Kudos: 1200
My Contributions
QUOTE(baavgai @ 28 May, 2008 - 06:29 AM) *

You should throw that in a tutorial or something, I think a lot of people are daunted by the logical operators. Also, your NOT has a typo.


Math theory is one of my favorite subjects. Knights and knaves! smile.gif


Onto your question: assuming you are using knight as T and knave as F or 1 and 0 respectively, you would use the following:

"at most one of Sir Hilary and Bill is a knight/knave"
Only one can be true.
(Hilary && !Bill) || (!Hilary && Bill) || (!Hilary && !Bill)

"All of us are knights/knaves"
How many--needs quantifying

Usually you construct a truth table based on each individual case.

Boolean algebra never uses (as far as I have seen) inclusve OR or AND | &. You'll only use || or &&

Hope that helps. If I'm way off base please tell me smile.gif

This post has been edited by KYA: 29 May, 2008 - 02:35 AM
User is online!Profile CardPM
+Quote Post

baavgai
RE: Boolean Algebra
29 May, 2008 - 03:50 AM
Post #7

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,047



Thanked: 106 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
There is almost never a reason to use inclusive OR(|). If fact, I'd forgotten it was even used in mathematics; such a notation is usually called "bitwise OR" by programmers and used to apply logic to bits in a value e.g. ( 5 | 3 ) == 7 which is ( 101 | 011 ) == 111.

Now to make your code into code. Here's an example:

cpp

/*
( Andrew && (!Nancy && !Andrew) ) || ( !Andrew && !(!Nancy && !Andrew) )
( A && (!N && !A) ) || ( !A && !(!N && !A) )
can be further simplified
NNA = (!N && !A)
( A && NNA ) || ( !A && !NNA )
*/
int test1(int A, int N) {
int NNA = (!N && !A);
return (( A && NNA ) || ( !A && !NNA ));
}


/* print all permutations */
void printAll() {
int A, N, rownum = 0;

printf("\tA\tN\tT1\n");
for(A=0; A<2; A++) {
for(N=0; N<2; N++) {
printf("%d:\t%d\t%d\t%d\n", ++rownum, A, N, test1(A,N));
}
}
}


I'm tempted to do the rest, but that's your job. wink2.gif

Hope this helps.

User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Boolean Algebra
29 May, 2008 - 12:54 PM
Post #8

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
QUOTE(baavgai @ 29 May, 2008 - 04:50 AM) *
There is almost never a reason to use inclusive OR(|).

I completely disagree with this statement on so many levels. Bitwise operators are extremely useful for things like flags. Take Windows programming for example. Bitwise operators are used all over the place.
User is offlineProfile CardPM
+Quote Post

KYA
RE: Boolean Algebra
29 May, 2008 - 01:25 PM
Post #9

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,053



Thanked: 124 times
Dream Kudos: 1200
My Contributions
In code yes, in pure boolean algebra sentences, no.
User is online!Profile CardPM
+Quote Post

herefishyfishy
RE: Boolean Algebra
29 May, 2008 - 03:35 PM
Post #10

D.I.C Head
Group Icon

Joined: 1 May, 2008
Posts: 60


Dream Kudos: 100
My Contributions
Am I the only one who doesn't get what
QUOTE
what are the first and second algebra means?

means?
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Boolean Algebra
29 May, 2008 - 05:04 PM
Post #11

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,047



Thanked: 106 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
QUOTE(Cerolobo @ 29 May, 2008 - 04:54 PM) *

QUOTE(baavgai @ 29 May, 2008 - 04:50 AM) *
There is almost never a reason to use inclusive OR(|).

I completely disagree with this statement on so many levels. Bitwise operators are extremely useful for things like flags. Take Windows programming for example. Bitwise operators are used all over the place.


You, sir, have totally failed context. tongue.gif

The question on the table is: "3. if i interprete the above algebra into C code, do i use the normal logical OR(||) and logical AND(&&) or i have to use the inclusive OR(|) and inclusive AND(&)?"

My answer is, if you're doing a boolean operation, a standard AND and OR, an inclusive OR has extremely narrow use. Even if you had quoted the rest of my post, you may have caught onto that. However, how a programmer utilizes this function didn't seen apropos to the thread.

User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Boolean Algebra
29 May, 2008 - 05:17 PM
Post #12

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
No, what confused me was the symbol. In Discrete Mathematics, inclusive OR is represented with a "v". "|" usually means divides.

In any case, a inclusive OR is true if one or both of the operands is ture. This is used in Discrete Mathematics.

So this quote didn't really seem logical to me
QUOTE
There is almost never a reason to use inclusive OR(|).

Since inclusive OR is used in Discrete. The symbol didn't make sense either, so I default to C, which is what the rest of your post was referring to.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/4/08 01:01PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month