Extension of recursive functions in Coq

Background

I understand that Iota abbreviation is used to reduce / expand recursive functions. For example, given the following application of a simple recursive function (factorial over natural numbers):

((fix fact (n:nat):nat := match n with | O => 1 | S m => n * fact m end) 2)

The abbreviation Iota extends the recursive call, effectively repeating the recursive function once:

Eval lazy iota in ((fix fact (n:nat):nat := match n with | O => 1 | S m => n * fact m end) 2).
 = (fun n:nat =>
    match n with
    | 0 => 1
    | S m =>
        n *
        (fix fact (m : nat) : nat :=
           match m with
           | 0 => 1
           | S m0 => m * fact m0
           end) m
    end) 2.

This behavior generalizes well to mutually recursive functions. For example, given the following mutually recursive function definitions:

Fixpoint even (n:nat):Prop := match n with | O => True | S m => odd m end
  with odd (n:nat):Prop := match n with | O => False | S m => even m end.

The iota reduction will correctly expand on recursive calls to even or odd, respectively. To do this, consider:

Theorem even_2 : even 2.
1 subgoal
==========
even 2
> lazy delta.

1 subgoal
==========
(fix even (n:nat):Prop := match n with ... end
 with odd (n:nat):Prop := match n with ... end
 for even) 2
> lazy iota.

1 subgoal
==========
(fun n:nat =>
  match n with
    | O => True
    | S m => (fix even (o:nat):Prop := match o with ... end
              with odd (o:nat):Prop := match o with ... end
              for odd) m
  end) 2

Problem

, , . , -, , Coq Iota , , . , :

Theorem even_n : forall n:nat, even n.
1 subgoal
==========
forall n:nat, even n
> intro n.

1 subgoal
n : nat
==========
even n
> lazy delta.

1 subgoal
==========
(fix even (n:nat):Prop := match n with ... end
 with odd (n:nat):Prop := match n with ... end
 for even) n
> lazy iota. (* FAILS TO REDUCE! *)

1 subgoal
==========
(fix even (n:nat):Prop := match n with ... end
 with odd (n:nat):Prop := match n with ... end
 for even) n

, Iota , Coq to Iota . , .

Coq Iota , - , ?

. , -

+4
1

, iota : Coq , iota , .

, : iota, , .

, ​​ , :

  • (n, ) , . , .

  • . , odd n <-> ~ even n, . ( , even):

    Goal forall n, even n = match n with | O => False | S m => odd m end.
    now destruct n.
    Qed.
    
+6

Source: https://habr.com/ru/post/1584284/


All Articles