![]() |
Connect++ 0.7.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 > &, vector< string > &, const string &) |
| Convert to Conjunctive Normal Form. | |
| void | split_sub_formulas (vector< FOF > &, vector< FOF > &) |
| Split subformulas in half. | |
| void | find_definitional_tuple (FOF &, vector< FOF > &, vector< FOF > &, bool) |
| Heavy-lifting for conversion to definitional clause form. | |
| void | definitional_convert_to_cnf_clauses (vector< Clause > &, vector< string > &, const string &) |
| 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. | |
| string | to_tptp_string (bool=false) const |
| Convert a FOF into a nice-looking string in the TPTP format. | |
| string | predicate_to_tptp_string () const |
| Assuming this is an Atom, return the predicate name as a 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 void | set_recs_p (TPTPRecords *_p) |
| Set up the pointer allowing TPTP outputs to be added. | |
| 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 > &, 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 * >, FOF *, bool=false) |
| Main helper function called by FOF::skolemize(). | |
| void | skolemize_universals_main (vector< Term * >, FOF *, bool=false) |
| 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 TPTPRecords * | recs_p = nullptr |
| Allow FOF to add TPTP outputs. | |
| 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 &out, const FOF &f) |
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 219 of file FOF.hpp.
| FOF::FOF | ( | const Literal & | lit | ) |
| lit | Reference to Literal to use. |
Definition at line 347 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 365 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 1169 of file FOF.cpp.
| void FOF::convert_to_cnf_clauses | ( | vector< Clause > & | cs, |
| vector< string > & | _names, | ||
| const string & | _role ) |
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 817 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 638 of file FOF.cpp.
| void FOF::definitional_convert_to_cnf_clauses | ( | vector< Clause > & | cs, |
| vector< string > & | _names, | ||
| const string & | _role ) |
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 984 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 1263 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 150 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 1259 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 97 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 1202 of file FOF.cpp.
| size_t FOF::find_and | ( | ) | const |
| void FOF::find_definitional_tuple | ( | FOF & | f, |
| vector< FOF > & | d, | ||
| vector< FOF > & | d_preds, | ||
| bool | in_conjunction ) |
Heavy-lifting for conversion to definitional clause form.
| f | First part of definitional tuple. |
| d | Second part of definitional tuple. |
| d_preds | Collects any new predicates introduced. |
| in_conjunctionm | Indicates whether or not the parent formula was a conjunction. |
Definition at line 916 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 1511 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 36 of file FOF.cpp.
| void FOF::invert_literal | ( | ) |
Self-explanatory!
Definition at line 462 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 407 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 87 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 205 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 519 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 648 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 323 of file FOF.cpp.
| void FOF::negate | ( | ) |
Negate an FOF, applying obvious simplifications if it's already negated or an implication.
Definition at line 431 of file FOF.cpp.
| string FOF::predicate_to_tptp_string | ( | ) | const |
Assuming this is an Atom, return the predicate name as a string.
Definition at line 1438 of file FOF.cpp.
| void FOF::push_negs | ( | ) |
Push all negations in.
DON'T call it on anything with a -> or <->.
Definition at line 573 of file FOF.cpp.
| void FOF::remove_existential_quantifiers | ( | ) |
Self-explanatory.
Definition at line 1131 of file FOF.cpp.
| void FOF::remove_iff | ( | ) |
Replace <-> throughout using ->.
Definition at line 474 of file FOF.cpp.
| void FOF::remove_imp | ( | ) |
Replace A->B throughout with neg A v B.
Definition at line 501 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 544 of file FOF.cpp.
| void FOF::remove_universal_quantifiers | ( | ) |
Self-explanatory.
Definition at line 1103 of file FOF.cpp.
Self-explanatory.
However note that this works only on Atoms: quantifiers will be unaffected.
Definition at line 73 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 211 of file FOF.cpp.
|
inlinestatic |
Set up pointer to the variable index etc.
Definition at line 241 of file FOF.hpp.
|
inlinestatic |
|
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 1490 of file FOF.cpp.
|
static |
As first version of simplify_cnf, but keep track of corresponding roles as well.
Definition at line 1447 of file FOF.cpp.
| void FOF::skolemize | ( | ) |
Skolemize the given formula.
All the hard work is done by skolemize_main.
Definition at line 1093 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 225 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 1098 of file FOF.cpp.
|
private |
The dual of skolemize_main.
Definition at line 273 of file FOF.cpp.
Split subformulas in half.
| left_sub | First half of the subformulas. |
| right_sub | Second half of subformulas. |
Definition at line 892 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 1159 of file FOF.cpp.
| string FOF::to_string | ( | ) | const |
Convert a FOF into a nice-looking string.
Definition at line 1267 of file FOF.cpp.
| string FOF::to_tptp_string | ( | bool | nesting = false | ) | const |
Convert a FOF into a nice-looking string in the TPTP format.
Argument allows you to collect variables for nested quantifiers.
Definition at line 1345 of file FOF.cpp.
|
friend |
Definition at line 1547 of file FOF.cpp.
|
staticprivate |
|
private |
|
staticprivate |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
private |
|
staticprivate |