Stream: Beginner Questions

Topic: Defining inductive predicate: fun vs primrec vs inductive?


view this post on Zulip Yiming Xu (Sep 11 2024 at 08:13):

I would like to translate the following type declaration into Isabelle/HOL.

view this post on Zulip Yiming Xu (Sep 11 2024 at 08:13):

image.png

view this post on Zulip Yiming Xu (Sep 11 2024 at 08:15):

The definitions above serves for evaluating a modal formula in the basic modal language. I defined formula, frame and model in Isabelle as follows. (Is everything good up to now?)

view this post on Zulip Yiming Xu (Sep 11 2024 at 08:15):

datatype form = VAR "num"
| FALSE
| DISJ "form" "form"
| NOT "form"
| DIAM "form"

record 'a frame =
world :: "'a ⇒ bool"
rel :: "'a ⇒ 'a ⇒ bool"

record 'a model = "'a frame" +
valt :: "num ⇒ 'a ⇒ bool"

view this post on Zulip Yiming Xu (Sep 11 2024 at 08:16):

But then I think I get confused on the translation of the "satis" predicate. It seems to be a bunch of options. There are primrec, fun and inductive. Is there any consideration that I should take before picking one?

view this post on Zulip Yiming Xu (Sep 11 2024 at 08:18):

I am attempting to do "fun". I wrote:
fun satis :: "'a model ⇒ 'a ⇒ form ⇒ bool"
where
"satis M w (VAR p) = M.valt p v ∧ M.frame.world w
| satis M w FALSE = false"

And it already started complaining:
image.png

view this post on Zulip Yiming Xu (Sep 11 2024 at 08:18):

May I please ask if there is any quick fix? Thanks in advance!

view this post on Zulip Yong Kiam (Sep 11 2024 at 08:30):

I'm not so familiar with record syntax in Isabelle, but that should be valt M

view this post on Zulip Yiming Xu (Sep 11 2024 at 08:59):

Yong Kiam said:

I'm not so familiar with record syntax in Isabelle, but that should be valt M

Thanks so much! The underscore before disappears.

view this post on Zulip Yiming Xu (Sep 11 2024 at 09:00):

Now I type (world (frame M)) and it does not look correct:
image.png

view this post on Zulip Yiming Xu (Sep 11 2024 at 09:01):

The "frame" is green, and may I please ask a "human language" translation of the error message?

view this post on Zulip Mathias Fleury (Sep 11 2024 at 13:41):

= is binding to strongly. Use statis M w ... <--> ... or statis M w ... = (...)

view this post on Zulip Mathias Fleury (Sep 11 2024 at 13:41):

And it is False

view this post on Zulip Mathias Fleury (Sep 11 2024 at 13:41):

instead of false

view this post on Zulip Yiming Xu (Sep 11 2024 at 16:29):

Thanks! I changed it into False and <-->.
image.png

view this post on Zulip Yiming Xu (Sep 11 2024 at 16:30):

Any clue why it thinks "frame" is green? M.frame also does not work.

view this post on Zulip Yiming Xu (Sep 11 2024 at 16:31):

Not obvious from https://isabelle.in.tum.de/doc/isar-ref.pdf how can we extract fields of a record term.

view this post on Zulip Mathias Fleury (Sep 11 2024 at 17:42):

frame is a type, you cannot use it as a function in a term

view this post on Zulip Mathias Fleury (Sep 11 2024 at 17:42):

I do not even know what you are trying to achieve

view this post on Zulip Yiming Xu (Sep 11 2024 at 17:47):

I would like the effect to be "a model consists of a frame and a valuation". So I should be able to type M.frame to extract the field "frame" from "M" and then type (M.frame).world to extract the field "world" from the frame "M.frame". But your comment does give a hint! I have just figured out the type "model" will not take "frame" as its field. So what I need is just "world M". Thank you!

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:01):

image.png

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:01):

For the type declaration, I wrote:

record 'a frame =
world :: "'a ⇒ bool"
rel :: "'a ⇒ 'a ⇒ bool"

record 'a model = "'a frame" +
valt :: "num ⇒ 'a ⇒ bool"

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:03):

The same recipe of writing rel M to be the field "rel" of M does not seem to work.

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:03):

Sorry if it turns out to be stupid, but I am confused again.

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:13):

It seems that Isabelle does not complain about rel M w v, it is complaining about te quantification.

image.png

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:13):

What's wrong here?

view this post on Zulip Mathias Fleury (Sep 11 2024 at 18:17):

add parentheses. And binds too strongly

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:19):

Thank you for the swift answer, it solves my problem.
image.png
Now Isabelle is happy.

view this post on Zulip Yiming Xu (Sep 11 2024 at 18:20):

(But I feel its strength to this extent is a bit weird.)

view this post on Zulip Yiming Xu (Sep 12 2024 at 03:52):

Regarding what to choose to use among fun/definition/primrec. I find an answer here:
https://courses.grainger.illinois.edu/cs576/sp2015/lectures/3-4/04-Isabelle-syntax-2x3.pdf slides 5.

view this post on Zulip Jan van Brügge (Sep 12 2024 at 18:04):

usually definition for stuff that does not recurse, fun for everything else

view this post on Zulip Jan van Brügge (Sep 12 2024 at 18:05):

there is rarely a reason to use primrec

view this post on Zulip Yiming Xu (Sep 12 2024 at 18:06):

Got it. I will just not use it for the foreseeable future then.


Last updated: Dec 21 2024 at 16:20 UTC