Advertisement
Guest User

Untitled

a guest
Aug 7th, 2021
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 65.46 KB | None | 0 0
  1. (*this program compiles with COQ 8.9*)
  2.  
  3. (*
  4. 2021/08/06
  5.  
  6. Author: Foys
  7. If you want to contact me the address is foYER.a41v;
  8. put all letters in the string above lower case and replace the letter v in
  9. the string above by <<"arobase" gmx.fr>>
  10. *)
  11.  
  12. Section Signatures_and_arities_of_formulas_and_terms.
  13.  
  14. Record Signature :=
  15. make_sgn
  16. {
  17. Function_symbol: Type;
  18. Relation_symbol: Type;
  19. function_arity: Function_symbol -> nat;
  20. relation_arity: Relation_symbol -> nat
  21. }.
  22.  
  23. Section definitions_of_terms_predicates_and_formulas.
  24.  
  25. Variable Sg: Signature.
  26.  
  27. Section terms_and_predicates.
  28.  
  29. Variable Variable_letter:Type. (*we introduce this in order to deal with
  30. bound_variables more easily than if we had constants*)
  31.  
  32. Inductive NFO_Term: nat -> Type :=
  33. |nfo_variable_to_term: Variable_letter -> NFO_Term 0
  34. |nfo_symbol_to_term: forall (x: Function_symbol Sg), NFO_Term (function_arity Sg x)
  35. |nfo_app_term: forall n:nat, NFO_Term (S n) -> NFO_Term 0 -> NFO_Term n.
  36.  
  37. Inductive NFO_Predicate: nat -> Type :=
  38. |nfo_symbol_to_predicate: forall (x: Relation_symbol Sg),
  39. NFO_Predicate (relation_arity Sg x)
  40. |nfo_app_predicate: forall n:nat, NFO_Predicate (S n) -> NFO_Term 0 -> NFO_Predicate n.
  41.  
  42. End terms_and_predicates.
  43.  
  44. Inductive NFO_Formula: Type -> Type :=
  45. |nfof_atomic_formula: forall (context:Type) (x:NFO_Predicate context 0),
  46. NFO_Formula context
  47. |nfof_nand: forall context:Type, NFO_Formula context -> NFO_Formula context ->
  48. NFO_Formula context
  49. |nfof_forall: forall context:Type,
  50. NFO_Formula (option context) -> NFO_Formula context.
  51.  
  52. (*Bound variables are dealt with the "locally nameless convention",which is a variant
  53. of De Bruijn indices, using the coq option operator. we start with a given context
  54. and the variables added to it can be viewed as numbers.*)
  55.  
  56. Section definition_of_the_other_logical_connectors.
  57.  
  58. Definition nfof_not (C:Type) (x:NFO_Formula C):NFO_Formula C:=
  59. nfof_nand C x x.
  60.  
  61. Definition nfof_implies (C:Type) (x y:NFO_Formula C):NFO_Formula C:=
  62. nfof_nand C x (nfof_not C y).
  63.  
  64. Definition nfof_and (C:Type) (x y:NFO_Formula C):NFO_Formula C:=
  65. nfof_not C (nfof_nand C x y).
  66.  
  67. Definition nfof_or (C:Type) (x y:NFO_Formula C):NFO_Formula C:=
  68. nfof_nand C (nfof_not C x) (nfof_not C y).
  69.  
  70. Definition nfof_equiv (C:Type) (x y:NFO_Formula C):NFO_Formula C:=
  71. nfof_and C (nfof_implies C x y) (nfof_implies C y x).
  72.  
  73. Definition nfof_exists (C:Type) (f:NFO_Formula (option C)):NFO_Formula C:=
  74. nfof_not C (nfof_forall C (nfof_not (option C) f)).
  75.  
  76. (*attempting to optimize these definitions is pointless; the very fact we use nand
  77. as a primary connector causes unfixable complexity issues and programs executed
  78. with the classes we define will probably make your computer crash. The purpose of
  79. first order logic as we define it is to explore its theoretical properties and
  80. prove mathematical theorems and in order to do this it is better to have the
  81. smallest number of items in inductive definitions, so that the proof is shorter.*)
  82.  
  83. End definition_of_the_other_logical_connectors.
  84.  
  85. Section definition_of_substitution_of_variables_in_terms_and_atomic_formulas.
  86.  
  87. Variables C D:Type.
  88. Variable environment: C -> NFO_Term D 0.
  89.  
  90. Fixpoint nfo_term_substitution (n:nat) (x:NFO_Term C n) {struct x}:NFO_Term D n :=
  91. match x in (NFO_Term _ n0) return (NFO_Term D n0) with
  92. | nfo_variable_to_term _ c => environment c
  93. | nfo_symbol_to_term _ x0 => nfo_symbol_to_term D x0
  94. | nfo_app_term _ n0 x1 x2 =>
  95. nfo_app_term D n0 (nfo_term_substitution (S n0) x1) (nfo_term_substitution 0 x2)
  96. end.
  97.  
  98. Fixpoint nfo_predicate_substitution (n:nat) (x:NFO_Predicate C n) {struct x}:
  99. NFO_Predicate D n :=
  100. match x in (NFO_Predicate _ n0) return (NFO_Predicate D n0) with
  101. | nfo_symbol_to_predicate _ x0 => nfo_symbol_to_predicate D x0
  102. | nfo_app_predicate _ n0 x1 x2 =>
  103. nfo_app_predicate D n0 (nfo_predicate_substitution (S n0) x1)
  104. (nfo_term_substitution 0 x2)
  105. end.
  106.  
  107. End definition_of_substitution_of_variables_in_terms_and_atomic_formulas.
  108.  
  109. Definition change_of_variable_in_terms (C D:Type) (ve: C -> D):=
  110. nfo_term_substitution C D (fun x:C => nfo_variable_to_term D (ve x)).
  111.  
  112. Definition constant_nfo_term_embedding
  113. (C:Type):(forall n:nat, NFO_Term C n -> NFO_Term (option C) n):=
  114. change_of_variable_in_terms C (option C) (Some).
  115.  
  116. Definition change_of_variable_in_predicates (C D:Type) (ve: C -> D):=
  117. nfo_predicate_substitution C D (fun x:C => nfo_variable_to_term D (ve x)).
  118.  
  119. Definition constant_nfo_predicate_embedding
  120. (C:Type):(forall n:nat, NFO_Predicate C n -> NFO_Predicate (option C) n):=
  121. change_of_variable_in_predicates C (option C) (Some).
  122.  
  123. Definition add_var_to_environment (C D:Type)(env: C -> NFO_Term D 0):
  124. option C -> NFO_Term (option D) 0:=
  125. option_rect (fun _:option C => NFO_Term (option D) 0)
  126. (fun y:C => change_of_variable_in_terms D (option D) Some 0 (env y))
  127. (nfo_variable_to_term (option D) (None)).
  128.  
  129. Fixpoint nfo_formula_substitution
  130. (C D:Type)
  131. (environment: C -> NFO_Term D 0)
  132. (f: NFO_Formula C)
  133. {struct f}:NFO_Formula D:=
  134. match f in (NFO_Formula T) return ((T -> NFO_Term D 0) -> NFO_Formula D) with
  135. | nfof_atomic_formula context x =>
  136. fun environment0 : context -> NFO_Term D 0 =>
  137. nfof_atomic_formula D (nfo_predicate_substitution context D environment0 0 x)
  138. | nfof_nand context f1 f2 =>
  139. fun environment0 : context -> NFO_Term D 0 =>
  140. nfof_nand D (nfo_formula_substitution context D environment0 f1)
  141. (nfo_formula_substitution context D environment0 f2)
  142. | nfof_forall context f0 =>
  143. fun environment0 : context -> NFO_Term D 0 =>
  144. nfof_forall D
  145. (nfo_formula_substitution
  146. (option context) (option D)
  147. (add_var_to_environment context D environment0) f0)
  148. end environment.
  149.  
  150. Definition change_of_variable_in_formulas (C D:Type) (ve: C -> D):=
  151. nfo_formula_substitution C D (fun x:C => nfo_variable_to_term D (ve x)).
  152.  
  153. Definition constant_nfo_formula_embedding
  154. (C:Type):NFO_Formula C -> NFO_Formula (option C):=
  155. change_of_variable_in_formulas C (option C) (Some).
  156.  
  157. Definition assign_term_to_var (C:Type)(t: NFO_Term C 0):
  158. option C -> NFO_Term C 0:=
  159. option_rect (fun _:option C => NFO_Term C 0)
  160. (nfo_variable_to_term C)
  161. t.
  162.  
  163. Definition nfo_term_specialization (C:Type) (t: NFO_Term C 0):=
  164. nfo_term_substitution (option C) C (assign_term_to_var C t).
  165.  
  166. Definition nfo_predicate_specialization (C:Type) (t: NFO_Term C 0):=
  167. nfo_predicate_substitution (option C) C (assign_term_to_var C t).
  168.  
  169. Definition nfo_formula_specialization (C:Type) (t: NFO_Term C 0):=
  170. nfo_formula_substitution (option C) C (assign_term_to_var C t).
  171.  
  172. Theorem nfo_term_substitution_transitivity:
  173. forall (C D E:Type)
  174. (env_cd: C -> NFO_Term D 0)
  175. (env_de: D -> NFO_Term E 0)
  176. (n:nat)
  177. (t: NFO_Term C n),
  178. nfo_term_substitution D E env_de n (nfo_term_substitution C D env_cd n t)=
  179. nfo_term_substitution
  180. C E
  181. (fun a:C => nfo_term_substitution D E env_de 0 (env_cd a))
  182. n t.
  183. Proof.
  184. induction t.
  185. simpl.
  186. reflexivity.
  187. simpl.
  188. reflexivity.
  189. simpl.
  190. rewrite IHt1.
  191. rewrite IHt2.
  192. reflexivity.
  193. Defined.
  194.  
  195. Theorem nfo_term_extensional_equality:
  196. forall (C D:Type)
  197. (env1 env2: C -> NFO_Term D 0),
  198. (forall c:C, env1 c = env2 c) ->
  199. forall (n:nat) (t: NFO_Term C n),
  200. nfo_term_substitution C D env1 n t =
  201. nfo_term_substitution C D env2 n t.
  202. Proof.
  203. intros C D env1 env2 eqenv.
  204. induction t.
  205. simpl.
  206. apply eqenv.
  207. simpl.
  208. reflexivity.
  209. simpl.
  210. rewrite IHt1.
  211. rewrite IHt2.
  212. reflexivity.
  213. Defined.
  214.  
  215. Theorem nfo_predicate_substitution_transitivity:
  216. forall (C D E:Type)
  217. (env_cd: C -> NFO_Term D 0)
  218. (env_de: D -> NFO_Term E 0)
  219. (n:nat)
  220. (p: NFO_Predicate C n),
  221. nfo_predicate_substitution D E env_de n (nfo_predicate_substitution C D env_cd n p)=
  222. nfo_predicate_substitution
  223. C E
  224. (fun a:C => nfo_term_substitution D E env_de 0 (env_cd a))
  225. n p.
  226. Proof.
  227. induction p.
  228. simpl.
  229. reflexivity.
  230. simpl.
  231. rewrite IHp.
  232. rewrite nfo_term_substitution_transitivity.
  233. reflexivity.
  234. Defined.
  235.  
  236. Theorem nfo_predicate_extensional_equality:
  237. forall (C D:Type)
  238. (env1 env2: C -> NFO_Term D 0),
  239. (forall c:C, env1 c = env2 c) ->
  240. forall (n:nat) (p: NFO_Predicate C n),
  241. nfo_predicate_substitution C D env1 n p =
  242. nfo_predicate_substitution C D env2 n p.
  243. Proof.
  244. intros C D env1 env2 eqenv.
  245. induction p.
  246. simpl.
  247. reflexivity.
  248. simpl.
  249. rewrite IHp.
  250. rewrite nfo_term_extensional_equality with (env2 := env2).
  251. reflexivity.
  252. assumption.
  253. Defined.
  254.  
  255. Theorem nfo_formula_extensional_equality:
  256. forall (C:Type) (f:NFO_Formula C)
  257. (D:Type) (env1 env2: C -> NFO_Term D 0) (eqenv: forall c:C, env1 c = env2 c),
  258. nfo_formula_substitution C D env1 f =
  259. nfo_formula_substitution C D env2 f.
  260. Proof.
  261. intros C.
  262. induction f.
  263. intros.
  264. simpl.
  265. apply f_equal.
  266. apply nfo_predicate_extensional_equality.
  267. assumption.
  268. intros.
  269. simpl.
  270. apply f_equal2.
  271. apply IHf1.
  272. assumption.
  273. apply IHf2.
  274. assumption.
  275. intros.
  276. simpl.
  277. apply f_equal.
  278. apply IHf.
  279. intros.
  280. destruct c.
  281. simpl.
  282. apply f_equal.
  283. apply eqenv.
  284. reflexivity.
  285. Defined.
  286.  
  287. Theorem nfo_formula_substitution_transitivity:
  288. forall (C:Type)(f:NFO_Formula C) (D E:Type)
  289. (env_cd: C -> NFO_Term D 0)
  290. (env_de: D -> NFO_Term E 0),
  291. nfo_formula_substitution D E env_de (nfo_formula_substitution C D env_cd f)=
  292. nfo_formula_substitution
  293. C E
  294. (fun a:C => nfo_term_substitution D E env_de 0 (env_cd a))
  295. f.
  296. Proof.
  297. induction f.
  298. intros.
  299. simpl.
  300. apply f_equal.
  301. apply nfo_predicate_substitution_transitivity.
  302. intros.
  303. simpl.
  304. apply f_equal2.
  305. apply IHf1.
  306. apply IHf2.
  307. intros.
  308. simpl.
  309. apply f_equal.
  310. rewrite IHf.
  311. apply nfo_formula_extensional_equality.
  312. intros.
  313. destruct c.
  314. simpl.
  315. unfold change_of_variable_in_terms.
  316. rewrite nfo_term_substitution_transitivity.
  317. rewrite nfo_term_substitution_transitivity.
  318. reflexivity.
  319. simpl.
  320. reflexivity.
  321. Defined.
  322.  
  323. Theorem nfo_term_identity_substitution:
  324. forall (C:Type)(n:nat)(t:NFO_Term C n),
  325. nfo_term_substitution C C (fun x:C => nfo_variable_to_term C x) n t = t.
  326. Proof.
  327. induction t.
  328. simpl.
  329. reflexivity.
  330. simpl.
  331. reflexivity.
  332. simpl.
  333. rewrite IHt1.
  334. rewrite IHt2.
  335. reflexivity.
  336. Defined.
  337.  
  338. Theorem nfo_predicate_identity_substitution:
  339. forall (C:Type)(n:nat)(p:NFO_Predicate C n),
  340. nfo_predicate_substitution C C (fun x:C => nfo_variable_to_term C x) n p = p.
  341. Proof.
  342. induction p.
  343. simpl.
  344. reflexivity.
  345. simpl.
  346. rewrite IHp.
  347. rewrite nfo_term_identity_substitution.
  348. reflexivity.
  349. Defined.
  350.  
  351. Theorem nfo_formula_identity_substitution:
  352. forall (C:Type)(f:NFO_Formula C),
  353. nfo_formula_substitution C C (fun x:C => nfo_variable_to_term C x) f = f.
  354. Proof.
  355. induction f.
  356. simpl.
  357. rewrite nfo_predicate_identity_substitution.
  358. reflexivity.
  359. simpl.
  360. rewrite IHf1.
  361. rewrite IHf2.
  362. reflexivity.
  363. simpl.
  364. rewrite nfo_formula_extensional_equality with
  365. (C:= option context)
  366. (env2 := fun (x:option context) =>
  367. nfo_variable_to_term (option context) x).
  368. rewrite IHf.
  369. reflexivity.
  370. intros.
  371. destruct c.
  372. simpl.
  373. reflexivity.
  374. simpl.
  375. reflexivity.
  376. Defined.
  377.  
  378. Section specialization_on_constant_terms.
  379.  
  380. Variable C:Type.
  381. Variable X: NFO_Term C 0.
  382.  
  383. Theorem specialization_doesnt_change_constant_terms:
  384. forall (n:nat) (t:NFO_Term C n),
  385. nfo_term_specialization C X n (constant_nfo_term_embedding C n t) = t.
  386. Proof.
  387. intros.
  388. apply eq_trans with
  389. (y:=nfo_term_substitution C C (fun u:C => nfo_variable_to_term C u) n t).
  390. unfold nfo_term_specialization.
  391. unfold constant_nfo_term_embedding.
  392. unfold change_of_variable_in_terms.
  393. rewrite nfo_term_substitution_transitivity.
  394. apply nfo_term_extensional_equality.
  395. intros.
  396. simpl.
  397. reflexivity.
  398. apply nfo_term_identity_substitution.
  399. Defined.
  400.  
  401. Theorem specialization_doesnt_change_constant_predicates:
  402. forall (n:nat) (p:NFO_Predicate C n),
  403. nfo_predicate_specialization C X n (constant_nfo_predicate_embedding C n p) = p.
  404. Proof.
  405. intros.
  406. apply eq_trans with
  407. (y:=nfo_predicate_substitution C C (fun u:C => nfo_variable_to_term C u) n p).
  408. unfold nfo_predicate_specialization.
  409. unfold constant_nfo_predicate_embedding.
  410. unfold change_of_variable_in_predicates.
  411. rewrite nfo_predicate_substitution_transitivity.
  412. apply nfo_predicate_extensional_equality.
  413. intros.
  414. simpl.
  415. reflexivity.
  416. apply nfo_predicate_identity_substitution.
  417. Defined.
  418.  
  419. Theorem specialization_doesnt_change_constant_formulas:
  420. forall (f:NFO_Formula C),
  421. nfo_formula_specialization C X (constant_nfo_formula_embedding C f) = f.
  422. Proof.
  423. intros.
  424. apply eq_trans with
  425. (y:=nfo_formula_substitution C C (fun u:C => nfo_variable_to_term C u) f).
  426. unfold nfo_formula_specialization.
  427. unfold constant_nfo_formula_embedding.
  428. unfold change_of_variable_in_formulas.
  429. rewrite nfo_formula_substitution_transitivity.
  430. apply nfo_formula_extensional_equality.
  431. intros.
  432. simpl.
  433. reflexivity.
  434. apply nfo_formula_identity_substitution.
  435. Defined.
  436.  
  437. End specialization_on_constant_terms.
  438.  
  439. Section double_substitution_lemmas.
  440.  
  441. Variable C:Type.
  442. Variable X: NFO_Term C 0.
  443. Variable Y: NFO_Term (option C) 0.
  444.  
  445. Definition first_var_assign
  446. (a:option (option C)):NFO_Term (option C) 0:=
  447. match a with
  448. |None => nfo_variable_to_term (option C) (None)
  449. |Some b => match b with
  450. |None => constant_nfo_term_embedding C 0 X
  451. |Some c => nfo_variable_to_term (option C) (Some c)
  452. end
  453. end.
  454.  
  455. Lemma double_substitution_for_variables:
  456. forall (c:option (option C)),
  457. nfo_term_substitution (option C) C (assign_term_to_var C X) 0
  458. (assign_term_to_var (option C) Y c) =
  459. nfo_term_substitution
  460. (option C) C
  461. (assign_term_to_var
  462. C
  463. (nfo_term_substitution (option C) C (assign_term_to_var C X) 0 Y)) 0
  464. (first_var_assign c).
  465. Proof.
  466. destruct c.
  467. destruct o.
  468. simpl.
  469. reflexivity.
  470. simpl.
  471. unfold constant_nfo_term_embedding.
  472. unfold change_of_variable_in_terms.
  473. rewrite nfo_term_substitution_transitivity.
  474. apply eq_trans with
  475. (y:= nfo_term_substitution C C (fun u:C => nfo_variable_to_term C u) 0 X).
  476. apply eq_sym.
  477. apply nfo_term_identity_substitution.
  478. apply nfo_term_extensional_equality.
  479. intros.
  480. simpl.
  481. reflexivity.
  482. reflexivity.
  483. Defined.
  484.  
  485. Theorem double_substitution_for_terms:
  486. forall (n:nat) (t:NFO_Term (option (option C)) n),
  487. nfo_term_specialization
  488. C X n
  489. (nfo_term_specialization (option C) Y n t) =
  490. nfo_term_specialization
  491. C (nfo_term_specialization C X 0 Y) n
  492. (nfo_term_substitution
  493. (option (option C)) (option C) first_var_assign n t).
  494. Proof.
  495. intros.
  496. unfold nfo_term_specialization.
  497. rewrite nfo_term_substitution_transitivity.
  498. rewrite nfo_term_substitution_transitivity.
  499. apply nfo_term_extensional_equality.
  500. apply double_substitution_for_variables.
  501. Defined.
  502.  
  503. Theorem double_substitution_for_predicates:
  504. forall (n:nat) (t:NFO_Predicate (option (option C)) n),
  505. nfo_predicate_specialization
  506. C X n
  507. (nfo_predicate_specialization (option C) Y n t) =
  508. nfo_predicate_specialization
  509. C (nfo_term_specialization C X 0 Y) n
  510. (nfo_predicate_substitution
  511. (option (option C)) (option C) first_var_assign n t).
  512. Proof.
  513. intros.
  514. unfold nfo_predicate_specialization.
  515. rewrite nfo_predicate_substitution_transitivity.
  516. rewrite nfo_predicate_substitution_transitivity.
  517. apply nfo_predicate_extensional_equality.
  518. apply double_substitution_for_variables.
  519. Defined.
  520.  
  521. Theorem double_substitution_for_formulas:
  522. forall (t:NFO_Formula (option (option C))),
  523. nfo_formula_specialization
  524. C X
  525. (nfo_formula_specialization (option C) Y t) =
  526. nfo_formula_specialization
  527. C (nfo_term_specialization C X 0 Y)
  528. (nfo_formula_substitution
  529. (option (option C)) (option C) first_var_assign t).
  530. Proof.
  531. intros.
  532. unfold nfo_formula_specialization.
  533. rewrite nfo_formula_substitution_transitivity.
  534. rewrite nfo_formula_substitution_transitivity.
  535. apply nfo_formula_extensional_equality.
  536. apply double_substitution_for_variables.
  537. Defined.
  538.  
  539. End double_substitution_lemmas.
  540.  
  541. Section Proof_theory.
  542.  
  543. Section adding_an_hypothesis_to_a_set_of_sentences.
  544.  
  545. Variable context:Type.
  546. Variable T: (NFO_Formula context) -> Type.
  547. Variable h: NFO_Formula context.
  548.  
  549. Inductive add_hypothesis:(NFO_Formula context) -> Type :=
  550. |new_hyp: add_hypothesis h
  551. |base_hyp: forall (f:NFO_Formula context),T f -> add_hypothesis f.
  552.  
  553. End adding_an_hypothesis_to_a_set_of_sentences.
  554.  
  555. Definition add_hyp_subtheory
  556. (C:Type) (h:NFO_Formula C) (T U:NFO_Formula C -> Type)
  557. (st: forall p:NFO_Formula C, T p -> U p) (f:NFO_Formula C)
  558. (a: add_hypothesis C T h f): add_hypothesis C U h f:=
  559. match a in (add_hypothesis _ _ _ f0) return (add_hypothesis C U h f0) with
  560. | new_hyp _ _ _ => new_hyp C U h
  561. | base_hyp _ _ _ f0 t => base_hyp C U h f0 (st f0 t)
  562. end.
  563.  
  564. Section morphisms_of_theories.
  565.  
  566. Variable C D:Type.
  567. Variable environment: C -> NFO_Term D 0.
  568. Variable theory: NFO_Formula C -> Type.
  569.  
  570. Inductive nfo_theory_substitution: NFO_Formula D -> Type:=
  571. |fots_intro: forall f:NFO_Formula C,
  572. theory f -> nfo_theory_substitution
  573. (nfo_formula_substitution C D environment f).
  574.  
  575. End morphisms_of_theories.
  576.  
  577. Definition substitution_subtheory
  578. (C D:Type) (env: C -> NFO_Term D 0) (T U:NFO_Formula C -> Type)
  579. (st: forall p:NFO_Formula C, T p -> U p) (f:NFO_Formula D)
  580. (a: nfo_theory_substitution C D env T f):
  581. nfo_theory_substitution C D env U f.
  582. Proof.
  583. intros.
  584. destruct a.
  585. apply fots_intro.
  586. apply st.
  587. assumption.
  588. Defined.
  589.  
  590. Definition change_of_variable_in_theories (C D:Type) (ve: C -> D):=
  591. nfo_theory_substitution C D (fun x:C => nfo_variable_to_term D (ve x)).
  592.  
  593. Definition constant_nfo_theory_embedding
  594. (C:Type):(NFO_Formula C -> Type) -> (NFO_Formula (option C) -> Type):=
  595. change_of_variable_in_theories C (option C) (Some).
  596.  
  597. Section characterization_of_the_constant_embedding_of_a_theory.
  598.  
  599. Variable context:Type.
  600. Variable theory: NFO_Formula context -> Type.
  601.  
  602. Inductive constant_nfo_theory_embedding_alternative:
  603. NFO_Formula (option context) -> Type:=
  604. |cfotea_intro: forall f:NFO_Formula context,
  605. theory f ->
  606. constant_nfo_theory_embedding_alternative
  607. (constant_nfo_formula_embedding context f).
  608.  
  609. Theorem constant_nfo_theory_embedding_check:
  610. forall f:NFO_Formula (option context),
  611. prod (constant_nfo_theory_embedding
  612. context theory f ->
  613. constant_nfo_theory_embedding_alternative f)
  614. (constant_nfo_theory_embedding_alternative f ->
  615. constant_nfo_theory_embedding
  616. context theory f).
  617. Proof.
  618. intros.
  619. split.
  620. intro.
  621. destruct X.
  622. apply cfotea_intro.
  623. assumption.
  624. intro.
  625. destruct X.
  626. unfold constant_nfo_theory_embedding.
  627. unfold change_of_variable_in_theories.
  628. apply fots_intro.
  629. assumption.
  630. Defined.
  631.  
  632. End characterization_of_the_constant_embedding_of_a_theory.
  633.  
  634. Section natural_deduction.
  635.  
  636. Inductive nand_natural_deduction:
  637. forall (C:Type) (hyp: NFO_Formula C -> Type), NFO_Formula C -> Type:=
  638. |nnd_ax: forall (C:Type) (hyp: NFO_Formula C -> Type) (f:NFO_Formula C),
  639. hyp f -> nand_natural_deduction C hyp f
  640. |nnd_nand_intro:
  641. forall (C:Type) (hyp: NFO_Formula C -> Type) (a b p q:NFO_Formula C),
  642. nand_natural_deduction C (add_hypothesis C (add_hypothesis C hyp a) b) p ->
  643. nand_natural_deduction C (add_hypothesis C (add_hypothesis C hyp a) b) q ->
  644. nand_natural_deduction C (add_hypothesis C (add_hypothesis C hyp a) b)
  645. (nfof_nand C p q) ->
  646. nand_natural_deduction C hyp (nfof_nand C a b)
  647. |nnd_nand_elim: forall (C:Type) (hyp: NFO_Formula C -> Type) (x y z:NFO_Formula C),
  648. nand_natural_deduction C hyp (nfof_nand C x (nfof_nand C y z)) ->
  649. nand_natural_deduction C hyp x ->
  650. nand_natural_deduction C hyp z
  651. |nnd_forall_intro: forall (C:Type) (hyp: NFO_Formula C -> Type)
  652. (f:NFO_Formula (option C)),
  653. nand_natural_deduction
  654. (option C) (constant_nfo_theory_embedding C hyp) f ->
  655. nand_natural_deduction C hyp (nfof_forall C f)
  656. |nnd_forall_elim: forall (C:Type) (hyp: NFO_Formula C -> Type)
  657. (f:NFO_Formula (option C))
  658. (t:NFO_Term C 0),
  659. nand_natural_deduction
  660. C hyp (nfof_forall C f) ->
  661. nand_natural_deduction
  662. C hyp (nfo_formula_specialization C t f).
  663.  
  664. Fixpoint nnd_general_weakening
  665. (C:Type)
  666. (T: NFO_Formula C -> Type)
  667. (f:NFO_Formula C)
  668. (U:NFO_Formula C -> Type)
  669. (st: forall p:NFO_Formula C, T p -> U p)
  670. (pr: nand_natural_deduction C T f)
  671. {struct pr}:nand_natural_deduction C U f.
  672. Proof.
  673. destruct pr.
  674. apply nnd_ax.
  675. apply st; assumption.
  676. apply nnd_nand_intro with (p:=p) (q:=q).
  677. apply nnd_general_weakening with (T:= add_hypothesis C (add_hypothesis C hyp a) b).
  678. apply add_hyp_subtheory; apply add_hyp_subtheory; assumption.
  679. assumption.
  680. apply nnd_general_weakening with (T:= add_hypothesis C (add_hypothesis C hyp a) b).
  681. apply add_hyp_subtheory; apply add_hyp_subtheory; assumption.
  682. assumption.
  683. apply nnd_general_weakening with (T:= add_hypothesis C (add_hypothesis C hyp a) b).
  684. apply add_hyp_subtheory; apply add_hyp_subtheory; assumption.
  685. assumption.
  686. apply nnd_nand_elim with (x:=x) (y:=y).
  687. apply nnd_general_weakening with (T:= hyp); assumption.
  688. apply nnd_general_weakening with (T:= hyp); assumption.
  689. apply nnd_forall_intro.
  690. apply nnd_general_weakening with (T:= constant_nfo_theory_embedding C hyp).
  691. apply substitution_subtheory.
  692. assumption.
  693. assumption.
  694. apply nnd_forall_elim.
  695. apply nnd_general_weakening with (T:=hyp).
  696. assumption.
  697. assumption.
  698. Defined.
  699.  
  700. Definition nnd_hypothesis_weakening
  701. (C:Type)
  702. (T: NFO_Formula C -> Type)
  703. (h f:NFO_Formula C)
  704. (pr: nand_natural_deduction C T f):
  705. (nand_natural_deduction C (add_hypothesis C T h) f):=
  706. nnd_general_weakening C T f (add_hypothesis C T h)
  707. (base_hyp C T h) pr.
  708.  
  709. Fixpoint nfo_nnd_substitution
  710. (C:Type) (T: NFO_Formula C -> Type) (f:NFO_Formula C)
  711. (pr: nand_natural_deduction C T f)
  712. (D:Type) (env: C -> NFO_Term D 0) {struct pr}:
  713. nand_natural_deduction
  714. D (nfo_theory_substitution C D env T) (nfo_formula_substitution C D env f).
  715. Proof.
  716. destruct pr.
  717. apply nnd_ax.
  718. apply fots_intro.
  719. assumption.
  720. simpl.
  721. apply nnd_nand_intro with
  722. (p:=nfo_formula_substitution C D env p)
  723. (q:=nfo_formula_substitution C D env q).
  724. apply nnd_general_weakening with
  725. (T:= nfo_theory_substitution C D env
  726. (add_hypothesis C (add_hypothesis C hyp a) b)).
  727. intros.
  728. destruct X.
  729. destruct a0.
  730. apply new_hyp.
  731. apply base_hyp.
  732. destruct a0.
  733. apply new_hyp.
  734. apply base_hyp.
  735. apply fots_intro.
  736. assumption.
  737. apply nfo_nnd_substitution.
  738. assumption.
  739. apply nnd_general_weakening with
  740. (T:= nfo_theory_substitution C D env
  741. (add_hypothesis C (add_hypothesis C hyp a) b)).
  742. intros.
  743. destruct X.
  744. destruct a0.
  745. apply new_hyp.
  746. apply base_hyp.
  747. destruct a0.
  748. apply new_hyp.
  749. apply base_hyp.
  750. apply fots_intro.
  751. assumption.
  752. apply nfo_nnd_substitution.
  753. assumption.
  754. apply nnd_general_weakening with
  755. (T:= nfo_theory_substitution C D env
  756. (add_hypothesis C (add_hypothesis C hyp a) b)).
  757. intros.
  758. destruct X.
  759. destruct a0.
  760. apply new_hyp.
  761. apply base_hyp.
  762. destruct a0.
  763. apply new_hyp.
  764. apply base_hyp.
  765. apply fots_intro.
  766. assumption.
  767. apply nfo_nnd_substitution with (D:=D) (env:=env) in pr3.
  768. simpl in pr3.
  769. assumption.
  770. apply nnd_nand_elim with
  771. (x:= nfo_formula_substitution C D env x)
  772. (y:= nfo_formula_substitution C D env y).
  773. apply nfo_nnd_substitution with (D:=D) (env:=env) in pr1.
  774. assumption.
  775. apply nfo_nnd_substitution.
  776. assumption.
  777. apply nnd_forall_intro.
  778. apply nnd_general_weakening with
  779. (T:= nfo_theory_substitution
  780. (option C)
  781. (option D)
  782. (add_var_to_environment C D env)
  783. (constant_nfo_theory_embedding C hyp)).
  784. intros.
  785. unfold constant_nfo_theory_embedding.
  786. destruct X.
  787. unfold change_of_variable_in_theories.
  788. unfold constant_nfo_theory_embedding in c.
  789. unfold change_of_variable_in_theories in c.
  790. destruct c.
  791. simpl.
  792. rewrite nfo_formula_substitution_transitivity.
  793. rewrite nfo_formula_extensional_equality
  794. with (C:=C) (D:= option D)
  795. (env2:= fun v:C =>
  796. nfo_term_substitution
  797. D (option D)
  798. (fun t:D => nfo_variable_to_term (option D) (Some t))
  799. 0
  800. (env v)
  801. ).
  802. rewrite <- nfo_formula_substitution_transitivity.
  803. apply fots_intro.
  804. apply fots_intro.
  805. assumption.
  806. intros.
  807. simpl.
  808. unfold change_of_variable_in_terms.
  809. reflexivity.
  810. apply nfo_nnd_substitution.
  811. assumption.
  812. apply nfo_nnd_substitution with (D:=D) (env := env) in pr.
  813. simpl in pr.
  814. apply nnd_forall_elim with (t:= nfo_term_substitution C D env 0 t) in pr.
  815. unfold nfo_formula_specialization in pr.
  816. unfold nfo_formula_specialization.
  817. rewrite nfo_formula_substitution_transitivity.
  818. rewrite nfo_formula_extensional_equality with
  819. (env2 := fun (v: option C) =>
  820. nfo_term_substitution
  821. (option D) D
  822. (assign_term_to_var D (nfo_term_substitution C D env 0 t))
  823. 0
  824. (nfo_term_substitution (option C) (option D)
  825. (add_var_to_environment C D env)
  826. 0
  827. (nfo_variable_to_term (option C) v))
  828. ).
  829. rewrite nfo_formula_substitution_transitivity in pr.
  830. assumption.
  831. intros c.
  832. destruct c.
  833. simpl.
  834. unfold change_of_variable_in_terms.
  835. rewrite nfo_term_substitution_transitivity.
  836. simpl.
  837. rewrite nfo_term_identity_substitution.
  838. reflexivity.
  839. simpl.
  840. reflexivity.
  841. Defined.
  842.  
  843. Section ND_proofs_of_some_usual_inference_rules.
  844.  
  845. Section classical_inference_rules_for_propositional_connectors.
  846.  
  847. Variable C:Type.
  848. Variable T: NFO_Formula C -> Type.
  849.  
  850. Notation D:= (nfof_nand C).
  851.  
  852. Notation "G |- F":= (nand_natural_deduction C G F) (at level 61).
  853. Notation P:= (NFO_Formula C).
  854.  
  855. Ltac ni v w := apply nnd_nand_intro with (p:=v) (q:=w).
  856. Ltac ne p q:= apply nnd_nand_elim with (x:=p) (y:=q).
  857. Ltac ax := apply nnd_ax.
  858. Ltac nh := apply new_hyp.
  859. Ltac bh := apply base_hyp.
  860. Ltac wh := apply nnd_hypothesis_weakening.
  861. Ltac ap := assumption.
  862.  
  863. Definition nnd_nand_symmetry:
  864. forall (U:P -> Type) (p q:P), U |- D p q -> U |- D q p.
  865. Proof.
  866. intros.
  867. ni p q.
  868. ax; nh.
  869. ax; bh; nh.
  870. wh; wh; ap.
  871. Defined.
  872.  
  873. Ltac ns := apply nnd_nand_symmetry.
  874.  
  875. Definition nnd_nand_elim_2:
  876. forall (U:P -> Type) (x y z:P), U |- D x (D y z) -> U |- x -> U |- y.
  877. Proof.
  878. intros.
  879. ne x z.
  880. ni x (D y z).
  881. wh; wh; ap.
  882. ns; ax; nh.
  883. wh; wh; ap.
  884. ap.
  885. Defined.
  886.  
  887. Ltac ne2 m n:= apply nnd_nand_elim_2 with (x:=m) (z:=n).
  888.  
  889. Definition nnd_explosion:
  890. forall (U:P -> Type)(x y z:P),
  891. (U |- x) ->
  892. (U |- y) ->
  893. (U |- D x y) ->
  894. (U |- z).
  895. Proof.
  896. intros.
  897. ne x z.
  898. ni x y.
  899. wh; wh; ap.
  900. wh; wh; ap.
  901. wh; wh; ap.
  902. ap.
  903. Defined.
  904.  
  905. Ltac nex m n := apply nnd_explosion with (x:=m) (y:=n).
  906.  
  907. Definition nnd_non_contradiction:
  908. forall (U:P -> Type)(x:P),
  909. U|- D x (D x x).
  910. Proof.
  911. intros.
  912. ni x x.
  913. ax; bh; nh.
  914. ax; bh; nh.
  915. ax; nh.
  916. Defined.
  917.  
  918. Ltac nc := apply nnd_non_contradiction.
  919.  
  920. Definition nnd_double_implies_intro:
  921. forall (U:P -> Type)(x y z:P),
  922. ((add_hypothesis C U x) |- y) ->
  923. ((add_hypothesis C U x) |- z) ->
  924. U |- D x (D y z).
  925. Proof.
  926. intros.
  927. ni y z.
  928. wh; ap.
  929. wh; ap.
  930. ax; nh.
  931. Defined.
  932.  
  933. Ltac ndii := apply nnd_double_implies_intro.
  934.  
  935. Definition nnd_nand_cases:
  936. forall (U:P -> Type)(x y z:P),
  937. ((add_hypothesis C (add_hypothesis C U x) y)|- z) ->
  938. ((add_hypothesis C U (D x y)) |- z) ->
  939. (U |- z).
  940. Proof.
  941. intros.
  942. ne (D (D z z) (D x y)) z.
  943. ns.
  944. ni x y.
  945. ne2 (D z z) y.
  946. ax; nh.
  947. ax; bh; nh.
  948. ne (D z z) x.
  949. ax; nh.
  950. ax; bh; nh.
  951. wh.
  952. ni z z.
  953. apply nnd_general_weakening with (T:= add_hypothesis C (add_hypothesis C U x) y).
  954. intros.
  955. destruct X1.
  956. nh.
  957. destruct a.
  958. bh; nh.
  959. bh; bh; bh; ap.
  960. ap.
  961. apply nnd_general_weakening with (T:= add_hypothesis C (add_hypothesis C U x) y).
  962. intros.
  963. destruct X1.
  964. nh.
  965. destruct a.
  966. bh; nh.
  967. bh; bh; bh; ap.
  968. ap.
  969. ax; bh; bh; nh.
  970. ns; ni z z.
  971. wh; ap.
  972. wh; ap.
  973. ax; nh.
  974. Defined.
  975.  
  976. Definition nnd_implies_intro:
  977. forall (U:P -> Type)(x y:P),
  978. (add_hypothesis C U x) |- y -> U |- nfof_implies C x y.
  979. Proof.
  980. intros.
  981. ni y y.
  982. wh; ap.
  983. wh; ap.
  984. ax; nh.
  985. Defined.
  986.  
  987. Definition nnd_implies_elim:
  988. forall (U:P -> Type)(x y:P),
  989. (U |- nfof_implies C x y) ->
  990. (U |- x) ->
  991. (U |- y).
  992. Proof.
  993. intros.
  994. ne x y.
  995. ap.
  996. ap.
  997. Defined.
  998.  
  999. Definition nnd_and_intro:
  1000. forall (U:P -> Type)(x y:P),
  1001. (U |- x) ->
  1002. (U |- y) ->
  1003. (U |- nfof_and C x y).
  1004. Proof.
  1005. intros.
  1006. ni x y.
  1007. wh; wh; ap.
  1008. wh; wh; ap.
  1009. ax; nh.
  1010. Defined.
  1011.  
  1012. Definition nnd_and_elim_left:
  1013. forall (U:P -> Type)(x y:P),
  1014. U |- (nfof_and C x y) -> U |- x.
  1015. Proof.
  1016. intros.
  1017. ne2 (D (D x y) (D x y)) y.
  1018. ns; nc.
  1019. ap.
  1020. Defined.
  1021.  
  1022. Definition nnd_and_elim_right:
  1023. forall (U:P -> Type)(x y:P),
  1024. U |- (nfof_and C x y) -> U |- y.
  1025. Proof.
  1026. intros.
  1027. ne (D (D x y) (D x y)) x.
  1028. ns; nc.
  1029. ap.
  1030. Defined.
  1031.  
  1032. Definition nnd_not_intro:
  1033. forall (U:P -> Type)(x y:P),
  1034. ((add_hypothesis C U x) |- y) ->
  1035. ((add_hypothesis C U x) |- nfof_not C y) ->
  1036. (U |- nfof_not C x).
  1037. Proof.
  1038. intros.
  1039. ni y y.
  1040. wh; ap.
  1041. wh; ap.
  1042. wh; ap.
  1043. Defined.
  1044.  
  1045. Definition nnd_not_elim:
  1046. forall (U:P -> Type)(x y:P),
  1047. (U |- x) ->
  1048. (U |- nfof_not C x) ->
  1049. U |- y.
  1050. Proof.
  1051. intros.
  1052. nex x x.
  1053. ap.
  1054. ap.
  1055. ap.
  1056. Defined.
  1057.  
  1058. Definition nnd_reductio_ad_absurdum:
  1059. forall (U:P -> Type)(x:P),
  1060. U |- nfof_not C (nfof_not C x) -> U |- x.
  1061. Proof.
  1062. intros.
  1063. ne (D (D x x) (D x x)) x.
  1064. ns; nc.
  1065. ap.
  1066. Defined.
  1067.  
  1068. Definition nnd_contraposition:
  1069. forall (U:P -> Type) (x y:P),
  1070. (U |- nfof_implies C x y) ->
  1071. (U |- nfof_implies C (nfof_not C y) (nfof_not C x)).
  1072. Proof.
  1073. intros.
  1074. ni x (D y y).
  1075. apply nnd_reductio_ad_absurdum.
  1076. ax; nh.
  1077. ax; bh; nh.
  1078. wh; wh; ap.
  1079. Defined.
  1080.  
  1081. Definition nnd_or_intro_left:
  1082. forall (U:P -> Type)(x y:P),
  1083. U |- x -> U |- nfof_or C x y.
  1084. Proof.
  1085. intros.
  1086. ni x x.
  1087. wh; wh; ap.
  1088. wh; wh; ap.
  1089. ax; bh; nh.
  1090. Defined.
  1091.  
  1092. Definition nnd_or_intro_right:
  1093. forall (U:P -> Type)(x y:P),
  1094. U |- y -> U |- nfof_or C x y.
  1095. Proof.
  1096. intros.
  1097. ni y y.
  1098. wh; wh; ap.
  1099. wh; wh; ap.
  1100. ax; nh.
  1101. Defined.
  1102.  
  1103. Definition nnd_or_elim:
  1104. forall (U:P -> Type)(x y z:P),
  1105. ((add_hypothesis C U x) |- z) ->
  1106. ((add_hypothesis C U y) |- z) ->
  1107. (U |- nfof_or C x y) ->
  1108. (U |- z).
  1109. Proof.
  1110. intros.
  1111. apply nnd_reductio_ad_absurdum.
  1112. ni (D x x) (D y y).
  1113. wh.
  1114. apply nnd_implies_elim with (x:= nfof_not C z).
  1115. apply nnd_contraposition.
  1116. wh.
  1117. apply nnd_implies_intro.
  1118. ap.
  1119. ax; nh.
  1120. wh.
  1121. apply nnd_implies_elim with (x:= nfof_not C z).
  1122. apply nnd_contraposition.
  1123. wh.
  1124. apply nnd_implies_intro.
  1125. ap.
  1126. ax; nh.
  1127. wh; wh; ap.
  1128. Defined.
  1129.  
  1130. End classical_inference_rules_for_propositional_connectors.
  1131.  
  1132. Section classical_inference_rules_and_theorems_for_quantifiers.
  1133.  
  1134. Variable C:Type.
  1135. Variable T: NFO_Formula C -> Type.
  1136.  
  1137. Notation D:= (nfof_nand C).
  1138.  
  1139. Notation "G |- F":= (nand_natural_deduction C G F) (at level 61).
  1140. Notation P:= (NFO_Formula C).
  1141.  
  1142. Ltac ni v w := apply nnd_nand_intro with (p:=v) (q:=w).
  1143. Ltac ne p q:= apply nnd_nand_elim with (x:=p) (y:=q).
  1144. Ltac ax := apply nnd_ax.
  1145. Ltac nh := apply new_hyp.
  1146. Ltac bh := apply base_hyp.
  1147. Ltac wh := apply nnd_hypothesis_weakening.
  1148. Ltac ap := assumption.
  1149.  
  1150. Definition nnd_exists_intro:
  1151. forall (f: NFO_Formula (option C)) (t:NFO_Term C 0),
  1152. (T |- (nfo_formula_specialization C t f)) ->
  1153. (T |- nfof_exists C f).
  1154. Proof.
  1155. intros.
  1156. apply nnd_not_intro with (y:= nfo_formula_specialization C t f).
  1157. wh; ap.
  1158. assert (nfof_not C (nfo_formula_specialization C t f) =
  1159. nfo_formula_specialization
  1160. C t
  1161. (nfof_not (option C) f))
  1162. as E.
  1163. unfold nfo_formula_specialization; simpl; reflexivity.
  1164. rewrite E.
  1165. apply nnd_forall_elim.
  1166. ax; nh.
  1167. Defined.
  1168.  
  1169.  
  1170. Definition nnd_exists_elim:
  1171. forall (f:NFO_Formula (option C))
  1172. (g:P),
  1173. (T |- nfof_exists C f) ->
  1174. (nand_natural_deduction
  1175. (option C)
  1176. (add_hypothesis (option C) (constant_nfo_theory_embedding C T) f)
  1177. (constant_nfo_formula_embedding C g)) ->
  1178. (T |- g).
  1179. Proof.
  1180. intros.
  1181. apply nnd_reductio_ad_absurdum.
  1182. apply nnd_not_intro with (y:= nfof_forall C (nfof_not (option C) f)).
  1183. apply nnd_forall_intro.
  1184. apply nnd_implies_elim with
  1185. (x:= constant_nfo_formula_embedding C (nfof_not C g)).
  1186. assert (constant_nfo_formula_embedding C (nfof_not C g) =
  1187. nfof_not (option C) (constant_nfo_formula_embedding C g)) as E.
  1188. reflexivity.
  1189. rewrite E.
  1190. apply nnd_contraposition.
  1191. apply nnd_implies_intro.
  1192. apply nnd_general_weakening with
  1193. (T:= (add_hypothesis (option C) (constant_nfo_theory_embedding C T) f)).
  1194. intros.
  1195. destruct X1.
  1196. nh.
  1197. bh.
  1198. destruct c.
  1199. apply fots_intro.
  1200. bh; ap.
  1201. ap.
  1202. ax.
  1203. apply fots_intro.
  1204. nh.
  1205. wh; ap.
  1206. Defined.
  1207.  
  1208.  
  1209. Definition nnd_forall_elim_2:
  1210. forall (U: NFO_Formula C -> Type) (f:NFO_Formula (option C)),
  1211. U |- nfof_forall C f ->
  1212. nand_natural_deduction
  1213. (option C)
  1214. (constant_nfo_theory_embedding C U) f.
  1215. Proof.
  1216. intros.
  1217. unfold constant_nfo_theory_embedding.
  1218. unfold change_of_variable_in_theories.
  1219. apply nfo_nnd_substitution
  1220. with (env:= fun x:C => nfo_variable_to_term (option C) (Some x))
  1221. in X.
  1222. simpl in X.
  1223. apply nnd_forall_elim
  1224. with (t:= nfo_variable_to_term (option C) (None))
  1225. in X.
  1226. simpl in X.
  1227. unfold nfo_formula_specialization in X.
  1228. rewrite nfo_formula_substitution_transitivity in X.
  1229. assert
  1230. (nfo_formula_substitution
  1231. (option C) (option C)
  1232. (fun a : option C =>
  1233. nfo_term_substitution
  1234. (option (option C)) (option C)
  1235. (assign_term_to_var
  1236. (option C)
  1237. (nfo_variable_to_term (option C) (None))) 0
  1238. (add_var_to_environment
  1239. C (option C)
  1240. (fun x : C => nfo_variable_to_term
  1241. (option C) (Some x)) a)) f
  1242. =
  1243. (nfo_formula_substitution
  1244. (option C) (option C)
  1245. (fun u:(option C) => nfo_variable_to_term (option C) u) f)
  1246. ) as e.
  1247. apply nfo_formula_extensional_equality.
  1248. intros.
  1249. destruct c.
  1250. simpl.
  1251. reflexivity.
  1252. simpl.
  1253. reflexivity.
  1254. rewrite e in X.
  1255. rewrite nfo_formula_identity_substitution in X.
  1256. assumption.
  1257. Defined.
  1258.  
  1259. Notation "v --> w":= (nfof_implies C v w) (right associativity, at level 51).
  1260.  
  1261. Definition nnd_universal_modus_ponens: forall f g:NFO_Formula (option C),
  1262. T |-
  1263. (nfof_forall C (nfof_implies (option C) f g)) --> (nfof_forall C f)
  1264. --> (nfof_forall C g).
  1265. Proof.
  1266. intros.
  1267. apply nnd_implies_intro.
  1268. apply nnd_implies_intro.
  1269. apply nnd_forall_intro.
  1270. apply nnd_implies_elim with (x:=f).
  1271. apply nnd_forall_elim_2.
  1272. ax; bh; nh.
  1273. apply nnd_forall_elim_2.
  1274. ax; nh.
  1275. Defined.
  1276.  
  1277. Definition nnd_constant_forall: forall f:NFO_Formula C,
  1278. T |- (nfof_implies C f
  1279. (nfof_forall C (constant_nfo_formula_embedding C f))).
  1280. Proof.
  1281. intros.
  1282. apply nnd_implies_intro.
  1283. apply nnd_forall_intro.
  1284. apply nnd_ax.
  1285. apply fots_intro.
  1286. nh.
  1287. Defined.
  1288.  
  1289. Definition nnd_specialization_formula:
  1290. forall (f:NFO_Formula (option C)) (t:NFO_Term C 0),
  1291. T |- nfof_implies C (nfof_forall C f) (nfo_formula_specialization C t f).
  1292. Proof.
  1293. intros.
  1294. apply nnd_implies_intro.
  1295. apply nnd_forall_elim.
  1296. ax; nh.
  1297. Defined.
  1298.  
  1299. Section the_witness_property.
  1300.  
  1301. Ltac mp r := apply nnd_implies_elim with (x:=r).
  1302. Ltac ded := apply nnd_implies_intro.
  1303.  
  1304. Variable s:NFO_Term C 0.
  1305. Variable f:NFO_Formula (option C).
  1306. Variable g:P.
  1307. Definition nnd_or_permutation: forall (U:P -> Type) (a b:P),
  1308. U|- (a --> b) --> b ->
  1309. U|- (b --> a) --> a.
  1310. Proof.
  1311. intros.
  1312. apply nnd_nand_cases with (x:=a) (y:= nfof_nand C b b).
  1313. ded; ax; bh; bh; nh.
  1314. ded; mp b.
  1315. ax; nh.
  1316. mp (a --> b).
  1317. wh; wh; assumption.
  1318. ax; bh; nh.
  1319. Defined.
  1320.  
  1321. Definition nnd_or_permutation_formula: forall a b:P,
  1322. T|- ((a --> b) --> b) --> (b --> a) --> a.
  1323. Proof.
  1324. intros.
  1325. ded.
  1326. apply nnd_or_permutation.
  1327. ax; nh.
  1328. Defined.
  1329.  
  1330. Definition nnd_or_forall_intro: forall (f1:P) (g1: NFO_Formula (option C)),
  1331. nand_natural_deduction
  1332. (option C) (constant_nfo_theory_embedding C T)
  1333. (nfof_implies
  1334. (option C)
  1335. (nfof_implies (option C) (constant_nfo_formula_embedding C f1) g1)
  1336. g1)
  1337. ->
  1338. T |- (f1 --> (nfof_forall C g1)) --> (nfof_forall C g1).
  1339. Proof.
  1340. intros.
  1341. ded.
  1342. apply nnd_forall_intro.
  1343. mp (nfof_implies (option C) (constant_nfo_formula_embedding C f1) g1).
  1344. apply nnd_general_weakening with
  1345. (T:=(constant_nfo_theory_embedding C T)).
  1346. intros.
  1347. destruct X0.
  1348. apply fots_intro.
  1349. bh; assumption.
  1350. assumption.
  1351. ded.
  1352. apply nnd_general_weakening with
  1353. (T:=(constant_nfo_theory_embedding
  1354. C (add_hypothesis
  1355. C (add_hypothesis C T (f1 --> (nfof_forall C g1))) f1))).
  1356. intros.
  1357. destruct X0.
  1358. simpl.
  1359. destruct a.
  1360. nh.
  1361. bh.
  1362. apply fots_intro.
  1363. assumption.
  1364. apply nnd_forall_elim_2.
  1365. mp f1.
  1366. ax; bh; nh.
  1367. ax; nh.
  1368. Defined.
  1369.  
  1370. Definition nnd_universal_witness:
  1371. nand_natural_deduction
  1372. (option C)
  1373. (constant_nfo_theory_embedding C T)
  1374. (nfof_implies
  1375. (option C)
  1376. (nfof_implies
  1377. (option C)
  1378. f
  1379. (constant_nfo_formula_embedding C (nfof_forall C f))
  1380. )
  1381. (constant_nfo_formula_embedding C g)
  1382. ) -> T |- g.
  1383. Proof.
  1384. intros.
  1385. mp ((nfof_forall C f) --> g).
  1386. mp ((g --> (nfof_forall C f)) --> (nfof_forall C f)).
  1387. apply nnd_or_permutation_formula.
  1388. apply nnd_or_forall_intro.
  1389. ded.
  1390. apply nnd_nand_cases with
  1391. (x:=f)
  1392. (y:= nfof_not (option C)
  1393. (constant_nfo_formula_embedding C (nfof_forall C f))).
  1394. ax; bh; nh.
  1395. mp (constant_nfo_formula_embedding C g).
  1396. ax; bh; nh.
  1397. mp (nfof_implies (option C) f
  1398. (constant_nfo_formula_embedding C (nfof_forall C f))).
  1399. wh; wh; assumption.
  1400. ax; nh.
  1401. ded.
  1402. rewrite <- specialization_doesnt_change_constant_formulas with (f:=g) (X:=s).
  1403. apply nnd_forall_elim.
  1404. apply nnd_forall_intro.
  1405. mp (nfof_implies (option C) f
  1406. (constant_nfo_formula_embedding C (nfof_forall C f))).
  1407. apply nnd_general_weakening with (T:= constant_nfo_theory_embedding C T).
  1408. intros.
  1409. destruct X0.
  1410. apply fots_intro.
  1411. bh; assumption.
  1412. assumption.
  1413. ded.
  1414. wh.
  1415. ax.
  1416. apply fots_intro.
  1417. nh.
  1418. Defined.
  1419.  
  1420. End the_witness_property.
  1421.  
  1422. End classical_inference_rules_and_theorems_for_quantifiers.
  1423.  
  1424. End ND_proofs_of_some_usual_inference_rules.
  1425.  
  1426. End natural_deduction.
  1427.  
  1428.  
  1429. Section basic_semantics.
  1430.  
  1431. Variable Univ:Type.
  1432.  
  1433. Fixpoint function_type_interpretation (n:nat) {struct n}:Type:=
  1434. match n with
  1435. |0 => Univ
  1436. |S k => Univ -> (function_type_interpretation k)
  1437. end.
  1438.  
  1439. Fixpoint relation_type_interpretation (n:nat) {struct n}:Type:=
  1440. match n with
  1441. |0 => Prop
  1442. |S k => Univ -> (relation_type_interpretation k)
  1443. end.
  1444.  
  1445. Variable (env_t: forall x: Function_symbol Sg,
  1446. function_type_interpretation (function_arity Sg x)).
  1447. Variable (env_r: forall x: Relation_symbol Sg,
  1448. relation_type_interpretation (relation_arity Sg x)).
  1449.  
  1450. Section interpretation_of_terms_and_predicates.
  1451.  
  1452. Variable C:Type.
  1453. Variable (env_c: C -> Univ).
  1454.  
  1455. Fixpoint fo_term_interpretation
  1456. (n:nat)
  1457. (t: NFO_Term C n)
  1458. {struct t}: function_type_interpretation n:=
  1459. match t in (NFO_Term _ n0) return (function_type_interpretation n0) with
  1460. | nfo_variable_to_term _ c => env_c c
  1461. | nfo_symbol_to_term _ x => env_t x
  1462. | nfo_app_term _ n0 t1 t2 =>
  1463. let t3 := fo_term_interpretation (S n0) t1 in
  1464. let t4 := fo_term_interpretation 0 t2 in t3 t4
  1465. end.
  1466.  
  1467. Fixpoint fo_predicate_interpretation
  1468. (n:nat)
  1469. (p: NFO_Predicate C n)
  1470. {struct p}: relation_type_interpretation n:=
  1471. match p in (NFO_Predicate _ n0) return (relation_type_interpretation n0) with
  1472. | nfo_symbol_to_predicate _ x => env_r x
  1473. | nfo_app_predicate _ n0 p0 n1 =>
  1474. let p1 := fo_predicate_interpretation (S n0) p0 in
  1475. let n2 := fo_term_interpretation 0 n1 in p1 n2
  1476. end.
  1477.  
  1478. End interpretation_of_terms_and_predicates.
  1479.  
  1480. Fixpoint nfo_formula_interpretation
  1481. (C:Type) (env_c: C -> Univ) (f:NFO_Formula C)
  1482. {struct f}:Prop:=
  1483. match f in (NFO_Formula T) return ((T -> Univ) -> Prop) with
  1484. | nfof_atomic_formula context x =>
  1485. fun env_c0 : context -> Univ =>
  1486. let x0 := fo_predicate_interpretation context env_c0 0 x in x0
  1487. | nfof_nand context f1 f2 =>
  1488. fun env_c0 : context -> Univ =>
  1489. let f3 := nfo_formula_interpretation context env_c0 f1 in
  1490. let f4 := nfo_formula_interpretation context env_c0 f2 in f3 -> f4 -> False
  1491. | nfof_forall context f0 =>
  1492. fun env_c0 : context -> Univ =>
  1493. all
  1494. (fun u : Univ =>
  1495. nfo_formula_interpretation
  1496. (option context)
  1497. (option_rect (fun _ : option context => Univ) env_c0 u) f0)
  1498. end env_c.
  1499.  
  1500. Fixpoint fo_term_interpretation_extensionality
  1501. (C:Type)
  1502. (env_c1 env_c2: C -> Univ)
  1503. (ext: forall l:C, env_c1 l = env_c2 l)
  1504. (k:nat)
  1505. (t:NFO_Term C k)
  1506. {struct t}:
  1507. fo_term_interpretation C env_c1 k t =
  1508. fo_term_interpretation C env_c2 k t.
  1509. Proof.
  1510. destruct t.
  1511. simpl; apply ext.
  1512. simpl; reflexivity.
  1513. simpl.
  1514. rewrite fo_term_interpretation_extensionality with
  1515. (env_c1:= env_c1)(env_c2:= env_c2).
  1516. rewrite fo_term_interpretation_extensionality with
  1517. (env_c1:= env_c1)(env_c2:= env_c2).
  1518. reflexivity.
  1519. assumption.
  1520. assumption.
  1521. Defined.
  1522.  
  1523. Fixpoint fo_predicate_interpretation_extensionality
  1524. (C:Type)
  1525. (env_c1 env_c2: C -> Univ)
  1526. (ext: forall l:C, env_c1 l = env_c2 l)
  1527. (k:nat)
  1528. (p:NFO_Predicate C k)
  1529. {struct p}:
  1530. fo_predicate_interpretation C env_c1 k p =
  1531. fo_predicate_interpretation C env_c2 k p.
  1532. Proof.
  1533. destruct p.
  1534. simpl; reflexivity.
  1535. simpl.
  1536. rewrite fo_predicate_interpretation_extensionality
  1537. with (env_c1:= env_c1)(env_c2:= env_c2).
  1538. rewrite fo_term_interpretation_extensionality with
  1539. (env_c1:= env_c1)(env_c2:= env_c2).
  1540. reflexivity.
  1541. assumption.
  1542. assumption.
  1543. Defined.
  1544.  
  1545. Lemma nand_equiv: forall A A' B B':Prop,
  1546. (A <-> A') -> (B <-> B') -> ((A -> B -> False) <-> (A' -> B' -> False)).
  1547. Proof.
  1548. intros.
  1549. tauto.
  1550. Defined.
  1551.  
  1552. Lemma all_equiv: forall (P Q: Univ -> Prop),
  1553. (forall x:Univ, P x <-> Q x) ->
  1554. ((all P) <-> (all Q)).
  1555. Proof.
  1556. intros.
  1557. split.
  1558. intros; intro.
  1559. apply H; apply H0.
  1560. intros; intro.
  1561. apply H; apply H0.
  1562. Defined.
  1563.  
  1564. Fixpoint nfo_formula_interpretation_extensionality
  1565. (C:Type)
  1566. (env_c1 env_c2: C -> Univ)
  1567. (ext: forall l:C, env_c1 l = env_c2 l)
  1568. (f:NFO_Formula C)
  1569. {struct f}:
  1570. nfo_formula_interpretation C env_c1 f <->
  1571. nfo_formula_interpretation C env_c2 f.
  1572. Proof.
  1573. destruct f.
  1574. simpl;
  1575. rewrite fo_predicate_interpretation_extensionality with (env_c2:= env_c2).
  1576. apply iff_refl.
  1577. assumption.
  1578. simpl; apply nand_equiv.
  1579. apply nfo_formula_interpretation_extensionality.
  1580. assumption.
  1581. apply nfo_formula_interpretation_extensionality.
  1582. assumption.
  1583. simpl; apply all_equiv.
  1584. intros.
  1585. apply nfo_formula_interpretation_extensionality.
  1586. intros.
  1587. destruct l.
  1588. simpl; apply ext.
  1589. simpl; reflexivity.
  1590. Defined.
  1591.  
  1592. Fixpoint fo_term_interpretation_substitution
  1593. (C D:Type)
  1594. (env_cd: C -> NFO_Term D 0)
  1595. (env_d: D -> Univ)
  1596. (k:nat)
  1597. (t:NFO_Term C k)
  1598. {struct t}:
  1599. fo_term_interpretation
  1600. C
  1601. (fun x:C => fo_term_interpretation D env_d 0 (env_cd x))
  1602. k t
  1603. = fo_term_interpretation
  1604. D env_d k
  1605. (nfo_term_substitution C D env_cd k t).
  1606. Proof.
  1607. destruct t.
  1608. simpl; reflexivity.
  1609. simpl; reflexivity.
  1610. simpl.
  1611. rewrite fo_term_interpretation_substitution.
  1612. rewrite fo_term_interpretation_substitution.
  1613. reflexivity.
  1614. Defined.
  1615.  
  1616. Fixpoint fo_predicate_interpretation_substitution
  1617. (C D:Type)
  1618. (env_cd: C -> NFO_Term D 0)
  1619. (env_d: D -> Univ)
  1620. (k:nat)
  1621. (p:NFO_Predicate C k)
  1622. {struct p}:
  1623. fo_predicate_interpretation
  1624. C
  1625. (fun x:C => fo_term_interpretation D env_d 0 (env_cd x))
  1626. k p
  1627. = fo_predicate_interpretation
  1628. D env_d k
  1629. (nfo_predicate_substitution C D env_cd k p).
  1630. Proof.
  1631. destruct p.
  1632. simpl; reflexivity.
  1633. simpl.
  1634. rewrite fo_term_interpretation_substitution.
  1635. rewrite fo_predicate_interpretation_substitution.
  1636. reflexivity.
  1637. Defined.
  1638.  
  1639. Fixpoint nfo_formula_interpretation_substitution
  1640. (C D:Type)
  1641. (env_cd: C -> NFO_Term D 0)
  1642. (env_d: D -> Univ)
  1643. (f:NFO_Formula C)
  1644. {struct f}:
  1645. nfo_formula_interpretation
  1646. C
  1647. (fun x:C => fo_term_interpretation D env_d 0 (env_cd x))
  1648. f
  1649. <->
  1650. nfo_formula_interpretation
  1651. D env_d
  1652. (nfo_formula_substitution C D env_cd f).
  1653. Proof.
  1654. destruct f.
  1655. simpl; rewrite fo_predicate_interpretation_substitution; apply iff_refl.
  1656. simpl.
  1657. apply nand_equiv.
  1658. apply nfo_formula_interpretation_substitution.
  1659. apply nfo_formula_interpretation_substitution.
  1660. simpl.
  1661. apply all_equiv.
  1662. intros.
  1663. simpl.
  1664. apply iff_trans with
  1665. (B:=
  1666. nfo_formula_interpretation
  1667. (option context)
  1668. (fun x0 : option context =>
  1669. fo_term_interpretation
  1670. (option D) (option_rect (fun _ : option D => Univ) env_d x) 0
  1671. (add_var_to_environment context D env_cd x0)) f
  1672. ).
  1673. apply nfo_formula_interpretation_extensionality.
  1674. intros.
  1675. destruct l.
  1676. simpl.
  1677. unfold change_of_variable_in_terms.
  1678. rewrite <- fo_term_interpretation_substitution.
  1679. simpl.
  1680. reflexivity.
  1681. simpl.
  1682. reflexivity.
  1683. apply nfo_formula_interpretation_substitution.
  1684. Defined.
  1685.  
  1686. Section regular_formulas.
  1687.  
  1688. (*Because COQ is intuitionnist, we need to restrict our analysis to
  1689. a certain type of propositions; fortunately all interpretations of formulas will
  1690. have the property we define below (and in fact, all formulas have it
  1691. under the extra assumption that the excluded middle holds). *)
  1692.  
  1693. Definition regular (P:Prop):Prop:= ((P -> False) -> False) -> P.
  1694.  
  1695. Lemma regular_implies: forall A B:Prop,
  1696. regular B -> regular (A -> B).
  1697. Proof.
  1698. intros A B.
  1699. unfold regular.
  1700. intros.
  1701. apply H.
  1702. intro.
  1703. apply H0.
  1704. intro.
  1705. apply H2.
  1706. apply H3.
  1707. apply H1.
  1708. Defined.
  1709.  
  1710. Lemma regular_false: regular False.
  1711. Proof.
  1712. intro.
  1713. apply H.
  1714. intro; assumption.
  1715. Defined.
  1716.  
  1717. Lemma regular_forall: forall P: Univ -> Prop,
  1718. (forall x:Univ, regular (P x)) -> regular (all P).
  1719. Proof.
  1720. intro P.
  1721. unfold regular.
  1722. intros.
  1723. intro t.
  1724. apply H.
  1725. intro.
  1726. apply H0.
  1727. intro.
  1728. apply H1.
  1729. apply H2.
  1730. Defined.
  1731.  
  1732. End regular_formulas.
  1733.  
  1734. Section the_soundness_theorem.
  1735.  
  1736. Hypothesis regular_atoms:
  1737. forall (C:Type) (env_c: C -> Univ)(p:NFO_Predicate C 0),
  1738. regular (fo_predicate_interpretation C env_c 0 p).
  1739.  
  1740. Theorem regular_interpretation: forall (C:Type)(env_c: C -> Univ)(f:NFO_Formula C),
  1741. regular (nfo_formula_interpretation C env_c f).
  1742. Proof.
  1743. induction f.
  1744. simpl.
  1745. apply regular_atoms.
  1746. simpl.
  1747. apply regular_implies.
  1748. apply regular_implies.
  1749. apply regular_false.
  1750. simpl.
  1751. apply regular_forall.
  1752. intros.
  1753. apply IHf.
  1754. Defined.
  1755.  
  1756. Fixpoint nnd_soundness
  1757. (C:Type)
  1758. (hyp: NFO_Formula C -> Type)
  1759. (env_c: C -> Univ)
  1760. (true_hyp: forall h:NFO_Formula C,
  1761. hyp h -> nfo_formula_interpretation C env_c h)
  1762. (f:NFO_Formula C)
  1763. (pr: nand_natural_deduction C hyp f)
  1764. {struct pr}:
  1765. nfo_formula_interpretation C env_c f.
  1766. Proof.
  1767. intros.
  1768. destruct pr.
  1769. apply true_hyp; assumption.
  1770. simpl.
  1771. intros.
  1772. apply nnd_soundness with (env_c := env_c) in pr3.
  1773. simpl in pr3.
  1774. apply pr3.
  1775. apply nnd_soundness with (env_c := env_c) in pr1.
  1776. assumption.
  1777. intros.
  1778. destruct X.
  1779. assumption.
  1780. destruct a0.
  1781. assumption.
  1782. apply true_hyp.
  1783. assumption.
  1784. apply nnd_soundness with (env_c := env_c) in pr2.
  1785. assumption.
  1786. intros.
  1787. destruct X.
  1788. assumption.
  1789. destruct a0.
  1790. assumption.
  1791. apply true_hyp.
  1792. assumption.
  1793. intros.
  1794. destruct X.
  1795. assumption.
  1796. destruct a0.
  1797. assumption.
  1798. apply true_hyp.
  1799. assumption.
  1800. apply nnd_soundness with (env_c:= env_c) in pr1.
  1801. apply nnd_soundness with (env_c:= env_c) in pr2.
  1802. simpl in pr1.
  1803. apply regular_interpretation.
  1804. intro.
  1805. apply pr1.
  1806. assumption.
  1807. intro; assumption.
  1808. assumption.
  1809. assumption.
  1810. simpl.
  1811. intro u.
  1812. apply nnd_soundness with (hyp := constant_nfo_theory_embedding C hyp).
  1813. intros.
  1814. destruct X.
  1815. apply nfo_formula_interpretation_substitution.
  1816. apply nfo_formula_interpretation_extensionality with (env_c1:= env_c).
  1817. intros.
  1818. simpl.
  1819. reflexivity.
  1820. apply true_hyp.
  1821. assumption.
  1822. assumption.
  1823. apply nnd_soundness with (env_c := env_c) in pr.
  1824. simpl in pr.
  1825. apply nfo_formula_interpretation_substitution.
  1826. apply nfo_formula_interpretation_extensionality with
  1827. (env_c1:= option_rect (fun _: option C => Univ) env_c
  1828. (fo_term_interpretation C env_c 0 t)).
  1829. intros.
  1830. destruct l.
  1831. simpl.
  1832. reflexivity.
  1833. simpl.
  1834. reflexivity.
  1835. apply pr.
  1836. assumption.
  1837. Defined.
  1838.  
  1839. End the_soundness_theorem.
  1840.  
  1841. End basic_semantics.
  1842.  
  1843. End Proof_theory.
  1844.  
  1845. End definitions_of_terms_predicates_and_formulas.
  1846.  
  1847. End Signatures_and_arities_of_formulas_and_terms.
  1848.  
  1849.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement