diff -r b1281a0051ae -r b611aee9f8e7 Attic/Quot/Examples/IntEx.thy --- a/Attic/Quot/Examples/IntEx.thy Thu Apr 29 09:13:18 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,256 +0,0 @@ -theory IntEx -imports "../Quotient_Product" "../Quotient_List" -begin - -fun - intrel :: "(nat \ nat) \ (nat \ nat) \ bool" (infix "\" 50) -where - "intrel (x, y) (u, v) = (x + v = u + y)" - -quotient_type - my_int = "nat \ nat" / intrel - apply(unfold equivp_def) - apply(auto simp add: mem_def expand_fun_eq) - done - -quotient_definition - "ZERO :: my_int" -is - "(0::nat, 0::nat)" - -quotient_definition - "ONE :: my_int" -is - "(1::nat, 0::nat)" - -fun - my_plus :: "(nat \ nat) \ (nat \ nat) \ (nat \ nat)" -where - "my_plus (x, y) (u, v) = (x + u, y + v)" - -quotient_definition - "PLUS :: my_int \ my_int \ my_int" -is - "my_plus" - -fun - my_neg :: "(nat \ nat) \ (nat \ nat)" -where - "my_neg (x, y) = (y, x)" - -quotient_definition - "NEG :: my_int \ my_int" -is - "my_neg" - -definition - MINUS :: "my_int \ my_int \ my_int" -where - "MINUS z w = PLUS z (NEG w)" - -fun - my_mult :: "(nat \ nat) \ (nat \ nat) \ (nat \ nat)" -where - "my_mult (x, y) (u, v) = (x*u + y*v, x*v + y*u)" - -quotient_definition - "MULT :: my_int \ my_int \ my_int" -is - "my_mult" - - -(* NOT SURE WETHER THIS DEFINITION IS CORRECT *) -fun - my_le :: "(nat \ nat) \ (nat \ nat) \ bool" -where - "my_le (x, y) (u, v) = (x+v \ u+y)" - -quotient_definition - "LE :: my_int \ my_int \ bool" -is - "my_le" - -term LE -thm LE_def - - -definition - LESS :: "my_int \ my_int \ bool" -where - "LESS z w = (LE z w \ z \ w)" - -term LESS -thm LESS_def - -definition - ABS :: "my_int \ my_int" -where - "ABS i = (if (LESS i ZERO) then (NEG i) else i)" - -definition - SIGN :: "my_int \ my_int" -where - "SIGN i = (if i = ZERO then ZERO else if (LESS ZERO i) then ONE else (NEG ONE))" - -print_quotconsts - -lemma plus_sym_pre: - shows "my_plus a b \ my_plus b a" - apply(cases a) - apply(cases b) - apply(auto) - done - -lemma plus_rsp[quot_respect]: - shows "(intrel ===> intrel ===> intrel) my_plus my_plus" -by (simp) - -lemma neg_rsp[quot_respect]: - shows "(op \ ===> op \) my_neg my_neg" -by simp - -lemma test1: "my_plus a b = my_plus a b" -apply(rule refl) -done - -lemma "PLUS a b = PLUS a b" -apply(lifting_setup test1) -apply(regularize) -apply(injection) -apply(cleaning) -done - -thm lambda_prs - -lemma test2: "my_plus a = my_plus a" -apply(rule refl) -done - -lemma "PLUS a = PLUS a" -apply(lifting_setup test2) -apply(rule impI) -apply(rule ballI) -apply(rule apply_rsp[OF Quotient_my_int plus_rsp]) -apply(simp only: in_respects) -apply(injection) -apply(cleaning) -done - -lemma test3: "my_plus = my_plus" -apply(rule refl) -done - -lemma "PLUS = PLUS" -apply(lifting_setup test3) -apply(rule impI) -apply(rule plus_rsp) -apply(injection) -apply(cleaning) -done - - -lemma "PLUS a b = PLUS b a" -apply(lifting plus_sym_pre) -done - -lemma plus_assoc_pre: - shows "my_plus (my_plus i j) k \ my_plus i (my_plus j k)" - apply (cases i) - apply (cases j) - apply (cases k) - apply (simp) - done - -lemma plus_assoc: "PLUS (PLUS x xa) xb = PLUS x (PLUS xa xb)" -apply(lifting plus_assoc_pre) -done - -lemma ex1tst: "Bex1_rel (op \) (\x :: nat \ nat. x \ x)" -sorry - -lemma ex1tst': "\!(x::my_int). x = x" -apply(lifting ex1tst) -done - - -lemma ho_tst: "foldl my_plus x [] = x" -apply simp -done - - -term foldl -lemma "foldl PLUS x [] = x" -apply(lifting ho_tst) -done - -lemma ho_tst2: "foldl my_plus x (h # t) \ my_plus h (foldl my_plus x t)" -sorry - -lemma "foldl PLUS x (h # t) = PLUS h (foldl PLUS x t)" -apply(lifting ho_tst2) -done - -lemma ho_tst3: "foldl f (s::nat \ nat) ([]::(nat \ nat) list) = s" -by simp - -lemma "foldl f (x::my_int) ([]::my_int list) = x" -apply(lifting ho_tst3) -done - -lemma lam_tst: "(\x. (x, x)) y = (y, (y :: nat \ nat))" -by simp - -(* Don't know how to keep the goal non-contracted... *) -lemma "(\x. (x, x)) (y::my_int) = (y, y)" -apply(lifting lam_tst) -done - -lemma lam_tst2: "(\(y :: nat \ nat). y) = (\(x :: nat \ nat). x)" -by simp - -lemma - shows "equivp (op \)" - and "equivp ((op \) ===> (op \))" -(* Nitpick finds a counterexample! *) -oops - -lemma lam_tst3a: "(\(y :: nat \ nat). y) = (\(x :: nat \ nat). x)" -by auto - -lemma id_rsp: - shows "(R ===> R) id id" -by simp - -lemma lam_tst3a_reg: "(op \ ===> op \) (Babs (Respects op \) (\y. y)) (Babs (Respects op \) (\x. x))" -apply (rule babs_rsp[OF Quotient_my_int]) -apply (simp add: id_rsp) -done - -lemma "(\(y :: my_int). y) = (\(x :: my_int). x)" -apply(lifting lam_tst3a) -apply(rule impI) -apply(rule lam_tst3a_reg) -done - -lemma lam_tst3b: "(\(y :: nat \ nat \ nat \ nat). y) = (\(x :: nat \ nat \ nat \ nat). x)" -by auto - -lemma "(\(y :: my_int => my_int). y) = (\(x :: my_int => my_int). x)" -apply(lifting lam_tst3b) -apply(rule impI) -apply(rule babs_rsp[OF fun_quotient[OF Quotient_my_int Quotient_my_int]]) -apply(simp add: id_rsp) -done - -lemma lam_tst4: "map (\x. my_plus x (0,0)) l = l" -apply (induct l) -apply simp -apply (case_tac a) -apply simp -done - -lemma "map (\x. PLUS x ZERO) l = l" -apply(lifting lam_tst4) -done - -end