Skip to main content

VerificationSession

Struct VerificationSession 

Source
pub struct VerificationSession { /* private fields */ }
Expand description

A verification session for working with the Verification IR.

A session accumulates variable declarations and assumptions, then verifies assertions against that context. This is the recommended API for most verification tasks.

Each verification call creates a fresh Z3 context to avoid lifetime issues.

§Examples

use logicaffeine_verify::{VerificationSession, VerifyExpr, VerifyType};

let mut session = VerificationSession::new();

// Declare variables
session.declare("x", VerifyType::Int);

// Add assumptions
session.assume(&VerifyExpr::gt(VerifyExpr::var("x"), VerifyExpr::int(0)));

// Verify assertions
let result = session.verify(&VerifyExpr::gte(VerifyExpr::var("x"), VerifyExpr::int(0)));
assert!(result.is_ok());

§Modus Ponens Example

use logicaffeine_verify::{VerificationSession, VerifyExpr, VerifyType};

let mut session = VerificationSession::new();
session.declare("x", VerifyType::Object);

// All mortals are human
session.assume(&VerifyExpr::implies(
    VerifyExpr::apply("Mortal", vec![VerifyExpr::var("x")]),
    VerifyExpr::apply("Human", vec![VerifyExpr::var("x")]),
));

// x is mortal
session.assume(&VerifyExpr::apply("Mortal", vec![VerifyExpr::var("x")]));

// Therefore x is human
assert!(session.verify(&VerifyExpr::apply("Human", vec![VerifyExpr::var("x")])).is_ok());

Implementations§

Source§

impl VerificationSession

Source

pub fn new() -> Self

Create a new verification session.

§Examples
use logicaffeine_verify::VerificationSession;

let session = VerificationSession::new();
Source

pub fn declare(&mut self, name: &str, ty: VerifyType)

Declare a variable with a type.

Variables must be declared before they can be used in assumptions or verifications.

§Examples
use logicaffeine_verify::{VerificationSession, VerifyType};

let mut session = VerificationSession::new();
session.declare("x", VerifyType::Int);
session.declare("p", VerifyType::Bool);
session.declare("socrates", VerifyType::Object);
Source

pub fn assume(&mut self, expr: &VerifyExpr)

Add an assumption (constraint) to the session.

Assumptions constrain the verification context. Subsequent calls to verify will check validity under all assumptions.

§Examples
use logicaffeine_verify::{VerificationSession, VerifyExpr, VerifyType};

let mut session = VerificationSession::new();
session.declare("x", VerifyType::Int);

// Assume x = 10
session.assume(&VerifyExpr::eq(VerifyExpr::var("x"), VerifyExpr::int(10)));

// Assume x > 0
session.assume(&VerifyExpr::gt(VerifyExpr::var("x"), VerifyExpr::int(0)));
Source

pub fn verify_with_binding( &self, var_name: &str, var_type: VerifyType, value: &VerifyExpr, predicate: &VerifyExpr, ) -> VerificationResult

Verify a predicate with a temporary variable binding.

Used for refinement type checking. Creates a scoped context where var_name = value is assumed, then verifies that predicate holds.

§Examples
use logicaffeine_verify::{VerificationSession, VerifyExpr, VerifyType};

let session = VerificationSession::new();

// Check that 10 satisfies the predicate x > 5
let result = session.verify_with_binding(
    "x",
    VerifyType::Int,
    &VerifyExpr::int(10),
    &VerifyExpr::gt(VerifyExpr::var("x"), VerifyExpr::int(5)),
);
assert!(result.is_ok());
Source

pub fn verify(&self, expr: &VerifyExpr) -> VerificationResult

Verify that an assertion is valid given current assumptions.

Uses the standard validity check: P is valid iff ¬P is unsatisfiable. Returns Ok(()) if the assertion can be proven, an error otherwise.

§Examples
use logicaffeine_verify::{VerificationSession, VerifyExpr, VerifyType};

let mut session = VerificationSession::new();
session.declare("x", VerifyType::Int);
session.assume(&VerifyExpr::eq(VerifyExpr::var("x"), VerifyExpr::int(10)));

// This should pass: 10 > 5
assert!(session.verify(&VerifyExpr::gt(VerifyExpr::var("x"), VerifyExpr::int(5))).is_ok());

// This should fail: 10 < 5
assert!(session.verify(&VerifyExpr::lt(VerifyExpr::var("x"), VerifyExpr::int(5))).is_err());
Source

pub fn check_sat(&self) -> Result<bool, VerificationError>

Check the joint satisfiability of all assumptions (no goal).

Returns Ok(true) when Z3 finds a model, Ok(false) when the assumptions are jointly unsatisfiable, and Err on solver-unknown — three-valued, so an unknown never reads as either verdict.

Source

pub fn verify_temporal( &self, initial: &VerifyExpr, transition: &VerifyExpr, property: &VerifyExpr, bound: u32, ) -> VerificationResult

Verify a temporal property via bounded model checking.

Unrolls the transition relation bound steps and checks if the property holds at every unrolled state.

  • initial: constraint on the initial state (e.g., s == 0)
  • transition: constraint relating current state to next state
  • property: the property to verify at each state
  • bound: number of unrolling steps

Returns Ok(()) if the property holds at all unrolled states, or an error with counterexample if a violation is found.

Trait Implementations§

Source§

impl Default for VerificationSession

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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.

§

impl<T, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

§

fn into_ast(self, _a: &A) -> A

Source§

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

Source§

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>,

Source§

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.