From f83695b5dcdc97168bcc7b684d5a6e305078f942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sun, 9 Feb 2020 10:26:24 +0700 Subject: [PATCH] Move closure functions to utils module --- src/translate/verify_properties.rs | 28 ++++------------------------ src/utils.rs | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/translate/verify_properties.rs b/src/translate/verify_properties.rs index 9e43508..e1249f8 100644 --- a/src/translate/verify_properties.rs +++ b/src/translate/verify_properties.rs @@ -117,7 +117,7 @@ where Some(definitions) => { let or_arguments = definitions.definitions.into_iter() - .map(|x| existential_closure(x)) + .map(|x| crate::existential_closure(x)) .collect::>(); let or = foliage::Formula::or(or_arguments); @@ -137,7 +137,7 @@ where formula: Box::new(completed_definition), }; - universal_closure(scoped_formula) + crate::universal_closure(scoped_formula) }, // This predicate has no definitions, so universally falsify it None => @@ -168,7 +168,7 @@ where formula: Box::new(not), }; - universal_closure(scoped_formula) + crate::universal_closure(scoped_formula) }, } }; @@ -446,7 +446,7 @@ fn read_rule(rule: &clingo::ast::Rule, context: &Context) -> Result<(), crate::E formula: Box::new(formula), }; - let integrity_constraint = universal_closure(scoped_formula); + let integrity_constraint = crate::universal_closure(scoped_formula); log::debug!("translated integrity constraint: {}", crate::output::human_readable::display_formula(&integrity_constraint, None, @@ -459,23 +459,3 @@ fn read_rule(rule: &clingo::ast::Rule, context: &Context) -> Result<(), crate::E Ok(()) } - -fn existential_closure(scoped_formula: crate::ScopedFormula) -> Box -{ - match scoped_formula.free_variable_declarations.is_empty() - { - true => scoped_formula.formula, - false => Box::new(foliage::Formula::exists(scoped_formula.free_variable_declarations, - scoped_formula.formula)), - } -} - -fn universal_closure(scoped_formula: crate::ScopedFormula) -> Box -{ - match scoped_formula.free_variable_declarations.is_empty() - { - true => scoped_formula.formula, - false => Box::new(foliage::Formula::for_all(scoped_formula.free_variable_declarations, - scoped_formula.formula)), - } -} diff --git a/src/utils.rs b/src/utils.rs index e7caf0a..dc1d90b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -44,8 +44,25 @@ pub(crate) struct ScopedFormula pub formula: Box, } -pub type InputConstantDeclarationDomains - = std::collections::BTreeMap, Domain>; +pub(crate) fn existential_closure(scoped_formula: crate::ScopedFormula) -> Box +{ + match scoped_formula.free_variable_declarations.is_empty() + { + true => scoped_formula.formula, + false => Box::new(foliage::Formula::exists(scoped_formula.free_variable_declarations, + scoped_formula.formula)), + } +} + +pub(crate) fn universal_closure(scoped_formula: crate::ScopedFormula) -> Box +{ + match scoped_formula.free_variable_declarations.is_empty() + { + true => scoped_formula.formula, + false => Box::new(foliage::Formula::for_all(scoped_formula.free_variable_declarations, + scoped_formula.formula)), + } +} pub fn parse_predicate_declaration(input: &str) -> Result, crate::Error> @@ -75,6 +92,9 @@ pub fn parse_predicate_declaration(input: &str) })) } +pub type InputConstantDeclarationDomains + = std::collections::BTreeMap, Domain>; + pub fn parse_constant_declaration(input: &str) -> Result<(std::rc::Rc, crate::Domain), crate::Error> {