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.
一种证明方法,这是很多证明中需要的工具,它在计算机的科学计算中使用非常重要(参见 Natural Deductive logic)
- 基准:首个为真
- 归纳假设:假设为真 ,证明 k + 1 为真
- 结论:所有的 n 为真
这种方法的原理在于:首先证明在某个起点值时命题成立,然后证明从一个值到下一个值的过程有效。当这两点都已经证明,那么任意值都可以通过反复使用这个方法推导出来。把这个方法想成多米诺效应也许更容易理解一些。例如:你有一列很长的直立着的多米诺骨牌,如果你可以:
-
证明第一张骨牌会倒。
-
证明只要任意一张骨牌倒了,那么与其相邻的下一张骨牌也会倒。
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▂ξ)
Euclidian Algorithm: If ,then
欧几里得算法又称辗转相除法,是指用于计算两个非负整数a,b的最大公约数。应用领域有数学和计算机两个方面。计算公式gcd(a,b) = gcd(b,a mod b)。
Modular Arithmetic: If , then
余数定理:
[0] = { ... , -6, -3 ,0 , 3, 6, ...} mod 3
[1] = { ... , -5, -2 ,1 , 4, 7, ...} mod 3
[2] = {... -4, -1, 2, 5, ..} mod 3
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.