use super::{Derivation, Logic, Options, Sequent, Translation, translate};
use crate::Error;
use crate::limits::{Limits, Progress};
use crate::linear::search::{self, Reason};
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct Outcome {
pub verdict: Verdict,
pub logic: Logic,
pub translation: Translation,
pub linear: search::Outcome,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub enum Verdict {
Valid(Box<Derivation>),
NotValid,
Unknown(Reason),
}
#[cfg_attr(feature = "parse", doc = "```")]
#[cfg_attr(not(feature = "parse"), doc = "```ignore")]
pub fn decide(
sequent: &Sequent,
options: &Options,
search: &search::Options,
limits: &Limits,
mut stop: impl FnMut(Progress) -> bool,
) -> Result<Outcome, Error> {
let (logic, translation) = (options.logic, options.translation());
let image = translate(sequent, logic, translation, limits)?;
let linear = search::prove_within(image.sequent(), image.mode(), search, limits, &mut stop)?;
let verdict = match &linear.verdict {
search::Verdict::Proved(proof) => {
let derivation = image.read_back(proof, limits, &mut stop)?;
derivation.check(limits, &mut stop)?;
Verdict::Valid(Box::new(derivation))
}
search::Verdict::Unprovable(_) => Verdict::NotValid,
search::Verdict::Unknown(reason) => Verdict::Unknown(*reason),
};
Ok(Outcome {
verdict,
logic,
translation,
linear,
})
}