[STATEMENT]
lemma s1_s2:
  assumes "x < q" "a < q" "b < q" and r:"r < q" "y < q"
  shows "((x + a) mod q * b + q - (a * b + q - r) mod q) mod q =
          (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
have s: "(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q
                 = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
have lhs: "(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x*b + r) mod q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
let ?h = "(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
have "[?h = x * y + q - (x * ((y + (q - b)) mod q) + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * ((y + (q - b)) mod q) + (q - r)) mod q] (mod q)
[PROOF STEP]
by(simp add: assms(1) cong_def q_gt_0)
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * ((y + (q - b)) mod q) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * ((y + (q - b)) mod q) + (q - r)) mod q] (mod q)
[PROOF STEP]
have "[?h = x * y + q - (x * (y + (q - b)) + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * ((y + (q - b)) mod q) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * (y + (q - b)) + (q - r)) mod q] (mod q)
[PROOF STEP]
by (metis mod_add_left_eq mod_mult_right_eq)
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * (y + (q - b)) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * (y + (q - b)) + (q - r)) mod q] (mod q)
[PROOF STEP]
have no_qq: "[?h = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * (y + (q - b)) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
by(metis distrib_left)
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
have "[?h = q*q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
have "[x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q*q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
by (smt qq_cong  add.assoc cong_diff_nat cong_def le_add2 le_trans mod_le_divisor q_gt_0)
[PROOF STATE]
proof (state)
this:
[x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
using cong_trans no_qq
[PROOF STATE]
proof (prove)
using this:
[x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
\<lbrakk>[?b = ?c] (mod ?a); [?c = ?d] (mod ?a)\<rbrakk> \<Longrightarrow> [?b = ?d] (mod ?a)
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
have mod: "[?h = q + q*q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
by (smt Nat.add_diff_assoc cong_def add.assoc add.commute le_add2 le_trans mod_add_self2 mod_le_divisor q_gt_0)
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
[PROOF STEP]
have "[?h = q + q*q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
have 1: "q \<ge> q - b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. q - b \<le> q
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
x < q
a < q
b < q
r < q
y < q

goal (1 subgoal):
 1. q - b \<le> q
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
q - b \<le> q

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
q - b \<le> q
[PROOF STEP]
have  "q*q \<ge> x*(q-b)" "q \<ge> q - r"
[PROOF STATE]
proof (prove)
using this:
q - b \<le> q

goal (1 subgoal):
 1. x * (q - b) \<le> q * q &&& q - r \<le> q
[PROOF STEP]
using 1  assms
[PROOF STATE]
proof (prove)
using this:
q - b \<le> q
q - b \<le> q
x < q
a < q
b < q
r < q
y < q

goal (1 subgoal):
 1. x * (q - b) \<le> q * q &&& q - r \<le> q
[PROOF STEP]
apply (auto simp add: mult_strict_mono)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>x < q; a < q; b < q; r < q; y < q\<rbrakk> \<Longrightarrow> x * (q - b) \<le> q * q
[PROOF STEP]
by (simp add: mult_le_mono)
[PROOF STATE]
proof (state)
this:
x * (q - b) \<le> q * q
q - r \<le> q

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x * (q - b) \<le> q * q
q - r \<le> q
[PROOF STEP]
have "q + q*q + x * y + q  > x * y + x * (q - b) + (q - r)"
[PROOF STATE]
proof (prove)
using this:
x * (q - b) \<le> q * q
q - r \<le> q

goal (1 subgoal):
 1. x * y + x * (q - b) + (q - r) < q + q * q + x * y + q
[PROOF STEP]
using assms(5)
[PROOF STATE]
proof (prove)
using this:
x * (q - b) \<le> q * q
q - r \<le> q
y < q

goal (1 subgoal):
 1. x * y + x * (q - b) + (q - r) < q + q * q + x * y + q
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
x * y + x * (q - b) + (q - r) < q + q * q + x * y + q

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x * y + x * (q - b) + (q - r) < q + q * q + x * y + q
[PROOF STEP]
have "[q + q*q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q*q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)"
[PROOF STATE]
proof (prove)
using this:
x * y + x * (q - b) + (q - r) < q + q * q + x * y + q

goal (1 subgoal):
 1. [q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
using minus_mod
[PROOF STATE]
proof (prove)
using this:
x * y + x * (q - b) + (q - r) < q + q * q + x * y + q
?b < ?a \<Longrightarrow> [?a - ?b mod q = ?a - ?b] (mod q)

goal (1 subgoal):
 1. [q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
[q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
using mod
[PROOF STATE]
proof (prove)
using this:
[q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
using cong_trans
[PROOF STATE]
proof (prove)
using this:
[q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r)) mod q] (mod q)
\<lbrakk>[?b = ?c] (mod ?a); [?c = ?d] (mod ?a)\<rbrakk> \<Longrightarrow> [?b = ?d] (mod ?a)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)
[PROOF STEP]
have "[?h = q + q*q + x * y + q - (x * y + (x * q - x*b) + (q - r))] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + x * (q - b) + (q - r))] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + (x * q - x * b) + (q - r))] (mod q)
[PROOF STEP]
by (simp add: right_diff_distrib')
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + (x * q - x * b) + (q - r))] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + (x * q - x * b) + (q - r))] (mod q)
[PROOF STEP]
have "[?h = q + q*q + x * y + q - x * y - (x * q - x*b) - (q - r)] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - (x * y + (x * q - x * b) + (q - r))] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - x * y - (x * q - x * b) - (q - r)] (mod q)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - x * y - (x * q - x * b) - (q - r)] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - x * y - (x * q - x * b) - (q - r)] (mod q)
[PROOF STEP]
have mod': "[?h = q + q*q + q - (x * q - x*b) - (q - r)] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + x * y + q - x * y - (x * q - x * b) - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - (x * q - x * b) - (q - r)] (mod q)
[PROOF STEP]
by(simp add: add.commute)
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - (x * q - x * b) - (q - r)] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - (x * q - x * b) - (q - r)] (mod q)
[PROOF STEP]
have neg: "[?h = q + q*q + q - x * q +  x*b - (q - r)] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - (x * q - x * b) - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - (x * q - x * b) - (q - r)] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
have "[q + q*q + q - (x * q - x*b) - (q - r) = q + q*q + q - x * q + x*b - (q - r)] (mod q)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
proof(cases "x = 0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. x = 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
 2. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
x = 0

goal (2 subgoals):
 1. x = 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
 2. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
x = 0

goal (1 subgoal):
 1. [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
[q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
x \<noteq> 0

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
have "x * q - x*b > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < x * q - x * b
[PROOF STEP]
using False assms
[PROOF STATE]
proof (prove)
using this:
x \<noteq> 0
x < q
a < q
b < q
r < q
y < q

goal (1 subgoal):
 1. 0 < x * q - x * b
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
0 < x * q - x * b

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
0 < x * q - x * b

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
have "q + q*q + q - x * q > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < q + q * q + q - x * q
[PROOF STEP]
by (metis assms(1) add.commute diff_mult_distrib2 less_Suc_eq mult.commute mult_Suc_right nat_0_less_mult_iff q_gt_0 zero_less_diff)
[PROOF STATE]
proof (state)
this:
0 < q + q * q + q - x * q

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
0 < x * q - x * b
0 < q + q * q + q - x * q
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
0 < x * q - x * b
0 < q + q * q + q - x * q

goal (1 subgoal):
 1. [q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
[q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
[q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - (x * q - x * b) - (q - r)] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
using mod' cong_trans
[PROOF STATE]
proof (prove)
using this:
[q + q * q + q - (x * q - x * b) - (q - r) = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - (x * q - x * b) - (q - r)] (mod q)
\<lbrakk>[?b = ?c] (mod ?a); [?c = ?d] (mod ?a)\<rbrakk> \<Longrightarrow> [?b = ?d] (mod ?a)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)
[PROOF STEP]
have "[?h = q + q*q + q +  x*b - (q - r)] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
have "[q + q*q + q - x * q +  x*b - (q - r) = q + q*q + q +  x*b - (q - r)] (mod q)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
proof(cases "x = 0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. x = 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
 2. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
x = 0

goal (2 subgoals):
 1. x = 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
 2. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
x = 0

goal (1 subgoal):
 1. [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
[q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
x \<noteq> 0

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
have "q*q > x*q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x * q < q * q
[PROOF STEP]
using False assms
[PROOF STATE]
proof (prove)
using this:
x \<noteq> 0
x < q
a < q
b < q
r < q
y < q

goal (1 subgoal):
 1. x * q < q * q
[PROOF STEP]
by (simp add: mult_strict_mono)
[PROOF STATE]
proof (state)
this:
x * q < q * q

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x * q < q * q
[PROOF STEP]
have 1: "q + q*q + q - x * q +  x*b - (q - r) > 0"
[PROOF STATE]
proof (prove)
using this:
x * q < q * q

goal (1 subgoal):
 1. 0 < q + q * q + q - x * q + x * b - (q - r)
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
0 < q + q * q + q - x * q + x * b - (q - r)

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 < q + q * q + q - x * q + x * b - (q - r)
[PROOF STEP]
have 2: "q + q*q + q +  x*b - (q - r) > 0"
[PROOF STATE]
proof (prove)
using this:
0 < q + q * q + q - x * q + x * b - (q - r)

goal (1 subgoal):
 1. 0 < q + q * q + q + x * b - (q - r)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
0 < q + q * q + q + x * b - (q - r)

goal (1 subgoal):
 1. x \<noteq> 0 \<Longrightarrow> [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 < q + q * q + q + x * b - (q - r)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
0 < q + q * q + q + x * b - (q - r)

goal (1 subgoal):
 1. [q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
by (smt 1 2 Nat.add_diff_assoc2 \<open>x * q < q * q\<close> add_cancel_left_left add_diff_inverse_nat
                le_add1 le_add2 le_trans less_imp_add_positive less_numeral_extra(3) minus_mod
                minus_q_mult_cancel mod_if mult.commute q_gt_0)
[PROOF STATE]
proof (state)
this:
[q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
[q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q) \<Longrightarrow> [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
using cong_trans neg
[PROOF STATE]
proof (prove)
using this:
[q + q * q + q - x * q + x * b - (q - r) = q + q * q + q + x * b - (q - r)] (mod q)
\<lbrakk>[?b = ?c] (mod ?a); [?c = ?d] (mod ?a)\<rbrakk> \<Longrightarrow> [?b = ?d] (mod ?a)
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q - x * q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)
[PROOF STEP]
have "[?h = q + q*q + q +  x*b - q + r] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - (q - r)] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - q + r] (mod q)
[PROOF STEP]
by (metis r(1) Nat.add_diff_assoc2 Nat.diff_diff_right le_add2 less_imp_le_nat semiring_normalization_rules(23))
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - q + r] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - q + r] (mod q)
[PROOF STEP]
have "[?h = q + q*q + q +  x*b + r] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b - q + r] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b + r] (mod q)
[PROOF STEP]
apply(simp add: cong_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (q * q + (q + x * b) + r) mod q \<Longrightarrow> (q * q + (q + x * b) + r) mod q = (q + q * q + q + x * b + r) mod q
[PROOF STEP]
by (metis (no_types, lifting) add.assoc add.commute add_diff_cancel_right' diff_is_0_eq' mod_if mod_le_divisor q_gt_0)
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b + r] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b + r] (mod q)
[PROOF STEP]
have "[?h = x*b + r] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = q + q * q + q + x * b + r] (mod q)

goal (1 subgoal):
 1. [(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * b + r] (mod q)
[PROOF STEP]
apply(simp add: cong_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (q + q * q + q + x * b + r) mod q \<Longrightarrow> (q + q * q + q + x * b + r) mod q = (x * b + r) mod q
[PROOF STEP]
by (metis mod_add_cong mod_add_self1 mod_mult_self1)
[PROOF STATE]
proof (state)
this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * b + r] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * b + r] (mod q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = x * b + r] (mod q)

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
by (simp add: cong_def assms)
[PROOF STATE]
proof (state)
this:
(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
have rhs: "((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x*b + r) mod q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
let ?h = "((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
have "[?h =  (x + a) mod q * b + q - (a * b + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) mod q * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
by (simp add: q_gt_0  assms(1) cong_def)
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) mod q * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) mod q * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
have "[?h = (x + a) * b + q - (a * b + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) mod q * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
by (smt Nat.add_diff_assoc cong_def mod_add_cong mod_le_divisor mod_mult_left_eq q_gt_0 assms)
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
have "[?h = x*b + a*b + q - (a * b + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x + a) * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
by(metis distrib_right)
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
have mod: "[?h = q + x*b + a*b + q - (a * b + (q - r)) mod q] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
by (smt Nat.add_diff_assoc cong_def add.assoc add.commute le_add2 le_trans mod_add_self2 mod_le_divisor q_gt_0)
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)
[PROOF STEP]
have "[?h =  q + x*b + a*b + q - (a * b + (q - r))] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
using  q_cong assms(1)
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)
[?a = q + ?a] (mod q)
x < q

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q); \<And>a. [a = q + a] (mod q); x < q\<rbrakk> \<Longrightarrow> [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
have ge: "q + x*b + a*b + q  > (a * b + (q - r))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a * b + (q - r) < q + x * b + a * b + q
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
x < q
a < q
b < q
r < q
y < q

goal (1 subgoal):
 1. a * b + (q - r) < q + x * b + a * b + q
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
a * b + (q - r) < q + x * b + a * b + q

goal (1 subgoal):
 1. \<lbrakk>[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q); \<And>a. [a = q + a] (mod q); x < q\<rbrakk> \<Longrightarrow> [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
a * b + (q - r) < q + x * b + a * b + q
[PROOF STEP]
have "[ q + x*b + a*b + q - (a * b + (q - r)) mod q =  q + x*b + a*b + q - (a * b + (q - r))] (mod q)"
[PROOF STATE]
proof (prove)
using this:
a * b + (q - r) < q + x * b + a * b + q

goal (1 subgoal):
 1. [q + x * b + a * b + q - (a * b + (q - r)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
using Divides.mod_less_eq_dividend cong_diff_nat  cong_def le_trans less_not_refl2
                  less_or_eq_imp_le q_gt_0 minus_mod
[PROOF STATE]
proof (prove)
using this:
a * b + (q - r) < q + x * b + a * b + q
(0::?'a) \<le> ?a \<Longrightarrow> ?a mod ?b \<le> ?a
\<lbrakk>[?a = ?b] (mod ?m); [?c = ?d] (mod ?m); ?c \<le> ?a; ?d \<le> ?b\<rbrakk> \<Longrightarrow> [?a - ?c = ?b - ?d] (mod ?m)
[?b = ?c] (mod ?a) = (?b mod ?a = ?c mod ?a)
\<lbrakk>?i \<le> ?j; ?j \<le> ?k\<rbrakk> \<Longrightarrow> ?i \<le> ?k
?n < ?m \<Longrightarrow> ?m \<noteq> ?n
?m < ?n \<or> ?m = ?n \<Longrightarrow> ?m \<le> ?n
0 < q
?b < ?a \<Longrightarrow> [?a - ?b mod q = ?a - ?b] (mod q)

goal (1 subgoal):
 1. [q + x * b + a * b + q - (a * b + (q - r)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
by presburger
[PROOF STATE]
proof (state)
this:
[q + x * b + a * b + q - (a * b + (q - r)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)

goal (1 subgoal):
 1. \<lbrakk>[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q); \<And>a. [a = q + a] (mod q); x < q\<rbrakk> \<Longrightarrow> [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[q + x * b + a * b + q - (a * b + (q - r)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[q + x * b + a * b + q - (a * b + (q - r)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
using mod cong_trans
[PROOF STATE]
proof (prove)
using this:
[q + x * b + a * b + q - (a * b + (q - r)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r)) mod q] (mod q)
\<lbrakk>[?b = ?c] (mod ?a); [?c = ?d] (mod ?a)\<rbrakk> \<Longrightarrow> [?b = ?d] (mod ?a)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)
[PROOF STEP]
have "[?h =  q + x*b + q - (q - r)] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + a * b + q - (a * b + (q - r))] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - (q - r)] (mod q)
[PROOF STEP]
by (simp add: add.commute)
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - (q - r)] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - (q - r)] (mod q)
[PROOF STEP]
have "[?h =  q + x*b + q - q + r] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - (q - r)] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - q + r] (mod q)
[PROOF STEP]
by (metis Nat.add_diff_assoc2 Nat.diff_diff_right r(1) le_add2 less_imp_le_nat)
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - q + r] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - q + r] (mod q)
[PROOF STEP]
have "[?h = q + x*b + r] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + q - q + r] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + r] (mod q)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + r] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + r] (mod q)
[PROOF STEP]
have "[?h = q + (x*b + r)] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + r] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + (x * b + r)] (mod q)
[PROOF STEP]
using add.assoc
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + x * b + r] (mod q)
?a + ?b + ?c = ?a + (?b + ?c)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + (x * b + r)] (mod q)
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + (x * b + r)] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + (x * b + r)] (mod q)
[PROOF STEP]
have "[?h = x*b + r] (mod q)"
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + (x * b + r)] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + r] (mod q)
[PROOF STEP]
using cong_def q_cong_reverse
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = q + (x * b + r)] (mod q)
[?b = ?c] (mod ?a) = (?b mod ?a = ?c mod ?a)
[q + ?a = ?a] (mod q)

goal (1 subgoal):
 1. [((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + r] (mod q)
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + r] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + r] (mod q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = x * b + r] (mod q)

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
by (simp add: cong_def assms(1))
[PROOF STATE]
proof (state)
this:
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = (x * b + r) mod q
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * b + r) mod q

goal (1 subgoal):
 1. (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q

goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
have lhs:"((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
x < q
a < q
b < q
r < q
y < q

goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q

goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
have rhs: "(x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
x < q
a < q
b < q
r < q
y < q

goal (1 subgoal):
 1. (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q

goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
have " ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q
[PROOF STEP]
using assms s[symmetric]
[PROOF STATE]
proof (prove)
using this:
x < q
a < q
b < q
r < q
y < q
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q

goal (1 subgoal):
 1. ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q

goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q

goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
using lhs rhs
[PROOF STATE]
proof (prove)
using this:
((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q
((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = ((x + a) mod q * b + (q - (a * b + (q - r)) mod q)) mod q
(x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q = (x * y + (q - (x * ((y + (q - b)) mod q) + (q - r)) mod q)) mod q

goal (1 subgoal):
 1. ((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
((x + a) mod q * b + q - (a * b + q - r) mod q) mod q = (x * y + q - (x * ((y + q - b) mod q) + q - r) mod q) mod q

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma (in order_topology) order_tendstoI:
  "(\<And>a. a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F) \<Longrightarrow> (\<And>a. y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F) \<Longrightarrow>
    (f \<longlongrightarrow> y) F"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<And>a. a < y \<Longrightarrow> \<forall>\<^sub>F x in F. a < f x; \<And>a. y < a \<Longrightarrow> \<forall>\<^sub>F x in F. f x < a\<rbrakk> \<Longrightarrow> (f \<longlongrightarrow> y) F
[PROOF STEP]
by (auto simp: order_tendsto_iff)


[STATEMENT]
lemma fds_integral_diff: "fds_integral (a - b) (f - g) = fds_integral a f - fds_integral b g"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. fds_integral (a - b) (f - g) = fds_integral a f - fds_integral b g
[PROOF STEP]
by (rule fds_eqI) (auto simp: fds_integral_def scaleR_diff_right)


[STATEMENT]
lemma (in jozsa) f_const_has_max_value:
  assumes "const 0 \<or> const 1"
  shows "(cmod (\<Sum>k<(2::nat)^n. (-1)^(f k)))\<^sup>2 = (2::nat)^(2*n)"
  and "(cmod (\<Sum>k<(2::nat)^n. (-1)^(f k + 1)))\<^sup>2 = (2::nat)^(2*n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (cmod (\<Sum>k<2 ^ n. (- 1) ^ f k))\<^sup>2 = real (2 ^ (2 * n)) &&& (cmod (\<Sum>k<2 ^ n. (- 1) ^ (f k + 1)))\<^sup>2 = real (2 ^ (2 * n))
[PROOF STEP]
using aux_comp_with_cmod[of n "\<lambda>k. f k"] aux_comp_with_cmod[of n "\<lambda>k. f k + 1"] const_def assms
[PROOF STATE]
proof (prove)
using this:
(\<forall>x<2 ^ n. f x = 0) \<or> (\<forall>x<2 ^ n. f x = 1) \<Longrightarrow> (cmod (\<Sum>k<2 ^ n. (- 1) ^ f k))\<^sup>2 = 2 ^ (2 * n)
(\<forall>x<2 ^ n. f x + 1 = 0) \<or> (\<forall>x<2 ^ n. f x + 1 = 1) \<Longrightarrow> (cmod (\<Sum>k<2 ^ n. (- 1) ^ (f k + 1)))\<^sup>2 = 2 ^ (2 * n)
const ?c = (\<forall>x\<in>{i. i < 2 ^ n}. f x = ?c)
const 0 \<or> const 1

goal (1 subgoal):
 1. (cmod (\<Sum>k<2 ^ n. (- 1) ^ f k))\<^sup>2 = real (2 ^ (2 * n)) &&& (cmod (\<Sum>k<2 ^ n. (- 1) ^ (f k + 1)))\<^sup>2 = real (2 ^ (2 * n))
[PROOF STEP]
by auto


[STATEMENT]
lemma residue_diff:
  assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}"
      and g_holo:"g holomorphic_on s - {z}"
  shows "residue (\<lambda>z. f z - g z) z= residue f z - residue g z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. residue (\<lambda>z. f z - g z) z = residue f z - residue g z
[PROOF STEP]
using residue_add[OF assms(1,2,3),of "\<lambda>z. - g z"] residue_neg[OF assms(1,2,4)]
[PROOF STATE]
proof (prove)
using this:
(\<lambda>z. - g z) holomorphic_on s - {z} \<Longrightarrow> residue (\<lambda>z. f z + - g z) z = residue f z + residue (\<lambda>z. - g z) z
residue (\<lambda>z. - g z) z = - residue g z

goal (1 subgoal):
 1. residue (\<lambda>z. f z - g z) z = residue f z - residue g z
[PROOF STEP]
by (auto intro:holomorphic_intros g_holo)


[STATEMENT]
lemma l9_18_3:
  assumes "Coplanar A B C P" and
    "Col X Y P"
  shows "A B C TSP X Y \<longleftrightarrow> (Bet X P Y \<and> \<not> Coplanar A B C X \<and> \<not> Coplanar A B C Y)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (A B CTSP X Y) = (Bet X P Y \<and> \<not> Coplanar A B C X \<and> \<not> Coplanar A B C Y)
[PROOF STEP]
by (meson TSP_def assms(1) assms(2) l9_39 not_bet_out not_col_permutation_5 tsp_distincts)


[STATEMENT]
lemma soundnessFCut: "[| validS (C # Gamma); validS (FNot C # Delta) |] ==> validS (Gamma @ Delta)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>validS (C # Gamma); validS (FNot C # Delta)\<rbrakk> \<Longrightarrow> validS (Gamma @ Delta)
[PROOF STEP]
(*  apply(force simp: validS_def evalS_append evalS_cons evalF_FNot)*)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>validS (C # Gamma); validS (FNot C # Delta)\<rbrakk> \<Longrightarrow> validS (Gamma @ Delta)
[PROOF STEP]
apply (simp add: validS_def, rule, rule)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>M phi. \<lbrakk>\<forall>M. \<forall>phi\<in>modelAssigns M. evalF M phi C \<or> evalS M phi Gamma; \<forall>M. \<forall>phi\<in>modelAssigns M. evalF M phi (FNot C) \<or> evalS M phi Delta; phi \<in> modelAssigns M\<rbrakk> \<Longrightarrow> evalS M phi (Gamma @ Delta)
[PROOF STEP]
apply(drule_tac x=M in spec)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>M phi. \<lbrakk>\<forall>M. \<forall>phi\<in>modelAssigns M. evalF M phi (FNot C) \<or> evalS M phi Delta; phi \<in> modelAssigns M; \<forall>phi\<in>modelAssigns M. evalF M phi C \<or> evalS M phi Gamma\<rbrakk> \<Longrightarrow> evalS M phi (Gamma @ Delta)
[PROOF STEP]
apply(drule_tac x=M in spec)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>M phi. \<lbrakk>phi \<in> modelAssigns M; \<forall>phi\<in>modelAssigns M. evalF M phi C \<or> evalS M phi Gamma; \<forall>phi\<in>modelAssigns M. evalF M phi (FNot C) \<or> evalS M phi Delta\<rbrakk> \<Longrightarrow> evalS M phi (Gamma @ Delta)
[PROOF STEP]
apply(drule_tac x=phi in bspec)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>M phi. \<lbrakk>phi \<in> modelAssigns M; \<forall>phi\<in>modelAssigns M. evalF M phi (FNot C) \<or> evalS M phi Delta\<rbrakk> \<Longrightarrow> phi \<in> modelAssigns M
 2. \<And>M phi. \<lbrakk>phi \<in> modelAssigns M; \<forall>phi\<in>modelAssigns M. evalF M phi (FNot C) \<or> evalS M phi Delta; evalF M phi C \<or> evalS M phi Gamma\<rbrakk> \<Longrightarrow> evalS M phi (Gamma @ Delta)
[PROOF STEP]
apply assumption
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>M phi. \<lbrakk>phi \<in> modelAssigns M; \<forall>phi\<in>modelAssigns M. evalF M phi (FNot C) \<or> evalS M phi Delta; evalF M phi C \<or> evalS M phi Gamma\<rbrakk> \<Longrightarrow> evalS M phi (Gamma @ Delta)
[PROOF STEP]
apply(drule_tac x=phi in bspec)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>M phi. \<lbrakk>phi \<in> modelAssigns M; evalF M phi C \<or> evalS M phi Gamma\<rbrakk> \<Longrightarrow> phi \<in> modelAssigns M
 2. \<And>M phi. \<lbrakk>phi \<in> modelAssigns M; evalF M phi C \<or> evalS M phi Gamma; evalF M phi (FNot C) \<or> evalS M phi Delta\<rbrakk> \<Longrightarrow> evalS M phi (Gamma @ Delta)
[PROOF STEP]
apply assumption
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>M phi. \<lbrakk>phi \<in> modelAssigns M; evalF M phi C \<or> evalS M phi Gamma; evalF M phi (FNot C) \<or> evalS M phi Delta\<rbrakk> \<Longrightarrow> evalS M phi (Gamma @ Delta)
[PROOF STEP]
apply (simp add: evalS_append evalF_FNot, blast)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma boncelet_phrase_length:
  fixes p \<delta> :: real assumes p: "p > 0" "p < 1" and \<delta>: "\<delta> > 0" "\<delta> < 1" "2*p + \<delta> < 2"
  fixes d :: "nat \<Rightarrow> real"
  defines "q \<equiv> 1 - p"
  assumes d_nonneg: "\<And>n. d n \<ge> 0"
  assumes d_rec: "\<And>n. n \<ge> 2 \<Longrightarrow> d n = 1 + p * d (nat \<lfloor>p * real n + \<delta>\<rfloor>) + q * d (nat \<lfloor>q * real n - \<delta>\<rfloor>)"
  shows   "d \<in> \<Theta>(\<lambda>x. ln x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. d \<in> \<Theta>(\<lambda>x. ln (real x))
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
0 < p
p < 1
0 < \<delta>
\<delta> < 1
2 * p + \<delta> < 2
q \<equiv> 1 - p
0 \<le> d ?n
2 \<le> ?n \<Longrightarrow> d ?n = 1 + p * d (nat \<lfloor>p * real ?n + \<delta>\<rfloor>) + q * d (nat \<lfloor>q * real ?n - \<delta>\<rfloor>)

goal (1 subgoal):
 1. d \<in> \<Theta>(\<lambda>x. ln (real x))
[PROOF STEP]
by (master_theorem recursion: d_rec, simp_all)


[STATEMENT]
lemma snd_graph_ran: "snd ` graph m = ran m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. snd ` graph m = ran m
[PROOF STEP]
unfolding graph_def ran_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. snd ` {(a, b) |a b. m a = Some b} = {b. \<exists>a. m a = Some b}
[PROOF STEP]
by force


[STATEMENT]
lemma val_ineq_set_is_semialgebraic':
  assumes "f \<in> carrier (Q\<^sub>p[\<X>\<^bsub>n\<^esub>])"
  assumes "g \<in> carrier (Q\<^sub>p[\<X>\<^bsub>n\<^esub>])"
  shows "is_semialgebraic n {x \<in> carrier (Q\<^sub>p\<^bsup>n\<^esup>). val (Qp_ev f x) \<le> val (Qp_ev g x)}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. is_semialgebraic n {x \<in> carrier (Q\<^sub>p\<^bsup>n\<^esup>). val (eval_at_point Q\<^sub>p x f) \<le> val (eval_at_point Q\<^sub>p x g)}
[PROOF STEP]
using assms val_ineq_set_is_semialgebraic
[PROOF STATE]
proof (prove)
using this:
f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>n\<^esub>])
g \<in> carrier (Q\<^sub>p [\<X>\<^bsub>n\<^esub>])
\<lbrakk>?f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>?n\<^esub>]); ?g \<in> carrier (Q\<^sub>p [\<X>\<^bsub>?n\<^esub>])\<rbrakk> \<Longrightarrow> is_semialgebraic ?n (val_ineq_set ?n ?f ?g)

goal (1 subgoal):
 1. is_semialgebraic n {x \<in> carrier (Q\<^sub>p\<^bsup>n\<^esup>). val (eval_at_point Q\<^sub>p x f) \<le> val (eval_at_point Q\<^sub>p x g)}
[PROOF STEP]
unfolding val_ineq_set_def
[PROOF STATE]
proof (prove)
using this:
f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>n\<^esub>])
g \<in> carrier (Q\<^sub>p [\<X>\<^bsub>n\<^esub>])
\<lbrakk>?f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>?n\<^esub>]); ?g \<in> carrier (Q\<^sub>p [\<X>\<^bsub>?n\<^esub>])\<rbrakk> \<Longrightarrow> is_semialgebraic ?n {x \<in> carrier (Q\<^sub>p\<^bsup>?n\<^esup>). val (eval_at_point Q\<^sub>p x ?f) \<le> val (eval_at_point Q\<^sub>p x ?g)}

goal (1 subgoal):
 1. is_semialgebraic n {x \<in> carrier (Q\<^sub>p\<^bsup>n\<^esup>). val (eval_at_point Q\<^sub>p x f) \<le> val (eval_at_point Q\<^sub>p x g)}
[PROOF STEP]
by blast


[STATEMENT]
lemma fPow_transfer [transfer_rule]:
  "(rel_fset A ===> rel_fset (rel_fset A)) fPow fPow"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (rel_fset A ===> rel_fset (rel_fset A)) fPow fPow
[PROOF STEP]
unfolding rel_fun_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>x y. rel_fset A x y \<longrightarrow> rel_fset (rel_fset A) (fPow x) (fPow y)
[PROOF STEP]
using Pow_transfer[unfolded rel_fun_def, rule_format, Transfer.transferred]
[PROOF STATE]
proof (prove)
using this:
rel_fset ?A ?x ?y \<Longrightarrow> rel_fset (rel_fset ?A) (fPow ?x) (fPow ?y)

goal (1 subgoal):
 1. \<forall>x y. rel_fset A x y \<longrightarrow> rel_fset (rel_fset A) (fPow x) (fPow y)
[PROOF STEP]
by blast


[STATEMENT]
lemma lborel_affine:
  fixes t :: "'a::euclidean_space"
  shows "c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c *\<^sub>R x)) (\<lambda>_. \<bar>c\<bar>^DIM('a))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c *\<^sub>R x)) (\<lambda>x. ennreal (\<bar>c\<bar> ^ DIM('a)))
[PROOF STEP]
using lborel_affine_euclidean[where c="\<lambda>_::'a. c" and t=t]
[PROOF STATE]
proof (prove)
using this:
(\<And>j. j \<in> Basis \<Longrightarrow> c \<noteq> 0) \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + (\<Sum>j\<in>Basis. (c * (x \<bullet> j)) *\<^sub>R j))) (\<lambda>x. ennreal (\<Prod>j\<in>Basis. \<bar>c\<bar>))

goal (1 subgoal):
 1. c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c *\<^sub>R x)) (\<lambda>x. ennreal (\<bar>c\<bar> ^ DIM('a)))
[PROOF STEP]
unfolding scaleR_scaleR[symmetric] scaleR_sum_right[symmetric] euclidean_representation prod_constant
[PROOF STATE]
proof (prove)
using this:
(\<And>j. j \<in> Basis \<Longrightarrow> c \<noteq> 0) \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c *\<^sub>R x)) (\<lambda>x. ennreal (\<bar>c\<bar> ^ DIM('a)))

goal (1 subgoal):
 1. c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c *\<^sub>R x)) (\<lambda>x. ennreal (\<bar>c\<bar> ^ DIM('a)))
[PROOF STEP]
by simp


[STATEMENT]
theorem factorial_condition_one: (* Jacobson theorem 2.21 *)
  "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G \<longleftrightarrow> factorial_monoid G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (divisor_chain_condition_monoid G \<and> primeness_condition_monoid G) = factorial_monoid G
[PROOF STEP]
proof (rule iffI, clarify)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>divisor_chain_condition_monoid G; primeness_condition_monoid G\<rbrakk> \<Longrightarrow> factorial_monoid G
 2. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
assume dcc: "divisor_chain_condition_monoid G"
    and pc: "primeness_condition_monoid G"
[PROOF STATE]
proof (state)
this:
divisor_chain_condition_monoid G
primeness_condition_monoid G

goal (2 subgoals):
 1. \<lbrakk>divisor_chain_condition_monoid G; primeness_condition_monoid G\<rbrakk> \<Longrightarrow> factorial_monoid G
 2. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
interpret divisor_chain_condition_monoid "G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. divisor_chain_condition_monoid G
[PROOF STEP]
by (rule dcc)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>divisor_chain_condition_monoid G; primeness_condition_monoid G\<rbrakk> \<Longrightarrow> factorial_monoid G
 2. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
interpret primeness_condition_monoid "G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. primeness_condition_monoid G
[PROOF STEP]
by (rule pc)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>divisor_chain_condition_monoid G; primeness_condition_monoid G\<rbrakk> \<Longrightarrow> factorial_monoid G
 2. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
show "factorial_monoid G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. factorial_monoid G
[PROOF STEP]
by (fast intro: factorial_monoidI wfactors_exist wfactors_unique)
[PROOF STATE]
proof (state)
this:
factorial_monoid G

goal (1 subgoal):
 1. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
assume "factorial_monoid G"
[PROOF STATE]
proof (state)
this:
factorial_monoid G

goal (1 subgoal):
 1. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
factorial_monoid G
[PROOF STEP]
interpret factorial_monoid "G"
[PROOF STATE]
proof (prove)
using this:
factorial_monoid G

goal (1 subgoal):
 1. factorial_monoid G
[PROOF STEP]
.
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. factorial_monoid G \<Longrightarrow> divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. divisor_chain_condition_monoid G \<and> primeness_condition_monoid G
[PROOF STEP]
by rule unfold_locales
[PROOF STATE]
proof (state)
this:
divisor_chain_condition_monoid G \<and> primeness_condition_monoid G

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma f_Exec_Stream_Acc_Output_nth: "
  \<lbrakk> 0 < k; n < length xs \<rbrakk> \<Longrightarrow>
  f_Exec_Comp_Stream_Acc_Output k output_fun trans_fun xs c ! n =
  last_message (map output_fun (
    f_Exec_Comp_Stream trans_fun (xs ! n # \<NoMsg>\<^bsup>k - Suc 0\<^esup>) (
      f_Exec_Comp trans_fun (xs \<down> n \<odot>\<^sub>f k) c)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < k; n < length xs\<rbrakk> \<Longrightarrow> f_Exec_Comp_Stream_Acc_Output k output_fun trans_fun xs c ! n = last_message (map output_fun (f_Exec_Comp_Stream trans_fun (xs ! n # NoMsg\<^bsup>k - Suc 0\<^esup>) (f_Exec_Comp trans_fun (xs \<down> n \<odot> k) c)))
[PROOF STEP]
by (unfold f_Exec_Comp_Stream_Acc_Output_def f_shrink_def, rule f_Exec_Stream_expand_aggregate_map_nth)


[STATEMENT]
lemma fact_less_mono: "0 < m \<Longrightarrow> m < n \<Longrightarrow> fact m < (fact n :: 'a::linordered_semidom)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < m; m < n\<rbrakk> \<Longrightarrow> fact m < fact n
[PROOF STEP]
by (metis of_nat_fact of_nat_less_iff fact_less_mono_nat)


[STATEMENT]
lemma is_projection_on_fixes_image:
  fixes M :: \<open>'a::metric_space set\<close>
  assumes a1: "is_projection_on \<pi> M" and a3: "x \<in> M"
  shows "\<pi> x = x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<pi> x = x
[PROOF STEP]
by (metis a1 a3 dist_pos_lt dist_self is_arg_min_def is_projection_on_def)


[STATEMENT]
lemma norm_cos_sin [simp]: "norm (Complex (cos t) (sin t)) = 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cmod (Complex (cos t) (sin t)) = 1
[PROOF STEP]
by (simp add: norm_complex_def)


[STATEMENT]
lemma has_field_derivative_Beta1 [derivative_intros]:
  assumes "x \<notin> \<int>\<^sub>\<le>\<^sub>0" "x + y \<notin> \<int>\<^sub>\<le>\<^sub>0"
  shows   "((\<lambda>x. Beta x y) has_field_derivative (Beta x y * (Digamma x - Digamma (x + y))))
               (at x within A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. Beta x y) has_field_derivative Beta x y * (Digamma x - Digamma (x + y))) (at x within A)
[PROOF STEP]
unfolding Beta_altdef
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. Gamma x * Gamma y * rGamma (x + y)) has_field_derivative Gamma x * Gamma y * rGamma (x + y) * (Digamma x - Digamma (x + y))) (at x within A)
[PROOF STEP]
by (rule DERIV_cong, (rule derivative_intros assms)+) (simp add: algebra_simps)


[STATEMENT]
lemma mat_rep_num_MM_Rel:
  assumes "MM_Rel A B"
  assumes "i < dim_row A"
  shows "mat_rep_num (mat_mod A) i = mat_rep_num B i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat_rep_num (local.mat_mod A) i = mat_rep_num B i
[PROOF STEP]
unfolding mat_rep_num_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. count_vec (row (local.mat_mod A) i) 1 = count_vec (row B i) 1
[PROOF STEP]
using vec_count_MV_Rel_direct assms mat_mod_vec_mod_row row_map_mat
[PROOF STATE]
proof (prove)
using this:
MV_Rel ?v1.0 ?v2.0 \<Longrightarrow> count_vec ?v2.0 ?i = count_vec (vec_mod ?v1.0) (to_int_mod_ring ?i)
MM_Rel A B
i < dim_row A
?i < dim_row ?A \<Longrightarrow> row (local.mat_mod ?A) ?i = vec_mod (row ?A ?i)
?i < dim_row ?A \<Longrightarrow> row (map_mat ?f ?A) ?i = map_vec ?f (row ?A ?i)

goal (1 subgoal):
 1. count_vec (row (local.mat_mod A) i) 1 = count_vec (row B i) 1
[PROOF STEP]
by (metis MM_Rel_def MV_Rel_def index_map_mat(2) mat_mod_dim(1) to_int_mod_ring_hom.hom_one)


[STATEMENT]
lemma Fourier_sum_offset_unpaired:
  fixes f :: "real \<Rightarrow> real"
  assumes f: "f absolutely_integrable_on {-pi..pi}" and periodic: "\<And>x. f(x + 2*pi) = f x"
  shows  "(\<Sum>k\<le>2*n. Fourier_coefficient f k * trigonometric_set k t) =
          (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f(x+t)) (2*k) * trigonometric_set (2*k) 0)"
  (is "?lhs = ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
have "?lhs = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f(x+t)) (2*k) *  trigonometric_set (2*k) 0 +
                   Fourier_coefficient (\<lambda>x. f(x+t)) (Suc (2*k)) * trigonometric_set (Suc (2*k)) 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0 + Fourier_coefficient (\<lambda>x. f (x + t)) (Suc (2 * k)) * trigonometric_set (Suc (2 * k)) 0)
[PROOF STEP]
apply (simp add: assms Fourier_sum_offset)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient (\<lambda>x. f (x + t)) k * trigonometric_set k 0) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0 + Fourier_coefficient (\<lambda>x. f (x + t)) (Suc (2 * k)) * trigonometric_set (Suc (2 * k)) 0)
[PROOF STEP]
apply (subst sum.in_pairs_0 [symmetric])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient (\<lambda>x. f (x + t)) k * trigonometric_set k 0) = (\<Sum>a\<le>Suc (2 * n). Fourier_coefficient (\<lambda>x. f (x + t)) a * trigonometric_set a 0)
[PROOF STEP]
by (simp add: trigonometric_set)
[PROOF STATE]
proof (state)
this:
(\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0 + Fourier_coefficient (\<lambda>x. f (x + t)) (Suc (2 * k)) * trigonometric_set (Suc (2 * k)) 0)

goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0 + Fourier_coefficient (\<lambda>x. f (x + t)) (Suc (2 * k)) * trigonometric_set (Suc (2 * k)) 0)

goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
have "\<dots> = ?rhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0 + Fourier_coefficient (\<lambda>x. f (x + t)) (Suc (2 * k)) * trigonometric_set (Suc (2 * k)) 0) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
by (auto simp: trigonometric_set)
[PROOF STATE]
proof (state)
this:
(\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0 + Fourier_coefficient (\<lambda>x. f (x + t)) (Suc (2 * k)) * trigonometric_set (Suc (2 * k)) 0) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)

goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)

goal (1 subgoal):
 1. (\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(\<Sum>k\<le>2 * n. Fourier_coefficient f k * trigonometric_set k t) = (\<Sum>k\<le>n. Fourier_coefficient (\<lambda>x. f (x + t)) (2 * k) * trigonometric_set (2 * k) 0)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma scale_shift_ms_aux_conv_mslmap:
  "scale_shift_ms_aux x = mslmap (map_prod ((*) (fst x)) ((+) (snd x)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. scale_shift_ms_aux x = mslmap (map_prod ((*) (fst x)) ((+) (snd x)))
[PROOF STEP]
by (rule ext) (simp add: scale_shift_ms_aux_def map_prod_def case_prod_unfold)


[STATEMENT]
lemma dom_map_ran: "fst ` set (map_ran f al) = fst ` set al"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. fst ` set (map_ran f al) = fst ` set al
[PROOF STEP]
by (simp add: map_ran_def image_image split_def)


[STATEMENT]
lemma subresultant_swap:
  shows "subresultant J f g = smult ((- 1) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
let ?A = "subresultant_mat J f g"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
let ?k = "degree f - J"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
let ?n = "degree g - J"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have nk: "?n + ?k = ?k + ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. degree g - J + (degree f - J) = degree f - J + (degree g - J)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
degree g - J + (degree f - J) = degree f - J + (degree g - J)

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have change: "j < ?k + ?n \<Longrightarrow> ((if j < ?k then j + ?n else j - ?k) < ?n)
    = (\<not> (j < ?k))" for j
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j < degree f - J + (degree g - J) \<Longrightarrow> ((if j < degree f - J then j + (degree g - J) else j - (degree f - J)) < degree g - J) = (\<not> j < degree f - J)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?j < degree f - J + (degree g - J) \<Longrightarrow> ((if ?j < degree f - J then ?j + (degree g - J) else ?j - (degree f - J)) < degree g - J) = (\<not> ?j < degree f - J)

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have "subresultant J f g = det ?A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. subresultant J f g = det (subresultant_mat J f g)
[PROOF STEP]
unfolding subresultant_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (subresultant_mat J f g) = det (subresultant_mat J f g)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
subresultant J f g = det (subresultant_mat J f g)

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
subresultant J f g = det (subresultant_mat J f g)

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have "\<dots> = (-1)^(?k * ?n) * det (mat (?k + ?n) (?k + ?n) (\<lambda> (i,j).
    ?A $$ (i,(if j < ?k then j + ?n else j - ?k))))" (is "_ = _ * det ?B")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (subresultant_mat J f g) = (- 1) ^ ((degree f - J) * (degree g - J)) * det (mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). subresultant_mat J f g $$ (i, if j < degree f - J then j + (degree g - J) else j - (degree f - J))))
[PROOF STEP]
by (rule det_swap_cols, auto simp: subresultant_mat_def Let_def)
[PROOF STATE]
proof (state)
this:
det (subresultant_mat J f g) = (- 1) ^ ((degree f - J) * (degree g - J)) * det (mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). subresultant_mat J f g $$ (i, if j < degree f - J then j + (degree g - J) else j - (degree f - J))))

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
det (subresultant_mat J f g) = (- 1) ^ ((degree f - J) * (degree g - J)) * det (mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). subresultant_mat J f g $$ (i, if j < degree f - J then j + (degree g - J) else j - (degree f - J))))

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have "?B = subresultant_mat J g f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). subresultant_mat J f g $$ (i, if j < degree f - J then j + (degree g - J) else j - (degree f - J))) = subresultant_mat J g f
[PROOF STEP]
unfolding subresultant_mat_def Let_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). if j < degree g - J then if i = degree f - J + (degree g - J) - 1 then monom (1::'a) (degree g - J - 1 - j) * f else [:coeff_int f (int (degree f) - int i + int j):] else if i = degree f - J + (degree g - J) - 1 then monom (1::'a) (degree f - J - 1 - (j - (degree g - J))) * g else [:coeff_int g (int (degree g) - int i + int (j - (degree g - J))):]) $$ (i, if j < degree f - J then j + (degree g - J) else j - (degree f - J))) = mat (degree g - J + (degree f - J)) (degree g - J + (degree f - J)) (\<lambda>(i, j). if j < degree f - J then if i = degree g - J + (degree f - J) - 1 then monom (1::'a) (degree f - J - 1 - j) * g else [:coeff_int g (int (degree g) - int i + int j):] else if i = degree g - J + (degree f - J) - 1 then monom (1::'a) (degree g - J - 1 - (j - (degree f - J))) * f else [:coeff_int f (int (degree f) - int i + int (j - (degree f - J))):])
[PROOF STEP]
by (rule eq_matI, unfold dim_row_mat dim_col_mat nk index_mat split,
      subst index_mat, (auto)[2], unfold split, subst change, force,
      unfold if_conn, rule if_cong[OF refl if_cong if_cong], auto)
[PROOF STATE]
proof (state)
this:
mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). subresultant_mat J f g $$ (i, if j < degree f - J then j + (degree g - J) else j - (degree f - J))) = subresultant_mat J g f

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
mat (degree f - J + (degree g - J)) (degree f - J + (degree g - J)) (\<lambda>(i, j). subresultant_mat J f g $$ (i, if j < degree f - J then j + (degree g - J) else j - (degree f - J))) = subresultant_mat J g f

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have "det \<dots> = subresultant J g f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (subresultant_mat J g f) = subresultant J g f
[PROOF STEP]
unfolding subresultant_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (subresultant_mat J g f) = det (subresultant_mat J g f)
[PROOF STEP]
..
[PROOF STATE]
proof (state)
this:
det (subresultant_mat J g f) = subresultant J g f

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
det (subresultant_mat J g f) = subresultant J g f

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have "(-1)^(?k * ?n) * \<dots> = [: (-1)^(?k * ?n) :] * \<dots> "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (- 1) ^ ((degree f - J) * (degree g - J)) * subresultant J g f = [:(- (1::'a)) ^ ((degree f - J) * (degree g - J)):] * subresultant J g f
[PROOF STEP]
by (unfold hom_distribs, simp)
[PROOF STATE]
proof (state)
this:
(- 1) ^ ((degree f - J) * (degree g - J)) * subresultant J g f = [:(- (1::'a)) ^ ((degree f - J) * (degree g - J)):] * subresultant J g f

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(- 1) ^ ((degree f - J) * (degree g - J)) * subresultant J g f = [:(- (1::'a)) ^ ((degree f - J) * (degree g - J)):] * subresultant J g f

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
have "\<dots> = smult ((-1)^(?k * ?n)) (subresultant J g f)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [:(- (1::'a)) ^ ((degree f - J) * (degree g - J)):] * subresultant J g f = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
[:(- (1::'a)) ^ ((degree f - J) * (degree g - J)):] * subresultant J g f = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)

goal (1 subgoal):
 1. subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
subresultant J f g = Polynomial.smult ((- (1::'a)) ^ ((degree f - J) * (degree g - J))) (subresultant J g f)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma rtranclp_invar_conclude_last: "(\<lambda>x y. P x y \<and> Q y)\<^sup>*\<^sup>* x y \<Longrightarrow> Q x \<Longrightarrow> Q y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>(\<lambda>x y. P x y \<and> Q y)\<^sup>*\<^sup>* x y; Q x\<rbrakk> \<Longrightarrow> Q y
[PROOF STEP]
using rtranclp.cases
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?r\<^sup>*\<^sup>* ?a1.0 ?a2.0; \<And>a. \<lbrakk>?a1.0 = a; ?a2.0 = a\<rbrakk> \<Longrightarrow> ?P; \<And>a b c. \<lbrakk>?a1.0 = a; ?a2.0 = c; ?r\<^sup>*\<^sup>* a b; ?r b c\<rbrakk> \<Longrightarrow> ?P\<rbrakk> \<Longrightarrow> ?P

goal (1 subgoal):
 1. \<lbrakk>(\<lambda>x y. P x y \<and> Q y)\<^sup>*\<^sup>* x y; Q x\<rbrakk> \<Longrightarrow> Q y
[PROOF STEP]
by fastforce


[STATEMENT]
lemma (in IrrFinGroupRepresentation) Schur_Ker :
  "GRepHom smult' T \<Longrightarrow> T ` V \<noteq> 0 \<Longrightarrow> inj_on T V"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>GRepHom smult' T; T ` V \<noteq> 0\<rbrakk> \<Longrightarrow> inj_on T V
[PROOF STEP]
using irr FGModuleHom.GSubspace_Ker[of G smult V smult' T]
        FGModuleHom.Ker_Im_iff[of G smult V smult' T]
        FGModuleHom.Ker0_imp_inj_on[of G smult V smult' T]
[PROOF STATE]
proof (prove)
using this:
RModule FG (\<cdot>) ?U \<and> ?U \<subseteq> V \<Longrightarrow> ?U = 0 \<or> ?U = V
GRepHom smult' T \<Longrightarrow> RModule FG (\<cdot>) (ker T \<inter> V) \<and> ker T \<inter> V \<subseteq> V
GRepHom smult' T \<Longrightarrow> (ker T \<inter> V = V) = (T ` V = 0)
\<lbrakk>GRepHom smult' T; ker T \<inter> V \<subseteq> 0\<rbrakk> \<Longrightarrow> inj_on T V

goal (1 subgoal):
 1. \<lbrakk>GRepHom smult' T; T ` V \<noteq> 0\<rbrakk> \<Longrightarrow> inj_on T V
[PROOF STEP]
by    auto


[STATEMENT]
lemma nl41: assumes "(l'::real) \<ge> 1" "r' \<ge> 1" "ll \<ge> 1" "r \<ge> 1"
shows "4 * (l' + ll) * (r' + r) \<le> (l' + ll + r' + r)^2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 4 * (l' + ll) * (r' + r) \<le> (l' + ll + r' + r)\<^sup>2
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
1 \<le> l'
1 \<le> r'
1 \<le> ll
1 \<le> r

goal (1 subgoal):
 1. 4 * (l' + ll) * (r' + r) \<le> (l' + ll + r' + r)\<^sup>2
[PROOF STEP]
by (sos "(((A<0 * R<1) + (R<1 * (R<1 * [r + ~1*l' + ~1*ll + r']^2))))")


[STATEMENT]
lemma Infinitesimal_star_of_mult: "x \<in> Infinitesimal \<Longrightarrow> x * star_of r \<in> Infinitesimal"
  for x :: "'a::real_normed_algebra star"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<in> Infinitesimal \<Longrightarrow> x * star_of r \<in> Infinitesimal
[PROOF STEP]
by (erule HFinite_star_of [THEN [2] Infinitesimal_HFinite_mult])


[STATEMENT]
lemma eexp_special_values_iff [simp]:
  "eexp x = 0 \<longleftrightarrow> x = -\<infinity>"
  "eexp x = 1 \<longleftrightarrow> x = 0"
  "eexp x = \<infinity> \<longleftrightarrow> x = \<infinity>"
  "eexp x = top \<longleftrightarrow> x = \<infinity>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((eexp x = 0) = (x = - \<infinity>) &&& (eexp x = 1) = (x = 0)) &&& (eexp x = \<infinity>) = (x = \<infinity>) &&& (eexp x = top) = (x = \<infinity>)
[PROOF STEP]
unfolding eexp_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((enn2ereal (ennexp x) = 0) = (x = - \<infinity>) &&& (enn2ereal (ennexp x) = 1) = (x = 0)) &&& (enn2ereal (ennexp x) = \<infinity>) = (x = \<infinity>) &&& (enn2ereal (ennexp x) = top) = (x = \<infinity>)
[PROOF STEP]
apply (auto simp add: zero_ennreal.rep_eq one_ennreal.rep_eq top_ereal_def)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. enn2ereal (ennexp x) = 0 \<Longrightarrow> x = - \<infinity>
 2. enn2ereal (ennexp x) = 1 \<Longrightarrow> x = 0
[PROOF STEP]
apply (metis e2ennreal_enn2ereal ennexp.simps(3) ennexp_strict_mono strict_mono_eq zero_ennreal_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. enn2ereal (ennexp x) = 1 \<Longrightarrow> x = 0
[PROOF STEP]
by (metis e2ennreal_enn2ereal eln_ennexp eln_simps(2) one_ennreal_def)


[STATEMENT]
lemma Qp_poly_comp_eval:
  assumes "is_poly_tuple m fs"
  assumes "length fs = n"
  assumes "f \<in> carrier (Q\<^sub>p[\<X>\<^bsub>n\<^esub>])"
  assumes "as \<in> carrier (Q\<^sub>p\<^bsup>m\<^esup>)"
  shows "Qp_ev (Qp_poly_comp m fs f) as = Qp_ev f (poly_map m fs as)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. eval_at_point Q\<^sub>p as (Qp_poly_comp m fs f) = eval_at_point Q\<^sub>p (poly_map m fs as) f
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. eval_at_point Q\<^sub>p as (Qp_poly_comp m fs f) = eval_at_point Q\<^sub>p (poly_map m fs as) f
[PROOF STEP]
have "(restrict (poly_tuple_eval fs) (carrier (Q\<^sub>p\<^bsup>m\<^esup>)) as) = poly_tuple_eval fs as"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. restrict (poly_tuple_eval fs) (carrier (Q\<^sub>p\<^bsup>m\<^esup>)) as = poly_tuple_eval fs as
[PROOF STEP]
unfolding restrict_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if as \<in> carrier (Q\<^sub>p\<^bsup>m\<^esup>) then poly_tuple_eval fs as else undefined) = poly_tuple_eval fs as
[PROOF STEP]
by (simp add: assms)
[PROOF STATE]
proof (state)
this:
restrict (poly_tuple_eval fs) (carrier (Q\<^sub>p\<^bsup>m\<^esup>)) as = poly_tuple_eval fs as

goal (1 subgoal):
 1. eval_at_point Q\<^sub>p as (Qp_poly_comp m fs f) = eval_at_point Q\<^sub>p (poly_map m fs as) f
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
restrict (poly_tuple_eval fs) (carrier (Q\<^sub>p\<^bsup>m\<^esup>)) as = poly_tuple_eval fs as

goal (1 subgoal):
 1. eval_at_point Q\<^sub>p as (Qp_poly_comp m fs f) = eval_at_point Q\<^sub>p (poly_map m fs as) f
[PROOF STEP]
using assms Qp.cring_axioms poly_compose_eval
[PROOF STATE]
proof (prove)
using this:
restrict (poly_tuple_eval fs) (carrier (Q\<^sub>p\<^bsup>m\<^esup>)) as = poly_tuple_eval fs as
is_poly_tuple m fs
length fs = n
f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>n\<^esub>])
as \<in> carrier (Q\<^sub>p\<^bsup>m\<^esup>)
cring Q\<^sub>p
\<lbrakk>is_poly_tuple ?m ?fs; length ?fs = ?n; ?f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>?n\<^esub>]); ?as \<in> carrier (Q\<^sub>p\<^bsup>?m\<^esup>)\<rbrakk> \<Longrightarrow> eval_at_point Q\<^sub>p (poly_tuple_eval ?fs ?as) ?f = eval_at_point Q\<^sub>p ?as (poly_compose ?n ?m ?fs ?f)

goal (1 subgoal):
 1. eval_at_point Q\<^sub>p as (Qp_poly_comp m fs f) = eval_at_point Q\<^sub>p (poly_map m fs as) f
[PROOF STEP]
unfolding Qp_poly_comp_def poly_map_def
[PROOF STATE]
proof (prove)
using this:
restrict (poly_tuple_eval fs) (carrier (Q\<^sub>p\<^bsup>m\<^esup>)) as = poly_tuple_eval fs as
is_poly_tuple m fs
length fs = n
f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>n\<^esub>])
as \<in> carrier (Q\<^sub>p\<^bsup>m\<^esup>)
cring Q\<^sub>p
\<lbrakk>is_poly_tuple ?m ?fs; length ?fs = ?n; ?f \<in> carrier (Q\<^sub>p [\<X>\<^bsub>?n\<^esub>]); ?as \<in> carrier (Q\<^sub>p\<^bsup>?m\<^esup>)\<rbrakk> \<Longrightarrow> eval_at_point Q\<^sub>p (poly_tuple_eval ?fs ?as) ?f = eval_at_point Q\<^sub>p ?as (poly_compose ?n ?m ?fs ?f)

goal (1 subgoal):
 1. eval_at_point Q\<^sub>p as (poly_compose (length fs) m fs f) = eval_at_point Q\<^sub>p (restrict (poly_tuple_eval fs) (carrier (Q\<^sub>p\<^bsup>m\<^esup>)) as) f
[PROOF STEP]
by presburger
[PROOF STATE]
proof (state)
this:
eval_at_point Q\<^sub>p as (Qp_poly_comp m fs f) = eval_at_point Q\<^sub>p (poly_map m fs as) f

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma sqmatrix_mult_distrib_left:
  "(A::('a::{comm_monoid_add,semiring},'m::len) sqmatrix) * (B + C) = A * B + A * C"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<cdot> (B + C) = A \<cdot> B + A \<cdot> C
[PROOF STEP]
by (cases A, cases B, cases C, simp add: distrib_left sum.distrib)


[STATEMENT]
lemma natLeq_under_leq: "under natLeq n = {0 .. n}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. under natLeq n = {0..n}
[PROOF STEP]
unfolding under_def natLeq_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {b. (b, n) \<in> {(x, y). x \<le> y}} = {0..n}
[PROOF STEP]
by auto


[STATEMENT]
lemma "[2, mod 10, 4] = {2, 12, 22, 32, 42}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [ 2, mod 10, 4 ] = {2, 12, 22, 32, 42}
[PROOF STEP]
apply (simp only: iMODb_conv)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [\<dots>4] \<otimes> 10 \<oplus> 2 = {2, 12, 22, 32, 42}
[PROOF STEP]
apply (simp add: iT_defs iT_Plus_def iT_Mult_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>x. Suc (Suc x)) ` (\<lambda>n. n * 10) ` {..4} = {2, 12, 22, 32, 42}
[PROOF STEP]
apply fastforce
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma Qp_funs_add'':
  assumes "f \<in> (carrier (Fun\<^bsub>n\<^esub> Q\<^sub>p))"
  assumes "g \<in> (carrier (Fun\<^bsub>n\<^esub> Q\<^sub>p))"
  shows "(f \<oplus>\<^bsub>Fun\<^bsub>n\<^esub> Q\<^sub>p\<^esub> g) = (\<lambda> x \<in> carrier (Q\<^sub>p\<^bsup>n\<^esup>). f x \<oplus>\<^bsub>Q\<^sub>p\<^esub> g x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f \<oplus>\<^bsub>function_ring (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p\<^esub> g = (\<lambda>x\<in>carrier (Q\<^sub>p\<^bsup>n\<^esup>). f x \<oplus> g x)
[PROOF STEP]
unfolding function_ring_def function_add_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f \<oplus>\<^bsub>\<lparr>carrier = carrier (Q\<^sub>p\<^bsup>n\<^esup>) \<rightarrow>\<^sub>E carrier Q\<^sub>p, monoid.mult = function_mult (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p, one = function_one (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p, zero = function_zero (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p, add = \<lambda>f g. \<lambda>x\<in>carrier (Q\<^sub>p\<^bsup>n\<^esup>). f x \<oplus> g x, smult = function_scalar_mult (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p\<rparr>\<^esub> g = (\<lambda>x\<in>carrier (Q\<^sub>p\<^bsup>n\<^esup>). f x \<oplus> g x)
[PROOF STEP]
using ring_record_simps(12)
[PROOF STATE]
proof (prove)
using this:
(\<oplus>\<^bsub>\<lparr>carrier = ?carrier, monoid.mult = ?mult, one = ?one, zero = ?zero, add = ?add, \<dots> = ?more\<rparr>\<^esub>) = ?add

goal (1 subgoal):
 1. f \<oplus>\<^bsub>\<lparr>carrier = carrier (Q\<^sub>p\<^bsup>n\<^esup>) \<rightarrow>\<^sub>E carrier Q\<^sub>p, monoid.mult = function_mult (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p, one = function_one (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p, zero = function_zero (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p, add = \<lambda>f g. \<lambda>x\<in>carrier (Q\<^sub>p\<^bsup>n\<^esup>). f x \<oplus> g x, smult = function_scalar_mult (carrier (Q\<^sub>p\<^bsup>n\<^esup>)) Q\<^sub>p\<rparr>\<^esub> g = (\<lambda>x\<in>carrier (Q\<^sub>p\<^bsup>n\<^esup>). f x \<oplus> g x)
[PROOF STEP]
by metis