Theorem: Nat.bitwise_lt_exp2 (Algdata/Data/Nat/Bits.lean)

State before:
f : Bool → Bool → Bool
m n k : Nat
hmk : m < 2 ^ k
hnk : n < 2 ^ k
⊢ bitwise f m n < 2 ^ k
Tactic:
induction k generalizing m n
State after:
case zero
f : Bool → Bool → Bool
m n : Nat
hmk : m < 2 ^ zero
hnk : n < 2 ^ zero
⊢ bitwise f m n < 2 ^ zero

case succ
f : Bool → Bool → Bool
n✝ : Nat
n_ih✝ : ∀ {m n : Nat}, m < 2 ^ n✝ → n < 2 ^ n✝ → bitwise f m n < 2 ^ n✝
m n : Nat
hmk : m < 2 ^ succ n✝
hnk : n < 2 ^ succ n✝
⊢ bitwise f m n < 2 ^ succ n✝

State before:
f : Bool → Bool → Bool
m n : Nat
hmk : m < 2 ^ zero
hnk : n < 2 ^ zero
⊢ bitwise f m n < 2 ^ zero
Tactic:
case zero =>
  cases m.eq_zero_of_lt_one hmk; cases n.eq_zero_of_lt_one hnk
  unfold bitwise; simp
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
⊢ bitwise f m n < 2 ^ succ k
Tactic:
case succ k h_ind =>
  by_cases m = 0
  case pos hm =>
    cases hm
    unfold bitwise; simp
    cases f false true <;> simp
    . exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
    . exact hnk
  case neg hm =>
    by_cases n = 0
    case pos hn =>
      cases hn
      unfold bitwise; simp [hm]
      cases f true false <;> simp
      . exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
      . exact hmk
    case neg hn =>
      unfold bitwise; simp [hm, hn]
      rw [←Nat.mul_two, Nat.pow_succ]
      have : m/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hmk
      have : n/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hnk
      cases f (m%2=1) (n%2=1) <;> simp
      . apply Nat.mul_lt_mul_of_pos_right ?_ (Nat.zero_lt_succ 1)
        exact h_ind ‹_› ‹_›
      . calc
        bitwise f (m/2) (n/2) * 2 + 1 
          < bitwise f (m/2) (n/2) * 2 + 2 := Nat.lt_succ_self _
        _ = (bitwise f (m/2) (n/2)) * 2 + 1*2 := rfl
        _ = (bitwise f (m/2) (n/2) + 1) * 2 := (Nat.add_mul _ _ 2).symm
        _ ≤ 2^k * 2 := Nat.mul_le_mul_right 2 (h_ind ‹m/2 < 2^k› ‹n/2 < 2^k›)
State after:
no goals

State before:
f : Bool → Bool → Bool
m n : Nat
hmk : m < 2 ^ zero
hnk : n < 2 ^ zero
⊢ bitwise f m n < 2 ^ zero
Tactic:
cases m.eq_zero_of_lt_one hmk
State after:
case refl
f : Bool → Bool → Bool
n : Nat
hnk : n < 2 ^ zero
hmk : 0 < 2 ^ zero
⊢ bitwise f 0 n < 2 ^ zero

State before:
case refl
f : Bool → Bool → Bool
n : Nat
hnk : n < 2 ^ zero
hmk : 0 < 2 ^ zero
⊢ bitwise f 0 n < 2 ^ zero
Tactic:
cases n.eq_zero_of_lt_one hnk
State after:
case refl.refl
f : Bool → Bool → Bool
hmk hnk : 0 < 2 ^ zero
⊢ bitwise f 0 0 < 2 ^ zero

State before:
case refl.refl
f : Bool → Bool → Bool
hmk hnk : 0 < 2 ^ zero
⊢ bitwise f 0 0 < 2 ^ zero
Tactic:
unfold bitwise
State after:
case refl.refl
f : Bool → Bool → Bool
hmk hnk : 0 < 2 ^ zero
⊢ (if 0 = 0 then if f false true = true then 0 else 0
    else
      if 0 = 0 then if f true false = true then 0 else 0
      else
        let n' := 0 / 2;
        let m' := 0 / 2;
        let b₁ := 0 % 2 = 1;
        let b₂ := 0 % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ zero

State before:
case refl.refl
f : Bool → Bool → Bool
hmk hnk : 0 < 2 ^ zero
⊢ (if 0 = 0 then if f false true = true then 0 else 0
    else
      if 0 = 0 then if f true false = true then 0 else 0
      else
        let n' := 0 / 2;
        let m' := 0 / 2;
        let b₁ := 0 % 2 = 1;
        let b₂ := 0 % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ zero
Tactic:
simp
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
⊢ bitwise f m n < 2 ^ succ k
Tactic:
by_cases m = 0
State after:
case pos
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
h✝ : m = 0
⊢ bitwise f m n < 2 ^ succ k

case neg
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
h✝ : ¬m = 0
⊢ bitwise f m n < 2 ^ succ k

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : m = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
case pos hm =>
  cases hm
  unfold bitwise; simp
  cases f false true <;> simp
  . exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
  . exact hnk
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
case neg hm =>
  by_cases n = 0
  case pos hn =>
    cases hn
    unfold bitwise; simp [hm]
    cases f true false <;> simp
    . exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
    . exact hmk
  case neg hn =>
    unfold bitwise; simp [hm, hn]
    rw [←Nat.mul_two, Nat.pow_succ]
    have : m/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hmk
    have : n/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hnk
    cases f (m%2=1) (n%2=1) <;> simp
    . apply Nat.mul_lt_mul_of_pos_right ?_ (Nat.zero_lt_succ 1)
      exact h_ind ‹_› ‹_›
    . calc
      bitwise f (m/2) (n/2) * 2 + 1 
        < bitwise f (m/2) (n/2) * 2 + 2 := Nat.lt_succ_self _
      _ = (bitwise f (m/2) (n/2)) * 2 + 1*2 := rfl
      _ = (bitwise f (m/2) (n/2) + 1) * 2 := (Nat.add_mul _ _ 2).symm
      _ ≤ 2^k * 2 := Nat.mul_le_mul_right 2 (h_ind ‹m/2 < 2^k› ‹n/2 < 2^k›)
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : m = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
cases hm
State after:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ bitwise f 0 n < 2 ^ succ k

State before:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ bitwise f 0 n < 2 ^ succ k
Tactic:
unfold bitwise
State after:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ (if 0 = 0 then if f false true = true then n else 0
    else
      if n = 0 then if f true false = true then 0 else 0
      else
        let n' := 0 / 2;
        let m' := n / 2;
        let b₁ := 0 % 2 = 1;
        let b₂ := n % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ succ k

State before:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ (if 0 = 0 then if f false true = true then n else 0
    else
      if n = 0 then if f true false = true then 0 else 0
      else
        let n' := 0 / 2;
        let m' := n / 2;
        let b₁ := 0 % 2 = 1;
        let b₂ := n % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ succ k
Tactic:
simp
State after:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ (if f false true = true then n else 0) < 2 ^ succ k

State before:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ (if f false true = true then n else 0) < 2 ^ succ k
Tactic:
cases f false true <;> simp
State after:
case refl.false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ 0 < 2 ^ succ k

case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ n < 2 ^ succ k

State before:
case refl.false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ 0 < 2 ^ succ k

case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ n < 2 ^ succ k
Tactic:
. exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
State after:
case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ n < 2 ^ succ k

State before:
case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ n < 2 ^ succ k
Tactic:
. exact hnk
State after:
no goals

State before:
case refl.false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ 0 < 2 ^ succ k
Tactic:
exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
State after:
no goals

State before:
case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
n : Nat
hnk : n < 2 ^ succ k
hmk : 0 < 2 ^ succ k
⊢ n < 2 ^ succ k
Tactic:
exact hnk
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
by_cases n = 0
State after:
case pos
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
h✝ : n = 0
⊢ bitwise f m n < 2 ^ succ k

case neg
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
h✝ : ¬n = 0
⊢ bitwise f m n < 2 ^ succ k

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : n = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
case pos hn =>
  cases hn
  unfold bitwise; simp [hm]
  cases f true false <;> simp
  . exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
  . exact hmk
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
case neg hn =>
  unfold bitwise; simp [hm, hn]
  rw [←Nat.mul_two, Nat.pow_succ]
  have : m/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hmk
  have : n/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hnk
  cases f (m%2=1) (n%2=1) <;> simp
  . apply Nat.mul_lt_mul_of_pos_right ?_ (Nat.zero_lt_succ 1)
    exact h_ind ‹_› ‹_›
  . calc
    bitwise f (m/2) (n/2) * 2 + 1 
      < bitwise f (m/2) (n/2) * 2 + 2 := Nat.lt_succ_self _
    _ = (bitwise f (m/2) (n/2)) * 2 + 1*2 := rfl
    _ = (bitwise f (m/2) (n/2) + 1) * 2 := (Nat.add_mul _ _ 2).symm
    _ ≤ 2^k * 2 := Nat.mul_le_mul_right 2 (h_ind ‹m/2 < 2^k› ‹n/2 < 2^k›)
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : n = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
cases hn
State after:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ bitwise f m 0 < 2 ^ succ k

State before:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ bitwise f m 0 < 2 ^ succ k
Tactic:
unfold bitwise
State after:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ (if m = 0 then if f false true = true then 0 else 0
    else
      if 0 = 0 then if f true false = true then m else 0
      else
        let n' := m / 2;
        let m' := 0 / 2;
        let b₁ := m % 2 = 1;
        let b₂ := 0 % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ succ k

State before:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ (if m = 0 then if f false true = true then 0 else 0
    else
      if 0 = 0 then if f true false = true then m else 0
      else
        let n' := m / 2;
        let m' := 0 / 2;
        let b₁ := m % 2 = 1;
        let b₂ := 0 % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ succ k
Tactic:
simp [hm]
State after:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ (if f true false = true then m else 0) < 2 ^ succ k

State before:
case refl
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ (if f true false = true then m else 0) < 2 ^ succ k
Tactic:
cases f true false <;> simp
State after:
case refl.false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ 0 < 2 ^ succ k

case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ m < 2 ^ succ k

State before:
case refl.false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ 0 < 2 ^ succ k

case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ m < 2 ^ succ k
Tactic:
. exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
State after:
case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ m < 2 ^ succ k

State before:
case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ m < 2 ^ succ k
Tactic:
. exact hmk
State after:
no goals

State before:
case refl.false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ 0 < 2 ^ succ k
Tactic:
exact Nat.pos_pow_of_pos k.succ (Nat.zero_lt_succ 1)
State after:
no goals

State before:
case refl.true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m : Nat
hmk : m < 2 ^ succ k
hm : ¬m = 0
hnk : 0 < 2 ^ succ k
⊢ m < 2 ^ succ k
Tactic:
exact hmk
State after:
no goals

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ bitwise f m n < 2 ^ succ k
Tactic:
unfold bitwise
State after:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ (if m = 0 then if f false true = true then n else 0
    else
      if n = 0 then if f true false = true then m else 0
      else
        let n' := m / 2;
        let m' := n / 2;
        let b₁ := m % 2 = 1;
        let b₂ := n % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ succ k

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ (if m = 0 then if f false true = true then n else 0
    else
      if n = 0 then if f true false = true then m else 0
      else
        let n' := m / 2;
        let m' := n / 2;
        let b₁ := m % 2 = 1;
        let b₂ := n % 2 = 1;
        let r := bitwise f n' m';
        if f (decide b₁) (decide b₂) = true then r + r + 1 else r + r) <
    2 ^ succ k
Tactic:
simp [hm, hn]
State after:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) + bitwise f (m / 2) (n / 2) + 1
    else bitwise f (m / 2) (n / 2) + bitwise f (m / 2) (n / 2)) <
    2 ^ succ k

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) + bitwise f (m / 2) (n / 2) + 1
    else bitwise f (m / 2) (n / 2) + bitwise f (m / 2) (n / 2)) <
    2 ^ succ k
Tactic:
rw [←Nat.mul_two, Nat.pow_succ]
State after:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) * 2 + 1
    else bitwise f (m / 2) (n / 2) * 2) <
    2 ^ k * 2

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) * 2 + 1
    else bitwise f (m / 2) (n / 2) * 2) <
    2 ^ k * 2
Tactic:
have : m/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hmk
State after:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this : m / 2 < 2 ^ k
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) * 2 + 1
    else bitwise f (m / 2) (n / 2) * 2) <
    2 ^ k * 2

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this : m / 2 < 2 ^ k
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) * 2 + 1
    else bitwise f (m / 2) (n / 2) * 2) <
    2 ^ k * 2
Tactic:
have : n/2 < 2^k := (Nat.div_lt_iff_lt_mul (Nat.zero_lt_succ 1)).mpr hnk
State after:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) * 2 + 1
    else bitwise f (m / 2) (n / 2) * 2) <
    2 ^ k * 2

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ (if f (decide (m % 2 = 1)) (decide (n % 2 = 1)) = true then bitwise f (m / 2) (n / 2) * 2 + 1
    else bitwise f (m / 2) (n / 2) * 2) <
    2 ^ k * 2
Tactic:
cases f (m%2=1) (n%2=1) <;> simp
State after:
case false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 < 2 ^ k * 2

case true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 + 1 < 2 ^ k * 2

State before:
case false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 < 2 ^ k * 2

case true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 + 1 < 2 ^ k * 2
Tactic:
. apply Nat.mul_lt_mul_of_pos_right ?_ (Nat.zero_lt_succ 1)
  exact h_ind ‹_› ‹_›
State after:
case true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 + 1 < 2 ^ k * 2

State before:
case true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 + 1 < 2 ^ k * 2
Tactic:
. calc
  bitwise f (m/2) (n/2) * 2 + 1 
    < bitwise f (m/2) (n/2) * 2 + 2 := Nat.lt_succ_self _
  _ = (bitwise f (m/2) (n/2)) * 2 + 1*2 := rfl
  _ = (bitwise f (m/2) (n/2) + 1) * 2 := (Nat.add_mul _ _ 2).symm
  _ ≤ 2^k * 2 := Nat.mul_le_mul_right 2 (h_ind ‹m/2 < 2^k› ‹n/2 < 2^k›)
State after:
no goals

State before:
case false
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 < 2 ^ k * 2
Tactic:
apply Nat.mul_lt_mul_of_pos_right ?_ (Nat.zero_lt_succ 1)
State after:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) < 2 ^ k

State before:
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) < 2 ^ k
Tactic:
exact h_ind ‹_› ‹_›
State after:
no goals

State before:
case true
f : Bool → Bool → Bool
k : Nat
h_ind : ∀ {m n : Nat}, m < 2 ^ k → n < 2 ^ k → bitwise f m n < 2 ^ k
m n : Nat
hmk : m < 2 ^ succ k
hnk : n < 2 ^ succ k
hm : ¬m = 0
hn : ¬n = 0
this✝ : m / 2 < 2 ^ k
this : n / 2 < 2 ^ k
⊢ bitwise f (m / 2) (n / 2) * 2 + 1 < 2 ^ k * 2
Tactic:
calc
bitwise f (m/2) (n/2) * 2 + 1 
  < bitwise f (m/2) (n/2) * 2 + 2 := Nat.lt_succ_self _
_ = (bitwise f (m/2) (n/2)) * 2 + 1*2 := rfl
_ = (bitwise f (m/2) (n/2) + 1) * 2 := (Nat.add_mul _ _ 2).symm
_ ≤ 2^k * 2 := Nat.mul_le_mul_right 2 (h_ind ‹m/2 < 2^k› ‹n/2 < 2^k›)
State after:
no goals