The module provides the elementary tools for working with first order logic. It allows defining both formulas and sets as well as performing some basic operations on them, such as evaluations regarding interpretations, performs substitutions, closures, ...
( String, List Basics.Int )
It represent an ident as a string and a list of subindices as integers
( String
, List Basics.Int
, Basics.Int
)
It represent a variable as a string, a list of subindices as integers, and a superindex that must be a positive int.
It is used to represent the terms in First Order Logic , these are variables, constants and functions. Note that constants are a particular case of functions, which are not dependent on any variable.
It is a recursive definition of a formula in First Order Logic. It could be a predicate, equality, universal quantification, existential quantificacation, negation, conjuction, implication, equivalence and unsatisfiable formula
List FormulaFOL
It is used to define sets of formulas in First Order Logic.
ffolNegation : FormulaFOL -> FormulaFOL
It gives the negarion of a formula applying idempotent rule or the insat/taut negation when corresponds.
termVarSymbols : Term -> List Variable
It gets all the variable symbols that acts inside a term
termVarSymbols (Func "f" [ Var "a", Func "c" [], Func "g" [ Var "b", Var "a" ] ]) =
[ "a", "b" ]
termsVarSymbols : List Term -> List Variable
It gets all the variables that acts inside a list of terms
termsVarSymbols [ Func "f" [ Var "a", Func "c" [] ], Func "g" [ Var "b", Var "c" ] ] =
[ "a", "b", "c" ]
ffolVarSymbols : FormulaFOL -> List Variable
It gets all the variables that acts inside a formula
f1 =
ffolReadExtraction <| ffolReadFromString "_p(x,y)=_p(y,x)"
f2 =
ffolReadExtraction <| ffolReadFromString "!A[x] !A[y] (M(x,y) -> !E[z] F(z, _jhon) & P(x,z) | P(y,z))"
ffolVarSymbols f1 =
[ "x", "y" ]
ffolVarSymbols f2 =
[ "x", "y", "z" ]
termConstSymbols : Term -> List Ident
It gets all the constant symbols that acts inside a term
termsConstSymbols : List Term -> List Ident
It gets all the constants symbols that acts inside a list of terms
ffolConstSymbols : FormulaFOL -> List Ident
It gets all the constant symbols that acts inside a formula
termFuncSymbols : Term -> List Ident
It gets all the function symbols that acts inside a term
termsFuncSymbols : List Term -> List Ident
It gets all the function symbols that acts inside a list of terms
ffolFuncSymbols : FormulaFOL -> List Ident
It gets all the function symbols that acts inside a formula
ffolPredSymbols : FormulaFOL -> List Ident
It gets all the predicate symbols that acts inside a formula
ffolContainsEquality : FormulaFOL -> Basics.Bool
It gets if a formual contains equal predicate or not
ffolFormTree : FormulaFOL -> Graph FormulaFOL ()
It gives a graph with the form tree of a formula. If you want visualize it you can use formTreeToDOT and visualize the result witn an online graphviz render. Don't forget change \\n
by \n
and \\"
by "
in a code editor previously.
ffolFormTree f2 |> formTreeToDOT =
"digraph G {\n rankdir=TB\n graph []\n node [shape=plaintext, color=black]\n edge [dir=none]\n\n 0 -> 1\n 1 -> 2\n 2 -> 3\n 2 -> 9\n 3 -> 4\n 3 -> 5\n 5 -> 6\n 5 -> 8\n 6 -> 7\n\n 0 [label=\"∀x ∀y ( ( M(x, y) → ( ∃z F(z, jhon) ∧ P(x, z) ) ) ∨ P(y, z) )\"]\n 1 [label=\"∀y ( ( M(x, y) → ( ∃z F(z, jhon) ∧ P(x, z) ) ) ∨ P(y, z) )\"]\n 2 [label=\"( ( M(x, y) → ( ∃z F(z, jhon) ∧ P(x, z) ) ) ∨ P(y, z) )\"]\n 3 [label=\"( M(x, y) → ( ∃z F(z, jhon) ∧ P(x, z) ) )\"]\n 4 [label=\"M(x, y)\"]\n 5 [label=\"( ∃z F(z, jhon) ∧ P(x, z) )\"]\n 6 [label=\"∃z F(z, jhon)\"]\n 7 [label=\"F(z, jhon)\"]\n 8 [label=\"P(x, z)\"]\n 9 [label=\"P(y, z)\"]\n}"
ffolIsWellFormed : FormulaFOL -> Basics.Bool
It indicates if a formula is well formed or not. A formula is well formed if it doesn't contain two nested quantifiers over the same variable
f3 = ffolReadExtraction <| ffolReadFromString "!A[x] !A[y] (M(x,y) -> !E[x] F(x, _jhon) & P(x,x) | P(y,x))"
ffolIsWellFormed f1 == True
ffolIsWellFormed f2 == True
ffolIsWellFormed f3 == False
ffolHasInstanceOfVar : FormulaFOL -> Variable -> Basics.Bool
It gives if a formula contains an instance of the variable given.
ffolHasFreeInstanceOfVar : FormulaFOL -> Variable -> Basics.Bool
It checks if in one formula if it exists any free instance of a given variable
ffolHasLinkedInstanceOfVar : FormulaFOL -> Variable -> Basics.Bool
It checks if in one formula if it exists any linked instance of a given variable
ffolFreeVars : FormulaFOL -> List Variable
It gives the variables of the formulas that are free. That is, variables that have a free instance in the formula
ffolLinkedVars : FormulaFOL -> List Variable
It gives the variables of the formulas that are linked. That is, variables that have a linked instance in the formula
termIsClosed : Term -> Basics.Bool
It determinates if a term is closed this is if it doesn't contains any variable
termClosedTerms : Term -> List Term
It gives the all the closed terms inside a term (including the entire term if it is closed)
termsClosedTerms : List Term -> List Term
It gives all the closed terms inside a list of terms.
ffolAllClosedTerms : FormulaFOL -> List Term
It gives the all the closed terms inside a formula
ffolIsOpen : FormulaFOL -> Basics.Bool
It determinates if a formula is opened this is if it doesn't contains any quantifier
ffolIsClosed : FormulaFOL -> Basics.Bool
It checks if s formula is closed this is if it hasn't any free variables
sfolNegation : SetFOL -> SetFOL
It transforms a SetFOL into a new SetFOL by negating each formula of the set.
sfolConjunction : SetFOL -> FormulaFOL
It transforms a SetFOL into a FormulaFOL using conjuction between formulas. If Set is empty Taut is given
sfolDisjunction : SetFOL -> FormulaFOL
It transforms a SetPL into a FormulaFOL using disjunction between formulas. If Set is empty Insat is given
Dict Variable Term
It defines a substitution in First Order Logic
substitutionDomain : Substitution -> List Variable
It gets the variable domain of the substitution, that is variables symbols that participates in it.
termApplySubstitution : Substitution -> Term -> Term
It performes a substitution in a term, replacing the variables according to the substitution.
ffolApplySubstitution : Substitution -> FormulaFOL -> FormulaFOL
It performes a substitution in a formula, replacing the variables according to the substitution.
substitutionComposition : Substitution -> Substitution -> Substitution
It gives the composition of two substitutions (s1 ∘ s2)
ffolRenameVars : FormulaFOL -> FormulaFOL
It renames variables in a formula if it is necessary. If a instance is linked to several quantifiers (non well formed formula) it takes the nearest one as reference.
ffolUniversalClosure : FormulaFOL -> FormulaFOL
It gives the universal closure of a formula
ffolExistentialClosure : FormulaFOL -> FormulaFOL
It gives the existential closure of a formula
( Set comparable
, { const : Dict Ident comparable
, func : Dict Ident ( Basics.Int
, Dict (List comparable) comparable )
, pred : Dict Ident ( Basics.Int
, Set (List comparable) ) }
)
It defines an interpretation in First Order Logic, this is a pair of a set of elements (universe) and a record with the following keys and values:
key:const
, value: A dictionary that asigns to each constant symbol a element of the universe.
key:func
, value: A dictionary that asigns to each function symbol, $f$, a tuple whose first argument regards to the arity, $n$, and second one a dictionary (who emulates a total function) that assigns to each posible k-tuple (as a list) of elements of the universe an element of this universe.
key:pred
, value: A dictionary that asigns to each predicate symbol, $P$, a tuple whose first argument regards to the arity, $n$, and second one the set of k-tuples (as lists) of elements of the universe that verifies the predicate.
lStructureIsValid : L_Structure comparable -> Basics.Bool
It checks that a L_Structure is valid, that is:
If all the values asigned to the constants are in the universe
For each function symbol, of arity k, all the possible k-tuples (as lists) of elements for the universe must be in the associated dictionary, and all the elements of its range must be in the universe.
For each predicate symbol, all the elements of the associated set must be lists whose length matches with the regarding arity and whose elements belongs to the universe
termInterpretation : Term -> L_Structure comparable -> Maybe comparable
It calculates the interpretation of a closed term regarding to a L_structure. If it is not interpretable by the L_struncture then it returns Nothing.
termsInterpretation : List Term -> L_Structure comparable -> Maybe (List comparable)
It calculates the interpretations of a list of closed terms, if any of them is not interpretable then it returns Nothing.
ffolValuation : FormulaFOL -> L_Structure comparable -> Maybe Basics.Bool
It calculates the valuation of a formula regarding to an interpretation. If the formula is not closed or any element is not interpretable it returns Nothing.
sfolInterpretation : SetFOL -> L_Structure comparable -> Maybe Basics.Bool
It calculates the valuation of a set of closed formulas regarding to an interpretation. If any formula is interpretable it returns Nothing.
ffolReadFromString : String -> ( Maybe FormulaFOL, String, String )
It reads the formula from a string. It returns a tuple with may be a formula (if it can be read it), the input considerated to parse and a message of error it it is not able to performs the parsing. The rules of the notation are:
_{
and }
and separated by commas. For example: X
,Y_{1}
, Xa_{1,1}
.a
,b_{1}
,john
, and functions (not constants): f(X)
, *g_{1}(X, a)
,*father(john)
, ...P
,Q_{1}(X)
,Uncle(john, paul)
, ...&
for conjunction, |
for disjunction, ->
for implication, <->
for equivalence and ¬
or -
for negation with classical priority(negation, conjunction, disjunction, implication, equivalence) and the use of parentheses to indicate another association priority.!E
for the existential!A
for the universal, followed by the variable indicated in brackets, [
and ]
, and by the quantized formula. As an example, the inductive property on a function (f) can be expressed as: !A[X_{1}] !A[X_{2}](f(X_{1}) = f(X_{2}) -> X_{1} = f(X_{2}))
, or the membership of a value (a) to the range of a function (g) like !E[X](g(X) = a))
.!T
and the unsatisfiable formula for!F
.ffolReadExtraction : ( Maybe FormulaFOL, String, String ) -> FormulaFOL
It extract the formula readed. If it is Nothing it returns Insat
ffolRead : String -> FormulaFOL
It reads the formula from a string. It returns the Formula if the string si correct, otherwise it returns Insat.
sfolRead : String -> SetFOL
It reads a set of formulas from a string. Each string that corresponds to each of the formulas of the set must be ended by a point .
(the last formula can, optionally, not be ended by a point).
ffolToInputString : FormulaFOL -> String
It gives the corresponding input syntax of a formula
substitutionReadFromString : String -> ( Maybe Substitution, String, String )
It returns a tuple with may be a substitution (if it can be read it), the input considerated to parse and a message of error if it is not able to performs the parsing. -- Messages are not perfect but we're working to improve it.
substitutionReadExtraction : ( Maybe Substitution, String, String ) -> Substitution
It extract the formula readed. If it is Nothing it returns Insat
substitutionToInputString : Substitution -> String
It generates the corresponding string input of a substitution
varToString : Variable -> String
It generates the string of a variable
varsToString : List Variable -> String
It generates the string of a list of variables
varToMathString : Variable -> String
It generates the string of a variable using Latex Notation
varsToMathString : List Variable -> String
It generates the string of a list of identifier
identToString : Ident -> String
It generates the string of an identifier
identsToString : List Ident -> String
It generates the string of a list of identifier
identToMathString : Ident -> String
It generates the string of an identifier using Latex notation
identsToMathString : List Ident -> String
It generates the string of a list of identifier
termToString : Term -> String
It generates the string of a term
termsToString : List Term -> String
It generates the string of a list of terms (parameters)
termToMathString : Term -> String
It generates the string of a term using latex notation
termsToMathString : List Term -> String
It generates the string of a list of terms (parameters) using latex notation
ffolToString : FormulaFOL -> String
It generates the string of a First Order Logic Formula,
sfolToString : SetFOL -> String
It generates the string of a First Order Logic Set of formulas,
ffolToMathString : FormulaFOL -> String
It generates the string of a First Order Logic Formula using latex notation
sfolToMathString : SetFOL -> String
It generates the string of a First Order Logic Set of formulas using latex notation as an array
sfolToMathString2 : SetFOL -> String
It generates the string of a First Order Logic Set of formulas using latex notation as an array
formTreeToString : Graph FormulaFOL () -> String
It gives a string representation of a form tree
formTreeToDOT : Graph FormulaFOL () -> String
It gives a string representation of a form tree using DOT format
substitutionToString : Substitution -> String
It gives a string representation of a substitution using latex notation
substitutionToMathString : Substitution -> String
It gives a string representation of a substitution using latex notation
l_StructureToString : L_Structure comparable -> (comparable -> String) -> String
It gives a L-structure as string. It needs a funtion that gives the string representation of the elements of the L-Structure