# HG changeset patch # User nipkow # Date 1495972663 -7200 # Node ID 431024edc9cfccdc0ab2929429ea1d4e2d83ac85 # Parent 440fe0937b92a4884c79562291dfb3f5d6732893 introduced arg_max diff -r 440fe0937b92 -r 431024edc9cf src/Doc/Main/Main_Doc.thy --- a/src/Doc/Main/Main_Doc.thy Sun May 28 11:32:15 2017 +0200 +++ b/src/Doc/Main/Main_Doc.thy Sun May 28 13:57:43 2017 +0200 @@ -79,7 +79,6 @@ @{term "\x\y. P"} & @{term[source]"\x. x \ y \ P"}\\ \multicolumn{2}{@ {}l@ {}}{Similarly for $<$, $\ge$ and $>$}\\ @{term "LEAST x. P"} & @{term[source]"Least (\x. P)"}\\ -@{term "ARG_MIN f x. P"} & @{term[source]"arg_min f (\x. P)"}\\ \end{supertabular} @@ -419,12 +418,17 @@ @{const Lattices_Big.Max} & @{typeof Lattices_Big.Max}\\ @{const Lattices_Big.arg_min} & @{typeof Lattices_Big.arg_min}\\ @{const Lattices_Big.is_arg_min} & @{typeof Lattices_Big.is_arg_min}\\ +@{const Lattices_Big.arg_max} & @{typeof Lattices_Big.arg_max}\\ +@{const Lattices_Big.is_arg_max} & @{typeof Lattices_Big.is_arg_max}\\ +@{const Lattices_Big.Greatest} & @{typeof Lattices_Big.Greatest}\\ \end{supertabular} \subsubsection*{Syntax} \begin{supertabular}{@ {} l @ {\quad$\equiv$\quad} l l @ {}} @{term "ARG_MIN f x. P"} & @{term[source]"arg_min f (\x. P)"}\\ +@{term "ARG_MAX f x. P"} & @{term[source]"arg_max f (\x. P)"}\\ +@{term "GREATEST x. P"} & @{term[source]"Greatest (\x. P)"}\\ \end{supertabular} diff -r 440fe0937b92 -r 431024edc9cf src/HOL/Hilbert_Choice.thy --- a/src/HOL/Hilbert_Choice.thy Sun May 28 11:32:15 2017 +0200 +++ b/src/HOL/Hilbert_Choice.thy Sun May 28 13:57:43 2017 +0200 @@ -522,7 +522,7 @@ lemma tfl_some: "\P x. P x \ P (Eps P)" by (blast intro: someI) - +(* subsection \Greatest value operator\ definition GreatestM :: "('a \ 'b::ord) \ ('a \ bool) \ 'a" @@ -607,7 +607,7 @@ apply (rule GreatestI) apply assumption+ done - +*) subsection \An aside: bounded accessible part\ diff -r 440fe0937b92 -r 431024edc9cf src/HOL/Lattices_Big.thy --- a/src/HOL/Lattices_Big.thy Sun May 28 11:32:15 2017 +0200 +++ b/src/HOL/Lattices_Big.thy Sun May 28 13:57:43 2017 +0200 @@ -915,4 +915,102 @@ apply (simp add: less_le_not_le) by (metis inj_on_eq_iff less_le mem_Collect_eq) + +subsection \Arg Max\ + +definition is_arg_max :: "('a \ 'b::ord) \ ('a \ bool) \ 'a \ bool" where +"is_arg_max f P x = (P x \ \(\y. P y \ f y > f x))" + +definition arg_max :: "('a \ 'b::ord) \ ('a \ bool) \ 'a" where +"arg_max f P = (SOME x. is_arg_max f P x)" + +abbreviation arg_max_on :: "('a \ 'b::ord) \ 'a set \ 'a" where +"arg_max_on f S \ arg_max f (\x. x \ S)" + +syntax + "_arg_max" :: "('a \ 'b) \ pttrn \ bool \ 'a" + ("(3ARG'_MAX _ _./ _)" [0, 0, 10] 10) +translations + "ARG_MAX f x. P" \ "CONST arg_max f (\x. P)" + +lemma is_arg_max_linorder: fixes f :: "'a \ 'b :: linorder" +shows "is_arg_max f P x = (P x \ (\y. P y \ f x \ f y))" +by(auto simp add: is_arg_max_def) + +lemma arg_maxI: + "P x \ + (\y. P y \ \ f y > f x) \ + (\x. P x \ \y. P y \ \ f y > f x \ Q x) \ + Q (arg_max f P)" +apply (simp add: arg_max_def is_arg_max_def) +apply (rule someI2_ex) + apply blast +apply blast +done + +lemma arg_max_equality: + "\ P k; \x. P x \ f x \ f k \ \ f (arg_max f P) = f k" + for f :: "_ \ 'a::order" +apply (rule arg_maxI [where f = f]) + apply assumption + apply (simp add: less_le_not_le) +by (metis le_less) + +lemma ex_has_greatest_nat_lemma: + "P k \ \x. P x \ (\y. P y \ \ f y \ f x) \ \y. P y \ \ f y < f k + n" + for f :: "'a \ nat" +by (induct n) (force simp: le_Suc_eq)+ + +lemma ex_has_greatest_nat: + "P k \ \y. P y \ f y < b \ \x. P x \ (\y. P y \ f y \ f x)" + for f :: "'a \ nat" +apply (rule ccontr) +apply (cut_tac P = P and n = "b - f k" in ex_has_greatest_nat_lemma) + apply (subgoal_tac [3] "f k \ b") + apply auto +done + +lemma arg_max_nat_lemma: + "\ P k; \y. P y \ f y < b \ + \ P (arg_max f P) \ (\y. P y \ f y \ f (arg_max f P))" + for f :: "'a \ nat" +apply (simp add: arg_max_def is_arg_max_linorder) +apply (rule someI_ex) +apply (erule (1) ex_has_greatest_nat) +done + +lemmas arg_max_natI = arg_max_nat_lemma [THEN conjunct1] + +lemma arg_max_nat_le: "P x \ \y. P y \ f y < b \ f x \ f (arg_max f P)" + for f :: "'a \ nat" +by (blast dest: arg_max_nat_lemma [THEN conjunct2, THEN spec, of P]) + + +text \\<^medskip> Specialization to \GREATEST\.\ + +(* LEAST ? *) +definition Greatest :: "('a::ord \ bool) \ 'a" (binder "GREATEST " 10) +where "Greatest \ arg_max (\x. x)" + +lemma Greatest_equality: + "\ P k; \x. P x \ x \ k \ \ (Greatest P) = k" + for k :: "'a::order" +apply (simp add: Greatest_def) +apply (erule arg_max_equality) +apply blast +done + +lemma GreatestI: "P k \ \y. P y \ y < b \ P (Greatest P)" + for k :: nat +unfolding Greatest_def by (rule arg_max_natI) auto + +lemma Greatest_le: "P x \ \y. P y \ y < b \ x \ (Greatest P)" + for x :: nat +unfolding Greatest_def by (rule arg_max_nat_le) auto + +lemma GreatestI_ex: "\k::nat. P k \ \y. P y \ y < b \ P (Greatest P)" +apply (erule exE) +apply (erule (1) GreatestI) +done + end diff -r 440fe0937b92 -r 431024edc9cf src/HOL/Library/Sublist.thy --- a/src/HOL/Library/Sublist.thy Sun May 28 11:32:15 2017 +0200 +++ b/src/HOL/Library/Sublist.thy Sun May 28 13:57:43 2017 +0200 @@ -284,7 +284,7 @@ subsection \Longest Common Prefix\ definition Longest_common_prefix :: "'a list set \ 'a list" where -"Longest_common_prefix L = (GREATEST ps WRT length. \xs \ L. prefix ps xs)" +"Longest_common_prefix L = (ARG_MAX length ps. \xs \ L. prefix ps xs)" lemma Longest_common_prefix_ex: "L \ {} \ \ps. (\xs \ L. prefix ps xs) \ (\qs. (\xs \ L. prefix qs xs) \ size qs \ size ps)" @@ -339,17 +339,17 @@ "\ L \ {}; \xs \ L. prefix ps xs; \qs. (\xs \ L. prefix qs xs) \ size qs \ size ps \ \ Longest_common_prefix L = ps" -unfolding Longest_common_prefix_def GreatestM_def +unfolding Longest_common_prefix_def arg_max_def is_arg_max_linorder by(rule some1_equality[OF Longest_common_prefix_unique]) auto lemma Longest_common_prefix_prefix: "xs \ L \ prefix (Longest_common_prefix L) xs" -unfolding Longest_common_prefix_def GreatestM_def +unfolding Longest_common_prefix_def arg_max_def is_arg_max_linorder by(rule someI2_ex[OF Longest_common_prefix_ex]) auto lemma Longest_common_prefix_longest: "L \ {} \ \xs\L. prefix ps xs \ length ps \ length(Longest_common_prefix L)" -unfolding Longest_common_prefix_def GreatestM_def +unfolding Longest_common_prefix_def arg_max_def is_arg_max_linorder by(rule someI2_ex[OF Longest_common_prefix_ex]) auto lemma Longest_common_prefix_max_prefix: