Download presentation
Presentation is loading. Please wait.
1
Canonical Big Operators
Yves Bertot, Georges Gonthier, Sidi Ould Biha, Ioana Paşca
2
Canonical Big Operators
∑Φ(n/d) md d | n ∑ai Xi i < n ⋀GCD Qi(X) i = 1 n ∑ (-1)σ ∏i Ai,iσ σSn Vi Vi ≈ W ∩ H H < G H maximal \bigcap_{H < G \atop H {\rm\ maximal}} H ∑ Xi + Yi = ∑Xi + ∑Yi i i i 25 December, 2018 Canonical Big Operators
3
Motivation Big operators for proof systems
General description Reusable code Easy manipulation Existing libraries are less general
4
Example: determinants
Leibnitz formula : Cauchy theorem : |AB| = |A| |B| |A| = ∑ (-1)σ ∏i Ai,iσ σSn |AB| = ∑ (-1)σ ∏i σSn (AB)i,iσ (∑j Ai,j Bj,iσ) = ∑ (-1)σ ∑ ∏i Ai,iρ σSn ρ ∏i Biρ,iσ Biρ,iσ = ∑ ∏i Ai,iρ ∑ (-1)σ ∏i Biρ,iσ σSn = ∑ ∏i Ai,iρ ∑ (-1)σ ∏j Bj,jρ-1σ i = jρ-1 ρSn ρSn ρ σSn =(∑ (-1)ρ ∏i Ai,iρ) ( ∑ (-1)τ ∏j Bj,jτ ) ρSn τSn σ = ρτ = ∑ (-1)ρ ∏i Ai,iρ ∑ (-1)τ ∏j Bj,jτ τSn ρSn = ∑ (-1)ρ ∏i Ai,iρ ∑ (-1)ρ-1σ ∏j Bj,jρ-1σ σSn ρSn ρSn + ∑ ∏i Ai,iρ |(Biρ,j)| ρSn + ∑ ∏i Ai,iρ ∑ (-1)σ ∏i Biρ,iσ σSn = |A| |B| 25 December, 2018 Canonical Big Operators
5
Canonical Big Operators
Notation Present the options Hide or fill the options Generic filling Definition reducebig R I op nil r P (F : I -> R) : R := foldr (fun i x => if P i then op (F i) x else x) nil r. Notation "\big[ op / nil ]_ ( i <- r | P ) F" := (reducebig op nil r (fun i => P) (fun i => F)). Notation "\big[ op / nil ]_( i <- r ) F" := (\big[op/nil]_(i <- r | true) F). Notation "\sum_ ( i <- r ) F" := (\big[addn/0%nat]_(i <- r) F) : nat_scope. Notation "\big[ op / nil ]_ i F" := (\big[op/nil]_(i <- fintype.enum _) F). 25 December, 2018 Canonical Big Operators
6
@reducebig nat _ addn 0 (enum _) .. (fun i : _ => F i)
Inferred Notation Polymorphism with dependent records Structure finType : Type := FinType { sort :> Type; enum : list sort; ... }. :> Variable I : finType. Variable F : I -> nat. sort I -> nat. Lemma null_sum : \sum_i F i = 0 -> forall i, F i = 0. @reducebig nat _ addn 0 (enum _) .. (fun i : _ => F i) I I I list (sort _) = list (sort I) 25 December, 2018 Canonical Big Operators
7
@reducebig nat _ addn 0 (enum _) .. (fun i : _ => V i * V i)
Canonical Structures Dependent records for ad hoc polymorphism Inductive ordinal n : Type := Ordinal i of i < n. Notation “''I_' n" := (ordinal n). Definition ord_enum n : list 'I_n := … Canonical Structure ordinal_finType n := FinType 'I_n (ord_enum n) … Variable V : 'I_10 -> nat. Hypothesis normV : \sum_i V i * V i <= 3. ordinal_finType _ 10 @reducebig nat _ addn 0 (enum _) .. (fun i : _ => V i * V i) list 'I_(_) list (sort _) = list 'I_10 25 December, 2018 Canonical Big Operators
8
Canonical Big Operators
Generic Lemmas Pull, split, reindex, exchange … Lemma big_split : forall I (r : list I) P F G, \big[*%M/1]_(i <- r | P i) (F i * G i) = \big[*%M/1]_(i <- r | P i) F i * \big[*%M/1]_(i <- r | P i) G i. ∏ (Fi *Gi ) = (∏ Fi ) * (∏ Gi ) ir, P(i) Variables F G : 'I_10 -> nat. Lemma sumnK : \sum_i (F i + G i) - \sum_i G i = \sum_i F i. Proof. by rewrite big_split addnK. Qed. 25 December, 2018 Canonical Big Operators
9
Canonical Big Operators
Operator structures Polymorphism for values! Structure law : Type := Law { operator : T -> T -> T; _ : associative operator; _ : left_unit unit operator; _ : right_unit unit operator }. Structure abelian_law : Type := AbelianLaw { abelaw :> law; _ : commutative (operator abelaw) }. Canonical Structure addn_monoid := Law addnA add0n addn0. Canonical Structure addn_abeloid := AbelianLaw addnC. … 25 December, 2018 Canonical Big Operators
10
Canonical Big Operators
A proof Lemma determinantM : forall n (A B : M_(n)), \det (A *m B) = \det A * \det B. Proof. move=> n A B; rewrite big_distrl /=. pose AB (f : {ffun _}) (s : 'S_n) i := A i (f i) * B (f i) (s i). transitivity (\sum_f \sum_(s : 'S_n) (-1) ^+ s * \prod_i AB f s i). rewrite exchange_big; apply: eq_bigr => /= s _. rewrite -big_distrr /=; congr (_ * _). pose F i j := A i j * B j (s i); rewrite -(bigA_distr_bigA F) /=. by apply: eq_bigr => x _; rewrite mxK. rewrite (bigID (fun f : {ffun _} => injectiveb f)) /= addrC big1 ?simp => [|f Uf]. rewrite (reindex (fun s => pval s)); last first. have s0 : 'S_n := 1%g; pose uf (f : F_(n)) := uniq (val f). exists (insubd s0) => /= f Uf; first apply: val_inj; exact: insubdK. apply: eq_big => /= [s|s _]; rewrite ?(valP s) // big_distrr /=. rewrite (reindex (mulg s)); last first. by exists (mulg s^-1) => t _; rewrite ?mulKVg ?mulKg. apply: eq_bigr => t _; rewrite big_split /= mulrA mulrCA mulrA mulrCA mulrA. rewrite -signr_addb odd_permM !pvalE; congr (_ * _). rewrite (reindex s^-1); last first. by exists (s : _ -> _) => i _; rewrite ?permK ?permKV. by apply: eq_bigr => i _; rewrite permM permKV ?eqxx // -{3}[i](permKV s). transitivity (\det (\matrix_(i, j) B (f i) j) * \prod_i A i (f i)). rewrite mulrC big_distrr /=; apply: eq_bigr => s _. rewrite mulrCA big_split //=; congr (_ * (_ * _)). case/injectivePn: Uf => i1 [i2 Di12 Ef12]. by rewrite (alternate_determinant Di12) ?simp //= => j; rewrite !mxK Ef12. Qed. \begin{eqnarray*} \det AB & = & \sum_{\sigma \in S_n} (-1)^\sigma \prod_i \left(\sum_j A_{ij} B_{j\sigma(i)}\right)\\ & = & \sum_{\phi :\; [1, n] \rightarrow [1, n]} \sum_{\sigma \in S_n} (-1)^\sigma \prod_i A_{i\phi(i)} B_{\phi(i)\sigma(i)}\\ & = & \sum_{\phi \notin S_n} \sum_{\sigma \in S_n} (-1)^\sigma \prod_i A_{i\phi(i)} B_{\phi(i)\sigma(i)} + \sum_{\phi \in S_n} \sum_{\sigma \in S_n} & = & \sum_{\phi \notin S_n} \left(\prod_i A_{i\phi(i)}\right) (-1)^\sigma \prod_i B_{\phi(i)\sigma(i)}\\ & & {} + \sum_{\phi \in S_n} (-1)^\phi \left(\prod_i A_{i\phi(i)}\right) (-1)^{\phi^{-1}\sigma} \prod_k B_{k\sigma(\phi^{-1}(k))}\\ \det \left(B_{\phi(i)j}\right)_{ij} + (\det A)\sum_{\tau \in S_n}(-1)^\tau \prod_k B_{k\tau(k)}\\ & = & 0 + (\det A)(\det B)\\ \end{eqnarray*} The first step swaps the iterated product of the Leibnitz formula with the sum in the general term of the matrix product, generating a sum over all functions from indices to indices. This is split into a sum over non-injective functions and a sum over permutations. The former is rearranged into a weighted sum of determinants of matrices with repeated rows, while the latter is reindexed, using the group properties of permutations, to become the desired product of determinants. 25 December, 2018 Canonical Big Operators
11
Canonical Big Operators
More proofs Polynomials Linear algebra The Cramer formula : adj A • A = |A| • Idn The Cayley-Hamilton Theorem : PA (A) = 0 Numerical Analysis Kantorovitch’s Theorem (convergence criterion for Newton’s root-finding method for functions of several variables). Group theory : The Gaschütz, Schur-Zassenhaus, Maeschke and Hall theorems Theorem Cayley_Hamilton : forall A, (Zpoly (char_poly A)).[A] = 0. Proof. move=> A; apply/eqP; apply/factor_theorem. rewrite -phi_Zpoly -mulmx_adjl phi_mul; move: (phi _) => q; exists q. by rewrite phi_add phi_opp phi_Zpoly phi_polyC ZpolyX. Qed. 25 December, 2018 Canonical Big Operators
12
Canonical Big Operators
Some conclusions Role of the infrastructure in organizing a library Type theory provides a rich language for expressing the intended use of theories. The key advantage is Coq’s Canonical Structure construct. Also: polymorphism, dependent records, type inference, coercions, notation Investing in theory infrastructure is most productive. 25 December, 2018 Canonical Big Operators
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.