Skip to content

Conversation

@Freek98
Copy link
Contributor

@Freek98 Freek98 commented Aug 13, 2025

Added proofs showing that the type of natural numbers is isomorphic to it's own sum and product.

  • Showed that if we have a function $f : \mathbb N \to \mathbb N$, which is increasing and starts at 0. We can then partition $\mathbb N$ into the pieces $[f k , f(k+1) )$.
  • Applying this fun fact to the double function, derived that $\mathbb N \cong \mathbb N + \mathbb N$
  • Applying this fun fact to the function ($n \mapsto \frac{n (n+1)}{2} $), derived that $\mathbb N \cong \mathbb N \times \mathbb N$.
  • There are also some small lemmas on the order of natural numbers and increasing functions.

open import Cubical.Tactics.NatSolver
open import Cubical.Data.Nat.Bijections.IncreasingFunction

Triangle⊂ℕ = Σ[ k ∈ ℕ ] Σ[ i ∈ ℕ ] (i ≤ k)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks more like Triangle⊂ℕ×ℕ to me.

@ecavallo
Copy link
Contributor

I changed Triangle⊂ℕ≅ℕ×ℕ to match. Merging now!

@ecavallo ecavallo merged commit ad6f8ee into agda:master Aug 18, 2025
@Freek98 Freek98 deleted the NatBijections branch August 18, 2025 14:52
open import Cubical.Data.Sigma
open import Cubical.Data.Nat.Bijections.Triangle

Triangle⊂ℕ×ℕ≅ℕ×ℕ : Iso Triangle⊂ℕ×ℕ (ℕ × ℕ)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you could use totalEquiv from Cubical.Functions.Fibration here (as n ≤ m is definitionally the same as fiber (_+ n) m)


private
1+k+t=k+t+1 : (n : ℕ) (t : ℕ ) suc (n + t) ≡ n + suc t
1+k+t=k+t+1 n t = solveℕ!
Copy link
Contributor

Choose a reason for hiding this comment

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

The solver here is also overkill, considering that this is exactly the type of +-suc

open import Cubical.Data.Nat.Bijections.IncreasingFunction

double :
double n = n + n
Copy link
Contributor

Choose a reason for hiding this comment

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

This is doubleℕ which is already defined in the library


private
2Sn=2n+2 : {n : ℕ} double (suc n) ≡ double n + 2
2Sn=2n+2 = solveℕ!
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also an instance of +-comm or +-suc, the solver is overkill

sucIncreasing→StrictlyIncreasing {m = m} {n = n} (k , m+k+1=n) =
sucIncreasing→strictlyIncreasing' m n k m+k+1=n where

sucIncreasing→strictlyIncreasing' :
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a lot of unnecessary whitespace between these lines
Also if you swap the positions of n and k here, you can use J>_ to simplify the proof a bit and avoid having to explicitly use subst

@anshwad10
Copy link
Contributor

Well, I had some nitpciks, but seems im too late because its already merged

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.

4 participants