From 2ceb539bf306992e726280c24ce8d7b69e4c8b5e Mon Sep 17 00:00:00 2001
From: Andreas Grois <andi@grois.info>
Date: Thu, 19 Sep 2024 00:14:18 +0200
Subject: Day 11 Parsing

---
 Common/Nat.lean | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 Common/Nat.lean

(limited to 'Common/Nat.lean')

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
-- 
cgit v1.2.3

