Properties Of Integers
Summary
A specail property exhibited by the subset of positive integers
The triangular numbers ti =i(i+1)/2 made triangulars |
The harmonic numbers |
The Fibonacci numbers |
The Lucas numbers L0 = 2, L1 = 1; and Ln = Ln-1 + Ln-2 for n ∈Z+ with n ≥ 2 |
The Eulerian numbers C(n+1, r) = C(n, r) + C(n, r-1) |
The primes |
When x,y ∈Z, we know that x+y, xy, x-y ∈Z. Thus we say that the set Z is closed under (the binary operations of) addition, multiplication, and subtraction.
The primes turn out to be the “building blocks” of the integers.
The Well-Ordering Principle
We find that we can define the set of positive elements of Z as
But we cannot represent Q+ or R+ using ≥ as we did for Z+
That is, X contains a least smallest elements.
The Well-Ordering Principle: Every nonempty subset of Z+ contains a smallest element.(We ofen express this by saying that Z+ is well ordered.)
The Pinciple of Mathematical Induction. Let S(n) denote an open mathematical statement (or set of such open statements) that involves one or more occurrences of the variable n which represents a positive integer.
- If S(1) is trues; and
- If whenever S(k) is trues (for some particular. But arbitrarily chosen, k ∈ Z+), then S(k+1) is true;
Part (a) is referred to as the basis step, while that in part (b) is called the inductive step.
這種方法的原理在於:首先證明在某個起點值時命題成立,然後證明從一個值到下一個值的過程有效。當這兩點都已經證明,那麼任意值都可以通過反覆使用這個方法推導出來。把這個方法想成多米諾效應也許更容易理解一些。例如:你有一列很長的直立着的多米諾骨牌,如果你可以:
-
證明第一張骨牌會倒。
-
證明只要任意一張骨牌倒了,那麼與其相鄰的下一張骨牌也會倒。
Set Examples of Mathematical Induction = null;
triangular number
1
1+2=3
(1+2)+3=6
(1+2+3)+4=10
(1+2+3+4)+5=15
...
The Sum of Squares
Cubic |
Procedure SumOfSquares1 (n: positive integer) Begin Sum := 0 For i := 1 to n do Sum := sum + End |
Qadratic |
---|
Procedure sumOfSquares2 (n: positive integer) Begin Sum := n * (n+1) * (2 * n + 1) / 6 end |
to determine whether , we must compare no more than times
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
3 |
6 |
7 |
10 |
11 |
16 |
20 |
33 |
56 |
low | mid | high |
Mathematical Induction in program.
while n ≠ 0 do
Begin
x := x * y
n := n – 1
end
answer := x
The flow chart
start |
|
Initialize the real variables x,y and the nonnegative integer variable n |
|
While n ≠0 |
|
X := x * y N = n - 1 |
Answer := x End |
Mathematical Induction And The SubSet
因爲新元素可以加入原有堆和追加爲一個新堆兩種選擇 | ||
---|---|---|
(n=1) | 1 | |
(n=2) | 2 | |
1 + 1 | ||
(n=3) | (1) | 3 |
(2) | 1 + 2 | |
(3) | 2 + 1 | |
(4) | 1 + 1 + 1 |
Principle of Mathematical Induction – Alternative Form
- If S(n0),S(n0+1),S(n0+2),…S(n1-1), and S(n1) are true; and
- If whenever S(n0), S(n0+1),S(n0+2) ,…S(k-1), and S(k) are true for some(particular but arbitrarily chosen) k ∈ Z+, where k ≥ n1, then the statement S(k+1) is also true
Then S(n) is true for all n ≥ n0
real world model a lamberjack, I 瞎編的 Laugh death you know! (一般有個簡陋的木架子防倒的吧!)
A lamberjack |
Logs total = 4n + 1 Layer = n |
Layern+1 = layern + 2 Layer1 = 6 |
Real world model compare
設計模式中的迭代模式,其目標也是將Items變成Well-Ordering化,便於執行迭代 |
比較、查找、等算法,都有一個前提,Items一般都是Well-Ordering的。慄如:1 班有40個學生,一天體育老師讓他們排成四隊....(中值法排隊,啊不,排序) |
Recursive
Recursive definition (associative)
Proposition Recursive
P1 ∧ (P2 ∧ P3) ⇔ (P1 ∧ P2) ∧ P3
Sets Recursive
The liner algorithm we learned on textbooks
- allot memory which A1 ∩ A2 ∩ A3,…An
- n -> A1
- n = n + 1 and P(n) = An
a recursively defined set X. start with an initial collection of elements that are in X – and this provides the base of the recursion. Then we provide a rule or list of rules that tell us how to find new elements in X from other elements already known to be in X.
real world recursion
感覺如果 也叫做遞歸的話
set real world recursion Lucas numbers = null
栗子:線性相關的狀態變化
(P -> S) ∧ Q -> R
這是個啥?假設 P=餓了,Q=飯錢夠,R=喫飽了。狀態第一版。感覺這個狀態怪怪的,不連續,不閉包 (@_@;)
剛喫飽的博主 --> 餓了去喫飯 --> 夠飯錢 --> 喫飽了
第二版
剛喫飽的博主 --> 餓了 && 夠飯錢 --> 喫飽了
Primes Numbers
If a, b Z and b 0, we say that that b divides a, and we write b|a, if there is an integer n such that a = bn. When this occurs we say that b is a divisor of a, or a is a multiple of b.
1 | 1|a and a|0 |
2 | [(a|b) (b|a)] => a = b |
3 | [(a|b) (b|c)] => a|c |
4 | a|b => a|bx, for all x Z |
5 | If x = y + z, for some x, y, z Z, and a divides two of the three integers x, y, and z, then a divides the remaining integer. |
6 | [(a|b) (a|c)] => a|(bx +cy), for all x, y Z .(The expression bx + cy is called a linear combination of b, c) |
7 | For 1 i n, let . If a divides each , then a|, where for all 1 i n |
舉個栗子:兩個圓筒,一個9升,一個4升,怎樣才能得到6升水啊?
問題即爲:假設a,b 爲整數,讓9a + 4b爲6的倍數。可以求得 a= 2, b = -3(2 * 9 + 4 * (-3) = 6)。
我們得到一個 {9, 4},下面我們可以推導還有哪些圓筒組合可以得到 6 升水。
根據 4 我們可以得到 {9 * 2, 4 * 2} = {18, 8},用18升和8升的圓筒也可以做到 (18 * 2 + 8 * (-3)) = 12,艾瑪,匡瓢了!
根據 5 我們可以得到 {9*2 - 6, 4 * 2 - 6} = {12, 2},用12升和2升的圓筒也可以做到(12 * 1 + 2 * (-3)) = 6。哈哈
重複以上兩步,就可以獲得一系列可以得到 6 升水的圓筒組合了(儘管博主還是直接拿 6 升的圓筒最省事<( ̄ c ̄)y▂ξ)
Using this binary operation of integer division we find ourselves in the area of mathmatics called number theory. which examines the properties of integers and other sets of numbers.
which have exactly two positive divisors, these integers are called primes.
If n Z and n is composite, then there is a prime p such that p|n
證明過程: | |
1 | 我們假設存在不能被質數整除的合數 |
2 | 這些合數組成一個集合 S 且 S 不爲空 |
3 | 根據 Well-Ordering Principle ,S 一定存在一個最小元素,假設這個元素爲 m |
4 | m 是一個合數,根據合數的性質 |
5 | 和 都是正整數, 和 |
6 | m 是 S 中最小元素,,也就是說 能被素數整除 或者 本身就是素數,也就是說 |
7 | 因爲 且 根據 (a|b => a|bx, for all x Z)得到 p|m,m是能被素數整除的合數,矛盾,命題得證 |
There are infinitely many primes.
The Division Algorithm. If a, b Z, with b > 0, then there exist unique q, r Z with a = qb + r, .
證明過程: | |
1 | a = qb + r, ,當 r = 0 時,a 能被 b 整除 b|a ,結論成立,考慮 a 不能被 b整除 |
2 | 在 q 和 r 兩個變量中 r 得條件最多,我們從條件最多的變量 r 開始分析,r = 0 時,成立。考慮 |
2.1 | 同上一個證明過程,我們有 r 的取值集合 |
2.1.1 | 當 時,令 t = 0, |
2.1.2 | 當 時,令 t = a - 1,a - tb = a - (a - 1)b = a(1 - b) + b, 因爲 ,所以 a(1 - b) + b > 0 |
2.1.3 | |
2.2 | 根據 Well-Ordering Principle ,S 一定存在一個最小元素,假設這個元素爲 r 且 |
2.2.1 | 如果 r = b, a = (q + 1)b 這與 a 不能被 b整除 矛盾 |
2.2.2 |
如果 r > b |
2.2.2.1 | 假設 r = b + c, c 爲 增量 |
2.2.2.2 | a - qb = r = b + c c = a - (q + 1)b |
2.2.2.3 | 這和 r 時 S 中的最小元素相矛盾 |
2.3 | S 最小元素 r 存在,且 r < b |
3 | 下面證明唯一性 |
3.1 | 假設 q,r 不唯一,假設存在 |
3.2 | 設 有 和 且 和 |
3.3 | |
3.4 | 因爲 我們得出矛盾 ,矛盾 |
4 | 命題得證 |
pseudocode of integer division
procedure IntegerDivision(a, b : Integers)
begin
if a = 0 then
begin
quotient := 0
remainder := 0
end
else
begin
r := abs(a) {the absolute value of a }
q := 0
while r >= b do
begin
r := r - b
q := q + 1
end
if a > 0 then
begin
quotient := q
remainder := r
end
else if r = 0 then
begin
quotient := -q
remainder := 0
end
else
begin
quotient := -q -1
remainder := b - r
end
end
end
實際應用:數制轉換
十進制78
78 ÷ 2 = 39 餘 0
39 ÷ 2 = 19 餘 1
19 ÷ 2 = 9 餘 1
9 ÷ 2 = 4 餘 1
4 ÷ 2 = 2 餘 0
2 ÷ 2 = 1 餘 0
1 ÷ 2 = 0 餘 1 (商爲0結束)
倒序得到 1001110 即爲對應的二進制
an algorithm
- an algorithm is a list of precise instructions designed to solve a particular type of problem - not just one special case
- In general, we expect all of our algorithms to receive input and provide the needed result(s) as output
- Also an algorithm should provide the same result whenever we repeat the value(s) for the input. which means each instruction is unique, and on any results depending on only the (initial) input.
- the instructions must be described in a simiple yet unambiguous manner, which can be executed by a machine.
- algorithms cannot go on indefinitely
the greatest common divisor algorithm
procedure gcd(a, b : positive integers)
begin
r := a mod b
d := b
while r > 0 do
begin
c := d
d := r
r := c mod d
end
end {gcd(a,b) is d, the last nonzero remainder}
if and p is prime, then p|ab => p|a or p|b
Every integer n > 1 can be written as a product of primes uniquely.