![]() |
Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
|
Representation of first order formulas. More...
#include <FOF.hpp>
Public Member Functions | |
FOF ()=delete | |
You don't want this constructor. | |
FOF (FOFType t) | |
You probably don't want this constructor. | |
FOF (const Literal &) | |
Construct FOF from Literal. | |
FOF (FOFType, const vector< FOF > &, Variable *) | |
Construct FOF for a non-literal. | |
void | show_indexes () const |
Show the indices. | |
FOFType | fof_type () |
Basic get method. | |
void | add_formula (const FOF &f) |
Add a subformula. | |
void | clear () |
Make an FOFType::Empty. | |
bool | is_literal () const |
Check if an FOF is a literal. | |
bool | is_clause () const |
Check if something is a clause. | |
void | remove_negation () |
Remove the leading negation from an arbitrary FOF, if it has one. | |
void | negate () |
Negate an FOF, applying obvious simplifications if it's already negated or an implication. | |
void | simple_negate () |
Negate an FOF without applying any simplifications. | |
void | invert_literal () |
Self-explanatory! | |
void | remove_iff () |
Replace <-> throughout using ->. | |
void | remove_imp () |
Replace A->B throughout with neg A v B. | |
void | make_unique_bound_variables () |
Replace all bound variables with unique new ones. | |
void | remove_redundant_quantifiers () |
Remove quantifiers if they don't bind anything in their scope. | |
void | push_negs () |
Push all negations in. | |
void | convert_to_nnf () |
Convert to Negation Normal Form. | |
void | miniscope () |
Apply the rules for miniscoping. | |
void | convert_to_cnf_clauses (vector< Clause > &) |
Convert to Conjunctive Normal Form. | |
void | split_sub_formulas (vector< FOF > &, vector< FOF > &) |
Split subformulas in half. | |
void | find_definitional_tuple (FOF &, vector< FOF > &, bool) |
Heavy-lifting for conversion to definitional clause form. | |
void | definitional_convert_to_cnf_clauses (vector< Clause > &) |
Convert to Conjunctive Normal Form using a form of definitional conversion. | |
void | skolemize () |
Skolemize the given formula. | |
void | remove_universal_quantifiers () |
Self-explanatory. | |
void | skolemize_universals () |
Skolemize the universal quantifiers in the given formula. | |
void | remove_existential_quantifiers () |
Self-explanatory. | |
void | to_Literal (Literal &) const |
Assuming the FOF is a literal, convert it to something of type Literal. | |
void | convert_to_clauses (vector< Clause > &) const |
Assuming you have a CNF, convert it to a collection of Clauses. | |
void | dnf_invert_and_convert_to_clauses (vector< Clause > &) const |
Assuming you have a DNF, invert it and convert it to a collection of CNF clauses. | |
size_t | find_and () const |
Does the collection of subformulas contain an AND? If so, find it. | |
size_t | find_or () const |
Does the collection of subformulas contain an OR? If so, find it. | |
void | distribute_or () |
Distribute ORs to the maximum extent possible. | |
void | distribute_and () |
Distribute ANDs to the maximum extent possible. | |
string | to_string () const |
Convert a FOF into a nice-looking string. | |
set< Term * > | find_free_variables () const |
Find the free variables in the formula. | |
Static Public Member Functions | |
static void | set_indexes (std::tuple< VariableIndex *, FunctionIndex *, PredicateIndex *, TermIndex * > is) |
Set up pointer to the variable index etc. | |
static FOF | make_literal (const Literal &lit) |
Directly make a Literal. | |
static FOF | make_neg (const FOF &f) |
Directly negate a FOF. | |
static FOF | make_and (const vector< FOF > &fs) |
Directly make a conjunction. | |
static FOF | make_or (const vector< FOF > &fs) |
Directly make a disjunction. | |
static FOF | make_imp (const FOF &lhs, const FOF &rhs) |
Directly make an implication. | |
static FOF | make_iff (const FOF &lhs, const FOF &rhs) |
Directly make an iff. | |
static FOF | make_forall (const FOF &f, Variable *v) |
Directly make a universally quantified FOF. | |
static FOF | make_exists (const FOF &f, Variable *v) |
Directly make an existentially quantified FOF. | |
static SimplificationResult | simplify_cnf (vector< Clause > &) |
Simplify the clauses in a CNF using the method in Clause. | |
static SimplificationResult | simplify_cnf (vector< Clause > &, vector< string > &) |
As first version of simplify_cnf, but keep track of corresponding roles as well. | |
Private Member Functions | |
bool | has_free_variable (Variable *) |
Does this formula contain the specified variable unbound? | |
void | replace_variable (Variable *, Variable *) |
Self-explanatory. | |
Term * | make_skolem_function (const vector< Term * > &) |
Make a new Skolem function. | |
void | replace_variable_with_term (Term *, Variable *) |
Replace a Variable with a Term. | |
void | skolemize_main (vector< Term * >) |
Main helper function called by FOF::skolemize(). | |
void | skolemize_universals_main (vector< Term * >) |
The dual of skolemize_main. | |
void | miniscope_split (Variable *, vector< FOF > &, vector< FOF > &) |
Helper for miniscope. | |
void | miniscope_all () |
Apply miniscoping to all subformulas. | |
FOF | make_definitional_predicate () const |
When doing definitional clause conversion you need to be able to make unique new predicates. This will provide one. | |
bool | distribute_or_once () |
Find an OR that can be distributed and deal with it. Indicate if there isn't one. | |
bool | distribute_and_once () |
Find an AND that can be distributed and deal with it. Indicate if there isn't one. | |
Private Attributes | |
FOFType | type |
Used for all FOFs to denote what kind it it. | |
Literal | pred |
FOFType::Atom can store one of these to represent a Literal. | |
vector< FOF > | sub_formulas |
Most FOFs will have subformulas. | |
Variable * | var |
Associate a Variable with a quantifier. | |
Static Private Attributes | |
static VariableIndex * | var_index = nullptr |
Access to the index: static because all FOFs should share it. | |
static FunctionIndex * | fun_index = nullptr |
Access to the index: static because all FOFs should share it. | |
static TermIndex * | term_index = nullptr |
Access to the index: static because all FOFs should share it. | |
static PredicateIndex * | pred_index = nullptr |
Access to the index: static because all FOFs should share it. | |
Friends | |
ostream & | operator<< (ostream &, const FOF &) |
Representation of first order formulas.
First and foremost: I intensely dislike the use of inheritance. I vastly prefer to make the methods static and do everything the obvioous way. If you want the alternative sort of OO, then feel free to implement this yourself.
This has to play nicely with the parser and with the indexing of terms, variables and so on, so it needs pointers to the relevant indices.
|
inline |
You probably don't want this constructor.
Definition at line 214 of file FOF.hpp.
FOF::FOF | ( | const Literal & | lit | ) |
lit | Reference to Literal to use. |
Definition at line 314 of file FOF.cpp.
Construct FOF for a non-literal.
t | Specify FOFType for what you're making. |
sf | Reference to vector of FOF for subformulas. |
v | Pointer to Variable. |
Definition at line 332 of file FOF.cpp.
|
inline |
|
inline |
void FOF::convert_to_clauses | ( | vector< Clause > & | cs | ) | const |
Assuming you have a CNF, convert it to a collection of Clauses.
Definition at line 1062 of file FOF.cpp.
void FOF::convert_to_cnf_clauses | ( | vector< Clause > & | cs | ) |
Convert to Conjunctive Normal Form.
Follow the usual recipe (Larry's lecture notes.) BUT there are lots of ways to do this—at present there is nothing sophisticated happening, and the approach is entirely obvious/straightforward. Also, this implementation does miniscoping.
cs | vector of clauses containing the CNF. |
Definition at line 784 of file FOF.cpp.
void FOF::convert_to_nnf | ( | ) |
Convert to Negation Normal Form.
Follows the usual recipe (Larry's lecture notes.)
Definition at line 605 of file FOF.cpp.
void FOF::definitional_convert_to_cnf_clauses | ( | vector< Clause > & | cs | ) |
Convert to Conjunctive Normal Form using a form of definitional conversion.
There are lots of ways of doing definitional conversion. However as the restricted backtracking paper describing leanCoP v2.1 gives experimental results demonstrating that a particular approach is preferred, this implements the method as described in that paper.
cs | vector of clauses containing the CNF. |
Definition at line 935 of file FOF.cpp.
void FOF::distribute_and | ( | ) |
Distribute ANDs to the maximum extent possible.
Assumes you have nothing but a quantifier-free DNF in NNF. The result will have a tree structure with ORs at the top, then ANDs, then literals.
Definition at line 1156 of file FOF.cpp.
|
private |
Find an AND that can be distributed and deal with it. Indicate if there isn't one.
Definition at line 149 of file FOF.cpp.
void FOF::distribute_or | ( | ) |
Distribute ORs to the maximum extent possible.
Assumes you have nothing but a quantifier-free NNF. The result will have a tree structure with ANDs at the top, then ORs, then literals.
Definition at line 1152 of file FOF.cpp.
|
private |
Find an OR that can be distributed and deal with it. Indicate if there isn't one.
Definition at line 96 of file FOF.cpp.
void FOF::dnf_invert_and_convert_to_clauses | ( | vector< Clause > & | cs | ) | const |
Assuming you have a DNF, invert it and convert it to a collection of CNF clauses.
Definition at line 1095 of file FOF.cpp.
size_t FOF::find_and | ( | ) | const |
Heavy-lifting for conversion to definitional clause form.
f | First part of definitional tuple. |
d | Second part of definitional tuple. |
in_conjunctionm | Indicates whether or not the parent formula was a conjunction. |
Definition at line 869 of file FOF.cpp.
set< Term * > FOF::find_free_variables | ( | ) | const |
Find the free variables in the formula.
Note: will consider x to be free in:
( P(x) | Ax. Q(x) ).
Definition at line 1289 of file FOF.cpp.
size_t FOF::find_or | ( | ) | const |
|
inline |
|
private |
Does this formula contain the specified variable unbound?
Only use this if bound variables are unique. (If it finds any quantifier binding the variable it will return false.)
v | Pointer to Variable of interest. |
Definition at line 35 of file FOF.cpp.
void FOF::invert_literal | ( | ) |
Self-explanatory!
Definition at line 429 of file FOF.cpp.
bool FOF::is_clause | ( | ) | const |
Check if something is a clause.
This checks in the strict sense: either it must be a literal or a disjunction of literals, including an empty disjunction.
Returns false if FOFType::Empty.
Definition at line 374 of file FOF.cpp.
bool FOF::is_literal | ( | ) | const |
|
private |
When doing definitional clause conversion you need to be able to make unique new predicates. This will provide one.
Definition at line 86 of file FOF.cpp.
Make a new Skolem function.
Mainly achieved using methods from other classes.
args | Vector of pointers to Term. These are the Skolem function arguments. |
Definition at line 204 of file FOF.cpp.
void FOF::make_unique_bound_variables | ( | ) |
Replace all bound variables with unique new ones.
Has to be done with care to maintain the indexes correctly.
Definition at line 486 of file FOF.cpp.
void FOF::miniscope | ( | ) |
Apply the rules for miniscoping.
Push the quantifiers in as much as you can. Don't use this unless your formula is in NNF.
Definition at line 615 of file FOF.cpp.
|
private |
Apply miniscoping to all subformulas.
Helper for miniscope.
Split subformulas into ones that do and don't have the relevant variable.
v | Pointer to Variable of interest. |
free | Reference to vector of FOF. Collect FOFs with the Variable. |
absent | Reference to vector of FOF. Collect FOFs without the Variable. |
Definition at line 290 of file FOF.cpp.
void FOF::negate | ( | ) |
Negate an FOF, applying obvious simplifications if it's already negated or an implication.
Definition at line 398 of file FOF.cpp.
void FOF::push_negs | ( | ) |
Push all negations in.
DON'T call it on anything with a -> or <->.
Definition at line 540 of file FOF.cpp.
void FOF::remove_existential_quantifiers | ( | ) |
Self-explanatory.
Definition at line 1024 of file FOF.cpp.
void FOF::remove_iff | ( | ) |
Replace <-> throughout using ->.
Definition at line 441 of file FOF.cpp.
void FOF::remove_imp | ( | ) |
Replace A->B throughout with neg A v B.
Definition at line 468 of file FOF.cpp.
void FOF::remove_negation | ( | ) |
void FOF::remove_redundant_quantifiers | ( | ) |
Remove quantifiers if they don't bind anything in their scope.
Yes, the TPTP does contain such formulas. Use this only if bound variables are unique.
Definition at line 511 of file FOF.cpp.
void FOF::remove_universal_quantifiers | ( | ) |
Self-explanatory.
Definition at line 996 of file FOF.cpp.
Self-explanatory.
However note that this works only on Atoms: quantifiers will be unaffected.
Definition at line 72 of file FOF.cpp.
Replace a Variable with a Term.
Mainly achieved using methods from other classes.
Note that this works only on Atoms: quantifiers will be unaffected.
Definition at line 210 of file FOF.cpp.
|
inlinestatic |
Set up pointer to the variable index etc.
Definition at line 236 of file FOF.hpp.
|
inline |
void FOF::simple_negate | ( | ) |
Negate an FOF without applying any simplifications.
|
static |
Simplify the clauses in a CNF using the method in Clause.
Definition at line 1268 of file FOF.cpp.
|
static |
As first version of simplify_cnf, but keep track of corresponding roles as well.
Definition at line 1238 of file FOF.cpp.
void FOF::skolemize | ( | ) |
Skolemize the given formula.
All the hard work is done by skolemize_main.
Definition at line 986 of file FOF.cpp.
|
private |
Main helper function called by FOF::skolemize().
The parameter is used to collect variables for the universal quantifiers inside which you find an existential quantifier. Those then become the parameters for the Skolem function.
skolem_arguments | Vector of pointers to Term. |
Definition at line 224 of file FOF.cpp.
void FOF::skolemize_universals | ( | ) |
Skolemize the universal quantifiers in the given formula.
All the hard work is done by skolemize_universals_main.
Definition at line 991 of file FOF.cpp.
|
private |
The dual of skolemize_main.
Definition at line 256 of file FOF.cpp.
Split subformulas in half.
left_sub | First half of the subformulas. |
right_sub | Second half of subformulas. |
Definition at line 845 of file FOF.cpp.
void FOF::to_Literal | ( | Literal & | new_lit | ) | const |
Assuming the FOF is a literal, convert it to something of type Literal.
This is straightforward as most of the heavy lifting has already been done. DON'T use it on an FOF that isn't in the form of a literal.
Definition at line 1052 of file FOF.cpp.
string FOF::to_string | ( | ) | const |
Convert a FOF into a nice-looking string.
Definition at line 1160 of file FOF.cpp.
|
friend |
Definition at line 1325 of file FOF.cpp.
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
private |
|
staticprivate |