Step by step simplification in coq?

2019-01-23 17:41发布

Is there a way to simplify one step at a time?

Say you have f1 (f2 x) both of which can be simplified in turn via a single simpl, is it possible to simplify f2 x as a first step, examine the intermediate result and then simplify f1?

Take for example the theorem:

Theorem pred_length : forall n : nat, forall l : list nat,
  pred (length (n :: l)) = length l.
Proof.
  intros.
  simpl.
  reflexivity.
Qed.

The simpl tactic simplifies Nat.pred (length (n :: l)) to length l. Is there a way to break that into a two step simplification i.e:

Nat.pred (length (n :: l)) --> Nat.pred (S (length l)) --> length l

标签: coq
2条回答
神经病院院长
2楼-- · 2019-01-23 17:49

We can turn simplification for pred off, simplify its argument and turn it back on:

Theorem pred_length : forall n : nat, forall l : list nat,
  pred (length (n :: l)) = length l.
Proof.
  intros.
  Arguments pred : simpl never.    (* do not unfold pred *)
  simpl.
  Arguments pred : simpl nomatch.  (* unfold if extra simplification is possible *)
  simpl.
  reflexivity.
Qed.

See §8.7.4 of the Reference Manual for more details.

查看更多
Explosion°爆炸
3楼-- · 2019-01-23 17:56

You can also use simpl for a specific pattern.

Theorem pred_length : forall n : nat, forall l : list nat,
  pred (length (n :: l)) = length l.
Proof.
 intros.
 simpl length.
 simpl pred.
 reflexivity.
Qed.

In case you have several occurrences of a pattern like length that could be simplified, you can further restrict the outcome of the simplification by giving a position of that occurrence (from left to right), e.g. simpl length at 1 or simpl length at 2 for the first or second occurrence.

查看更多
登录 后发表回答