theory Equivalence_Relations_Lecture imports Complex_Main begin (* tests whether r is a subset of X \times X *) (* expected type: a (a \times a) => bool actual types use exponential law ((un)currying): a => ( (a \times a) => bool ) *) definition is_relation_on :: "'a set => ('a \ 'a) set => bool" where "is_relation_on X r = (r \ X \ X)" definition is_reflexive :: "'a set => ('a \ 'a) set => bool" where "is_reflexive X r = (\ x \ X. (x,x) \ r)" definition is_symmetric :: "'a set => ('a \ 'a) set => bool" where "is_symmetric X r = (\ x \ X. \ y \ X. (x,y) \ r --> (y,x) \ r)" definition is_transitive :: "'a set => ('a \ 'a) set => bool" where "is_transitive X r = (\ x \ X. \ y \ X. \ z \ X. ((x,y) \ r \ (y,z) \ r) --> (x,z) \ r)" definition is_equivalence_relation :: "'a set => ('a \ 'a) set => bool" where "is_equivalence_relation X r = (is_relation_on X r \ is_reflexive X r \ is_symmetric X r \ is_transitive X r)" lemma diagonal_is_equivalence_relation: fixes X shows "is_equivalence_relation X {(x,y). x \ X \ y\ X \ x = y}" proof - define diag_X where "diag_X = {(x,y). x \ X \ y \ X \ x = y}" have diag_X_is_relation_on_X: "is_relation_on X diag_X" unfolding is_relation_on_def proof (intro subsetI ballI) fix xy :: "'a \ 'a" assume xy_in_diag_X: "xy \ diag_X" then show "xy \ X \ X" using diag_X_def xy_in_diag_X by auto qed have diag_X_is_reflexive: "is_reflexive X diag_X" unfolding is_reflexive_def proof (intro ballI) fix x :: 'a assume x_in_X: "x \ X" show "(x,x) \ diag_X" using x_in_X diag_X_def by simp qed have diag_X_is_symmetric: "is_symmetric X diag_X" proof - have "\ x \ X. \ y \ X. (x,y) \ diag_X --> (y,x) \ diag_X" proof (intro ballI impI) fix x :: 'a assume x_in_X: "x \ X" fix y :: 'a assume y_in_X: "y \ X" assume xy_in_diag_X: "(x,y) \ diag_X" from xy_in_diag_X diag_X_def have "x = y" by simp then have "y = x" by simp then show "(y,x) \ diag_X" by (simp add: diag_X_def x_in_X y_in_X) qed then show ?thesis by (simp add: is_symmetric_def) qed have diag_X_is_transitive: "is_transitive X diag_X" proof - have "\ x \ X. \ y \ X. \ z \ X. ((x,y) \ diag_X \ (y,z) \ diag_X) --> (x,z) \ diag_X" proof (intro ballI impI) fix x :: 'a assume x_in_X: "x \ X" fix y :: 'a assume y_in_X: "y \ X" fix z :: 'a assume z_in_X: "z \ X" assume xy_yz_in_diag_X: "(x,y) \ diag_X \ (y,z) \ diag_X" from xy_yz_in_diag_X diag_X_def have x_eq_y: "x = y" by simp from xy_yz_in_diag_X diag_X_def have y_eq_z: "y = z" by simp then have x_eq_z: "x = z" using x_eq_y y_eq_z by simp then show "(x,z) \ diag_X" using x_eq_z by (simp add: diag_X_def x_in_X z_in_X) qed then show ?thesis by (simp only: is_transitive_def) qed from diag_X_is_relation_on_X diag_X_is_reflexive diag_X_is_symmetric diag_X_is_transitive show ?thesis by (simp add: is_equivalence_relation_def diag_X_def) qed end