Zulip Chat Archive

Stream: mathlib4

Topic: Inductive definition using minimum of some subset of ℕ


Tony Ma (Dec 28 2024 at 06:18):

I want to define a sequence inductively, each term depending on the last and is defined as the minimum of some subset of ℕ. I found thatsInf seems not so convenient while using. How shall I simplify Nat.find ⋯ = 3 or should I use something other than sInf instead? (ℕ is well-ordered. Could I utilize this fact?)

import Mathlib

noncomputable def A :   
| 0 => 2
| n + 1 => sInf {x | x > A n  Nat.Prime x}
decreasing_by
  apply Nat.lt_succ_self

example : A 1 = 3 := by
  have A0 : A 0 = 2 := by
    simp [A]
  simp [A, sInf]
  have h :  x, x > A 0  Nat.Prime x := by
    use 3
    simp [A0]
    exact Nat.prime_three
  simp [dif_pos h]

  /-
  A0 : A 0 = 2
  h : ∃ x > A 0, Nat.Prime x
  ⊢ Nat.find ⋯ = 3
  -/

Matt Diamond (Dec 28 2024 at 06:26):

you might want to take a look at how docs#Nat.Subtype.ofNat does this using docs#Nat.Subtype.succ

Matt Diamond (Dec 28 2024 at 06:26):

(or just use Nat.Subtype.ofNat itself)

Matt Diamond (Dec 28 2024 at 06:29):

unless I'm misreading you and you're trying to do something more complex than just enumerating an infinite set (which is how I interpreted your example)

Tony Ma (Dec 28 2024 at 07:12):

The precise definition I wanted is

noncomputable def A :   
| 0 => 1
| n + 1 => sInf {x | x > A n   i j k : Finset.Icc 0 n, A i + A j  3 * A k   i j : Finset.Icc 0 n, A i + A j  3 * x   i k :Finset.Icc 0 n, A i + x  3 * A k}

So, the next element depends on the previous.

Tony Ma (Dec 28 2024 at 07:14):

@Matt Diamond I guess inductive definition is required in my case.

Matt Diamond (Dec 28 2024 at 07:24):

Well, there's also docs#Nat.strongRecOn as another option... not sure what the pros or cons here would be

Tony Ma (Dec 28 2024 at 07:24):

Is there a way to simplify, if I still use sInf?

Matt Diamond (Dec 28 2024 at 07:25):

I'm not sure... btw it looks like one of your conditions (∀ i j k : Finset.Icc 0 n, A i + A j ≠ 3 * A k) doesn't mention x... is that a typo?

Tony Ma (Dec 28 2024 at 07:27):

Oh yes. I shall remove that.

Tony Ma (Dec 28 2024 at 07:28):

What is the way to use strongRecOn?

Matt Diamond (Dec 28 2024 at 07:37):

This isn't the best explanation, but:

You pass it two arguments, the first being the input and the second argument is the inductive step, which you define as a function like fun n IH => ...

Within that function, you're able to use IH to access previously defined values. The type of IH is (x : Nat) → x < n → motive x, so if you pass in some x along with a proof that x < n, you get back the value of A x (which is what motive x is).

Tony Ma (Dec 28 2024 at 07:40):

Sorry I think I might be not familiar with how to define something... Could you show me some example that uses strongRecOn in definitino?

Matt Diamond (Dec 28 2024 at 07:45):

honestly I think I'm leading you down the wrong path here... you should probably just stick with the inductive definition you were working with

Tony Ma (Dec 28 2024 at 07:47):

Ok. Nevermind and thx a lot. But maybe I could still use the inductive definition with sInf replaced by something better? Should I prove some lemma before or what could I do to avoid the complicated `Nat.find ... = 3

Violeta Hernández (Dec 28 2024 at 21:43):

What's the issue with using sInf?

Violeta Hernández (Dec 28 2024 at 21:44):

The natural numbers implement docs#ConditionallyCompleteLinearOrderBot which is a very specific typeclass that interfaces well with them

Violeta Hernández (Dec 28 2024 at 21:45):

There's even a few lemmas for well-ordered CCLOBs, such as docs#csInf_mem

Violeta Hernández (Dec 28 2024 at 21:46):

You should only really be using Nat.find if you care about computability. In fact, you can see in docs#Nat.instInfSet that sInf on naturals is defined in terms of Nat.find.


Last updated: May 02 2025 at 03:31 UTC