0

I want to create an executable inductive within a locale. Without the locale everything works fine:

definition "P a b = True"

inductive test :: "'a ⇒ 'a ⇒ bool" where
  "test a a" |
  "test a b ⟹ P b c ⟹ test a c" 

code_pred test .

However, when I try the same in a locale, it does not work:

locale localTest
begin
definition "P' a b = True"

inductive test' :: "'a ⇒ 'a ⇒ bool" where
  "test' a a" |
  "test' a b ⟹ P' b c ⟹ test' a c" 

code_pred test' 
end

The code_pred line in the locale returns the following error:

Not a constant: test'
corny
  • 7,824
  • 3
  • 14
  • 20

3 Answers3

2

Expressed sloppily, locales are an abstraction mechanism that allows to introduce new constants relative to some hypothetical constants satisfying hypothetical properties, whereas code generation is more concrete (you need all the information that is required to implement a function, not just its abstract specification).

For that reason you first need to interpret a locale, before you can generate code. Of course, in your example there are no hypothetical constants and properties, thus an interpretation is trivial

interpretation test: localTest .

After that, you can use

code_pred test.test' .
chris
  • 4,988
  • 20
  • 36
  • How does this apply to locales with parameters? [modified example](http://pastebin.com/3neFUcHv) – corny Mar 10 '13 at 12:25
2

You can give alternative introduction rules (see isabelle doc codegen section 4.2: Alternative introduction rules) and thereby avoid an interpretation. This also works for locales with parameters (and even for constants that are not defined inductively). A variant of your example having a parameter:

locale l =
  fixes A :: "'a set"
begin
definition "P a b = True"

inductive test :: "'a ⇒ 'a ⇒ bool" where
  "a ∈ A ⟹ test a a" |
  "test a b ⟹ P b c ⟹ test a c" 
end

We introduce a new constant

definition "foo A = l.test A"

And prove its introduction rules (thus the new constant is sound w.r.t. the old one).

lemma [code_pred_intro]:
  "a ∈ A ⟹ foo A a a"
  "foo A a b ⟹ l.P b c ⟹ foo A a c"
  unfolding foo_def by (fact l.test.intros)+

Finally, we have to show that the new constant is also complete w.r.t. the old one:

code_pred foo by (unfold foo_def) (metis l.test.simps)
chris
  • 4,988
  • 20
  • 36
0

Complete guess here, but I'm wondering if renaming test to test' has messed things up for you. (Consider changing code_pred test' to code_pred "test'".)

John Wickerson
  • 1,204
  • 12
  • 23