Papers
Topics
Authors
Recent
Search
2000 character limit reached

Potential Functions as Types

Published 9 Jul 2026 in cs.PL and cs.DS | (2607.08547v2)

Abstract: Amortized analysis can be framed from the physicist's view, amenable to manual verification in dependent type theory using potential functions, and the banker's view, amenable to automated inference in substructural type theory using type-level credit annotations. In this work, we synthesize these perspectives in Calf, a dependent type theory cost verification. From the physicist's view, we present a fracture and gluing theorem that renders every type as containing a fusion of an abstraction function and a potential function. By construction, every program between two such types must preserve abstraction, to facilitate modularity of behavior, and conserve potential, to facilitate modularity of cost. Incorporating the banker's view, we synthetically construct type operators for credits and debits. We then define Giralf, a graded substructural dependent type theory for programming with credits and debits, which is semantically interpreted as a sub-language of Calf. Finally, we adapt an inference algorithm to transform a limited class of Calf programs into Giralf counterparts, automating the cost analysis of common algorithms in Calf.

Summary

  • The paper presents a unified approach to amortized analysis by embedding cost abstraction into types using modal type theory.
  • It introduces a modal fracture-and-gluing theorem that bridges concrete and abstract cost representations for sound, compositional analysis.
  • The work implements an automated inference algorithm in Giralf, generalizing AARA to support dependently-typed programming and resource verification.

Synthetic Amortized Cost Verification: Potential Functions as Types

Introduction and Synthetic Modal Perspective

The paper "Potential Functions as Types" (2607.08547) develops a synthetic, modular framework for amortized analysis that unifies the physicist's and banker's views within dependent type theory. The physicist's view, grounded in potential functions and energy conservation principles, facilitates manual verification of amortized cost bounds in systems like Calf, a dependent type theory for cost analysis. The banker's view, emphasizing credits as substructural resources, enables automated cost inference, as in Automatic Amortized Resource Analysis (AARA).

A central technical contribution is the synthesis of these approaches within a modal, phase-distinct type-theoretic framework. The fracture and gluing theorem is generalized at the computation-type level, rendering every type as encoding both an abstraction function and a potential function. Programs between such types necessarily preserve abstraction (modular behavior) and conserve potential (modular cost).

To internalize the banker's view, the authors introduce synthetic type operators for credits and debits. This enables the construction of resource-aware dependent types supporting cost annotations in a systematic, compositional manner. The modal distinction allows client code to interact with abstract cost interfaces while implementation-specific details remain encapsulated.

Building upon previous work on abstraction functions as types, the paper proposes a fracture and gluing theorem for computation types (cost algebras). This theorem establishes an equivalence: every computation type decomposes into a concrete type, an abstract type, and a cost-aware abstraction homomorphism.

This structure generalizes previous results for value types and critically enables cost effects—potential functions can be "built into" types synthetically. Modal operators (abstract/concrete) isolate the client-facing specification from implementation, facilitating modular verification under explicit phase assumptions (such as abstraction or behavior).

Cost algebra homomorphisms are defined to cohere with the cost effect, guaranteeing that homomorphisms preserve and propagate cost as potential. Every type now contains an abstraction function and a potential function, rendering the physicist's conservation of energy as a built-in syntactic invariant.

Credits, Debits, and Substructural Types

The banker's view is synthesized by internalizing credits and debits as type constructors. The credit operator augments a type by emitting additional cost, corresponding to potential stored as credits. Conversely, the debit operator allows cost to be offset by assumed credits, enabling more flexible resource management.

These operators are compositional and admit functorial weakening and monoidal laws. The abstraction homomorphism is leveraged to ensure credits are ghost data; they are invisible in both the concrete implementation and abstract specification phases, serving only to mediate cost invariants.

Inductive types such as credit-carrying lists and trees are constructed, supporting both linear and polynomial credit annotations. This generalization enables representation of classical amortized data structures (e.g., batched queues, splay trees) as synthetically verified types, with both behavioral abstraction and potential encoded.

Giralf: Graded Inferential Resource-Aware Logical Framework

To streamline programming with credits/debits and enable automated resource analysis, the authors introduce Giralf, a graded substructural dependent type theory overlaying Calf. Giralf supports dependency (substructural resources depending on structural values), bounded recursion (structural induction only), and internalizes graded typing judgments.

Types in Giralf embed credit/debit annotations, supporting resource-aware algorithms on data structures such as lists with linear/quadratic credits. The typing judgment Γ;Δ;q⊢e:A\Gamma; \Delta; q \vdash e : A encodes a program ee given a linear context Δ\Delta and a credit context qq, resulting in type AA.

A resource-aware semantics interprets Giralf as a sublanguage of Calf, providing a soundness theorem: cost bounds inferred in Giralf are always upper bounds for the actual costs accrued in Calf, up to a conservation condition involving the potential function.

Automated Cost Inference and Constraint Solving

The resource analysis techniques of AARA are adapted for Giralf, enabling automated inference of cost bounds via LP-based constraint solving. Skeletal translation augments Calf programs with credit/debit annotations, with unknowns for credit amounts solved by LP techniques. Cost-free and cost-aware annotations are combined to support symbolic invariants, critical for implementing resource-polymorphic types such as quadratic-credit lists.

The integration is certifying: the inference algorithm produces Giralf terms in Agda, each accompanied by a certificate of amortized cost correctness. The mechanized approach guarantees that all cost bounds are sound with respect to the program semantics, and are compositional over inductive types and modular abstractions.

Implications and Future Directions

This work substantially advances the integration of amortized analysis within dependent type theory by encoding potential functions and credits as syntactic elements of types. The modular abstraction allows compositional verification of cost bounds, facilitating implementation of complex resource-aware algorithms without loss of client-facing guarantees.

The practical outcome is a unified framework for both manual and automated amortized cost verification, supporting structurally rich inductive types and advanced resource abstractions. The machinery enables the development of certified resource-aware libraries and interfaces, with cost invariants enforced synthetically at the type level.

Theoretically, the modal, phase-distinct approach opens new avenues for semantic cost analysis, supporting future generalizations to persistent data structures (as in Okasaki's work) and non-commutative cost models. Extensions to multivariate or exponential resource bounds, more general inductive types, or persistent amortization are highlighted as promising directions.

Conclusion

The paper proposes a synthetic, modular, and highly general framework for amortized cost verification in dependent type theory. By rendering potential functions as types and synthesizing the physicist's and banker's perspectives, the approach provides strong compositional and abstraction guarantees for resource-aware programming and verification. The Giralf overlay supports automated cost inference, and the entire framework is mechanized in Cubical Agda, facilitating principled integration into proof assistants and certifying resource analysis tools.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.