Skip to content

Improve speed of PMATCH_INTRO_CONV and PMATCH_ELIM_CONV in patternMatchesLib #2052

Open

Description

@ordinarymath

fun case_pmatch_eq_prove t t' = let
val tm = mk_eq (t, t')
(* very slow, simple approach. Just brute force.
TODO: change implementation to get more runtime-speed *)
val my_tac = (
REPEAT (BasicProvers.TOP_CASE_TAC THEN
ASM_REWRITE_TAC[]) THEN
FULL_SIMP_TAC (rc_ss []) [PMATCH_EVAL, PMATCH_ROW_COND_def,
PMATCH_INCOMPLETE_def]
)
in
(* set_goal ([], tm) *)
prove (tm, REPEAT my_tac)
end handle HOL_ERR _ => raise UNCHANGED
fun PMATCH_INTRO_CONV t =
case_pmatch_eq_prove t (case2pmatch true t)
fun PMATCH_INTRO_CONV_NO_OPTIMISE t =
case_pmatch_eq_prove t (case2pmatch false t)

fun PMATCH_ELIM_CONV t =
case_pmatch_eq_prove t (pmatch2case t)

TOP_CASE_TAC is terrible for performance.

Activity

  1. mn200 commented on Sep 7, 2026

    @mn200
    Member

    Is this code much used? If not, I will mark this as low priority.

  2. ordinarymath commented on Sep 7, 2026

    @ordinarymath
    ContributorAuthor

    PMATCH_ELIM_CONV is pretty much used for the pmatch theorems for CakeML definitions for the translator to use.

    
    Definition dest_Seq_def:
      (dest_Seq (Seq p1 p2) = (p1,p2:'a wordLang$prog)) /\
      (dest_Seq p = (Skip,p))
    End
    
    Theorem dest_Seq_pmatch:
      !p.
      dest_Seq p =
      pmatch p of
        Seq p1 p2 => (p1,p2:'a wordLang$prog)
       | p => (Skip,p)
    Proof
      rpt strip_tac
      >> CONV_TAC(RAND_CONV patternMatchesLib.PMATCH_ELIM_CONV)
      >> every_case_tac
      >> fs[dest_Seq_def]
    QED
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions