Skip to content

Algorithm for populating Trocq database for inductives#73

Open
Tvallejos wants to merge 42 commits into
rocq-community:masterfrom
Tvallejos:prop
Open

Algorithm for populating Trocq database for inductives#73
Tvallejos wants to merge 42 commits into
rocq-community:masterfrom
Tvallejos:prop

Conversation

@Tvallejos

Copy link
Copy Markdown

description todo

@MysaaJava

Copy link
Copy Markdown
Collaborator

TODO

  • rebase
  • git mv std/algo/theories generic/inductives and change std/_CoqProject and hott/_CoqProject accordingly
  • git mv std/algo/elpi elpi/inductives and update Elpi Accumulate accordingly
  • git mv std/algo/tests tests/inductives and update tests/_CoqProject.{std,hott} accordingly
  • Move most significant examples of std/algo/detailed to docs/inductive-generation, and write some documentation to docs/codebase.md about how the inductive generation works. Remove std/algo/detailed.
  • rename Umap to Map4
  • Remove coq.locate and {{ ... }} constructs from inside elpi code
  • Remove dead code inside Rel40

Todo for myself, after merge:

  • split utils.elpi content to adequates files if needed
  • accumulate from inside elpi files directly
  • Fold generic/Param_xxx into one file generic/Param_inductives.v Move check commands to tests/inductives/check_.....v
  • Add a failing test with an inductive to Prop. For example with derive False which should generate False_sym when it doesn't. Check Zulip #Trocq users & devs > populating the Trocq database

Issues for later:

  • There is a duplicated database with trocq.db, derive.param2.db and derive.xxx.db
  • Can we clean all the databases derive.xxxx.db ?

@Tvallejos

Copy link
Copy Markdown
Author

Hi @MysaaJava,
I'm using Trocq definitions in elpi files. Where should I register those definitions?

A few examples are Mapn.Has, eq_Mapn and eq

@MysaaJava

Copy link
Copy Markdown
Collaborator

I think you can add them to database.elpi.
You can add a predicate definition here, and accumulate on the clause.
You can see an example in Hierarchy.v which calls a predicate in generation/hierarchy.elpi

@Tvallejos

Copy link
Copy Markdown
Author

I've been working on recovering the build for HoTT.
Inductives in HoTT are defined using universe polymorphism, so I need to extend the plugins to not assume global _ terms. In particular, almost all my derivations query derive.param2.db, which currently does not support universe polymorphism issue.

I minimized the dependencies to derive, but there are a couple more that will need such extension. For instance, discriminate and isK in derive.
I'm working on adding support for these plugins before continuing.

@Tvallejos

Tvallejos commented May 11, 2026

Copy link
Copy Markdown
Author

This PR now depends on LPCIC/coq-elpi#1003.
To fully recover the build for HoTT, derivations isK and ltac.discriminate in elpi's derive have to be adapted to support universe polymorphic definitions PR. I'll be working on those.

@Tvallejos Tvallejos marked this pull request as draft May 11, 2026 13:29
@Tvallejos

Copy link
Copy Markdown
Author

Depends on LPCIC/coq-elpi#1003 and LPCIC/coq-elpi#1018 , which were merged before the release of rocq-elpi 3.4.0.

Also depends on LPCIC/coq-elpi#1022 and LPCIC/coq-elpi#1030 . The first PR was merged, but not released and the second PR is pending review.

I'll work on cleaning a bit the history before rebasing

@Tvallejos Tvallejos force-pushed the prop branch 2 times, most recently from a76bced to 652bcff Compare May 30, 2026 10:18
@Tvallejos

Tvallejos commented Jun 1, 2026

Copy link
Copy Markdown
Author

Hi @MysaaJava, @CohenCyril. Most of the CI is green again.
I'm getting an error building trocq-std-examples, but seems related to the nix setup.

Here is the error I'm getting:

File "./flt3_step.v", line 14, characters 0-50:
Error:
Compiled library mathcomp.algebra.ssralg (in file /nix/store/qgggghxlg3mhwj0wc59rlx9zsnk0xcfa-rocq-core9.1-mathcomp-algebra-2.5.0/lib/coq/9.1/user-contrib/mathcomp/algebra/ssralg.vo) makes inconsistent assumptions over library mathcomp.boot.nmodule

Would you know why is this happening?

@Tvallejos Tvallejos force-pushed the prop branch 4 times, most recently from 456c356 to 2ce27a3 Compare June 5, 2026 15:29
@Tvallejos

Copy link
Copy Markdown
Author

I removed the detailed examples of derivations from this PR.
The failing CI is due a nix issue I could not reproduce it locally. Here is a Zulip discussion about it.

@Tvallejos Tvallejos marked this pull request as ready for review June 5, 2026 16:41
@Tvallejos

Tvallejos commented Jun 5, 2026

Copy link
Copy Markdown
Author

A few comments:
mymap.elpi is derivative of map.elpi from coq-elpi.
The predicate whd-fuel is derivative of coq-elpi's.

Is there something to be done regarding license? both projects, trocq and coq-elpi are GNU LESSER GENERAL PUBLIC LICENSE

@MysaaJava MysaaJava left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comments on the code:

  • Remove all coq.locate and relpace them with database predicates POSTPONED
  • Use elpi accumulate system (and this should remove the need for #[superglobal])
  • Accumulate headers first, then files, and databases after
  • There is a lot of coq.typecheck ? ? _ is there a reason not to put ok instead of _ ?
  • Why are they main predicates both in elpi and rocq files ?

Questions for @CohenCyril

  • Should we have some "{{:gref ...}}" inside the code ? Why not, after all
  • Some utilities -> move them to util.elpi ?
  • Separate «static» database "trocq.consts" and «dynamic» database "trocq.translations" ?
  • What is Unset Universe Minimization ToSet. ?
  • The Trocq file header is not in the added files. How bad is that ?
  • Are the names of the Rocq files good ? Is From Trocq Require Import Relnm. clear ?

Comment thread examples/std/Vector_tuple.v Outdated
Comment thread elpi/inductives/mapn.elpi

pred build-has-of i:map-class, o:gref.
build-has-of M R :-
coq.locate {calc ("Map" ^ {map-class.to_string M} ^ ".BuildHas")} R.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with a database predicate

Comment thread elpi/inductives/mR.elpi Outdated
Comment thread elpi/inductives/mRRmK.elpi
Comment thread elpi/inductives/mRRmK.elpi Outdated
Comment thread hott/Stdlib.v Outdated
Comment thread std/algo/aignore/testing.v Outdated
Comment thread std/algo/aignore/testing.v Outdated
Comment thread std/_CoqProject
Comment thread tests/_CoqProject.hott Outdated
@CohenCyril

CohenCyril commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Should we have some "{{:gref ...}}" inside the code ? Why not, after all

All coq.locate and {{:gref ...}} have basically the same defect and must be removed when located outside .v file: indeed .elpi code is relocatable and importing the same .elpi file in distinct sets of Require Import directive may lead to different results.

Tvallejos added 10 commits June 24, 2026 17:08
algorithm design

collecting projectors

partially generating the type of the injection lemma

partially generating the type of injection lemmas + params

deriving injection lemmas type

correcting use of is

injection terms + definitions

adding injection lemmas to the db
…given an inductive

implementing mR for unit + bool

extending mR for enum containers

0+ constructors with 0+ arguments

mR for recursive non parametric inductives

Enum + Recursive no TyParam + TyParam no Recursive

mR working for recursive inductives with type parameters
deriving type of Rm

Rm for non inductive parameters, constructors without arguments

Rm for non parametric inductives, constructors with 0+ arguments

Rm for non parametric recursive arguments

using KR to get arguments for IR_ind

Rm for type parameters

Rm for type parameters + recursion
fix _Coqproject
injK init

refactoring some code

wip injK type

cleaning

refactoring + cleaning

moving some functions to utils

wip injK adding type conlusion

refactoring + generating injK types

body of injKij

tests for injK
mRRmK of False

mRRmK body, many constructors 0 args. Unit, Bool, etc

fixing imports + porting to elpi 3
fixing some duplicated files after the rebase
collecting arguments for rewriting injKs

mRRmK for inds with multiple constructors + multiple arguments. No recursion No Typaram

mRRmK + recusion

mRRmK for type parameters + recursion

cleaning mRRmK

deriving mRRmK
Tvallejos added 13 commits June 24, 2026 17:08
add logical path to generic/inductives

add generic to logical path in tests

rename rel44 umap + mv tests to tests/inductives removing checks in generic

fix tests

postpone docs on inductive generation
wip introducing use of coq.env.global to recover HoTT build

pruning extra plugins in derive
removing derive.bcongr dependency

removing derive.eqk dependency

removing some comments
adapt to univ.poly.param2 issue 1003 in rocq-elpi

fix some uses of coq.env.global

recovers param_empty for HoTT. requires isK and discriminate for pglobal to recover the rest

fixes param_bool for hott

adapt injections + injK to sortpoly

fix injK for inductives with type parameteres

fix sym symK non-dep path induction

fix option for hott

fixes sym and symK

fix injections + injK + Rm

fixes mRRmK up to sum

fixes prod + adds 'iota' for primitive projections

fixes lists

fix vector

fixes hott
recover examples/std

fixes examples/hott
update dependencies trocq-std

opam temporary hott dep + dev dep

update nix

temporary nix dependency for hott as discussed in rocq-community#79 and a temporary dependency for coq-elpi

update nix, last PR got merged in coq-elpi master
@Tvallejos Tvallejos force-pushed the prop branch 3 times, most recently from f74b49c to fc71038 Compare June 24, 2026 21:49
@Tvallejos Tvallejos requested a review from MysaaJava June 25, 2026 13:09

@MysaaJava MysaaJava left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Remove extra "Extra Dependencies"

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.

3 participants