Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. 1.Factorial
  2.  
  3. {N ≥ 0 } // precondition
  4. {1==1} // by consequence rule
  5. {1 == product(int k in(1..1); k} // by assign and compose and maths
  6. int x = 1;
  7. {x == product(int k in(1..0+1); k} // by assign and compose
  8. int i = 0;
  9. {x== product (int k in (1..i+1); k} // invariant
  10. while (i != N)
  11. {x == product (int k in (1..i+1); k} ^ i!=N} // Invariant and guard
  12. {x*(i+1)== product(int k int(1..i+1); k} // by assign and compose
  13. i = i + 1
  14. {x*i == product(int k in(1..i); k} //by assign
  15. x = x * i;
  16. {x == product (int k in (1..i); k} // invariant
  17. {x == product {int k in (1..i); k} ^ N==i} //invariant and not(guard)
  18. {x == product {int k in (1..N); k}} // postcondition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement