Skip to content

Commit 6a4d35d

Browse files
committed
add p2.3.c
1 parent d2e9a96 commit 6a4d35d

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

ch02/README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,40 @@ Naive-Polynomial-Evaluation(arr, x)
328328
* LI and proof
329329
```cpp
330330
(To avoid Greek letter Sigma, here is using sum(head, tail)() function instead)
331-
LI:
331+
L.I.:
332332
At the start of each iteration of the for loop of lines 2–3,
333-
y = sum(k = 0, k = n - (i + 1)) ()
333+
y = sum(k = 0, k = n - (i + 1)) (a(k + i + 1) * x ^ k)
334+
335+
I.:
336+
Prior to the first iteration,
337+
y = sum(k = 0, k = -1) (a(k + i + 1) * x ^ k)
338+
upper limit is lower than lower limit, this equation is meaningless, y = 0
339+
Hence, I holds.
340+
341+
M.:
342+
Suppose L.I. holds before i = i
343+
y = sum(k = 0, k = n - (i + 1)) (a(k + i + 1) * x ^ k)
344+
345+
by line 2 - 3, LHS becomes:
346+
y = a(i) + x * y
347+
= a(i) + x * ( a(i + 1) + a(i + 2) * x + ... + a(n) * x^(n - i - 1)
348+
= a(i) + a(i + 1) * x + a(i + 2) * x^2 + ... + a(n) * x^(n - i)
349+
350+
when i = i - 1 RHS becomes
351+
sum(k = 0, k = n - i) (a(k + i) * x ^ k)
352+
= a(i) + a(i + 1) * x + a(i + 2) * x^2 + ... + a(n) * x^(n - i)
353+
354+
LHS = RHS, hence M holds for next iteration.
355+
356+
T.:
357+
The termination condition is i = -1
358+
y = sum(k = 0, k = n - (-1 + 1)) (a(k - 1 + 1) * x ^ k)
359+
= sum(k = 0, k = n) (a(k) * x ^ k)
360+
Hence, T holds.
361+
362+
L.I. holds.
363+
364+
365+
366+
334367
```

0 commit comments

Comments
 (0)