Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 有没有一个好的策略来证明给定的定理?_Sorting_Coq - Fatal编程技术网

Sorting 有没有一个好的策略来证明给定的定理?

Sorting 有没有一个好的策略来证明给定的定理?,sorting,coq,Sorting,Coq,应该使用什么策略来证明这一结果(最后,承认)?提前感谢您的任何提示微微一笑: 希望这是一个正确的定理。当我有错误的直觉时,我已经被烧死了,并且找到了反例 Require Import Permutation List Lia FunInd Recdef. Set Implicit Arguments. Inductive value := x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7. Inductive variable := aux | num: value

应该使用什么策略来证明这一结果(最后,承认)?提前感谢您的任何提示微微一笑:

希望这是一个正确的定理。当我有错误的直觉时,我已经被烧死了,并且找到了反例

Require Import Permutation List Lia FunInd Recdef.
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.

Inductive step :=
| assignments: forall (L: list assignment), step
| conditional: forall (c: comparison) (positive negative: step), step.

Definition algorithm := list step.

Definition instantation := variable -> nat.

Definition list_of_values (i: instantation) :=
  i (num x0) :: i (num x1) :: i (num x2) :: i (num x3) :: i (num x4) :: i (num x5) :: i (num x6) :: i (num x7) :: nil.

Definition is_permutation (i1 i2: instantation) := Permutation (list_of_values i1) (list_of_values i2).

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.

Fixpoint run_step (s: step) (i: instantation): instantation :=
  match s with
  | assignments L => run_assignment_list L i
  | conditional (GT more less) pos neg =>
       if Compare_dec.gt_dec (i (num more)) (i (num less)) then run_step pos i else run_step neg i
  end.

Fixpoint run_algorithm (a: algorithm): instantation -> instantation :=
  match a with
  | nil => fun i => i
  | s :: t => fun i => run_algorithm t (run_step s i)
  end.
Definition permuting_step (s: step) := forall (i: instantation), is_permutation i (run_step s i).
Definition permuting_algorithm (a: algorithm) := forall (i: instantation), is_permutation i (run_algorithm a i).

Theorem permuting_algorithm_aux00 (a: algorithm) (s: step):
  permuting_algorithm (s :: a) -> permuting_algorithm a /\ permuting_step s.
Proof.
Admitted.

这与其说是一个Coq问题,不如说是一个数学问题

可能有一个反例。请对此进行调查:赋值会洗牌寄存器aux、x1、x2、…、x7的值。但是,当您查找置换时,您只查看x1、x2、…、x7的值

假设有一个步骤将x1的值存储到aux中,将x2的值复制到x1和x2中,并保留所有其他寄存器不变。当只查看x1、…、x7中的值列表时,此步骤不是排列(因为重复)。我们把这个叫做 步骤s1

然后考虑将AUX值复制到AUX和X1中的步骤S2,并保持所有其他值不变。同样,当只查看寄存器x1、…、x7时,这不是一个排列,因为它引入了一个以前不在这些寄存器中的值

现在
s1::s2::nil
是寄存器x1、…、x7上的标识函数。这是一种排列。但s1和(s2::nil)都不是置换步骤或置换算法

对于Coq计数器示例,证明s1不是置换步骤就足够了。这是:

Definition la1 :=
  assign aux (num x1) ::
  assign (num x1) (num x2):: nil.

Definition la2 :=
  assign (num x1) aux :: nil.

Definition s1 := assignments la1.
Definition s2 := assignments la2.

Lemma pa_all : permuting_algorithm (s1 :: s2:: nil).
Proof.
intros i.
unfold s1, s2, is_permutation.
unfold list_of_values; simpl.
apply Permutation_refl.
Qed.

Lemma not_permuting_step_s1 : ~permuting_step s1.
Proof.
unfold s1, permuting_step, is_permutation.
set (f := fun x => if variable_eq_dec x (num x1) then 0 else 1).
intros abs.
assert (abs1 := abs f).
revert abs1.
unfold list_of_values, f; simpl; intros abs1.
absurd (In 0 (1::1::1::1::1::1::1::1::nil)).
  simpl; intuition easy.
apply (Permutation_in 0 abs1); simpl; right; left; easy.
Qed.

这与其说是一个Coq问题,不如说是一个数学问题

可能有一个反例。请对此进行调查:赋值会洗牌寄存器aux、x1、x2、…、x7的值。但是,当您查找置换时,您只查看x1、x2、…、x7的值

假设有一个步骤将x1的值存储到aux中,将x2的值复制到x1和x2中,并保留所有其他寄存器不变。当只查看x1、…、x7中的值列表时,此步骤不是排列(因为重复)。我们把这个叫做 步骤s1

然后考虑将AUX值复制到AUX和X1中的步骤S2,并保持所有其他值不变。同样,当只查看寄存器x1、…、x7时,这不是一个排列,因为它引入了一个以前不在这些寄存器中的值

现在
s1::s2::nil
是寄存器x1、…、x7上的标识函数。这是一种排列。但s1和(s2::nil)都不是置换步骤或置换算法

对于Coq计数器示例,证明s1不是置换步骤就足够了。这是:

Definition la1 :=
  assign aux (num x1) ::
  assign (num x1) (num x2):: nil.

Definition la2 :=
  assign (num x1) aux :: nil.

Definition s1 := assignments la1.
Definition s2 := assignments la2.

Lemma pa_all : permuting_algorithm (s1 :: s2:: nil).
Proof.
intros i.
unfold s1, s2, is_permutation.
unfold list_of_values; simpl.
apply Permutation_refl.
Qed.

Lemma not_permuting_step_s1 : ~permuting_step s1.
Proof.
unfold s1, permuting_step, is_permutation.
set (f := fun x => if variable_eq_dec x (num x1) then 0 else 1).
intros abs.
assert (abs1 := abs f).
revert abs1.
unfold list_of_values, f; simpl; intros abs1.
absurd (In 0 (1::1::1::1::1::1::1::1::nil)).
  simpl; intuition easy.
apply (Permutation_in 0 abs1); simpl; right; left; easy.
Qed.

删除此类反例的一个选项可能是要求算法“紧凑”:不动点紧凑型|u算法(a:算法):Prop:=将a与| nil=>True |(赋值L):(赋值L0)::t=>False | x::t=>compact|u算法t end匹配。无论如何,下次我真的应该更仔细地寻找反例。非常感谢。禁止像GTA这样无用的比较。不,我不认为你的紧凑性概念会改变它。问题的症结在于我在第二段中所写的内容:只要你对
x
变量之一执行赋值,你就在执行一个不是排列的步骤。但是,由于名为
aux
的额外寄存器,您仍然可以实现置换。Rideau、Serpette和Leroy撰写了一篇相关的论文。删除此类反例的一个选项可以是要求算法“紧凑”:不动点紧凑_算法(A:algorithm):Prop:=将A与| nil=>True |(赋值L):(赋值L0)::t=>False | x::t=>compact_算法t end匹配。无论如何,下次我真的应该更仔细地寻找反例。非常感谢。禁止像GTA这样无用的比较。不,我不认为你的紧凑性概念会改变它。问题的症结在于我在第二段中所写的内容:只要你对
x
变量之一执行赋值,你就在执行一个不是排列的步骤。但是,由于名为
aux
的额外寄存器,您仍然可以实现置换。Rideau、Serpette和Leroy撰写了一篇相关论文。
Definition la1 :=
  assign aux (num x1) ::
  assign (num x1) (num x2):: nil.

Definition la2 :=
  assign (num x1) aux :: nil.

Definition s1 := assignments la1.
Definition s2 := assignments la2.

Lemma pa_all : permuting_algorithm (s1 :: s2:: nil).
Proof.
intros i.
unfold s1, s2, is_permutation.
unfold list_of_values; simpl.
apply Permutation_refl.
Qed.

Lemma not_permuting_step_s1 : ~permuting_step s1.
Proof.
unfold s1, permuting_step, is_permutation.
set (f := fun x => if variable_eq_dec x (num x1) then 0 else 1).
intros abs.
assert (abs1 := abs f).
revert abs1.
unfold list_of_values, f; simpl; intros abs1.
absurd (In 0 (1::1::1::1::1::1::1::1::nil)).
  simpl; intuition easy.
apply (Permutation_in 0 abs1); simpl; right; left; easy.
Qed.