Verified Interactive Computation of Definite Integrals
Total Page:16
File Type:pdf, Size:1020Kb
Verified Interactive Computation of Definite Integrals Runqing Xu, Liming Li, Bohua Zhan SKLCS, Institute of Software, Chinese Academy of Sciences Motivation Many symbolic computations are involved in science and engineering, including reasoning about safety-critical systems. Motivation In this work, we consider definite integrals on a finite interval. Q: find the error in the following calculation: 휋 휋 න 1 + cos 2푥 푑푥 = න 1 + cos2 푥 − sin2(푥) 푑푥 0 0 휋 2 0 2 cos 푥 푑푥 = 휋 0 2 cos 푥 푑푥 = 2 sin 휋 − 2 sin 0 = 0 = A: 2 cos2 푥 should be simplified to 2 cos(푥) . The correct answer is 2 2. On Python’s SymPy 1.5.1: Motivation How to guarantee the correctness of symbolic computation? 1. Use computer algebra systems, such as Mathematica and Maple: • Advantage: easy to use and automatic. • Disadvantage: cannot solve everything, cannot actually guarantee correctness (Durán et al, 2014) 2. Use interactive theorem provers, such as Isabelle/HOL, Coq, HOL Light, HOL4... • Advantage: strong guarantees of correctness. • Disadvantage: not automatic, requires users to be proficient in higher- order logic, analysis library, etc. Can we combine the advantages of computer algebra systems and ITP? Architecture Goal: let user perform computations in a familiar CAS-like setting, then convert the computation into higher-order logic proofs. Overall plan: fix an intermediate language of computational rules, as a bridge between formal and “informal”. 2. 3. “Informal” computations 1. Formal proofs 4. Terms and Computations • Syntax: 푒 ∷= 푣 푐 푒1 표푝 푒2 푓 푒 Deriv(푒) | Integral(푒, 푎, 푏) • Location: point to subexpressions by specifying the path to a subtree in the AST of the expression. 1 + Integral(1 + sin3 푥 , 푥, 0, 1) • A computation is represented as a list of 0 1 steps, each step containing: 1 Integral(1 + sin3 푥 , 푥, 0, 1) • which rule is used; 0 1 2 3 • location the rule is applied; 1 + sin 푥 0 1 0 1 • parameters for the rule; 1 sin3 푥 • result of computation. • Around 10 kinds of steps in current work. 푙표푐 sin3 푥 = 1.0.1 Integration Rules Simplification: rewrite an expression to an equivalent simpler form. Combine terms: 휋 4휋 휋 + ⟹ 3 3 Expand products of polynomials: 푥 + 1 × 푥 − 1 ⟹ 푥2 − 1 Simplify values of trigonometric functions: 휋 1 휋 sin ⟹ sin − 푥 ⟹ cos(푥) 6 2 2 Basic integrals: 휋 1 2 2 2 න 6푥 푑푥 ⟹ 3 න 푑푥 ⟹ 2log(2) න cos 푥 푑푥 ⟹ 1 0 1 푥 0 Not included: Expansion of large powers (e.g. (풙 + 풚 + ퟏ)ퟕ). 풙ퟐ−ퟏ Reduce quotients of polynomials (e.g. = 풙 + ퟏ). 풙−ퟏ Integration Rules 푏 푔(푏) ′ . Substitution: apply 푎 푓 푔 푥 푔 푥 푑푥 = 푔(푎) 푓 푢 푑푢 in either direction Forward substitution: Backward Substitution: 푏 푔(푏) 푔(푏) 푏 න 푓 푔 푥 푔′ 푥 푑푥 ⟹ න 푓 푢 푑푢 න 푓 푢 푑푢 ⟹ න 푓 푔 푥 푔′ 푥 푑푥 푎 푔(푎) 푔(푎) 푎 Example: Example: 1 1 1 න 푑푥 න 1 − 푥2 푑푥 3/4 1 − 푥 − 1 0 1/2 휋 2푢 2 = න 푑푢 (substitute 푢 for 1 − 푥) = න 1 − sin2 푡 cos 푡 푑푡 (substitute 푥 by sin(푡)) 0 푢 − 1 0 Record both 푓 and 푔 as parameters. Record 푔, 푎, 푏 as parameters. 2푢 Here 푓 = and 푔 = 1 − 푥. Here 푔 = sin 푡 , 푎 = 0, 푏 = 휋/2. 푢−1 Integration Rules Trigonometric Identities: rewrite an expression to a possibly more complex form, in order to prepare for a substitution or integration by parts. Fu et al. divides the trigonometric identities into several groups, with name of the form TR푖, for example: TR5: sin2 푥 = 1 − cos2 푥 1 TR7: cos2 푥 = (1 + cos(2푥)) 2 푥+푦 푥−푦 TR9: sin 푥 + cos 푥 = 2 sin cos , etc 2 2 TR11: sin 2푥 = 2 sin 푥 cos 푥 , cos 2푥 = cos2 푥 − sin2 푥 , etc In the computation step, record name of Fu’s rule and location of application. Example: π/2 π/2 cos 2푥 +1 ( cos2 푥 푑푥 = 푑푥 (Trigonometric identity, TR7 π/6 π/6 2 Integration Rules Integration by Parts: 푏 푏 ′ 푏 ′ න 푢 푥 푣 푥 푑푥 = 푢 푥 푣 푥 |푎 − න 푢 푥 푣 푥 푑푥 푎 푎 Example: 2 푥 푥 2 2 푥 푥 ( −1 푥푒 푑푥 = 푥푒 |−1 − −1 푒 푑푥 (Integration by parts, 푢 = 푥, 푣 = 푒 Splitting an integral: 푏 푐 푏 න 푓 푥 푑푥 = න 푓 푥 푑푥 + න 푓 푥 푑푥 (푎 ≤ 푐 ≤ 푏) 푎 푎 푐 Example: 1 2 0 2 1 2 (−1 푥 푑푥 = −1 푥 푑푥 + 0 푥 푑푥 (Splitting an integral, 푐 = 0 User Interface Allows user to specify computation steps, provides various conveniences: Display in LaTeX format. Selection of actions and subexpressions to perform the action on. Automatically generate some parameters of steps (e.g. name of Fu’s rule). Automatic integration algorithms (Slagle’s method). Conversion to higher-order logic, showing if successful. User Interface: Example Slagle’s Method A heuristic integration algorithm (Slagle, 1963) • Simple but effective. • Output is human readable, can be translated to computation steps. • Search on algorithmic and heuristic transformations, maintaining a tree consisting of AND nodes and OR nodes. AND node OR node (all child nodes must be resolved) (one child node need resolved) 휋 1 4 න 푥3 + 푥2 + 푥 푑푥 2 sin (푥) න 4 푑푥 0 0 cos (푥) 휋 휋 1 4 1 1 1 2 2 푧 3 2 න tan4(푥) 푑푥 න cot−4(푥) 푑푥 න 32 푑푥 න 푥 푑푥 න 푥 푑푥 න 푥 푑푥 (1 + 푧2) (1 − 푧2)4 0 0 0 0 0 0 Slagle’s Method Algorithmic transformation (always applied) • Factor constant 푏 푏 න 푐푓 푥 푑푥 = 푐 න 푓 푥 푑푥 푎 푎 • Decomposition 푏 푏 න ∑푓푖 푥 푑푥 = ∑ න 푓푖 푥 푑푥 푎 푎 • Linear substitution 푏 푐1+푐2푏 1 න 푓 푐 + 푐 푣 푑푣 = න 푓 푢 푑푢 1 2 푐 푎 푐1+푐2푎 2 Slagle’s Method Heuristic Transformation (plausible but not always appropriate) • Substitute a non-linear subexpression whose derivative divides the integrand: 푏 푑 2 1 2 2 ′ 2 න 푥푒푥 푑푥 = න 푑푢 (substitute 푒푥 by 푢, since 푒푥 = 2푥푒푥 ) 푎 푐 2 2 • For each quadratic subexpression of the form 푐2 + 푐1푥 푐2 • if 푐1 < 0, 푐2 > 0, try the substitution x = sin 푢 , which replaces the −푐1 2 quadratic to 푐2cos 푢 푏 푥4 푑 sin4(푥) න 2 5/2 푑푥 = න 4 푑푥 푎 (1 − 푥 ) 푐 cos (푥) • ...... • ...... (ten rules in total) Proof Reconstruction • From a sequence of computation steps, automatically reconstruct proof in higher-order logic. This is possible since all necessary information is already available. • Main tasks: • Proofs for simplification of expressions. • Proofs for inequality checking. • Applying integration theorems, including check side conditions (e.g. continuity, integrability, …) • Implementation in HolPy, an interactive theorem prover written in Python, with Python API for proof automation. Proof Automation Simplification: reduce expressions to canonical form. • Each monomial can be converted to the form 푝1 푝2 푝푘 푐 ∙ 푎1 푎2 … 푎푘 푐: prime number 푎푖: prime number / a term whose head is not an arithmetic operator 푝푖 ∈ 0, 1 if 푎푖 is a prime number • A polynomial is a sum of monomials which are all distinct and in sorted order. Example 푝1 6 2 푥 + 32/3 = 61/221/2푥 + 61/221/232/3푥 = 21/231/221/2푥 + 21/221/321/232/3푥 = 2 ⋅ 31/2푥 + 6 ⋅ 31/6 푐 푎1 푎2 Proof Automation Inequality checking A major task in proof automation is inequality checking, for instance, if we want to simplify 푓(푥)2 to 푓(푥) when 푥 ∈ 푎, 푏 , then we need to prove that 푥 ∈ 푎, 푏 ⟹ 푓 푥 ≥ 0 We implemented a heuristic procedure for inequality checking which can be considered as a simplified version of interval arithmetic. For instance, we can deduce 2 − 2 ∙ sin2 푥 ≥ 0 by the following steps: 휋 푥 ∈ 0, ⟹ sin 푥 ∈ 0,1 ⟹ sin2 푥 ∈ 0,1 ⟹ 2 2 − 2 ∙ sin2 푥 ∈ 0,2 ⟹ 2 − 2 ∙ sin2 푥 ≥ 0 In the future, consider other heuristic extensions (e.g. Avigad et al, JAR ’16). Proof Automation Applying theorems • Automatic proofs of continuity, integrability, etc. (Currently can only handle the basic cases). • Use of integration theorems such as substitution, integration by parts (simple because the parameters of the rule already contain required instantiations). Background library • Ported statements of over 1000 theorems from HOL Light. • About 40% are proved using the point-and-click user interface in HolPy (ICFEM ’19). Experiments We evaluated our prototype on problems taken from • Exam preparation books (Tongji) • Online problems listed by D. Kouba • MIT Integration Bee Future Work • Long-term plan: implement a symbolic computation tool with correctness guaranteed by generating proofs. • Extend expressions and integration rules to support: Multivariable integrals; Improper integrals, Laplace and Fourier transforms; Vector, matrix and tensor calculus. • Generate proofs to different interactive theorem provers: Isabelle, HOL Light, HOL4 (higher-order logic). Coq, Lean (dependent type theory). Q&A THANK YOU!.