Dmitriy Traytel
2016-02-11 11:18:30 UTC
Hi Joachim,
that indeed would be a nice feature, not only for product types but for all non-recursive arguments of a (co)datatype constructor. Similarly for records.
I guess one non-invasive to implement this would be via a plugin to the free_constructors abstraction (c.f. Ctr_Sugar.ctr_sugar_interpretation). Jasmin and me are putting this on some low-priority feature request list. But if you really want the functionality (i.e. want to do it by yourself), we would be happy to give more guidance.
Cheers,
Dmitriy
that indeed would be a nice feature, not only for product types but for all non-recursive arguments of a (co)datatype constructor. Similarly for records.
I guess one non-invasive to implement this would be via a plugin to the free_constructors abstraction (c.f. Ctr_Sugar.ctr_sugar_interpretation). Jasmin and me are putting this on some low-priority feature request list. But if you really want the functionality (i.e. want to do it by yourself), we would be happy to give more guidance.
Cheers,
Dmitriy
Dear Isabelle list,
I was surprised to find that one function definition involving a type
(t1 × t2) would work, but the equivalent function definition involving
a custom data type isomorphic to (t1 × t2) (i.e. one constructor with
two fields) would not work. See
http://stackoverflow.com/questions/35225110/termination-checking-for-product-types
for the example.
The reason is, of course, that the selectors of the pair type are set
lemma measure_fst[measure_function]: "is_measure f ⟹ is_measure (λp. f (fst p))"
by (rule is_measure_trivial)
lemma measure_snd[measure_function]: "is_measure f ⟹ is_measure (λp. f (snd p))"
by (rule is_measure_trivial)
and doing something similar for my custom type solves the problem.
But it was still surprising, so I wonder if there is a reason not to
register a similar measure function for product data types by default.
Concrete proposal for your consideration: For product data types
datatype t = C t₁ ... tₙ
automatically generate the equivalent of
"is_measure f ⟹ is_measure (λ t. case t of C t₁ ... tₙ ⇒ (t₁,...,tₙ)"..
Greetings,
Joachim
--
Dipl.-Math. Dipl.-Inform. Joachim Breitner
Wissenschaftlicher Mitarbeiter
http://pp.ipd.kit.edu/~breitner
I was surprised to find that one function definition involving a type
(t1 × t2) would work, but the equivalent function definition involving
a custom data type isomorphic to (t1 × t2) (i.e. one constructor with
two fields) would not work. See
http://stackoverflow.com/questions/35225110/termination-checking-for-product-types
for the example.
The reason is, of course, that the selectors of the pair type are set
lemma measure_fst[measure_function]: "is_measure f ⟹ is_measure (λp. f (fst p))"
by (rule is_measure_trivial)
lemma measure_snd[measure_function]: "is_measure f ⟹ is_measure (λp. f (snd p))"
by (rule is_measure_trivial)
and doing something similar for my custom type solves the problem.
But it was still surprising, so I wonder if there is a reason not to
register a similar measure function for product data types by default.
Concrete proposal for your consideration: For product data types
datatype t = C t₁ ... tₙ
automatically generate the equivalent of
"is_measure f ⟹ is_measure (λ t. case t of C t₁ ... tₙ ⇒ (t₁,...,tₙ)"..
Greetings,
Joachim
--
Dipl.-Math. Dipl.-Inform. Joachim Breitner
Wissenschaftlicher Mitarbeiter
http://pp.ipd.kit.edu/~breitner