# 尾递归

(define (fact n)
(cond
((= n 1) 1)
(else (* n (fact (- n 1))))))

(define (fact1 n)
(define (fact-iter product counter)
(cond
((= counter 1) product)
(else (fact-iter (* product counter) (- counter 1)))))
(fact-iter 1 n))
;;;Solve 4!
(fact 4)
(fact1 4)



;;; 求幂

(define (expr b n)
(if (= n 0)
1
(* b (expt b (- n 1)))))

;;;iter form
(define (expr1 b n)
(define (expr-iter b counter product)
(if (= counter 0)
product
(expr-iter b (- counter 1) (* b product))))
(expr-iter b  n 1))

(expr 4 5)
(expr1 4 5)


===>另外还有一种更快速的方法 ;; b^n =(b^(n/2))^2, n is even ;; b^n =(b*b^(n-1)) , n is odd

(define (fast-iter b n)
(cond
((= n 0) 1)
((even? n) (square (fast)))
(else (* b (fast-iter b (- n 1))))))



====>并最终得到尾递归的一般形式 结合求定积分

===>

(define (sum term a  next b)
(define (sum-iter a result)
(if <???>
<???>
(iter <???> <???>)))
(sum-iter <???> <???>)
)

##### 令狐冲
###### Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.