Skip to content

Conversation

@mattam82
Copy link
Member

This PR adds a new loop-checking algorithm to MetaCoq, which should allow to handle arbitrary universe constraints efficiently, e.g. max (u + 1, v) = max (j, k+ 2). It is based on a constructive proof by Bezem et Coquand for the slightly more general problem of building a model in N^∞ of a set of horn clauses of shape u + k \/ ... \/ l + n -> l' + k'. This can be restricted to check if a loop follows from a set of constraints or if we have a model in N, which can in turn be seen as a valuation of the clauses making them all (non-vacuously) true.

The algorithm is currently only shown to be terminating and to return a valid model when it finds one, but it might also answer Loop, in which case we have not (yet) proven that there is indeed a loop.

I added a new extracted plugin in the test-suite (based on plugin-demo), that provides a new command MetaCoq Check Universes that checks for a model using the new algorithm on all the constraints in the global environment at the point of the call. It currently takes < 0.5s to verify that there is a valuation with 4 distinct universes for all the universes and constraints in Coq's standard library.

mattam82 and others added 3 commits July 17, 2025 14:32
Terminating but incorrect loop check

Improved version, whose termination relies on the correctness of check_model

Move back to template-coq folder

Improve the algorithm after discussion with Marc Bezem

Comment a bit

Try enforcing new constraints

Reorganize inner loop

Cleaner inner_loop

Finished inner loop

Inner loop termination proven

Before change of v_minus_w_bound

Prove the well-foundedness of loop

Inner loop termination proof finished

Finished all proofs

Finish proofs of auxilliary lemmas

Finished all proofs with new invariants

Comments and extraction setup

Abstract LoopChecking on level / sets / maps implementation

Move clauses.v to LoopChecking and TemplateLoopChecking

Functorize the algorithm

Simplified loops

Cleaned up LoopChecking and TemplateLoopChecking

Support correct quoting/unquoting of the universe graph/context.
Also rename Constraint to LevelConstraint, preparing for a later move to general universe constraints

Add a new (extracted) plugin to test the loop checking algorithm.

Move back to subst_instance_cstr for level constraints

Move live tests of loop_checking to the test-suite

Revert changes to Universes.v

Avoid repeateadly folding over clauses in inner loop

Optimize a bit loop checking to avoid partitioning clause repeatedly

Fix UnivConstraint -> LevelConstraint change

Remove useless extraction file in template-coq

MSetList is no longer needed
@mattam82 mattam82 force-pushed the universes-clause-check branch from 2549615 to 2d178ab Compare July 18, 2025 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants