Coq: Stuck using the subtype

后端 未结 3 1403
我在风中等你
我在风中等你 2021-01-22 04:57

I have following definitions: (definition of positive integers as a subtype of nat)

Definition Z_pos_filter (p: nat) : bool :=
  if (beq_nat p 0) then false else         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 05:07

    Here is how I would do it in vanilla Coq. I'm assuming we can still tweak the definitions.

    From Coq Require Import Arith.
    Local Coercion is_true : bool >-> Sortclass.
    
    Definition Z_pos: Set := {n : nat | 0  Z_pos -> Z_pos.
      intros [x xpos%Nat.ltb_lt] [y ypos%Nat.ltb_lt].
      refine (exist  _ (x * y) _).
      now apply Nat.ltb_lt, Nat.mul_pos_pos.
    Defined.
    
    Lemma compat: forall p q: Z_pos, Z_pos__N (Z_pos_mult p q) = Z_pos__N p * Z_pos__N q.
    Proof. now intros [x xpos] [y ypos]. Qed.
    

    Let me add that dealing with this kind of thing is much more pleasant in SSReflect/Mathcomp.

提交回复
热议问题