Zulip Chat Archive

Stream: new members

Topic: Beginner question


Guilherme Espada (Jan 11 2021 at 17:29):

The following code:

inductive term
|t_true : term
|t_false : term
|t_zero : term


def size : term -> 
| t_true := 1
| t_false := 1
| t_zero := 1

does not work. What am I missing?

Kevin Buzzard (Jan 11 2021 at 17:37):

I'm missing the error message

Kevin Buzzard (Jan 11 2021 at 17:37):

And you're probably missing open term

Guilherme Espada (Jan 11 2021 at 17:41):

This fixes it!
(the error message is invalid application, function expected)
Another question, when I list only a single option on the size function, it doesn't error. Why?

def size : term -> 
| t_true := 1

Reid Barton (Jan 11 2021 at 17:43):

Same reason that

def size : term -> 
| anything := 1

doesn't error

Guilherme Espada (Jan 11 2021 at 18:00):

Thanks!

Omar Shehab (Mar 20 2024 at 11:35):

 let M := factorial N + 1;
  let p := minFac M;
  have pp : Prime p | {
    refine minFac_prime _:
    have : factorial N > 0,
    from factorial_pos N;
    linarith,
  },

I have an error in this part can anybody help with that

Yaël Dillies (Mar 20 2024 at 11:42):

You can add #backticks to make your message readable

Arthur Paulino (Mar 20 2024 at 11:43):

Note: #backticks is a clickable like that will tell you what people mean by "backticks"

Alex J. Best (Mar 20 2024 at 11:43):

It looks like you are trying to use lean 3 syntax (which is the old deprecated version). Are you trying to use lean 3 or lean 4 (recommended)

Alex J. Best (Mar 20 2024 at 11:44):

If you are trying to use lean 4 you should try to follow some materials from https://leanprover-community.github.io/learn.html

Riccardo Brasca (Mar 20 2024 at 11:44):

I think one error is that docs#Nat.minFac_prime proves that Nat.Prime p, while you said you wanted to prove Prime p

Omar Shehab (Mar 20 2024 at 12:19):

import Mathlib.Data.Nat.Prime
import Mathlib.Tactic

theorem infinitude_of_primes (N : ) :  p, p  N  Nat.Prime p :=
let M := Nat.factorial N + 1;
let p := Nat.minFac M;
have h0 : 0 < N := Nat.zero_lt_succ _;
have h1 : M  1 := Nat.ne_of_gt (Nat.succ_lt_succ (Nat.factorial_pos N));
have primeP : Nat.Prime p := Nat.minFac_prime h1;
have h2 : p  M := Nat.minFac_dvd M;
have h3 : N < p :=
  Nat.lt_of_not_ge (λ hge,
    have h4 : p  Nat.factorial N := primeP.dvd_factorial (Nat.le_of_succ_le hge);
    have h5 : p  1 := Nat.dvd_sub' h2 h4;
    Nat.prime.not_dvd_one primeP h5);
p, Nat.le_of_lt h3, primeP

I have edited the code so that it follows the lean4 syntax but I still get an error

Riccardo Brasca (Mar 20 2024 at 13:44):

The first error I see is the fact that you write a function using λ x, x + 3: this is Lean3 style, in Lean 4 we write

fun x  x + 3

Riccardo Brasca (Mar 20 2024 at 13:44):

Also, we don't use ; to finish a line

Riccardo Brasca (Mar 20 2024 at 13:45):

Is there a reason why you are not in tactic mode?


Last updated: May 02 2025 at 03:31 UTC