Zulip Chat Archive

Stream: mathlib4

Topic: Golfing a have in !4#4738


Jeremy Tan (Jun 06 2023 at 15:26):

!4#4738 This works, but is there a way to prove h₁ (with a real 3 exponent) in one line? I can't see the theorems that norm_cast used

theorem deriv2_sqrt_mul_log (x : ) :
    (deriv^[2]) (fun x => sqrt x * log x) x = -log x / (4 * sqrt x ^ 3) := by
  simp only [Nat.iterate, deriv_sqrt_mul_log']
  cases' le_or_lt x 0 with hx hx
  · rw [sqrt_eq_zero_of_nonpos hx]
    norm_num
    refine' HasDerivWithinAt.deriv_eq_zero _ (uniqueDiffOn_Iic 0 x hx)
    refine' (hasDerivWithinAt_const _ _ 0).congr_of_mem (fun x hx => _) hx
    rw [sqrt_eq_zero_of_nonpos hx, MulZeroClass.mul_zero, div_zero]
  · have h₀ : sqrt x  0 := sqrt_ne_zero'.2 hx
    convert (((hasDerivAt_log hx.ne').const_add 2).div ((hasDerivAt_sqrt hx.ne').const_mul 2) <|
      mul_ne_zero two_ne_zero h₀).deriv using 1
    nth_rw 3 [ mul_self_sqrt hx.le]
    have := pow_ne_zero 3 h₀
    have h₁ : sqrt x ^ 3  0 := by norm_cast
    field_simp; norm_cast; ring

Jeremy Tan (Jun 06 2023 at 15:27):

Note that in pow_ne_zero 3 h₀ the 3 is natural

Damiano Testa (Jun 06 2023 at 15:49):

have h₁ : sqrt x ^ 3  0 := ne_of_eq_of_ne (rpow_nat_cast (sqrt x) 3) (pow_ne_zero 3 h₀)

seems to work. I am not sure that this is really better, though.

Jireh Loreaux (Jun 06 2023 at 15:51):

@Jeremy Tan that 3 should have type , see docs#deriv2_sqrt_mul_log. You need the HPow local macro hack.

Jireh Loreaux (Jun 06 2023 at 15:53):

In general, if you see things that are naturals in powers that are being coerced to , there's a good chance lean4#2220 is to blame.

Jeremy Tan (Jun 06 2023 at 15:55):

Then why are you not fixing this now?

Ruben Van de Velde (Jun 06 2023 at 15:58):

Probably for much of the same reasons you aren't

Jireh Loreaux (Jun 06 2023 at 15:59):

Because you're working on the file? I'm in the middle of my own projects; it would be inconvenient for me to switch branches, pull, cache, change and push, not to mention the fact that the PR is not marked as help-wanted. There's a separation of responsibilities.

Jeremy Tan (Jun 06 2023 at 16:00):

I meant lean4#2220

Jeremy Tan (Jun 06 2023 at 16:02):

I've read the comments and there are a few nice proposals there

Jireh Loreaux (Jun 06 2023 at 16:07):

Again, separation of responsibilities (and authority). This is a Lean 4 core issue, and I have essentially no experience there. I trust others who are more comfortable in that space to handle it at some point. Maybe I will eventually get comfortable making PRs to Lean 4 core, but I don't feel a strong impetus to do so right now.

Jeremy Tan (Jun 06 2023 at 16:16):

I admit I did put the hack in one of my other PRs

Jireh Loreaux (Jun 06 2023 at 16:24):

That's the right approach for the moment. It preserves the intended declaration from mathlib3, and as long as you leave a porting note referencing lean4#2220, it can easily be removed when that issue is fixed.

Jeremy Tan (Jun 06 2023 at 17:20):

...though I had not included the hack when I started working on !4#4738, so I've re-ported the file properly at !4#4746

Jeremy Tan (Jun 06 2023 at 17:25):

With the hack the haves indeed disappear


Last updated: Dec 20 2023 at 11:08 UTC