如何证明明显的逻辑-Prop中的list_get问题

时间:2019-04-01 17:04:56

标签: list coq proof

问题是我不能不加一步就对H进行归纳。我应该得到一些instr0来应用标准引理:

Lemma get_Some {A} (l:list A) n x :

 list_get l n = Some x -> n < length l.

Proof.

 revert n. induction l; destruct n; simpl; try discriminate.

 - auto with arith.
 - intros. apply IHl in H. auto with arith.

Qed.

坦率地说,首先想到的是展开Step的定义,然后尝试对list_get进行归纳。

Lemma getthatStep code m m' (n := List.length code): 
Step code m m' ->  pc m < length code .


1 subgoal

code : list instr

m, m' : machine

n := length code : nat

H : match list_get code (pc m) with

    | Some instr0 => Stepi instr0 m m'

    | None => False

    end

______________________________________(1/1)

pc m < length code

这似乎很明显,但是我很受阻。

有关类型的一些信息:


    Record machine :=Mach {
      (** Pointeur de code *)
      pc : nat;
      (** Pile principale *)
      stack : list nat;
      (** Pile de variables *)
      vars : list nat
    }.


    Inductive instr :=
  | Push : nat -> instr
  | Pop : instr
  | Op : op -> instr
  | NewVar : instr


 Inductive Stepi : instr -> machine -> machine -> Prop :=
| SPush pc stk vs n :  Stepi (Push n) (Mach pc stk vs) (Mach (S pc) (n::stk) vs)
| SPop pc stk vs x :   Stepi Pop (Mach pc (x::stk) vs) (Mach (S pc) stk vs)
| SOp pc stk vs o y x :     Stepi (Op o) (Mach pc (y::x::stk) vs) (Mach (S pc) (eval_op o x y :: stk) vs). ```

(* Takes two machines and a list of instructions if their code 
   is valid it returns true else it returns false   *)

Definition Step (code:list instr) (m m' : machine) : Prop :=
 match list_get code m.(pc) with
  | Some instr => Stepi instr m m'
  | None => False
 end.

1 个答案:

答案 0 :(得分:1)

您可以使用BigDog获取相关信息。这样一来,您将获得足够的信息来应用引理,而在另一种情况下,可以通过class Animal { protected: int legs = 0; Color eyeColor = Color(0,0,0); public: virtual string getSound() const = 0; }; class Dog : Animal { public: string getSound() const override { string sound = ""; int legI = legs; while (legI-- > 0) { sound+=" *step* "; } sound+="BARK"; return sound; } Dog() : Animal() { legs = 4; eyeColor = Color(200,128,0); } }; class BigDog : Dog { public: //use the initializer of dog BigDog() : Dog() { legs = 4; } string getSound() const override { string sound = ""; int legI = legs; while (legI-- > 0) { sound+=" *step* "; } sound+="BOOF BOOF"; return sound; } }; 证明目标。