Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Boolean Equivalents - Basic Identities

  1. #1
    Member
    Join Date
    Jul 2012
    Location
    Dallas area
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Boolean Equivalents - Basic Identities

    I'm looking at a table meant to help me simplify condition code, but I'm not exactly sure what these statements mean. I understand the first one: !!x (double-arrow) x. No problem. A double-negative equals a positive (or "true"). But the rest of the equivalencies are not making sense to me yet. Like this one:
    x || false (double-arrow) x
    Does that read like this: "a variable named "x" OR a false result of an expression is the same thing as that variable named "x"? If that is in fact how that reads, then I don't see how that is equivalent to "x". I'm having the same problem understanding:
    x && true (double-arrow) x
    and;
    x || true (double-arrow) true
    and so on...

    Maybe this first-time poster just needs a nap. But please explain, anyway.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,948
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: Boolean Equivalents - Basic Identities

    x && true (double-arrow) x
    Not sure what that is supposed to say. The part following true is confusing.
    What is the definition for x?
    What does (double-arrow) mean?
    No one would code: !!x
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: Boolean Equivalents - Basic Identities

    Quote Originally Posted by pict3000 View Post
    ...
    x || false (double-arrow) x
    Does that read like this: "a variable named "x" OR a false result of an expression is the same thing as that variable named "x"? ....
    Symbolic logic loses a little when we are confined to non-symbolic text, but I'm think your double arrow means what you said.

    I'll use .OR. to represent a logical operation between boolean variables

    So, I'll try it like this...

    Suppose x is a boolean variable. It can only take on one of two possible values: True, False. Mathematicians are more likely to call the value 1 and 0, respectively and they define certain operation in terms of 1s and 0s, but we can use True and False if we want to.

    Try it in the following logical equation.
    1. Let x = False.
      Then x .OR. False ==> False .OR. False ==> False

    2. Let x = True.
      Then x .OR. False ==> True .OR. False ==> True

    3. Therefore x .OR. false ==> x


    I'm using ==> as an indication that an expression on the left implies a result given on the right.

    Hardware guys know this without even thinking about it. If one input of an OR gate is tied low (logic 0 or False), then if you apply a logic 1 (True) to the other input, the output is 1 (True). If you apply a logic 1 (True) to the other input, the output is 1. In other words, if one input is tied low, the output is equal to the other input.

    Try it again with .AND.


    Quote Originally Posted by Norm
    No one would code: !!x
    Maybe you wouldn't code that in Java, but if the subject is symbolic logic, it's not uncommon to see expressions like that during various kind of manipulations.

    It's also used in C90 programming where there are no Boolean variables, and !!x is very useful in certain situations, but that's another story...

    Note that C program statement (C++ too), if x is some kind of numerical data type, !!x is not a boolean algebraic expression, it has an arithmetic value of zero or 1 depending on whether the numerical value of x is equal to zero or not equal to zero.)

    Cheers!


    Z
    Last edited by Zaphod_b; July 28th, 2012 at 08:23 PM.

  4. #4
    Member
    Join Date
    Jul 2012
    Location
    Dallas area
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Equivalents - Basic Identities

    Norm,

    This is right out of an intro to Java textbook. This reference table is titled Basic Identities of Boolean Logic. These statements are meant to show a simplified equivalent (right side of the double arrow) to the condition statement on the left side of the double arrow. The double arrow is the symbol for "equivalent". I don't have a double arrow on my keyboard, so I wrote it out. I'm not following the logic of these "equivalent" statements, though.

    Does that clarify at all?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,948
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: Boolean Equivalents - Basic Identities

    Would the double arrow look like this: <==>
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member
    Join Date
    Jul 2012
    Location
    Dallas area
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Equivalents - Basic Identities

    The book shows a solid line between the arrow points. It means "the same thing as" (equivalent). I take it that's what your symbol means, too.

  7. #7
    Member
    Join Date
    Jul 2012
    Location
    Dallas area
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Equivalents - Basic Identities

    ...and yes, it look very much like your example - only with a solid line between the arrow points.

  8. #8
    Member
    Join Date
    Jul 2012
    Location
    Dallas area
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Equivalents - Basic Identities

    Thank you, Zaphod_b!

    Great explanation!

  9. #9
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    989
    Thanks
    7
    Thanked 207 Times in 183 Posts

    Default Re: Boolean Equivalents - Basic Identities

    Richard Feynman tells a story somewhere about having a cousin who was baffled by some problem in maths - a calculation of some sort. He thought that the calculation was quite straight forward and told his cousin what the answer was, but his cousin objected: "No, I have to solve it with algebra!". Feynman expresses some dissatisfaction with algebra if it acts to obscure the calculation.

    Consider the following rules of algebra (the sort of thing Feynman's cousin might have found confusing). And think about what they mean:

    x = -(-x)
    x = x + 0
    x.1 = x

    It is reasonable to say that these rules express the fact that the left and right hand side have the same value, whatever the value of x might be. They are valid identities of algebra but, it must be admitted, they are pretty useless aids to calculation.

    -----

    Your book is saying something similar about thinking and the rules of logic. Variables and other expressions, like the letters and expressions of algebra, have values. And it is possible to find pairs of things that always have the same value whatever the value of x may be.

    x <-> !!x
    x <-> x || false
    x && true <-> x
    x || true <-> true

    If you don't think these identities always hold, come up with a value of x that makes the two sides of the "equation" have different values.

    -----

    The algebra examples were chosen to mimic the logic ones. (With true and false playing the role of one and zero) But we notice a couple of differences. First the logical x can only have two values which makes the rules of logic rather easy to check. And secondly the last of the logic rules has no straight forward counterpart in arithmetic.

    I'm inclined to agree with Feynman: these rules of logic add little to our ability of to perform boolean calculations. (They are, however, convenient symbolic shortcuts to help us reason about such calculations). So try and understand why they are true, but don't get too hung up over them: they are not expressing profound truths about reasoning.

    [Edit] slow

  10. #10
    Member
    Join Date
    Jul 2012
    Location
    Dallas area
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Equivalents - Basic Identities

    pbrockway2, Thanks for your helpful insights.

    I think the point of these basic identities, as they're called in the text, is to give guidance for simplifying code in the condition. Whether or not it will prove helpful for that, well...

    They're also meant to give us alternative solutions when we're sort of stuck.

  11. #11
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    989
    Thanks
    7
    Thanked 207 Times in 183 Posts

    Default Re: Boolean Equivalents - Basic Identities

    I think the point of these basic identities, as they're called in the text, is to give guidance for simplifying code in the condition.
    Fair enough - and anything that helps is ... helpful!

    I find it helpful to read an expression. Actually read it, rather than just letting it hit the eyes as a sequence of symbols. Often I'll mentally respond to myself "Oh!, that just means...". The best rule of thumb, though, is never to write long, ugly, unintelligible conditions. It costs nothing to break them up into component subexpressions and assign them meaningfully named variables.

Similar Threads

  1. Need help with boolean method! =(
    By leao in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 14th, 2010, 10:18 AM
  2. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM
  3. Some help with boolean
    By JPetroSS in forum Java Theory & Questions
    Replies: 3
    Last Post: November 2nd, 2010, 06:38 AM
  4. Need help with what I believe is Boolean & add branching
    By JavaBeginner123 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 1st, 2010, 02:55 PM
  5. [SOLVED] Modification of Boolean function in Java program
    By lotus in forum Java SE APIs
    Replies: 4
    Last Post: July 10th, 2009, 11:15 AM

Tags for this Thread