Zulip Chat Archive
Stream: lean4
Topic: Decidable List.cons?
Bjørn Kjos-Hanssen (Jan 23 2024 at 21:50):
I'm not sure what to do here. apply?
gives a suggestion exact inst✝ (a :: w)
that doesn't work.
instance (P: List (Fin 2) → Prop) [DecidablePred P]
(w : List (Fin 2)) (a : Fin 2)
:
Decidable (P (a :: w)) := sorry
Ruben Van de Velde (Jan 23 2024 at 21:56):
Does inferInstance
work?
Damiano Testa (Jan 23 2024 at 21:57):
There was a discussion somewhere about what should exact?/apply?
do about inaccessible identifiers. If you need this to work, you can work around it like this:
Decidable (P (a :: w)) := by
rename_i h
exact h (a :: w)
Damiano Testa (Jan 23 2024 at 21:58):
Ruben, your suggestion work as well! As does by solve_by_elim
.
Bjørn Kjos-Hanssen (Jan 23 2024 at 22:05):
Nice!
(I hadn't realized that inst✝: DecidablePred P
being inaccessible was the problem.)
Kyle Miller (Jan 23 2024 at 22:21):
By the way, because inferInstance
works on its own, you shouldn't need to write this instance
Bjørn Kjos-Hanssen (Jan 23 2024 at 22:25):
Can I import inferInstance
?
Yury G. Kudryashov (Jan 23 2024 at 22:27):
In which sense "import"?
Yury G. Kudryashov (Jan 23 2024 at 22:28):
[DecidablePred P]
means (reducibly) [∀ x, Decidable (P x)]
, so you don't need x
-specific instances for Decidable (P x)
.
Bjørn Kjos-Hanssen (Jan 23 2024 at 22:31):
Yury G. Kudryashov said:
In which sense "import"?
Never mind, I see it now.
Bjørn Kjos-Hanssen (Jan 23 2024 at 22:36):
Kyle Miller said:
By the way, because
inferInstance
works on its own, you shouldn't need to write this instance
Perhaps we shouldn't even have to write := inferInstance
:smile: at all
Kim Morrison (Jan 23 2024 at 22:50):
Do you want to show us your example where you need it?
Bjørn Kjos-Hanssen (Jan 24 2024 at 00:02):
Scott Morrison said:
Do you want to show us your example where you need it?
It's for an implementation of recursive backtracking in Lean. I can already use that method to count the number of squarefree words of a given length, but I wanted to generalize it to arbitrary decidable properties P
. I can share shortly...
Bjørn Kjos-Hanssen (Jan 24 2024 at 01:23):
Scott Morrison said:
Do you want to show us your example where you need it?
https://github.com/bjoernkjoshanssen/bay/blob/main/Backtracking.lean
Eric Wieser (Jan 24 2024 at 01:26):
Could you put a lakefile.lean
and lean-toolchain
in that repository so that we can run the code in it?
Eric Wieser (Jan 24 2024 at 01:26):
Otherwise we have to guess the mathlib version, which guarantees that it won't work in future
Eric Wieser (Jan 24 2024 at 01:28):
I was able to paste it into the web editor and it worked ok
Eric Wieser (Jan 24 2024 at 01:28):
Kyle Miller said:
By the way, because
inferInstance
works on its own, you shouldn't need to write this instance
Kyle is correct; you can simply delete both instance
s and it keeps working
Bjørn Kjos-Hanssen (Jan 24 2024 at 01:36):
Eric Wieser said:
Kyle Miller said:
By the way, because
inferInstance
works on its own, you shouldn't need to write this instanceKyle is correct; you can simply delete both
instance
s and it keeps working
Oops, that's because I shared a working version without the generalization. But basically I want to replace squarefree
by an arbitrary (monotone, decidable) predicate on List (Fin 2)
.
Eric Wieser (Jan 24 2024 at 01:38):
I think the remark still remains
Bjørn Kjos-Hanssen (Jan 24 2024 at 03:55):
Eric Wieser said:
I think the remark still remains
I have fixed the code now so it works for an arbitrary "monotone" predicate and updated the github. And indeed, those two instances could be safely deleted.
Bjørn Kjos-Hanssen (Jan 24 2024 at 04:00):
The main point is illustrated in line 85: example : count_those_with_suffix SQF myvec = 1 := by decide
Squarefree binary words form a somewhat trivial example but it is easy to adapt to cover any "forbidden pattern", for instance cubefree words. Anyway, thanks for the help!
Last updated: May 02 2025 at 03:31 UTC