Error in defining Ackermann in Coq

前端 未结 3 1670
终归单人心
终归单人心 2020-12-31 09:37

I am trying to define the Ackermann-Peters function in Coq, and I\'m getting an error message that I don\'t understand. As you can see, I\'m packaging the arguments a,

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 10:04

    You get this error because you are referencing the ack function while you are defining it. Self reference is only allowed in Fixpoints (ie. recursive functions) but the problem is, as you probably know, that the Ackermann function is not a primitive recursive function.

    See Coq'Art section 4.3.2.2 for some more information on this.

    So one alternative way to define it is by inlining a second recursive function that is structurally recursive for the second argument; so something like

    Fixpoint ack (n m : nat) : nat :=
      match n with
      | O => S m
      | S p => let fix ackn (m : nat) :=
                   match m with
                   | O => ack p 1
                   | S q => ack p (ackn q)
                   end
               in ackn m
      end.
    

提交回复
热议问题