Canonical Big Operators Yves Bertot Georges Gonthier Sidi
Canonical Big Operators Yves Bertot, Georges Gonthier, Sidi Ould Biha, Ioana Paşca
Big Operators ∑Φ(n/d) md ∑ ai X i d|n n ⋀GCD Qi(X) i<n i=1 ∑ (-1)σ ∏i Ai, iσ Vi ∩H σ Sn Vi ≈ W H<G H maximal bigcap_{H < G atop H {rm maximal}} H ∑ Xi + Yi = ∑Xi + ∑Yi i 17. 12. 2021 i i Canonical Big Operators 2
Motivation • Big operators for proof systems – General description – Reusable code – Easy manipulation • Existing libraries are less general
Notation 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. • Present the options Notation "big[ op / nil ]_ ( i <- r | P ) F" : = (reducebig op nil r (fun i => P) (fun i => F)). • Hide or fill the options 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. • Generic filling Notation "big[ op / nil ]_ i F" : = (big[op/nil]_(i <- fintype. enum _) F). 17. 12. 2021 Canonical Big Operators 5
Inferred Notation • Polymorphism with dependent records Structure fin. Type : = Fin. Type { sort : > Type; enum : list sort; . . . }. Variable I : fin. Type. Variable F : Isort -> nat. I -> nat. Lemma null_sum : sum_i F i = 0 -> forall i, F i = 0. @reducebig nat I _ addn 0 (enum I _). . (fun i : I _ => F i) list (sort _) = list (sort I) 17. 12. 2021 Canonical Big Operators 6
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_fin. Type n : = Fin. Type 'I_n (ord_enum n) … Variable V : 'I_10 -> nat. Hypothesis norm. V : sum_i V i * V i <= 3. ordinal_fin. Type 10 _ @reducebig nat _ addn 0 (enum _). . (fun i : _ => V i * V i) list (sort _) = list 'I_10 list 'I_(_) 17. 12. 2021 Canonical Big Operators 7
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 ) i r, P(i) Variables F G : 'I_10 -> nat. Lemma sumn. K : sum_i (F i + G i) - sum_i G i = sum_i F i. Proof. by rewrite big_split addn. K. Qed. 17. 12. 2021 Canonical Big Operators 8
Operator structures • Polymorphism for values! Structure law : Type : = Structure abelian_law : Type : = Law { Abelian. Law { operator : T -> T; abelaw : > law; _ : associative operator; _ : commutative (operator abelaw) _ : left_unit operator; }. _ : right_unit operator }. Canonical Structure addn_monoid : = Law addn. A add 0 n addn 0. Canonical Structure addn_abeloid : = Abelian. Law addn. C. … 17. 12. 2021 Canonical Big Operators 9
A proof begin{eqnarray*} Lemma determinant. M : forall n (A B : M_(n)), det (A *m B) = det A * det B. det AB & = & sum_{sigma in S_n} (-1)^sigma prod_i Proof. left(sum_j A_{ij} B_{jsigma(i)}right)\ move=> n A B; rewrite big_distrl /=. & = & sum_{phi [1, n]} pose AB (f : {ffun _}) (s : 'S_n) i : = A i (f i) * : ; B (f[1, i) n] (s rightarrow i). sum_{sigma in S_n} transitivity (sum_f sum_(s : 'S_n) (-1) ^+ s * prod_i AB f s i). prod_i A_{iphi(i)} B_{phi(i)sigma(i)}\ rewrite exchange_big; apply: eq_bigr => (-1)^sigma /= s _. & = & sum_{phi notin S_n} sum_{sigma in S_n} rewrite -big_distrr /=; congr (_ * _). (-1)^sigma prod_i B_{phi(i)sigma(i)} pose F i j : = A i j * B j (s i); rewrite -(big. A_distr_big. A F) A_{iphi(i)} /=. + sum_{phi in S_n} sum_{sigma in S_n} by apply: eq_bigr => x _; rewrite mx. K. (-1)^sigma prod_i A_{iphi(i)} B_{phi(i)sigma(i)}\ rewrite (big. ID (fun f : {ffun _} => injectiveb f)) /= addr. C big 1 ? simp => [|f Uf]. = & last sum_{phi rewrite (reindex (fun s => pval& s)); first. notin S_n} left(prod_i A_{iphi(i)}right) sum_{sigma inf). S_n} have s 0 : 'S_n : = 1%g; pose uf (f : F_(n)) : = uniq (val (-1)^sigma prod_i B_{phi(i)sigma(i)}\ exists (insubd s 0) => /= f Uf; first apply: val_inj; exact: insubd. K. & & {} + sum_{phi in S_n} apply: eq_big => /= [s|s _]; rewrite ? (val. P s) // big_distrr /=. (-1)^phi left(prod_i A_{iphi(i)}right) rewrite (reindex (mulg s)); last first. sum_{sigma in S_n} by exists (mulg s^-1) => t _; rewrite ? mul. KVg ? mul. Kg. (-1)^{phi^{-1}sigma} apply: eq_bigr => t _; rewrite big_split /= mulr. A mulr. CA mulr. A. prod_k B_{ksigma(phi^{-1}(k))}\ rewrite -signr_addb odd_perm. M !pval. E; congr (_ * _). & = & sum_{phi notin S_n} left(prod_i A_{iphi(i)}right) rewrite (reindex s^-1); last first. det left(B_{phi(i)j}right)_{ij} by exists (s : _ -> _) => i _; rewrite ? perm. KV. + (det A)sum_{tau in S_n}(-1)^tau by apply: eq_bigr => i _; rewrite perm. M perm. KV ? eqxx // -{3}[i](perm. KV s). prod_k B_{ktau(k)}\ & = & 0 + (det A)(det B)\ transitivity (det (matrix_(i, j) B (f i) j) * prod_i A i (f i)). end{eqnarray*} rewrite mulr. C big_distrr /=; apply: eq_bigr => s _. The//=; first step(_swaps iterated product of the Leibnitz formula with rewrite mulr. CA big_split congr * (_ the * _)). the sum in the general term of the matrix product, generating a sum over by apply: eq_bigr => x _; rewrite mx. K. all functions from indices to indices. This is split into a sum over case/injective. Pn: Uf => i 1 [i 2 Di 12 Ef 12]. non-injective functions and a over permutations. The former is rearranged by rewrite (alternate_determinant Di 12) ? simp //= => j; sum rewrite !mx. K Ef 12. into a weighted sum of determinants of matrices with repeated rows, Qed. while the latter is reindexed, using the group properties of permutations, to become the desired product of determinants. 17. 12. 2021 Canonical Big Operators 10
More proofs • Polynomials • Linear algebra – The Cramer formula : adj A • A = |A| • Idn – The Cayley-Hamilton Theorem : PA (A) = 0 Cayley_Hamilton • Theorem Numerical Analysis : forall A, (Zpoly (char_poly A)). [A] = 0. Proof. – Kantorovitch’s Theorem (convergence criterion for Newton’s move=> A; apply/eq. P; apply/factor_theorem. rewrite -phi_Zpoly -mulmx_adjl phi_mul; ofmove: (phi _) => q; exists q. root-finding method for functions several variables). by rewrite phi_add phi_opp phi_Zpoly phi_poly. C Zpoly. X. Qed. • Group theory : – The Gaschütz, Schur-Zassenhaus, Maeschke and Hall theorems 17. 12. 2021 Canonical Big Operators 11
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. 17. 12. 2021 Canonical Big Operators 12
- Slides: 12