Agda中有哪些大小的类型?我试图阅读有关MiniAgda的文章,但由于以下几点未能继续:
>
和#
模式意味着什么?我试图在Coq中定义Ackermann-Peters函数,我收到一条我不明白的错误消息.正如你所看到的,我把a, b
Ackermann 的论据打包成一对ab
; 我提供了一个定义参数的排序函数的排序.然后我使用Function
表单来定义Ackermann本身,为它提供ab
参数的排序函数.
Require Import Recdef.
Definition ack_ordering (ab1 ab2 : nat * nat) :=
match (ab1, ab2) with
|((a1, b1), (a2, b2)) =>
(a1 > a2) \/ ((a1 = a2) /\ (b1 > b2))
end.
Function ack (ab : nat * nat) {wf ack_ordering} : nat :=
match ab with
| (0, b) => b + 1
| (a, 0) => ack (a-1, 1)
| (a, b) => ack (a-1, …
Run Code Online (Sandbox Code Playgroud) 有喜欢的战术什么simpl
的Program Fixpoint
S'
特别是,如何证明以下琐碎的陈述?
Program Fixpoint bla (n:nat) {measure n} :=
match n with
| 0 => 0
| S n' => S (bla n')
end.
Lemma obvious: forall n, bla n = n.
induction n. reflexivity.
(* I'm stuck here. For a normal fixpoint, I could for instance use
simpl. rewrite IHn. reflexivity. But here, I couldn't find a tactic
transforming bla (S n) to S (bla n).*)
Run Code Online (Sandbox Code Playgroud)
显然,Program Fixpoint
这个玩具示例没有必要,但我在一个更复杂的设置中面临同样的问题,我需要证明Program Fixpoint
手动终止.
我和Coq鬼混.具体来说,我试图实现mergesort,然后证明它的工作原理.
我尝试实施的是:
Fixpoint sort ls :=
match ls with
| nil => nil
| cons x nil => cons x nil
| xs =>
let (left, right) := split xs nil nil
in merge (sort left) (sort right)
end.
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Error:
Recursive definition of sort is ill-formed.
In environment
sort : list nat -> list nat
ls : list nat
x : nat
l : list nat
y : nat
l0 : list nat
left : list nat
right : …
Run Code Online (Sandbox Code Playgroud) http://docs.idris-lang.org/en/v0.99/tutorial/theorems.html#totality-checking-issues指出:
其次,到目前为止,目前的实施工作进展有限,因此可能仍然存在一种情况,即它认为功能是总的而不是.不要依赖它来证明你的证明!
这是否意味着不能依赖Idris作为证据,或者是否有办法创建不需要整体检查的证明?
他们似乎服务于类似的目的.到目前为止我注意到的一个区别是,虽然Program Fixpoint
会接受一个复合测量{measure (length l1 + length l2) }
,但Function
似乎拒绝这个并且只会允许{measure length l1}
.
是否Program Fixpoint
比Function
它们更强大,或者它们更适合不同的用例?
I'm trying to formalize each integer as an equivalence class of pairs of natural numbers, where the first component is the positive part, and the second component is the negative part.
Definition integer : Type := prod nat nat.
I want to define a normalization function where positives and negatives cancel as much as possible.
Fixpoint normalize (i : integer) : integer :=
let (a, b) := i in
match a with
| 0 => (0, b)
| S a' …
Run Code Online (Sandbox Code Playgroud) 我对术语有以下定义:
Inductive term : Type :=
| Var : variable -> term
| Func : function_symbol -> list term -> term.
Run Code Online (Sandbox Code Playgroud)
一个函数,该函数pos_list
获取术语列表并为每个子术语返回“位置”列表。例如,对于[Var "e"; Func "f" [Var "x"; Func "i" [Var "x"]]]
我来说,应该知道[[1]; [2]; [2; 1]; [2; 2]; [2; 2; 1]]
每个元素在子项的树层次结构中的位置。
Definition pos_list (args:list term) : list position :=
let fix pos_list_aux ts is head :=
let enumeration := enumerate ts in
let fix post_enumeration ts is head :=
match is with
| [] => [] …
Run Code Online (Sandbox Code Playgroud) 为了通过一个良好的关系理解递归,我决定实现扩展的欧几里得算法。
扩展的欧几里得算法适用于整数,因此我需要一些关于整数的良好依据。我尝试使用中的关系Zwf
,但没有任何效果(我需要查看更多示例)。我认为使用该函数映射Z
起来会更容易,然后将其用作关系即可。我们的朋友来帮助我。所以这是我做的:nat
Z.abs_nat
Nat.lt
wf_inverse_image
Require Import ZArith Coq.ZArith.Znumtheory.
Require Import Wellfounded.
Definition fabs := (fun x => Z.abs_nat (Z.abs x)). (* (Z.abs x) is a involutive nice guy to help me in the future *)
Definition myR (x y : Z) := (fabs x < fabs y)%nat.
Definition lt_wf_on_Z := (wf_inverse_image Z nat lt fabs) lt_wf.
Run Code Online (Sandbox Code Playgroud)
扩展的欧几里得算法如下所示:
Definition euclids_type (a : Z) := forall b : Z, Z * Z * Z.
Definition euclids_rec …
Run Code Online (Sandbox Code Playgroud) 编辑
Require Import Bool List ZArith.
Variable A: Type.
Inductive error :=
| Todo.
Inductive result (A : Type) : Type :=
Ok : A -> result A | Ko : error -> result A.
Variable bool_of_result : result A -> bool.
Variable rules : Type.
Variable boolean : Type.
Variable positiveInteger : Type.
Variable OK: result unit.
Definition dps := rules.
Inductive dpProof :=
| DpProof_depGraphProc : list
(dps * boolean * option (list positiveInteger) * option dpProof) -> …
Run Code Online (Sandbox Code Playgroud)