Skip to content

feat(notations): add user-extensible notations#985

Draft
strub wants to merge 2 commits intomainfrom
notations
Draft

feat(notations): add user-extensible notations#985
strub wants to merge 2 commits intomainfrom
notations

Conversation

@strub
Copy link
Copy Markdown
Member

@strub strub commented Apr 23, 2026

Adds a notation construct that lets users declare #-prefixed
syntactic sugar for formulas, with template-based parsing and
typing-time expansion.

Notations are stored as operators (sharing abbreviation
infrastructure), so they work uniformly with import/export, clone,
locality, sections, qualified lookup, and rewrite /#foo unfolds.

Declarations:

notation #big ['a] #< i : 'a >
    (r : 'a list)
    (P : i ==> bool = predT)
    (F : i ==> t)
  "[" i " : " r ("| " P)? "] " F =
  big P F r.

Uses:

lemma L (d : 'a distr) (f : 'a -> real) J :
  uniq J =>
  BRA.#big [ x : J ] (mu1 d x * f x).`1 <= 1%r.

lemma M &m (bs : out_t list) :
  Dst.#big [ b : bs ] (Pr[A.guess() @ &m : res = b]) <= 1%r.

(* slot placeholders work as pose / rewrite patterns *)
pose c := #big [ _ : _ | _ ] _.

Expansions round-trip back to template syntax in the pretty-printer.

Includes a stdlib port: #big / #bigi are declared in Bigop.eca
and used across algebra, analysis, distributions, modules, and
crypto files.

Tests under tests/notations/ (wired into make unit) and reference
documentation under doc/notation.rst.

@strub strub self-assigned this Apr 23, 2026
@strub strub force-pushed the notations branch 2 times, most recently from 022943c to 50d9941 Compare April 23, 2026 12:33
Moves the polymorphic variant types used by the SMT option grammar
rules (`prover`, `pi`, `smt`) out of the parser's `%{ ... %}` header
into `EcParsetree` (renamed to `psmtprover`, `psmt_prover_info`,
`psmt` for consistency with the other `p*` parsetree types).

Also enables menhir's `--inspection` flag on the parser so the
generated `MenhirInterpreter` module exposes nonterminal symbols for
external inspection.  The flag requires nonterminal action types to
be accessible from outside the parser module, which is why the types
have to leave the `%{ ... %}` header.

Prep for a subsequent feature commit that relies on `--inspection`.
No semantic change to SMT parsing.
@strub strub force-pushed the notations branch 6 times, most recently from c83c264 to ac46337 Compare April 24, 2026 07:09
Adds a `notation` construct that lets users declare `#`-prefixed
syntactic sugar for formulas, with template-based parsing and
typing-time expansion.

Notations are stored as operators (sharing abbreviation
infrastructure), so they work uniformly with import/export, clone,
locality, sections, qualified lookup, and `rewrite /#foo` unfolds.

Declarations:

    notation #big ['a] #< i : 'a >
        (r : 'a list)
        (P : i ==> bool = predT)
        (F : i ==> t)
      "[" i " : " r ("| " P)? "] " F =
      big P F r.

Uses:

    lemma L (d : 'a distr) (f : 'a -> real) J :
      uniq J =>
      BRA.#big [ x : J ] (mu1 d x * f x).`1 <= 1%r.

    lemma M &m (bs : out_t list) :
      Dst.#big [ b : bs ] (Pr[A.guess() @ &m : res = b]) <= 1%r.

    (* slot placeholders work as pose / rewrite patterns *)
    pose c := #big [ _ : _ | _ ] _.

Expansions round-trip back to template syntax in the pretty-printer.

Includes a stdlib port: `#big` / `#bigi` are declared in Bigop.eca
and used across algebra, analysis, distributions, modules, and
crypto files.

Tests under tests/notations/ (wired into `make unit`) and reference
documentation under doc/notation.rst.
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.

1 participant