โ† back to index

Weakest Preconditions in Fibrations

Bart Jacobs ยท 2014 ยท preprint

Prereqs: ๐Ÿž Staton 2025 (Hoare triples, weakest precondition). ๐Ÿž Fritz 2020 (Kleisli categories) helps.

Weakest preconditions arise automatically from a wpfibration over a Kleisli category. The poset of predicates sitting above each type is the fiber; lifting a morphism through the fibration computes wp.

base category (Kleisli) p X Y f : X → D(Y) Pred(Y) Q y > 0 true Pred(X) wp(f,Q) x > 1 wp lift

Predicates as a poset fibration

Above each type X sits a poset of predicates: propositions ordered by implication. "x > 5" implies "x > 0", so "x > 5" sits above "x > 0" in the fiber over integers. A fibration layers types on the bottom, predicates stacked above, ordered by strength.

Scheme

Lifting through the Kleisli category

A stochastic function f: X โ†’ D(Y) lives in the wpKleisli category of the distribution monad. To compute wp(f, Q), you lift the predicate Q on Y back through f: for each input x, check whether every possible output satisfies Q.

Scheme

Order enrichment makes wp monotone

The fibers are posets, so wp is monotone: if Qโ‚ implies Qโ‚‚, then wp(f, Qโ‚) implies wp(f, Qโ‚‚). Stronger postconditions give stronger preconditions. The order-enriched Kleisli structure guarantees this.

Scheme

Composition of wp via Kleisli composition

wp(f;g, Q) = wp(f, wp(g, Q)). Computing wp of the composed pipeline in one shot gives the same answer as computing wp(g, Q) first and feeding it to wp(f, -). The fibration structure guarantees this. Not a coincidence: functoriality.

Scheme

Notation reference

Paper Scheme Meaning
Pred(X)(lambda (x) ...)Fiber: predicates on X
P โ‰ค Q(implies? P Q dom)P implies Q (stronger precondition)
wp(f, Q)(wp f Q)Weakest precondition via lifting
Kl(D); Kleisli(Distribution)Kleisli category of distribution monad
p*(wp f ...)Reindexing functor (pullback along f)
Neighbors

Other paper pages

Foundations (Wikipedia)

Translation notes

All examples use finite distributions and boolean predicates. Jacobs works with order-enriched categories where predicates form complete lattices and the fibration carries left and right adjoints to reindexing. The wp computation on this page checks all elements of a small support set. In the paper, wp is a right adjoint to substitution in the fibration: a universal construction over arbitrary effect monads, not just distributions. The pointwise "for all y" check is the same; the categorical machinery that guarantees it exists is not.

Every example is Simplified.

Ready for the real thing? Start at ยง3 for the fibration of predicates over Kleisli categories, ยง5 for the wp-semantics.

Framework connection: The fibration-based wp construction is the theoretical backbone for computing weakest preconditions in the Natural Framework's ambient Kleisli category. (jkAmbient Category)