Zulip Chat Archive

Stream: new members

Topic: Subtraction types?


Sandy Maguire (Jan 12 2021 at 14:42):

I'm working on a theorem that postulates x \in \R - \Z. Does lean have a notion of subtraction types? Or do I need to kludge this together with x \in R and by showing \not \exists (k : \N), coe k = x?

Kevin Buzzard (Jan 12 2021 at 15:16):

What is \R - \Z? Is it a subtype or a subset? There are I guess different ways you can formalise this. If x : \R then you could just say

import data.real.basic

open set

example (x : ) : x  range (coe :   ) := sorry

Yakov Pechersky (Jan 12 2021 at 15:22):

Is a floor_ring? You could use things that aren't equal to their own floor.

Kevin Buzzard (Jan 12 2021 at 15:23):

It is a floor_ring but this is kind of clunky

Yakov Pechersky (Jan 12 2021 at 15:23):

Aww the thumbs up went away.

Kevin Buzzard (Jan 12 2021 at 15:23):

I wanted to indicate "yes it's a floor ring" but then I decided I didn't want to promote the idea of using this fact ;-)

Yakov Pechersky (Jan 12 2021 at 15:23):

Right, because it'd be equiv to the "not in range of coe", and one would have to show anyway that the things that _are_ equal to their own floor are exactly those that are in the range of coe.

Kevin Buzzard (Jan 12 2021 at 15:24):

It might all depend on how one is going to use this in the proof.

Sandy Maguire (Jan 14 2021 at 15:57):

Sorry --- forgot about this thread. The example is:

Suppose x∈R − Z and m∈Z such that x < m < x+ 1. Show that m is unique.

Kevin Buzzard (Jan 14 2021 at 16:00):

By "m is unique" you mean x < m < x + 1 -> x < n < x + 1 -> m = n right? In which case you don't need to assume that x is not an integer, this is true even in that case (for trivial reasons).

Sandy Maguire (Jan 14 2021 at 16:01):

Yes, that's what i mean by unique! But is this true for non-integers with lt rather than le?

Kevin Buzzard (Jan 14 2021 at 16:01):

import data.real.basic

example (x : ) (m n : ) : x < m  (m : ) < x + 1 
  x < n  (n : ) < x + 1  m = n := sorry

should be provable.

Kevin Buzzard (Jan 14 2021 at 16:02):

It's also true if you change x < m to x <= m and x < n to x <= n yes.

Kevin Buzzard (Jan 14 2021 at 16:03):

You don't ever need to assume something is a non-integer.

Kevin Buzzard (Jan 14 2021 at 16:03):

Where you need a non-integer is when you prove "exists m : Z, x < m < x + 1`. You don't need it for uniqueness.

Sandy Maguire (Jan 14 2021 at 16:03):

maybe i'm slow this morning (before coffee), but if x is an integer, then there are no integers for m, n to be between x and x + 1, right?

Kevin Buzzard (Jan 14 2021 at 16:04):

That's right, and that's why you can prove it, because you have a false assumption so you can prove anything.

Sandy Maguire (Jan 14 2021 at 16:04):

oh i see, thanks

Kevin Buzzard (Jan 14 2021 at 16:04):

I'm never saying "there exists an m for which this works", I'm only saying "if we have an m for which this works, then ..."

Sandy Maguire (Jan 14 2021 at 16:04):

that's more trivial than i was expecting :)

Damiano Testa (Jan 14 2021 at 16:05):

In Lean, trivial is the new hard...

Kevin Buzzard (Jan 14 2021 at 16:05):

And there will be a very elegant proof using le_floor or floor_le or floor_lt or whatever there is.

Sandy Maguire (Jan 14 2021 at 16:05):

out of personal curiosity (i'm a type guy first and foremost), is there some way to show x \in \R - \Z?

Kevin Buzzard (Jan 14 2021 at 16:05):

The floor function is a great example of an adjoint functor, I found to my surprise a while ago.

Kevin Buzzard (Jan 14 2021 at 16:06):

Sandy Maguire said:

out of personal curiosity (i'm a type guy first and foremost), is there some way to show x \in \R - \Z?

Under what assumptions? Of course this is false in general (take x = 37)

Sandy Maguire (Jan 14 2021 at 16:06):

sorry, show is the wrong word. subtract Z from the R type

Kevin Buzzard (Jan 14 2021 at 16:06):

(m : \R) <= x iff m <= floor(x)

Kevin Buzzard (Jan 14 2021 at 16:07):

You have to decide what the type of x is going to be. x can only have one type.

Kevin Buzzard (Jan 14 2021 at 16:07):

If x is going to have type real then you can just say that x is not an element of the subset of real consisting of integers.

Sandy Maguire (Jan 14 2021 at 16:07):

i think what you're saying is "just show it with a witness" rather than construct a new type which excludes the values

Kevin Buzzard (Jan 14 2021 at 16:08):

If however you want to make a completely new type R - Z, then you can make this type, and then if x is a term of that type then x will represent a real which isn't an integer, but x itself will not be a real number, which might have some annoying consequences down the line.

Kevin Buzzard (Jan 14 2021 at 16:08):

You can put a predicate on real saying "I am not in the range of the map from the integers" and then you can make a subtype corresponding to that predicate.

Sandy Maguire (Jan 14 2021 at 16:08):

i haven't yet wrapped my mind around lean's type system, and this question is just me trying to suss out where the edges are

Sandy Maguire (Jan 14 2021 at 16:09):

that's helpful, thanks

Kevin Buzzard (Jan 14 2021 at 16:09):

But then you will have a map from that subtype to the reals, and that map will not be "the identity map".

Sandy Maguire (Jan 14 2021 at 16:09):

while i have you, i'm trying to write a function biggest : \forall {alpha : Type}, (alpha -> \nat) -> \alpha

Kevin Buzzard (Jan 14 2021 at 16:10):

It will of course morally be the inclusion, but do you really want to make a new definition and then constantly apply that inclusion, prove lemmas about the definition? It is typically easier in a system like Lean to just use the definitions which are already there.

Sandy Maguire (Jan 14 2021 at 16:10):

which is not computable in general but probably lean can handle this?

Kevin Buzzard (Jan 14 2021 at 16:10):

computability isn't an issue, that's right

Sandy Maguire (Jan 14 2021 at 16:10):

i'm happy to restrict alpha to finite, enumerable types

Kevin Buzzard (Jan 14 2021 at 16:10):

Then it's nat.find on the image.

Sandy Maguire (Jan 14 2021 at 16:12):

i'll dig in. i really appreciate how helpful you are, kevin!

Kevin Buzzard (Jan 14 2021 at 16:12):

import data.real.basic

def RminusZ : Type := {x :  // ¬  n : , x = n}

example (x : RminusZ) :  := x -- fails because x is not a real

example (x : RminusZ) :  := x.val -- works because val : RminusZ -> R

Kevin Buzzard (Jan 14 2021 at 16:13):

Wait, it's a bit trickier than nat.find because what happens if the map from alpha to nat isn't injective? Then you have to choose a random element whose image is the max.

Kevin Buzzard (Jan 14 2021 at 16:13):

i.e. you have "joint biggest" elements.

Yakov Pechersky (Jan 14 2021 at 16:13):

What's annoying about the new type is that it's not closed under addition.

Yakov Pechersky (Jan 14 2021 at 16:14):

Can one even define addition on it?

Kevin Buzzard (Jan 14 2021 at 16:14):

Every definition you make is annoying until you have made the API for that definition.

Kevin Buzzard (Jan 14 2021 at 16:14):

You can define an action of the integers on it, Z -> RminusZ -> RminusZ using addition.

Kevin Buzzard (Jan 14 2021 at 16:15):

But every new definition comes with a certain amount of pain, and this is why it's easier to just add in assumptions to your theorems like (hx : ¬ ∃ n : ℤ, x = n).

Sandy Maguire (Jan 14 2021 at 16:16):

this is an extremely fruitful discussion. i'm coming from haskell where the answer is ALWAYS "define a new type"

Kevin Buzzard (Jan 14 2021 at 16:17):

Because what are you going to do with x : RminusZ anyway? You'll try and compare it with other real numbers or integers, so you will never be talking about x, you'll always be talking about x.val. And then eventually you'll need the proof that x isn't an integer, which is x.property I think (I just call it x.2), and then you realise that actually all you ever needed was x.val and x.2 and you could have just started with these anyway.

Kevin Buzzard (Jan 14 2021 at 16:18):

I don't know anything about Haskell I'm afraid, I'm a mathematician with very little programming experience.

Kevin Buzzard (Jan 14 2021 at 16:18):

I've just learnt the hard way how to say things in Lean in the way which makes them easiest to prove.

Sandy Maguire (Jan 14 2021 at 16:18):

@Kevin Buzzard mind pushing me a bit further on the "nat.find on the image" thread? is the predicate i want that x | \forall (y : \alpha), f x > f y ?

Kevin Buzzard (Jan 14 2021 at 16:19):

That predicate will never hold because y can be x

Sandy Maguire (Jan 14 2021 at 16:19):

fair. if i restrict that part away? :)

Kevin Buzzard (Jan 14 2021 at 16:21):

If f isn't injective you still have problems.

Sandy Maguire (Jan 14 2021 at 16:21):

okay, i'll think about what i actually want

Sandy Maguire (Jan 14 2021 at 16:21):

thanks again


Last updated: Dec 20 2023 at 11:08 UTC