Skip to content

Add named and local simplify hint databases#954

Open
strub wants to merge 1 commit into
mainfrom
hint-simplify-db
Open

Add named and local simplify hint databases#954
strub wants to merge 1 commit into
mainfrom
hint-simplify-db

Conversation

@strub
Copy link
Copy Markdown
Member

@strub strub commented Mar 25, 2026

Introduce named simplify databases, proof-local control over the active
DBs and lemmas, head-symbol filtering, and proof-local defaults for the
simplify/cbv simplification machinery.

Global declarations:

hint simplify {lemma}+ .             (* default database *)
hint simplify in {db} : {lemma}+ .   (* named database   *)

Selecting a database and filtering by head symbol on simplify/cbv:

simplify hint {db}                   (* use named database         *)
cbv      hint {db}
simplify with {sym}+                 (* only rules headed by sym   *)
simplify with - {sym}+               (* all rules except those     *)
simplify with {sym}+ hint {db}       (* filter + named database    *)

Proof-local modifications of the active configuration:

hint +db simplify {db}+ .            (* activate named DBs         *)
hint -db simplify {db}+ .            (* deactivate named DBs       *)
hint +simplify [in {db}] {lemma}+ .  (* add lemmas locally         *)
hint -simplify [in {db}] {lemma}+ .  (* remove lemmas locally      *)
hint clear simplify [in {db}] .      (* clear local add/remove     *)

Proof-local defaults consulted by later bare simplify/cbv calls:

hint simplify hint {db} .            (* default database           *)
hint simplify with [-] {sym}+ .      (* default head filter        *)
hint simplify clear .                (* clear local defaults       *)

Scoped application around a tactic, restored on the resulting subgoals:

with hint {command} ( {tactic} ) .

Thread the local simplify context through proof goals so the active DB
set, lemma overrides, default database, and head filter propagate across
subgoals and are consulted by simplify and cbv. Update simplify-hint
printing and reduction storage to support named databases and head
filtering.

Document all syntax forms in doc/tactics/hint-simplify.rst and add
regression tests (tests/hint_simplify_db.ec, tests/local_hint_simplify.ec,
tests/simplify_head_filter.ec).

@Gustavo2622
Copy link
Copy Markdown
Contributor

Partially answers #918 by wrapping exponent simplification lemmas.

@strub strub force-pushed the hint-simplify-db branch 6 times, most recently from 3ae8c0e to 38c60c2 Compare June 2, 2026 06:22
Introduce named simplify databases, proof-local control over the active
DBs and lemmas, head-symbol filtering, and proof-local defaults for the
`simplify`/`cbv` simplification machinery.

Global declarations:

    hint simplify {lemma}+ .             (* default database *)
    hint simplify in {db} : {lemma}+ .   (* named database   *)

Selecting a database and filtering by head symbol on simplify/cbv:

    simplify hint {db}                   (* use named database         *)
    cbv      hint {db}
    simplify with {sym}+                 (* only rules headed by sym   *)
    simplify with - {sym}+               (* all rules except those     *)
    simplify with {sym}+ hint {db}       (* filter + named database    *)

Proof-local modifications of the active configuration:

    hint +db simplify {db}+ .            (* activate named DBs         *)
    hint -db simplify {db}+ .            (* deactivate named DBs       *)
    hint +simplify [in {db}] {lemma}+ .  (* add lemmas locally         *)
    hint -simplify [in {db}] {lemma}+ .  (* remove lemmas locally      *)
    hint clear simplify [in {db}] .      (* clear local add/remove     *)

Proof-local defaults consulted by later bare simplify/cbv calls:

    hint simplify hint {db} .            (* default database           *)
    hint simplify with [-] {sym}+ .      (* default head filter        *)
    hint simplify clear .                (* clear local defaults       *)

Scoped application around a tactic, restored on the resulting subgoals:

    with hint {command} ( {tactic} ) .

Thread the local simplify context through proof goals so the active DB
set, lemma overrides, default database, and head filter propagate across
subgoals and are consulted by `simplify` and `cbv`. Update simplify-hint
printing and reduction storage to support named databases and head
filtering.

Document all syntax forms in doc/tactics/hint-simplify.rst and add
regression tests (tests/hint_simplify_db.ec, tests/local_hint_simplify.ec,
tests/simplify_head_filter.ec).
@strub strub force-pushed the hint-simplify-db branch from 38c60c2 to 0fbdba0 Compare June 2, 2026 06:25
Copy link
Copy Markdown
Contributor

@bgregoir bgregoir left a comment

Choose a reason for hiding this comment

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

General comment:
I think the syntax is a little bit to verbose.
More importantly, if I have well understood only one database can be selected. I don't understand this restriction.

Comment thread src/ecPrinting.ml
| EcTheory.Th_reduction { red_base; _ } ->
(* FIXME: section we should add the lemma in the reduction *)
Format.fprintf fmt "hint simplify."
begin match red_base with
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the printing info is partial here. Lemmas added or removed from the database are not printed

Comment thread src/ecPrinting.ml

| EcTheory.Th_reduction _ ->
| EcTheory.Th_reduction { red_base; _ } ->
(* FIXME: section we should add the lemma in the reduction *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this comment explain what should be done

Comment thread src/ecEnv.mli
val get : topsym -> env -> rule list
type base = symbol

val dname : symbol
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

dname is for "default name" ?

Comment thread src/ecEnv.mli
val add1 : path * rule_option * rule option -> env -> env
val add : ?import:bool -> (path * rule_option * rule option) list -> env -> env
val get : topsym -> env -> rule list
type base = symbol
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why a database name is a symbol and not a path?
I don't claim that it should be, just asking the question.

Comment thread src/ecSimplifyContext.ml

(* Name of the default simplify database. Must agree with
[EcEnv.Reduction.dname]. *)
let dname : symbol = ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why dname is defined here and also in ecEnv

Comment thread src/ecSimplifyContext.ml
(* -------------------------------------------------------------------- *)
let normbase (base : symbol option) : symbol =
match base with
| Some "default" | None -> dname
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we have Some "default" ? I think either option should be remove or "default" should

Comment thread src/ecSimplifyContext.ml
(* -------------------------------------------------------------------- *)
type simplify_context = {
ls_active : Ssym.t;
ls_default_db : symbol option option;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some comment will be welcome on the meaning of symbol option option...

Comment thread src/ecSimplifyContext.ml
: simplify_context
=
let hd = hd |> omap (fun (mode, paths) ->
let paths = List.fold_left (fun acc p -> Sp.add p acc) Sp.empty paths in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is no Sp.of_list function ?

Comment thread src/ecReduction.mli
logic : rlogic_info; (* perform logical simplification *)
modpath : bool; (* reduce module path *)
user : bool; (* reduce user defined rules *)
user_db : EcSymbols.symbol option; (* user reduction database *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it means that only one user reduction database can be added?

box (wrap_default x) = box (x + 1).
proof.
hint -db simplify default.
simplify.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should make sure it is disabling, maybe add "fail trivial" after first simplify?

proof.
hint +simplify wrap_localE.
hint -simplify wrap_localE.
simplify.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above, should make sure that simplify is failing

trivial.
qed.

lemma cbv_named_with_exclude (x : int) :
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this actually test whether wrap1 hint is excluded?

@strub
Copy link
Copy Markdown
Member Author

strub commented Jun 2, 2026

General comment:
I think the syntax is a little bit to verbose.
More importantly, if I have well understood only one database can be selected. I don't understand this restriction.

Several databases should be selectable. I'll check and fix if needed.

For the syntax, I agree. If you have a better proposition, I take it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants