Support empty n-aries
This commit is contained in:
parent
51cbdb313f
commit
9a8013f1cb
@ -486,8 +486,6 @@ impl Formula
|
|||||||
{
|
{
|
||||||
pub fn and(arguments: Formulas) -> Self
|
pub fn and(arguments: Formulas) -> Self
|
||||||
{
|
{
|
||||||
assert!(!arguments.is_empty());
|
|
||||||
|
|
||||||
Self::And(arguments)
|
Self::And(arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,8 +535,6 @@ impl Formula
|
|||||||
|
|
||||||
pub fn if_and_only_if(arguments: Formulas) -> Self
|
pub fn if_and_only_if(arguments: Formulas) -> Self
|
||||||
{
|
{
|
||||||
assert!(!arguments.is_empty());
|
|
||||||
|
|
||||||
Self::IfAndOnlyIf(arguments)
|
Self::IfAndOnlyIf(arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,8 +566,6 @@ impl Formula
|
|||||||
|
|
||||||
pub fn or(arguments: Formulas) -> Self
|
pub fn or(arguments: Formulas) -> Self
|
||||||
{
|
{
|
||||||
assert!(!arguments.is_empty());
|
|
||||||
|
|
||||||
Self::Or(arguments)
|
Self::Or(arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,42 +177,52 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
display_formula(argument, Some(self.formula), ChildPosition::Any))?,
|
display_formula(argument, Some(self.formula), ChildPosition::Any))?,
|
||||||
crate::Formula::And(arguments) =>
|
crate::Formula::And(arguments) =>
|
||||||
{
|
{
|
||||||
let mut separator = "";
|
if arguments.is_empty()
|
||||||
|
|
||||||
assert!(!arguments.is_empty());
|
|
||||||
|
|
||||||
let (parent_formula, position) = match arguments.len()
|
|
||||||
{
|
{
|
||||||
0 | 1 => (self.parent_formula, self.position),
|
write!(format, "true")?;
|
||||||
_ => (Some(self.formula), ChildPosition::Any),
|
}
|
||||||
};
|
else
|
||||||
|
|
||||||
for argument in arguments
|
|
||||||
{
|
{
|
||||||
write!(format, "{}{:?}", separator,
|
let (parent_formula, position) = match arguments.len()
|
||||||
display_formula(argument, parent_formula, position))?;
|
{
|
||||||
|
1 => (self.parent_formula, self.position),
|
||||||
|
_ => (Some(self.formula), ChildPosition::Any),
|
||||||
|
};
|
||||||
|
|
||||||
separator = " and "
|
let mut separator = "";
|
||||||
|
|
||||||
|
for argument in arguments
|
||||||
|
{
|
||||||
|
write!(format, "{}{:?}", separator,
|
||||||
|
display_formula(argument, parent_formula, position))?;
|
||||||
|
|
||||||
|
separator = " and "
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
crate::Formula::Or(arguments) =>
|
crate::Formula::Or(arguments) =>
|
||||||
{
|
{
|
||||||
let mut separator = "";
|
if arguments.is_empty()
|
||||||
|
|
||||||
assert!(!arguments.is_empty());
|
|
||||||
|
|
||||||
let (parent_formula, position) = match arguments.len()
|
|
||||||
{
|
{
|
||||||
0 | 1 => (self.parent_formula, self.position),
|
write!(format, "false")?;
|
||||||
_ => (Some(self.formula), ChildPosition::Any),
|
}
|
||||||
};
|
else
|
||||||
|
|
||||||
for argument in arguments
|
|
||||||
{
|
{
|
||||||
write!(format, "{}{:?}", separator,
|
let (parent_formula, position) = match arguments.len()
|
||||||
display_formula(argument, parent_formula, position))?;
|
{
|
||||||
|
1 => (self.parent_formula, self.position),
|
||||||
|
_ => (Some(self.formula), ChildPosition::Any),
|
||||||
|
};
|
||||||
|
|
||||||
separator = " or "
|
let mut separator = "";
|
||||||
|
|
||||||
|
for argument in arguments
|
||||||
|
{
|
||||||
|
write!(format, "{}{:?}", separator,
|
||||||
|
display_formula(argument, parent_formula, position))?;
|
||||||
|
|
||||||
|
separator = " or "
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
crate::Formula::Implies(crate::Implies{direction, antecedent, implication}) =>
|
crate::Formula::Implies(crate::Implies{direction, antecedent, implication}) =>
|
||||||
@ -248,22 +258,27 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
},
|
},
|
||||||
crate::Formula::IfAndOnlyIf(arguments) =>
|
crate::Formula::IfAndOnlyIf(arguments) =>
|
||||||
{
|
{
|
||||||
let mut separator = "";
|
if arguments.is_empty()
|
||||||
|
|
||||||
assert!(!arguments.is_empty());
|
|
||||||
|
|
||||||
let (parent_formula, position) = match arguments.len()
|
|
||||||
{
|
{
|
||||||
0 | 1 => (self.parent_formula, self.position),
|
write!(format, "true")?;
|
||||||
_ => (Some(self.formula), ChildPosition::Any),
|
}
|
||||||
};
|
else
|
||||||
|
|
||||||
for argument in arguments
|
|
||||||
{
|
{
|
||||||
write!(format, "{}{:?}", separator,
|
let (parent_formula, position) = match arguments.len()
|
||||||
display_formula(argument, parent_formula, position))?;
|
{
|
||||||
|
1 => (self.parent_formula, self.position),
|
||||||
|
_ => (Some(self.formula), ChildPosition::Any),
|
||||||
|
};
|
||||||
|
|
||||||
separator = " <-> "
|
let mut separator = "";
|
||||||
|
|
||||||
|
for argument in arguments
|
||||||
|
{
|
||||||
|
write!(format, "{}{:?}", separator,
|
||||||
|
display_formula(argument, parent_formula, position))?;
|
||||||
|
|
||||||
|
separator = " <-> "
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
crate::Formula::Compare(
|
crate::Formula::Compare(
|
||||||
@ -666,6 +681,7 @@ mod tests
|
|||||||
#[test]
|
#[test]
|
||||||
fn format_and()
|
fn format_and()
|
||||||
{
|
{
|
||||||
|
assert!(and(vec![]), "true");
|
||||||
assert!(and(vec![p()]), "p");
|
assert!(and(vec![p()]), "p");
|
||||||
assert!(and(pqr()), "p and q and r");
|
assert!(and(pqr()), "p and q and r");
|
||||||
}
|
}
|
||||||
@ -673,6 +689,7 @@ mod tests
|
|||||||
#[test]
|
#[test]
|
||||||
fn format_or()
|
fn format_or()
|
||||||
{
|
{
|
||||||
|
assert!(or(vec![]), "false");
|
||||||
assert!(or(vec![p()]), "p");
|
assert!(or(vec![p()]), "p");
|
||||||
assert!(or(pqr()), "p or q or r");
|
assert!(or(pqr()), "p or q or r");
|
||||||
}
|
}
|
||||||
@ -687,6 +704,7 @@ mod tests
|
|||||||
#[test]
|
#[test]
|
||||||
fn format_if_and_only_if()
|
fn format_if_and_only_if()
|
||||||
{
|
{
|
||||||
|
assert!(if_and_only_if(vec![]), "true");
|
||||||
assert!(if_and_only_if(vec![p()]), "p");
|
assert!(if_and_only_if(vec![p()]), "p");
|
||||||
assert!(if_and_only_if(vec![p(), q()]), "p <-> q");
|
assert!(if_and_only_if(vec![p(), q()]), "p <-> q");
|
||||||
assert!(if_and_only_if(pqr()), "p <-> q <-> r");
|
assert!(if_and_only_if(pqr()), "p <-> q <-> r");
|
||||||
|
Loading…
Reference in New Issue
Block a user