Skip to content

Commit f5a22b1

Browse files
committed
simplifying boolean/functional quantifier removal code
1 parent 7447e22 commit f5a22b1

File tree

1 file changed

+10
-38
lines changed

1 file changed

+10
-38
lines changed

src/formula.h

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,8 +1328,8 @@ struct callback_applier {
13281328
return leaves;
13291329
}
13301330

1331-
sp_tau_node<BAs...> apply_wff_remove_buniversal(const sp_tau_node<BAs...>& n) {
1332-
auto args = n || tau_parser::wff_cb_arg || only_child_extractor<BAs...>;
1331+
std::pair<sp_tau_node<BAs...>, sp_tau_node<BAs...>> get_quantifier_remove_constituents(const tau_parser::nonterminal type, const sp_tau_node<BAs...>& n) {
1332+
auto args = n || type || only_child_extractor<BAs...>;
13331333
auto var = args[0];
13341334
auto T = args[2];
13351335
auto F = args[3];
@@ -1341,54 +1341,26 @@ struct callback_applier {
13411341
right_changes[var] = F;
13421342
auto right = replace<sp_tau_node<BAs...>>(args[1], right_changes)
13431343
| only_child_extractor<BAs...> | optional_value_extractor<sp_tau_node<BAs...>>;
1344+
return {left, right};
1345+
}
1346+
1347+
sp_tau_node<BAs...> apply_wff_remove_buniversal(const sp_tau_node<BAs...>& n) {
1348+
auto [left, right] = get_quantifier_remove_constituents(tau_parser::wff_cb_arg, n);
13441349
return build_wff_and<BAs...>(left, right);
13451350
}
13461351

13471352
sp_tau_node<BAs...> apply_wff_remove_bexistential(const sp_tau_node<BAs...>& n) {
1348-
auto args = n || tau_parser::wff_cb_arg || only_child_extractor<BAs...>;
1349-
auto var = args[0];
1350-
auto T = args[2];
1351-
auto F = args[3];
1352-
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> left_changes;
1353-
left_changes[var] = T;
1354-
auto left = replace<sp_tau_node<BAs...>>(args[1], left_changes)
1355-
| only_child_extractor<BAs...> | optional_value_extractor<sp_tau_node<BAs...>>;
1356-
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> right_changes;
1357-
right_changes[var] = F;
1358-
auto right = replace<sp_tau_node<BAs...>>(args[1], right_changes)
1359-
| only_child_extractor<BAs...> | optional_value_extractor<sp_tau_node<BAs...>>;
1353+
auto [left, right] = get_quantifier_remove_constituents(tau_parser::wff_cb_arg, n);
13601354
return build_wff_or<BAs...>(left, right);
13611355
}
13621356

13631357
sp_tau_node<BAs...> apply_bf_remove_funiversal(const sp_tau_node<BAs...>& n) {
1364-
auto args = n || tau_parser::bf_cb_arg || only_child_extractor<BAs...>;
1365-
auto var = args[0];
1366-
auto T = args[2];
1367-
auto F = args[3];
1368-
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> left_changes;
1369-
left_changes[var] = T;
1370-
auto left = replace<sp_tau_node<BAs...>>(args[1], left_changes)
1371-
| only_child_extractor<BAs...> | optional_value_extractor<sp_tau_node<BAs...>>;
1372-
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> right_changes;
1373-
right_changes[var] = F;
1374-
auto right = replace<sp_tau_node<BAs...>>(args[1], right_changes)
1375-
| only_child_extractor<BAs...> | optional_value_extractor<sp_tau_node<BAs...>>;
1358+
auto [left, right] = get_quantifier_remove_constituents(tau_parser::bf_cb_arg, n);
13761359
return build_bf_and<BAs...>(left, right);
13771360
}
13781361

13791362
sp_tau_node<BAs...> apply_bf_remove_fexistential(const sp_tau_node<BAs...>& n) {
1380-
auto args = n || tau_parser::bf_cb_arg || only_child_extractor<BAs...>;
1381-
auto var = args[0];
1382-
auto T = args[2];
1383-
auto F = args[3];
1384-
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> left_changes;
1385-
left_changes[var] = T;
1386-
auto left = replace<sp_tau_node<BAs...>>(args[1], left_changes)
1387-
| only_child_extractor<BAs...> | optional_value_extractor<sp_tau_node<BAs...>>;
1388-
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> right_changes;
1389-
right_changes[var] = F;
1390-
auto right = replace<sp_tau_node<BAs...>>(args[1], right_changes)
1391-
| only_child_extractor<BAs...> | optional_value_extractor<sp_tau_node<BAs...>>;
1363+
auto [left, right] = get_quantifier_remove_constituents(tau_parser::bf_cb_arg, n);
13921364
return build_bf_or<BAs...>(left, right);
13931365
}
13941366

0 commit comments

Comments
 (0)