use super::proofs::{Instances, Proof, Step};
use super::sequents::Sequent as SequentForm;
use crate::limits::{Limits, Space};
use crate::linear::fragment::{Fragment, Mode};
use crate::linear::occurrences::{Member, OccId, Sign};
use crate::linear::search::{
Basis, Bias, Cadence, Classical, Disproof, Engine, Equation, Jobs, Marking, OneSided,
OneSidedSymbol, Outcome as Out, Reason, Refutation, Saturated, Stable, StateEquation,
Statistics, Unbalanced, UnbalancedSymbol, Verdict,
};
use crate::linear::sequents::{Atom, Symbol};
use crate::wire::{self, Readable};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
impl Serialize for Fragment {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(self.name())
}
}
impl<'a> Deserialize<'a> for Fragment {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
let name = String::deserialize(deserializer)?;
name.parse().map_err(serde::de::Error::custom)
}
}
impl Serialize for Mode {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(self.name())
}
}
impl<'a> Deserialize<'a> for Mode {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
let name = <std::borrow::Cow<'a, str>>::deserialize(deserializer)?;
name.parse().map_err(serde::de::Error::custom)
}
}
#[derive(Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub(super) enum Why {
Stopped,
RecursionLimit {
depth: u32,
},
CopyBound {
copies: u32,
},
MemoryLimit {
limit_bytes: u64,
},
IndexLimit,
WorkLimit {
limit: u64,
},
Unchecked {
limit_bytes: u64,
},
WitnessDepth {
depth: u32,
},
Instances {
instances: u32,
},
}
impl From<Reason> for Why {
fn from(r: Reason) -> Self {
match r {
Reason::Stopped => Why::Stopped,
Reason::RecursionLimit { depth } => Why::RecursionLimit { depth },
Reason::CopyBound { copies } => Why::CopyBound { copies },
Reason::MemoryLimit { limit_bytes } => Why::MemoryLimit { limit_bytes },
Reason::IndexLimit => Why::IndexLimit,
Reason::WorkLimit { limit } => Why::WorkLimit { limit },
Reason::Unchecked { limit_bytes } => Why::Unchecked { limit_bytes },
Reason::WitnessDepth { depth } => Why::WitnessDepth { depth },
Reason::Instances { instances } => Why::Instances { instances },
}
}
}
impl From<Why> for Reason {
fn from(w: Why) -> Self {
match w {
Why::Stopped => Reason::Stopped,
Why::RecursionLimit { depth } => Reason::RecursionLimit { depth },
Why::CopyBound { copies } => Reason::CopyBound { copies },
Why::MemoryLimit { limit_bytes } => Reason::MemoryLimit { limit_bytes },
Why::IndexLimit => Reason::IndexLimit,
Why::WorkLimit { limit } => Reason::WorkLimit { limit },
Why::Unchecked { limit_bytes } => Reason::Unchecked { limit_bytes },
Why::WitnessDepth { depth } => Reason::WitnessDepth { depth },
Why::Instances { instances } => Reason::Instances { instances },
}
}
}
impl Serialize for Reason {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
Why::from(*self).serialize(serializer)
}
}
impl<'a> Deserialize<'a> for Reason {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
Why::deserialize(deserializer).map(Reason::from)
}
}
#[derive(Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
enum Literal {
Atom,
Dual,
}
impl From<Sign> for Literal {
fn from(sign: Sign) -> Self {
match sign {
Sign::Atom => Literal::Atom,
Sign::Dual => Literal::Dual,
}
}
}
impl From<Literal> for Sign {
fn from(literal: Literal) -> Self {
match literal {
Literal::Atom => Sign::Atom,
Literal::Dual => Sign::Dual,
}
}
}
#[derive(Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
enum WhyNot {
Exhausted,
Unbalanced {
atom: u32,
least: i32,
most: i32,
},
OneSided {
atom: u32,
least: i32,
most: i32,
copied: Literal,
},
Equation {
formulas: u64,
needed: i64,
tensors: u64,
pars: u64,
ones: u64,
bottoms: u64,
mix: bool,
},
StateEquation {
atoms: Vec<(u32, i64)>,
clauses: Vec<(u32, i64)>,
dropped: Vec<u32>,
},
Classical {
assignment: Vec<bool>,
},
Saturated {
positive: Vec<Literal>,
sequents: Vec<StableForm>,
},
UnbalancedSymbol {
symbol: u32,
least: i32,
most: i32,
},
OneSidedSymbol {
symbol: u32,
least: i32,
most: i32,
copied: Literal,
},
Basis {
body: Literal,
classes: Vec<Vec<u32>>,
markings: Vec<MarkingForm>,
},
}
#[derive(Serialize, Deserialize)]
struct MarkingForm {
atoms: Vec<(u32, u32)>,
tickets: Vec<(u32, u32)>,
}
#[derive(Serialize, Deserialize)]
struct StableForm {
linear: Vec<u32>,
unrestricted: Vec<u32>,
absorbs: bool,
}
impl From<&Refutation> for WhyNot {
fn from(r: &Refutation) -> Self {
match r {
&Refutation::Unbalanced(Unbalanced { atom, least, most }) => WhyNot::Unbalanced {
atom: atom.get(),
least,
most,
},
&Refutation::OneSided(OneSided {
atom,
least,
most,
copied,
}) => WhyNot::OneSided {
atom: atom.get(),
least,
most,
copied: copied.into(),
},
&Refutation::Equation(Equation {
formulas,
needed,
tensors,
pars,
ones,
bottoms,
mix,
}) => WhyNot::Equation {
formulas,
needed,
tensors,
pars,
ones,
bottoms,
mix,
},
Refutation::StateEquation(StateEquation {
atoms,
clauses,
dropped,
}) => WhyNot::StateEquation {
atoms: atoms.iter().map(|&(a, w)| (a.get(), w)).collect(),
clauses: clauses.iter().map(|&(o, w)| (o.get(), w)).collect(),
dropped: dropped.iter().map(|o| o.get()).collect(),
},
Refutation::Classical(Classical { assignment }) => WhyNot::Classical {
assignment: assignment.clone(),
},
Refutation::Saturated(Saturated { positive, sequents }) => WhyNot::Saturated {
positive: positive.iter().map(|&sign| sign.into()).collect(),
sequents: sequents
.iter()
.map(|s| StableForm {
linear: s.linear.iter().map(|o| o.get()).collect(),
unrestricted: s.unrestricted.iter().map(|o| o.get()).collect(),
absorbs: s.absorbs,
})
.collect(),
},
Refutation::Basis(Basis {
body,
classes,
markings,
}) => WhyNot::Basis {
body: (*body).into(),
classes: classes
.iter()
.map(|class| class.iter().map(|o| o.get()).collect())
.collect(),
markings: markings
.iter()
.map(|m| MarkingForm {
atoms: m.atoms.iter().map(|&(a, n)| (a.get(), n)).collect(),
tickets: m.tickets.clone(),
})
.collect(),
},
&Refutation::UnbalancedSymbol(UnbalancedSymbol {
symbol,
least,
most,
}) => WhyNot::UnbalancedSymbol {
symbol: symbol.get(),
least,
most,
},
&Refutation::OneSidedSymbol(OneSidedSymbol {
symbol,
least,
most,
copied,
}) => WhyNot::OneSidedSymbol {
symbol: symbol.get(),
least,
most,
copied: copied.into(),
},
Refutation::Exhausted => WhyNot::Exhausted,
}
}
}
impl From<WhyNot> for Refutation {
fn from(w: WhyNot) -> Self {
match w {
WhyNot::Exhausted => Refutation::Exhausted,
WhyNot::Unbalanced { atom, least, most } => Refutation::Unbalanced(Unbalanced {
atom: Atom::new(atom),
least,
most,
}),
WhyNot::OneSided {
atom,
least,
most,
copied,
} => Refutation::OneSided(OneSided {
atom: Atom::new(atom),
least,
most,
copied: copied.into(),
}),
WhyNot::Equation {
formulas,
needed,
tensors,
pars,
ones,
bottoms,
mix,
} => Refutation::Equation(Equation {
formulas,
needed,
tensors,
pars,
ones,
bottoms,
mix,
}),
WhyNot::StateEquation {
atoms,
clauses,
dropped,
} => Refutation::StateEquation(StateEquation {
atoms: atoms.into_iter().map(|(a, w)| (Atom::new(a), w)).collect(),
clauses: clauses
.into_iter()
.map(|(o, w)| (OccId::new(o), w))
.collect(),
dropped: dropped.into_iter().map(OccId::new).collect(),
}),
WhyNot::Classical { assignment } => Refutation::Classical(Classical { assignment }),
WhyNot::UnbalancedSymbol {
symbol,
least,
most,
} => Refutation::UnbalancedSymbol(UnbalancedSymbol {
symbol: Symbol::new(symbol),
least,
most,
}),
WhyNot::OneSidedSymbol {
symbol,
least,
most,
copied,
} => Refutation::OneSidedSymbol(OneSidedSymbol {
symbol: Symbol::new(symbol),
least,
most,
copied: copied.into(),
}),
WhyNot::Basis {
body,
classes,
markings,
} => Refutation::Basis(Basis::new(
body.into(),
classes
.into_iter()
.map(|class| class.into_iter().map(OccId::new).collect())
.collect(),
markings
.into_iter()
.map(|m| {
Marking::new(
m.atoms
.into_iter()
.map(|(a, n)| (Atom::new(a), n))
.collect(),
m.tickets,
)
})
.collect(),
)),
WhyNot::Saturated { positive, sequents } => Refutation::Saturated(Saturated::new(
positive.into_iter().map(Sign::from).collect(),
sequents
.into_iter()
.map(|s| {
Stable::new(
s.linear.into_iter().map(OccId::new).collect(),
s.unrestricted.into_iter().map(OccId::new).collect(),
s.absorbs,
)
})
.collect(),
)),
}
}
}
impl Serialize for Refutation {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
WhyNot::from(self).serialize(serializer)
}
}
impl<'a> Deserialize<'a> for Refutation {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
WhyNot::deserialize(deserializer).map(Refutation::from)
}
}
#[derive(Serialize, Deserialize)]
struct DisproofForm {
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "wire::version"
)]
version: Option<u32>,
sequent: SequentForm,
mode: Mode,
refutation: WhyNot,
#[serde(default, skip_serializing_if = "Option::is_none")]
goal: Option<Vec<u32>>,
}
impl DisproofForm {
fn within(self, limits: &Limits) -> Result<Disproof, crate::Error> {
let sequent = self.sequent.within(limits)?;
let atoms = sequent.atom_names().len();
let occurrences = usize::try_from(sequent.occurrences()).unwrap_or(usize::MAX);
let atom = |atom: Atom| match atom.index() {
index if index < atoms => Ok(()),
index => Err(crate::Error::IndexOutOfBounds {
space: Space::Atom,
index,
len: atoms,
}),
};
let symbols = sequent.symbols().len();
let symbol = |symbol: Symbol| match symbol.index() {
index if index < symbols => Ok(()),
index => Err(crate::Error::IndexOutOfBounds {
space: Space::Symbol,
index,
len: symbols,
}),
};
let occurrence = |index: usize| match index {
index if index < occurrences => Ok(()),
index => Err(crate::Error::IndexOutOfBounds {
space: Space::Occurrence,
index,
len: occurrences,
}),
};
let refutation = Refutation::from(self.refutation);
match &refutation {
Refutation::Unbalanced(unbalanced) => atom(unbalanced.atom)?,
Refutation::OneSided(one_sided) => atom(one_sided.atom)?,
Refutation::UnbalancedSymbol(unbalanced) => symbol(unbalanced.symbol)?,
Refutation::OneSidedSymbol(one_sided) => symbol(one_sided.symbol)?,
Refutation::StateEquation(equation) => {
for &(a, _) in &equation.atoms {
atom(a)?;
}
for &(o, _) in &equation.clauses {
occurrence(o.index())?;
}
for o in &equation.dropped {
occurrence(o.index())?;
}
}
Refutation::Saturated(saturated) => {
for s in &saturated.sequents {
for o in s.linear.iter().chain(&s.unrestricted) {
occurrence(o.index())?;
}
}
}
Refutation::Basis(basis) => {
for o in basis.classes.iter().flatten() {
occurrence(o.index())?;
}
for m in &basis.markings {
for &(a, _) in &m.atoms {
atom(a)?;
}
}
}
Refutation::Exhausted | Refutation::Equation(_) | Refutation::Classical(_) => {}
}
let disproof = Disproof::new(sequent, self.mode, refutation);
Ok(match self.goal {
None => disproof,
Some(goal) => {
for &m in &goal {
occurrence(m as usize)?;
}
disproof.of_goal(goal.into_iter().map(Member::new).collect())
}
})
}
}
impl Serialize for Disproof {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
DisproofForm {
version: Some(
wire::level_of(self.refutation(), self.mode())
.max(wire::level_of_sequent(self.sequent())),
),
sequent: SequentForm::from(self.sequent()),
mode: self.mode(),
refutation: WhyNot::from(self.refutation()),
goal: self
.goal()
.map(|goal| goal.iter().map(|m| m.get()).collect()),
}
.serialize(serializer)
}
}
impl<'a> Deserialize<'a> for Disproof {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
Self::read(deserializer, &Limits::default())
}
}
impl crate::sealed::Readable for Disproof {}
impl Readable for Disproof {
const FORM: &'static str = "disproof";
fn read<'de, D: Deserializer<'de>>(deserializer: D, limits: &Limits) -> Result<Self, D::Error> {
DisproofForm::deserialize(deserializer)?
.within(limits)
.map_err(wire::fail)
}
}
#[derive(Serialize)]
struct DisproofKeys<'a> {
sequent: SequentForm,
#[serde(skip_serializing_if = "Option::is_none")]
goal: Option<&'a [Member]>,
}
#[derive(Serialize)]
struct Outcome<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
version: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
deduxit: Option<&'static str>,
verdict: &'static str,
#[serde(skip_serializing_if = "Option::is_none")]
checked: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
reason: Option<Why>,
#[serde(skip_serializing_if = "Option::is_none")]
refutation: Option<WhyNot>,
fragment: &'static str,
mode: Mode,
engine: Engine,
statistics: Statistics,
#[serde(flatten)]
proof: Option<Proof>,
#[serde(flatten)]
disproof: Option<DisproofKeys<'a>>,
}
impl Serialize for Out {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
form(self, true).serialize(serializer)
}
}
pub(super) struct Nested<'a>(pub(super) &'a Out);
impl Serialize for Nested<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
form(self.0, false).serialize(serializer)
}
}
pub(super) fn level(outcome: &Out) -> u32 {
match &outcome.verdict {
Verdict::Unprovable(d) => {
wire::level_of(d.refutation(), outcome.mode).max(wire::level_of_sequent(d.sequent()))
}
Verdict::Proved(p) => {
wire::level_in(Some(outcome.mode)).max(wire::level_of_sequent(p.sequent()))
}
Verdict::Unknown(_) => wire::level_in(Some(outcome.mode)),
}
}
fn form(outcome: &Out, top: bool) -> Outcome<'_> {
let verdict = outcome.verdict.name();
let (reason, refutation, proof, disproof) = match &outcome.verdict {
Verdict::Proved(p) => (None, None, Some(Proof::keys(p)), None),
Verdict::Unprovable(d) => {
let keys = DisproofKeys {
sequent: SequentForm::from(d.sequent()),
goal: d.goal(),
};
let why = WhyNot::from(d.refutation());
(None, Some(why), None, Some(keys))
}
Verdict::Unknown(r) => (Some(Why::from(*r)), None, None, None),
};
Outcome {
version: top.then(|| level(outcome)),
deduxit: top.then_some(env!("CARGO_PKG_VERSION")),
verdict,
checked: proof.as_ref().map(|_| outcome.checked),
reason,
refutation,
fragment: outcome.fragment.name_in(outcome.mode),
mode: outcome.mode,
engine: outcome.engine,
statistics: outcome.statistics,
proof,
disproof,
}
}
#[derive(Deserialize)]
#[serde(rename_all = "lowercase")]
enum VerdictWord {
Proved,
Unprovable,
Unknown,
}
struct EngineRead(Engine);
impl<'a> Deserialize<'a> for EngineRead {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
let name = <std::borrow::Cow<'a, str>>::deserialize(deserializer)?;
Ok(Self(name.parse().unwrap_or(Engine::Unknown)))
}
}
#[derive(Deserialize)]
pub(super) struct OutcomeForm {
#[serde(default, deserialize_with = "wire::version")]
#[expect(dead_code, reason = "read for its check of the level alone")]
version: Option<u32>,
verdict: VerdictWord,
#[serde(default)]
checked: Option<bool>,
#[serde(default)]
reason: Option<Why>,
#[serde(default)]
refutation: Option<WhyNot>,
fragment: Fragment,
mode: Mode,
engine: EngineRead,
statistics: Statistics,
#[serde(default)]
sequent: Option<SequentForm>,
#[serde(default)]
nodes: Option<Vec<Step>>,
#[serde(default)]
goal: Option<Vec<u32>>,
#[serde(default)]
instances: Option<Instances>,
}
impl OutcomeForm {
pub(super) fn within(self, limits: &Limits) -> Result<Out, crate::Error> {
let missing = |key: &str| crate::Error::Json {
form: "outcome",
message: format!("missing field `{key}`"),
};
let verdict = match self.verdict {
VerdictWord::Proved => {
let sequent = self.sequent.ok_or_else(|| missing("sequent"))?;
let nodes = self.nodes.ok_or_else(|| missing("nodes"))?;
let proof = Proof::of_keys(sequent, nodes, self.mode, self.goal, self.instances);
Verdict::Proved(Box::new(proof.within(limits)?))
}
VerdictWord::Unprovable => {
let disproof = DisproofForm {
version: None,
sequent: self.sequent.ok_or_else(|| missing("sequent"))?,
mode: self.mode,
refutation: self.refutation.ok_or_else(|| missing("refutation"))?,
goal: self.goal,
};
Verdict::Unprovable(Box::new(disproof.within(limits)?))
}
VerdictWord::Unknown => {
Verdict::Unknown(self.reason.ok_or_else(|| missing("reason"))?.into())
}
};
let checked = matches!(verdict, Verdict::Proved(_)) && self.checked.unwrap_or(false);
Ok(Out {
verdict,
fragment: self.fragment,
mode: self.mode,
engine: self.engine.0,
statistics: self.statistics,
net: None,
checked,
})
}
}
impl<'a> Deserialize<'a> for Out {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
Self::read(deserializer, &Limits::default())
}
}
impl crate::sealed::Readable for Out {}
impl Readable for Out {
const FORM: &'static str = "outcome";
fn read<'de, D: Deserializer<'de>>(deserializer: D, limits: &Limits) -> Result<Self, D::Error> {
OutcomeForm::deserialize(deserializer)?
.within(limits)
.map_err(wire::fail)
}
}
impl Serialize for Engine {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.collect_str(self)
}
}
impl<'a> Deserialize<'a> for Engine {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
String::deserialize(deserializer)?
.parse()
.map_err(serde::de::Error::custom)
}
}
impl Serialize for Bias {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.collect_str(self)
}
}
impl<'a> Deserialize<'a> for Bias {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
String::deserialize(deserializer)?
.parse()
.map_err(serde::de::Error::custom)
}
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum AutoOrNumber {
Number(u64),
Word(String),
}
impl AutoOrNumber {
fn number<E: serde::de::Error>(self) -> Result<Option<u64>, E> {
match self {
Self::Number(n) => Ok(Some(n)),
Self::Word(word) if word == "auto" => Ok(None),
Self::Word(word) => Err(E::custom(format!(
"expected a number or \"auto\", found {word:?}"
))),
}
}
}
impl Serialize for Jobs {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
Self::Auto => serializer.serialize_str("auto"),
Self::Count(n) => serializer.serialize_u64(u64::try_from(*n).unwrap_or(u64::MAX)),
}
}
}
impl<'a> Deserialize<'a> for Jobs {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
Ok(match AutoOrNumber::deserialize(deserializer)?.number()? {
None => Self::Auto,
Some(n) => Self::Count(usize::try_from(n).unwrap_or(usize::MAX)),
})
}
}
impl Serialize for Cadence {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
Self::Auto => serializer.serialize_str("auto"),
Self::Every(n) => serializer.serialize_u32(*n),
}
}
}
impl<'a> Deserialize<'a> for Cadence {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
Ok(match AutoOrNumber::deserialize(deserializer)?.number()? {
None => Self::Auto,
Some(n) => Self::Every(u32::try_from(n).map_err(serde::de::Error::custom)?),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn reasons_read_back() {
for reason in [
Reason::Stopped,
Reason::RecursionLimit { depth: 2048 },
Reason::CopyBound { copies: 3 },
Reason::MemoryLimit {
limit_bytes: 1 << 30,
},
Reason::IndexLimit,
Reason::WorkLimit { limit: 1 << 20 },
Reason::Unchecked {
limit_bytes: 1 << 30,
},
Reason::WitnessDepth { depth: 64 },
Reason::Instances { instances: 1 << 16 },
] {
let json = serde_json::to_string(&reason).unwrap();
assert_eq!(
serde_json::from_str::<Reason>(&json).unwrap(),
reason,
"{json}"
);
}
assert_eq!(
serde_json::to_string(&Reason::CopyBound { copies: 3 }).unwrap(),
r#"{"kind":"copy_bound","copies":3}"#
);
let unknown = serde_json::from_str::<Reason>(r#"{"kind":"tired"}"#);
assert!(
unknown
.unwrap_err()
.to_string()
.contains("unknown variant `tired`")
);
}
#[test]
fn refutations_read_back() {
let (a, o) = (Atom::new, OccId::new);
for refutation in [
Refutation::Exhausted,
Refutation::Unbalanced(Unbalanced {
atom: a(1),
least: 1,
most: 2,
}),
Refutation::OneSided(OneSided {
atom: a(0),
least: -2,
most: -1,
copied: Sign::Dual,
}),
Refutation::Equation(Equation {
formulas: 2,
needed: 3,
tensors: 1,
pars: 0,
ones: 0,
bottoms: 0,
mix: false,
}),
Refutation::StateEquation(StateEquation {
atoms: vec![(a(0), 2), (a(2), -1)],
clauses: vec![(o(3), 1)],
dropped: vec![o(5)],
}),
Refutation::Saturated(Saturated::new(
vec![Sign::Atom, Sign::Dual],
vec![
Stable::new(vec![o(1), o(1), o(4)], vec![o(2)], false),
Stable::new(Vec::new(), Vec::new(), true),
],
)),
] {
let json = serde_json::to_string(&refutation).unwrap();
let back = serde_json::from_str::<Refutation>(&json).unwrap();
assert_eq!(back, refutation, "{json}");
}
let unknown = serde_json::from_str::<Refutation>(r#"{"kind":"tableau"}"#);
let message = unknown.unwrap_err().to_string();
assert!(message.contains("unknown variant `tableau`"), "{message}");
}
}