Lecture 7 - Integer Properties (Part 1)

ITSC 2175: Logic and Algorithms - Integer Properties 1

Even and Odd Integers

An integer n is classified as even or odd based on its relationship to the integer k:

  • Even Integer: An integer n is considered even if there exists an integer k such that n = 2k.

    • Examples:

      • -78 is even because -78 = 2(-39), where -39 is an integer.

      • 10n^3 + 8n - 4 is even because it can be expressed as 2(5n^3 + 4n - 2). Here, (5n^3 + 4n - 2) is an integer if n is an integer.

  • Odd Integer: An integer n is considered odd if there exists an integer k such that n = 2k+1.

    • Examples:

      • 109 is odd because 109 = 2(54) + 1, where 54 is an integer.

      • -35 is odd because -35 = 2(-18) + 1, where -18 is an integer.

      • 4n + 3 is odd because it can be rewritten as 2(2n + 1) + 1. Here, (2n + 1) is an integer if n is an integer.

      • -2n^2 - 5 is odd because it can be rewritten as -2n^2 - 6 + 1 = 2(-n^2 - 3) + 1. Here, (-n^2 - 3) is an integer if n is an integer to represent k.

Divisibility

Definition: Let d and n be two integers, with d
eq 0. We say that d divides n if there exists an integer k such that n = kd.

  • Notation: "d divides n" is denoted by d | n.

  • Terminology: If d | n:

    • n is said to be a multiple of d.

    • d is a divisor (or factor) of n.

  • Does Not Divide: "d does not divide n" is denoted by d \nmid n.

  • Example: 6 = 2 imes 3. Hence:

    • 3 | 6 (3 divides 6).

    • 6 is a multiple of 3.

    • 3 is a divisor of 6.

  • Important Distinction: The statement d | n is a boolean condition (either true or false). It is fundamentally different from the expression n/d, which represents a rational number.

Division Algorithm

Statement: For any integer n and any positive integer d, there exist unique integers q (quotient) and r (remainder) such that n = qd + r.

  • Properties of the Remainder: The remainder r must satisfy 0 \leq r < d. This means r \in {0, 1, 2, \dots, d-1}.

  • Quotient (q): Defined as q = n \text{ div } d = \lfloor n/d \rfloor (round down n/d).

  • Remainder (r): Defined as r = n \text{ mod } d = n - qd.

  • Examples:

    • Given n = 25, d = 6.

      • q = 25 \text{ div } 6 = \lfloor 25/6 \rfloor = \lfloor 4.166… \rfloor = 4.

      • r = 25 - (4 imes 6) = 25 - 24 = 1.

      • Thus, 25 = 4 \times 6 + 1.

    • Given n = -30, d = 8.

      • q = -30 \text{ div } 8 = \lfloor -30/8 \rfloor = \lfloor -3.75 \rfloor = -4.

      • r = -30 - (-4 imes 8) = -30 - (-32) = -30 + 32 = 2.

      • Thus, -30 = -4 \times 8 + 2.

Number Systems

Each number system is characterized by a base and a specific set of digits used to represent numbers.

  • Decimal System (Base 10):

    • Base: 10.

    • Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

  • Binary System (Base 2):

    • Base: 2.

    • Digits: 0, 1.

  • Hexadecimal System (Base 16):

    • Base: 16.

    • Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

    • Value Mapping: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.

Converting from Decimal to Other Systems

Conversion from a decimal number to any other base system can be performed using repetitive division.
Process:

  1. Divide the decimal number by the target base.

  2. Record the remainder.

  3. Take the quotient from the division and use it as the new number for the next division step.

  4. Repeat steps 1-3 until the quotient becomes 0.

  5. The remainders, read from bottom-up (last remainder is the leftmost bit/digit, first remainder is the rightmost bit/digit), form the number in the new base.

  • Example: Decimal to Binary (Convert 120 base 10 to binary):

n

n \text{ div } 2

n \text{ mod } 2

120

60

0

60

30

0

30

15

0

15

7

1

7

3

1

3

1

1

1

0

1

Reading the remainders from bottom to top: 1111000.
Therefore, 120_{10} = 1111000_2.
  • Example: Decimal to Hexadecimal (Convert 637 base 10 to hexadecimal):

n

n \text{ div } 16

n \text{ mod } 16

637

39

D (13)

39

2

7

2

0

2

Reading the remainders from bottom to top: 27D.
Therefore, 637_{10} = 27D_{16}.
Converting from Other Systems to Decimal

Conversion from any other base system to decimal is done by summing the products of each digit with the base raised to the power corresponding to the digit's position.
Process:

  1. Assign a positional value to each digit, starting from 0 for the rightmost digit and increasing by 1 for each position to the left.

  2. For each digit, multiply the digit's value by the base raised to its positional power.

  3. Sum up all these multiplication results.

  • Example: Binary to Decimal (Convert 10011100_2 to decimal):

    • Positional Powers of 2:

Position

7

6

5

4

3

2

1

0

Power

2^7

2^6

2^5

2^4

2^3

2^2

2^1

2^0

Value

128

64

32

16

8

4

2

1

Digit

1

0

0

1

1

1

0

0

*   **Calculation**: (1 \times 128) + (0 \times 64) + (0 \times 32) + (1 \times 16) + (1 \times 8) + (1 \times 4) + (0 \times 2) + (0 \times 1) 
    = 128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156 
*   Therefore, 10011100_2 = 156_{10}.
  • Example: Hexadecimal to Decimal (Convert 403E_{16} to decimal):

    • Positional Powers of 16:

Position

3

2

1

0

Power

16^3

16^2

16^1

16^0

Value

4096

256

16

1

Digit

4

0

3

E (14)

*   **Calculation**: (4 \times 4096) + (0 \times 256) + (3 \times 16) + (14 \times 1) 
    = 16384 + 0 + 48 + 14 = 16446 
*   Therefore, 403E_{16} = 16446_{10}.

Prime and Composite Numbers

These classifications apply to integers greater than 1.

  • Prime Number: An integer n is prime if it is greater than 1 and its only factors are 1 and itself.

  • Composite Number: An integer n is composite if and only if n > 1, and there exists an integer m such that 1 < m < n and m \mid n (meaning m is a factor of n other than 1 or n).

  • Example: Identify prime numbers from the list: 1, 2, 4, 7, 10

    • 1 is neither prime nor composite by definition (must be >1).

    • 2 is prime (factors: 1, 2).

    • 4 is composite (factors: 1, 2, 4; 2 is a factor other than 1 or 4).

    • 7 is prime (factors: 1, 7).

    • 10 is composite (factors: 1, 2, 5, 10; 2 and 5 are factors other than 1 or 10).

Inequalities

Inequalities are used to describe the relative order or size of two real numbers.

  • Trichotomy Property: For any two real numbers x and c, exactly one of the following statements is true:

    • x < c (x is less than c)

    • x = c (x is equal to c)

    • x > c (x is greater than c)

  • Definitions of Inclusive Inequalities:

    • x \geq c: x is greater than or equal to c.

    • x \leq c: x is less than or equal to c.

Reasoning with Inequalities

Understanding the implications of inequality statements is crucial:

  • If x = c, then x \geq c (true, as x is equal to c).

  • If x > c, then x \geq c (true, as x is greater than c).

  • If x = c, then x \leq c (true, as x is equal to c).

  • If x < c, then x \leq c (true, as x is less than c).

  • If \neg(x < c) (it is not true that x is less than c), then x = c or x > c, which implies x \geq c. (True, this is equivalent to x \geq c).

  • If \neg(x > c) (it is not true that x is greater than c), then x = c or x < c, which implies x \leq c. (True, this is equivalent to x \leq c).

  • Examples (Let x be a real number. Indicate whether each statement is true or false):

    • If x > 4, then x \geq 4: True (If x is strictly greater than 4, it is also greater than or equal to 4).

    • If x \geq 4, then x > 4: False (Consider x=4. 4 \geq 4 is true, but 4 > 4 is false).

    • If x < 4, then x \leq 3: False (Consider x=3.5. 3.5 < 4 is true, but 3.5 \leq 3 is false).

    • If x < 4, then x \leq 5: True (If x is less than 4, it must also be less than (and thus less than or equal to) 5).

Rational Numbers

Definition: A number x is considered rational if there exist two integers a and b such that b \neq 0 and x = a/b.

  • Key Conditions: The denominator b must not be zero, and both a and b must be integers.