2010-12-13 40 views
5

Tôi đang cố gắng để sử dụng chức năng để xác định một định nghĩa đệ quy sử dụng một biện pháp, và tôi nhận được lỗi:Sử dụng forall trong đệ quy định nghĩa Chức năng

Error: find_call_occs : Prod 

tôi gửi bài mã nguồn toàn bộ tại dưới cùng, nhưng chức năng của tôi là

Function kripke_sat (M : kripke) (s : U) (p : formula) {measure size p}: Prop := 
match p with 
| Proposition p' => L M (s)(p') 
| Not p' => ~ kripke_sat M s p' 
| And p' p'' => kripke_sat M s p' /\ kripke_sat M s p'' 
| Or p' p'' => kripke_sat M s p' \/ kripke_sat M s p'' 
| Implies p' p'' => ~kripke_sat M s p' \/ kripke_sat M s p'' 
| Knows a p' => forall t, ~(K M a) s t \/ kripke_sat M t p' 
| EvKnows p' => forall i, kripke_sat M s (Knows i p') 
end. 

Tôi biết vấn đề là do các yếm: nếu tôi thay thế bằng True, nó hoạt động. Tôi cũng biết tôi gặp lỗi tương tự nếu phía bên tay phải của tôi sử dụng các hàm ý (->). Fixpoint hoạt động với các quầy hàng, nhưng không cho phép tôi xác định thước đo.

Bạn có lời khuyên nào không?

Như đã hứa, mã hoàn chỉnh của tôi là:

Module Belief. 

Require Import Arith.EqNat. 
Require Import Arith.Gt. 
Require Import Arith.Plus. 
Require Import Arith.Le. 
Require Import Arith.Lt. 
Require Import Logic. 
Require Import Logic.Classical_Prop. 
Require Import Init.Datatypes. 

Require Import funind.Recdef. 

(* Formalization of a variant of a logic of knowledge, as given in Halpern 1995 *) 

Section Kripke. 

    Variable n : nat. 
    (* Universe of "worlds" *) 
    Definition U := nat. 
    (* Universe of Principals *) 
    Definition P := nat. 
    (* Universe of Atomic propositions *) 
    Definition A := nat. 

    Inductive prop : Type := 
    | Atomic : A -> prop. 

    Definition beq_prop (p1 p2 :prop) : bool := 
    match (p1,p2) with 
     | (Atomic p1', Atomic p2') => beq_nat p1' p2' 
    end. 

    Inductive actor : Type := 
    | Id : P -> actor. 

    Definition beq_actor (a1 a2: actor) : bool := 
    match (a1,a2) with 
     | (Id a1', Id a2') => beq_nat a1' a2' 
    end. 

    Inductive formula : Type := 
    | Proposition : prop -> formula 
    | Not : formula -> formula 
    | And : formula -> formula -> formula 
    | Or : formula -> formula -> formula 
    | Implies : formula -> formula ->formula 
    | Knows : actor -> formula -> formula 
    | EvKnows : formula -> formula (*me*) 
    . 

    Inductive con : Type := 
    | empty : con 
    | ext : con -> prop -> con. 

    Notation " C# P " := (ext C P) (at level 30). 

    Require Import Relations. 

    Record kripke : Type := mkKripke { 
    K : actor -> relation U; 
    K_equiv: forall y, equivalence _ (K y); 
    L : U -> (prop -> Prop) 
    }. 

Fixpoint max (a b: nat) : nat := 
    match a, b with 
    | 0, _ => a 
    | _, 0 => b 
    | S(a'), S(b') => 1 + max a' b' 
end. 

Fixpoint length (p: formula) : nat := 
    match p with 
    | Proposition p' => 1 
    | Not p' => 1 + length(p') 
    | And p' p'' => 1 + max (length p') (length p'') 
    | Or p' p'' => 1 + max (length p') (length p'') 
    | Implies p' p'' => 1 + max (length p') (length p'') 
    | Knows a p' => 1 + length(p') 
    | EvKnows p' => 1 + length(p') 
end. 

Fixpoint numKnows (p: formula): nat := 
    match p with 
| Proposition p' => 0 
| Not p' => 0 + numKnows(p') 
| And p' p'' => 0 + max (numKnows p') (numKnows p'') 
| Or p' p'' => 0 + max (numKnows p') (numKnows p'') 
| Implies p' p'' => 0 + max (numKnows p') (numKnows p'') 
| Knows a p' => 0 + numKnows(p') 
| EvKnows p' => 1 + numKnows(p') 
end. 

Definition size (p: formula): nat := 
(numKnows p) + (length p). 

Definition twice (n: nat) : nat := 
n + n. 

Theorem duh: forall a: nat, 1 + a > a. 
Proof. induction a. apply gt_Sn_O. 
apply gt_n_S in IHa. unfold plus in *. apply IHa. Qed. 

Theorem eq_lt_lt: forall (a b c d: nat), a = b -> c<d -> a+ c< b+d. 
Proof. intros. apply plus_le_lt_compat. 
apply eq_nat_elim with (n:=a) (m := b). apply le_refl. 
apply eq_nat_is_eq. apply H. apply H0. Qed. 


Function kripke_sat (M : kripke) (s : U) (p : formula) {measure size p}: Prop := 
    match p with 
| Proposition p' => L M (s)(p') 
| Not p' => ~ kripke_sat M s p' 
| And p' p'' => kripke_sat M s p' /\ kripke_sat M s p'' 
| Or p' p'' => kripke_sat M s p' \/ kripke_sat M s p'' 
| Implies p' p'' => ~kripke_sat M s p' \/ kripke_sat M s p'' 
| Knows a p' => forall t, ~(K M a) s t \/ kripke_sat M t p' 
| EvKnows p' => forall i, kripke_sat M s (Knows i p') 
end. 

Trả lời

6

Các "Function" plugin vẫn còn rất thực nghiệm. Trong tài liệu bạn có thể tìm

term0 must be build as a pure pattern-matching tree (match...with) with λ-abstractions and applications only at the end of each branch.

Nhưng tôi phải đồng ý rằng thông báo lỗi này là xa là rõ ràng (thông báo lỗi thường như vậy nên một trong hai kết thúc với "Đề nghị thông báo" hoặc có nhiều người dùng thân thiện, tôi coi đây là lỗi). Nó có nghĩa là yếm không được phép trong cơ thể của một chức năng (tôi không biết có hay không có lý do lý thuyết cho hành vi này).

Vì vậy, bạn cần thực hiện định nghĩa của mình "bằng tay" mà không cần sự trợ giúp của Chức năng. Dưới đây là một ví dụ nhỏ bạn có thể thích ứng với sự phát triển của bạn. Chúc may mắn!


Inductive form : Set := 
    | T : form 
    | K : nat -> form -> form 
    | eK : form -> form. 

Fixpoint size (f : form) : nat := match f with 
    | T => 1 
    | K _ f => S (size f) 
    | eK f => S (S (size f)) 
end. 

Require Import Wf. 
Require Import Wf_nat. 

Definition R x y := size x < size y. 
Lemma R_wf : well_founded R. 
    apply well_founded_ltof. 
Qed. 

Lemma lem1 : 
    forall x n, R x (K n x). 
unfold R; intuition. 
Qed. 

Lemma lem2 : 
    forall x n, R (K n x) (eK x). 
unfold R; intuition. 
Qed. 


Definition interpret : form -> Prop. 
(* we use the well_founded_induction instead of Function *) 
refine (well_founded_induction_type R_wf (fun _ => Prop) (fun x f => _)). 
destruct x. 
exact True.          (* ⟦T⟧ ≡ True *) 
exact (n = 2 /\ f x (lem1 x n)).    (* ⟦K n F⟧ ≡ (n = 2) ∧ ⟦F⟧ *) 
exact (forall n:nat, f (K n x) (lem2 x n)).  (* ⟦eK F⟧ ≡ ∀n:nat,⟦K n F⟧ *) 
Defined. 

PS: Tôi sẽ điền vào báo cáo lỗi với phiên bản mã đơn giản sau đây của bạn.

Require Import Recdef. 

    Inductive I : Set := 
    | C : I. 

    Definition m (_ : I) := 0. 

    Function f (x : I) {measure m x} : Type := match x with 
    | C => nat -> nat end. 
0

Thông báo lỗi đã thay đổi trong Coq 8.4 nhưng vấn đề vẫn còn đó. Các thông báo lỗi mới là: "Lỗi: Tìm thấy một sản phẩm không thể đối xử với một thuật ngữ như vậy."

sự thay đổi trong thông báo lỗi này cũng dẫn đến lỗi của Marc bị đóng cửa: http://www.lix.polytechnique.fr/coq/bugs/show_bug.cgi?id=2457

Các vấn đề liên quan