Monday, July 19, 2010

Issues faced with Mule-2.2.1

Mule is one of the open-source(commercial support available) ESB. These are some of the showstoppers I faced while I used mule in one of my projects. (Things may get resolved in future versions though).
  1. It does not support multiple headers. So, what it means is that, If you're doing some kind of login and your server sends multiple Set-Cookie header to mule in response then mule will ignore all but last Set-Cookie header. To add to the trouble, you'll read RFC-2109 and believe that concatenating all the cookies(using comma as separator) inside single Set-Cookie header will resolve it but it'll not as browsers don't honor the spec in this regard.


  2. You can't set virtual host/port on a http request made from mule. So, if you want to use mule as a proxy to transparently pass the host header to the end server, well it will not.


  3. Do not use MuleMessage.getPayloadAsString() in case your payload is Input-Stream, as it will read the whole stream ignoring Content-Length "property" completely and that will result in issues if your response was a http message with large binary content. Content-Length might also get messed up in the end response.


  4. It is completely unintuitive, you will end up writing too much code inside xml configuration.

Tuesday, July 13, 2010

how to prove it - ch6, sec6.5(Closures Again) ex

Ex-1:
(a) Prove that F.
Its clear that BA and AA and also A is closed under f, hence AF. So F

Prove that F is closure of B under f.

Step-I: Prove that BF
Since for every CF, BC. Hence BF

Step-II: Prove that F is closed under f.
Let x be an arbitrary element of F. Let C be arbitrary element of F. Then xC and hence f(x)C. Since C is arbitrary, so CFf(x)F and hence f(x)F. Thus F is closed under f.

Step-III: F is smallest set closed under f s.t. B is its subset.
Let C be some set s.t. C is closed under f and BC. Then CF and hence FC. So F is indeed the smallest.

From Step I, II and III its clear that F is closure of B under f.

(b) Let C = nZ+Bn

Step-I: prove that BC
Since B1=B and B1C, hence BC

Step-II: prove that C is closed under f
Let x be arbitrary element of C. Then we can choose some positive integer n s.t. xBn. Then f(x)Bn+1. Then f(x)C. Thus C is closed under f.

Step-III: prove that C is smallest set closed under f s.t. B is its subset
Let D be some other set s.t. BD and D is closed under f. We'll prove by induction that for any positive number n, BnD and hence CD.

Base case: for n = 1
B1=B, so B1D

Induction step: Suppose n is arbitrary positive integer and BnD.

Let y be arbitrary element of Bn+1. Then we can choose some xBn s.t. f(x) = y. Since BnD, so xD and hence f(x)D. Then yD. Since y is arbitrary, so Bn+1D.

From the three steps above, its proven that C is closure of B under f.


Ex-2: Using the terminology from ex-1, B = {0}.
Then, B1 = B = {0}
B2 = {f(0)} = {1}
B3 = {f(1)} = {2}
B4 = {f(2)} = {3}
...

closure of {0} under f is nZ+Bn = {0,1,2,3,...} = Set of all natural numbers.


Ex-3: We'll imitate the reasoning followed in ex-1(a).

Let H = {C | BCA and fF, C is closed under f}

Step-I: prove that H
BA and AA and for every function f in F, A is closed under f. Hence AH. Thus H

So, H is defined. We will prove that H is closure of B under F.

Step-II: Prove that BH
Since for every CH, BC. Hence BH

Step-III: Prove that H is closed under F.
Let x be an arbitrary element of H. Let C be arbitrary element of H. Then xC. Let f be arbitrary element of F. Then f(x)C. Since C is arbitrary, so CHf(x)H and hence f(x)H. Thus H is closed under f. Since f is arbitrary, so H is closed under F.

Step-IV: H is smallest set closed under F s.t. B is its subset.
Let C be some set s.t. C is closed under F and BC. Then CH and hence HC. So H is indeed the smallest.

From Step I, II, III and IV its clear that H is closure of B under F. Hence closure of B under F exists.


Ex-4,5,6: I could not solve ex-4 and 5,6 are dependant on it. TODO


Ex-7: We'll use induction to prove it.

Base case: n = 1, Since RS, so R1S1

Induction step: let n be arbitrary positive integer and RnSn

Now, Let (x,y) be arbitrary element of A X A s.t. (x,y)Rn+1

Since Rn+1 = RnR, so (x,y)RnR. Then we can choose some zA s.t. (x,z)R and (z,y)Rn. Then (x,z)S and (z,y)Sn. Then (x,y)SnS. Then (x,y)Sn+1. Since (x,y) is arbitrary, so Rn+1Sn+1.


Ex-8:
(a) Let n be arbitrary positive integer.
RSR, so using result of ex-7, (RS)nRn. Similarly, (RS)nSn. Thus (RS)nRnSn. However, the two are not equal as is evident from following counterexample.
A = {1,2,3,4}
R = {(1,2), (2,4)}
S = {(1,3), (3,4)}

Then (RS)2= and R2S2 = {(1,4)}

(b) R(RS), so Rn(RS)n. Similarly, Sn(RS)n. Thus RnSn(RS)n. However, the two are not equal as is evident from following counterexample.
A = {1,2,3,4}
R = {(1,2), (2,4)}
S = {(2,3), (3,4)}

R2 = {(1,4)}
S2 = {(2,4)}

R2S2 = {(1,4), (2,4)}

RS = {(1,2), (2,4), (2,3), (3,4)}
(RS)2 = {(1,4),(2,4),(1,3)}

clearly the two are not equal.


Ex-9:
(a) Let d(a,b) = n and d(b,c) = m. Then
(a,b)Rn and
(b,c)Rm

Then (a,c)RmRn. Then (a,c)Rm+n. Hence d(a,c) (m+n) = d(a,b) + d(b,c)

(b) TODO


Ex-10:
(a) We'll prove it by induction.

Base case: n = 1
() Let (a,b) be arbitrary element of R1 that is R. Let us define a function f s.t. f(0) = a and f(1) = b. Clearly, f is R-path from a to b of length 1. So it exists
() Let f be an R-path from a to b of length 1. Then (f(0),f(1))R. Thus (a,b)R.

Induction step: Let n be a positive integer and Rn = {(a,b)AxA | there is an R-path from a to b of length n}

() Let (a,b) be arbitrary element of Rn+1. Then (a,b)RRn. Then we can choose some c s.t. (a,c)Rn and (c,b)R.
By induction hypothesis we can choose f, a R-path from a to c of length n. Then f(0) = a and f(n) = c. Then f{(n+1),b} is an R-path from a to b of length n+1.
() Let f be an R-path from a to b of length n+1. Let f(n) = c. Then f\{(n+1,b)} is an R-path from a to c of length n. So, by induction hypothesis, (a,c)Rn. Also, (f(n),f(n+1))R, so (c,b)R. Thus (a,b)RRn. Hence (a,b)Rn+1

(b) From theorem 6.5.2, S=nZ+Rn

() Let (a,b) be arbitrary element of S. Then we can choose some positive integer n s.t. (a,b)Rn. Then, by result proved in part(a), there exists an R-path from a to b of length n.

() Let n be arbitrary positive integer. Let f be an R-path from a to b of length n. Then (a,b)Rn. Then (a,b)S


Ex-11:
(a) We'll prove it by induction.

Base case: n = 1, Let (a,b) be arbitrary element of R1\iA. Then (a,b)R and ab. Let us define f s.t. f(0) = a and f(1) = b. clearly f is an R-path from a to b of length 1 and also f is one-to-one

Induction step: Let n be arbitrary positive integer. Let Rn\iA = {(a,b)AxA | there is a simple R-path from a to b of length atmost n}


Let (a,b) be arbitrary element of Rn+1\iA. Then (a,b)Rn+1 and ab. then (a,b)R1Rn. Then we can choose some cA s.t. (a,c)Rn and (c,b)R. By induction hypothesis, we can find some simple R-path from a to c of length m s.t. mn.
Now let us define g = f {(m+1,b)}. Consider following cases..

case#1: bRan(f)
Then g is one-to-one and also a R-path from a to b of length m+1 and (m+1)(n+1)

case#2: bRan(f)
Then we can choose some km s.t. f(k) = b. Let us define another function h s.t. h(x) = f(x) for {1,k}. Then h is one-to-one and an R-path from a to b of length k and kn+1.

from both the cases, its clear that there exists a simple R-path from a to b of length atmost n+1.

(b) From theorem 6.5.2, S = nZ+Rn

() Let (a,b) be arbitrary element of S\iA. Then (a,b)S and ab. Then we can choose some positive integer n s.t. (a,b)Rn. Using result of part-a, there exists a simple R-path from a to b of length atmost n.

() Let f be a simple R-path from a to b of length n. Then f is one-to-one, and hence f(0)f(n) and hence ab and so (a,b)iA. Also from ex-10(a) (a,b)Rn and hence (a,b)S. Since (a,b)S and (a,b)iA, so (a,b)S\iA.


Ex-12:
(a) Since d(a,b) = n, so by definition of the distance as given in ex-9, (a,b)Rn and there don't exist any number m smaller than n s.t. (a,b)Rm.
Also since ab, so (a,b)iA. Then (a,b)Rn\iA. Then by result of ex-11(a) we can conclude that there is a simple R-path from a to b of length atmost n.
Now we will prove by contradiction that a simple R-path from a to b of length smaller than n can not exist and hence there is a simple R-path from a to b of length n.

Assume there is a simple R-path from a to b of length m and m < n. Then by ex-10(a), (a,b)Rm. But this is a contradiction as d(a,b) = n. Hence there is a simple R-path from a to b of length n.

(b) As d(a,a) = n, so (a,a)Rn. Then by ex-10(a), there is a R-path, let us call if f, from a to b of length n.
Then f(0) = a = f(n).

Let i and j be arbitrary positive integers smaller than n s.t. f(i) = f(j) = c where cA.

Since f(0) = a and f(i) = c, clearly f is an R-path of length i from a to c and hence by ex-10(a), (a,c)Ri.
Let us define h(x) = f(x+j). Then h(0) = f(j) = c and h(n-j) = f(n) = a. Clearly h is an R-path from c to a of length n-j and hence again by ex-10(a), (c,a)Rn-j
Thus (a,a)Rn-jRi. And then (a,a)Rn-j+i. Since d(a,a) = n, so (n-j+i)n. Then ij.

Using above reasoning by switching roles of f(i) and f(j), we can come to the conclusion that ji.

Since ij and ji, so i=j. Since i and j are arbitrary positive integers smaller than n, so i<nj<n(f(i)=f(j)i=j)


Ex-13: Let f:jnA be a simple R-path of length n where jn = {0,1,2,3,...,n}

Then size of Dom(f) = Size of jn = n+1
size of Ran(f) = size of A = m

Since f is one-to-one, so n+1m. Then n(m-1) . Thus n can atmost be m-1. Hence maximum possible length of a simple R-path is m-1.

Now we will prove that, for any n > m we can choose some l < m s.t. RnRl.
Let (a,b) be arbitrary element of Rn. Let d(a,b) = l. Then by ex-12(a), there is a simple R-path from a to b of length l. Then l < m. Since d(a,b) = l, hence (a,b)Rl. Since (a,b) is arbitrary, so RnRl
Since n is arbitrary, so n>ml<m(RnRl)

So, {Rnn>m}{Rn1nm}

Then S = {Rnn>1} = {Rn1nm}


Ex-14: Base case: n = 1, x = (1+1)! + 2 = 2! + 2 = 4
i can only be 0 in this case and clearly (i+2) = 2 divides (x+i) = 4

Induction step: Suppose n is an arbitrary positive integer, define x = (n+1)! + 2, s.t. for every i s.t. 0in-1, (i+2)|(x+i).

Let y = (n+2)! + 2. Let us consider following possible set of cases.

Case#1: i = n
Then (i+2) = (n+2) and (y+i) = (n+2)! + (n+2) = (n+2)[(n+1)!+1]. clearly (i+2)|(y+i)

Case#2: i < n
y+i = (n+2)! + 2 + i
= (n+2).(n+1)! + (2+i)
= (n+2)[(n+1)! + (2+i) - (2+i)] + (2+i)
= (n+2)[(n+1)! + (2+i)] - (n+2)(2+i) + (2+i)
= (n+2)(x+i) - [(n+2) - 1](2+i)
= (n+2)(x+i) - (n+1)(i+2)

by induction hypothesis, (i+2)|(x+i) and also (i+2)|[(n+1)(i+2)].

Thus (i+2)|(y+i)

Its clear from above cases that for every i s.t. 0in, (i+2)|(y+i)

Saturday, July 3, 2010

how to prove it - ch6, sec6.4(Strong Induction) ex

Strong induction is a variant of mathematical induction that is used to prove the goals of the form nNP(n).

To Prove a goal of the form nNP(n)
Prove that n[(k<nP(k))P(n)], where n and k both are natural numbers. Note that no base case is necessary in a proof by strong induction.

Why it works?
If we proved n[(k<nP(k))P(n)]. Then plugging n = 0, we get (k<0P(k))P(0). Now, k<0P(k) is vacuously true as there are no natural numbers smaller than 0. Hence P(0) is true. Now keep applying the strong induction hypothesis to see that P(n) is true for any natural number.

Note:
I highly recommend that base case should atleast be checked if not proved. Because, not checking the base case, can lead to false proofs as following. (I'm taking ex-17(a) from section-6.1)

Q. Can you point out the error in following proof?

Theorem: Prove that for all nN, 1.30+3.31+5.32+..+(2n+1)3n=n3n+1

Proof:

Let n be arbitrary natural number. Suppose, for all natural numbers k smaller than n,
1.30+3.31+5.32+..+(2k+1)3k=k3k+1

Since (n-1) < n, Then it follows from our assumption that
1.30+3.31+5.32+..(2n-1)3n-1=(n-1)3n

So, 1.30+3.31+5.32+..+(2n+1)3n
= 1.30+3.31+5.32+..(2n-1)3n-1+(2n+1)3n
= (1.30+3.31+5.32+..(2n-1)3n-1)+(2n+1)3n
= (n-1)3n+(2n+1)3n
= 3n.3n
= n3n+1

Hence, by the assumptions of strong induction, 1.30+3.31+5.32+..+(2n+1)3n=n3n+1

Ans. To apply the induction hypothesis "for all natural numbers k smaller than n ..." to n-1, you need not only that (as you said) n-1 < n but also that n-1 is a natural number. That fails when n=0, so your argument doesn't cover the case n=0. – Andreas Blass [http://mathoverflow.net/questions/11964/strong-induction-without-a-base-case/]

============================================================================================


Ex-1

Givens:
n[(k<nP(k))P(n)]
Q(n) = k<nP(k)

(a) () Suppose nQ(n). Let n be arbitrary. It follows from our assumption that Q(n+1). Then k<(n+1)P(k). In particular we can choose k = n to see that P(n). Since n is arbitrary, so nP(n)

() Suppose nP(n). So for any n, for every k < n, P(k). Then k<nP(k). Then Q(n). Since n is arbitrary, so nQ(n)

(b) Base case: For n = 0, Q(0) = k<0P(k) , since there is no k smaller than 0 so this statement is vacuously true.

Induction step: Let n be arbitrary natural number and Q(n). Then k<nP(k). Then it follows from the givens that P(n). Thus k<(n+1)P(k). So Q(n+1).


Ex-2 Let q be arbitrary natural number. Suppose, for all k < q, ¬pN(pk=2).

Assume, we can choose a natural number p s.t. pq=2. Then, following the logic used in theorem 6.2.5, we come to the conclusion that p and q both are even. Now, let us say p' = p/2 and q' = q/2. Then, pʹqʹ=2. Since q' < q, so this contradicts with our induction hypothesis. Hence we can not choose such a natural number p. Hence k<(q+1)[¬pN(pk=2)]. Since q is arbitrary, so 2 is irrational.


Ex-3
(a) Assume 6 is rational. Let S = { qZ+pZ+(pq=6) }. Then S. So, using well-ordering-property we can choose the smallest element of S, say q, and a positive integer p s.t. pq=6.
Then, p2q2=6
=> p2=6q2

so p2 is even and hence p is even, then we can choose a p' such that p = 2p'.

Then, (2pʹ)2=6q2
=> 4(pʹ)2=6q2
=> 2(pʹ)2=3q2

Then 3q2 is even and hence q2 is even and hence q is even, then we can choose a q' such that q = 2q'.

Also, since pq=6
=> pʹqʹ=6

so clearly qʹS and also qʹ<q. This contradicts with the assumption that q is smallest element of S and hence 6 is irrational.

(b) Assume 2+3 is rational. Then we can choose positive integers p and q s.t.
pq=2+3

On squaring both sides we get

p2q2=2+3+26
=> p2q2=5+26
=> 6=p2-5q22q2

Then , 6 is rational. this is a contradiction with result proved in part(a). Hence 2+3 is irrational.


Ex-4 Let n be arbitrary natural number s.t. n12. Suppose for every k < n, there is some combination of blue and red beads that is worth k credits.

Let us consider the following cases.

Case#1: n15
Then (n-3)12 and (n-3)<n. It follows from induction hypothesis that we can choose b blue and r red beads s.t. 3b + 7r = (n-3).
Then n = 3(b+1) + 7r.

Case#2: n = 12
n = 3(4) + 0(7)

Case#3: n = 13
n = 3(2) + 7(1)

Case#4: n = 14
n = 3(0) + 7(2)

Its clear from all these cases that for every n12 we can choose some combination of red and blue beads that worth n credits.


Ex-5 Let n be arbitrary natural number s.t. n1. Suppose for every k < n, xk+1xk is integer.

Now, from induction hypothesis, xn-1+1xn-1 and x+1x, both are integers.

Hence (xn-1+1xn-1)(x+1x) is an integer
=> xn+1xn-2+xn-2+1xn is an integer
=> (xn+1xn)+(xn-2+1xn-2) is an integer

Since (n-2) < n, so (xn-2+1xn-2) is an integer. And hence, xn+1xn is also an integer.


Ex-6
(a) Let n be arbitrary natural number. Suppose, for every k < n, i=0kFi=Fk+2-1

Now, i=0nFi
= (i=0n-1Fi)+Fn (apply induction hypothesis to get...)
= Fn+1-1+Fn
= Fn+1+Fn-1
= Fn+2-1

(b) Let n be arbitrary natural number. Suppose, for every k < n, i=0k(Fi)2=FkFk+1

Now, i=0n(Fi)2
= (i=0n-1(Fi)2)+(Fn)2 (apply induction hypothesis to get...)
= Fn-1Fn+(Fn)2
= Fn(Fn-1+Fn)
= FnFn+1

(c) Let n be arbitrary natural number. Suppose, for every k < n, i=0kF2i+1=F2k+2

Now, i=0nF2i+1
= (i=0n-1F2i+1)+F2n+1 (apply induction hypothesis to get...)
= F2(n-1)+2+F2n+1
= F2n+F2n+1
= F2n+2

(d) Scratchwork:
i=00F2i=0=F2.0+1-1
i=01F2i=1=F2.1+1-1
i=02F2i=4=F2.2+1-1
i=03F2i=12=F2.3+1-1
i=04F2i=33=F2.4+1-1

easy guess... i=0nF2i=F2n+1-1

Proof:
Let n be arbitrary natural number. Suppose, for every k < n, i=0kF2i=F2k+1-1

Now, i=0nF2i
= i=0n-1F2i+F2n (apply induction hypothesis to get...)
= (F2(n-1)+1-1)+F2n
= F2n-1+F2n-1
= F2n+1-1


Ex-7
(a) Let m be an arbitrary natural number greater than or equal to 1. Let n be an arbitrary natural number. Suppose for every k < n, Fm+k=Fm-1Fk+FmFn+1

Let us consider following cases.

Case#1: n = 0
Then LHS = Fm+0=Fm
RHS = Fm-1F0+FmF0+1 = 0+FmF1 = Fm
clearly LHS = RHS

Case#2: n = 1
Then LHS = Fm+1
RHS = Fm-1F1+FmF2 = Fm-1+Fm = Fm+1
clearly LHS = RHS

Case#3: n2
Fm+n
= Fm+n-1+Fm+n-2 (apply induction hypothesis to get...)
= (Fm-1Fn-1+FmFn)+(Fm-1Fn-2+FmFn-1)
= Fm-1(Fn-1+Fn-2)+Fm(Fn+Fn-1)
= Fm-1Fn+FmFn+1

clearly, by strong induction, Fm+n=Fm-1Fn+FmFn+1

(b) Let m be an arbitrary natural number greater than or equal to 1. Let n be an arbitrary natural number greater than or equal to 1. Suppose for every k < n, Fm+k=Fm+1Fk+1+Fm-1Fn-1

Let us consider following cases.

Case#1: n = 2
LHS = Fm+2
RHS = Fm+1F3-Fm-1F1 = 2Fm+1-Fm-1 = Fm+1+Fm+1-Fm-1 = Fm+1+Fm+Fm-1-Fm-1 = Fm+1+Fm = Fm+2
clearly, LHS = RHS

Case#2: n = 3
LHS = Fm+3
RHS = Fm+1F4-Fm-1F2 = 3Fm+1-Fm-1 = 2Fm+1+Fm+Fm-1-Fm-1 = 2Fm+1+Fm = Fm+1+Fm+2 = Fm+3
clearly, LHS

Case#3: n > 3
Fm+n
= Fm+n-1+Fm+n-2 (apply induction hypothesis on both terms)
= (Fm+1Fn-Fm-1Fn-2)+(Fm+1Fn-1-Fm-1Fn-3)
= Fm+1(Fn+Fn-1)-Fm-1(Fn-2+Fn-3)
= Fm+1Fn+1-Fm-1Fn-1

Its clearly from above 3 cases that for any natural number n1, Fm+n=Fm+1Fn+1-Fm-1Fn-1

(c) Let n be an arbitrary natural number. Suppose for every k < n, (Fk)2+(Fk+1)2=F2k+1

Let us consider following cases.

Case#1: n = 1
(F1)2+(F2)2=12+12=1+1=2=F3=F2(1)+1

Case#2: n = 2
(F2)2+(F3)2=12+22=1+4=5=F5=F2(2)+1

Case#3: n > 3
(Fn)2+(Fn+1)2
= (Fn-1+Fn-2)2+(Fn+Fn-1)2
= (Fn-1)2+(Fn-2)2+2Fn-1Fn-2+(Fn)2+(Fn-1)2+2FnFn-1
= ((Fn-1)2+(Fn-2)2)+((Fn)2+(Fn-1)2)+2(Fn-1Fn-2+FnFn-1)

In part(a) put m = n and n = n-2 to check that Fn-1Fn-2+FnFn-1=F2n-2, so above term becomes...

= ((Fn-1)2+(Fn-2)2)+((Fn)2+(Fn-1)2)+2F2n-2 (apply induction hypothesis to get)
= (F2n-3)+(F2n-1)+2F2n-2
= (F2n-3+F2n-2)+(F2n-1+F2n-2)
= F2n-1+F2n
= F2n+1

From above 3 cases, its clear that for all natural number n, (Fn)2+(Fn+1)2=F2n+1

(d) Let m be any arbitrary positive integer.

Let n be arbitrary positive integer and for every k < n, if m|k then FmFk.

Now, let m|n. Then m = nk for some positive integer k.

Let us consider following possible cases

Case#1: k = 1
then m = n and clearly FmFn

Case#2: k > 1
Then Fn
= Fkm
= Fkm-m+m
= Fm+(k-1)m (apply part(a) result)
= Fm-1F(k-1)m+FmF(k-1)m+1

by induction hypothesis, FmF(k-1)m. Hence Fm(Fm-1F(k-1)m). Also, Fm(FmF(k-1)m+1)

So FmFn

(e) Its trivial to prove the base cases with n = 1 and n = 2, I'm skiping them.

Let n be arbitrary natural number s.t. n > 2 and for every k < n,

F2k-1=i=0k-12k-i-2i and
F2k=i=0k-12k-i-1i

Now, F2n-1
= F2n-2+F2n-3
= F2(n-1)+F2(n-1)-1 (now apply induction hypothesis)
= i=0n-22(n-1)-i-1i+i=0n-22(n-1)-i-2i
= i=0n-22n-i-3i+i=0n-22n-i-4i

Let us look consider the 2nd term..
i=0n-22n-i-4i (let i = j-1)
= j=1n-12n-j-3j-1 (let j = i)
= i=1n-12n-i-3i-1

So, F2n-1
= i=0n-22n-i-3i+i=1n-12n-i-3i-1
= (2n-30+i=1n-22n-i-3i)+(i=1n-22n-i-3i-1+n-2n-2)
= 1+i=1n-2(2n-i-3i+2n-i-3i-1)+1
= 1+i=1n-22n-i-2i+1
= 2n-0-20+i=1n-22n-i-2i+2n-(n-1)-2n-1
= i=0n-12n-i-2i

Using similar steps we can get the result for F2n


Ex-8:
(a) () Suppose a0,a1,a2... is Gibonacci sequence.
clearly, a0=c0=1
a1=c1=c
a2=c2

It follows from the assumption that a2=a1+a0
=> c2=c+1
=> c2-c-1

on solving above quadratic equation for c, we get that c is either 1+52 or 1-52

() Suppose c = 1+52 or c = 1-52, in both the cases
c2=c+1
=> cn=cn-1+cn-2
=> an=an-1+an-2

Hence a0,a1,a2... is Gibonacci sequence.

(b) Let n be an arbitrary natural number. Suppose for every k < n, ak=ak-1+ak-2

Now, an-1+an-2
= s(1+52)n-1+t(1-52)n-1+s(1+52)n-2+t(1-52)n-2
= s(1+52)n-2(1+52+1)+t(1-52)n-2(1-52+1)
= s(1+52)n-2(3+52)+t(1-52)n-2(3-52)
= s(1+52)n-2(1+52)2+t(1-52)n-2(1-52)2
= s(1+52)n+t(1-52)n
= an

(c) Scratchwork:
a0=s+t ...(i)

a1=s(1+52)+t(1-52)
=> 2a1=(s+t)+5(s-t)
=> s-t=2a1-a05 ...(ii)

we can easily solve equation (i) and (ii) to get

s = 5a0+(2a1-a0)510
t = 5a0-(2a1-a0)510

Formal Proof:

Let s = 5a0+(2a1-a0)510 and
t = 5a0-(2a1-a0)510

its trivial to check that
an=s(1+52)n+t(1-52)n holds true with chosen values of s and t for n = 0 and n = 1

from the result of part(b), a0,a1,a2,... is Gibonacci sequence if an=s(1+52)n+t(1-52)n for any real numbers s and t so it should be true for chosen values of s and t also.

Hence such s and t indeed exist.


Ex-9: In ex-18(c), put a0=L0=2 and a1=L1=1

Use s = 5a0+(2a1-a0)510
t = 5a0-(2a1-a0)510 to get

s = 1 and t = 1

thus the required formula is... for n2, Ln=(1+52)n+(1-52)n

And, from the analysis of ex-8(c) itself this should be correct.


Ex-10: Scratchwork:
Let us imitate ex-8(a) and assume an=cn

Since, an=5an-1-6an-2
=> cn=5cn-1-6cn-2
=> c2=5c-6
=> c2-5c+6=0
=> c2-2c-3c+6=0
=> c(c-2)-3(c-2)=0
=> (c-2)(c-3)=0

Thus either c = 2 or c = 3

Now imitate ex-8(b) to guess that

an=s2n+t3n, where s and t are some real numbers.

Since a0=-1, so s+t=-1 ... eq(i)

and since a1=0, so 2s+3t=0 ... eq(ii)

on solving eq(i) and (ii) we get

s = -3 and t = 2

So, an=2.3n-3.2n

Formal Proof:

The formula is an=2.3n-3.2n

Suppose for every k < n, ak=2.3k-3.2k

Let us consider following cases

Case#1: n = 0
RHS = 2.30-3.20=2-3=-1=a0 = LHS

Case#2: n = 1
RHS = 2.31-3.21=0=a1 = LHS

Case#3: n > 1
5an-1-6an-2 (apply induction hypothesis to get)
= 5(2.3n-1-3.2n-1)-6(2.3n-2-3.2n-2)
= 10.3n-1-15.2n-1-4.3n-1+9.2n-1
= 6.3n-1-6.2n-1
= 2.3n-3.2n
= an


Ex-11: clearly a0=0=F0, a1=1=F1 and a2=1=F2.

Now let n be arbitrary natural number. suppose for every k < n, ak=Fk

Now, an
12an-3+32an-2+12an-1
= an-3+3an-2+an-12 (apply induction hypothesis to get)
= Fn-3+3Fn-2+Fn-12
= (Fn-3+Fn-2)+2Fn-2+Fn-12
= Fn-1+2Fn-2+Fn-12
= 2(Fn-1+Fn-2)2
= Fn

so for all natural number n, an=Fn


Ex-12: Scratchwork:

we need to prove that # of elements in Pn=Fn+2=Fn+1+Fn
This gives a hint that # of elements Pn = # of elements in Pn-1 + in Pn-2

Let us check that for some values of n

P1 = {,{1}} , size = 2
P2 = {,{1},{2}}, size = 3
P3 = {,{1},{2},{3},{1,3}}, size = 5
P4 = {,{1},{2},{3},{4},{1,3},{1,4},{2,4}}, size = 8

clearly our guess about the sizes seems to be true.

Also, now its easy to see that for all n > 2

Pn = Pn-1 {X{n}XPn-2} (TODO: prove it)

Formal Proof:

# of elements in P1=2=F3
# of elements in P2=3=F4

Let n be arbitrary natural number greater than 2.

Then Pn=Pn-1 {X{n}XPn-2}

thus, # of elements in Pn = # of element in Pn-1 + in Pn-2 = Fn+1+Fn = Fn+2

Hence, for any natural number n s.t. n1, # of elements in Pn = Fn+2


Ex-13:
(a) Let us consider both the possible cases:
Case#1: n0
Then it follows directly from theorem-6.4.1(division theorem) that there exist integers q and r s.t. n = mq + r where 0r<m

Case#2: n < 0
Then -n is +ve. Hence we can choose some integers q and r s.t. 0r<m and
-n = qm + r
=> n = -qm - r
=> n = -qm - r + m - m
=> n = -(q+1)m + (m-r)

Let q' = -(q+1) and r' = (m-r). clearly q' and r' are integers and 0rʹ<m

so, n = q'm + r'

(b) We will prove it by contradiction. Let us assume there exist distinct integers q1,q2 and distinct integers r1,r2 s.t. 0r1,r2<m and
n=q1m+r1 and
n=q2m+r2

so, q1m+r1=q2m+r2
=> m=r2-r1q1-q2

Since 0r1,r2<m, so r2-r1<m.
Also, q1-q2>1

Thus r2-r1q1-q2<m. So m can not be equal to r2-r1q1-q2. So we have a contradiction and hence distinct q1,q2 and distinct r1,r2 are not possible. So for every n and m, there exist only unique integers q and r s.t. n = qm + r

(c) Let us choose m = 2. Then For every integer n, we can choose integers q and r s.t. n = 2q + r and 0r<2. So only 2 following cases are possible

Case#1: r = 0
Then n = 2q. Then n is even

Case#2: r = 1
Then n = 2q + 1. Then n is odd

Since n is arbitrary, so every integer is either even or odd.


Ex-14: Let a be maximum of 5k and k(k+1). Let n be an arbitrary integer greater than a. Using result of ex-13(a) we can choose some integers q and r s.t. n = kq + r and 0r<k.

Assume q4. Then n=kq+r4k+r5ka. Since na is not possible by assumption, hence q5. Then from example-6.1.3 it follows that 2qq2.

Now, assume qk. Then n=kq+rk2+rk2+k=k(k+1)a. Since na is not possible by assumption, hence q(k+1).

So, q(k+1)
=> q2q(k+1)=qk+q>qk+r=n

Thus q2n

Since 2qq2, so 2qn. Then 2(kq+r)2r.nk. Then 2(kq+r)nk. Thus 2nnk.


Ex-15:
(a) Suppose, for every m s.t. m1 and m < k, a1f1+a2f2+..+amfmO(g).

Now |f|
= |a1f1+a2f2+..+akfk|
= |(a1f1+a2f2+..+ak-1fk-1)+akfk|
a1f1+a2f2+..+ak-1fk-1+akfk

Since fkO(g) so we can choose some aZ+ and cR+ s.t. for every n > a, fk(n)cg(n)

By induction hypothesis, a1f1+a2f2+..+ak-1fk-1O(g), so we can choose some aʹZ+ and cʹR+ s.t. for every n > a',
a1f1(n)+a2f2(n)+..+ak-1fk-1(n)cʹg(n)

Let a'' be maximum of a and a'. Then for every n > a''

|f(n)|
a1f1+a2f2+..+ak-1fk-1+akfk
cʹg(n)+cakg(n)=(cʹ+cak)g(n)

Thus, fO(g)

(b) Using result of ex-14, for every positive integer k we can choose some positive integer a s.t. for every n > a, 2nnk. Then all of 1,n,n2,n3,.... are elements of O(2n) or O(g). So using result of part(a), f is also element of O(g).

Ex-16:
(a) We can choose integers s and t s.t. d = as + bt.

Also by division theorem we can choose integers q and r s.t. a = dq + r and 0r<d.

Then a = (as + bt)q + r
=> a = asq + btq + r
=> r = (1-sq)a + (-tq)b

Then rS. Since d is smallest element of S, so dr. But r < d. Hence, the only value possible for r is 0. Thus a = dq and Hence d|a. By similar argument we can prove that d|b also.

(b) We can choose integers s and t s.t. d = as + bt. Since c|a and c|b, so c|(as) and c|(bt) both. Hence c|(as+bt) and so c|d.


Ex-17:
(a) Suppose p divides ab. Let d be the greatest common divisor of a and p then by ex-16 we can choose integers s and t s.t.
d = as + pt

Since d is gcd of a and p, so it divides p. Since p is prime, so d is either 1 or p. Let us consider both the cases.

Case#1: d = 1
Then 1 = as + pt. Since p|ab, so we can choose some real number k s.t. ab = kp. Then a = kpb.
Then 1 = skpb+pt
=> b = skp + ptb
=> b = (sk + tb)p

Thus p divides b.

Case#2: d = p
Then p = as + pt
=> a = p(1-t)s

Thus p divides a.

From above 2 cases its clear that either p|a or p|b.

(b) Let n be an arbitrary natural number s.t. n1. Suppose for every 1k<n, if p divides a1a2a3...ak then pai for some i, 1ik.

Suppose p divides a1a2a3...an.
=> p divides (a1a2a3...an-1).an

then, by using result of ex-17(a) either p divides a1a2a3...an-1 or p divides an. Let us consider both the cases.

Case#1: p divides a1a2a3...an-1
Then, by induction hypothesis, we can choose some i, 1i(n-1) s.t. p divides ai

Case#2: p divides an

Thus we can choose some i, 1in s.t. p divides ai


Ex-18: We will use induction over j.

Base case: j = 1. Suppose p1,q1,q2,...,qk are all prime numbers s.t. p1=q1q2...qk. Since p1 is prime, so clearly k = 1 and p1=q1

Induction Step: Suppose j be an arbitrary integer s.t. j1 and for all k1 and for all non decreasing sequence of primes p1,p2,...,pj and q1,q2,...,qk if p1p2...pj=q1q2...qk then both the sequences are same.

Now suppose p1,p2,...,pj,pj+1 and q1,q2,...,qk are non-decreasing sequences of primes s.t.
p1p2...pjpj+1=q1q2...qk

clearly pj+1 divides q1q2...qk, so by result of ex-17(b) we can choose some i s.t. pj+1=qi. Since qiqk,
so pj+1qk ... (i)

Also, qk divides p1p2...pjpj+1, so by result of ex-17(b) we can choose some i s.t. qk=pipj+1. Thus qkpj+1... (ii)

From (i) and (ii), its clear that pj+1=qk.

Then p1p2...pj=q1q2...qk-1. By induction hypothesis both these sequences are same and hence the sequences p1,p2,...,pj,pj+1 and q1,q2,...,qk are same.


Ex-19: Scratchwork:
a0=1
a1=1+a0=2
a2=1+a0+a1=4
a3=1+a0+a1+a2=8
a4=1+a0+a1+a2+a3=16

we can guess that an=2n

There is another way to find it. Let us look at that

an+1=1+i=0nai
=> an+1=1+i=0n-1ai+an
=> an+1=an+an
=> an+1=2an
=> an+1=22an-1
=> an+1=23an-2
=> an+1=24an-3
...
...
=> an+1=2n+1an-n
=> an+1=2n+1a0
=> an+1=2n+1

Formal Proof:

The formula is, for any natural number n, an=2n

Base case: n = 0, a0=1=20

Induction step: Suppose for arbitrary natural number n, an=2n

Now, an+1
= 1+i=0nai
= 1+i=0n-1ai+an
= an+an
= 2an
= 2.2n
= 2n+1


Ex-20: Scratchwork:
Let Fn denotes nth fibonacci number.

a0=1=F2F1
a1=1+1=2=F3F2
a2=1+12=32=F4F3
a3=1+23=53=F5F4
a4=1+35=85=F6F5
a5=1+58=138=F7F6

easy enough to guess that an=Fn+2Fn+1

Proof:

Suppose for every k < n, ak=Fk+2Fk+1

Now, an
= 1+1an-1 (apply induction hypothesis to get)
= 1+FnFn+1
= Fn+1+FnFn+1
= Fn+2Fn+1