@@ -328,7 +328,40 @@ Naive-Polynomial-Evaluation(arr, x)
328
328
* LI and proof
329
329
``` cpp
330
330
(To avoid Greek letter Sigma, here is using sum (head, tail)() function instead)
331
- LI :
331
+ L.I. :
332
332
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
+
334
367
```
0 commit comments