Elm Exactly

Theorempow2_of_dvd

StandardElmMech/Eff/Properties.lean:223, Numbers: a float's exact value is decimal · term proof

A92: a list of byte sequences encodes as an array of byte sequences. -/ theorem a92_bytes_nested : Enc (.list .bytes) (Val.ofList [binVal [1, 2]]) (.arr (.cons (.bytes [1, 2]) .nil)) := (enc_iff _ _ _).mpr (by decide +kernel) /-! ## Canonical payload types and boundary values (D7) -/ mutual /-- Canonical payload types: the fields of every record type strictly increasing by label. -/ def PTy.canonB : PTy → Bool | .list τ | .maybe τ | .array τ => τ.canonB | .tuple2 a b => a.canonB && b.canonB | .tuple3 a b c => a.canonB && b.canonB && c.canonB | .record fs => fs.canonB && fs.labelsIncreasing | _ => true def PFields.canonB : PFields → Bool | .nil => true | .cons _ τ rest => τ.canonB && rest.canonB def PFields.labelsIncreasing : PFields → Bool | .nil => true | .cons _ _ .nil => true | .cons l _ (.cons l' τ' rest) => decide (l < l') && (PFields.cons l' τ' rest).labelsIncreasing end def PTy.Canon (τ : PTy) : Prop := τ.canonB = true /-! ## Numbers: a float's exact value is decimal

Statement

theorem pow2_of_dvd : ∀ (k d : Nat), d ∣ 2 ^ k → ∃ j, d = 2 ^ j
  | 0, d, h => ⟨0, by simpa using Nat.eq_one_of_dvd_one h⟩
  | k + 1, d, h => by
    by_cases he : d % 2 = 0
    · obtain ⟨d', rfl⟩ : ∃ d', d = 2 * d'

Proof

⟨d / 2, by omega⟩
      have : d' ∣ 2 ^ k := by
        rw [Nat.pow_succ, Nat.mul_comm (2 ^ k) 2] at h
        exact Nat.dvd_of_mul_dvd_mul_left (by decide : 0 < 2) h
      obtain ⟨j, rfl⟩ := pow2_of_dvd k d' this
      exact ⟨j + 1, by rw [Nat.pow_succ, Nat.mul_comm]⟩
    · have hc : Nat.Coprime d 2 := by
        unfold Nat.Coprime
        rw [Nat.gcd_comm, Nat.gcd_rec, show d % 2 = 1 by omega]
        rfl
      rw [Nat.pow_succ] at h
      exact pow2_of_dvd k d (hc.dvd_of_dvd_mul_right h)

Proved by a term, which Lean's kernel checks directly.

Used by

About ruling A92 of the book, where the implementations disagreed or were silent and the definition decides.

In StandardElmMech/Eff/Properties.lean: APPLY of the effect values has one member; the rulings A74, A76, A88 and A92; canonical payload types, the decimality of a float's exact value, and that every value of a payload type has a canonical encoding (enc_total).

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.