formath school 2012 p 1
play

Formath School 2012 p.1 Motiv a tion T ake a las s i - PowerPoint PPT Presentation

T we lfth Le s s on F orm a lis in g a LUP De om p os ition Formath School 2012 p.1 Motiv a tion T ake a las s i algorithm Corme n LUP algorithm How diffi ult to formalis e ? T e s t our lin e ar


  1. T we lfth Le s s on F orm a lis in g a LUP De om p os ition Formath School 2012 – p.1

  2. Motiv a tion T ake a las s i algorithm Corme n LUP algorithm How diffi ult to formalis e ? T e s t our lin e ar alge bra ( matrix.v ) Formath School 2012 – p.2

  3. Lin e a r e qua tion s x + 2 y + 3 z = 5 2 x − 4 y + 6 z = 18 3 x − 9 y − 3 z = 6 Formath School 2012 – p.3

  4. Lin e a r e qua tion s       1 2 3 x 5 2 − 4 6 y  = 18            3 − 9 − 3 z 6       1 2 3 1 0 0 1 2 3  = 2 − 4 6 2 − 8 0 0 1 0            3 − 9 − 3 3 − 15 − 12 0 0 1 Formath School 2012 – p.4

  5. Lin e a r e qua tion s         1 0 0 1 2 3 x 5  = 2 − 8 0 0 1 0 y 18 , , , ,                3 − 15 − 12 0 0 1 z 6             1 0 0 x 1 5 1 2 3 x x 1              =  = 2 − 8 0 y 1 18 0 1 0 y y 1                       3 − 15 − 12 z 1 6 0 0 1 z z 1 x 1 = 5 y 1 = − 1 z 1 = 2 z = 2 y = − 1 x = 1 Formath School 2012 – p.5

  6. Lin e a r e qua tion s       1 2 3 1 0 0 1 2 3 2 − 4 6  = 2 − 8 0 0 1 0            3 − 9 − 3 3 − 15 − 12 3 0 1 A = L U P j     P = 1 i     Formath School 2012 – p.6

  7. Algorithm Easy ase: re ursive onstru tion Add to A one line and a olumn of zeros: = P A L U a w a w 1 1 = P A L U Formath School 2012 – p.7

  8. Algorithm Main ase ( a � = 0 ) S hur omp lement A ′ = A − 1 /a ( v ∗ w ) a w A v a w A ′ Formath School 2012 – p.8

  9. Algorithm Main ase: re ursive onstru tion ( A ′ = A − 1 /a ( v ∗ w ) ) = A ′ P L U u = 1 /a ( P ∗ v ) a w a w 1 1 = A ′ P A L U v u Formath School 2012 – p.9

  10. Algorithm Sp e ial ase Line p ermutation a w = P A L U a w = P ′ A L U Formath School 2012 – p.10

  11. Algorithm 1. Put a n on � ze ro e le me n t at (0,0) if n e e de d by lin e p e rmutation 2. Pe rform the re urs iv e all on the S hur omp le me n t 3. Re omp os e the re s ult of the re urs iv e all Formath School 2012 – p.11

  12. F orm a lis a tion Write the algorithm Write the s p e ifi ation Prov e that the s p e ifi ation is me t Formath School 2012 – p.12

  13. Wha t is a m a trix? Inductive matrix ( m n : nat) R := Matrix of {ffun ’I_ m ∗ ’I_ n → R }. Notation "’M[ R ]_( m , n )" := (matrix m n R ). Notation "’M[ R ]_( n )" := ’M[ R ]_( n , n ). Definition A : ’M[ R ]_( m , n ) := \ matrix(i,j) E . A i j : R Formath School 2012 – p.13

  14. G e ttin g blo ks Us in g ordin al : whe re   .  A ul A ur  A dl A dr lshift n ( i : ’I_ m ) : ’I_( m + n ) rshift m ( i : ’I_ n ) : ’I_( m + n ) split ( i : ’I_( m + n )) : ’I_ m + ’I_ n Inductive A + B := inl of A | inr of B Formath School 2012 – p.14

  15. Row blo k [ A l | A r ] Definition row_mx A l A r : ’M[ R ]_( m , n 1 + n 2 ) : = \ matrix_( i , j ) match split j with inl j 1 ⇒ A l i j 1 | inr j 2 ⇒ A r i j 2 end. Definition lsubmx ( A : ’M[ R ]_( m , n 1 + n 2 )) : = \ matrix_( i , j ) A i (lshift n 2 j ). Definition rsubmx ( A : ’M[ R ]_( m , n 1 + n 2 )) : = \ matrix_( i , j ) A i (rshift n 1 j ). Formath School 2012 – p.15

  16. Colum n blo k    A u  A d Definition col_mx A u A d : ’M[ R ]_( m 1 + m 2 , n ) : = \ matrix_( i , j ) match split i with inl i 1 ⇒ A u i 1 j | inr i 2 ⇒ A d i 2 j end. Definition usubmx ( A : ’M[ R ]_( m 1 + m 2 , n )) : = \ matrix_( i , j ) A (lshift m 2 i ) j . Definition dsubmx ( A : ’M[ R ]_( m 1 + m 2 , n )) : = \ matrix_( i , j ) A (rshift m 1 i ) j . Formath School 2012 – p.16

  17. Blo k    A ul A ur  A dl A dr Definition col_mx A ul A ur A dl A dr : = col_mx (row_mx A ul A ur ) (row_mx A dl A dr ). Definition ulsubmx A := lsubmx (usubmx A ). Definition ursubmx A := rsubmx (usubmx A ). Definition dlsubmx A := lsubmx (dsubmx A ). Definition drsubmx A := rsubmx (dsubmx A ). Formath School 2012 – p.17

  18. Pe rm uta tion i 2 [A] i 1 Definition row_perm ( s : ’S_ m ) A : = \ matrix_( i , j ) A ( s i ) j . Definition perm_mx n s : ’M[ R ]_ n : = row_perm s 1%:M. Definition xrow i 1 i 2 A : = row_perm (tperm i 1 i 2 ) A . Definition tperm_mx n i 1 i 2 : ’M[ R ]_ n : = perm_mx (tperm i 1 i 2 ). Formath School 2012 – p.18

  19. Pi kin g Let P a predi ate on a finite type T i [A] where [pick x | P x ] : option T If there is a default value: Inductive option ( A : Type) : = Some of A | None. where odflt a [pick x | P x ] : T Definition odflt ( A : Type) ( a : A ) ( o : option A ) := if o is Some v then v else a . Formath School 2012 – p.19

  20. Algorithm 1. Put a n on � ze ro e le me n t at (0,0) if n e e de d by lin e p e rmutation 2. Pe rform the re urs iv e all on the S hur omp le me n t 3. Re omp os e the re s ult of the re urs iv e all Formath School 2012 – p.20

  21. Algorithm Let M n : ’M[ F ]_ n . = Fixpoint cormen_lup n : M n .+1 -> M n .+1 * M n .+1 * M n .+1 : = if n is _.+1 then fun A ⇒ let k : odflt 0 [pick k | A k 0 != 0 ] in = let A 1 : ’M_(1 + _) : xrow 0 k A in = let P 1 : ’M_(1 + _) : tperm_mx 0 k in = let Schur := drsubmx A 1 - (( A k 0 )^-1 *: dlsubmx A 1 ) *m ursubmx A 1 in let: ( P 2 , L 2 , U 2 ) := cormen_lup Schur in let P : block_mx 1 0 0 P 2 * P 1 in = let L : block_mx 1 0 (( A k 0 )^-1 *: ( P 2 *m dlsubmx A 1 )) L 2 in = let U : block_mx (ulsubmx A 1 ) (ursubmx A 1 ) 0 U 2 in = ( P , L , U ) else fun A ⇒ ( 1 , 1 , A ) . Formath School 2012 – p.21

  22. S p e ifi a tion We hav e a de omp os ition : T he firs t omp on e n t is a p e rmutation : Lemma cormen_lup_correct n ( A : ’M_ n .+1) : let: ( P , L , U ) : = cormen_lup A in P * A = L * U . Definition perm_mx n s : ’M[ R ]_ n : = row_perm s 1%:M. Definition is_perm_mx n ( A : ’M[ R ]_ n ) : = existsb s : ’S_ n , A == perm_mx s . Lemma cormen_lup_perm n ( A : ’M[ F ]_ n .+1) : let: ( P , _, _) : = cormen_lup A in is_perm_mx P . Formath School 2012 – p.22

  23. S p e ifi a tion T he s e on d omp on e n t is a lowe r trian gular matrix with on e of the diagon al T he third omp on e n t is an up p p e r trian gular matrix Lemma cormen_lup_lower n ( A : ’M[F]_ n .+1) ( i j : ’I_ n .+1) : let: (_, L , _) : = cormen_lup A in i <= j → L i j = ( i == j )%:R. Lemma cormen_lup_upper n ( A : ’M[F]_ n .+1) ( i j : ’I_ n .+1) : let: (_, _, U ) : = cormen_lup A in j < i → U i j = 0 . Formath School 2012 – p.23

  24. Prov in g I Lemma cormen_lup_correct n ( A : ’M[ F ]_ n .+1) : ( P , L , U ) : = cormen_lup A in P * A = L * U . let: Lemma mulmx_block ( m 1 m 2 n 1 n 2 p 1 p 2 : nat) ( A ul : ’M[ R ]_( m 1 , n 1 )) ( A ur : ’M[ R ]_( m 1 , n 2 )) ( A dl : ’M[ R ]_( m 2 , n 1 )) ( A dr : ’M[ R ]_( m 2 , n 2 )) ( B ul : ’M_( n 1 , p 1 )) ( B ur : ’M_( n 1 , p 2 )) ( B dl : ’M_( n 2 , p 1 )) ( B dr : ’M_( n 2 , p 2 )), block_mx A ul A ur A dl A dr *m block_mx B ul B ur B dl B dr = block_mx ( A ul *m B ul + A ur *m B dl ) ( A ul *m B ur + A ur *m B dr ) ( A dl *m B ul + A dr *m B dl ) ( A dl *m B ur + A dr *m B dr ) Lemma mxE F : matrix_of_fun F =2 F . Lemma mx11_scalar ( A : ’M[ R ]_1) : A = ( A 0 0)%:M. Formath School 2012 – p.24

  25. Prov in g I Lemma cormen_lup_correct n ( A : ’M[ F ]_ n .+1) : ( P , L , U ) : = cormen_lup A in P * A = L * U . let: Proof. elim: n ⇒ [| n IHn ] /= in A *; first by rewrite !mul1r. set k : = odflt _ _; set A 1 : ’M_(1 + _) : = xrow _ _ _. = _ - _; move/(_ A ′ ): IHn ; case: cormen_lup ⇒ [[ P ′ L ′ U ′ ]] /= IHn . set A ′ : rewrite -mulrA -!mulmxE -xrowE -/ A 1 /= -[ n .+2]/(1 + n .+1)%N -{1}(submxK A 1 ). rewrite !mulmx_block !mul0mx !mulmx0 !add0r !addr0 !mul1mx -{ L ′ U ′ }[ L ′ *m _] IHn . rewrite -scalemxAl !scalemxAr -!mulmxA addrC -mulrDr { A ′ } subrK. congr (block_mx _ _ (_ *m _) _). rewrite [_ *: _]mx11_scalar !mxE lshift0 tpermL {}/ A 1 {}/ k . case: pickP ⇒ /= [ k nzAk0 | no k ]; first by rewrite mulVf ?mulmx1. rewrite (_ : dlsubmx _ = 0 ) ?mul0mx //; apply/colP ⇒ i . by rewrite !mxE lshift0 (elimNf eqP ( no k _)). Qed. Formath School 2012 – p.25

  26. Prov in g II Lemma cormen_lup_perm n ( A : ’M[ F ]_ n .+1) : let: ( P , _, _) : = cormen_lup A in is_perm_mx P . Lemma perm_mx_is_perm ( n : nat) ( s : ’S_ n ) : is_perm_mx (perm_mx s ). Lemma is_perm_mxMr ( n : nat) ( A B : ’M[ R ]_ n ) : is_perm_mx B → is_perm_mx ( A *m B ) = is_perm_mx A . Definition lift0_mx A : ’M[ R ]_(1 + n) := block_mx 1 0 0 A . Lemma lift0_mx_is_perm ( n : nat) ( s : ’S_ n ) : is_perm_mx (lift0_mx (perm_mx s )). Formath School 2012 – p.26

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend