Skip to content
Snippets Groups Projects
Unverified Commit 967f9ead authored by SimonGuilloud's avatar SimonGuilloud Committed by GitHub
Browse files

Merge pull request #45 from cache-nez/require-arity

Require that PredicateFormula's and ConnectorFormula's args correspond to the label's arity
parents 6e3fd810 e0a7260e
No related branches found
No related tags found
3 merge requests!54Front integration,!53Front integration,!52Front integration
...@@ -23,6 +23,7 @@ private[fol] trait FormulaDefinitions extends FormulaLabelDefinitions with TermD ...@@ -23,6 +23,7 @@ private[fol] trait FormulaDefinitions extends FormulaLabelDefinitions with TermD
* The formula counterpart of [[PredicateLabel]]. * The formula counterpart of [[PredicateLabel]].
*/ */
sealed case class PredicateFormula(label: PredicateLabel, args: Seq[Term]) extends Formula { sealed case class PredicateFormula(label: PredicateLabel, args: Seq[Term]) extends Formula {
require(label.arity == args.size)
override def freeVariables: Set[VariableLabel] = args.foldLeft(Set.empty[VariableLabel])((prev, next) => prev union next.freeVariables) override def freeVariables: Set[VariableLabel] = args.foldLeft(Set.empty[VariableLabel])((prev, next) => prev union next.freeVariables)
override def constantPredicates: Set[ConstantPredicateLabel] = label match { override def constantPredicates: Set[ConstantPredicateLabel] = label match {
...@@ -42,6 +43,7 @@ private[fol] trait FormulaDefinitions extends FormulaLabelDefinitions with TermD ...@@ -42,6 +43,7 @@ private[fol] trait FormulaDefinitions extends FormulaLabelDefinitions with TermD
* The formula counterpart of [[ConnectorLabel]]. * The formula counterpart of [[ConnectorLabel]].
*/ */
sealed case class ConnectorFormula(label: ConnectorLabel, args: Seq[Formula]) extends Formula { sealed case class ConnectorFormula(label: ConnectorLabel, args: Seq[Formula]) extends Formula {
require(label.arity == -1 || label.arity == args.length)
override def freeVariables: Set[VariableLabel] = args.foldLeft(Set.empty[VariableLabel])((prev, next) => prev union next.freeVariables) override def freeVariables: Set[VariableLabel] = args.foldLeft(Set.empty[VariableLabel])((prev, next) => prev union next.freeVariables)
override def constantFunctions: Set[ConstantFunctionLabel] = args.foldLeft(Set.empty[ConstantFunctionLabel])((prev, next) => prev union next.constantFunctions) override def constantFunctions: Set[ConstantFunctionLabel] = args.foldLeft(Set.empty[ConstantFunctionLabel])((prev, next) => prev union next.constantFunctions)
......
...@@ -38,7 +38,7 @@ class PrinterTest extends AnyFunSuite { ...@@ -38,7 +38,7 @@ class PrinterTest extends AnyFunSuite {
assert(prettyFormula(BinderFormula(Forall, x, BinderFormula(Exists, y, BinderFormula(ExistsOne, z, a)))) == "∀x. ∃y. ∃!z. a") assert(prettyFormula(BinderFormula(Forall, x, BinderFormula(Exists, y, BinderFormula(ExistsOne, z, a)))) == "∀x. ∃y. ∃!z. a")
assert(prettyFormula(PredicateFormula(ConstantPredicateLabel("f", 2), Seq(x, y, z))) == "f(?x, ?y, ?z)") assert(prettyFormula(PredicateFormula(ConstantPredicateLabel("f", 3), Seq(x, y, z))) == "f(?x, ?y, ?z)")
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment