Basic stuff for propositional logic: datatype, parsing and prettyprinting, syntax and semantics, normal forms.
Although this module defines a specific type prop for primitive propositions, most of the functions defined here for propositional logic are applicable (and intended to be applied) in general to any kind of formula and in particular to our specific type of first order logic formulas fol. These functions handle symbolic computation at the propositional level for any kind of formula unless the signature restricts them to the prop type.
As remarked in the handbook, the defined type prop for propositional variables is fixed here just to make experimentation with some of the operations easier.Type | Description |
Function or value | Description |
|
|
|
Function or value | Description |
|
|
|
|
|
|
Full Usage:
print_propvar prec p
Parameters:
'a
p : prop
Modifiers: inline Type parameters: 'a |
|
|
|
Full Usage:
sprint_propvar prec p
Parameters:
'a
p : prop
Returns: string
Modifiers: inline Type parameters: 'a |
Function or value | Description |
Example
Evaluates to [P "p"; P "q"; P "r"] .
|
|
Example
Evaluates to "x" .
|
|
|
Example
Evaluates to `(p /\ q) /\ q /\ (p /\ q) /\ q` .
|
Function or value | Description |
A valuation is a function from the set of atoms to the set of
truth-values {
Example
The following evaluates the formula given a valuation that evaluates
Evaluates to true .
|
Function or value | Description |
Full Usage:
allvaluations fm
Parameters:
formula<'a>
-
The input formula.
Returns: ('a -> bool) list
All possible valuations of the atoms in the formula.
|
This function is not part of the handbook's code and it is added here for convenience and exercise.
Example
val fm: obj
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map: mapping: ('T -> 'U) -> list: 'T list -> 'U list
val v: (obj -> obj)
val a: obj
Evaluates to:
|
Full Usage:
fprint_truthtable sw fm
Parameters:
TextWriter
-
The TextWriter to print to.
fm : formula<prop>
-
The input prop formula.
|
See also Prop.print_truthtable
Example
val file: System.IO.StreamWriter
namespace System
namespace System.IO
type File =
static member AppendAllLines: path: string * contents: IEnumerable<string> -> unit + 1 overload
static member AppendAllLinesAsync: path: string * contents: IEnumerable<string> * encoding: Encoding * ?cancellationToken: CancellationToken -> Task + 1 overload
static member AppendAllText: path: string * contents: string -> unit + 1 overload
static member AppendAllTextAsync: path: string * contents: string * encoding: Encoding * ?cancellationToken: CancellationToken -> Task + 1 overload
static member AppendText: path: string -> StreamWriter
static member Copy: sourceFileName: string * destFileName: string -> unit + 1 overload
static member Create: path: string -> FileStream + 2 overloads
static member CreateSymbolicLink: path: string * pathToTarget: string -> FileSystemInfo
static member CreateText: path: string -> StreamWriter
static member Decrypt: path: string -> unit
...
<summary>Provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of <see cref="T:System.IO.FileStream" /> objects.</summary> System.IO.File.CreateText(path: string) : System.IO.StreamWriter
System.IO.StreamWriter.Close() : unit
After evaluation the file contains the text
|
Full Usage:
onallvaluations subfn v ats
Parameters:
('a -> bool) -> bool
-
A function that given a valuation return true or false.
v : 'a -> bool
-
The default valuation for other atoms.
ats : 'a list
-
The list of atoms on which to test all possibile valuations.
Returns: bool
true, if subfn returns true on all
possible valuations of the atoms ats with
valuation v for all other atoms; otherwise false.
|
This function is used to define both truth-table (see Prop.print_truthtable) and Prop.tautology
Example
Evaluates to true .
|
|
Each logical connective is interpreted by a corresponding bool operator of the metalanguage. A truth-table shows how the truth-value assigned to a formula is determined by those of its atoms, based on the interpretation of its logical connectives. For binary connective we have: \begin{array}{|c|c||c|c|c|c|} \hline p & q & p \land q & p \lor q & p \Rightarrow q & p \Leftrightarrow q \\ \hline false & false & false & false & true & true \\ \hline false & true & false & true & true & false \\ \hline true & false & false & true & false & false \\ \hline true & true & true & true & true & true \\ \hline \end{array} while for the unary negation: \begin{array}{|c||c|} \hline p & \neg p \\ \hline false & true\\ \hline true & false\\ \hline \end{array}A truth table has one column for each propositional variable and one final column showing all of the possible results of the logical operation that the table represents. Each row of the truth table contains one possible configuration of the propositional variables, and the result of the operation for those values. In particular, truth-tables can be used to show whether (i) a prop formula is logically valid (i.e. a tautology: see Prop.tautology that, as this function, is based on Prop.onallvaluations) when the result column hastrue in each rows of the table; (ii)
Prop.satisfiable, when the result colum
has true at least in one row; (iii)
Prop.unsatisfiable when has
false in each rows.
Example
After evaluation the following text is printed to the
stdout :
|
|
See also Prop.print_truthtable
Example
Evaluates to:
|
Function or value | Description |
Full Usage:
satisfiable fm
Parameters:
formula<'a>
-
The input formula.
Returns: bool
true, if the formula is a satisfiable at the propositional level;
otherwise false.
|
Example
Evaluates to false .
Example
Evaluates to true .
|
Full Usage:
tautology fm
Parameters:
formula<'a>
-
The input formula.
Returns: bool
true, if the formula is a tautology at the propositional level;
otherwise false.
|
Example
Evaluates to true .
Example
Evaluates to false .
Example
Evaluates to false .
Example
Evaluates to false .
|
Full Usage:
unsatisfiable fm
Parameters:
formula<'a>
-
The input formula.
Returns: bool
true, if the formula is a unsatisfiable at the propositional level;
otherwise false.
|
Example
Evaluates to true .
Example
Evaluates to false .
|
Function or value | Description |
|
|
|
This function applies to formulas a simplification routine similar to the one Intro.simplify1 applies on algebraic expressions. It eliminates the basic propositional constants \(\bot\) and \(\top\) based on the equivalences similar to the following (see the implementation for details):
Example
Evaluates to `false` .
|
Function or value | Description |
|
A literal is an atomic formula or its negation. This function can be applied to any kind of formulas but is specifically intended to be used on literals.
Example
Evaluates to `~p` .
Example
Evaluates to `p` .
|
Full Usage:
negative lit
Parameters:
formula<'a>
-
The input literal.
Returns: bool
true, if the literal is negative; otherwise false.
|
A literal is an atomic formula or its negation. This function can be applied to any kind of formulas but is specifically intended to be used on literals.
Example
Evaluates to true .
Example
Evaluates to false .
|
Full Usage:
positive lit
Parameters:
formula<'a>
-
The input literal.
Returns: bool
true, if the literal is positive; otherwise false.
|
A literal is an atomic formula or its negation. This function can be applied to any kind of formulas but is specifically intended to be used on literals.
Example
Evaluates to true .
Example
Evaluates to false .
|
Function or value | Description |
Applies Prop.psimplify first and then Prop.nenf_naive.
Example
Evaluates to `p <=> ~q)` .
Example
Evaluates to `q` .
|
|
|
Example
Evaluates to `p <=> ~q` .
Example
Evaluates to `false <=> ~q` .
|
A formula is in negation normal form (NNF) if it is constructed from literals using only the binary connectives \(\land\) and \(\lor\), or else is one of the degenerate cases \(\top\) and \(\bot\). It is analogous to the following procedure in ordinary algebra: (i) replace subtraction by its definition \(x - y = x + -y\) and then (ii) systematically push negations down using \(-(x + y) = -x + -y\), \(-(xy) = (-x)y\), \(-(-x) = x\).nnf implements a complete transformation in NNF
applying Prop.psimplify first
and then Prop.nnf_naive.
NoteNegation normal form is not a canonical form: for example, \(a \land (b \lor \lnot c)\) and \((a \land b) \lor (a \land \lnot c)\) are equivalent, and are both in negation normal form. (from https://en.wikipedia.org/wiki/Negation_normal_form) Example
Evaluates to `p` .
Example
Evaluates to `(p /\ q \/ ~p /\ ~q) /\ r /\ ~s \/ (p /\ ~q \/ ~p /\ q) /\ (~r \/ s)` .
|
|
|
A formula is in negation normal form (NNF) if it is
constructed from literals using only the binary connectives \(\land\)
and \(\lor\), or else is one of the degenerate cases \(\top\) and
\(\bot\).
Example
Evaluates to `p /\ ~false` .
|
Function or value | Description |
Full Usage:
allsatvaluations subfn v pvs
Parameters:
('a -> bool) -> bool
-
A function that given a valuation return true or false.
v : 'a -> bool
-
The default valuation for other atoms.
pvs : 'a list
-
The list of atoms on which to test all possibile valuations.
Returns: ('a -> bool) list
The list of valuations for which subfn holds on pvs .
|
![]() ![]() ![]() ![]() ![]() ![]()
A close analogue of
Prop.onallvaluations that collects
into a list the valuations for which
Example
val fm: obj
val atms: obj
val satvals: (int list -> obj -> obj)
Example
val fm: obj
val atms: obj list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map: mapping: ('T -> 'U) -> list: 'T list -> 'U list
val v: (obj -> obj)
val a: obj
Evaluates to:
|
Full Usage:
distrib s1 s2
Parameters:
'a list list
-
The first input set of set.
s2 : 'a list list
-
The second input set of set.
Returns: 'a list list
The set of the unions of first sets with the latter.
|
It is used to obtain the distributive laws of
Example
Evaluates to
[[1; 2; 3]; [1; 2; 4]; [2; 3]; [2; 4]] .
ExampleRepresenting the distributive laws:
|
|
The distributive laws are the following:
Example
Evaluates to `p /\ q \/ p /\ r` .
Example
Evaluates to `p ==> q` .
|
A formula is in disjunctive normal form (DNF) if it is an iterated disjunction of conjunctions of litterals. It is analogous to a fully expanded sum of products expression like \(x^3 + x^2 y + xy + z\) in algebra. It is not canonical since for examplep /\ ~q /\ r \/ p /\ q /\ ~r \/ p /\ q /\ r and
p /\ q \/ p /\ r are both equivalent DNF.
Example
Evaluates to
`q \/ ~p` .
Example
val fm: obj
val dnf: obj
Evaluates to true .
|
|
|
See Prop.dnf for a definition of DNF. dnf_by_truth_tables , from all valuations satisfying the formula,
generates an equivalent that is the disjunction of the conjunctions of
the atoms that in each evaluation are mapped to true or their negations
if they're mapped to false. Thus, it is based on the same semantic
process of truth-tables.
Note also that since it is based on truth-tables (or more precisely
on valuations), it generates disjunctions in which each conjunct
contains every atoms of the original formula, while other dnf functions
generate more cleaner results.
Example
|
|
|
|
|
|
As the name suggest, it is intended to be used on literals and actually is used just to define Prop.dnf_by_truth_tables
Example
Evaluates to `p /\ ~q` .
|
Full Usage:
purednf fm
Parameters:
formula<'a>
-
The input formula.
Returns: formula<'a> list list
A dnf equivalent of the input formula in a set of sets representation
with possible superfluous and subsumed disjuncts, if the input is in
NNF; otherwise a meaningless list of lists of the input itself.
|
The resulting global set represents the disjunction and the
subsets the conjunctions: e.g. the set of sets representation of
Example
Evaluates to
[[`p`; `~p`]; [`p`; `~r`]; [`q`; `r`; `~p`]; [`q`; `r`; `~r`]] .
Example
Evaluates to
[[`p ==> q`]] .
|
It is raw because:
Example
Evaluates to `(p /\ q \/ p /\ r) \/ s` .
Example
Evaluates to `p ==> q` .
Example
Evaluates to
`(p /\ ~p \/ (q /\ r) /\ ~p) \/ p /\ ~r \/ (q /\ r) /\ ~r` .
|
|
|
It exploits the list of list representation filtering out trivial complementary literals and subsumed ones (with subsumption checking, done very naively: quadratic).
Example
Evaluates to
[[`q`]; [`~p`]] .
|
Full Usage:
trivial lits
Parameters:
formula<'a> list
-
The input list of literals.
Returns: bool
true, if there are complementary literals in the input list;
otherwise false.
|
Example
Evaluates to
true .
Example
Evaluates to
false .
|
Function or value | Description |
A formula is in conjunctive normal form (CNF) if it is an iterated conjunction of disjunctions of litterals. It is analogous to a fully factorized product of sums expression like \((x + 1)(y + 2)(z + 3)\) in algebra.
Example
val fm: obj
val cnf: obj
Evaluates to
true .
|
|
|
In the cnf context the outer set represents the iterated conjunction
and the subsets the disjunctions. Thus,
Example
Evaluates to
[[`q`; `~p`]] .
Example
Evaluates to [[`p`; `~p`]] .
|
|
It exploits the list of list representation filtering out trivial complementary literals and subsumed ones.
Example
Evaluates to
[[`q`; `~p`]] .
Example
Evaluates to [[`p`; `~p`]] .
|