theory week10B_demo 
imports "~~/src/HOL/Hoare/HeapSyntax" 
begin


primrec
  fac :: "nat \<Rightarrow> nat"
where
  "fac 0 = 1"
| "fac (Suc n) = (Suc n) * fac n"


lemma "VARS B { True } B := 2 { B = 2 }"
  apply vcg
done

lemma 
  " VARS (x::nat) y r 
    {True (*TODO *)} 
    IF x>y THEN r:=x ELSE r:=y FI
    {False (*TODO*)} "
oops


lemma
  "VARS (A::int) B 
   { A = 0 \<and> B = 0 }
    WHILE A \<noteq> a
    INV { True (*TODO*) } DO 
      B := B + b; 
      A := A + 1
    OD
    {False (*TODO*) }"
oops


lemma factorial_sound:
  "VARS A B
  { A = n}
  B := 1;
  WHILE A \<noteq> 0 INV { True (*TODO *) } DO
    B := B * A;
    A := A - 1
  OD
  { B = fac n }"
oops

  

-- "Arrays"
  

lemma 
 "VARS I L 
 { True }
  I := 0;
  WHILE I < length L \<and> L!I \<noteq> key 
  INV { True (*TODO*)} DO
    I := I+1 
  OD
  { False (*TODO*) }"
oops




-- Pointers


lemma
 "VARS nxt p
  { List nxt p Ps \<and> X \<in> set Ps }
  WHILE p \<noteq> Null \<and> p \<noteq> Ref X
  INV {True (*TODO*) }
  DO p := p^.nxt OD
  { False (*TODO*) }"
oops

lemma "VARS tl p q pp qq
  {List tl p Ps \<and> List tl q Qs \<and> set Ps \<inter> set Qs = {} \<and> size Qs \<le> size Ps}
  pp := p;
  WHILE q \<noteq> Null
  INV { True (* TODO *)}
  DO qq := q^.tl; q^.tl := pp^.tl; pp^.tl := q; pp := q^.tl; q := qq OD
  {List tl p (splice Ps Qs)}"
thm splice.simps
oops
 
end