Skip to content

Commit 3eff328

Browse files
committed
14.3.5 fix
1 parent 63ec0c0 commit 3eff328

5 files changed

Lines changed: 69 additions & 35 deletions

File tree

‎prover/src/countermodel/alternative_algorithm/availability.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ impl AlternativeCountermodelFinderAvailability
3737

3838
pub fn get_available_first_order_logics() -> Vec<Rc<dyn Logic>>
3939
{
40-
return Self::get_available_propositional_logics().iter()
41-
.map(|propositional_logic| Rc::new(FirstOrderLogic
40+
return vec!
41+
[
42+
Rc::new(FirstOrderLogic
4243
{
4344
domain_type: FirstOrderLogicDomainType::ConstantDomain,
4445
identity_type: FirstOrderLogicIdentityType::ContingentIdentity,
45-
base_logic: propositional_logic.clone(),
46-
}) as Rc<dyn Logic>).collect();
46+
base_logic: Rc::new(PropositionalLogic{}),
47+
}),
48+
];
4749
}
4850
}

‎prover/src/logic/first_order_logic/forall_quantifier_rule.rs‎

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::logic::first_order_logic::predicate_args_with_equivalences::create_eq
1313
use crate::logic::{LogicRule, LogicRuleResult};
1414
use crate::logic::rule_apply_factory::RuleApplyFactory;
1515
use crate::tree::node::ProofTreeNode;
16-
use crate::tree::node_factory::ProofTreeNodeID;
16+
use crate::tree::node_factory::{ProofTreeNodeFactory, ProofTreeNodeID};
1717
use crate::tree::path::ProofTreePath;
1818
use crate::tree::subtree::ProofSubtree;
1919

@@ -118,18 +118,11 @@ impl ForAllQuantifierRule
118118
let logic_pointer = factory.get_logic().clone();
119119
let logic = logic_pointer.cast_to::<FirstOrderLogic>().unwrap();
120120

121-
for path in factory.tree.get_paths_that_goes_through_node(node)
121+
let all_paths = factory.tree.get_paths_that_goes_through_node(node);
122+
for path in all_paths.clone()
122123
{
123124
let mut output_nodes = ForAllQuantifierOutputNodes::new(logic.domain_type);
124-
self.apply_for_all_quantification_impl(factory, &path, node, x, p, extras, &mut output_nodes);
125-
126-
if output_nodes.is_empty()
127-
{
128-
//there are no objects to be iterated, act similar to exists quantifier
129-
let object_name_factory = ExistsQuantifierRule{}.get_object_name_factory(factory, node);
130-
let (instantiated_p, instantiated_x) = p.instantiated(x, &object_name_factory, extras);
131-
output_nodes.add(factory, instantiated_x.unwrap_or(x.clone()), instantiated_p, extras);
132-
}
125+
self.apply_for_all_quantification_impl(factory, &all_paths, &path, node, x, p, extras, &mut output_nodes);
133126

134127
let subtree = output_nodes.to_proof_subtree(factory);
135128
output_subtrees.push((path.get_leaf_node_id(), subtree));
@@ -138,8 +131,8 @@ impl ForAllQuantifierRule
138131
return LogicRuleResult::Subtrees(output_subtrees);
139132
}
140133

141-
fn apply_for_all_quantification_impl(&self,
142-
factory : &mut RuleApplyFactory, path : &ProofTreePath, node : &ProofTreeNode,
134+
fn apply_for_all_quantification_impl(&self, factory : &mut RuleApplyFactory,
135+
all_paths : &Vec<ProofTreePath>, path : &ProofTreePath, spawner_node : &ProofTreeNode,
143136
x : &PredicateArgument, p : &Formula, extras : &FormulaExtras,
144137
output_nodes : &mut ForAllQuantifierOutputNodes,
145138
)
@@ -163,12 +156,34 @@ impl ForAllQuantifierRule
163156
.map(|a| a.object_name.clone())
164157
.collect::<BTreeSet<SmolStr>>();
165158

159+
if object_names.is_empty()
160+
{
161+
//there are no objects to be iterated, act similar to exists quantifier
162+
let object_name_factory = ExistsQuantifierRule{}.get_object_name_factory(factory, spawner_node);
163+
let (instantiated_p, instantiated_x) = p.instantiated(x, &object_name_factory, extras);
164+
output_nodes.add(factory, instantiated_x.unwrap_or(x.clone()), instantiated_p, extras);
165+
return;
166+
}
167+
166168
for object_name in object_names
167169
{
168170
let (binded_p, binded_x) = p.binded(x, object_name, extras);
169-
output_nodes.add(factory, binded_x.unwrap_or(x.clone()), binded_p, extras);
171+
172+
if !self.should_skip_outputting_binded_formula(all_paths, spawner_node, &binded_p)
173+
{
174+
output_nodes.add(factory, binded_x.unwrap_or(x.clone()), binded_p, extras);
175+
}
170176
}
171177
}
178+
179+
fn should_skip_outputting_binded_formula(&self, all_paths : &Vec<ProofTreePath>,
180+
spawner_node : &ProofTreeNode, binded_formula : &Formula) -> bool
181+
{
182+
return all_paths.iter().flat_map(|path| path.nodes.iter())
183+
.filter(|node| node.spawner_node_id == spawner_node.id)
184+
.find(|node| node.formula == *binded_formula)
185+
.is_some();
186+
}
172187
}
173188

174189
pub fn get_args_that_definitely_exists(all_formulas_on_path : &Vec<Formula>, possible_world : PossibleWorld) -> BTreeSet<PredicateArgument>

‎prover/src/proof.rs‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use itertools::Itertools;
12
use crate::formula::to_string::FormulaFormatOptions;
23
use crate::graph::Graph;
34
use crate::logic::{LogicName, LogicRuleCollection, LogicRuleResult};
@@ -45,21 +46,26 @@ impl ProofAlgorithm
4546
{
4647
let ram_consumption = measure_total_number_of_allocated_bytes(||
4748
{
48-
let (box node, mut result) = self.consume_next_queue_node().unwrap();
49+
if let Some((node, mut result)) = self.consume_next_queue_node()
50+
{
51+
ExecutionLog::log(format!("Apply: <{}> {}\nResult: {}", node.id,
52+
node.formula.to_string_with_options(&formula_format_options),
53+
result.to_string_with_options(&formula_format_options)));
4954

50-
ExecutionLog::log(format!("Apply: <{}> {}\nResult: {}", node.id,
51-
node.formula.to_string_with_options(&formula_format_options),
52-
result.to_string_with_options(&formula_format_options)));
55+
self.proof_tree.append_logic_rule_result(&mut result, node.id);
5356

57+
if !self.problem_flags.should_skip_contradiction_check
58+
{
59+
self.proof_tree.check_for_contradictions();
60+
}
5461

55-
self.proof_tree.append_logic_rule_result(&mut result, node.id);
62+
if self.decomposition_queue.is_node_reusable(&node) && result.is_empty()
63+
{
64+
self.decomposition_queue.ban_reusable_node(&node);
65+
}
5666

57-
if !self.problem_flags.should_skip_contradiction_check
58-
{
59-
self.proof_tree.check_for_contradictions();
67+
self.decomposition_queue.push_logic_rule_result(result);
6068
}
61-
62-
self.decomposition_queue.push_logic_rule_result(result);
6369
});
6470

6571
let log_helper_data = ExecutionLogHelperData::flush();
@@ -89,12 +95,9 @@ impl ProofAlgorithm
8995
factory.set_spawner_node_id(Some(node.id));
9096

9197
let result = self.logic_rules.apply(&mut factory, &node);
92-
if !result.is_empty()
93-
{
94-
return Some((node, result));
95-
}
9698

97-
return Some((node, LogicRuleResult::Empty));
99+
return if !result.is_empty() { Some((node, result)) }
100+
else { Some((node, LogicRuleResult::Empty)) };
98101
}
99102

100103
return None;

‎prover/src/proof/decomposition_queue.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ impl DecompositionPriorityQueue
7070
let reusable_node = self.reusable_nodes.remove(0);
7171
if !self.banned_reusable_nodes.contains(&reusable_node)
7272
{
73-
self.consumable_nodes.push(reusable_node.clone());
74-
self.banned_reusable_nodes.push(reusable_node);
73+
self.consumable_nodes.push(reusable_node);
7574
}
7675
}
7776

@@ -142,4 +141,17 @@ impl DecompositionPriorityQueue
142141
_ => false
143142
};
144143
}
144+
145+
pub fn is_node_reusable(&self, node : &Box<ProofTreeNode>) -> bool
146+
{
147+
return self.reusable_nodes.contains(node);
148+
}
149+
150+
pub fn ban_reusable_node(&mut self, node : &Box<ProofTreeNode>)
151+
{
152+
if self.reusable_nodes.contains(node)
153+
{
154+
self.banned_reusable_nodes.push(node.clone());
155+
}
156+
}
145157
}

‎prover/src/tree/path.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct ProofTreePathNodeData
1919
pub id : ProofTreeNodeID,
2020
pub is_contradictory : bool,
2121
pub formula : Formula,
22+
pub spawner_node_id : ProofTreeNodeID,
2223
}
2324

2425
impl ProofTreePathNodeData
@@ -30,6 +31,7 @@ impl ProofTreePathNodeData
3031
id: node.id,
3132
is_contradictory: node.is_contradictory,
3233
formula: node.formula.clone(),
34+
spawner_node_id: node.spawner_node_id.unwrap_or_default()
3335
};
3436
}
3537
}

0 commit comments

Comments
 (0)