Skip to content
Snippets Groups Projects
Commit 4be9a1aa authored by Katja Goltsova's avatar Katja Goltsova
Browse files

Require that PredicateFormula's and ConnectorFormula's args correspond to the label's arity

Analogous to the existing requirement in FunctionTerm.
parent d0a96d1a
No related branches found
No related tags found
4 merge requests!54Front integration,!53Front integration,!52Front integration,!45Require that PredicateFormula's and ConnectorFormula's args correspond to the label's arity
...@@ -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.
Finish editing this message first!
Please register or to comment