@@ -13,7 +13,7 @@ use crate::logic::first_order_logic::predicate_args_with_equivalences::create_eq
1313use crate :: logic:: { LogicRule , LogicRuleResult } ;
1414use crate :: logic:: rule_apply_factory:: RuleApplyFactory ;
1515use crate :: tree:: node:: ProofTreeNode ;
16- use crate :: tree:: node_factory:: ProofTreeNodeID ;
16+ use crate :: tree:: node_factory:: { ProofTreeNodeFactory , ProofTreeNodeID } ;
1717use crate :: tree:: path:: ProofTreePath ;
1818use 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
174189pub fn get_args_that_definitely_exists ( all_formulas_on_path : & Vec < Formula > , possible_world : PossibleWorld ) -> BTreeSet < PredicateArgument >
0 commit comments