January:05(Mon)

MTH 225 Exercise-Set #1

Due January 14 (Wednesday)


Where it's appropriate, show intermediate work/explanations for obtaining answers.  (If you're not sure where it's appropriate, ask.)


  1. Do the following exercises of Section 1.1 in our textbook:


  2. [2 points]   At one point in a Java program (named ProofBuilder) which I wrote, I wanted to express the condition that if one variable named argument2 wasn't null, then a second variable named argument1 shouldn't be be null.  That is to say, I wanted to express the following condition in my Java code:
        (argument2 ≠ null) → (argument1 ≠ null)
    
    In case you're wondering, the specific type of Java statement that I was writing here was an assert statement; but if you want you can consider the situation as though I was writing an if statement as follows:
        .
        .
        .
        if (  _________  )  // "(argument2≠null) → (argument1≠null)"
            {
            .
            .
            .
    
    Thus, I wanted to complete the underline blank "________" there with a Java expression which would have the value true when  argument2≠null  is true and  argument1≠null  is true, the value false when  argument2≠null  is true and  argument1≠null  is false, the value true when  argument2≠null  is false and  argument1≠null  is true, and the value true when  argument2≠null  is false and  argument1≠null  is false
    But Java doesn't have a simple operator clearly corresponding to the logical connective "" ("implies").  So what needed to be done here wasn't so straightforward. 

    How can this problem be solved?  Give a Java expression that one could write in the head of the if statement here, equivalent to the logical expression "(argument2≠null) → (argument1≠null)".  (You need to write just one Java expression fitting in the if statement to solve this problem; I'm not interested in code that is radically restructured or something.)
    Explain why you think your answer is correct.


  3. Do the following exercises of Section 1.2 in our textbook:


  4. [4 points]
    De Morgan's Laws can sometimes make it more convenient for a programmer to express a logical expression in a computer program.  For Java, these laws state that the expression  !(condition1 && condition2)  is logically equivalent to the expression  (!condition1 || !condition2),  and the expression  !(condition1 || condition2)  is logically equivalent to the expression  (!condition1 && !condition2).  (See De Morgan's Laws also in our textbook.)  For example, the following three segments of code are all equivalent:
        if (  !(num1 > num2  ||  num2 > num3)  )
            System.out.println("num2 is in the middle");
    
        if (  !(num1 > num2)  &&  !(num2 > num3) )
            System.out.println("num2 is in the middle");
    
        if (  num1 <= num2  &&  num2 <= num3 )
            System.out.println("num2 is in the middle");
    
    Then consider the following Java expressions:
    1.   !(x < 4) && !(y >= 7)
    2.   !(a == b) || !(g != 5)
    3.   !( x <= 8  &&  y > 3 )
    4.   !( i > 2  ||  j <= 9 )
    Simplify those expressions, using De Morgan's laws (etc.) to find Java expressions that are equivalent to those expressions but contain no occurrences of Java's logical NOT operator, "!".  (You are allowed to use the inequality operator "!="; it is technically distinct from Java's logical NOT operator, "!".)

    Acknowledgement: This exercise was derived from "Java: How to Program" by Deitel & Deitel.