- 定义函数square,目的是计算给定自然数n的平方,但是不能用乘法运算。
Coq代码
Fixpoint square( n : nat ): nat := match n with |0 => 0 |S n' => square n' + n' + n' + 1 end. Compute (square 10).
运行截图
Fixpoint square( n : nat ): nat := match n with |0 => 0 |S n' => square n' + n' + n' + 1 end. Compute (square 10).