Zulip Chat Archive
Stream: new members
Topic: Lean doesn't recognize byContradiction / by_contra tactics
Michael Novak (Oct 18 2025 at 04:32):
I opened in nvim a new lean file which I named testing.lean. Then I started writing a few simple exercises, which worked well without any problem. Now I wanted to prove something by contradiction so I started with open Classical, then I started the proof and everything worked until the moment I started the proof by contradiction part - I got error message unknown tactic - both for byContradiction and by_contra (what's the difference between the two by the way?).
I suspect that maybe I should import something, maybe mathlib? This is the first time I open a lean file by my self - until now I used the files of the Math in Lean textbook, so I'm not sure exactly how to import libraries like mathlib and weather that's even relevant in this case because I didn't get any error on line open Classical so I assume this doesn't require mathlib, right?
David Renshaw (Oct 18 2025 at 04:35):
The by_contra tactic is defined in Batteries: https://github.com/leanprover-community/batteries/blob/8da40b72fece29b7d3fe3d768bac4c8910ce9bee/Batteries/Tactic/Init.lean#L30-L46
Michael Novak (Oct 18 2025 at 04:59):
what are Batteries?
Ruben Van de Velde (Oct 18 2025 at 05:40):
It's a library that you can depend on from your lakefile
Michael Novak (Oct 18 2025 at 05:49):
what is my lakefile?
Michael Novak (Oct 18 2025 at 05:51):
I just created a file named testing. lean, so maybe I should have done more, but I just don't know what (I'm not using VS code).
Ruben Van de Velde (Oct 18 2025 at 07:27):
Oh, if you want to write anything more than the most trivial of code, you'd best create a project using lake, which will allow you to depend on other projects
Kenny Lau (Oct 18 2025 at 07:28):
@Michael Novak you might want to consider setting up mathlib4 as dependency
Michael Novak (Oct 18 2025 at 07:43):
O.k, I followed the instructions here for creating a new lean project and now everything works. Sorry for being stupid and wasting your time, that's just not explained in the math in lean textbook (at least not in the first 4 chapters that I read).
Ruben Van de Velde (Oct 18 2025 at 07:50):
No worries, we're here to help
Kevin Buzzard (Oct 18 2025 at 08:16):
(especially in this channel, which is precisely for "I'm getting started and am stuck at some point on the gigantic learning curve" questions)
Last updated: Dec 20 2025 at 21:32 UTC