frac.v 1.74 KB
Newer Older
1
From Coq.QArith Require Import Qcanon.
2
From iris.algebra Require Export cmra.
3
From iris.proofmode Require Import classes.
4
Set Default Proof Using "Type".
Robbert Krebbers's avatar
Robbert Krebbers committed
5

6
Notation frac := Qp (only parsing).
Robbert Krebbers's avatar
Robbert Krebbers committed
7

8
9
Section frac.
Canonical Structure fracC := leibnizC frac.
Robbert Krebbers's avatar
Robbert Krebbers committed
10

11
12
13
Instance frac_valid : Valid frac := λ x, (x  1)%Qc.
Instance frac_pcore : PCore frac := λ _, None.
Instance frac_op : Op frac := λ x y, (x + y)%Qp.
Robbert Krebbers's avatar
Robbert Krebbers committed
14

15
Lemma frac_included (x y : frac) : x  y  (x < y)%Qc.
Robbert Krebbers's avatar
Robbert Krebbers committed
16
Proof. by rewrite Qp_lt_sum. Qed.
17

18
19
20
Corollary frac_included_weak (x y : frac) : x  y  (x  y)%Qc.
Proof. intros ?%frac_included. auto using Qclt_le_weak. Qed.

21
Definition frac_ra_mixin : RAMixin frac.
Robbert Krebbers's avatar
Robbert Krebbers committed
22
Proof.
23
  split; try apply _; try done.
Robbert Krebbers's avatar
Robbert Krebbers committed
24
  unfold valid, op, frac_op, frac_valid. intros x y. trans (x+y)%Qp; last done.
25
  rewrite -{1}(Qcplus_0_r x) -Qcplus_le_mono_l; auto using Qclt_le_weak.
Robbert Krebbers's avatar
Robbert Krebbers committed
26
Qed.
27
Canonical Structure fracR := discreteR frac frac_ra_mixin.
28

29
Global Instance frac_cmra_discrete : CmraDiscrete fracR.
30
Proof. apply discrete_cmra_discrete. Qed.
31
End frac.
Robbert Krebbers's avatar
Robbert Krebbers committed
32

33
Global Instance frac_full_exclusive : Exclusive 1%Qp.
34
Proof.
35
  move=> y /Qcle_not_lt [] /=. by rewrite -{1}(Qcplus_0_r 1) -Qcplus_lt_mono_l.
36
Qed.
Zhen Zhang's avatar
Zhen Zhang committed
37

38
39
40
41
42
43
44
45
46
Global Instance frac_cancelable (q : frac) : Cancelable q.
Proof. intros ?????. by apply Qp_eq, (inj (Qcplus q)), (Qp_eq (q+y) (q+z))%Qp. Qed.

Global Instance frac_id_free (q : frac) : IdFree q.
Proof.
  intros [q0 Hq0] ? EQ%Qp_eq. rewrite -{1}(Qcplus_0_r q) in EQ.
  eapply Qclt_not_eq; first done. by apply (inj (Qcplus q)).
Qed.

Ralf Jung's avatar
Ralf Jung committed
47
48
49
50
Lemma frac_op' (q p : Qp) : (p  q) = (p + q)%Qp.
Proof. done. Qed.

Lemma frac_valid' (p : Qp) :  p  (p  1%Qp)%Qc.
Zhen Zhang's avatar
Zhen Zhang committed
51
Proof. done. Qed.
52

53
54
Global Instance is_op_frac q : IsOp' q (q/2)%Qp (q/2)%Qp.
Proof. by rewrite /IsOp' /IsOp frac_op' Qp_div_2. Qed.