Zulip Chat Archive

Stream: new members

Topic: Default alternative


Nicolò Cavalleri (Jul 14 2021 at 09:31):

I want to define a map which takes certain values on a set of a type and takes garbage values on the complementary of the set. Is there a way to do this without requiring the target type to be inhabited and sending terms in the complementary of the set on the default term? I'd like to do this without requiring additional type classes

Kevin Buzzard (Jul 14 2021 at 09:49):

What if the set and the target type are both empty?

Nicolò Cavalleri (Jul 14 2021 at 09:58):

You're right, sorry, I missed an important detail. I am in the following situation: the domain is inhabited iff the codomain is.

Nicolò Cavalleri (Jul 14 2021 at 09:58):

The domain is the base space of a vector bundle and the codomain is the total space

Eric Wieser (Jul 14 2021 at 09:59):

You can always use if nonempty domain then (assume x, sorry) else false.elim sorry as your (noncomputable) implementation

Nicolò Cavalleri (Jul 14 2021 at 10:19):

What is the difference between inhabited and nonempty?

Eric Wieser (Jul 14 2021 at 10:22):

The former is in Type u, the latter is in Prop

Eric Wieser (Jul 14 2021 at 10:23):

docs#ite requires a prop

Nicolò Cavalleri (Jul 14 2021 at 10:23):

Ok thanks!

Nicolò Cavalleri (Jul 14 2021 at 10:46):

I can see there is nonempty_of_inhabited but is there any inhabited_of_nonempty?

Eric Wieser (Jul 14 2021 at 10:55):

Theres tactic#inhabit

Eric Wieser (Jul 14 2021 at 10:55):

But also, it's very rare to need what you're asking for. If you have h: nonempty T instead of h : inhabited T, you can use docs#classical.choice instead of docs#default.

Nicolò Cavalleri (Jul 14 2021 at 10:58):

Ok thanks! Also it tells me that it cannot synthesize an instance for decidable (nonempty B) B is just a Type. Is this normal?

Nicolò Cavalleri (Jul 14 2021 at 11:54):

I guess I'll need to do

open classical
local attribute [instance] prop_decidable

Anne Baanen (Jul 14 2021 at 12:06):

Exactly, or you can write open_locale classical to do so in one line.

Anne Baanen (Jul 14 2021 at 12:11):

Some more details: The reason we distinguish between inhabited X and nonempty X is that the former is strictly stronger intuitionistically: a term in inhabited X points to a specific element of X, while a term in nonempty X shows that it is contradictory to assume there are no elements of X at all. So going from inhabited X to X is easy, while going from nonempty X to X is not computable.

For example, for the type X of all x : ℕ such that either x = 0 and the Riemann hypothesis doesn't hold, or x = 1 and the Riemann hypothesis holds, it's very difficult to give an example of X, while it's easy to show that X cannot be empty.

Anne Baanen (Jul 14 2021 at 12:13):

Nicolò Cavalleri said:

Ok thanks! Also it tells me that it cannot synthesize an instance for decidable (nonempty B) B is just a Type. Is this normal?

Yes, nonempty is not in general decidable. Consider for example the type X containing all valid proofs of the Riemann hypothesis. Determining whether this type is empty is at least as hard as proving or disproving RH.

Nicolò Cavalleri (Jul 14 2021 at 18:15):

@Anne Baanen thank you very much for this explanation


Last updated: Dec 20 2023 at 11:08 UTC