Zulip Chat Archive

Stream: Is there code for X?

Topic: Enlarge the codomain of a function


Pedro Sánchez Terraf (Jan 05 2023 at 22:53):

Really basic question: I have S U : set α, h : S ⊆ U, and f : X → ↥S. Is there a coextension function such that coextension f h U : X → ↥U is f with codomain U?

I tried to do

#find Π x y, (x  y)  (_  x)  (_  y)

but found nothing (other searches, like #find (_ → _) → (_ ⊆ _) → (_ → _) resulted in “excessive memory consumption”).
Meta question: How do I look for things like this without bothering you??

Sky Wilshaw (Jan 05 2023 at 23:07):

You could try something like inclusion h \circ f.

Sky Wilshaw (Jan 05 2023 at 23:07):

docs#set.inclusion

Sky Wilshaw (Jan 05 2023 at 23:08):

At least in my opinion Lean is a hard language to learn, and asking questions should be encouraged - it certainly helped me a lot when I was learning!

Sky Wilshaw (Jan 05 2023 at 23:13):

One way to find functions that you might not know about is library_search. If you write a (precise enough) function signature, lean can try to search for a function that it knows about to basically fill in that function in any way it knows. For example:

example {α β : Type*} (S U : set α) (h : S  U) (f : β  S) (b : β) : U := by library_search

gives

Try this: refine set.inclusion h (f b)

You might have seen this in the context of writing proofs, where library_search gives a proof that's already in mathlib, but there's no real difference between proofs and other terms in Lean, so library_search can help you with both. Of course, it doesn't know what you're actually trying to do, so library_search won't always give you the correct answer:

def add_one (n : ) :  := by library_search
-- Try this: exact n

Last updated: Dec 20 2023 at 11:08 UTC