Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete the computable version of real.sqrt #13634

Closed
wants to merge 19 commits into from
Closed

Conversation

Smaug123
Copy link
Collaborator

@Smaug123 Smaug123 commented Apr 22, 2022

This PR is dramatically not ready for merge, or even for review. I'm putting it up so that I have something to make the subject of an "anyone interested in this project" thread in Zulip.

It may or may not be useful to follow https://proofwiki.org/wiki/Hero%27s_Method.

I've redefined sqrt_aux from what was originally there, because the original had some nasty "coalescing at 0" properties (see 430413a).

Open in Gitpod

@Smaug123 Smaug123 added the help-wanted The author needs attention to resolve issues label Apr 22, 2022
src/data/real/sqrt.lean Outdated Show resolved Hide resolved
src/data/real/sqrt.lean Outdated Show resolved Hide resolved
src/data/real/sqrt.lean Outdated Show resolved Hide resolved
src/data/real/sqrt.lean Outdated Show resolved Hide resolved
src/data/real/sqrt.lean Outdated Show resolved Hide resolved
src/data/real/sqrt.lean Outdated Show resolved Hide resolved
Comment on lines +160 to +161
lemma sq_div_self {a : ℚ} (a_nonzero : a ≠ 0) : a ^ 2 / a = a :=
by rw [pow_two, div_eq_iff a_nonzero]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the hypothesis is not needed given Lean's definition of division:

Suggested change
lemma sq_div_self {a : ℚ} (a_nonzero : a ≠ 0) : a ^ 2 / a = a :=
by rw [pow_two, div_eq_iff a_nonzero]
lemma sq_div_self {a : ℚ} : a ^ 2 / a = a :=
begin
obtain rfl|a_nonzero := eq_or_ne a 0,
{ rw [div_zero] },
{ rw [pow_two, div_eq_iff a_nonzero] }
end

and the lemma generalizes without changes to lemma sq_div_self {α : Type*} [group_with_zero α] {a : α} : a ^ 2 / a = a :=

reduce the import graph. -/
theorem rat.cauchy_schwarz (a b : ℚ) : 4 * a * b ≤ (a + b) ^ 2 :=
begin
suffices pos: 0 ≤ (a + b) ^ 2 - 4 * a * b, exact sub_nonneg.mp pos,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
suffices pos: 0 ≤ (a + b) ^ 2 - 4 * a * b, exact sub_nonneg.mp pos,
rw ←sub_nonneg,

Comment on lines +135 to +137
{ intros hyp,
{ by_contradiction,
exact sqrt_aux_ne_zero_step f i h hyp, }, },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ intros hyp,
{ by_contradiction,
exact sqrt_aux_ne_zero_step f i h hyp, }, },
{ intros hyp,
by_contradiction h,
exact sqrt_aux_ne_zero_step f i h hyp, },

induction i with i hyp,
{ unfold sqrt_aux, exact zero_le_one},
{ unfold sqrt_aux,
simp, cancel_denoms,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't leave a plain simp if it doesn't prove the goal - use simp? or squeeze_simp to replace it with simp only [...] with just the lemmas you use

... ≤ sqrt_aux f i ^ 2 / 4 : div_nonneg (sq_nonneg _) (by norm_num), },
{ rw max_eq_right_of_lt h,
by_cases sqrt_aux f i = 0,
{ simp at h, exfalso, exact h, },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this will work:

Suggested change
{ simp at h, exfalso, exact h, },
{ simpa using h },

Comment on lines 177 to 178
by_cases sqrt_aux f i = 0,
{ simp at h, exfalso, exact h, },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using by_cases and then immediately proving one case can't happen is not the most readable: you can do

have h : sqrt_aux f i ≠ 0,
{ ... },

by_cases sqrt_aux f i = 0,
{ simp at h, exfalso, exact h, },
{ cancel_denoms,
have u : _ := rat.cauchy_schwarz (sqrt_aux f i ^ 2) (f (i + 1)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
have u : _ := rat.cauchy_schwarz (sqrt_aux f i ^ 2) (f (i + 1)),
have u := rat.cauchy_schwarz (sqrt_aux f i ^ 2) (f (i + 1)),

@Smaug123 Smaug123 removed the help-wanted The author needs attention to resolve issues label Jun 5, 2022
@Smaug123
Copy link
Collaborator Author

Smaug123 commented Jun 5, 2022

Closing this because it's not obvious that it's even possible. The method doesn't converge at x=0, and I don't think diagonalising down to 0 is going to work either.

@Smaug123 Smaug123 closed this Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants