Skip to content

Commit f679dd2

Browse files
committed
Removed linter warnings
1 parent e3baae1 commit f679dd2

1 file changed

Lines changed: 99 additions & 90 deletions

File tree

Map_Extra.thy

Lines changed: 99 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -420,19 +420,30 @@ proof (rule injI)
420420
qed
421421
qed
422422

423+
thm set_eqI
424+
423425
lemma bij_completed_map [intro]:
424-
"\<lbrakk> dom f = ran f; inj_on f (dom f) \<rbrakk> \<Longrightarrow>
425-
bij_betw (Some ++ f) UNIV (range Some)"
426-
apply (simp add:bij_betw_def inj_completed_map)
427-
apply safe
428-
apply (rename_tac x)
429-
apply (case_tac "x \<in> dom f")
430-
apply (simp)
431-
apply (metis domD rangeI)
432-
apply (simp)
433-
apply (simp add:image_def)
434-
apply (metis (full_types) dom_image_ran dom_left_map_add image_iff map_add_dom_app_simps(3))
435-
done
426+
fixes f :: "'a \<rightharpoonup> 'a"
427+
assumes "dom f = ran f" "inj_on f (dom f)"
428+
shows "bij_betw (Some ++ f) UNIV (range Some)"
429+
proof -
430+
have "range (Some ++ f) = range Some"
431+
proof (rule set_eqI, rule iffI)
432+
fix x
433+
assume "x \<in> range (Some ++ f)"
434+
thus "x \<in> range Some"
435+
using image_iff by fastforce
436+
next
437+
fix x :: "'a option"
438+
assume "x \<in> range Some"
439+
thus "x \<in> range (Some ++ f)"
440+
by (metis assms(1) dom_image_ran[of f] image_iff[of x f "dom f"] image_iff[of "Some _" Some "dom f"] image_iff[of x Some UNIV]
441+
map_add_dom_app_simps(1)[of _ f Some] map_add_dom_app_simps(3)[of _ f Some] rangeI[of "Some ++ f"])
442+
qed
443+
thus ?thesis
444+
by (metis assms(1,2) inj_completed_map inj_on_imp_bij_betw)
445+
qed
446+
436447

437448
lemma bij_map_Some:
438449
"bij_betw f a (Some ` b) \<Longrightarrow> bij_betw (the \<circ> f) a b"
@@ -508,11 +519,7 @@ proof (rule ext)
508519
done
509520

510521
ultimately show "map_inv (f ++ g) x = (map_inv f ++ map_inv g) x"
511-
apply (case_tac "x \<in> ran g")
512-
apply (simp)
513-
apply (case_tac "x \<in> ran f")
514-
apply (simp_all)
515-
done
522+
by blast
516523
qed
517524

518525
lemma map_inv_dom_res:
@@ -521,7 +528,7 @@ lemma map_inv_dom_res:
521528
using assms
522529
apply (simp add: map_inv_def restrict_map_def ran_restrict_map_def dom_def ran_def fun_eq_iff inj_on_def)
523530
apply (safe intro!: some_equality)
524-
apply (metis (mono_tags, lifting) option.simps(3) someI_ex)+
531+
apply (metis (mono_tags, lifting) someI_ex)+
525532
done
526533

527534
lemma map_inv_ran_res:
@@ -537,11 +544,17 @@ lemma map_add_lookup [simp]:
537544
by (simp add:map_add_def dom_def)
538545

539546
lemma map_add_Some: "Some ++ f = map_id_on (- dom f) ++ f"
540-
apply (rule ext)
541-
apply (rename_tac x)
542-
apply (case_tac "x \<in> dom f")
543-
apply (simp_all)
544-
done
547+
proof
548+
fix x
549+
show "(Some ++ f) x = (map_id_on (- dom f) ++ f) x"
550+
proof (cases "x \<in> dom f")
551+
case True
552+
then show ?thesis by simp
553+
next
554+
case False
555+
then show ?thesis by simp
556+
qed
557+
qed
545558

546559
lemma distinct_map_dom:
547560
"x \<notin> set xs \<Longrightarrow> x \<notin> dom [xs [\<mapsto>] ys]"
@@ -557,32 +570,19 @@ lemma distinct_map_ran:
557570
apply (simp add:zip_rev[THEN sym])
558571
done
559572

560-
lemma maplets_lookup[rule_format,dest]:
561-
"\<lbrakk> length xs = length ys; distinct xs \<rbrakk> \<Longrightarrow>
562-
\<forall> y. [xs [\<mapsto>] ys] x = Some y \<longrightarrow> y \<in> set ys"
563-
by (induct rule:list_induct2, auto)
564-
573+
lemma maplets_lookup [dest]:
574+
"\<lbrakk> length xs = length ys; distinct xs; \<forall> y. [xs [\<mapsto>] ys] x = Some y \<rbrakk> \<Longrightarrow> y \<in> set ys"
575+
using ranI by fastforce
576+
565577
lemma maplets_distinct_inj [intro]:
566578
"\<lbrakk> length xs = length ys; distinct xs; distinct ys; set xs \<inter> set ys = {} \<rbrakk> \<Longrightarrow>
567579
inj_on [xs [\<mapsto>] ys] (set xs)"
568580
apply (induct rule:list_induct2)
569581
apply (simp_all)
570582
apply (rule conjI)
571583
apply (rule inj_onI)
572-
apply (rename_tac x xs y ys xa ya)
573-
apply (case_tac "xa = x")
574-
apply (simp)
575-
apply (case_tac "xa = y")
576-
apply (simp)
577-
apply (simp)
578-
apply (case_tac "ya = x")
579-
apply (simp)
580-
apply (simp add:inj_on_def)
581-
apply (safe)
582-
apply (rename_tac x xs y ys xa)
583-
apply (case_tac "xa = y")
584-
apply (simp)
585-
apply (metis maplets_lookup)
584+
apply (metis fun_upd_def inj_on_contraD)
585+
apply (metis image_iff ranI ran_maplets)
586586
done
587587

588588
lemma map_inv_maplet[simp]: "map_inv [x \<mapsto> y] = [y \<mapsto> x]"
@@ -621,53 +621,57 @@ qed
621621
lemma map_inv_maplets [simp]:
622622
"\<lbrakk> length xs = length ys; distinct xs; distinct ys; set xs \<inter> set ys = {} \<rbrakk> \<Longrightarrow>
623623
map_inv [xs [\<mapsto>] ys] = [ys [\<mapsto>] xs]"
624-
apply (induct rule:list_induct2)
625-
apply (simp_all)
626-
apply (rename_tac x xs y ys)
627-
apply (subgoal_tac "map_inv ([xs [\<mapsto>] ys] ++ [x \<mapsto> y]) = map_inv [xs [\<mapsto>] ys] ++ map_inv [x \<mapsto> y]")
628-
apply (simp)
629-
apply (rule map_inv_add')
630-
apply (auto)
631-
done
624+
proof (induct rule:list_induct2)
625+
case Nil
626+
then show ?case by simp
627+
next
628+
case (Cons x xs y ys)
629+
have "map_inv ([xs [\<mapsto>] ys] ++ [x \<mapsto> y]) = map_inv [xs [\<mapsto>] ys] ++ map_inv [x \<mapsto> y]"
630+
proof (rule map_inv_add')
631+
from Cons show "inj_on [xs [\<mapsto>] ys] (dom [xs [\<mapsto>] ys])" by auto
632+
from Cons show "inj_on [x \<mapsto> y] (dom [x \<mapsto> y])" by auto
633+
from Cons show "dom [xs [\<mapsto>] ys] \<inter> dom [x \<mapsto> y] = {}" by auto
634+
from Cons show "ran [xs [\<mapsto>] ys] \<inter> ran [x \<mapsto> y] = {}" by auto
635+
qed
636+
with Cons show ?case
637+
by (metis disjoint_iff distinct.simps(2) list.set_intros(2) map_inv_maplet map_update_as_add map_upds_Cons map_upds_twist)
638+
qed
632639

633-
lemma maplets_lookup_nth [rule_format,simp]:
634-
"\<lbrakk> length xs = length ys; distinct xs \<rbrakk> \<Longrightarrow>
635-
\<forall> i < length ys. [xs [\<mapsto>] ys] (xs ! i) = Some (ys ! i)"
636-
apply (induct rule:list_induct2)
637-
apply (safe, simp_all)
638-
apply (rename_tac x xs y ys i)
639-
apply (case_tac i)
640-
apply (simp_all)
641-
apply (metis nth_mem)
640+
lemma maplets_lookup_nth [simp]:
641+
"\<lbrakk> length xs = length ys; distinct xs; i < length ys \<rbrakk> \<Longrightarrow>
642+
[xs [\<mapsto>] ys] (xs ! i) = Some (ys ! i)"
643+
apply (induct arbitrary: i rule:list_induct2)
644+
apply simp
645+
using less_Suc_eq_0_disj apply auto
642646
done
643647

644648
theorem inv_map_inv:
645-
"\<lbrakk> inj_on f (dom f); ran f = dom f \<rbrakk>
646-
\<Longrightarrow> inv (the \<circ> (Some ++ f)) = the \<circ> map_inv (Some ++ f)"
647-
apply (rule ext)
648-
apply (simp add:map_add_Some map_inv_add')
649-
apply (simp add:inv_def)
650-
apply (rename_tac x)
651-
apply (case_tac "\<exists> y. f y = Some x")
652-
apply (erule exE)
653-
apply (rename_tac x y)
654-
apply (subgoal_tac "x \<in> ran f")
655-
apply (subgoal_tac "y \<in> dom f")
656-
apply (simp)
657-
apply (rule some_equality)
658-
apply (simp)
659-
apply (metis (opaque_lifting, mono_tags) domD domI dom_left_map_add inj_on_contraD map_add_Some map_add_dom_app_simps(3) option.sel)
660-
apply (simp add:dom_def)
661-
apply (metis ranI)
662-
apply (simp)
663-
apply (rename_tac x)
664-
apply (subgoal_tac "x \<notin> ran f")
665-
apply (simp)
666-
apply (rule some_equality)
667-
apply (simp)
668-
apply (metis domD dom_left_map_add map_add_Some map_add_dom_app_simps(3) option.sel)
669-
apply (metis dom_image_ran image_iff)
670-
done
649+
assumes "inj_on f (dom f)" "ran f = dom f"
650+
shows "inv (the \<circ> (Some ++ f)) = the \<circ> map_inv (Some ++ f)"
651+
proof
652+
fix x
653+
show "(inv (the \<circ> (Some ++ f))) x = (the \<circ> map_inv (Some ++ f)) x"
654+
proof (cases "x \<in> ran f")
655+
case True
656+
then obtain y where y:"f y = Some x"
657+
by (metis dom_image_ran image_iff)
658+
with assms show ?thesis
659+
apply (simp add:map_add_Some map_inv_add' inv_def)
660+
apply (rule some_equality)
661+
apply simp
662+
apply (metis (full_types) Compl_iff domIff inj_on_def map_add_Some map_add_dom_app_simps(2,3) map_id_dom option.exhaust_sel ranI)
663+
done
664+
next
665+
case False
666+
then show ?thesis
667+
apply (simp add:map_add_Some map_inv_add' inv_def)
668+
apply (rule some_equality)
669+
apply (simp add: assms(1,2) map_inv_add')
670+
apply (metis (no_types, opaque_lifting) Un_UNIV_right assms(1,2) dom_map_add inj_completed_map map_add_None map_add_Some map_id_dom map_id_on_UNIV map_inv_f_f option.exhaust_sel
671+
option.sel)
672+
done
673+
qed
674+
qed
671675

672676
lemma map_comp_dom: "dom (g \<circ>\<^sub>m f) \<subseteq> dom f"
673677
by (metis (lifting, full_types) Collect_mono dom_def map_comp_simps(1))
@@ -884,11 +888,16 @@ lemma map_add_cancel:
884888
(metis domIff)
885889

886890
lemma map_le_iff_add: "f \<subseteq>\<^sub>m g \<longleftrightarrow> (\<exists> h. dom(f) \<inter> dom(h) = {} \<and> f ++ h = g)"
887-
apply (safe)
888-
apply (rule_tac x="g -- f" in exI)
889-
apply (metis (no_types, lifting) Int_emptyI domIff map_add_cancel map_le_def map_minus_def)
890-
apply (simp add: map_add_comm)
891-
done
891+
proof
892+
assume "f \<subseteq>\<^sub>m g"
893+
hence "dom f \<inter> dom (g -- f) = {} \<and> f ++ (g -- f) = g"
894+
by (metis (no_types, lifting) Int_emptyI domIff map_add_cancel map_le_def map_minus_def)
895+
thus "\<exists>h. dom f \<inter> dom h = {} \<and> f ++ h = g" by blast
896+
next
897+
assume "\<exists>h. dom f \<inter> dom h = {} \<and> f ++ h = g"
898+
thus "f \<subseteq>\<^sub>m g"
899+
by (auto simp add: map_add_comm)
900+
qed
892901

893902
lemma map_add_comm_weak: "(\<forall> k \<in> dom m1 \<inter> dom m2. m1(k) = m2(k)) \<Longrightarrow> m1 ++ m2 = m2 ++ m1"
894903
by (simp add: map_add_def option.case_eq_if fun_eq_iff)

0 commit comments

Comments
 (0)