Sunday, October 28, 2012
Drawing Function vs Fitting Model in R
layout(matrix(c(1,2), 1,2, byrow=TRUE))
# http://www.stat.umn.edu/geyer/5102/examp/reg.html
qftn <- function(x) x^2 * 3
curve(qftn, 1, 3, main = "Function: y = x^2 * 3")
x <- c(1:3)
y <- c(3, 12, 27)
plot(x, y, main="Fitting model: y = x^2 * 3")
model <- lm(y ~ I(x^2 * 3))
curve(predict(model, newdata = data.frame(x = x)), add = TRUE)
# May also draw the coordinate pairs, like so:
text(1,4, "(1,3)")
text(2,13, "(2,12)")
text(2.9,27, "(3,27)")
Wednesday, October 24, 2012
Goldbach Conjecture and odd numbers > 5
Prove that if every even natural number greater than 2 is a sum of two primes (the Goldbach Conjecture), then every odd natural number greater than 5 is a sum of three primes.
== Solution ==
This is equivalent to asking if every even natural number greater than 2 is a sum of two primes,
  |
\[
\begin{aligned}
\forall{(n \in \mathbb{N} \land n > 1)} \exists{(p,q \in \mathbb{P})}[p + q & = 2n]
\end{aligned}
\]
|
is it true that:
  |
\[
\begin{aligned}
\forall{(m \in \mathbb{N} \land m > 2)} \exists{(r,s,t \in \mathbb{P})}[r + s + t & = 2m + 1]
\end{aligned}
\]
|
Exploiting m > 2 and n > 1:
  |
\[
\begin{aligned}
\forall{(m \in \mathbb{N} \land m > 2)} \exists{(x \in \mathbb{N})}[x & = m - 1 > 1] \\
m & = x + 1 > 2
\end{aligned}
\]
|
Now,
  |
\[
\begin{aligned}
2m + 1 & = 2(x + 1) + 1 \\
& = 2x + 3 \\
\end{aligned}
\]
|
But x is greater than 1 which means 2x is an even number greater than 2, and therefore is a sum of two primes. Since 3 is prime, (2m + 1), an arbitrary odd natural number greater than 5, is therefore a sum of three primes.
Tuesday, October 23, 2012
Composite \(f(n) = n^2 + bn + c\)
Prove that there is a quadratic \(f(n) = n^2 + bn + c\), with positive integers coefficients b, c, such that \(f(n)\) is composite (i.e, not prime) for all positive integers n, or else prove that the statement is false.
== Attempt ==
  |
\[
\begin{aligned}
f(n) & = n^2 + bn + c \\
& = (n^2 + \frac{b}{2})^2 - \frac{b^2}{4} + c
\end{aligned}
\]
|
This means when
  |
\[
\begin{aligned}
c & = \frac{b^2}{4}
\end{aligned}
\]
|
Then,
  |
\[
\begin{aligned}
f(n) & = (n^2 + \frac{b}{2})^2
\end{aligned}
\]
|
which is composite !
12|\(n\) and 12|\(n^3\)
Prove or disprove the statement “An integer n is divisible by 12 if and only if \(n^3\) is divisible by 12.”
== Solution ==
If integer n is divisible by 12, for some integer m:
  |
\[
\begin{aligned}
n & = 12m \\
n^3 & = 12^3m^3
\end{aligned}
\]
|
Clearly, \(n^3\) is divisible by 12. How about the converse ? Is n divisible by 12 if \(n^3\) is divisible by 12 ? Note \(12 = 2^2 \times 3\), so one counter example would be:
  |
\[
\begin{aligned}
n^3 & = 2^3 \cdot 3^3 = 12 \cdot 18 \\
n & = 2 \cdot 3 = 6
\end{aligned}
\]
|
In other words, \(n^3\) is divisible by 12, but not n. Hence the converse is false.
Monday, October 22, 2012
Prove \(\sqrt{3}\) is irrational
Prove that \(\sqrt{3}\) is irrational.
== Attempt ==
First, let's prove the lemma that if the square of an integer n is divisible by 3, n must be divisible by 3. Why ? A integer can be written in only one of 3 forms:
  |
\[
\begin{aligned}
Case \space 1: n & = 3x \\
Case \space 2: n & = 3x + 1 \\
Case \space 3: n & = 3x + 2 \\
\end{aligned}
\]
|
where x is an integer. If we take the square of n in each case:
  |
\[
\begin{aligned}
Case \space 1: n^2 & = (3x)^2 = 9x^2 \\
Case \space 2: n^2 & = (3x + 1)^2 = 9x^2 + 6x + 1 = 3(3x^2 + 2x) + 1 \\
Case \space 3: n^2 & = (3x + 2)^2 = 9x^2 + 12x + 4 = 3(3x^2 + 4x + 1) + 1
\end{aligned}
\]
|
Note that only in case 1 when n is divisible by 3 would \(n^2\) be divisible by 3. This completes the proof of the lemma.
Now suppose \(\sqrt{3}\) is rational,
  |
\[
\exists{p,q \in \mathbb{N}}[\sqrt{3} = \frac{p}{q}]
\]
|
such that p and q has no common factors. Squaring both sides,
  |
\[
\begin{aligned}
3 & = \frac{p^2}{q^2} \\
3q^2 & = p^2
\end{aligned}
\]
|
This means \(p^2\) is divisible by 3. By the above lemma, this means p must be divisible by 3. Or p = 3r for some integer r.
  |
\[
\begin{aligned}
3q^2 & = p^2 = (3r)^2 = 9r^2 \\
q^2 & = 3r^2
\end{aligned}
\]
|
This means \(q^2\) is divisible by 3, and by the lemma above, q must be divisible by 3. To summarize, both p and q are divisible by 3, but this contradicts the initial assumption that p and q has no common factor!
Hence \(\sqrt{3}\) is irrational.
Sunday, October 21, 2012
Proof of perfect square
Prove or disprove the claim that for any positive integer m there is a positive integer n such that mn + 1 is a perfect square.
== Attempt ==
First, the claim can be expressed as:
  |
\[
\forall{(m,n \in \mathbb{N})} \exists {(r \in \mathbb{Z})} [m \cdot n + 1 = r^2]
\]
|
Observe that:
  |
\[
\begin{aligned}
m \cdot n + 1 & = r^2 \\
m \cdot n & = r^2 - 1 \\
m \cdot n & = (r + 1)(r - 1) \\
n & = \frac{(r + 1)(r - 1)}{m} \\
\end{aligned}
\]
|
This means if the claim is true, m must divide either (r + 1) or (r - 1):
  |
\[
\begin{aligned}
\exists{(x \in \mathbb{N})} [(m \cdot x = r + 1) \lor (m \cdot x = r - 1)]
\end{aligned}
\]
|
Or,
  |
\[
\begin{aligned}
\exists{(x \in \mathbb{N})} [(r = m \cdot x - 1) \lor (r = m \cdot x + 1)]
\end{aligned}
\]
|
For example, when m = 1, the smallest value of r such that n > 0 would be when x = 3. So:
  |
\[
\begin{aligned}
r & = 1 \cdot 3 - 1 & = 2 \\
n & = \frac{(2 + 1)(2 - 1)}{1} & = 3 \\
m \cdot n + 1 & = 1 \cdot 3 + 1 & = 2^2
\end{aligned}
\]
|
Given m >= 1, we can always pick a value x such that:
  |
\[
\begin{aligned}
r = m \cdot x - 1 >= 2
\end{aligned}
\]
|
This is when:
  |
\[
\begin{aligned}
x >= \frac{3}{m}
\end{aligned}
\]
|
which means we can always find a value r (from m and x) and n (from r and m) that satisfies the claim. This completes the proof.
Thursday, October 18, 2012
What's the laziest possible thing a programmer can do ?
Ask the above question ! Or, in short, recursion :)