A least-fixpoint first-order-shape-relation interpreter for the lambda-calculus
Project description
co_lambda
A first-order-shape-relation interpreter for the lambda-calculus, realizing the
semantics of the paper papers/co-lambda/first-order.tex, depending on fixpoints.
A lambda-term's tree is the readout of a single first-order weak-head shape relation Sh
over term positions. The shape at a position is single-valued, so there is no set to aggregate.
readout(node) resolves each position's head via its Sh and descends.
Because positions are interned (structurally-equal positions are one object, identity is a pointer test), a cyclic structure has finitely many positions and the least-fixpoint reading folds it into a finite rational tree where head reduction would unfold forever. So the readout terminates on every rational tree, and decides an unproductive cycle as the meaningless leaf in finite time, where head reduction diverges. Interning is the finest instance of a pluggable position congruence (see below); a coarser sound congruence folds more.
readout has two re-entry policies:
fold_cycles=True(default) is the least fixpointlfp, the denotation: a guarded cycle folds into a finite rational graph (renderprints it with#Nback-references); the only leaves are variables and the meaningless⊥.fold_cycles=Falseis the finite-budget first-iteration readingT↑1: a re-entered guarded cycle is cut to the distinct guarded-cut leaf∅(the hole where the budget stopped on a productive cycle), kept separate from the meaningless⊥(an unproductive cycle, a position with no shape).∅never appears in the least fixpoint.
The calculus is pure (Var/Lam/App): no recursion binder is needed. The Y combinator
produces the structural repetition that interning folds, so:
Y (cons 0)(the cyclic streamr = cons 0 r) folds to a finite rational tree.Ω = (λx.xx)(λx.xx)andY (λx.x)(i.e.letrec x = x) are unproductive cycles: they read out as⊥under both readings.
The fold/cut is taken only at closed positions, so a folded back-reference never misreads a free de Bruijn variable.
Position congruence (a second parameter)
Which positions count as "the same" when the readout folds is a parameter, a position
congruence (Definition def:congruence in the paper). readout(node, congruence=...) keys the
fold on congruence.key(node) instead of raw object identity. A congruence is sound when it
is contained in tree equality (it never folds positions with different trees); stated over the
full signature, soundness is the congruence law read coinductively, so a well-formed congruence
folds without changing the denotation. _congruence.py provides four instances, from finest to
coarser:
IdentityCongruence(the default): syntactic de Bruijn identity,key = id(node), a pointer test. The finest instance; reproduces the pure-interning readout exactly.EGraphCongruence: a union-find with congruence closure over the syntactic constructors. The caller asserts sound (tree-equal) merges withmerge(a, b); closure propagates them toApp/Lamparents, and the readout shares the merged positions. The inductive (least-fixpoint) family: it folds whatever finitely many tree-equal pairs generate.PositionEGraphCongruence: the faithfuldef:congruence, keyed on the demanded descent (the shape tree) rather than the syntax. It auto-folds any two positions bisimilar underShwith no asserted merge (a redex and its reduct collapse on sight), folding exactly the rational fragment. It cannot finitize an infinitely-presented shape graph, so theY F 0witness below still diverges: bisimulation alone does not rescue a dead-argument cycle.DeadSubtermCongruence(rules=...): equality up to dead subterms, the key being the syntax with every dead-argument slot erased to a canonical placeholder (a tree-preserving map, not a congruence closure). The dead slots are recognised by a library of sound rules; the caller enables a subset.RecursionArgumentRulefolds the paper'sY F 0witness, where a constant-headed recursion carries an index it never inspects;UnusedParameterRuleerases the argument of a function that discards it. This is the one reading that folds the witness, which neither e-graph can.
No parser is provided. Build terms in Python with the HOAS DSL in _dsl.py (lam, app,
build), which compiles to a first-order de Bruijn AST; _prelude.py collects example terms
(combinators, Scott-encoded lists, Church numerals with Peano arithmetic).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file co_lambda-0.6.0.post6.dev0.tar.gz.
File metadata
- Download URL: co_lambda-0.6.0.post6.dev0.tar.gz
- Upload date:
- Size: 136.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
101d6e27d834f579fbc36d3c819f79684a9647f3f5aa0aa3ac6ce673e9bec0f7
|
|
| MD5 |
9cc04c124cf28456acdb86672da1c56b
|
|
| BLAKE2b-256 |
4c1cb2046b7e0077191c692dbce2bf80ae5d671d4f6714a0d7b35120921cb959
|
Provenance
The following attestation bundles were made for co_lambda-0.6.0.post6.dev0.tar.gz:
Publisher:
ci.yml on Atry/co-lambda
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
co_lambda-0.6.0.post6.dev0.tar.gz -
Subject digest:
101d6e27d834f579fbc36d3c819f79684a9647f3f5aa0aa3ac6ce673e9bec0f7 - Sigstore transparency entry: 1892339825
- Sigstore integration time:
-
Permalink:
Atry/co-lambda@11c69d4810f1875863f01a9f6c52cf51c2cc9843 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Atry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@11c69d4810f1875863f01a9f6c52cf51c2cc9843 -
Trigger Event:
push
-
Statement type:
File details
Details for the file co_lambda-0.6.0.post6.dev0-py3-none-any.whl.
File metadata
- Download URL: co_lambda-0.6.0.post6.dev0-py3-none-any.whl
- Upload date:
- Size: 139.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba7a11a944367a16df1e71dc148dd28719bc65ff0a58435d1cb37dd0ae086546
|
|
| MD5 |
fd697803e9ebc125f1d78d2a09a9dd34
|
|
| BLAKE2b-256 |
a9d081d01451e866ed336b8284494fac8fe0003a09218ce1b2b656d28e22f71e
|
Provenance
The following attestation bundles were made for co_lambda-0.6.0.post6.dev0-py3-none-any.whl:
Publisher:
ci.yml on Atry/co-lambda
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
co_lambda-0.6.0.post6.dev0-py3-none-any.whl -
Subject digest:
ba7a11a944367a16df1e71dc148dd28719bc65ff0a58435d1cb37dd0ae086546 - Sigstore transparency entry: 1892340008
- Sigstore integration time:
-
Permalink:
Atry/co-lambda@11c69d4810f1875863f01a9f6c52cf51c2cc9843 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Atry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@11c69d4810f1875863f01a9f6c52cf51c2cc9843 -
Trigger Event:
push
-
Statement type: