Bad name binding in Isabelle - isabelle

When entering the following definition
datatype env = "nat => 'a option"
Isabelle/jedit shows an exclamation mark and says
Legacy feature! Bad name binding: "nat => 'a option"
What is the problem and how can I fix this type synonym?
Update: even
datatype 'a env = "nat => 'a option"
which is better a definition in theory did not solve the problem.

On the right-hand side of a datatype definition, you normally list the constructors of the datatype. In your example, you have not written any constructor, so datatype thinks that you want to call it nat => 'a option, which is not a legal name for a constructor or any other Isabelle constant.
If you just want to introduce env as a type abbreviation for nat => 'a option, type_synonym is what you are looking for.
type_synonym 'a env = "nat => 'a option"
Note that you have to repeat all type variables on the left-hand side. Then, 'a env and nat => 'a option can be used interchangeably. If you want to introduce a new type constructor for env, then you must provide a constructor name such as Env:
datatype 'a env = Env "nat => 'a option"

Related

Isabelle/HOL error Type unification failed: Clash of types "nat" and "_ set" Type error in application: incompatible operand type

Im really new to isabelle, this is my problem
theory MyTheory3
imports Main
begin
(* 3.1) a) define a type natpair, whose elements are pairs of natural numbers.*)
datatype natpair = Natpair "nat × nat"
(*3.1 b)define a function of type natpair ⇒ nat that returns the sum of the elements of a pair of natural
numbers.*)
definition natpair_sum :: "natpair ⇒ nat" where
"Natpair((a::nat) × (b::nat)) = a + b"
end
i get the error
Type unification failed: Clash of types "nat" and "_ set"
Type error in application: incompatible operand type
Operator: (×) :: ??'a set ⇒ ??'b set ⇒ (??'a × ??'b) set Operand: a
:: nat
in addition, can someone show me an example of natpair with a parameterized
constructor
Thanks in advance
youre nuric
Your code has several issues:
Operator (×) is not a constructor for pairs but the Cartesian product of sets; pairs are constructed using the syntax (a, b) or Pair a b.
The definition natpair_sum does not use its name in the equation, that is, the correct syntax is definition natpair_sum :: "natpair ⇒ nat" where "natpair_sum ... = ...".
Pattern matching is not allowed in the left-hand side of a definition; you can use the case construct in the right-hand side of the definition or you can use functions instead.
There is no need to add type annotations for the components of the pair.
As examples, here are two possible definitions for natpair_sum:
definition natpair_sum :: "natpair ⇒ nat" where
"natpair_sum np = (case np of Natpair (a, b) ⇒ a + b)"
fun natpair_sum :: "natpair ⇒ nat" where
"natpair_sum (Natpair (a, b)) = a + b"
As for your last question, I'm not quite sure what you mean by "an example of natpair with a parameterized constructor". Natpair is already a data constructor which takes a pair of nat's as the only parameter.

What is the main symbol in Isabelle's set operator (‘) :: ('a => 'b) => 'a set => 'b set?

I was wondering what is the symbol ‘ in the Isabelle tutorial main.pdf below (under the section "Set")?
(‘) :: ('a => 'b) => 'a set => 'b set
By looking into the symbols tab, the closest in shape I could find is \<acute> under the "Unsorted" category. I tried to evaluate the following expression, but it doesn't parse:
value "´ (λ(n::nat). n+1) {1,2}"
value "(λ(n::nat). n+1) ´ {1,2}"
Can anyone help to explain the usage here and what it does?
I believe that the symbol that you are looking for is `, not ‘ or ´. The symbol ` is an infix notation for the constant image that is defined in theory Set.thy in the main library of Isabelle/HOL. Hopefully, the name of the constant is self-explanatory. For completeness, I restate the definition in this answer:
definition image :: "('a ⇒ 'b) ⇒ 'a set ⇒ 'b set" (infixr "`" 90)
where "f ` A = {y. ∃x∈A. y = f x}"
Thence,
value "(λ(n::nat). n+1) ` {1,2}"
evaluates to "{2, 3}" :: "nat set", as expected.

Isabelle/Simpl: Type unification failed using hoarestate

I started using Isabelle/Simpl and write the following theory according to the user guide:
theory Scratch
imports Simpl.Simpl
begin
hoarestate newvars =
N :: nat
lemma (in newvars) "Γ ⊢ {} ´N :== ´N + 1 {}"
sorry
end
But Isabelle complains that type unification fails:
Type unification failed
Type error in application: operator not of function type
Operator: N_' :: 'a
Operand: s :: ??'a
Simpl itself (including its user guide) successfully compiles.
How can I make it pass?
As Javier Díaz pointed out, importing only Simpl.Vcg instead of Simpl.Simpl does the trick.
The cause of the error seems a name collision against a record defined in Simpl.SyntaxTest. It contains the following record definition:
record 'g vars = "'g state" +
A_' :: "nat list"
AA_' :: "nat list list"
I_' :: nat
M_' :: nat
N_' :: nat
R_' :: int
S_' :: int
B_' :: bool
Abr_':: string
p_' :: ref
q_' :: ref
Isabelle seems to prefer N_' in the record to N in the hoarestate, although the hoarestate is defined later😥. I don't know why this is the case.

Constraining type variables in locales

The Isabelle library contains the classes real_inner and real_normed_vector, the latter of which is declared a subclass of the former in ~~src/HOL/Library/Inner_Product.thy.
Now, suppose we have a locale
locale foo =
fixes goo :: "'a::{real_normed_vector} => bool"
and wish to extend this locale with some new constants, and also constraining the sort of 'a to be real_inner at the same time, like so:
locale extended = foo +
fixes ext :: "'a::{real_inner} => nat"
Is there a way to do this? Trying to do this using the examples above sees Isabelle give goo the type 'b::{real_normed_vector} => bool in extended, when I instead require the type 'a::{real_inner} => bool.
You can do it like this:
locale extended = foo goo
for goo :: "'a :: real_inner ⇒ bool" +
fixes ext :: "'a => nat"

Defining a function which returns functions in Isabelle

I'm trying to do the following simple thing: given a topological space, extract its topology and view it as a poset. For that, I imported Topology.thy and Orders.thy and tried something along these lines
fun undtop :: "'a top ⇒'a partial_order" where
"undtop T = (leq ::"T ⇒ T ⇒ bool" where
"leq x y = (x ⊆ y)")"
where 'a top is the type 'a set set and partial_order is of type 'a=>'a => bool (the theory Orders.thy defines a class class partial_order) . The idea was that some T of type a' top should give the topology and then undtop would pick such a T and associate a partial order leq, viewed as a map T => T => bool. Clearly this is not how it works, so I'd like to ask
1) How would you define a function that picks each T of a certain type and defines a new function with domain T?
2) How to specify that this T of type 'a top is a topology, and not just a random collection of subsets, i.e how do I tell Isabelle that it should obey the axioms of the locale "topology" in Topology.thy?
Thank you for the support, as a beginner I'm still struggling with the syntax and the way Isabelle operates.

Resources