Hello all,
I hope you're all well.
I wanted to ask whether the number 0 is considered a natural number in Isabelle/HOL?
Please find the snippet of code I am currently working with below:
(* Implementation of search in a quadtree - for naive quadtree *)
fun search_quadtree:: "nat quadtree ⇒ nat ⇒ bool" where
"search_quadtree (Leaf a) b = (if a = b then True else False)" |
"search_quadtree (Node l1 l2 l3 l4 a) b = (if a = b then True
else search_quadtree l1 b ∨
search_quadtree l2 b ∨
search_quadtree l3 b ∨
search_quadtree l4 b)"
(* Return the data in the node of a quadtree *)
fun datain_quadtree:: "nat quadtree ⇒ nat" where
"datain_quadtree (Leaf a) = a" |
"datain_quadtree (Node l1 l2 l3 l4 a) = a"
(* Create a function that returns a set of elements in the quadtree *)
fun quadtree_set:: "nat quadtree ⇒ nat set ⇒ nat set" where
"quadtree_set (Leaf a) as = {a} ∪ as" |
"quadtree_set (Node l1 l2 l3 l4 a) as = {a} ∪
{datain_quadtree l1} ∪
{datain_quadtree l2} ∪
{datain_quadtree l3} ∪
{datain_quadtree l4} ∪
as"
(* Create a function that returns a set of elements in that tree *)
lemma "search_quadtree quadtree a' ⟹ True ⟷ a' ∈ quadtree_set (quadtree) {}"
I'm currently working on writing a proof of the idea that:
The function search_quadtree looking for an element in the tree should return true if and only if it is part of the set of elements in the quadtree. Hopefully, this makes sense in the lemma.
After using sledgehammer, I get a counterexample (see below):
Auto Quickcheck found a counterexample:
quadtree = Node (Leaf 1) (Leaf 1) (Leaf 1) (Node (Leaf 0) (Leaf 0) (Leaf 0) (Leaf 0) 1) 1
a' = 0
Evaluated terms:
True = True
a' ∈ quadtree_set quadtree {} = False
I've tried to evaluate this quadtree and found that it only returns a set with the number 1, where I was expecting it to return a set {0, 1}.
This leads me to question: is the number 0 not a natural number in Isabelle/HOL?
0 is certainly of type nat
, otherwise the expressions here would not even type-check instead of not returning the value you expect. There seems to be a bug in quadtree_set
. In particular, there is no recursive call at all (unlike in search_quadtree
), so you only add the data immediately in the parameter and its immediate children (if any), but not anything that's nested more deeply.
Makes sense! Thank you Sebastian
Last updated: Dec 21 2024 at 16:20 UTC