Lecture 001

int pow(int a, int b)
//@requires b>= 0;
  if (b == 0) return 1;
  return pow(a, b-1) *a;

:warning: check what pow(a, b-1) returns when b==0; we certainly want it to return a value other than 1 and a function. The function above will return 1 and exit.

int f(int x, int y)
//@requires y>=0
//@ensures \result == pow(a, b)
  int a = x;
  int b = y;

  int r = 1;
  while (y>1) {
    if (y % 2 == 1) {
      r = x*r;
    x = x*x;
    y = y/2;


:warning: //@requires should be before curly braces :warning: \result can only take the value after the function runs, so you have to copy the value. Otherwise, it should raise an error.

:warning: one-line comment @requires should be like the following, remember the @ :warning: the first function is O(n) while the second is O(log n)

/*@requires e>=0 @*/

:question: does c0 only have int? :question: when does = assigns a pointer, not a actual value

Table of Content