Skip to content

Commit

Permalink
Binding weak cbv to reduction tactic "cbv head".
Browse files Browse the repository at this point in the history
Include some rephrasing in doc, co-authored by Jim.

Co-Authored-By: Jim Fehrle <jim.fehrle@gmail.com>
  • Loading branch information
herbelin and jfehrle committed Oct 27, 2023
1 parent 8301093 commit 710fdb0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
7 changes: 4 additions & 3 deletions doc/changelog/04-tactics/17503-redexpr.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- **Added:**
:tacn:`lazy`, :tacn:`simpl` and :tacn:`cbn` and the associated :cmd:`Eval` and :tacn:`eval` reductions
learnt to do head reduction when given flag `head`
:tacn:`lazy`, :tacn:`simpl`, :tacn:`cbn` and :tacn:`cbv` and the associated :cmd:`Eval`
and :tacn:`eval` reductions learned to do head reduction when given flag `head`
(eg `Eval lazy head in (fun x => Some ((fun y => y) x)) 0` produces `Some ((fun y => y) 0)`)
(`#17503 <https://github.com/coq/coq/pull/17503>`_,
by Gaëtan Gilbert).
by Gaëtan Gilbert; :tacn:`cbv` case added in `#18190 <https://github.com/coq/coq/pull/18190>`_,
by Hugo Herbelin).
8 changes: 4 additions & 4 deletions doc/sphinx/proofs/writing-proofs/equality.rst
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ which reduction engine to use. See :ref:`type-cast`.) For example:
.. prodn::
reductions ::= {+ @reduction }
| {? head } @delta_reductions
reduction ::= beta
reduction ::= head
| beta
| delta {? @delta_reductions }
| head
| match
| fix
| cofix
Expand All @@ -508,8 +508,8 @@ which reduction engine to use. See :ref:`type-cast`.) For example:
then only the named reductions are applied. The reductions include:

`head`
Do only head reduction, without going under binders. Only
supported by :tacn:`simpl`, :tacn:`cbn` and :tacn:`lazy`.
Do only head reduction, without going under binders.
Supported by :tacn:`simpl`, :tacn:`cbv`, :tacn:`cbn` and :tacn:`lazy`.
If this is the only specified reduction, all other reductions are applied.

`beta`
Expand Down
2 changes: 1 addition & 1 deletion doc/tools/docgram/orderedGrammar
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ reductions: [
]

reduction: [
| "head"
| "beta"
| "delta" OPT delta_reductions
| "head"
| "match"
| "fix"
| "cofix"
Expand Down
2 changes: 1 addition & 1 deletion tactics/redexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ let reduction_of_red_expr_val = function
in
(contextualize am o,DEFAULTcast)
| Cbv (Norm, f) -> (e_red (cbv_norm_flags ~strong:true f),DEFAULTcast)
| Cbv (Head, _) -> CErrors.user_err Pp.(str "cbv does not support head-only reduction.")
| Cbv (Head, f) -> (e_red (cbv_norm_flags ~strong:false f),DEFAULTcast)
| Cbn (w,f) ->
let cbn = match w with Norm -> Cbn.norm_cbn | Head -> Cbn.whd_cbn in
(e_red (cbn f), DEFAULTcast)
Expand Down
6 changes: 6 additions & 0 deletions test-suite/output/reduction.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
| S p => S (add p m)
end) 1 2)
: nat
= 4
: nat
= (fix add (n m : nat) {struct n} : nat :=
match n with
| 0 => m
Expand All @@ -23,6 +25,10 @@
: nat
= S (1 + 2 + 2)
: nat
= 6
: nat
= ignore (fun x : nat => 1 + x)
: unit
= ignore (fun x : nat => 1 + x)
: unit
= ignore (fun x : nat => 1 + x)
Expand Down
4 changes: 4 additions & 0 deletions test-suite/output/reduction.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ Eval hnf in match (plus (S n) O) with S n => n | _ => O end.
Eval simpl head in 2 + 2.
Eval cbn head in 2 + 2.
Eval lazy head in 2 + 2.
Eval cbv head in 2 + 2.

Eval lazy head delta in 2 + 2.

Eval simpl head in 2 + (2 + 2).

Eval simpl head in (2 + 2) + 2.

Eval cbv head in (2 + 2) + 2.

Axiom ignore : forall {T}, T -> unit.
Eval simpl head in ignore (fun x => 1 + x).
Eval cbn head in ignore (fun x => 1 + x).
Eval lazy head in ignore (fun x => 1 + x).
Eval cbv head in ignore (fun x => 1 + x).

0 comments on commit 710fdb0

Please sign in to comment.