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.
inferencesare in the session’s own order, the conclusion first. Each is{"sequent": [ids], "rule": name, "principal": position, "premises": [indices]}, with the rule’sname. An open goal is its sequent alone.historylists 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
impl Interactive
Sourcepub fn cut(
&mut self,
goal: GoalId,
formula: &CutFormula,
left: &[usize],
limits: &Limits,
) -> Result<[GoalId; 2], Error>
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::NoGoalfor a goal that is not open;StepError::Modein an ordered mode;StepError::Splitfor a position past the goal or named twice;StepError::Succedentsin intuitionistic mode where a premise would not have exactly one succedent (the formulas going left must all be hypotheses);StepError::CutSymbolfor 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::Eigenvariablefor 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
impl Interactive
Sourcepub fn rules(
&self,
goal: GoalId,
position: usize,
) -> Result<Vec<Applicable>, StepError>
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.
Sourcepub fn apply(
&mut self,
goal: GoalId,
step: &Step,
) -> Result<Vec<GoalId>, StepError>
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:
∀Rand∃L(∀one-sided) open the body with a fresh eigenvariable.∃Rand∀L(∃one-sided) open it with the step’s witness, or with a metavariable when the witness is open. A later axiom orclosebinds the metavariable, andundoof 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.
Sourcepub fn split_passes(&self, goal: GoalId, step: &Step) -> Result<bool, StepError>
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.
Sourcepub fn undo(&mut self) -> Option<GoalId>
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.
Sourcepub fn close(
&mut self,
goal: GoalId,
options: &Options,
view: &ViewOptions,
limits: &Limits,
stop: impl FnMut(Progress) -> bool,
) -> Result<Closed, Error>
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.
Sourcepub fn close_with(
&mut self,
goal: GoalId,
proof: &Proof,
view: &ViewOptions,
limits: &Limits,
stop: impl FnMut(Progress) -> bool,
) -> Result<(), Error>
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.
Sourcepub fn fill(
&mut self,
goal: GoalId,
proof: &Proof,
view: &ViewOptions,
limits: &Limits,
stop: impl FnMut(Progress) -> bool,
) -> Result<(), Error>
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.
Sourcepub fn close_all(
&mut self,
options: &Options,
view: &ViewOptions,
limits: &Limits,
stop: impl FnMut(Progress) -> bool,
) -> Vec<(GoalId, Result<Closed, Error>)>
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
impl Interactive
Sourcepub fn invert(
&mut self,
goal: GoalId,
limits: &Limits,
) -> Result<Inverted, StepError>
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.
Sourcepub fn invert_all(&mut self, limits: &Limits) -> Inverted
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.
Sourcepub fn is_invertible(&self, sequent: &[Member], step: &Step) -> bool
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 (!Rwhen every hypothesis is a!);1alone, 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
impl Interactive
Sourcepub fn proof(
&self,
limits: &Limits,
stop: impl FnMut(Progress) -> bool,
) -> Result<Proof, Error>
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
impl Interactive
Sourcepub fn witness(&self, text: &str) -> Result<Witness, StepError>
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.
Sourcepub fn opened_term(&self, goal: GoalId) -> Option<String>
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
impl Interactive
Sourcepub fn new(sequent: &Sequent, mode: Mode) -> Result<Self, Error>
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.
Sourcepub fn of_classical(
sequent: &ClassicalSequent,
mode: Mode,
limits: &Limits,
) -> Result<Self, Error>
pub fn of_classical( sequent: &ClassicalSequent, mode: Mode, limits: &Limits, ) -> Result<Self, Error>
Sourcepub fn writing(&self) -> Option<&[Written]>
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.
Sourcepub fn formula_as_written(&self, member: Member) -> Option<impl Display + '_>
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.
Sourcepub fn occurrence(&self, member: Member) -> OccId
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.
Sourcepub fn formula(&self, member: Member) -> impl Display + '_
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.
Sourcepub fn reading(&self) -> Option<Reading<'_>>
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.
Sourcepub fn goals(&self) -> impl Iterator<Item = GoalId> + '_
pub fn goals(&self) -> impl Iterator<Item = GoalId> + '_
Returns the open goals, in the order they were opened.
Sourcepub fn goal(&self, id: GoalId) -> Result<&[Member], StepError>
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.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns whether no goal is open.
Sourcepub fn steps(&self) -> usize
pub fn steps(&self) -> usize
Returns how many steps were taken (rules applied, cuts made and goals closed by the search), less those undone.
Sourcepub fn derivation(&self) -> Result<Derivation<'_>, Error>
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.
Sourcepub fn derivation_within(
&self,
view: &ViewOptions,
limits: &Limits,
stop: impl FnMut(Progress) -> bool,
) -> Result<Derivation<'_>, Error>
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.
Sourcepub fn derivation_ids(&self) -> Vec<GoalId>
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
impl Clone for Interactive
Source§impl Debug for Interactive
impl Debug for Interactive
Source§impl<'a> Deserialize<'a> for Interactive
impl<'a> Deserialize<'a> for Interactive
Source§fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
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.
impl Owner for Interactive
interactive only.Source§impl Readable for Interactive
impl Readable for Interactive
Auto Trait Implementations§
impl Forget for Interactive
impl Freeze for Interactive
impl Move for Interactive
impl RefUnwindSafe for Interactive
impl Send for Interactive
impl Sync for Interactive
impl Unpin for Interactive
impl UnsafeUnpin for Interactive
impl UnwindSafe for Interactive
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.