Cairn · module

Cairn.Fuzz.Metrics

lean/Cairn/Fuzz/Metrics.lean

Random text metrics, valid by construction

Layout and text theorems quantify over every TextMetrics that is Valid, so the fuzzer shouldn't test with the mono stand-in only. random seed gives each font its own widths: each scalar's width is a hash of the seed, the font and the scalar, between 30% and 90% of the font size (wider for CJK and emoji), and 0 for combining marks and zero-width joiners; offsets are their prefix sums. Ascent and descent are random fractions of the size. random_valid proves every such metrics Valid.

Imports Cairn.Fuzz.Rng, Cairn.Font, Cairn.Layout.Proofs

Order

Inductive types 1

inductive

Cairn.Fuzz.MetricsChoice

lean/Cairn/Fuzz/Metrics.lean:88
MetricsChoice : Type

The metrics a sequence runs with: random from a seed, or the mono stand-in.

Constructors
random (seed : UInt64) : MetricsChoice
Instances

Repr Inhabited

Definitions 9

def

Cairn.Fuzz.sums

lean/Cairn/Fuzz/Metrics.lean:18
sums (acc : Int) : List Nat → List Int

Prefix sums from acc: one more entry than widths, starting at acc, never decreasing.

def

Cairn.Fuzz.zeroWidth

lean/Cairn/Fuzz/Metrics.lean:48
zeroWidth (c : Char) : Bool

Scalars that take no width: combining marks, variation selectors, joiners.

def

Cairn.Fuzz.wide

lean/Cairn/Fuzz/Metrics.lean:54
wide (c : Char) : Bool

Wide scalars: CJK and emoji.

def

Cairn.Fuzz.fontKey

lean/Cairn/Fuzz/Metrics.lean:56
fontKey (f : Font) : UInt64
def

Cairn.Fuzz.charWidth

lean/Cairn/Fuzz/Metrics.lean:59
charWidth (seed : UInt64) (f : Font) (c : Char) : Nat
def

Cairn.Fuzz.fraction

lean/Cairn/Fuzz/Metrics.lean:66
fraction (seed : UInt64) (f : Font) (salt : UInt64) (lo hi : Nat) : Nat
def

Cairn.Fuzz.randomMetrics

lean/Cairn/Fuzz/Metrics.lean:71
randomMetrics (seed : UInt64) : TextMetrics

Random metrics from a seed.

def

Cairn.Fuzz.MetricsChoice.metrics

lean/Cairn/Fuzz/Metrics.lean:93
metrics : MetricsChoice → TextMetrics
def

Cairn.Fuzz.MetricsChoice.gen

lean/Cairn/Fuzz/Metrics.lean:102
gen : Gen MetricsChoice

One sequence in eight uses mono.

Theorems 5

theorem

Cairn.Fuzz.sums_length

provedlean/Cairn/Fuzz/Metrics.lean:22
sums_length (acc : Int) (ws : List Nat) : (sums acc ws).length = ws.length + 1
theorem

Cairn.Fuzz.sums_ge

provedlean/Cairn/Fuzz/Metrics.lean:26
sums_ge (ws : List Nat) (acc : Int) (i : Nat) (h : i < (sums acc ws).length) :
  acc ≤ (sums acc ws)[i]
theorem

Cairn.Fuzz.sums_mono

provedlean/Cairn/Fuzz/Metrics.lean:36
sums_mono (ws : List Nat) (acc : Int) (i j : Nat) (hi : i < (sums acc ws).length)
  (hj : j < (sums acc ws).length) : i ≤ j → (sums acc ws)[i] ≤ (sums acc ws)[j]
theorem

Cairn.Fuzz.random_valid

provedlean/Cairn/Fuzz/Metrics.lean:76
random_valid (seed : UInt64) : (randomMetrics seed).Valid
theorem

Cairn.Fuzz.MetricsChoice.valid

provedlean/Cairn/Fuzz/Metrics.lean:97
valid (c : MetricsChoice) : c.metrics.Valid

Instances 2

instance

Cairn.Fuzz.instReprMetricsChoice

lean/Cairn/Fuzz/Metrics.lean:91
instReprMetricsChoice : Repr MetricsChoice
instance

Cairn.Fuzz.instInhabitedMetricsChoice

lean/Cairn/Fuzz/Metrics.lean:91
instInhabitedMetricsChoice : Inhabited MetricsChoice