Skip to main content

Interactive

Struct Interactive 

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

A proof in progress: a derivation built step by step from its conclusion, with the goals still open as its leaves.

A session starts with the sequent as its one open goal. Each step applies a rule to a formula of a goal, named by its position (apply); rules lists the rules that act on a formula. The search can close a goal (close), and undo takes back the last step (or keep a clone). Once no goal is open, proof returns the proof, checked.

§Examples

use deduxit::linear::proofs::interactive::Needs;
use deduxit::{Limits, linear::{Interactive, Mode, Named, Rule, Sequent, Step}};

// ⊢ ~A, A ⊗ ~B, B: the goal's formulas are 0: ~A, 1: A ⊗ ~B, 2: B.
let sequent: Sequent = "A, A -o B |- B".parse()?;
let mut state = Interactive::new(&sequent, Mode::CLASSICAL)?;
let root = state.goals().next().unwrap();
let rules = state.rules(root, 1)?;
assert_eq!((rules[0].rule, rules[0].needs), (Named::from(Rule::Tensor), Needs::Split));
// ⊗ on formula 1, with formula 0 going to the left premise.
let goals = state.apply(root, &Step::new(1, Rule::Tensor).left(&[0]))?;
// Two goals are open: ⊢ ~A, A and ⊢ ~B, B.
assert_eq!(state.goals().collect::<Vec<_>>(), goals);
state.apply(goals[0], &Step::new(0, Rule::Ax))?;
state.apply(goals[1], &Step::new(0, Rule::Ax))?;
assert!(state.is_complete());
let proof = state.proof(&Limits::default(), |_| false)?;
assert_eq!(proof.nodes().len(), 3);

§JSON

With the feature serialize, a session is written as {"version": 1, "sequent": …, "mode": "intuitionistic", "inferences": […], "history": […]} (wire), the mode by its name.

  • inferences are in the session’s own order, the conclusion first. Each is {"sequent": [ids], "rule": name, "principal": position, "premises": [indices]}, with the rule’s name. An open goal is its sequent alone.
  • history lists the inferences the steps closed, in order.
  • A session that keeps how its sequent was written (writing) also has "written": {"inputs": [ids], "implications": [ids]}: the occurrences written on the input side and those written as an implication, ascending.

Reading a session back replays every inference, so a session read is as sound as one built through apply. A front end keeps this between requests, and the command’s session saves it.

Needs the cargo feature interactive (on by default).

Implementations§

Source§

impl Interactive

Source

pub fn cut( &mut self, goal: GoalId, formula: &CutFormula, left: &[usize], limits: &Limits, ) -> Result<[GoalId; 2], Error>

Cuts an open goal Γ, Δ on the formula A that formula names, and returns the two goals the cut opens.

The goals are the premises Γ, A and Δ, A⊥, in that order: the formulas at the positions left go to the first, the others to the second. Intuitionistically they are Γ ⊢ A and Δ, A ⊢ C, so the goal’s succedent C goes to the second premise.

A and its dual join the session’s sequent as a cut formula (Sequent::cuts). Their occurrences are recorded as formula was written, A right of ⊢ and A⊥ left of it, so that the two-sided views print them as written. undo takes the cut back, and its formula with it.

An ordered mode has no cut, since there the dual of a formula turns it round. In a session with quantifiers, A is a closed formula of the sequent’s symbols and the goal’s eigenvariables, and may have quantifiers of its own; the goals’ instances keep their terms. A cut formula with a quantifier makes a session without one a session with quantifiers.

§Errors

Nothing changes on an error. Error::Step with:

  • StepError::NoGoal for a goal that is not open;
  • StepError::Mode in an ordered mode;
  • StepError::Split for a position past the goal or named twice;
  • StepError::Succedents in intuitionistic mode where a premise would not have exactly one succedent (the formulas going left must all be hypotheses);
  • StepError::CutSymbol for a cut formula naming a symbol the sequent has with another arity or role, or, in a session with quantifiers, one the sequent does not have and that is not an eigenvariable’s letter used as a constant;
  • StepError::Eigenvariable for an eigenvariable outside the goal’s scope.

Also Error::CutFormula for a cut formula with no formula or more than one, Error::NotIntuitionistic in intuitionistic mode for a one-sided formula that cannot be a goal, and Error::Refused when the sequent with the cut formula has more occurrences than limits.occurrences.

Source§

impl Interactive

Source

pub fn rules( &self, goal: GoalId, position: usize, ) -> Result<Vec<Applicable>, StepError>

Returns the rules that can act on the formula at position of the open goal, judged by the formula’s connective and the mode alone.

They are the axiom on a literal, ⊗ ⅋ 1 ⊥ & ⊕₁ ⊕₂ ⊤ ! ∀ ∃ on their connectives, ?d ?c ?w on a ? formula, wk on any other formula in affine mode, and Mix on any formula when the mode has it. In intuitionistic mode they carry their two-sided names. Nothing acts on 0. Whether the rest of the goal lets a rule apply (the axiom’s dual, the context of 1 and !, a valid split, one succedent) is for apply to decide.

§Errors

StepError::NoGoal for a goal that is not open, and StepError::NoFormula for a position outside its sequent.

Source

pub fn apply( &mut self, goal: GoalId, step: &Step, ) -> Result<Vec<GoalId>, StepError>

Applies a step to the open goal and returns the goals it opens, in the order of the rule’s premises. A rule that closes the goal (the axiom, 1, ⊤) opens none.

Only ⊗ and Mix take a split (Step::left). In intuitionistic mode the rule may be given by its classical or its two-sided name, and the session records the two-sided one. A step that fails changes nothing.

With quantifiers:

  • ∀R and ∃L (∀ one-sided) open the body with a fresh eigenvariable.
  • ∃R and ∀L (∃ one-sided) open it with the step’s witness, or with a metavariable when the witness is open. A later axiom or close binds the metavariable, and undo of that step unbinds it.
  • The axiom unifies its two literals’ terms, binding open witnesses, with the occurs check and the eigenvariable condition: an open witness never takes an eigenvariable made after it.
§Errors

A StepError that names what the step needed: an open goal, a formula at the position, a rule that acts on it in the mode, a split that fits, the dual of an axiom, a context of ? formulas for ! and none for 1, a witness only where the rule takes one, a term of the sequent’s symbols and the eigenvariables in scope.

Source

pub fn split_passes(&self, goal: GoalId, step: &Step) -> Result<bool, StepError>

Returns whether the split of a ⊗ step passes the focused engine’s count prunes: false means that this split cannot be closed.

It is a cheap test to run before trying a split; a split that passes may still fail. The step’s rule is not read: the step is a ⊗ on a ⊗ formula, and a Mix on any other.

§Errors

As rules does for the goal and the position.

Source

pub fn undo(&mut self) -> Option<GoalId>

Takes back the last step (a rule applied, a cut, or a goal closed by the search) and returns the goal it reopened, or None when there is no step to take back. The open witnesses the step bound are open again.

Source

pub fn close( &mut self, goal: GoalId, options: &Options, view: &ViewOptions, limits: &Limits, stop: impl FnMut(Progress) -> bool, ) -> Result<Closed, Error>

Runs the search on an open goal, as prove_goal does, and returns what it did.

When the search proves the goal, the derivation of its proof is grafted onto the goal as one step, which undo takes back whole. Otherwise nothing changes. The outcome’s proof, if any, proves the goal alone.

The search runs within limits, and the grafted derivation must fit them too. When it does not, or stop ends its unfolding, the goal stays open and Closed::grafted says why; the proof stays in the outcome, so a proved goal is never lost.

§Errors

Error::Step for a goal that is not open, and the errors of the search (prove_goal). A graft that the limits or stop refuse is no error: Closed::grafted holds it.

Source

pub fn close_with( &mut self, goal: GoalId, proof: &Proof, view: &ViewOptions, limits: &Limits, stop: impl FnMut(Progress) -> bool, ) -> Result<(), Error>

Closes an open goal with a proof of it that the caller’s own search found, as close does with the proof its search finds. A caller that runs several searches side by side uses this.

The proof must be over the session’s sequent, and its root must conclude the goal, as a proof from prove_goal on the goal’s members (goal) does. It must pass the checker in the session’s mode. Its derivation is grafted within limits as one step.

§Errors

Error::Step for a goal that is not open, Error::ForeignProof for a proof of another sequent, Error::GoalMismatch for one of another goal, Error::Check with CheckError::Invalid for one the checker rejects in the session’s mode; and, leaving the goal open, Error::Check with CheckError::Refused when a bound or stop ends the check, and Error::Refused when they refuse the graft. Error::is_refusal tells the refusals from the rejection.

Source

pub fn fill( &mut self, goal: GoalId, proof: &Proof, view: &ViewOptions, limits: &Limits, stop: impl FnMut(Progress) -> bool, ) -> Result<(), Error>

Closes an open goal with a proof of an equal sequent made elsewhere, such as another session’s.

The proof is carried over to the goal (Proof::onto), its conclusions matched to the goal’s formulas in any order. It then closes the goal as close_with does: checked in the session’s mode, as one step.

§Errors

Error::Step for a goal that is not open, Error::SequentMismatch for a proof whose conclusions are not the goal’s formulas, and the errors of close_with. Among them is Error::Check with CheckError::Invalid for a proof the checker rejects in the session’s mode, such as one that uses another mode’s rules.

Source

pub fn close_all( &mut self, options: &Options, view: &ViewOptions, limits: &Limits, stop: impl FnMut(Progress) -> bool, ) -> Vec<(GoalId, Result<Closed, Error>)>

Runs the search on every open goal in turn, as close does, and returns each goal with what closing it did.

A goal the search does not prove, or whose closing fails, stays open, and the run goes on with the next. The limits bound each goal’s search on its own.

Source§

impl Interactive

Source

pub fn invert( &mut self, goal: GoalId, limits: &Limits, ) -> Result<Inverted, StepError>

Applies the rules invertible in the session’s mode (is_invertible) to an open goal, and then to every goal those steps open, until none applies.

On each goal it takes a rule that closes the goal (⊤, the axiom, 1) first, and otherwise the rule on the first formula that has one. Each application is an ordinary step. It always ends, since every premise of these rules has fewer connectives, units and literals than its conclusion. The bytes of the inferences it adds are bounded by limits.memory_bytes: at the bound it stops, and the steps it took stand (Inverted::finished).

§Errors

StepError::NoGoal for a goal that is not open.

Source

pub fn invert_all(&mut self, limits: &Limits) -> Inverted

Applies the invertible rules to every open goal in turn, as invert does to one, all within one memory bound.

Source

pub fn is_invertible(&self, sequent: &[Member], step: &Step) -> bool

Returns whether a step on a sequent of this session’s forest (an open goal, or an inference’s conclusion) applies a rule invertible in the session’s mode, and is a valid step there.

The invertible rules are:

  • in every mode ⅋, ⊥, & and ⊤, under any name the intuitionistic or the ordered reading gives them (⊸R, ⊗L, &R, ⊕L, 1L, ⊤R, 0L, \R, /R), and ∀ (∀R, ∃L);
  • ! when every other formula is a ? formula (!R when every hypothesis is a !);
  • 1 alone, the axiom on a literal and its dual alone, and ⊗ alone, with no context to split.

No ? rule is among them: dereliction and weakening are not invertible, and contraction is, but applying it never ends.

Source§

impl Interactive

Source

pub fn proof( &self, limits: &Limits, stop: impl FnMut(Progress) -> bool, ) -> Result<Proof, Error>

Returns the proof of the finished derivation: its proof term, which the checker has accepted in the session’s mode.

A witness still open becomes a fresh constant: an eigenvariable that no ∀ step introduces. The checker always runs. It never rejects a derivation built through this interface, but the session is not trusted more than a search engine.

§Errors

Error::OpenGoals while goals are open. Error::Check when the checker rejects the term, or gives the check up within limits or when stop fires (with CheckError::Refused).

Source§

impl Interactive

Source

pub fn witness(&self, text: &str) -> Result<Witness, StepError>

Reads a witness from text, such as f(a, g(b)), for a Step’s with_witness.

The text is a closed term of the sequent’s function symbols and constants, and of the session’s eigenvariables by the letters the session writes them with. Whether its eigenvariables are in the goal’s scope is for apply to decide.

§Errors

StepError::Witness for text that is not such a term: an unknown name, a predicate, a symbol given the wrong number of arguments, or a stray bracket or comma.

Source

pub fn opened_term(&self, goal: GoalId) -> Option<String>

Returns the term a closed ∀ or ∃ step on goal opened its formula with, as text, or None for a goal no quantifier step closed.

The term is written as the step took it: a ∀ step’s eigenvariable by its letter, an ∃ step’s given witness, or $1, $2, … for a witness left open, whatever an axiom or the search filled it with later. witness reads a given witness back, to take the step again.

Source§

impl Interactive

Source

pub fn new(sequent: &Sequent, mode: Mode) -> Result<Self, Error>

Starts a proof of the sequent in the mode, with the whole sequent as the one open goal.

The sequent’s cut formulas are left out: a session’s cut formulas are those of its own cuts (cut), added as they are made.

§Errors

Error::NotIntuitionistic in intuitionistic mode for a sequent without an intuitionistic reading, Error::IntuitionisticMix for intuitionistic mode with Mix, Error::OrderedMode for a mode Mode::check refuses otherwise, Error::OrderedFragment in an ordered mode for a sequent beyond unit-free MLL, and Refusal::Occurrences past the default bound.

Source

pub fn within( sequent: &Sequent, mode: Mode, limits: &Limits, ) -> Result<Self, Error>

Starts a proof as new does, within the caller’s limits: the sequent may unfold to at most limits.occurrences occurrences, and the terms of a session with quantifiers are bounded by limits.terms.

§Errors

As new does, the bound being limits.occurrences.

Source

pub fn of_classical( sequent: &ClassicalSequent, mode: Mode, limits: &Limits, ) -> Result<Self, Error>

Starts a proof as within does, of a classical sequent as it was written. The session keeps how it was written (writing), so that its derivation can be drawn two-sided (TwoSided) at any point.

§Errors

As within does.

Source

pub fn writing(&self) -> Option<&[Written]>

Returns how the sequent was written, by occurrence, for a session started from a classical sequent as written, and None otherwise.

Source

pub fn formula_as_written(&self, member: Member) -> Option<impl Display + '_>

Returns the formula a member stands for as the session’s sequent was written, its negation included (A ⊸ B, ~(A ⊗ B)), and a cut formula as it was typed.

Returns None for a session that does not keep how its sequent was written (writing), and for an instance of a formula under a binder.

Source

pub fn forest(&self) -> &Forest

Returns the forest of the sequent being proved.

Source

pub fn occurrence(&self, member: Member) -> OccId

Returns the occurrence a member of the session stands for: the member itself below the forest’s length, and the instance’s occurrence past it.

Source

pub fn formula(&self, member: Member) -> impl Display + '_

Returns the formula a member of the session stands for, as text.

In an intuitionistic mode the formula is written two-sided, as the session’s reading has it (A ⊸ B for a hypothesis the one-sided sequent holds as A ⊗ ~B); otherwise one-sided. An instance has its terms in place of its bound variables, an eigenvariable is written by its letter, and an open witness as $1, $2, ….

§Panics

For a member past the forest that the session does not number. No goal of the session holds one.

Source

pub fn sequent(&self) -> &Sequent

Returns the sequent being proved.

Source

pub fn mode(&self) -> Mode

Returns the mode.

Source

pub fn reading(&self) -> Option<Reading<'_>>

Returns the intuitionistic reading of the sequent in intuitionistic mode, and None in classical mode. The reading says on which side of ⊢ to show each formula.

Source

pub fn goals(&self) -> impl Iterator<Item = GoalId> + '_

Returns the open goals, in the order they were opened.

Source

pub fn goal(&self, id: GoalId) -> Result<&[Member], StepError>

Returns the sequent of an open goal: its members, in ascending order. A step names a formula by its position here.

§Errors

StepError::NoGoal if the id is not an open goal.

Source

pub fn is_complete(&self) -> bool

Returns whether no goal is open.

Source

pub fn steps(&self) -> usize

Returns how many steps were taken (rules applied, cuts made and goals closed by the search), less those undone.

Source

pub fn derivation(&self) -> Result<Derivation<'_>, Error>

Returns the derivation so far, two-sided in intuitionistic mode, with the open goals as leaves of Rule::Open.

The derivation numbers its inferences premises before conclusions, so its ids are not the session’s; derivation_ids maps them.

§Errors

Refusal::Output for a derivation past the default Limits::derivation_bytes.

Source

pub fn derivation_within( &self, view: &ViewOptions, limits: &Limits, stop: impl FnMut(Progress) -> bool, ) -> Result<Derivation<'_>, Error>

Returns the derivation so far as derivation does, within the caller’s limits and until stop fires.

The size estimate decides, as for a proof’s derivation, whether it fits limits.derivation_bytes. Its inferences are the session’s own, never compacted, whatever view says.

§Errors

Refusal::Output past limits.derivation_bytes, and Refusal::Stopped when stop fired.

Source

pub fn derivation_ids(&self) -> Vec<GoalId>

Returns, for every inference of derivation by its id, the id of the same inference in this session.

It turns the inference n of a drawing (the SVG’s i<n>) into the goal that apply and close take.

Trait Implementations§

Source§

impl Clone for Interactive

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Interactive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Deserialize<'a> for Interactive

Source§

fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>

Deserializes a session within the default limits, as wire::upgrade does.

Source§

impl Owner for Interactive

Available on crate feature interactive only.
Source§

fn forest(&self) -> &Forest

The session’s forest.

Source§

impl Readable for Interactive

Source§

fn read<'de, D: Deserializer<'de>>( deserializer: D, limits: &Limits, ) -> Result<Self, D::Error>

Reads a session and checks that it is consistent, as Interactive describes.

Source§

const FORM: &'static str = "session"

The form’s name, as an error names it: sequent, proof, …
Source§

impl Serialize for Interactive

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serializes the session as a document: its sequent, mode, inferences and steps, and where it has them, how the sequent was written and the first-order table.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.