A \emph{base $10$ over-expansion} of a positive integer $N$ is an expression of the form
\[
N = d_k 10^k + d_{k-1} 10^{k-1} + \cdots + d_0 10^0
\]
with $d_k \neq 0$ and $d_i \in \{0,1,2,\dots,10\}$ for all $i$. For instance, the integer $N = 10$ has two base $10$ over-expansions: $10 = 10 \cdot 10^0$ and the usual base $10$ expansion $10 = 1 \cdot 10^1 + 0 \cdot 10^0$. Which positive integers have a unique base $10$ over-expansion?

the set of positive integers that do not contain the digit 0 in their base 10 representation

Prove that the answer is the integers with no $0$'s in their usual base $10$ expansion.

@Eq (Set Nat) answer
  (@setOf Nat fun (n : Nat) =>
    And (@GT.gt Nat instLTNat n (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))
      (Not
        (@Exists Nat fun (a : Nat) =>
          And
            (@Membership.mem Nat (List Nat) (@List.instMembership Nat)
              (Nat.digits (@OfNat.ofNat Nat (nat_lit 10) (instOfNatNat (nat_lit 10))) n) a)
            (@Eq Nat a (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))

hoverexpansion

overexpansion = fun N d ↦ N = ∑ i : Fin d.length, (d.get i) * 10 ^ i.1 ∧ d.getLastI ≠ 0 ∧ ∀ a ∈ d, a ∈ Finset.range 11

hS

∀ N : ℕ, N ∈ S ↔ N > 0 ∧ ∃! d : List ℕ, overexpansion N d


Suppose that \( f \) is a function on the interval \([1,3]\) such that \(-1 \leq f(x) \leq 1\) for all \( x \) and \( \int_{1}^{3} f(x) \, dx = 0 \). How large can \(\int_{1}^{3} \frac{f(x)}{x} \, dx \) be?

@Eq Real answer
  (Real.log
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@OfNat.ofNat Real (nat_lit 4)
        (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
      (@OfNat.ofNat Real (nat_lit 3)
        (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))))

∀ x : Set.Icc (1 : ℝ) 3, -1 ≤ f x ∧ f x ≤ 1


@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 181) (instOfNatNat (nat_lit 181)))

Odd answer ∧ answer.Prime ∧ ((answer : ℤ) ∣ a 2015)


Compute $\log_2 \left( \prod_{a=1}^{2015}\prod_{b=1}^{2015}(1+e^{2\pi iab/2015}) \right)$. Here $i$ is the imaginary unit (that is, $i^2=-1$).

@Eq Complex answer
  (@OfNat.ofNat Complex (nat_lit 13725)
    (@instOfNatAtLeastTwo Complex (nat_lit 13725)
      (@AddMonoidWithOne.toNatCast Complex (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 13723) (instOfNatNat (nat_lit 13723))))))

Complex.log (∏ a : Fin 2015, ∏ b : Fin 2015, (1 + Complex.exp (2 * Real.pi * Complex.I * (a.1 + 1) * (b.1 + 1) / 2015))) / Complex.log 2 = answer


For each real number $x$, let
\[
f(x) = \sum_{n\in S_x} \frac{1}{2^n},
\]
where $S_x$ is the set of positive integers $n$ for which $\lfloor nx \rfloor$ is even. What is the largest real number $L$ such that $f(x) \geq L$ for all $x \in [0,1)$? (As usual, $\lfloor z \rfloor$ denotes the greatest integer less than or equal to $z$.)

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@OfNat.ofNat Real (nat_lit 4)
      (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
    (@OfNat.ofNat Real (nat_lit 7)
      (@instOfNatAtLeastTwo Real (nat_lit 7) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 5) (instOfNatNat (nat_lit 5)))))))

S = fun (x : ℝ) ↦ {n : ℤ | n > 0 ∧ Even ⌊n * x⌋}

IsGreatest {l : ℝ | ∀ x ∈ Set.Ico 0 1, f x ≥ l} answer


Given a list of the positive integers $1,2,3,4,\dots$, take the first three numbers $1,2,3$ and their sum $6$ and cross all four numbers off the list. Repeat with the three smallest remaining numbers $4,5,7$ and their sum $16$. Continue in this way, crossing off the three smallest remaining numbers and their sum, and consider the sequence of sums produced: $6,16,27,36,\dots$. Prove or disprove that there is some number in the sequence whose base $10$ representation ends with $2015$.

∀ S : Set ℕ, S.encard ≥ 3 → ((Smin3 S) 0 = sInf S ∧ (Smin3 S) 1 = sInf (S \ {(Smin3 S) 0}) ∧ (Smin3 S) 2 = sInf (S \ {(Smin3 S) 0, (Smin3 S) 1}))

hsums

∀ n : ℕ, sums n = (Smin3 (sets n)) 0 + (Smin3 (sets n)) 1 + (Smin3 (sets n)) 2

hsetsn

∀ n : ℕ, sets (n + 1) = sets n \ {(Smin3 (sets n)) 0, (Smin3 (sets n)) 1, (Smin3 (sets n)) 2, sums n}

(∃ n : ℕ, List.IsPrefix [5, 1, 0, 2] (Nat.digits 10 (sums n))) ↔ answer


Let $S$ be the set of all $2 \times 2$ real matrices $M=\begin{pmatrix} a & b \\ c & d \end{pmatrix}$ whose entries $a,b,c,d$ (in that order) form an arithmetic progression. Find all matrices $M$ in $S$ for which there is some integer $k>1$ such that $M^k$ is also in $S$.

the set of all matrices of the form α * I or β * A, where I is the identity matrix and A is a specific matrix

Show that matrices of the form $\alpha A$ or $\beta B$, where $A=\left(\begin{smallmatrix} 1 & 1 \\ 1 & 1 \end{smallmatrix}\right)$, $B=\left(\begin{smallmatrix} -3 & -1 \\ 1 & 3 \end{smallmatrix}\right)$, and $\alpha,\beta \in \mathbb{R}$, are the only matrices in $S$ that satisfy the given condition.

@Eq
  (Set
    (Matrix (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
      (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real))
  answer
  (@setOf
    (Matrix (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
      (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real)
    fun
      (A :
        Matrix (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
          (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real) =>
    Or
      (@Exists Real fun (α : Real) =>
        ∀ (i j : Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))),
          @Eq Real (A i j)
            (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) α
              (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))))
      (@Exists Real fun (β : Real) =>
        And
          (@Eq Real
            (A
              (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 0)
                (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                  (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 0)))
              (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 0)
                (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                  (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 0))))
            (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) β
              (@Neg.neg Real Real.instNeg
                (@OfNat.ofNat Real (nat_lit 3)
                  (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
                    (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))))))
          (And
            (@Eq Real
              (A
                (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 0)
                  (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                    (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 0)))
                (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 1)
                  (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                    (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 1))))
              (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) β
                (@Neg.neg Real Real.instNeg (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))))
            (And
              (@Eq Real
                (A
                  (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 1)
                    (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                      (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 1)))
                  (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 0)
                    (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                      (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 0))))
                (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) β
                  (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))))
              (@Eq Real
                (A
                  (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 1)
                    (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                      (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 1)))
                  (@OfNat.ofNat (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) (nat_lit 1)
                    (@Fin.instOfNat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
                      (@Nat.instNeZeroSucc (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))) (nat_lit 1))))
                (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) β
                  (@OfNat.ofNat Real (nat_lit 3)
                    (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
                      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))))))))

M ∈ S ∧ (∃ k > 1, M ^ k ∈ S) ↔ M ∈ answer


Let $T$ be the set of all triples $(a,b,c)$ of positive integers for which there exist triangles with side lengths $a,b,c$. Express
\[
\sum_{(a,b,c) \in T} \frac{2^a}{3^b 5^c}
\]
as a rational number in lowest terms.

@Eq (Prod Int Nat) answer
  (@Prod.mk Int Nat (@OfNat.ofNat Int (nat_lit 17) (@instOfNat (nat_lit 17)))
    (@OfNat.ofNat Nat (nat_lit 21) (instOfNatNat (nat_lit 21))))

quotientof (∑' t : (Fin 3 → ℤ), if (∀ n : Fin 3, t n > 0) ∧ t 0 < t 1 + t 2 ∧ t 1 < t 2 + t 0 ∧ t 2 < t 0 + t 1
    then 2^(t 0)/(3^(t 1)*5^(t 2)) else 0) = answer


Let $P_n$ be the number of permutations $\pi$ of $\{1,2,\dots,n\}$ such that
\[
|i-j| = 1 \mbox{ implies } |\pi(i) -\pi(j)| \leq 2
\]
for all $i,j$ in $\{1,2,\dots,n\}$. Show that for $n \geq 2$, the quantity
\[
P_{n+5} - P_{n+4} - P_{n+3} + P_n
\]
does not depend on $n$, and find its value.

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4)))

hP

P = fun n ↦ {pi : Finset.Icc 1 n → Finset.Icc 1 n | Bijective pi ∧ ∀ i j : Finset.Icc 1 n, Nat.dist i j = 1 → Nat.dist (pi i) (pi j) ≤ 2}.ncard


For each positive integer $k$, let $A(k)$ be the number of odd divisors of $k$ in the interval $[1,\sqrt{2k})$. Evaluate $\sum_{k=1}^\infty (-1)^{k-1}\frac{A(k)}{k}$.

Show that the sum converges to $\pi^2/16$.

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) Real.pi
      (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
    (@OfNat.ofNat Real (nat_lit 16)
      (@instOfNatAtLeastTwo Real (nat_lit 16) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 14) (instOfNatNat (nat_lit 14)))))))

hA

∀ k > 0, A k = {j : ℕ | Odd j ∧ j ∣ k ∧ j < Real.sqrt (2 * k)}.encard

Tendsto (fun K : ℕ ↦ ∑ k in Finset.Icc 1 K, (-1 : ℝ) ^ ((k : ℝ) - 1) * (A k / (k : ℝ))) atTop (𝓝 answer)


Find the smallest positive integer $j$ such that for every polynomial $p(x)$ with integer coefficients and for every integer $k$, the integer \[ p^{(j)}(k) = \left. \frac{d^j}{dx^j} p(x) \right|_{x=k} \] (the $j$-th derivative of $p(x)$ at $k$) is divisible by 2016.

open Polynomial Filter Topology Real Set Nat

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 8) (instOfNatNat (nat_lit 8)))

IsLeast {j : ℕ | 0 < j ∧ ∀ P : ℤ[X], ∀ k : ℤ, 2016 ∣ (derivative^[j] P).eval k} answer


Given a positive integer $n$, let $M(n)$ be the largest integer $m$ such that
\[
\binom{m}{n-1} > \binom{m-1}{n}.
\]
Evaluate
\[
\lim_{n \to \infty} \frac{M(n)}{n}.
\]

Show that the answer is $\frac{3 + \sqrt{5}}{2}$.

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
      (@OfNat.ofNat Real (nat_lit 3)
        (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
      (Real.sqrt
        (@OfNat.ofNat Real (nat_lit 5)
          (@instOfNatAtLeastTwo Real (nat_lit 5) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3))))))))
    (@OfNat.ofNat Real (nat_lit 2)
      (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))

hM

∀ n > 0, IsGreatest {m | 0 < m ∧ (m - 1).choose n < m.choose (n - 1)} (M n)

Tendsto (fun n ↦ M n / (n : ℝ)) atTop (𝓝 answer)


Suppose that $f$ is a function from $\mathbb{R}$ to $\mathbb{R}$ such that
\[
f(x) + f\left( 1 - \frac{1}{x} \right) = \arctan x
\]
for all real $x \neq 0$. (As usual, $y = \arctan x$ means $-\pi/2 < y < \pi/2$ and $\tan y = x$.) Find
\[
\int_0^1 f(x)\,dx.
\]

Prove that the answer is $\frac{3\pi}{8}$.

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
      (@OfNat.ofNat Real (nat_lit 3)
        (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
      Real.pi)
    (@OfNat.ofNat Real (nat_lit 8)
      (@instOfNatAtLeastTwo Real (nat_lit 8) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 6) (instOfNatNat (nat_lit 6)))))))

hf

∀ x : ℝ, x ≠ 0 → f x + f (1 - 1 / x) = Real.arctan x


Find the smallest constant $C$ such that for every real polynomial $P(x)$ of degree $3$ that has a root in the interval $[0,1]$,
\[
\int_0^1 \left| P(x) \right|\,dx \leq C \max_{x \in [0,1]} \left| P(x) \right|.
\]

Prove that the smallest such value of $C$ is $\frac{5}{6}$.

open Polynomial Filter Topology Real Set Nat List

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@OfNat.ofNat Real (nat_lit 5)
      (@instOfNatAtLeastTwo Real (nat_lit 5) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3))))))
    (@OfNat.ofNat Real (nat_lit 6)
      (@instOfNatAtLeastTwo Real (nat_lit 6) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4)))))))

hp

∀ c, p c ↔
        ∀ P : Polynomial ℝ, P.degree = 3 →
        (∃ x ∈ Icc 0 1, P.eval x = 0) →
        ∫ x in (0)..1, |P.eval x| ≤ c * (sSup {y | ∃ x ∈ Icc 0 1, y = |P.eval x|})


Let $x_0,x_1,x_2,\dots$ be the sequence such that $x_0=1$ and for $n \geq 0$,
\[
x_{n+1} = \ln(e^{x_n} - x_n)
\]
(as usual, the function $\ln$ is the natural logarithm). Show that the infinite series
\[
x_0 + x_1 + x_2 + \cdots
\]
converges and find its sum.

@Eq Real answer
  (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
    (Real.exp (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
    (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))

hxn

∀ n : ℕ, x (n + 1) = log (exp (x n) - (x n))


Define a positive integer $n$ to be \emph{squarish} if either $n$ is itself a perfect square or the distance from $n$ to the nearest perfect square is a perfect square. For example, $2016$ is squarish, because the nearest perfect square to $2016$ is $45^2 = 2025$ and $2025 - 2016 = 9$ is a perfect square. (Of the positive integers between $1$ and $10$, only $6$ and $7$ are not squarish.)

For a positive integer $N$, let $S(N)$ be the number of squarish integers between $1$ and $N$,
inclusive. Find positive constants $\alpha$ and $\beta$ such that
\[
\lim_{N \to \infty} \frac{S(N)}{N^\alpha} = \beta,
\]
or show that no such constants exist.

Prove that the limit exists for $\alpha = \frac{3}{4}$ and equals $\beta = \frac{4}{3}$.

open Classical Polynomial Filter Topology Real Set Nat List

@Eq (Prod Real Real) answer
  (@Prod.mk Real Real
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@OfNat.ofNat Real (nat_lit 3)
        (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
      (@OfNat.ofNat Real (nat_lit 4)
        (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@OfNat.ofNat Real (nat_lit 4)
        (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
      (@OfNat.ofNat Real (nat_lit 3)
        (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))))

hsquarish

∀ n, squarish n ↔ IsSquare n ∨ ∃ w : ℤ, IsSquare |n - w ^ 2| ∧ ∀ v : ℕ, |n - w ^ 2| ≤ |n - v ^ 2|

hS

S = fun n ↦ {i ∈ Finset.Icc 1 n | squarish i}.card

p

ℝ → ℝ → Prop

hp

∀ α β, p α β ↔ α > 0 ∧ β > 0 ∧ Tendsto (fun N ↦ S N / (N : ℝ) ^ α) atTop (𝓝 β)

(∀ α β : ℝ, ((α, β) = answer ↔ p α β)) ∨ ¬∃ α β : ℝ, p α β


Let $A$ be a $2n \times 2n$ matrix, with entries chosen independently at random. Every entry is chosen to be $0$ or $1$, each with probability $1/2$. Find the expected value of $\det(A-A^t)$ (as a function of $n$), where $A^t$ is the transpose of $A$.

Show that the expected value equals $\frac{(2n)!}{4^nn!}$.

@Eq (Nat → Real) answer fun (n_1 : Nat) =>
  @HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@Nat.cast Real Real.instNatCast
      (Nat.factorial
        (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
          n_1)))
    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
      (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
        (@OfNat.ofNat Real (nat_lit 4)
          (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
        n_1)
      (@Nat.cast Real Real.instNatCast (Nat.factorial n_1)))

Set (Matrix (Fin (2 * n)) (Fin (2 * n)) ℝ)

mats01 = {A | ∀ i j : Fin (2 * n), A i j = 0 ∨ A i j = 1}

(∑' A : mats01, (A.1 - (Matrix.transpose A)).det) / mats01.ncard = answer n


Find all functions $f$ from the interval $(1,\infty)$ to $(1,\infty)$ with the following property: if $x,y \in (1,\infty)$ and $x^2 \leq y \leq x^3$, then $(f(x))^2 \leq f(y) \leq (f(x))^3$.

the set of all functions of the form f(x) = x^c for some c > 0

Show that the only such functions are the functions $f(x)=x^c$ for some $c>0$.

@Eq
  (Set
    (@Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))) →
      @Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))))
  answer
  (@setOf
    (@Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))) →
      @Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))))
    fun
      (f_1 :
        @Set.Elem Real
            (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))) →
          @Set.Elem Real
            (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))) =>
    @Exists Real fun (c : Real) =>
      And (@GT.gt Real Real.instLT c (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))
        (∀
          (x :
            @Set.Elem Real
              (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))),
          @Eq Real
            (@Subtype.val Real
              (fun (x_1 : Real) =>
                @Membership.mem Real (Set Real) (@Set.instMembership Real)
                  (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
                  x_1)
              (f_1 x))
            (@HPow.hPow Real Real Real (@instHPow Real Real Real.instPow)
              (@Subtype.val Real
                (fun (x_1 : Real) =>
                  @Membership.mem Real (Set Real) (@Set.instMembership Real)
                    (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
                    x_1)
                x)
              c)))

f ∈ answer ↔
    (∀ x y : Set.Ioi (1 : ℝ), ((x : ℝ) ^ 2 ≤ y ∧ y ≤ (x : ℝ) ^ 3) → ((f x : ℝ) ^ 2 ≤ f y ∧ f y ≤ (f x : ℝ) ^ 3))


@Eq Real answer (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))


Let $S$ be the smallest set of positive integers such that (a) $2$ is in $S$, (b) $n$ is in $S$ whenever $n^2$ is in $S$, and (c) $(n+5)^2$ is in $S$ whenever $n$ is in $S$. Which positive integers are not in $S$?.

Show that all solutions are in the set $\{x \in \mathbb{Z}\, |\, x > 0 \land (x = 1 \lor 5 \mid x)\}

@Eq (Set Int) answer
  (@setOf Int fun (x : Int) =>
    And (@GT.gt Int Int.instLTInt x (@OfNat.ofNat Int (nat_lit 0) (@instOfNat (nat_lit 0))))
      (Or (@Eq Int x (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1))))
        (@Dvd.dvd Int Int.instDvd (@OfNat.ofNat Int (nat_lit 5) (@instOfNat (nat_lit 5))) x)))

∀ S, IsQualifying S ↔
  (∀ n ∈ S, 0 < n) ∧
  2 ∈ S ∧
  (∀ n > 0, n ^ 2 ∈ S → n ∈ S) ∧
  (∀ n ∈ S, (n + 5) ^ 2 ∈ S)


Suppose that a positive integer $N$ can be expressed as the sum of $k$ consecutive positive integers
\[
N = a + (a+1) +(a+2) + \cdots + (a+k-1)
\]
for $k=2017$ but for no other values of $k>1$. Considering all positive integers $N$ with this property, what is the smallest positive integer $a$ that occurs in any of these expressions?

Prove that the smallest value of $a$ is $16$.

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 16) (instOfNatNat (nat_lit 16)))

p

ℤ → ℕ → Prop

hS

S = fun (a : ℤ) k ↦ ∑ i in Finset.range k, (a + i)

hq

∀ N, q N ↔ p N 2017 ∧ ∀ k : ℕ, k > 1 → k ≠ 2017 → ¬p N k


Evaluate the sum \begin{gather*} \sum_{k=0}^\infty \left( 3 \cdot \frac{\ln(4k+2)}{4k+2} - \frac{\ln(4k+3)}{4k+3} - \frac{\ln(4k+4)}{4k+4} - \frac{\ln(4k+5)}{4k+5} \right) \ = 3 \cdot \frac{\ln 2}{2} - \frac{\ln 3}{3} - \frac{\ln 4}{4} - \frac{\ln 5}{5} + 3 \cdot \frac{\ln 6}{6} - \frac{\ln 7}{7} \ - \frac{\ln 8}{8} - \frac{\ln 9}{9} + 3 \cdot \frac{\ln 10}{10} - \cdots . \end{gather*} (As usual, $\ln x$ denotes the natural logarithm of $x$.)

@Eq Real answer
  (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
    (Real.log
      (@OfNat.ofNat Real (nat_lit 2)
        (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))
    (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))


Find the number of ordered $64$-tuples $(x_0,x_1,\dots,x_{63})$ such that $x_0,x_1,\dots,x_{63}$ are distinct elements of $\{1,2,\dots,2017\}$ and
\[
x_0 + x_1 + 2x_2 + 3x_3 + \cdots + 63 x_{63}
\]
is divisible by 2017.

Prove that the answer is $\frac{2016!}{1953!} - 63! \cdot 2016$

@Eq Nat answer
  (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat)
    (@HDiv.hDiv Nat Nat Nat (@instHDiv Nat Nat.instDiv)
      (Nat.factorial (@OfNat.ofNat Nat (nat_lit 2016) (instOfNatNat (nat_lit 2016))))
      (Nat.factorial (@OfNat.ofNat Nat (nat_lit 1953) (instOfNatNat (nat_lit 1953)))))
    (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat)
      (Nat.factorial (@OfNat.ofNat Nat (nat_lit 63) (instOfNatNat (nat_lit 63))))
      (@OfNat.ofNat Nat (nat_lit 2016) (instOfNatNat (nat_lit 2016)))))

S

Finset (Finset.range 64 → Finset.Icc 1 2017)

hs

∀ x, x ∈ S ↔ (Injective x ∧ (2017 ∣ (∑ i : Finset.range 64, if i ≤ (⟨1, by norm_num⟩ : Finset.range 64) then (x i : ℤ) else i * (x i : ℤ))))


Find all ordered pairs $(a,b)$ of positive integers for which $\frac{1}{a} + \frac{1}{b} = \frac{3}{2018}$.

@Eq (Set (Prod Int Int)) answer
  (@Insert.insert (Prod Int Int) (Set (Prod Int Int)) (@Set.instInsert (Prod Int Int))
    (@Prod.mk Int Int (@OfNat.ofNat Int (nat_lit 673) (@instOfNat (nat_lit 673)))
      (@OfNat.ofNat Int (nat_lit 1358114) (@instOfNat (nat_lit 1358114))))
    (@Insert.insert (Prod Int Int) (Set (Prod Int Int)) (@Set.instInsert (Prod Int Int))
      (@Prod.mk Int Int (@OfNat.ofNat Int (nat_lit 674) (@instOfNat (nat_lit 674)))
        (@OfNat.ofNat Int (nat_lit 340033) (@instOfNat (nat_lit 340033))))
      (@Insert.insert (Prod Int Int) (Set (Prod Int Int)) (@Set.instInsert (Prod Int Int))
        (@Prod.mk Int Int (@OfNat.ofNat Int (nat_lit 1009) (@instOfNat (nat_lit 1009)))
          (@OfNat.ofNat Int (nat_lit 2018) (@instOfNat (nat_lit 2018))))
        (@Insert.insert (Prod Int Int) (Set (Prod Int Int)) (@Set.instInsert (Prod Int Int))
          (@Prod.mk Int Int (@OfNat.ofNat Int (nat_lit 2018) (@instOfNat (nat_lit 2018)))
            (@OfNat.ofNat Int (nat_lit 1009) (@instOfNat (nat_lit 1009))))
          (@Insert.insert (Prod Int Int) (Set (Prod Int Int)) (@Set.instInsert (Prod Int Int))
            (@Prod.mk Int Int (@OfNat.ofNat Int (nat_lit 340033) (@instOfNat (nat_lit 340033)))
              (@OfNat.ofNat Int (nat_lit 674) (@instOfNat (nat_lit 674))))
            (@Singleton.singleton (Prod Int Int) (Set (Prod Int Int)) (@Set.instSingletonSet (Prod Int Int))
              (@Prod.mk Int Int (@OfNat.ofNat Int (nat_lit 1358114) (@instOfNat (nat_lit 1358114)))
                (@OfNat.ofNat Int (nat_lit 673) (@instOfNat (nat_lit 673))))))))))


Let \( S_1, S_2, \ldots, S_{2^n-1} \) be the nonempty subsets of \( \{1, 2, \ldots, n\} \) in some order, and let \( M \) be the \( (2^n - 1) \times (2^n - 1) \) matrix whose \((i, j)\) entry is $m_{ij} = \begin{cases} 0 & \text{if } S_i \cap S_j = \emptyset; \\ 1 & \text{otherwise}. \end{cases} $ Calculate the determinant of \( M \).

Show that the solution is 1 if n = 1, and otherwise -1.

@Eq (Nat → Real) answer fun (n_1 : Nat) =>
  @ite Real (@Eq Nat n_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
    (instDecidableEqNat n_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
    (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
    (@Neg.neg Real Real.instNeg (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))

hS

Set.range S = (Set.Icc 1 n).powerset \ {∅}

hM

∀ i j, M i j = if (S i ∩ S j = ∅) = True then 0 else 1


Determine the greatest possible value of $\sum_{i=1}^{10} \cos(3x_i)$ for real numbers $x_1, x_2, \ldots, x_{10}$ satisfying $\sum_{i=1}^{10} \cos(x_i) = 0$.

Show that the solution is $\frac{480}{49}$

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@OfNat.ofNat Real (nat_lit 480)
      (@instOfNatAtLeastTwo Real (nat_lit 480) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 478) (instOfNatNat (nat_lit 478))))))
    (@OfNat.ofNat Real (nat_lit 49)
      (@instOfNatAtLeastTwo Real (nat_lit 49) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 47) (instOfNatNat (nat_lit 47)))))))

IsGreatest
      {∑ i, Real.cos (3 * x i) | (x : Fin 10 → ℝ) (hx : ∑ i, Real.cos (x i) = 0)}
      answer


Let $\mathcal{P}$ be the set of vectors defined by $\mathcal{P}=\left\{\left.\begin{pmatrix} a \\ b \end{pmatrix}\right| 0 \leq a \leq 2, 0 \leq b \leq 100,\text{ and }a,b \in \mathbb{Z}\right\}$. Find all $\mathbf{v} \in \mathcal{P}$ such that the set $\mathcal{P} \setminus \{\mathbf{v}\}$ obtained by omitting vector $\mathbf{v}$ from $\mathcal{P}$ can be partitioned into two sets of equal size and equal sum.

{v : Mathlib.Vector ℤ 2 | ∃ b : ℤ, 0 ≤ b ∧ b ≤ 100 ∧ Even b ∧ v.toList = [1, b]}

Show that the answer is the collection of vectors $\begin{pmatrix} 1 \\ b \end{pmatrix}$ where $0 \leq b \leq 100$ and $b$ is even.

@Eq (Set (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) → Int)) answer
  (@setOf (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) → Int)
    fun (v_1 : Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) → Int) =>
    @Exists Int fun (b : Int) =>
      And (@LE.le Int Int.instLEInt (@OfNat.ofNat Int (nat_lit 0) (@instOfNat (nat_lit 0))) b)
        (And (@LE.le Int Int.instLEInt b (@OfNat.ofNat Int (nat_lit 100) (@instOfNat (nat_lit 100))))
          (And (@Even Int Int.instAdd b)
            (@Eq (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) → Int) v_1
              (@Matrix.vecCons Int (Nat.succ (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))
                (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1)))
                (@Matrix.vecCons Int (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))) b
                  (@Matrix.vecEmpty Int)))))))

(v ∈ P ∧ (∃ Q R : Finset (Fin 2 → ℤ),
    (Q ∪ R = Pvdiff) ∧ (Q ∩ R = ∅) ∧ (Q.card = R.card) ∧
    (∑ q in Q, q 0 = ∑ r in R, r 0) ∧ (∑ q in Q, q 1 = ∑ r in R, r 1)))
  ↔ v ∈ answer


Find all positive integers $n < 10^{100}$ for which simultaneously $n$ divides $2^n$, $n-1$ divides $2^n-1$, and $n-2$ divides $2^n - 2$.

Show that the solution is the set $\{2^2, 2^4, 2^8, 2^16\}$.

@Eq (Set Nat) answer
  (@Insert.insert Nat (Set Nat) (@Set.instInsert Nat)
    (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
      (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
      (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
    (@Insert.insert Nat (Set Nat) (@Set.instInsert Nat)
      (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
        (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
        (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))
      (@Insert.insert Nat (Set Nat) (@Set.instInsert Nat)
        (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
          (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
          (@OfNat.ofNat Nat (nat_lit 16) (instOfNatNat (nat_lit 16))))
        (@Singleton.singleton Nat (Set Nat) (@Set.instSingletonSet Nat)
          (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
            (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
            (@OfNat.ofNat Nat (nat_lit 256) (instOfNatNat (nat_lit 256))))))))


Determine all possible values of the expression
\[
A^3+B^3+C^3-3ABC
\]
where $A, B$, and $C$ are nonnegative integers.

the set of nonnegative integers not congruent to 3 or 6 modulo 9

The answer is all nonnegative integers not congruent to $3$ or $6 \pmod{9}$.

@Eq (Set Int) answer
  (@setOf Int fun (n : Int) =>
    And (@GE.ge Int Int.instLEInt n (@OfNat.ofNat Int (nat_lit 0) (@instOfNat (nat_lit 0))))
      (And
        (Not
          (Int.ModEq (@OfNat.ofNat Int (nat_lit 9) (@instOfNat (nat_lit 9))) n
            (@OfNat.ofNat Int (nat_lit 3) (@instOfNat (nat_lit 3)))))
        (Not
          (Int.ModEq (@OfNat.ofNat Int (nat_lit 9) (@instOfNat (nat_lit 9))) n
            (@OfNat.ofNat Int (nat_lit 6) (@instOfNat (nat_lit 6)))))))

{n : ℤ | ∃ A B C : ℤ, A ≥ 0 ∧ B ≥ 0 ∧ C ≥ 0 ∧ A^3 + B^3 + C^3 - 3*A*B*C = n} = answer


Given real numbers $b_0, b_1, \dots, b_{2019}$ with $b_{2019} \neq 0$, let $z_1,z_2,\dots,z_{2019}$ be
the roots in the complex plane of the polynomial
\[
P(z) = \sum_{k=0}^{2019} b_k z^k.
\]
Let $\mu = (|z_1| + \cdots + |z_{2019}|)/2019$ be the average of the distances from $z_1,z_2,\dots,z_{2019}$ to the origin. Determine the largest constant $M$ such that $\mu \geq M$ for all choices of $b_0,b_1,\dots, b_{2019}$ that satisfy
\[
1 \leq b_0 < b_1 < b_2 < \cdots < b_{2019} \leq 2019.
\]

@Eq Real answer
  (@HPow.hPow Real Real Real (@instHPow Real Real Real.instPow)
    (@OfNat.ofNat Real (nat_lit 2019)
      (@instOfNatAtLeastTwo Real (nat_lit 2019) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2017) (instOfNatNat (nat_lit 2017))))))
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@Neg.neg Real Real.instNeg (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
      (@OfNat.ofNat Real (nat_lit 2019)
        (@instOfNatAtLeastTwo Real (nat_lit 2019) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2017) (instOfNatNat (nat_lit 2017))))))))

hv

v = fun b => b.degree = 2019 ∧ 1 ≤ (b.coeff 0).re ∧ (b.coeff 2019).re ≤ 2019 ∧
  (∀ i : Fin 2020, (b.coeff i).im = 0) ∧ (∀ i : Fin 2019, (b.coeff i).re < (b.coeff (i + 1)).re)

hμ

μ = fun b => (Multiset.map (fun ω : ℂ => ‖ω‖) (Polynomial.roots b)).sum/2019

IsGreatest {M : ℝ | ∀ b, v b → μ b ≥ M} answer


Let $f$ be a continuous real-valued function on $\mathbb{R}^3$. Suppose that for every sphere $S$ of radius $1$, the integral of $f(x,y,z)$ over the surface of $S$ equals $0$. Must $f(x,y,z)$ be identically 0?

open MeasureTheory Metric Topology Filter

∀ f, P f ↔ ∀ C, ∫ x in sphere C 1, f x ∂μH[2] = 0

(∀ f, Continuous f → P f → f = 0) ↔ answer


Let $p$ be an odd prime number, and let $\mathbb{F}_p$ denote the field of integers modulo $p$. Let $\mathbb{F}_p[x]$ be the ring of polynomials over $\mathbb{F}_p$, and let $q(x) \in \mathbb{F}_p[x]$ be given by $q(x)=\sum_{k=1}^{p-1} a_kx^k$, where $a_k=k^{(p-1)/2}\mod{p}$. Find the greatest nonnegative integer $n$ such that $(x-1)^n$ divides $q(x)$ in $\mathbb{F}_p[x]$.

Show that the answer is $\frac{p-1}{2}$.

@Eq (Nat → Nat) answer fun (p_1 : Nat) =>
  @HDiv.hDiv Nat Nat Nat (@instHDiv Nat Nat.instDiv)
    (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) p_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
    (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))


Denote by $\mathbb{Z}^2$ the set of all points $(x,y)$ in the plane with integer coordinates. For each integer $n \geq 0$, let $P_n$ be the subset of $\mathbb{Z}^2$ consisting of the point $(0,0)$ together with all points $(x,y)$ such that $x^2+y^2=2^k$ for some integer $k \leq n$. Determine, as a function of $n$, the number of four-point subsets of $P_n$ whose elements are the vertices of a square.

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat)
    (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) (@OfNat.ofNat Nat (nat_lit 5) (instOfNatNat (nat_lit 5))) n_1)
    (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))

∀ sPn : Finset (Fin 2 → ℤ), sPnsquare sPn ↔ (sPn.card = 4 ∧ ∃ p4 : Fin 4 → (Fin 2 → ℤ), Set.range p4 = sPn ∧ (∃ s > 0, ∀ i : Fin 4, dist (pZtoR (p4 i) : EuclideanSpace ℝ (Fin 2)) (pZtoR (p4 (i + 1))) = s) ∧ (dist (pZtoR (p4 0)) (pZtoR (p4 2)) = dist (pZtoR (p4 1)) (pZtoR (p4 3))))

{sPn : Finset (Fin 2 → ℤ) | (sPn : Set (Fin 2 → ℤ)) ⊆ Pn ∧ sPnsquare sPn}.encard = answer n


For all $n \geq 1$, let
\[
a_n = \sum_{k=1}^{n-1} \frac{\sin \left( \frac{(2k-1)\pi}{2n} \right)}{\cos^2 \left( \frac{(k-1)\pi}{2n} \right) \cos^2 \left( \frac{k\pi}{2n} \right)}.
\]
Determine
\[
\lim_{n \to \infty} \frac{a_n}{n^3}.
\]

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@OfNat.ofNat Real (nat_lit 8)
      (@instOfNatAtLeastTwo Real (nat_lit 8) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 6) (instOfNatNat (nat_lit 6))))))
    (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) Real.pi
      (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3)))))

Tendsto (fun n : ℕ => (a n)/n^3) atTop (𝓝 answer)


Let $\mathcal{F}$ be the set of functions $f(x,y)$ that are twice continuously differentiable for $x \geq 1,y \geq 1$ and that satisfy the following two equations (where subscripts denote partial derivatives):
\begin{gather*}
xf_x+yf_y=xy\ln(xy), \\
x^2f_{xx}+y^2f_{yy}=xy.
\end{gather*}
For each $f \in \mathcal{F}$, let $m(f)=\min_{s \geq 1} (f(s+1,s+1)-f(s+1,s)-f(s,s+1)+f(s,s))$. Determine $m(f)$, and show that it is independent of the choice of $f$.

@Eq Real answer
  (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
      (@OfNat.ofNat Real (nat_lit 2)
        (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))
      (Real.log
        (@OfNat.ofNat Real (nat_lit 2)
          (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))))
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
      (@OfNat.ofNat Real (nat_lit 2)
        (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))))

vec

ℝ → ℝ → (Fin 2 → ℝ)

hvec

∀ x y : ℝ, (vec x y) 0 = x ∧ (vec x y 1) = y

∀ x ≥ 1, ∀ y ≥ 1, x * deriv (fun x' : ℝ => f (vec x' y)) x + y * deriv (fun y' : ℝ => f (vec x y')) y = x * y * Real.log (x * y)

∀ x ≥ 1, ∀ y ≥ 1, x ^ 2 * iteratedDeriv 2 (fun x' : ℝ => f (vec x' y)) x + y ^ 2 * iteratedDeriv 2 (fun y' : ℝ => f (vec x y')) y = x * y

sInf {f (vec (s + 1) (s + 1)) - f (vec (s + 1) s) - f (vec s (s + 1)) + f (vec s s) | s ≥ 1} = answer


Let $F_m$ be the $m$th Fibonacci number, defined by $F_1 = F_2 = 1$ and $F_m = F_{m-1} + F_{m-2}$ for all $m \geq 3$. Let $p(x)$ be the polynomial of degree $1008$ such that $p(2n + 1) = F_{2n+1}$ for $n = 0,1,2,\ldots,1008$. Find integers $j$ and $k$ such that $p(2019) = F_j - F_k$.

Show that the solution takes the form of $(j, k) = (2019, 1010)$.

@Eq (Prod Nat Nat) answer
  (@Prod.mk Nat Nat (@OfNat.ofNat Nat (nat_lit 2019) (instOfNatNat (nat_lit 2019)))
    (@OfNat.ofNat Nat (nat_lit 1010) (instOfNatNat (nat_lit 1010))))

∀ j k : ℕ, (P.eval 2019 = F j - F k) ↔ ⟨j, k⟩ = answer


Let \( \mathbb{Z}^n \) be the integer lattice in \( \mathbb{R}^n \). Two points in \( \mathbb{Z}^n \) are called neighbors if they differ by exactly 1 in one coordinate and are equal in all other coordinates. For which integers \( n \geq 1 \) does there exist a set of points \( S \subset \mathbb{Z}^n \) satisfying the following two conditions? \begin{enumerate} \item If \( p \) is in \( S \), then none of the neighbors of \( p \) is in \( S \). \item If \( p \in \mathbb{Z}^n \) is not in \( S \), then exactly one of the neighbors of \( p \) is in \( S \). \end{enumerate}

Show that the statement is true for every \(n \geq 1\)

@Eq (Set Nat) answer (@Set.Ici Nat Nat.instPreorder (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))

∀ p q, neighbors p q ↔ (∃ i : Fin n, abs (p i - q i) = 1 ∧ ∀ j ≠ i, p j = q j)

(1 ≤ n ∧ ∃ S : Set (Fin n → ℤ),
    (∀ p ∈ S, ∀ q, neighbors p q → q ∉ S) ∧ (∀ p ∉ S, {q ∈ S | neighbors p q}.encard = 1)) ↔ n ∈ answer


Find the number of positive integers $N$ satisfying: (i) $N$ is divisible by $2020$, (ii) $N$ has at most $2020$ decimal digits, (iii) The decimal digits of $N$ are a string of consecutive ones followed by a string of consecutive zeros.

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 508536) (instOfNatNat (nat_lit 508536)))

∃ k l, k ≥ l ∧ N = ∑ i in Finset.range (k - l + 1), 10 ^ (i + l)

Set.ncard {x : ℕ | (2020 ∣ x) ∧ (Nat.log 10 x) + 1 ≤ 2020 ∧ (∃ k l, k ≥ l ∧ x = ∑ i in Finset.range (k - l + 1), 10 ^ (i + l))} = answer


Let $k$ be a nonnegative integer. Evaluate
\[
\sum_{j=0}^k 2^{k-j} \binom{k+j}{j}.
\]

@Eq (Nat → Nat) answer fun (k_1 : Nat) =>
  @HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
    (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))) k_1

(∑ j in Finset.Icc 0 k, 2 ^ (k - j) * Nat.choose (k + j) j) = answer k


Let $a_0 = \pi/2$, and let $a_n = \sin(a_{n-1})$ for $n \geq 1$. Determine whether
\[
\sum_{n=1}^\infty a_n^2
\]
converges.

(∃ L, Tendsto (fun m : ℕ => ∑ n in Finset.Icc 1 m, (a n)^2) atTop (𝓝 L)) ↔ answer


Let $a_n$ be the number of sets $S$ of positive integers for which
\[
\sum_{k \in S} F_k = n,
\]
where the Fibonacci sequence $(F_k)_{k \geq 1}$ satisfies $F_{k+2} = F_{k+1} + F_k$ and begins $F_1 = 1, F_2 = 1, F_3 = 2, F_4 = 3$. Find the largest integer $n$ such that $a_n = 2020$.

@Eq Int answer
  (@HSub.hSub Int Int Int (@instHSub Int Int.instSub)
    (@Nat.cast Int instNatCastInt (Nat.fib (@OfNat.ofNat Nat (nat_lit 4040) (instOfNatNat (nat_lit 4040)))))
    (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1))))

ha

a = fun n : ℤ => {S : Finset ℕ | (∀ k ∈ S, k > 0) ∧ ∑ k : S, Nat.fib k = n}.ncard


For a positive integer $N$, let $f_N$ be the function defined by
\[
f_N(x) = \sum_{n=0}^N \frac{N+1/2-n}{(N+1)(2n+1)} \sin((2n+1)x).
\]
Determine the smallest constant $M$ such that $f_N(x) \leq M$ for all $N$ and all real $x$.

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid)) Real.pi
    (@OfNat.ofNat Real (nat_lit 4)
      (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))

answer = sSup {y | ∃ᵉ (N > 0) (x : ℝ), y = f N x}


For a positive integer $n$, define $d(n)$ to be the sum of the digits of $n$ when written in binary (for example, $d(13) = 1+1+0+1=3)$. Let
\[
S = \sum_{k=1}^{2020} (-1)^{d(k)} k^3.
\]
Determine $S$ modulo 2020.

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 1990) (instOfNatNat (nat_lit 1990)))

hd

d = fun n : ℕ => ∑ i : Fin (Nat.digits 2 n).length, (Nat.digits 2 n)[i]!


Let $n$ be a positive integer, and let $V_n$ be the set of integer $(2n+1)$-tuples $\mathbf{v} = (s_0, s_1, \cdots, s_{2n-1}, s_{2n})$ for which $s_0 = s_{2n} = 0$ and $|s_j - s_{j-1}| = 1$ for $j=1,2,\cdots,2n$. Define \[ q(\mathbf{v}) = 1 + \sum_{j=1}^{2n-1} 3^{s_j}, \] and let $M(n)$ be the average of $\frac{1}{q(\mathbf{v})}$ over all $\mathbf{v} \in V_n$. Evaluate $M(2020)$.

Show that the answer is $\frac{1}{4040}$.

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
    (@OfNat.ofNat Real (nat_lit 4040)
      (@instOfNatAtLeastTwo Real (nat_lit 4040) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 4038) (instOfNatNat (nat_lit 4038)))))))

V

ℕ → Set (ℕ → ℤ)

q

ℕ → (ℕ → ℤ) → ℝ

hq

q = fun n s ↦ 1 + ∑ j in Finset.Icc 1 (2 * n - 1), 3 ^ (s j)

hM

M = fun n ↦ (∑' v : V n, 1 / (q n v)) / (V n).ncard


A grasshopper starts at the origin in the coordinate plane and makes a sequence of hops.
Each hop has length $5$, and after each hop the grasshopper is at a point whose coordinates are both integers; thus, there are $12$ possible locations for the grasshopper after the first hop.
What is the smallest number of hops needed for the grasshopper to reach the point $(2021, 2021)$?

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 578) (instOfNatNat (nat_lit 578)))

IsLeast
      {k | ∃ l, P ((0, 0) :: l) ∧ l.getLast! = (2021, 2021) ∧ l.length = k}
      answer


For every positive real number $x$, let $g(x)=\lim_{r \to 0}((x+1)^{r+1}-x^{r+1})^\frac{1}{r}$. Find $\lim_{x \to \infty}\frac{g(x)}{x}$.

@Eq Real answer (Real.exp (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))

Tendsto (fun x : ℝ => g x / x) atTop (𝓝 answer)


Determine all positive integers $N$ for which the sphere $x^2+y^2+z^2=N$ has an inscribed regular tetrahedron whose vertices have integer coordinates.

Show that the integers $N$ with this property are those of the form $3m^2$ for some positive integer $m$.

@Eq (Set Nat) answer
  (@setOf Nat fun (x : Nat) =>
    @Exists Nat fun (m : Nat) =>
      And (@GT.gt Nat instLTNat m (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))
        (@Eq Nat
          (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3)))
            (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid)) m
              (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))
          x))

∀ p, intcoords p ↔ ∀ i : Fin 3, p i = round (p i)

(0 < N ∧ ∃ A B C D : EuclideanSpace ℝ (Fin 3),
    A ∈ Nsphere ∧ B ∈ Nsphere ∧ C ∈ Nsphere ∧ D ∈ Nsphere ∧
    intcoords A ∧ intcoords B ∧ intcoords C ∧ intcoords D ∧
    (∃ s > 0, dist A B = s ∧ dist A C = s ∧ dist A D = s ∧ dist B C = s ∧ dist B D = s ∧ dist C D = s))
  ↔ N ∈ answer


Let
\[
I(R) = \iint_{x^2+y^2 \leq R^2} \left( \frac{1+2x^2}{1+x^4+6x^2y^2+y^4} - \frac{1+y^2}{2+x^4+y^4} \right)\,dx\,dy.
\]
Find
\[
\lim_{R \to \infty} I(R),
\]
or show that this limit does not exist.

The limit exists and equals $\frac{\sqrt{2}}{2} \pi \log 2$.

@Eq Real answer
  (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
      (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
        (Real.sqrt
          (@OfNat.ofNat Real (nat_lit 2)
            (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
              (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))
        (@OfNat.ofNat Real (nat_lit 2)
          (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))
      Real.pi)
    (Real.log
      (@OfNat.ofNat Real (nat_lit 2)
        (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))))

hS

S = fun R => ball (0 : EuclideanSpace ℝ (Fin 2)) R


Let $A$ be the set of all integers $n$ such that $1 \leq n \leq 2021$ and $\gcd(n,2021)=1$. For every nonnegative integer $j$, let $S(j)=\sum_{n \in A}n^j$. Determine all values of $j$ such that $S(j)$ is a multiple of $2021$.

the set of all j such that neither 42 nor 46 divides j

Show that the values of $j$ in question are those not divisible by either $42$ or $46$.

@Eq (Set Nat) answer
  (@setOf Nat fun (j_1 : Nat) =>
    And (Not (@Dvd.dvd Nat Nat.instDvd (@OfNat.ofNat Nat (nat_lit 42) (instOfNatNat (nat_lit 42))) j_1))
      (Not (@Dvd.dvd Nat Nat.instDvd (@OfNat.ofNat Nat (nat_lit 46) (instOfNatNat (nat_lit 46))) j_1)))


Let $P(x)$ be a polynomial whose coefficients are all either $0$ or $1$. Suppose that $P(x)$ can be written as a product of two nonconstant polynomials with integer coefficients. Does it follow that $P(2)$ is a composite integer?

Show that it does follow that $P(2)$ is a composite integer.

(∀ P, (∀ n : ℕ, P.coeff n = 0 ∨ P.coeff n = 1) →
    (∃ Q R : Polynomial ℤ, Q.degree > 0 ∧ R.degree > 0 ∧ P = Q * R) →
    (P.eval 2 ≠ 0 ∧ P.eval 2 ≠ 1 ∧ ¬Prime (P.eval 2)))
  ↔ answer


Determine the maximum value of the sum $S = \sum_{n=1}^\infty \frac{n}{2^n}(a_1a_2 \dots a_n)^{1/n}$ over all sequences $a_1,a_2,a_3,\dots$ of nonnegative real numbers satisfying $\sum_{k=1}^\infty a_k=1$.

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@OfNat.ofNat Real (nat_lit 2)
      (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))
    (@OfNat.ofNat Real (nat_lit 3)
      (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))))

IsGreatest
      {S | ∃ a : ℕ+ → ℝ, (∑' k, a k = 1) ∧ (∀ k, 0 ≤ a k) ∧
        S = ∑' n : ℕ+, n / 2 ^ (n : ℕ) * (∏ k in Finset.Icc 1 n, a k) ^ (1 / n : ℝ)}
      answer


Let $h(x,y)$ be a real-valued function that is twice continuously differentiable throughout $\mathbb{R}^2$, and define $\rho(x,y)=yh_x-xh_y$. Prove or disprove: For any positive constants $d$ and $r$ with $d>r$, there is a circle $\mathcal{S}$ of radius $r$ whose center is a distance $d$ away from the origin such that the integral of $\rho$ over the interior of $\mathcal{S}$ is zero.

rho

((EuclideanSpace ℝ (Fin 2)) → ℝ) → (EuclideanSpace ℝ (Fin 2)) → ℝ

∀ (h : (EuclideanSpace ℝ (Fin 2)) → ℝ) (p : EuclideanSpace ℝ (Fin 2)),
    rho h p = (p 1) *
      deriv (fun x' : ℝ => h ((WithLp.equiv 2 (EuclideanSpace ℝ (Fin 2))).symm ![x', p 1])) (p 0)
      - (p 0) * deriv (fun y' : ℝ => h ((WithLp.equiv 2 (EuclideanSpace ℝ (Fin 2))).symm ![p 0, y'])) (p 1)

(∀ h : (EuclideanSpace ℝ (Fin 2)) → ℝ, ContDiff ℝ 2 h →
    (∀ d > 0, ∀ r > 0, d > r → (∃ c : EuclideanSpace ℝ (Fin 2), dist c 0 = d ∧ (∫ p in (ball c r), rho h p) = 0))) ↔ answer


Determine all ordered pairs of real numbers $(a,b)$ such that the line $y = ax+b$ intersects the curve $y = \ln(1+x^2)$ in exactly one point.

Show that the solution is the set of ordered pairs $(a,b)$ which satisfy at least one of (1) $a = b = 0$, (2) $|a| \geq 1$, and (3) $0 < |a| < 1$ and $b < \log(1 + r_{-}^2) - ar_{-}$ or $b > \log(1 + r_{+}^2) - ar_{+}$ where $r_{\pm} = \frac{1 \pm \sqrt{1 - a^2}}{a}$.

@Eq (Set (Prod Real Real)) answer
  (@setOf (Prod Real Real) fun (x : Prod Real Real) =>
    _example.match_1 (fun (x_1 : Prod Real Real) => Prop) x fun (a b : Real) =>
      Or
        (And (@Eq Real a (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))
          (@Eq Real b (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))))
        (Or
          (@LE.le Real Real.instLE (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
            (@abs Real Real.lattice Real.instAddGroup a))
          (And
            (@LT.lt Real Real.instLT (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))
              (@abs Real Real.lattice Real.instAddGroup a))
            (And
              (@LT.lt Real Real.instLT (@abs Real Real.lattice Real.instAddGroup a)
                (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
              (Or
                (@LT.lt Real Real.instLT b
                  (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                    (Real.log
                      (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
                        (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                        (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
                          (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
                            (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                              (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                              (Real.sqrt
                                (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                                  (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                                  (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
                                    a (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))
                            a)
                          (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
                    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) a
                      (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
                        (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                          (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                          (Real.sqrt
                            (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                              (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                              (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) a
                                (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))
                        a))))
                (@GT.gt Real Real.instLT b
                  (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                    (Real.log
                      (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
                        (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                        (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
                          (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
                            (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
                              (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                              (Real.sqrt
                                (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                                  (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                                  (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
                                    a (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))
                            a)
                          (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
                    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) a
                      (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
                        (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
                          (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                          (Real.sqrt
                            (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                              (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                              (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) a
                                (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))
                        a)))))))))

{a : (ℝ × ℝ) | ∃! x : ℝ, a.1 * x + a.2 = Real.log (1 + x^2)} = answer


Let $n$ be an integer with $n \geq 2$. Over all real polynomials $p(x)$ of degree $n$, what is the largest possible number of negative coefficients of $p(x)^2$?

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat)
    (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) n_1)
    (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))

hnegs

∀ P : ℝ[X], negs P = ∑ i in Finset.range (P.natDegree + 1), if P.coeff i < 0 then 1 else 0


Alice and Bob play a game on a board consisting of one row of 2022 consecutive squares. They take turns placing tiles that cover two adjacent squares, with Alice going first. By rule, a tile must not cover a square that is already covered by another tile. The game ends when no tile can be placed according to this rule. Alice's goal is to maximize the number of uncovered squares when the game ends; Bob's goal is to minimize it. What is the greatest number of uncovered squares that Alice can ensure at the end of the game, no matter how Bob plays?

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 290) (instOfNatNat (nat_lit 290)))

∀ x y, IsValidMove x y ↔
      (x = y ∧ ∀ i < 2021, i ∉ x → i + 1 ∈ x) ∨
      ∃ i < 2021, i ∉ x ∧ i + 1 ∉ x ∧ y = x ∪ {i, i + 1}

∀ g, IsValidGame g ↔ (∃ gt, g = ∅ :: gt) ∧ g.Chain' IsValidMove

ConformsToStrategy

List (Set (Fin 2022)) → (Set (Fin 2022) → Set (Fin 2022)) → Prop

∀ g s, ConformsToStrategy g s ↔
      ∀ (i) (h : i + 1 < g.length), Even i → g[i + 1] = s g[i]

IsGreatest
      {n | ∃ s, (∀ x, IsValidMove x (s x)) ∧ ∀ g,
        IsValidGame g → ConformsToStrategy g s → ∃ gh x, g = gh ++ [x] ∧ n ≤ xᶜ.ncard}
      answer


Let $n$ be a positive integer. Determine, in terms of $n$, the largest integer $m$ with the following property: There exist real numbers $x_1,\dots,x_{2n}$ with $-1<x_1<x_2<\cdots<x_{2n}<1$ such that the sum of the lengths of the $n$ intervals $[x_1^{2k-1},x_2^{2k-1}],[x_3^{2k-1},x_4^{2k-1}],\dots,[x_{2n-1}^{2k-1},x_{2n}^{2k-1}]$ is equal to $1$ for all integers $k$ with $1 \leq k \leq m$.

@Eq (Nat → Nat) answer fun (n_1 : Nat) => n_1

IsGreatest
      {m : ℕ | ∃ x : ℕ → ℝ,
        StrictMono x ∧ -1 < x 1 ∧ x (2 * n) < 1 ∧
        ∀ k ∈ Icc 1 m, ∑ i in Icc 1 n, ((x (2 * i) : ℝ) ^ (2 * k - 1) - (x (2 * i - 1)) ^ (2 * k - 1)) = 1}
    (answer n)


Let $\times$ represent the cross product in $\mathbb{R}^3$. For what positive integers $n$ does there exist a set $S \subset \mathbb{R}^3$ with exactly $n$ elements such that $S=\{v \times w:v,w \in S\}$?

Show that the possible values of $n$ are $1$ and $7$.

@Eq (Set Nat) answer
  (@Insert.insert Nat (Set Nat) (@Set.instInsert Nat) (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))
    (@Singleton.singleton Nat (Set Nat) (@Set.instSingletonSet Nat)
      (@OfNat.ofNat Nat (nat_lit 7) (instOfNatNat (nat_lit 7)))))

∀ S : Finset (Fin 3 → ℝ), P S ↔ (S = {u : Fin 3 → ℝ | ∃ v w : S, u = crossProduct v w})

(0 < n ∧ ∃ S : Finset (Fin 3 → ℝ), S.card = n ∧ P S) ↔ n ∈ answer


Assign to each positive real number a color, either red or blue. Let $D$ be the set of all distances $d>0$ such that there are two points of the same color at distance $d$ apart. Recolor the positive reals so that the numbers in $D$ are red and the numbers not in $D$ are blue. If we iterate this recoloring process, will we always end up with all the numbers red after a finite number of steps?

hrecolor

∀ isred d, recolor isred d ↔ ∃ p q : ℝ, p > 0 ∧ q > 0 ∧ p < q ∧ isred p = isred q ∧ q - p = d

(∀ isred, (∃ k, ∀ p > 0, (recolor^[k] isred) p)) ↔ answer


Find all integers $n$ with $n \geq 4$ for which there exists a sequence of distinct real numbers $x_1,\dots,x_n$ such that each of the sets $\{x_1,x_2,x_3\},\{x_2,x_3,x_4\},\dots,\{x_{n-2},x_{n-1},x_n\},\{x_{n-1},x_n,x_1\}$, and $\{x_n,x_1,x_2\}$ forms a $3$-term arithmetic progression when arranged in increasing order.

Show that the values of $n$ in question are the multiples of $3$ starting with $9$.

@Eq (Set Nat) answer
  (@setOf Nat fun (n_1 : Nat) =>
    And (@Dvd.dvd Nat Nat.instDvd (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3))) n_1)
      (@GE.ge Nat instLENat n_1 (@OfNat.ofNat Nat (nat_lit 9) (instOfNatNat (nat_lit 9)))))

ℝ → ℝ → ℝ → Prop


For $0 \leq p \leq 1/2$, let $X_1,X_2,\dots$ be independent random variables such that
$X_i=\begin{cases}
1 & \text{with probability $p$,} \\
-1 & \text{with probability $p$,} \\
0 & \text{with probability $1-2p$,}
\end{cases}$
for all $i \geq 1$. Given a positive integer $n$ and integers $b,a_1,\dots,a_n$, let $P(b,a_1,\dots,a_n)$ denote the probability that $a_1X_1+\dots+a_nX_n=b$. For which values of $p$ is it the case that $P(0,a_1,\dots,a_n) \geq P(b,a_1,\dots,a_n)$ for all positive integers $n$ and all integers $b,a_1,\dots,a_n$?

@Eq (Set Real) answer
  (@Set.Icc Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
      (@OfNat.ofNat Real (nat_lit 4)
        (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))))

hXset

∀ n > 0, Xset n = {X : Fin n → ℤ | ∀ i : Fin n, X i = 1 ∨ X i = -1 ∨ X i = 0}

hXprob

∀ n > 0, ∀ X : Fin n → ℤ, Xprob n X = ∏ i : Fin n, if (X i = 1 ∨ X i = -1) then p else (1 - 2 * p)

hP

∀ n > 0, ∀ (b : ℤ) (a : Fin n → ℤ), P n b a = ∑' X : {X' ∈ Xset n | (∑ i : Fin n, a i * X' i) = b}, Xprob n X

(0 ≤ p ∧ p ≤ 1 / 2 ∧ (∀ n > 0, ∀ (b : ℤ) (a : Fin n → ℤ), P n 0 a ≥ P n b a)) ↔ p ∈ answer


Find all continuous functions $f:\mathbb{R}^+ \to \mathbb{R}^+$ such that $f(xf(y))+f(yf(x))=1+f(x+y)$ for all $x,y>0$.

the set of functions of the form f(x) = 1 / (1 + c * x) where c ≥ 0

Show that the only such functions are the functions $f(x)=\frac{1}{1+cx}$ for some $c \geq 0$.

@Eq
  (Set
    (@Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))) →
      @Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))))
  answer
  (@setOf
    (@Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))) →
      @Set.Elem Real
        (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))))
    fun
      (f_1 :
        @Set.Elem Real
            (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))) →
          @Set.Elem Real
            (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))) =>
    @Exists Real fun (c : Real) =>
      And (@GE.ge Real Real.instLE c (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))
        (∀
          (x :
            @Set.Elem Real
              (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))),
          @Eq Real
            (@Subtype.val Real
              (fun (x_1 : Real) =>
                @Membership.mem Real (Set Real) (@Set.instMembership Real)
                  (@Set.Ioi Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))
                  x_1)
              (f_1 x))
            (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
              (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
              (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
                (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
                (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) c
                  (@Subtype.val Real
                    (fun (x_1 : Real) =>
                      @Membership.mem Real (Set Real) (@Set.instMembership Real)
                        (@Set.Ioi Real Real.instPreorder
                          (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))
                        x_1)
                    x))))))

(∃ fr : ℝ → ℝ, (∀ x : Set.Ioi (0 : ℝ), fr x = f x) ∧ (∀ x y : Set.Ioi (0 : ℝ), fr (x * fr y) + fr (y * fr x) = 1 + fr (x + y))) ↔ f ∈ answer


For a positive integer $n$, let $f_n(x) = \cos(x) \cos(2x) \cos(3x) \cdots \cos(nx)$. Find the smallest $n$ such that $|f_n''(0)| > 2023$.

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 18) (instOfNatNat (nat_lit 18)))

hf

∀ n > 0, f n = fun x : ℝ => ∏ i in Finset.Icc 1 n, Real.cos (i * x)

IsLeast {n | 0 < n ∧ |iteratedDeriv 2 (f n) 0| > 2023} answer


Let $n$ be an even positive integer. Let $p$ be a monic, real polynomial of degree $2n$; that is to say, $p(x) = x^{2n} + a_{2n-1} x^{2n-1} + \cdots + a_1 x + a_0$ for some real coefficients $a_0, \dots, a_{2n-1}$. Suppose that $p(1/k) = k^2$ for all integers $k$ such that $1 \leq |k| \leq n$. Find all other real numbers $x$ for which $p(1/x) = x^2$.

Show that the other real numbers satisfying $p(1/x) = x^2$ are $\pm \frac{1}{n!}.$

@Eq (Nat → Set Real) answer fun (n_1 : Nat) =>
  @Insert.insert Real (Set Real) (@Set.instInsert Real)
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
      (@Nat.cast Real Real.instNatCast (Nat.factorial n_1)))
    (@Singleton.singleton Real (Set Real) (@Set.instSingletonSet Real)
      (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
        (@Neg.neg Real Real.instNeg (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
        (@Nat.cast Real Real.instNatCast (Nat.factorial n_1))))

hS

S = {x : ℝ | ∃ k : ℤ, x = k ∧ 1 ≤ |k| ∧ |k| ≤ n}

{x : ℝ | p.eval (1/x) = x^2} \ S = answer n


Determine the smallest positive real number $r$ such that there exist differentiable functions $f\colon \mathbb{R} \to \mathbb{R}$ and $g\colon \mathbb{R} \to \mathbb{R}$ satisfying
\begin{enumerate}
 \item[(a)] $f(0) > 0$,
 \item[(b)] $g(0) = 0$,
 \item[(c)] $|f'(x)| \leq |g(x)|$ for all $x$,
 \item[(d)] $|g'(x)| \leq |f(x)|$ for all $x$, and
 \item[(e)] $f(r) = 0$. \end{enumerate}

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid)) Real.pi
    (@OfNat.ofNat Real (nat_lit 2)
      (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))

answer = sInf {r > 0 | ∃ f g : ℝ → ℝ,
    Differentiable ℝ f ∧ Differentiable ℝ g ∧
    (∀ x : ℝ, |deriv f x| ≤ |g x| ∧ |deriv g x| ≤ |f x|) ∧
    f 0 > 0 ∧ g 0 = 0 ∧ f r = 0}


For a nonnegative integer $k$, let $f(k)$ be the number of ones in the base 3 representation of $k$. Find all complex numbers $z$ such that \[ \sum_{k=0}^{3^{1010}-1} (-2)^{f(k)} (z+k)^{2023} = 0. \]

Show that the solution is the set of complex numbers $\{- \frac{3^{1010} - 1}{2}, - \frac{3^{1010} - 1}{2} \pm \frac{\sqrt{9^{1010} - 1}}{4}i \}$

@Eq (Set Complex) answer
  (@Insert.insert Complex (Set Complex) (@Set.instInsert Complex)
    (@HDiv.hDiv Complex Complex Complex (@instHDiv Complex (@DivInvMonoid.toDiv Complex Complex.instDivInvMonoid))
      (@Neg.neg Complex Complex.instNeg
        (@HSub.hSub Complex Complex Complex (@instHSub Complex Complex.instSub)
          (@HPow.hPow Complex Nat Complex
            (@instHPow Complex Nat
              (@Monoid.toNatPow Complex
                (@MonoidWithZero.toMonoid Complex (@Semiring.toMonoidWithZero Complex Complex.instSemiring))))
            (@OfNat.ofNat Complex (nat_lit 3)
              (@instOfNatAtLeastTwo Complex (nat_lit 3)
                (@AddMonoidWithOne.toNatCast Complex
                  (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
                (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
            (@OfNat.ofNat Nat (nat_lit 1010) (instOfNatNat (nat_lit 1010))))
          (@OfNat.ofNat Complex (nat_lit 1) (@One.toOfNat1 Complex Complex.instOne))))
      (@OfNat.ofNat Complex (nat_lit 2)
        (@instOfNatAtLeastTwo Complex (nat_lit 2)
          (@AddMonoidWithOne.toNatCast Complex (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))
    (@Insert.insert Complex (Set Complex) (@Set.instInsert Complex)
      (@HAdd.hAdd Complex Complex Complex (@instHAdd Complex Complex.instAdd)
        (@HDiv.hDiv Complex Complex Complex (@instHDiv Complex (@DivInvMonoid.toDiv Complex Complex.instDivInvMonoid))
          (@Neg.neg Complex Complex.instNeg
            (@HSub.hSub Complex Complex Complex (@instHSub Complex Complex.instSub)
              (@HPow.hPow Complex Nat Complex
                (@instHPow Complex Nat
                  (@Monoid.toNatPow Complex
                    (@MonoidWithZero.toMonoid Complex (@Semiring.toMonoidWithZero Complex Complex.instSemiring))))
                (@OfNat.ofNat Complex (nat_lit 3)
                  (@instOfNatAtLeastTwo Complex (nat_lit 3)
                    (@AddMonoidWithOne.toNatCast Complex
                      (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
                    (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
                (@OfNat.ofNat Nat (nat_lit 1010) (instOfNatNat (nat_lit 1010))))
              (@OfNat.ofNat Complex (nat_lit 1) (@One.toOfNat1 Complex Complex.instOne))))
          (@OfNat.ofNat Complex (nat_lit 2)
            (@instOfNatAtLeastTwo Complex (nat_lit 2)
              (@AddMonoidWithOne.toNatCast Complex
                (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
              (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))
        (@HDiv.hDiv Complex Complex Complex (@instHDiv Complex (@DivInvMonoid.toDiv Complex Complex.instDivInvMonoid))
          (@HMul.hMul Complex Complex Complex (@instHMul Complex Complex.instMul)
            (↑(Real.sqrt
                (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                  (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
                    (@OfNat.ofNat Real (nat_lit 9)
                      (@instOfNatAtLeastTwo Real (nat_lit 9) Real.instNatCast
                        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 7) (instOfNatNat (nat_lit 7))))))
                    (@OfNat.ofNat Nat (nat_lit 1010) (instOfNatNat (nat_lit 1010))))
                  (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))))
            Complex.I)
          (@OfNat.ofNat Complex (nat_lit 4)
            (@instOfNatAtLeastTwo Complex (nat_lit 4)
              (@AddMonoidWithOne.toNatCast Complex
                (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
              (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))))
      (@Singleton.singleton Complex (Set Complex) (@Set.instSingletonSet Complex)
        (@HSub.hSub Complex Complex Complex (@instHSub Complex Complex.instSub)
          (@HDiv.hDiv Complex Complex Complex (@instHDiv Complex (@DivInvMonoid.toDiv Complex Complex.instDivInvMonoid))
            (@Neg.neg Complex Complex.instNeg
              (@HSub.hSub Complex Complex Complex (@instHSub Complex Complex.instSub)
                (@HPow.hPow Complex Nat Complex
                  (@instHPow Complex Nat
                    (@Monoid.toNatPow Complex
                      (@MonoidWithZero.toMonoid Complex (@Semiring.toMonoidWithZero Complex Complex.instSemiring))))
                  (@OfNat.ofNat Complex (nat_lit 3)
                    (@instOfNatAtLeastTwo Complex (nat_lit 3)
                      (@AddMonoidWithOne.toNatCast Complex
                        (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
                      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
                  (@OfNat.ofNat Nat (nat_lit 1010) (instOfNatNat (nat_lit 1010))))
                (@OfNat.ofNat Complex (nat_lit 1) (@One.toOfNat1 Complex Complex.instOne))))
            (@OfNat.ofNat Complex (nat_lit 2)
              (@instOfNatAtLeastTwo Complex (nat_lit 2)
                (@AddMonoidWithOne.toNatCast Complex
                  (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
                (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))
          (@HDiv.hDiv Complex Complex Complex (@instHDiv Complex (@DivInvMonoid.toDiv Complex Complex.instDivInvMonoid))
            (@HMul.hMul Complex Complex Complex (@instHMul Complex Complex.instMul)
              (↑(Real.sqrt
                  (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                    (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
                      (@OfNat.ofNat Real (nat_lit 9)
                        (@instOfNatAtLeastTwo Real (nat_lit 9) Real.instNatCast
                          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 7) (instOfNatNat (nat_lit 7))))))
                      (@OfNat.ofNat Nat (nat_lit 1010) (instOfNatNat (nat_lit 1010))))
                    (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))))
              Complex.I)
            (@OfNat.ofNat Complex (nat_lit 4)
              (@instOfNatAtLeastTwo Complex (nat_lit 4)
                (@AddMonoidWithOne.toNatCast Complex
                  (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne))
                (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))))))


Alice and Bob play a game in which they take turns choosing integers from $1$ to $n$. Before any integers are chosen, Bob selects a goal of 'odd' or 'even'. On the first turn, Alice chooses one of the $n$ integers. On the second turn, Bob chooses one of the remaining integers. They continue alternately choosing one of the integers that has not yet been chosen, until the $n$th turn, which is forced and ends the game. Bob wins if the parity of $\{k : \mbox{the number $k$ was chosen on the $k$th turn}\}$ matches his goal. For which values of $n$ does Bob have a winning strategy?

Show that Bob has a winning strategy for all $n$.

@Eq (Set Nat) answer
  (@setOf Nat fun (n : Nat) => @LT.lt Nat instLTNat (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))) n)

∀ g, IsValidGame g ↔ g.Nodup ∧ (∀ i ∈ g, i ∈ Icc 1 g.length)

∀ g, parityOf g = ((range g.length).filter fun i ↦ g[i]! = i + 1).card

∀ g s, ConformsToStrategy g s ↔
      ∀ (i) (h : i < g.length), Odd i → g[i] = s (g.take i)

∀ n s, IsWinningFor n s ↔
      ∃ p, ∀ g, g.length = n → IsValidGame g → ConformsToStrategy g s → parityOf g = p

{n : ℕ | 0 < n ∧ ∃ s, IsWinningFor n s} = answer


Consider an $m$-by-$n$ grid of unit squares, indexed by $(i,j)$ with $1 \leq i \leq m$ and $1 \leq j \leq n$. There are $(m-1)(n-1)$ coins, which are initially placed in the squares $(i,j)$ with $1 \leq i \leq m-1$ and $1 \leq j \leq n-1$. If a coin occupies the square $(i,j)$ with $i \leq m-1$ and $j \leq n-1$ and the squares $(i+1,j)$, $(i,j+1)$, and $(i+1,j+1)$ are unoccupied, then a legal move is to slide the coin from $(i,j)$ to $(i+1,j+1)$. How many distinct configurations of coins can be reached starting from the initial configuration by a (possibly empty) sequence of legal moves?

Show that the number of such configurations is $\binom{m+n-2}{m-1}$.

@Eq (Nat → Nat → Nat) answer fun (m_1 n_1 : Nat) =>
  Nat.choose
    (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat) m_1 n_1)
      (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
    (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) m_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))

initcoins

ℕ → ℕ → Bool

hinitcoins

initcoins = (fun i j : ℕ => (i ≤ m - 2 ∧ j ≤ n - 2 : Bool))

∀ coins1 coins2,
  IsLegalMove coins1 coins2 ↔
    ∃ i j, i < m - 1 ∧ j < n - 1 ∧
      coins1 i j ∧ !coins1 (i + 1) j ∧ !coins1 i (j + 1) ∧ !coins1 (i + 1) (j + 1) ∧
      !coins2 i j ∧ !coins2 (i + 1) j ∧ !coins2 i (j + 1) ∧ coins2 (i + 1) (j + 1) ∧
      (∀ i' j', ((i', j') ≠ (i, j) ∧ (i', j') ≠ (i + 1, j) ∧ (i', j') ≠ (i, j + 1) ∧ (i', j') ≠ (i + 1, j + 1))
        → coins1 i' j' = coins2 i' j')

∀ seq, IsLegalSeq seq ↔ seq.length ≥ 1 ∧ seq[0]! = initcoins ∧ (∀ i < seq.length - 1, IsLegalMove seq[i]! seq[i + 1]!)

{config : ℕ → ℕ → Bool | ∃ seq : List (ℕ → ℕ → Bool), IsLegalSeq seq ∧ config = seq.getLast!}.encard = answer m n


For each positive integer $n$, let $k(n)$ be the number of ones in the binary representation of $2023 * n$. What is the minimum value of $k(n)$?

@Eq Nat answer (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3)))

sInf {(digits 2 (2023 * n)).sum | n > 0} = answer


A sequence $y_1, y_2, \ldots, y_k$ of real numbers is called zigzag if $k = 1$, or if $y_2 - y_1, y_3 - y_2, \ldots, y_k - y_{k-1}$ are nonzero and alternate in sign. Let $X_1, X_2,\ldots, X_n$ be chosen independently from the uniform distribution on $[0,1]$. Let $a(X_1, X_2, \ldots, X_n)$ be the largest value of $k$ for which there exists an increasing sequence of integers $i_1, i_2, \ldots, i_k$ such that $X_{i_1}, X_{i_2}, \ldots, X_{i_k}$ is zigzag. Find the expected value of $a(X_1, X_2, \ldots, X_n)$ for $n \ge 2$.

Show that the expected value is \frac{2n + 2}{3}.

@Eq (Nat → Real) answer fun (n_1 : Nat) =>
  @HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
      (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
        (@OfNat.ofNat Real (nat_lit 2)
          (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))
        (@Nat.cast Real Real.instNatCast n_1))
      (@OfNat.ofNat Real (nat_lit 2)
        (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))
    (@OfNat.ofNat Real (nat_lit 3)
      (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))

∀ (k : ℕ) [NeZero k] (y : Fin k → ℝ),
      IsZigZag y ↔ k = 1 ∨ ((∀ i, i + 1 < k → y (i + 1) ≠ y i)) ∧
        (∀ i, i + 2 < k → (y (i + 2) < y (i + 1) ↔ y i < y (i + 1)))

ha

∀ x, IsGreatest {k | ∃ i : Fin k ↪o Fin n, IsZigZag ((↑) ∘ x ∘ i)} (a x)


For a nonnegative integer $n$ and a strictly increasing sequence of real numbers $t_0,t_1,\dots,t_n$, let $f(t)$ be the corresponding real-valued function defined for $t \geq t_0$ by the following properties:
\begin{enumerate}
\item[(a)] $f(t)$ is continuous for $t \geq t_0$, and is twice differentiable for all $t>t_0$ other than $t_1,\dots,t_n$;
\item[(b)] $f(t_0)=1/2$;
\item[(c)] $\lim_{t \to t_k^+} f'(t)=0$ for $0 \leq k \leq n$;
\item[(d)] For $0 \leq k \leq n-1$, we have $f''(t)=k+1$ when $t_k<t<t_{k+1}$, and $f''(t)=n+1$ when $t>t_n$.
\end{enumerate}
Considering all choices of $n$ and $t_0,t_1,\dots,t_n$ such that $t_k \geq t_{k-1}+1$ for $1 \leq k \leq n$, what is the least possible value of $T$ for which $f(t_0+T)=2023$?

Show that the minimum value of $T$ is $29$.

@Eq Real answer
  (@OfNat.ofNat Real (nat_lit 29)
    (@instOfNatAtLeastTwo Real (nat_lit 29) Real.instNatCast
      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 27) (instOfNatNat (nat_lit 27))))))

tne

ℕ → (ℕ → ℝ) → Set ℝ

htne

∀ n ts, tne n ts = {t | t > ts 0 ∧ ∀ i : Fin n, t ≠ ts (i.1 + 1)}

IsLeast
    {(T : ℝ) | 0 ≤ T ∧ ∃ (n : ℕ) (ts : ℕ → ℝ) (f : ℝ → ℝ),
      ∀ k : Fin n, ts (k.1 + 1) ≥ ts k.1 + 1 ∧
      ContinuousOn f (Set.Ici (ts 0)) ∧
      ContDiffOn ℝ 1 f (tne n ts) ∧
      DifferentiableOn ℝ (derivWithin f (tne n ts)) (tne n ts) ∧
      f (ts 0) = 0.5 ∧
      (∀ k : Fin (n + 1),
        Tendsto (derivWithin f (tne n ts)) (𝓝[>] (ts k.1)) (𝓝 0)) ∧
      (∀ k : Fin n,
        ∀ t ∈ Set.Ioo (ts k.1) (ts (k.1 + 1)),
          iteratedDerivWithin 2 f (tne n ts) t = k.1 + 1) ∧
      (∀ t > ts n,
        iteratedDerivWithin 2 f (tne n ts) t = n + 1) ∧
      f (ts 0 + T) = 2023}
    answer


Determine which positive integers $n$ have the following property: For all integers $m$ that are relatively prime to $n$, there exists a permutation $\pi:\{1,2,\dots,n\} \to \{1,2,\dots,n\}$ such that $\pi(\pi(k)) \equiv mk \pmod{n}$ for all $k \in \{1,2,\dots,n\}$.

Show that the desired property holds if and only if $n=1$ or $n \equiv 2 \pmod{4}$.

@Eq (Set Nat) answer
  (@setOf Nat fun (n_1 : Nat) =>
    Or (@Eq Nat n_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
      (Nat.ModEq (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))) n_1
        (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))

n ∈ answer ↔
    0 < n ∧
    (∀ m : ℤ, IsRelPrime m n → ∃ p : Equiv.Perm (Fin n),
      ∀ k : Fin n, (p (p k)).1 + 1 ≡ m * (k.1 + 1) [ZMOD n])


Let $n$ be a positive integer. For $i$ and $j$ in $\{1,2,\dots,n\}$, let $s(i,j)$ be the number of pairs $(a,b)$ of nonnegative integers satisfying $ai+bj=n$. Let $S$ be the $n$-by-$n$ matrix whose $(i,j)$ entry is $s(i,j)$. For example, when $n=5$, we have $S = \begin{bmatrix}
6 & 3 & 2 & 2 & 2 \\
3 & 0 & 1 & 0 & 1 \\
2 & 1 & 0 & 0 & 1 \\
2 & 0 & 0 & 0 & 1 \\
2 & 1 & 1 & 1 & 2
\end{bmatrix}$. Compute the determinant of $S$.

Show that the determinant equals $(-1)^{\lceil n/2 \rceil-1}2\lceil\frac{n}{2}\rceil$.

@Eq (Nat → Int) answer fun (n_1 : Nat) =>
  @HMul.hMul Int Int Int (@instHMul Int Int.instMul)
    (@HMul.hMul Int Int Int (@instHMul Int Int.instMul)
      (@HPow.hPow Int Nat Int (@instHPow Int Nat (@Monoid.toNatPow Int Int.instMonoid))
        (@Neg.neg Int Int.instNegInt (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1))))
        (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat)
          (@Nat.ceil Rat Rat.instOrderedSemiring
            (@FloorRing.toFloorSemiring Rat Rat.instLinearOrderedRing Rat.instFloorRing)
            (@HDiv.hDiv Rat Rat Rat (@instHDiv Rat Rat.instDiv) (@Nat.cast Rat Rat.instNatCast n_1)
              (@OfNat.ofNat Rat (nat_lit 2) (@Rat.instOfNat (nat_lit 2)))))
          (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))
      (@OfNat.ofNat Int (nat_lit 2) (@instOfNat (nat_lit 2))))
    (@Nat.cast Int instNatCastInt
      (@Nat.ceil Rat Rat.instOrderedSemiring
        (@FloorRing.toFloorSemiring Rat Rat.instLinearOrderedRing Rat.instFloorRing)
        (@HDiv.hDiv Rat Rat Rat (@instHDiv Rat Rat.instDiv) (@Nat.cast Rat Rat.instNatCast n_1)
          (@OfNat.ofNat Rat (nat_lit 2) (@Rat.instOfNat (nat_lit 2))))))

hS

∀ i j : Fin n, S i j = ∑' a : ℕ, ∑' b : ℕ, if a * (i.1 + 1) + b * (j.1 + 1) = (n : ℤ) then 1 else 0