vstd_extra/resource/pcm/
frac.rs1use vstd::arithmetic::*;
11use vstd::pcm::PCM;
12use vstd::prelude::*;
13
14verus! {
15
16#[verifier::ext_equal]
18pub ghost enum FracR<T> {
19 Unit,
20 Frac(real, T),
21 Invalid,
22}
23
24impl<T: PartialEq> PCM for FracR<T> {
25 open spec fn valid(self) -> bool {
26 match self {
27 FracR::Unit => true,
28 FracR::Frac(q, _) => 0.0real < q && q <= 1.0real,
29 FracR::Invalid => false,
30 }
31 }
32
33 open spec fn op(self, other: Self) -> Self {
35 match (self, other) {
36 (FracR::Unit, x) => x,
37 (x, FracR::Unit) => x,
38 (FracR::Frac(q1, a1), FracR::Frac(q2, a2)) => {
39 if a1 == a2 && 0.0real < q1 && 0.0real < q2 && q1 + q2 <= 1.0real {
40 FracR::Frac(q1 + q2, a1)
41 } else {
42 FracR::Invalid
43 }
44 },
45 _ => FracR::Invalid,
46 }
47 }
48
49 open spec fn unit() -> Self {
50 FracR::Unit
51 }
52
53 proof fn closed_under_incl(a: Self, b: Self) {
54 }
55
56 proof fn commutative(a: Self, b: Self) {
57 }
58
59 proof fn associative(a: Self, b: Self, c: Self) {
60 }
61
62 proof fn op_unit(a: Self) {
63 }
64
65 proof fn unit_valid() {
66 }
67}
68
69}