simplify left-pad a touch
This commit is contained in:
parent
a5040e9b84
commit
1ae5d8eb46
1 changed files with 10 additions and 7 deletions
|
@ -498,10 +498,12 @@ def left_pad' (to : Nat) {n : Nat} (with' : α) (xs : SizedArray α n)
|
|||
: SizedArray α to := by
|
||||
let pad_amt := to - n
|
||||
let (h₂ : pad_amt = to - n) := rfl
|
||||
|
||||
let padding := replicate pad_amt with'
|
||||
let padded := append padding xs
|
||||
rw [h₂] at padded
|
||||
rw [Nat.sub_add_cancel] at padded
|
||||
|
||||
rw [h₂, Nat.sub_add_cancel] at padded
|
||||
|
||||
exact padded
|
||||
exact h
|
||||
|
||||
|
@ -510,18 +512,19 @@ def left_pad (to : Nat) {n : Nat} (with' : α) (xs : SizedArray α n)
|
|||
cases hle : (decide (to ≤ n)) with
|
||||
| true =>
|
||||
rw [max, Nat.instMaxNat, maxOfLe]
|
||||
simp
|
||||
let hle : to ≤ n := of_decide_eq_true hle
|
||||
simp [hle]
|
||||
exact xs
|
||||
| false =>
|
||||
let hle : ¬to ≤ n := of_decide_eq_false hle
|
||||
|
||||
rw [max, Nat.instMaxNat, maxOfLe]
|
||||
simp [hle]
|
||||
|
||||
let hnle := hle
|
||||
rw [Nat.not_le_eq, ← Nat.succ_eq_add_one] at hnle
|
||||
let hnle := Nat.le_of_succ_le hnle
|
||||
|
||||
rw [max, Nat.instMaxNat, maxOfLe]
|
||||
simp
|
||||
simp [hle]
|
||||
|
||||
exact left_pad' to with' xs hnle
|
||||
|
||||
#eval left_pad 10 413 (from_list [1,2,3,4,5,6,7])
|
||||
|
|
Loading…
Reference in a new issue