简体   繁体   English

我怎样才能证明forall ab,a <=? b = true -> a <=? S b = 在 Coq 中为真

[英]How can I proove forall a b, a <=? b = true -> a <=? S b = true in Coq

Is it possible to prove this forall (ab: nat), a <=? b = true -> a <=? S b = true.是否有可能证明这个forall (ab: nat), a <=? b = true -> a <=? S b = true. forall (ab: nat), a <=? b = true -> a <=? S b = true. in Coq?在考克?

I tried this so far到目前为止我试过这个

Lemma leb_0_r : forall x, x <=? 0 = true -> x = 0.
  intros. induction x. reflexivity. discriminate H. 
Qed.

Lemma leb_S : forall a b, a <=? b = true -> a <=? S b = true.
  intros a b Hab. induction b. apply leb_0_r in Hab. now rewrite Hab.

But here I got stuck on the induction hypothesis但是在这里我陷入了归纳假设

1 subgoal

a, b : nat
Hab : (a <=? S b) = true
IHb : (a <=? b) = true -> (a <=? S b) = true

========================= (1 / 1)

(a <=? S (S b)) = true

I tried induction on a too我也试过感应

Lemma leb_S : forall a b, a <=? b = true -> a <=? S b = true.
  intros a b Hab. induction a. reflexivity. simpl. destruct b.
  discriminate Hab. simpl in Hab.


1 subgoal

a, b : nat
Hab : (a <=? b) = true
IHa : (a <=? S b) = true -> (a <=? S (S b)) = true

========================= (1 / 1)

(a <=? S b) = true

The problem is that I always get to S a <= b or a <= S b and I can't simplify that.问题是我总是得到S a <= ba <= S b ,我无法简化它。

After posting here I realized that conclusion of IHa is equal to the goal of second try and vice versa:thinking:在这里发帖后,我意识到 IHa 的结论等于第二次尝试的目标,反之亦然:思考:

You could try not to use induction, but transitivity of the <= relation instead.您可以尝试不使用归纳,而是使用<=关系的传递性。

I am nor sure if you are learning Coq and this is an exercise or if you are using Coq.我不确定您是否正在学习 Coq,这是一个练习,或者您是否正在使用 Coq。 In the latter case the answer is: I would have thought the lia tactic can do this, but it requires a bit of massaging:在后一种情况下,答案是:我原以为 lia 策略可以做到这一点,但它需要一点按摩:

Require Import PeanoNat.
Require Import Lia.

Lemma leb_0_r : forall x, x <=? 0 = true -> x = 0.
Proof.
  intros.
  Fail lia.
  Search (_ <=? _ = true).
  apply Nat.leb_le in H.
  lia.
Qed.

In the former case, I would need to know what you are allowed to use.在前一种情况下,我需要知道您可以使用什么。 Eg this works:例如,这有效:

Require Import PeanoNat.

Lemma leb_0_r : forall x, x <=? 0 = true -> x = 0.
Proof.
  intros.
  apply Nat.leb_le in H.
  inversion H.
  reflexivity.
Qed.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM