Zulip Chat Archive

Stream: new members

Topic: I can't make sense of this error


Icaro Costa (Jan 09 2023 at 23:58):

This is my code:

import analysis.calculus.deriv
import data.real.basic
import data.list.basic
import tactic
import algebra.big_operators.basic
import data.nat.interval

import algebra.group.defs

open_locale big_operators

open finset

/-Function definitions-/
variable (f :   )
variable (u :   )
variable (C :   )

noncomputable def D : (  )  (  )
  | a := deriv a

noncomputable def Dn : ()  (  )  (  )
  | 0 := id
  | 1 := D
  | (a+1) := D  Dn a

noncomputable def h (n : )(x : ) :  :=  p in Icc 1 n, (C p) * (((Dn (n-p) (D u)) x)^p) * ((Dn p u) x)

noncomputable def Dnfu (n : ) :    := (Dn n) (f  u)

#check Dn 1 (f  u)
#check Dnfu 1

The output of #check Dn 1 (f ∘ u) is Dn 1 (f ∘ u) : ℝ → ℝ, which is what I'm expecting. However, #check Dnfu 1 outputs Dnfu 1 : (ℝ → ℝ) → ℕ → ℝ → ℝ. Why is that?

Yakov Pechersky (Jan 10 2023 at 00:01):

It's because you have

variable (f :   )
variable (u :   )

so Dnfu (f : ℝ → ℝ) (u : ℝ → ℝ) (n : ℕ) : ℝ → ℝ := ...

Sky Wilshaw (Jan 10 2023 at 00:02):

Note that lean can interpret the symbol 1 as quite a lot of things, and in this case, it's interpreting it as a function ℝ → ℝ.

Yakov Pechersky (Jan 10 2023 at 00:02):

while neither f nor u are mentioned in the body of def Dn, so they are not inferred to be variables/arguments of that function.

Icaro Costa (Jan 10 2023 at 00:03):

Sky Wilshaw said:

Note that lean can interpret the symbol 1 as quite a lot of things, and in this case, it's interpreting it as a function ℝ → ℝ.

Wait, really? How do I just write "one"

Sky Wilshaw (Jan 10 2023 at 00:03):

As Yakov said, the first argument to Dnfuis actually f.

Yakov Pechersky (Jan 10 2023 at 00:03):

#check Dnfu f u 1

Icaro Costa (Jan 10 2023 at 00:06):

Oh, so it still expects f and u even though they aren't arguments of Dnfu?

Yakov Pechersky (Jan 10 2023 at 00:06):

Yakov Pechersky said:

It's because you have

variable (f :   )
variable (u :   )

so Dnfu (f : ℝ → ℝ) (u : ℝ → ℝ) (n : ℕ) : ℝ → ℝ := ...

because f and u are mentioned in the body of Dnfu. How could f and u not be arguments of Dnfu if they're mentioned in the body?

Sky Wilshaw (Jan 10 2023 at 00:07):

Actually, lean detects that they are arguments! The keyword variable makes f and u parameters to any function that uses them.

Icaro Costa (Jan 10 2023 at 00:09):

Sky Wilshaw said:

Actually, lean detects that they are arguments! The keyword variable makes f and u parameters to any function that uses them.

Oh, is there a way to make them just "arbitrary" functions? As some sort of constant

Sky Wilshaw (Jan 10 2023 at 00:09):

This is the correct way to do that.

Sky Wilshaw (Jan 10 2023 at 00:10):

A "constant in the environment" is exactly the same as a parameter to a function.

Sky Wilshaw (Jan 10 2023 at 00:11):

But when you used these functions in #check, lean didn't know if you really wanted to use the f from the environment or some other f.

Icaro Costa (Jan 10 2023 at 00:12):

Sky Wilshaw said:

But when you used these functions in #check, lean didn't know if you really wanted to use the f from the environment or some other f.

Ok, it's making sense now. How do I tell #check that I want to use the same f without having to pass it as a parameter?

Sky Wilshaw (Jan 10 2023 at 00:12):

I don't know of an easy way to do this. Most of the time, you won't be using #check, so this isn't usually a problem.

Sky Wilshaw (Jan 10 2023 at 00:13):

I mean, you'll only use #check while testing.

Sky Wilshaw (Jan 10 2023 at 00:13):

When you're writing theorems, you don't need to pass f explicitly.

Icaro Costa (Jan 10 2023 at 00:14):

Ok, I think I can live with that.

Icaro Costa (Jan 10 2023 at 00:14):

Thanks for the help, Sky and Yakov


Last updated: Dec 20 2023 at 11:08 UTC