class_document

class_document - Example Matrix addition A[0..n-1, 0..m-1]...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Example Matrix addition A[0..n-1, 0..m-1] B[0..n-1, 0..m-1] {n>0 ^ m>0} C_INV: { A ir,ic 0 < =ir < r 0< = ic,< m: D[ir, ic] = A[ir, ic] + B[ir, ic] A jc 0<=jc < c : D[r, jc] = A[r, jc] + B[r, jc] } ^ T-INV: {0 < = r < =n ^ 0 < = c < =m} W (n, n-1 ……0) * (m,m-1,…0) (r1.c1) UNDER (r2,c2) if r1> r2 or r1=r2 ^ c1>c2 TF: (r,c) {n>0 ^ m>0} (r,c) := (0,0); {C_INV ^ T_INV} Loopselect {C_INV ^ T_INV}r/=n^ c /= m => D[r,c] := A[r,c] + B[r.c] ; c:=c+1 {C_INV ^ T_INV} Or {C_INV ^ T_INV}r/=n ^ c=m => c:=0; r:= r+1 {C_INV ^ T_INV} end loopselect; {A ir,ic 0 < =ir < n 0< = ic,<m D[ir, ic] = A[ir, ic] + B[ir, ic]} We need to prove that {C_INV ^ T_INV} are invariants We need to show that C_INV ^ -BB => A ir,ic 0 < =ir < n 0< = ic,<m D[ir, ic] = A[ir, ic] + B[ir, ic] We need to show that T_INV ^(r/=n^ c /= n) U (r/=n ^ c=n) => TF € W We need to show {T_INV ^ r/=n^ c = m ^ T-OLD= TF } c:=0 r:= r+1 TF UNDER T-OLD} And {T_INV ^ r/=n^ c /= m ^ T-OLD= TF } D[r,c] := A[r,c] + B[r.c] ; c:=c+1 {TF UNDER T-OLD} Nested loops: (three loops) A[0..n-1] B[0..m-1] C[0..p-1] {n>0,m>0,p>0} (a,b,c):=(0,0,0); while a!=n loop while b!=m loop while c!=p loop c:=c+1 end; (b,c) := (b+1,0) End; (a,b,c):= (0,0, a+1) end; {POST_CONDITION} {n>0,m>0,p>0} (a,b,c) := (0,0,0) Loopselect c!=p => c:=c+1 or b!=m ^ c=p => (b,c) := (b+1,0) or a!=n ^ b=m ^ c=p => (a,b,c):= (0,0, a+1) end loopselect; W (n, n-1, … )* (m, m-1,…) * (p,p-1,..) UNDER Lexicographic order with “>” (a1,b1,c1) UNDER (a2,b2,c2) if (a1=a2 ^ b1=b2 ^ c1>c2) or (a1=a2 ^ b1>b2) or a1>a2 ...
View Full Document

Page1 / 2

class_document - Example Matrix addition A[0..n-1, 0..m-1]...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online