Related — transfer by instance resolution #
A foundational kernel of a Trocq-style relatedness layer whose typeclass
instance resolution composes a transfer automatically for closed first-order
op-trees. The relation is an encoding: Related enc a b means b is the
encoding enc a of the abstract value a.
Given:
- a leaf fact "the encoding of a value is related to it" (
leaf/leafId), and - per-operation commuting squares (
RelatedBinOp:enc (op x y) = bop (enc x) (enc y)), each a registered witness (never invented here — the soundness lives entirely in the suppliedRelatedBinOpinstance),
the composition instance composeBinOp lets instance resolution synthesize a
Related enc t (T) for any closed term t built from registered binary ops,
where T is the corresponding emitted op-tree. The corollary transferRel
then extracts the underlying equation enc t = T.
Demonstration #
The emitted Baby Bear field arithmetic
(Bridges.ReprTransferInstances.bbFieldMul/bbFieldAdd, proved equal to the
abstract */+ via bbFieldMul_eq/bbFieldAdd_eq) is registered as
RelatedBinOp instances with the identity encoding. Instance resolution then
composes the transfer of a composite expression with no manual proof:
a * b + c = bbFieldAdd (bbFieldMul a b) c
is closed purely by (inferInstance : Related id _ _).rel.
Scope and limits #
- Closed first-order only. The composition handles op-trees over registered
binary operations on a single carrier
Awith a single encodingenc. There is no support for binders, parametric/higher-order operations, mixed carriers, or relation polymorphism (the full Trocq hierarchy of relation classes). This is a small kernel. - Encoding-correctness is the
RelatedBinOpwitness. The commuting square for each operation must be supplied as a proved instance; this file does not supply it. The transfer is only as sound as the registered witnesses. - The
idencoding needs its own leaf. Instance resolution keys on syntactic heads and does not reduceid atoawhile matching, so the genericleaf(headRelated enc a (enc a)) cannot serve the identity encoding in the demonstration. A dedicated low-priorityleafId(headRelated id a a) supplies it. Both leaves arepriority := lowso the structuralcomposeBinOpis preferred and resolution does not loop on a leaf.
A registered realization of a binary operation: the commuting square
enc (op x y) = bop (enc x) (enc y). This is the witness that the
emitted operation bop realizes the abstract operation op along enc.
It is always supplied; the transfer is sound exactly to the extent this
square is.
The commuting square for this operation.
Instances
Composition. If bop realizes op (a registered RelatedBinOp) and
a', b' are the encodings of a, b, then bop a' b' is the encoding
of op a b. This is the instance that makes resolution compose the
transfer through an op-tree.
A registered realization of a unary operation: the commuting square
enc (op x) = uop (enc x), the unary analogue of RelatedBinOp.
The commuting square for this operation.
Instances
Composition for unary operations. If uop realizes op and a' is the
encoding of a, then uop a' is the encoding of op a.
Leaf (generic encoding). The encoding of a value is related to it.
Low priority so the structural composeBinOp is tried first and resolution
terminates at leaves rather than looping.
Demonstration: the emitted Baby Bear field as registered operations #
The emitted Baby Bear field multiply realizes abstract * (identity
encoding). Witness: bbFieldMul_eq.
The emitted Baby Bear field add realizes abstract + (identity encoding).
Witness: bbFieldAdd_eq.