`ptrEqThen`'s compiled implementation disagrees with its definition when `beq` is not reflexive

Open
#1,095 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active

Research direction

Read src/verso/Verso/BEq.lean, especially the definitions of ptrEqThen and ptrBEq, and reproduce the examples with native_decide and the NaN list. Compare the existing API contract with the documented constraints on withPtrEqUnsafe in Lean core; the issue leaves the choice of fix open. Done means the compiled implementations no longer disagree with their stated contract, with regression coverage for non-reflexive equality.

Written by the indexing model from the issue text.

Description

Verso.BEq.ptrEqThen beq x y is defined as beq x y, but its implemented_by replacement unsafePtrEqThen returns true whenever x and y are pointer-equal. The two agree only if beq is reflexive, and neither the signature nor the docstring requires that. With a non-reflexive beq, native_decide proves False:

import Verso.BEq
open Verso.BEq

def p (a _ : Nat) : Bool := decide (a < 1)

theorem logical : ptrEqThen p 1 1 = false := by simp [ptrEqThen, p]
theorem compiled : ptrEqThen p 1 1 = true := by native_decide
theorem ptrEqThen_false : False := by
  have h := logical.symm.trans compiled
  cases h
#print axioms ptrEqThen_false
-- 'ptrEqThen_false' depends on axioms: [propext, compiled._native.native_decide.ax_1_1]

ptrBEq has the same gap for any BEq instance that is not reflexive. With xs : List Float := [Float.ofBits 0x7ff8000000000000] (a NaN), #eval xs == xs prints false and #eval ptrBEq xs xs prints true.

Checked at 58b5db4989f67235d1fffb0e0bc4a02bdcc87412 (current main) with Lean 4.36.0-rc2.

This relies on native_decide, so it is not a kernel inconsistency. Verso's own call sites compare with derived or structural BEqs, and I did not find one whose result changes, so this is about the API contract and about proofs that use native_decide.

Possible fixes are to document that beq must be reflexive, or to take a proof argument as withPtrEq did. The docstring of withPtrEqUnsafe in Lean core explains why core no longer provides a polymorphic safe version, so a reflexivity hypothesis alone may not be enough for every α.

Dominant language
Lean
Stars
420
Forks
134
Avg merge
1d 9m
Merged PRs (30d)
46

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from leanprover/verso

All issues in leanprover/verso

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.