Writer Monad Transformer Utilities #
This file extends WriterT with helper lemmas and the additive wrapper AddWriterT.
The first half of the file collects basic WriterT run, bind, and lifting lemmas, together with
the LawfulAppend class used to build lawful WriterT instances over append-like logs.
The second half specializes WriterT to additive cost accumulation via Multiplicative, and
introduces predicates and notation for reasoning about outputs and accumulated costs.
Instances For
Instances For
AddWriterT: Additive Writer Monad Transformer #
Writer monad transformer with additive cost accumulation.
Defined as WriterT (Multiplicative ω) M, which uses Monoid (Multiplicative ω)
(derived from AddMonoid ω) so that tell accumulates via + with identity 0.
The types Multiplicative ω and ω are definitionally equal (Multiplicative is a plain
def, not a structure), so no runtime wrapping occurs.
Instances For
Forget the additive cost log and keep only the outputs of an AddWriterT computation.
Instances For
Observe only the accumulated additive cost of an AddWriterT computation.
Instances For
Record an additive cost w in the writer log.
Instances For
CostsAs oa f means that the accumulated cost of oa is determined by its output via the
function f.
Concretely, whenever oa produces output a, the recorded cost is exactly f a. This is a
strong structural property: it can fail when the same output can be reached by different execution
paths carrying different costs.
Instances For
HasCost oa w means that every execution path of oa incurs the constant cost w.
Instances For
OutputCostAtMost oa w means that oa admits an output-indexed cost description bounded above
by the constant w.
Concretely, there is some function f : α → ω such that every execution producing output a
accumulates cost f a, and each such f a is at most w. This is stronger than a merely
pathwise upper bound when the same output can be reached with different costs.
Instances For
OutputCostAtLeast oa w means that oa admits an output-indexed cost description bounded
below by the constant w.
As with [AddWriterT.OutputCostAtMost], this packages a cost function determined by the final
output, not just an arbitrary pathwise lower bound.
Instances For
Cost[ oa ] = w means that the AddWriterT computation oa incurs the same additive cost
w on every execution path.
This is notation for [AddWriterT.HasCost]. It is intended for theorem statements where the
constant-cost reading is more natural than the underlying output-indexed formulation
[AddWriterT.CostsAs].
Instances For
OutputCost[ oa ] ≤ w means that oa admits an output-indexed additive-cost bound by w.
This is notation for [AddWriterT.OutputCostAtMost]. It is best used when cost is already known
to be determined by the final output, or when that stronger formulation is useful in a proof.
Instances For
OutputCost[ oa ] ≥ w means that oa admits an output-indexed additive-cost lower bound by
w.
This is notation for [AddWriterT.OutputCostAtLeast]. As with [OutputCost[ oa ] ≤ w], it is
formulated in terms of an output-indexed cost witness rather than arbitrary execution paths.