Zulip Chat Archive
Stream: Is there code for X?
Topic: test unique pair from two lists for a property, output bool
Jared green (Feb 07 2025 at 15:18):
i tried to write this:
variable {a :Type}[h : DecidableEq a] (l1 l2: List a) (f : a -> a -> Bool)
∃! s: a × a, s.1 ∈ l1 ∧ s.2 ∈ l2 ∧ f s.1 s.2
as a filtering condition over a list of pairs of lists. but then lean cant tell if thats decidable.
Aaron Liu (Feb 07 2025 at 15:24):
It seems like there are no definitions mentioning both docs#Decidable and docs#ExistsUnique.
If you add [DecidableEq a]
then typeclass search finds
Decidable (∃ a ∈ l1, ∃ b ∈ l2, f a b ∧ ∀ c ∈ l1, ∀ d ∈ l2, f c d → a = c ∧ b = d)
Edward van de Meent (Feb 07 2025 at 15:39):
i imagine it might be easier to filter using List.product
?
Jared green (Feb 07 2025 at 15:40):
yes it would, but i dont know the function
Jared green (Feb 07 2025 at 15:41):
list.existunique or list.one or something
Edward van de Meent (Feb 07 2025 at 15:42):
something like ((l1.product l2).filter (fun s => f s.1 s.2 = true)).length = 1
Edward van de Meent (Feb 07 2025 at 15:44):
import Mathlib
variable (α : Type) (l1 l2 : List α) [DecidableEq α] (f : α → α → Bool)
#synth Decidable (((l1.product l2).dedup.filter (fun s => f s.1 s.2 = true)).length = 1)
Last updated: May 02 2025 at 03:31 UTC