Zulip Chat Archive

Stream: new members

Topic: 0 - n = 0


Malvin Gattinger (Feb 28 2022 at 22:48):

I think I just learned that 0 - n = 0 for any n : ℕ in Lean, is that correct?

lemma theLemma { m n :  }: m = m - 1 - 1 - n + n + 2 :=
begin
  induction m,
  simp,
  -- why does Lean want me to prove  0 = n + 2  now?
  sorry,
  sorry,
end

-- oh, wait a minute!
#eval 0 - 1
-- | 0

Riccardo Brasca (Feb 28 2022 at 22:51):

Dont worry :)

Riccardo Brasca (Feb 28 2022 at 22:51):

You can read about it here

Riccardo Brasca (Feb 28 2022 at 22:53):

But the important part of the story is that subtraction on it's not exactly the operation you are familiar with (it is when its result is in ). If you try the same in , everything will behave as expected.

Riccardo Brasca (Feb 28 2022 at 22:54):

If you are a beginner I would suggest just to avoid subtraction on (or division in ).

Mario Carneiro (Feb 28 2022 at 23:00):

The short answer is that a - b in nat is actually the function max(a - b, 0)

Malvin Gattinger (Feb 28 2022 at 23:00):

Aha, okay, That blog post is excellent explanation and entertainment, thank you :sweat_smile:


Last updated: Dec 20 2023 at 11:08 UTC