Skip to content

Interactive mode to complete instances in tactics mode#595

Open
cecilemarcon wants to merge 16 commits into
math-comp:masterfrom
cecilemarcon:interactive-mode
Open

Interactive mode to complete instances in tactics mode#595
cecilemarcon wants to merge 16 commits into
math-comp:masterfrom
cecilemarcon:interactive-mode

Conversation

@cecilemarcon

Copy link
Copy Markdown
Collaborator

This adds an [#[interactive]] attribute to the HB.instance command.

This attribute opens goals to complete to finish the instance declaration.
Once these goals are completed, one uses the HB.endinstance command to finish the instance.

Any suggestions welcome !

@gares

gares commented Jun 5, 2026

Copy link
Copy Markdown
Member

Quick thing, if the test needs the Stdlib, it should go into tests_stdlib

Comment thread HB/structures.v Outdated
Comment on lines +840 to +866
func under term, list (pair term term) -> term.
under (fun N Ty F) Acc (fun N Ty F') :-
@pi-decl N Ty x\
under (F x) [(pr x Ty)|Acc] (F' x).
under (app L) Acc (app L') :-
aux Acc L L'.

func aux list (pair term term), list term -> list term.
aux _ [] [].
aux Acc [T|TS] [T|TS'] :-
coq.typecheck T Ty ok,
coq.typecheck Ty TyTy ok,
%coq.typecheck-ty does not make coercions
(not (TyTy = {{Prop}}); T = global _), !,
aux Acc TS TS'.
aux Acc [T|TS] [T'|TS'] :-
std.spy! (abstract Acc T TA),
log.coq.env.add-const _ TA _ @opaque! C,
T' = app [(global (const C))|{std.map Acc fst}],
aux Acc TS TS'.

func abstract list (pair term term), term -> term.
abstract [] T T' :-
copy T T'.
abstract [(pr V Ty) | A] T (fun `x` Ty F) :-
pi w\ (copy V w :- !) => abstract A T (F w).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this code should go to utils, maybe in a namespace abstract-props-as-lemmas.
You can then leave here just the call to abstract-props-as-lemmas.main (now called under).

Related design question for @CohenCyril is how configurable this should be, i.e. instead of using Prop as a marker one may want to flag the fields of mixins/factories as not-data. It may be possible to have a default (Prop) and a field-attribute as https://rocq-prover.org/doc/master/refman/language/extensions/canonical.html#rocq:attr.canonical (in rocq/Elpi) but it may require some little work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes I think it is better if configurable. But reasonable choices are essentially Prop, SProp and hProp. So possibly just registering them (as a open list) and unifying with them is enough.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

An issue with moving that code to utils is that it uses "log.coq.env.add-const" which is in log and which in turns uses some code from utils (eg "avoid-name-collision)
I could always create a new file to store these functions...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ignore log, the log module is a relic. I guess the collision avoidance code can go to utils as well.

Comment thread HB/structures.v Outdated
coq.typecheck T Ty ok,
coq.typecheck Ty TyTy ok,
%coq.typecheck-ty does not make coercions
(not (TyTy = {{Prop}}); T = global _), !,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if T is globla_ we don't really need to typecheck it. You could have a "fast path" for this case.
like a rule axu Acc [global _ as T|....

Comment thread HB/structures.v Outdated
func under term, list (pair term term) -> term.
under (fun N Ty F) Acc (fun N Ty F') :-
@pi-decl N Ty x\
under (F x) [(pr x Ty)|Acc] (F' x).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It may make sense to have a triple here and also store N, and use that N in abstract in place of `x`

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, done ! the name of the parameter is used in the abstraction

Comment thread HB/structures.v Outdated
}}.

#[proof="end"]
Elpi Export HB.endinstance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nitpick HB.end_instance

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done :)

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