Coq中证明algorithm'与algorithm''类型等价性的求助
Coq形式化证明工作阻碍
当前开展n=8特定场景下排序问题的*log₂(n!)*下界证明时,遇到两类算法类型等价性的证明阻塞:
- 不确定是自身证明经验不足导致无法完成推导
- 或是前期的结构定义存在逻辑疏漏,始终无法完成等价性证明
其中*algorithm''类型*对应证明框架里的决策树模型。
核心定义与待证目标
以下是本次工作涉及的完整Coq代码:
Require Import List Lia. Set Implicit Arguments. Inductive value := x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7. Inductive variable := aux | num: value -> variable. Definition variable_eq_dec (x y: variable): {x=y} + {x<>y}. Proof. destruct x, y. + left; auto. + right; abstract congruence. + right; abstract congruence. + destruct v, v0; try (left; abstract congruence); (right; abstract congruence). Defined. Inductive assignment := assign: variable -> variable -> assignment. Inductive comparison := GT: forall (more less: value), comparison. Definition instantation := variable -> nat. Definition run_assignment (a: assignment) (i: instantation): instantation := match a with | assign v1 v2 => fun x => if variable_eq_dec x v1 then i v2 else i x end. Fixpoint run_assignment_list (L: list assignment): instantation -> instantation := match L with | nil => fun i => i | a :: l => fun i => run_assignment_list l (run_assignment a i) end. Inductive algorithm': nat -> Type := | leaf': algorithm' 0 | conditional': forall n (c: comparison) (pos_assignments neg_assignments: list assignment) (pos neg: algorithm' n), algorithm' (S n). Inductive algorithm'': nat -> Type := | leaf'': list assignment -> algorithm'' 0 | conditional'': forall n (c: comparison) (pos neg: algorithm'' n), algorithm'' (S n). Definition run_algorithm' n (a: algorithm' n): instantation -> instantation. Proof. induction a. + exact (fun x => x). + intro i. destruct c. exact (if Compare_dec.gt_dec (i (num more)) (i (num less)) then IHa1 (run_assignment_list pos_assignments i) else IHa2 (run_assignment_list neg_assignments i)). Defined. Definition run_algorithm'' n (a: algorithm'' n) (i: instantation): instantation. Proof. induction a. + exact (run_assignment_list l i). + destruct c. exact (if Compare_dec.gt_dec (i (num more)) (i (num less)) then IHa1 else IHa2). Defined. Fixpoint append_assignments n (a: algorithm'' n) (L: list assignment): algorithm'' n := match a with | leaf'' L0 => leaf'' (L ++ L0) | conditional'' c pos neg => conditional'' c (append_assignments pos L) (append_assignments neg L) end. Fixpoint algorithm'_to_algorithm'' n (a: algorithm' n): algorithm'' n := match a with | leaf' => leaf'' nil | conditional' c Lpos Lneg pos neg => conditional'' c (append_assignments (algorithm'_to_algorithm'' pos) Lpos) (append_assignments (algorithm'_to_algorithm'' neg) Lneg) end. Theorem algorithm'_algorithm''_equiv n (a: algorithm' n): forall (i: instantation) (x: variable), run_algorithm' a i x = run_algorithm'' (algorithm'_to_algorithm'' a) i x. Proof. Admitted.
本次待证定理的核心目标是:证明通过algorithm'_to_algorithm''完成结构转换前后,两类算法在任意输入实例化i下,对任意变量x的运行结果完全相等。目前该证明无法顺利推进,需要相关方向的帮助。
内容的提问来源于stack exchange,提问作者Lessness Randomness
相关产品推荐
相关产品推荐

