Zulip Chat Archive

Stream: Is there code for X?

Topic: Euler's number e


Iocta (Jun 19 2024 at 20:25):

I see there is the Real.exp function. Is the number e defined?

Riccardo Brasca (Jun 19 2024 at 20:26):

It is Real.exp 1. I don't think there is a notation for it

Riccardo Brasca (Jun 19 2024 at 20:26):

In the sense that when we need it we just write Real.exp 1.

Jireh Loreaux (Jun 20 2024 at 16:10):

There is a unicode character for this: U+2107 , but that looks an awful lot like epsilon. Potentially we could use 𝑒, which is U+1D452, in the Real scope.

Edward van de Meent (Jun 20 2024 at 19:23):

i think introducing that notation might trick people into writing e^x rather than Real.exp x, which might lead to defeq problems?

Kyle Miller (Jun 20 2024 at 23:09):

It's probably not a good idea, but that could be addressed with a macro:

notation "𝑒" => Real.exp 1

macro_rules | `(𝑒 ^ $x) => `(Real.exp $x)

#check 𝑒 ^ 2
-- Real.exp 2

Vincent Beffara (Jun 21 2024 at 07:00):

But then other people would write e^z to mean Complex.exp z

Edward van de Meent (Jun 21 2024 at 09:47):

then something like

import Mathlib.Data.Complex.Basic

class NaturalExp (R:Type*) where
  exp : R -> R -- possibly more fields, i'm not sure what kind of requirements are natural here

noncomputable instance : NaturalExp Real where
  exp := Real.exp

noncomputable instance : NaturalExp Complex where
  exp := Complex.exp

notation "𝑒" => NaturalExp.exp 1

macro_rules | `(𝑒 ^ $x) => `(NaturalExp.exp $x)

example : 𝑒 ^ 2 = Real.exp 2 := rfl

example : 𝑒 ^ 2 = Complex.exp 2 := rfl

Edward van de Meent (Jun 21 2024 at 10:07):

i imagine fields like exp_add and exp_zero are some natural conditions... but these aren't sufficient conditions to uniquely define (𝑒 ^ .)

Eric Rodriguez (Jun 21 2024 at 11:23):

If it's just a notation class we usually don't need to add conditions

Edward van de Meent (Jun 21 2024 at 11:56):

i suppose that's fair...

Edward van de Meent (Jun 21 2024 at 11:58):

but i imagine unifying the api involved would be useful...

Edward van de Meent (Jun 21 2024 at 11:58):

and i think that takes more than just a notation class

Eric Rodriguez (Jun 21 2024 at 13:57):

I don't know if it's wise to unify the API, just let lemmas for all the different exps apply IMO

Eric Wieser (Jun 21 2024 at 13:58):

Don't forget docs#NormedSpace.exp

Jireh Loreaux (Jun 21 2024 at 14:57):

I think we don't need the macro expansion for 𝑒 ^ x if we just put in the docstring for the notation that it should only be used for Real.exp 1.

Eric Wieser (Jun 21 2024 at 16:20):

elab_rules | `(𝑒 ^ $x) => throwError "don't do this"

Mario Carneiro (Jun 22 2024 at 19:14):

that could be a linter...

Edward van de Meent (Jun 22 2024 at 19:16):

linters like this can be elab_rules, you mean? :upside_down:

Eric Wieser (Jun 23 2024 at 18:19):

Mario Carneiro said:

that could be a linter...

What's the difference between a linter and an elaborator that throws a warning using logLint?

Damiano Testa (Jun 23 2024 at 18:21):

It is easier to silence the linter than the elaborator.

Eric Wieser (Jun 23 2024 at 20:12):

Well, if the elaborator calls docs#Lean.Linter.logLintIf then the silencing mechanism is unchanged

Mario Carneiro (Jun 24 2024 at 23:20):

Note, I count "fake linters" that run during elaboration but use logLint as linters for this purpose

Mario Carneiro (Jun 24 2024 at 23:21):

(an example of which is linter.deprecated)


Last updated: May 02 2025 at 03:31 UTC