summaryrefslogtreecommitdiff
path: root/Common/Nat.lean
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2024-09-19 00:14:18 +0200
committerAndreas Grois <andi@grois.info>2024-09-19 00:14:18 +0200
commit2ceb539bf306992e726280c24ce8d7b69e4c8b5e (patch)
tree3433e5bb28f65f475dcf2ee17544dc1ff2e0d612 /Common/Nat.lean
parent2c1f2362c69ab20b10b61bdbebf8e5121eca38b1 (diff)
Day 11 Parsing
Diffstat (limited to 'Common/Nat.lean')
-rw-r--r--Common/Nat.lean13
1 files changed, 13 insertions, 0 deletions
diff --git a/Common/Nat.lean b/Common/Nat.lean
new file mode 100644
index 0000000..4c25315
--- /dev/null
+++ b/Common/Nat.lean
@@ -0,0 +1,13 @@
+namespace Nat
+
+theorem two_d_coordinate_to_index_lt_size {x y w h: Nat} (h₁ : x < w) (h₂ : y < h) : x + w*y < w*h :=
+ Nat.le_pred_of_lt h₂
+ |> Nat.mul_le_mul_left w
+ |> Nat.add_le_add_iff_right.mpr
+ |> (Nat.mul_pred w h).subst (motive :=λx↦w * y + w ≤ x + w)
+ |> (Nat.sub_add_cancel (Nat.le_mul_of_pos_right w (Nat.zero_lt_of_lt h₂))).subst
+ |> (Nat.add_comm _ _).subst (motive := λx↦x ≤ w*h)
+ |> Nat.le_sub_of_add_le
+ |> Nat.lt_of_lt_of_le h₁
+ |> λx↦(Nat.add_lt_add_right) x (w * y)
+ |> (Nat.sub_add_cancel (Nat.le_of_lt ((Nat.mul_lt_mul_left (Nat.zero_lt_of_lt h₁)).mpr h₂))).subst