core

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package core implements definitional equality checking (conversion) for the HoTT kernel.

This package provides the conversion checking algorithm that determines if two terms are definitionally equal. This is essential for type checking, as types are compared for equality modulo computation (beta reduction, eta rules, etc.).

Conversion Checking

The Conv function reports whether two terms are definitionally equal under a typing environment:

env := core.NewEnv()
equal := core.Conv(env, term1, term2, ConvOptions{EnableEta: true})

The algorithm uses Normalization by Evaluation (NbE):

  1. Evaluate both terms to semantic values using internal/eval
  2. Reify values back to normal forms
  3. Apply η-expansion if enabled
  4. Compare normal forms structurally via AlphaEq

Options

ConvOptions controls conversion behavior:

  • EnableEta: Enable η-equality for functions (Π) and pairs (Σ)

Alpha-Equivalence

AlphaEq compares two terms for structural equality modulo de Bruijn indices. Since variables use de Bruijn indices, alpha-equivalence is simply structural comparison. This is used as the final step in conversion checking.

Eta-Equality

When [ConvOptions.EnableEta] is true, the converter recognizes eta-equal terms:

  • Functions: f ≡ \x. f x (eta rule for Π types)
  • Pairs: p ≡ (fst p, snd p) (eta rule for Σ types)

Environment

Env represents a typing environment mapping de Bruijn indices to values. It wraps eval.Env and is extended with terms using Env.Extend.

Cubical Type Theory

The package supports cubical type theory extensions including:

Cubical equality is handled via extension functions (alphaEqExtension, shiftTermExtension) that delegate to appropriate handlers for cubical terms.

Legacy API

ConvLegacy provides backward compatibility with code using EtaFlags. New code should use Conv with ConvOptions instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphaEq

func AlphaEq(a, b ast.Term) bool

AlphaEq compares two core terms modulo alpha (de Bruijn makes this structural).

func Conv

func Conv(env *Env, t, u ast.Term, opts ConvOptions) bool

Conv reports whether t and u are definitionally equal under env. If opts.EnableEta is true, use η-rules for functions (Pi) and pairs (Sigma).

Implementation strategy: 1. Evaluate both terms to Values using NbE 2. Reify both Values back to normal forms 3. Apply η-expansion if enabled 4. Compare normal forms structurally

func ConvLegacy added in v1.2.0

func ConvLegacy(a, b ast.Term, flags EtaFlags) bool

Conv (legacy) - wrapper for backward compatibility

Types

type ConvOptions added in v1.2.0

type ConvOptions struct {
	EnableEta bool // Enable η-equality for functions (Π) and pairs (Σ)
}

ConvOptions controls the behavior of definitional equality checking.

type Env added in v1.2.0

type Env struct {
	// contains filtered or unexported fields
}

Env represents a typing environment for conversion checking. For now, this is a simple wrapper around eval.Env.

func NewEnv added in v1.2.0

func NewEnv() *Env

NewEnv creates a new empty environment.

func (*Env) Extend added in v1.2.0

func (e *Env) Extend(t ast.Term) *Env

Extend adds a term to the environment by evaluating it.

type EtaFlags

type EtaFlags struct{ Pi, Sigma bool }

Legacy API compatibility - kept for existing tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL