Let x ∈ ℕ, 2^{n} > x ≥ 0. Define the 2’s complement of x as 2^{n} – x if x ≠ 0. When x = 0 its 2’s complement is 0. So x + (2^{n} – x) = 2^{n} and 2^{n} – (2^{n} – x) = x.

0 < x < 2^{n-1} ⇒ 0 > -x > -2^{n-1} ⇒ 2^{n} > 2^{n} – x > 2^{n-1}.

2^{n} > x > 2^{n-1} ⇒ -2^{n} < -x < -2^{n-1} ⇒ 0 < 2^{n} – x < 2^{n-1}.

Note that 2^{n-1}, like zero, is its own complement.

If we want half of the bit patterns (2^{n} รท 2 = 2^{n-1}) to represent negative integers then it’s natural to let the first n-1 bits represent zero and the positive integers from 1 to 2^{n-1} – 1.

If we have the representation of a negative integer then it’s easy to compute the corresponding negative integer. Let 2^{n-1} < 2^{n} – x < 2^{n}. Remove sign bit: 2^{n} – x – 2^{n-1} = 2^{n-1} – x. Then -2^{n-1} + (2^{n-1} – x) = -x.

**Addition of two negative integers**

Let x,y ∈ ℕ, x ≠ 0, y ≠ 0. To show that -x + -y = -(x + y), assume x < 2^{n-1}, y < 2^{n-1}, x + y < 2^{n-1}. Then (2^{n} – x) + (2^{n} – y) = 2^{n} + (2^{n} – (x + y)). Discarding the 2^{n} bit leaves 2^{n} – (x + y).

**Addition of a positive integer and a negative integer**

0 < y < x < 2^{n-1} ⇒ 0 < x – y < 2^{n-1}.

x – y = x + -y ≡ x + 2^{n} – y ≡ x – y (discarding the 2^{n} bit).

0 < x < y < 2^{n-1} ⇒ 0 < y – x < 2^{n-1} – x < 2^{n-1}.

x – y ≡ x + 2^{n} – y = 2^{n} – (y – x).

x – y < 0 ⇒ x – y ≡ 2^{n} – |x – y| = 2^{n} – -(x – y) = 2^{n} – (y – x).

**Sign Extension**

2^{n} > 2^{n} – x ≥ 2^{n-1}.

*m* additional bits.

Sign extend: 2^{n} – x + Σ(i = 0 to m-1, 2^{n+i}).

Prove: 2^{n+m} – x = 2^{n} – x + Σ(i = 0 to m-1, 2^{n+i}).

2^{n+m} – x – (2^{n} – x + Σ(i = 0 to m-1, 2^{n+i})) = 2^{n+m} – Σ(i = 0 to m-1, 2^{n+i}) – 2^{n} = 2^{n+m} – 2^{n+m} = 0.

Starting from *s*, find the smallest prime *k ≥ s*.

Since *q – p* is small, *q – s* is small also. So *pk* is close to *pq*, i.e. *pq – pk* is small.

Starting from *pq*, since *k* is prime, exactly one *n* ∈ *{a, a + 1, a + 2, …, a + k – 1 = pq}* is not coprime with *k*. Using the method found here, * n = a + (-a mod k) *.

Let *d = gcd(n, pq)*. If *d > 1* then *d = p*. Otherwise choose the next *k* consecutive numbers less than *a* and repeat.

Runnable code in the Frink language:

p = 96436875510168134260978951531720215975911176926194651907111357743104310827706384687021784900521146900897417521181 q = 96436875510168134260978951531720215975911176926194651907111357743104310827706384687021784900521146900897417697981 if isPrime[p] println["p is prime"] if isPrime[q] println["q is prime"] println["prime difference:"] println[q - p] mysqrt[n] := { b = bitLength[n] m = 0 i = ceil[b/2] - 1 while i >= 0 { if (m+2^i)^2 <= n m = m + 2^i i = i - 1 } return m } pq = p * q s = mysqrt[pq] if s^2 <= pq && (s+1)^2 > pq println["sqrt function works"] else println["wtf"] k = nextPrime[s - 1] println["prime between q and s:"] println[k] println["prime, sqrt difference:"] println[k - s] i = pq - k + 1 do { n = i + (-i % k) d = gcd[n,pq] if d > 1 { println["good"] break } i = i - k } while i >= s]]>

II) *To do*

**ii)** *Skipped* (similar to **(i)**).

II) Suppose α is injective and α(~A) ⊄ ~α(A). Then there is a t ∈ T such that t ∈ α(~A) and t ∉ ~α(A) ⇒ there is an s_{1} ∈ ~A such that α(s_{1}) = t and t ∈ α(A) ⇒ there is an s_{2} ∈ A such that α(s_{2}) = t ⇒ α(s_{1}) = α(s_{2}) and s_{1} ≠ s_{2}. Contradiction. Thus α is injective ⇒ α(~A) ⊂ ~α(A).

III) α is surjective can’t imply α(~A) ⊄ ~α(A), otherwise a bijective map would contradict part (II). α is surjective can’t imply α(~A) ⊂ ~α(A) by the example in part (I).

]]>II) t ∈ α(A ∩ B) ⇒ there is an s ∈ A ∩ B such that α(s) = t ⇒ there is an s ∈ A and s ∈ B such that α(s) = t ⇒ t ∈ α(A) and t ∈ α(B). Thus α(A ∩ B) ⊂ α(A) ∩ α(B).

III) α = { (s_{1}, t_{1}), (s_{2}, t_{0}), (s_{3}, t_{0}) }. A ⊂ S = { s_{1}, s_{2} }. B ⊂ S = { s_{1}, s_{3} }. α(A ∩ B) = { t_{1} }. α(A) ∩ α(B) = { t_{1}, t_{0} }.

II) Suppose α is injective and there exist maps γ_{1}, γ_{2} of a set U into S such that γ_{1} ≠ γ_{2} but αγ_{1} = αγ_{2}. Then there is a u ∈ U such that γ_{1}(u) ≠ γ_{2}(u). So α(γ_{1}(u)) ≠ α(γ_{2}(u)). Contradiction. Conversely, by contraposition, if α is not injective there exists s_{1}, s_{2} such that s_{1} ≠ s_{2} and α(s_{1}) = α(s_{2}). Define γ_{1}: U → S as { (u, s_{1}) | u ∈ U }. Define γ_{2}: U → S as { (u, s_{2}) | u ∈ U }. Thus γ_{1} ≠ γ_{2} but αγ_{1} = αγ_{2}.

II) Since α is surjective, choose one and only one s in the fiber (section 0.3) over t ∈ im α such that (t, s) ∈ β for every t ∈ T. β is clearly a map and αβ = 1_{T}. Conversely, suppose α is not surjective. Then there exists a t_{1} ≠ α(s) for every s ∈ S. Since αβ = 1_{T}, α(β(t_{1})) = t_{1}. Contradiction.

III) For part (I) if β is unique, every element t ∈ T must be in the range of α. Otherwise the image under β, of each t not in the range of α, can be made arbitrarily different. Thus contradicting the uniqueness of β.

For part (II) suppose β is unique and α is not injective. Then there exists s_{1}, s_{2} such that α(s_{1}) = α(s_{2}) and s_{1} ≠ s_{2}. If (α(s_{1}), s_{1}) ∈ β, replace it with (α(s_{1}), s_{2}). If (α(s_{1}), s_{2}) ∈ β, replace it with (α(s_{1}), s_{1}). Thus β is not unique. Contradiction.

**b)** Suppose f is not injective. There exists x_{1}, x_{2} such that f( x_{1}) = f( x_{2}) and x_{1} ≠ x_{2}. Hence g(f( x_{1})) = g(f( x_{2})) and x_{1} ≠ x_{2}. Contradiction.

**c)** z = g(y) for some y, y = f(x) for some x ⇒ z = g(f(x))

**d)** Suppose g is not surjective. There exists z ≠ g(y) for every y ⇒ z ≠ g(f(x)) for every x. Contradiction.

**e)** X = ℕ, f: n → 2n+1, is injective and not surjective. f(n) = { 0 if n=0, n-1 otherwise } is surjective and not injective.

**f)** By **(b)** and **(d)**, f is injective and g is surjective. Suppose f is surjective and g is not injective. There exists y_{1}, y_{2} such that g( y_{1}) = g( y_{2}) and y_{1} ≠ y_{2}. So g(f( x_{1})) = g(f( x_{2})) and [y_{1} = f(x_{1})] ≠ [y_{2} = f(x_{2})] for some x_{1}, x_{2}. By definition of function x_{1} ≠ x_{2}, contradicting gf being bijective. Thus f is surjective ⇒ g is injective.