Struct creusot_contracts::logic::Int

source ·
pub struct Int(/* private fields */);
Expand description

An unbounded, mathematical integer.

This type cannot be only be constructed in logical or ghost code.

§Integers in pearlite

Note that in pearlite, all integer literals are of type Int:

let x = 1i32;
//             ↓ need to use the view operator to convert `i32` to `Int`
proof_assert!(x@ == 1);

You can use the usual operators on integers: +, -, *, / and %.

Note that those operators are not available in ghost code.

Implementations§

source§

impl Int

source

pub fn new(value: i128) -> GhostBox<Self>

Create a new Int value

The result is wrapped in a GhostBox, so that it can only be access inside a ghost! block.

You should not have to use this method directly: instead, use the int suffix inside of a ghost block:

let x: GhostBox<Int> = ghost!(1int);
ghost! {
    let y: Int = 2int;
};

pure

ensures

*result == value@

source

pub fn pow(self, p: Int) -> Int

Compute self^p.

§Example
proof_assert!(2.pow(3) == 8);

logic

source

pub fn max(self, x: Int) -> Int

Compute the maximum of self and x.

§Example
proof_assert!(10.max(2) == 10);

logic

source

pub fn min(self, x: Int) -> Int

Compute the minimum of self and x.

§Example
proof_assert!(10.max(2) == 2);

logic

source

pub fn div_euclid(self, d: Int) -> Int

Compute the euclidean division of self by d.

§Example
proof_assert!(10.div_euclid(3) == 3);

logic

source

pub fn rem_euclid(self, d: Int) -> Int

Compute the remainder of the euclidean division of self by d.

§Example
 proof_assert!(10.rem_euclid(3) == 1);

logic

source

pub fn abs_diff(self, other: Int) -> Int

Compute the absolute difference of self and x.

§Example
proof_assert!(10.abs_diff(3) == 7);
proof_assert!(3.abs_diff(10) == 7);
proof_assert!((-5).abs_diff(5) == 10);

logic

if self < other {
    other - self
} else {
    self - other
}

Trait Implementations§

source§

impl Add for Int

source§

fn add(self, other: Int) -> Self

pure

ensures

result == self + other

§

type Output = Int

The resulting type after applying the + operator.
source§

impl AddLogic for Int

source§

fn add(self, other: Self) -> Self

logic

§

type Output = Int

source§

impl Clone for Int

source§

fn clone(&self) -> Self

pure

ensures

result == *self

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl DeepModel for Int

source§

fn deep_model(self) -> Self::DeepModelTy

logic

self

§

type DeepModelTy = Int

source§

impl Div for Int

source§

fn div(self, other: Int) -> Self

pure

ensures

result == self / other

§

type Output = Int

The resulting type after applying the / operator.
source§

impl DivLogic for Int

source§

fn div(self, other: Self) -> Self

logic

§

type Output = Int

source§

impl<T> IndexLogic<Int> for [T]

source§

fn index_logic(self, ix: Int) -> Self::Item

logic

pearlite! { self@[ix] }

§

type Item = T

source§

impl<T, const N: usize> IndexLogic<Int> for [T; N]

source§

fn index_logic(self, ix: Int) -> Self::Item

logic

pearlite! { self@[ix] }

§

type Item = T

source§

impl<T> IndexLogic<Int> for Seq<T>

source§

fn index_logic(self, _: Int) -> Self::Item

logic

§

type Item = T

source§

impl<T> IndexLogic<Int> for Snapshot<Seq<T>>

source§

fn index_logic(self, ix: Int) -> Self::Item

logic

pearlite! { (*self)[ix] }

§

type Item = T

source§

impl<T, A: Allocator> IndexLogic<Int> for Vec<T, A>

source§

fn index_logic(self, ix: Int) -> Self::Item

logic

pearlite! { self@[ix] }

§

type Item = T

source§

impl<T, A: Allocator> IndexLogic<Int> for VecDeque<T, A>

source§

fn index_logic(self, ix: Int) -> Self::Item

logic

pearlite! { self@[ix] }

§

type Item = T

source§

impl Mul for Int

source§

fn mul(self, other: Int) -> Self

pure

ensures

result == self * other

§

type Output = Int

The resulting type after applying the * operator.
source§

impl MulLogic for Int

source§

fn mul(self, other: Self) -> Self

logic

§

type Output = Int

source§

impl Neg for Int

source§

fn neg(self) -> Self

pure

ensures

result == -self

§

type Output = Int

The resulting type after applying the - operator.
source§

impl NegLogic for Int

source§

fn neg(self) -> Self

logic

§

type Output = Int

source§

impl OrdLogic for Int

source§

fn cmp_log(self, o: Self) -> Ordering

logic

if self < o {
    Ordering::Less
} else if self == o {
    Ordering::Equal
} else {
    Ordering::Greater
}
source§

fn le_log(self, _: Self) -> bool

logic

source§

fn lt_log(self, _: Self) -> bool

logic

source§

fn ge_log(self, _: Self) -> bool

logic

source§

fn gt_log(self, _: Self) -> bool

logic

source§

fn cmp_le_log(x: Self, y: Self)

law

ensures

x.le_log(y) == (x.cmp_log(y) != Ordering::Greater)

source§

fn cmp_lt_log(x: Self, y: Self)

law

ensures

x.lt_log(y) == (x.cmp_log(y) == Ordering::Less)

source§

fn cmp_ge_log(x: Self, y: Self)

law

ensures

x.ge_log(y) == (x.cmp_log(y) != Ordering::Less)

source§

fn cmp_gt_log(x: Self, y: Self)

law

ensures

x.gt_log(y) == (x.cmp_log(y) == Ordering::Greater)

source§

fn refl(x: Self)

law

ensures

x.cmp_log(x) == Ordering::Equal

source§

fn trans(x: Self, y: Self, z: Self, o: Ordering)

law

requires

x.cmp_log(y) == o

requires

y.cmp_log(z) == o

ensures

x.cmp_log(z) == o

source§

fn antisym1(x: Self, y: Self)

law

requires

x.cmp_log(y) == Ordering::Less

ensures

y.cmp_log(x) == Ordering::Greater

source§

fn antisym2(x: Self, y: Self)

law

requires

x.cmp_log(y) == Ordering::Greater

ensures

y.cmp_log(x) == Ordering::Less

source§

fn eq_cmp(x: Self, y: Self)

law

ensures

(x == y) == (x.cmp_log(y) == Ordering::Equal)

source§

impl PartialEq for Int

source§

fn eq(&self, other: &Self) -> bool

pure

ensures

result == (*self == *other)

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rem for Int

source§

fn rem(self, other: Int) -> Self

pure

ensures

result == self % other

§

type Output = Int

The resulting type after applying the % operator.
source§

impl RemLogic for Int

source§

fn rem(self, other: Self) -> Self

logic

§

type Output = Int

source§

impl Sub for Int

source§

fn sub(self, other: Int) -> Self

pure

ensures

result == self - other

§

type Output = Int

The resulting type after applying the - operator.
source§

impl SubLogic for Int

source§

fn sub(self, other: Self) -> Self

logic

§

type Output = Int

source§

impl Copy for Int

source§

impl WellFounded for Int

Auto Trait Implementations§

§

impl Freeze for Int

§

impl RefUnwindSafe for Int

§

impl !Send for Int

§

impl !Sync for Int

§

impl Unpin for Int

§

impl UnwindSafe for Int

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> MakeSized for T
where T: ?Sized,

source§

fn make_sized(&self) -> Box<T>

logic

ensures

*result == *self

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,