首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Coq上变换离开前一状态的引理

在Coq上变换离开前一状态的引理
EN

Stack Overflow用户
提问于 2020-09-21 11:24:57
回答 2查看 127关注 0票数 0

我想部分导出输入是依赖列表的函数。

我试图用证明来定义deriveP

DeriveCoquelicot.Derive中的一个函数。

代码语言:javascript
复制
Definition deriveP {P A B}(k:nat)(I:Euc (S P) -> Euc A -> Euc B)
                             (input:Euc A)(train:Euc B)(p :Euc (S P)) 
                              :(lt k (S P)) -> (lt ((S P)-(k+1)) (S P)) -> R.
intros.
pose fk := firstk k (S P) p H.
pose lk := lastk ((S P)-(k+1)) (S P) p H0.
pose pk := EucNth k p.
apply arith_basic in H.
exact ( Derive (fun PK => EucSum (QuadraticError (I (fk +++ (PK ::: lk)) input) train )) pk ).

我不能应用蒂亚戈弹出的arith_basic,因为H在fk中使用。在生成fk之前,我可以将arith_basic应用于H,但是由于没有k < P.+1,所以我不能使用fk。

我想在离开arith_basic的时候将k < P.+1应用于H。

请帮帮我。

(***********************************************************)

这是R的依赖列表。

代码语言:javascript
复制
Require Import Coq.Reals.Reals.
Require Import Coquelicot.Coquelicot.

Inductive Euc:nat -> Type:=
|RO : Euc 0
|Rn : forall {n:nat}, R -> Euc n -> Euc (S n).

Notation "[ ]" := RO.
Notation "[ r1 , .. , r2 ]" := (Rn r1 .. ( Rn r2 RO ) .. ).
Infix ":::" := Rn (at level 60, right associativity).

基本列表操作。

代码语言:javascript
复制
Definition head {n} (v : Euc (S n)) : R :=
  match v with
  | x ::: _ => x
  end.

Definition tail {n} (v : Euc (S n)) : Euc n :=
  match v with
  | _ ::: v => v
  end.

(* extract the last element *)   
Fixpoint last {n} : Euc (S n) -> R :=
  match n with
  | 0%nat => fun v => head v
  | S n => fun v => last (tail v)
  end.

(* eliminate last element from list *)
Fixpoint but_last {n} : Euc (S n) -> Euc n :=
  match n with
  | 0%nat => fun _ => []
  | S n => fun v => head v ::: but_last (tail v)
  end.
 
(* do the opposite of cons *)
Fixpoint snoc {n} (v : Euc n) (x : R) : Euc (S n) :=
  match v with
  | [] => [x]
  | y ::: v => y ::: snoc v x
  end.

(* extract last k elements *)
Fixpoint lastk k n : Euc n -> (lt k n) -> Euc k := 
  match n with
    |0%nat => fun _ (H : lt k 0) => False_rect _ (Lt.lt_n_O _ H)
    |S n => match k with
              |S m => fun v H => snoc (lastk m n (but_last v) (le_S_n _ _ H)) (last v)
              |0%nat => fun _ H => []
            end
  end.

(* extract first k elements *)
Fixpoint firstk k n : Euc n -> (lt k n) -> Euc k := 
  match n with
    |0%nat => fun _ (H :lt k 0) => False_rect _ (Lt.lt_n_O _ H)
    |S n => match k with
              |S m => fun v H => (head v) ::: firstk m n (tail v) (le_S_n _ _ H)
              |0%nat => fun _ _ => []
            end
  end.

(* extract nth element *)
(* 0 origine *)
Fixpoint EucNth (k:nat) :forall {n}, Euc (S n) -> R:=
 match k with
 | 0%nat => fun _ e => head e
 | S k' => fun n =>
   match n return Euc (S n) -> R with
   | 0%nat => fun e => head e
   | S n' => fun v => EucNth k' (tail v)
   end
 end.

Fixpoint EucAppend {n m} (e:Euc n) (f:Euc m) :Euc (n+m):=
 match e with
 |[] => f
 |e' ::: es => e' ::: (EucAppend es f)
 end.

Infix "+++" := EucAppend (at level 60, right associativity).

Fixpoint QuadraticError {n : nat} (b : Euc n) : Euc n -> Euc n.
refine (match b in Euc n return Euc n -> Euc n with
    |@Rn m x xs => _    
    |@RO => fun H => []
 end).
remember (S m).
intro H; destruct H as [| k y ys].
inversion Heqn0.
inversion Heqn0.
subst; exact ((x - y)^2 ::: QuadraticError _ xs ys).
Defined.

Fixpoint EucSum {A}(e:Euc A) :R:=
 match e with
 | [] => 0%R
 | e' ::: es => e' + (EucSum es)
 end.
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-23 10:46:54

我自己解决了。

我们可以用generalize策略在子目标中复制引理.

代码语言:javascript
复制
Definition deriveP {P A B}(k:nat)(I:Euc (S P) -> Euc A -> Euc B)
                                 (input:Euc A)(train:Euc B)(p :Euc (S P)) 
                                  :(lt k (S P)) -> (lt ((S P)-(k+1)) (S P)) -> R.
intros.
generalize H.
intro H1.
apply arith_basic in H1.
pose lk := lastk ((S P)-(k+1)) (S P) p H0.
pose fk := firstk k (S P) p H.
pose pk := EucNth k p.
rewrite (_: (P.+1)%nat = (k + (P.+1 - (k + 1)%coq_nat)%coq_nat.+1)%coq_nat) in I.
exact ( Derive (fun PK => EucSum (QuadraticError (I (fk +++ (PK ::: lk)) input) train )) pk ).
apply H1.
Defined.
票数 0
EN

Stack Overflow用户

发布于 2020-09-22 03:49:21

你的引理k+S (P - (k + 1)) =P只需基本代数运算即可求解。特别是你只需要两个柠檬就可以让这更容易:

代码语言:javascript
复制
Theorem minus_assoc : forall y z, z < y -> z + (y - z) = y.
  intro y.
  induction y.
  intros;inversion H.
  intros.
  destruct z.
  trivial.
  rewrite PeanoNat.Nat.sub_succ.
  rewrite <- (IHy _ (le_S_n _ _ H)) at 2; trivial.
Qed.

Theorem minus_S : forall x y, y < x -> S (x - (S y)) = x - y.
  intro.
  induction x.
  intros.
  inversion H.
  intros.
  destruct y.
  simpl.
  rewrite PeanoNat.Nat.sub_0_r; trivial.
  rewrite PeanoNat.Nat.sub_succ.
  apply IHx.
  exact (le_S_n _ _ H).
Qed.

现在你只需要把你的目标改写成一个琐碎的介词:

代码语言:javascript
复制
Theorem arith_basic : forall k P, k < P -> k + S (P - (k + 1)) = P.
  intros.
  rewrite PeanoNat.Nat.add_1_r.
  rewrite minus_S.
  auto.
  rewrite minus_assoc.
  assumption.
  trivial.
Qed.

这些目标中的大多数都可以通过lia策略自动求解Z、nat、正数和N的算术目标。

代码语言:javascript
复制
Theorem arith_basic : forall k P, k < P -> k + S (P - (k + 1)) = P.
  intros;lia.
Qed

即使我推荐自动化,用手证明可以帮助理解您的主要目标,这可能无法通过自动化来解决。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63991302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档