pub mod agree;
pub mod auth;
pub mod excl;
pub mod fmap;
mod int;
pub mod lattice;
mod nat;
pub mod option;
mod positive;
mod positive_real;
pub mod prod;
pub mod sum;
pub mod update;
pub mod view;
#[cfg(creusot)]
use crate::logic::such_that;
use crate::{logic::Set, prelude::*};
pub trait RA: Sized {
#[logic]
fn op(self, other: Self) -> Option<Self>;
#[logic(open, inline)]
#[ensures(result == (self == other))]
fn eq(self, other: Self) -> bool {
self == other
}
#[logic]
#[ensures(result == (exists<factor> self.op(factor) == Some(other)))]
fn incl(self, other: Self) -> bool;
#[logic(law)]
#[requires(self.op(other) == Some(comb))]
#[ensures(self.incl(comb))]
fn incl_op(self, other: Self, comb: Self) {}
#[logic(open, sealed)]
fn incl_eq(self, other: Self) -> bool {
self.eq(other) || self.incl(other)
}
#[logic(open, sealed)]
fn incl_eq_op(a: Self, b: Self, x: Self) -> bool {
match a.op(b) {
None => false,
Some(ab) => ab.incl_eq(x),
}
}
#[logic]
#[requires(factor.incl(self))]
#[ensures(factor.op(result) == Some(self))]
fn factor(self, factor: Self) -> Self {
such_that(|r| factor.op(r) == Some(self))
}
#[logic(open, sealed)]
fn update(self, x: Self) -> bool {
pearlite! {
forall<y: Self> self.op(y) != None ==> x.op(y) != None
}
}
#[logic(open, sealed)]
fn update_nondet(self, s: Set<Self>) -> bool {
pearlite! {
forall<y: Self> self.op(y) != None ==>
exists<x: Self> s.contains(x) && x.op(y) != None
}
}
#[logic(law)]
#[ensures(a.op(b) == b.op(a))]
fn commutative(a: Self, b: Self);
#[logic]
#[ensures(a.op(b).and_then_logic(|ab: Self| ab.op(c)) == b.op(c).and_then_logic(|bc| a.op(bc)))]
fn associative(a: Self, b: Self, c: Self);
#[logic(law)]
#[requires(a.op(b) == None)]
#[requires(b.op(c) == Some(bc))]
#[ensures(a.op(bc) == None)]
fn associative_none(a: Self, b: Self, c: Self, bc: Self) {
Self::associative(a, b, c);
}
#[logic(law)]
#[requires(a.op(b) == Some(ab))]
#[requires(b.op(c) == Some(bc))]
#[ensures(a.op(bc) == ab.op(c))]
fn associative_some(a: Self, b: Self, c: Self, ab: Self, bc: Self) {
Self::associative(a, b, c);
}
#[logic(law)]
#[requires(a.incl(b))]
#[requires(b.incl(c))]
#[ensures(a.incl(c))]
fn incl_transitive(a: Self, b: Self, c: Self) {
let _ = Self::associative;
}
#[logic]
fn core(self) -> Option<Self>;
#[logic]
#[requires(self.core() != None)]
#[ensures({
let c = self.core().unwrap_logic();
c.op(c) == Some(c)
})]
#[ensures(self.core().unwrap_logic().op(self) == Some(self))]
fn core_idemp(self);
#[logic]
#[requires(i.op(i) == Some(i))]
#[requires(i.op(self) == Some(self))]
#[ensures(match self.core() {
Some(c) => i.incl(c),
None => false,
})]
fn core_is_maximal_idemp(self, i: Self);
#[logic]
#[ensures(result == (forall<x, y> self.op(x) != None ==>
self.op(x) == self.op(y) ==> x == y))]
fn cancelable(self) -> bool {
pearlite! { forall<x, y> self.op(x) != None ==>
self.op(x) == self.op(y) ==> x == y
}
}
}
pub trait UnitRA: RA {
#[logic]
#[ensures(forall<x: Self> #[trigger(x.op(result))] x.op(result) == Some(x))]
fn unit() -> Self;
#[logic(law)]
#[ensures(forall<x: Self> x.incl(x))]
fn incl_refl() {
let _ = Self::unit();
}
#[logic(open)]
#[ensures(self.core() == Some(result))]
fn core_total(self) -> Self {
self.core_is_maximal_idemp(Self::unit());
self.core().unwrap_logic()
}
#[logic]
#[ensures(self.core_total().op(self.core_total()) == Some(self.core_total()))]
#[ensures(self.core_total().op(self) == Some(self))]
fn core_total_idemp(self);
#[logic(law)]
#[ensures(Self::unit().core_total() == Self::unit())]
fn unit_core() {
Self::unit().core_idemp()
}
}