Theory Wlog_Examples
section ‹‹Wlog_Examples› – Examples how to use \texttt{wlog}›
theory Wlog_Examples
imports Wlog Complex_Main
begin
text ‹The theorem @{thm [source] Complex.card_nth_roots} has the additional assumption \<^term>‹n > 0›.
We use exactly the same proof except for stating that w.l.o.g., \<^term>‹n > 0›.›
lemma card_nth_roots_strengthened:
assumes "c ≠ 0"
shows "card {z::complex. z ^ n = c} = n"
proof -
wlog n_pos: "n > 0"
using negation by (simp add: infinite_UNIV_char_0)
have "card {z. z ^ n = c} = card {z::complex. z ^ n = 1}"
by (rule sym, rule bij_betw_same_card, rule bij_betw_nth_root_unity) fact+
also have "… = n" by (rule card_roots_unity_eq) fact+
finally show ?thesis .
qed
text ‹This example very roughly follows Harrison \<^cite>‹"harrison-wlog"›:›
lemma schur_ineq:
fixes a b c :: ‹'a :: linordered_idom› and k :: nat
assumes a0: ‹a ≥ 0› and b0: ‹b ≥ 0› and c0: ‹c ≥ 0›
shows ‹a^k * (a - b) * (a - c) + b^k * (b - a) * (b - c) + c^k * (c - a) * (c - b) ≥ 0›
(is ‹?lhs ≥ 0›)
proof -
wlog ordered[simp]: ‹a ≤ b› ‹b ≤ c› generalizing a b c keeping a0 b0 c0
apply (rule rev_mp[OF c0]; rule rev_mp[OF b0]; rule rev_mp[OF a0])
apply (rule linorder_wlog_3[of _ a b c])
apply (simp add: algebra_simps)
by (simp add: hypothesis)
from ordered have [simp]: ‹a ≤ c›
by linarith
have ‹?lhs = (c - b) * (c^k * (c - a) - b^k * (b - a)) + a^k * (c - a) * (b - a)›
by (simp add: algebra_simps)
also have ‹… ≥ 0›
by (auto intro!: add_nonneg_nonneg mult_nonneg_nonneg mult_mono power_mono zero_le_power simp: a0 b0 c0)
finally show ‹?lhs ≥ 0›
by -
qed
text ‹The following illustrates how facts already proven before a @{command wlog} can be still be used after the wlog.
The example does not do anything useful.›
lemma ‹A ⟹ B ⟹ A ∧ B›
proof -
have test1: ‹1=1› by simp
assume a: ‹A›
then have test2: ‹A ∨ 1≠2› by simp
assume b: ‹B›
with a have test3: ‹A ∧ B› by simp
wlog true: ‹True› generalizing A B keeping b
using negation by blast
text ‹The already proven theorems cannot be accessed directly anymore (wlog starts a new proof block).
Recovered versions are available, however:›
thm wlog_keep.test1
thm wlog_keep.test2
thm wlog_keep.test3
oops
end