(* ========================================================================= *)
(* First order logic based on the language of arithmetic. *)
(* ========================================================================= *)
prioritize_num();;
(* ------------------------------------------------------------------------- *)
(* Syntax of terms. *)
(* ------------------------------------------------------------------------- *)
parse_as_infix("++",(20,"right"));;
parse_as_infix("**",(22,"right"));;
;
let term_DISTINCT = distinctness "term";;
let term_INJ = injectivity "term";;
(* ------------------------------------------------------------------------- *)
(* Syntax of formulas. *)
(* ------------------------------------------------------------------------- *)
parse_as_infix("===",(18,"right"));;
parse_as_infix("<<",(18,"right"));;
parse_as_infix("<<=",(18,"right"));;
parse_as_infix("&&",(16,"right"));;
parse_as_infix("||",(15,"right"));;
parse_as_infix("-->",(14,"right"));;
parse_as_infix("<->",(13,"right"));;
let form_INDUCT,form_RECURSION = define_type
"form = False
| True
| === term term
| << term term
| <<= term term
| Not form
| && form form
| || form form
| --> form form
| <-> form form
| !! num form
| ?? num form";
;
let form_DISTINCT = distinctness "form";;
let form_INJ = injectivity "form";;
(* ------------------------------------------------------------------------- *)
(* Semantics of terms and formulas in the standard model. *)
(* ------------------------------------------------------------------------- *)
parse_as_infix("|->",(22,"right"));;
let valmod = new_definition
`(x |-> a) (v:A->B) = \y. if y = x then a else v(y)`;;
let VALMOD = prove
(`!v x y a. ((x |-> y) v) a = if a = x then y else v(a)`,
let VALMOD_SWAP = prove
(`!v x y a b.
~(x = y) ==> ((x |-> a) ((y |-> b) v) = (y |-> b) ((x |-> a) v))`,
(* ------------------------------------------------------------------------- *)
(* Assignment. *)
(* ------------------------------------------------------------------------- *)
parse_as_infix("|=>",(22,"right"));;
let assign = new_definition
`(x |=> a) = (x |-> a) V`;;
let ASSIGN = prove
(`!x y a. (x |=> a) y = if y = x then a else V(y)`,
(* ------------------------------------------------------------------------- *)
(* Variables in a term and free variables in a formula. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Logical axioms. *)
(* ------------------------------------------------------------------------- *)
let axiom_RULES,axiom_INDUCT,axiom_CASES = new_inductive_definition
`(!p q. axiom(p --> (q --> p))) /\
(!p q r. axiom((p --> q --> r) --> (p --> q) --> (p --> r))) /\
(!p. axiom(((p --> False) --> False) --> p)) /\
(!x p q. axiom((!!x (p --> q)) --> (!!x p) --> (!!x q))) /\
(!x p. ~(x IN FV p) ==> axiom(p --> !!x p)) /\
(!x t. ~(x IN FVT t) ==> axiom(??x (V x === t))) /\
(!t. axiom(t === t)) /\
(!s t. axiom((s === t) --> (Suc s === Suc t))) /\
(!s t u v. axiom(s === t --> u === v --> s ++ u === t ++ v)) /\
(!s t u v. axiom(s === t --> u === v --> s ** u === t ** v)) /\
(!s t u v. axiom(s === t --> u === v --> s === u --> t === v)) /\
(!s t u v. axiom(s === t --> u === v --> s << u --> t << v)) /\
(!s t u v. axiom(s === t --> u === v --> s <<= u --> t <<= v)) /\
(!p q. axiom((p <-> q) --> p --> q)) /\
(!p q. axiom((p <-> q) --> q --> p)) /\
(!p q. axiom((p --> q) --> (q --> p) --> (p <-> q))) /\
axiom(True <-> (False --> False)) /\
(!p. axiom(Not p <-> (p --> False))) /\
(!p q. axiom((p && q) <-> (p --> q --> False) --> False)) /\
(!p q. axiom((p || q) <-> Not(Not p && Not q))) /\
(!x p. axiom((??x p) <-> Not(!!x (Not p))))`;;
(* ------------------------------------------------------------------------- *)
(* Deducibility from additional set of nonlogical axioms. *)
(* ------------------------------------------------------------------------- *)
parse_as_infix("|--",(11,"right"));;
let proves_RULES,proves_INDUCT,proves_CASES = new_inductive_definition
`(!p. axiom p \/ p IN A ==> A |-- p) /\
(!p q. A |-- (p --> q) /\ A |-- p ==> A |-- q) /\
(!p x. A |-- p ==> A |-- (!!x p))`;;
(* ------------------------------------------------------------------------- *)
(* Some lemmas. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Proof of soundness. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Variant variables for use in renaming substitution. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Substitution within terms. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Formula substitution --- somewhat less trivial. *)
(* ------------------------------------------------------------------------- *)
let FORMSUBST_EQ = prove
(`!p i j. (!x. x
IN FV(p) ==> (i(x) = j(x)))
==> (
formsubst i p =
formsubst j p)`,
MATCH_MP_TAC form_INDUCT THEN
REWRITE_TAC[
FV;
formsubst;
IN_UNION;
IN_DELETE] THEN
SIMP_TAC[] THEN REWRITE_TAC[
CONJ_ASSOC] THEN
GEN_REWRITE_TAC I [GSYM
CONJ_ASSOC] THEN CONJ_TAC THENL
[MESON_TAC[
TERMSUBST_EQ]; ALL_TAC] THEN
CONJ_TAC THEN MAP_EVERY X_GEN_TAC [`x:num`; `p:form`] THEN
(DISCH_TAC THEN MAP_EVERY X_GEN_TAC [`i:num->term`; `j:num->term`] THEN
DISCH_TAC THEN REWRITE_TAC[
LET_DEF;
LET_END_DEF; form_INJ] THEN
MATCH_MP_TAC(TAUT `a /\ (a ==> b) ==> a /\ b`) THEN SIMP_TAC[] THEN
CONJ_TAC THENL
[ALL_TAC;
DISCH_THEN(K ALL_TAC) THEN FIRST_ASSUM MATCH_MP_TAC THEN
REWRITE_TAC[
valmod] THEN ASM_SIMP_TAC[]] THEN
AP_THM_TAC THEN BINOP_TAC THENL
[ASM_MESON_TAC[];
AP_TERM_TAC THEN AP_TERM_TAC THEN FIRST_ASSUM MATCH_MP_TAC THEN
REWRITE_TAC[
valmod] THEN ASM_MESON_TAC[]]));;
(* ------------------------------------------------------------------------- *)
(* Quasi-substitution. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* The numeral mapping. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Closed-ness. *)
(* ------------------------------------------------------------------------- *)