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