Suppose that each of 20 students has made a choice of anywhere from 0 to 6 courses from a total of 6 courses offered. Prove or disprove: there are 5 students and 2 courses such that all 5 have chosen both courses or all 5 have chosen neither course.

Show that the solution is that the statement is false.

answer ↔ (∃ (students : Finset (Fin 20)) (courses : Finset (Fin 6)),
                        students.card = 5 ∧
                        courses.card = 2 ∧
                        (↑courses ⊆ ⋂ s ∈ students, choices s ∨ ↑courses ⊆ ⋂ s ∈ students, (choices s)ᶜ))


Let $c>0$ be a constant. Give a complete description, with proof, of the set of all continuous functions $f:\mathbb{R} \to \mathbb{R}$ such that $f(x)=f(x^2+c)$ for all $x \in \mathbb{R}$.

the set of functions described by the condition

Show that if $c \leq 1/4$ then $f$ must be constant, and if $c>1/4$ then $f$ can be defined on $[0,c]$ as any continuous function with equal values on the endpoints, then extended to $x>c$ by the relation $f(x)=f(x^2+c)$, then extended further to $x<0$ by the relation $f(x)=f(-x)$.

@Eq (Real → Set (Real → Real)) answer fun (c_1 : Real) =>
  @ite (Set (Real → Real))
    (@LE.le Real Real.instLE c_1
      (@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))))))))
    (Real.decidableLE c_1
      (@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))))))))
    (@setOf (Real → Real) fun (f_1 : Real → Real) => @Exists Real fun (d : Real) => ∀ (x : Real), @Eq Real (f_1 x) d)
    (@setOf (Real → Real) fun (f_1 : Real → Real) =>
      And
        (@ContinuousOn Real Real
          (@UniformSpace.toTopologicalSpace Real (@PseudoMetricSpace.toUniformSpace Real Real.pseudoMetricSpace))
          (@UniformSpace.toTopologicalSpace Real (@PseudoMetricSpace.toUniformSpace Real Real.pseudoMetricSpace)) f_1
          (@Set.Icc Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)) c_1))
        (And (@Eq Real (f_1 (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))) (f_1 c_1))
          (And
            (∀ (x : Real),
              @GT.gt Real Real.instLT x (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)) →
                @Eq Real (f_1 x)
                  (f_1
                    (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
                      (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) x
                        (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
                      c_1)))
            (∀ (x : Real),
              @LT.lt Real Real.instLT x (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)) →
                @Eq Real (f_1 x) (f_1 (@Neg.neg Real Real.instNeg x))))))

ℝ → Set (ℝ → ℝ)

(Continuous f ∧ ∀ x : ℝ, f x = f (x ^ 2 + c)) ↔ f ∈ answer c


Define a \emph{selfish} set to be a set which has its own cardinality (number of elements) as an element. Find, with proof, the number of subsets of $\{1,2,\ldots,n\}$ which are \emph{minimal} selfish sets, that is, selfish sets none of whose proper subsets is selfish.

Show that the number of subsets is $F_n$, the $n$th Fibonacci number.

hselfish

∀ s : Finset ℕ, selfish s = (s.card ∈ s)

{s : Finset ℕ | (s : Set ℕ) ⊆ Set.Icc 1 n ∧ selfish s ∧ (∀ ss : Finset ℕ, ss ⊂ s → ¬selfish ss)}.encard = answer n


Given that $\{x_1,x_2,\ldots,x_n\}=\{1,2,\ldots,n\}$, find, with proof, the largest possible value, as a function of $n$ (with $n \geq 2$), of $x_1x_2+x_2x_3+\cdots+x_{n-1}x_n+x_nx_1$.

Show that the maximum is $(2n^3+3n^2-11n+18)/6$.

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @HDiv.hDiv Nat Nat Nat (@instHDiv Nat Nat.instDiv)
    (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat)
      (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat)
        (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat)
          (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
            (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid)) n_1
              (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3)))))
          (@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)) n_1
              (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
        (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) (@OfNat.ofNat Nat (nat_lit 11) (instOfNatNat (nat_lit 11)))
          n_1))
      (@OfNat.ofNat Nat (nat_lit 18) (instOfNatNat (nat_lit 18))))
    (@OfNat.ofNat Nat (nat_lit 6) (instOfNatNat (nat_lit 6)))

IsGreatest
  {k | ∃ x : ℕ → ℤ,
    (x '' (Finset.range n) = Set.Icc (1 : ℤ) n) ∧
    ∑ i : Fin n, x i * x ((i + 1) % n) = k}
  (answer n)


For any square matrix $A$, we can define $\sin A$ by the usual power series: $\sin A=\sum_{n=0}^\infty \frac{(-1)^n}{(2n+1)!}A^{2n+1}$. Prove or disprove: there exists a $2 \times 2$ matrix $A$ with real entries such that $\sin A=\begin{pmatrix} 1 & 1996 \\ 0 & 1 \end{pmatrix}$.

Show that there does not exist such a matrix $A$.

matsin

Matrix (Fin 2) (Fin 2) ℝ → Matrix (Fin 2) (Fin 2) ℝ


Given a finite string $S$ of symbols $X$ and $O$, we write $\Delta(S)$ for the number of $X$'s in $S$ minus the number of $O$'s. For example, $\Delta(XOOXOOX)=-1$. We call a string $S$ \emph{balanced} if every substring $T$ of (consecutive symbols of) $S$ has $-2 \leq \Delta(T) \leq 2$. Thus, $XOOXOOX$ is not balanced, since it contains the substring $OOXOO$. Find, with proof, the number of balanced strings of length $n$.

Show that the number of balanced strings of length $n$ is $3 \cdot 2^{n/2}-2$ if $n$ is even, and $2^{(n+1)/2}-2$ if $n$ is odd.

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat)
    (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat)
      (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
        (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
        (@Nat.floor Nat Nat.instOrderedSemiring instFloorSemiringNat
          (@HDiv.hDiv Nat Nat Nat (@instHDiv Nat Nat.instDiv)
            (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat) n_1
              (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
            (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))
      (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
        (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
        (@Nat.floor Nat Nat.instOrderedSemiring instFloorSemiringNat
          (@HDiv.hDiv Nat Nat Nat (@instHDiv Nat Nat.instDiv)
            (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat) n_1
              (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
            (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))
    (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))

hΔ

∀ S, ∀ a b, a ≤ b → Δ S a b = ∑ i in Finset.Icc a b, (S i : ℤ)

hbalanced

∀ S, balanced S ↔ ∀ a b, a ≤ b → |Δ S a b| ≤ 2

{S : Fin n → ℤˣ | balanced S}.ncard = answer n


Evaluate \begin{gather*} \int_0^\infty \left(x-\frac{x^3}{2}+\frac{x^5}{2\cdot 4}-\frac{x^7}{2\cdot 4\cdot 6}+\cdots\right) \\ \left(1+\frac{x^2}{2^2}+\frac{x^4}{2^2\cdot 4^2}+\frac{x^6}{2^2\cdot 4^2 \cdot 6^2}+\cdots\right)\,dx. \end{gather*}

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

series2 = fun x => ∑' n : ℕ, x^(2*n)/(∏ i : Finset.range n, (2 * ((i : ℝ) + 1))^2)

Tendsto (fun t => ∫ x in Set.Icc 0 t, series1 x * series2 x) atTop (𝓝 answer)


Let $N_n$ denote the number of ordered $n$-tuples of positive integers $(a_1,a_2,\ldots,a_n)$ such that $1/a_1 + 1/a_2 +\ldots + 1/a_n=1$.  Determine whether $N_{10}$ is even or odd.

hN

N = fun (n : ℕ+) => {t : Fin n → ℕ+ | (∀ i j : Fin n, i < j → t i <= t j) ∧ (∑ i : Fin n, (1 : ℝ)/(t i) = 1) }


For a positive integer $n$ and any real number $c$, define $x_k$ recursively by $x_0=0$, $x_1=1$, and for $k\geq 0$, \[x_{k+2}=\frac{cx_{k+1}-(n-k)x_k}{k+1}.\] Fix $n$ and then take $c$ to be the largest value for which $x_{n+1}=0$. Find $x_k$ in terms of $n$ and $k$, $1\leq k\leq n$.

fun n k => Nat.choose (n.toNat-1) (k.toNat-1)

Show that the solution is that $x_k = {n - 1 \choose k - 1}$.

@Eq (Int → Int → Real) answer fun (n_1 k : Int) =>
  @Nat.cast Real Real.instNatCast
    (Nat.choose
      (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) (Int.toNat n_1)
        (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
      (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) (Int.toNat k)
        (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))

∀ k : Set.Icc 1 n, x (sSup S) k = answer n k


Let $\{x\}$ denote the distance between the real number $x$ and the nearest integer.  For each positive integer $n$, evaluate \[F_n=\sum_{m=1}^{6n-1} \min(\{\frac{m}{6n}\},\{\frac{m}{3n}\}).\] (Here $\min(a,b)$ denotes the minimum of $a$ and $b$.)

@Eq (Nat → Real) answer fun (n : Nat) => @Nat.cast Real Real.instNatCast n

hF

F = fun (n : ℕ) => ∑ m in Finset.Icc 1 (6 * n - 1), min (dist_to_int (m/(6*n)) ) (dist_to_int (m/(3*n)))


For each positive integer $n$, write the sum $\sum_{m=1}^n 1/m$ in the form $p_n/q_n$, where $p_n$ and $q_n$ are relatively prime positive integers.  Determine all $n$ such that 5 does not divide $q_n$.

Show that the solution is the set of natural numbers which are between $1$ and $4$, or between $20$ and $24$, or between $100$ and $104$, or between $120$ and $124$.

@Eq (Set Nat) answer
  (@setOf Nat fun (n_1 : Nat) =>
    Or
      (And (@LE.le Nat instLENat (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))) n_1)
        (@LE.le Nat instLENat n_1 (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4)))))
      (Or
        (And (@LE.le Nat instLENat (@OfNat.ofNat Nat (nat_lit 20) (instOfNatNat (nat_lit 20))) n_1)
          (@LE.le Nat instLENat n_1 (@OfNat.ofNat Nat (nat_lit 24) (instOfNatNat (nat_lit 24)))))
        (Or
          (And (@LE.le Nat instLENat (@OfNat.ofNat Nat (nat_lit 100) (instOfNatNat (nat_lit 100))) n_1)
            (@LE.le Nat instLENat n_1 (@OfNat.ofNat Nat (nat_lit 104) (instOfNatNat (nat_lit 104)))))
          (And (@LE.le Nat instLENat (@OfNat.ofNat Nat (nat_lit 120) (instOfNatNat (nat_lit 120))) n_1)
            (@LE.le Nat instLENat n_1 (@OfNat.ofNat Nat (nat_lit 124) (instOfNatNat (nat_lit 124))))))))

n ∈ answer ↔ ¬5 ∣ (∑ m in Finset.Icc 1 n, 1/m : ℚ).den


Let $A_1=0$ and $A_2=1$. For $n>2$, the number $A_n$ is defined by concatenating the decimal expansions of $A_{n-1}$ and $A_{n-2}$ from left to right.  For example $A_3=A_2 A_1=10$, $A_4=A_3 A_2 = 101$, $A_5=A_4 A_3 = 10110$, and so forth.  Determine all $n$ such that $11$ divides $A_n$.

Show that the solution is those n for which n can be written as 6k+1 for some integer k.

@Eq (Set Nat) answer
  (@setOf Nat fun (n : Nat) =>
    Nat.ModEq (@OfNat.ofNat Nat (nat_lit 6) (instOfNatNat (nat_lit 6))) n
      (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))

{n | 1 ≤ n ∧ 11 ∣ Nat.ofDigits 10 (A n).reverse} = answer


@Eq Real answer
  (@OfNat.ofNat Real (nat_lit 6)
    (@instOfNatAtLeastTwo Real (nat_lit 6) Real.instNatCast
      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))))


Given a point $(a,b)$ with $0<b<a$, determine the minimum perimeter of a triangle with one vertex at $(a,b)$, one on the $x$-axis, and one on the line $y=x$.  You may assume that a triangle of minimum perimeter exists.

$\sqrt{2a^2 + 2b^2}$ if $a > b$, otherwise $0$

Show that the solution is $\sqrt{2a^2 + 2b^2}.

@Eq (Real → Real → Real) answer fun (a_1 b_1 : Real) =>
  @ite Real (@GT.gt Real Real.instLT a_1 b_1) (Real.decidableLT b_1 a_1)
    (Real.sqrt
      (@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))))))
          (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) a_1
            (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))
        (@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))))))
          (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) b_1
            (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))
    (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))


Find necessary and sufficient conditions on positive integers $m$ and $n$ so that \[\sum_{i=0}^{mn-1} (-1)^{\lfloor i/m \rfloor +\lfloor i/n\rfloor}=0.\]

{nm | let ⟨n,m⟩ := nm; multiplicity 2 n ≠ multiplicity 2 m}

Show that the sum is 0 if and only if the largest powers of $2$ dividing $m$ and $n$ are different.

@Eq (Set (Prod Nat Nat)) answer
  (@setOf (Prod Nat Nat) fun (nm : Prod Nat Nat) =>
    _example.match_1 (fun (nm_1 : Prod Nat Nat) => Prop) nm fun (n_1 m_1 : Nat) =>
      @Ne Nat (@multiplicity Nat Nat.instMonoid (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) n_1)
        (@multiplicity Nat Nat.instMonoid (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) m_1))

hquantity

quantity = fun n m => ∑ i in Finset.range (m * n), (-1)^(i/m + i/n)


Let $N$ be the positive integer with 1998 decimal digits, all of them 1; that is, \[N=1111\cdots 11.\] Find the thousandth digit after the decimal point of $\sqrt N$.

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

answer = (Nat.floor (10^1000 * Real.sqrt N)) % 10


Find polynomials $f(x)$,$g(x)$, and $h(x)$, if they exist, such that for all $x$, \[|f(x)|-|g(x)|+h(x) = \begin{cases} -1 & \mbox{if $x<-1$} \\3x+2 & \mbox{if $-1 \leq x \leq 0$} \\-2x+2 & \mbox{if $x>0$.}\end{cases}\]?

Show that the answer is such functions do exist.

answer ↔ ∃ f g h : Polynomial ℝ, ∀ x : ℝ, |f.eval x| - |g.eval x| + h.eval x = if x < -1 then -1 else (if (x ≤ 0) then 3 * x + 2 else -2 * x + 2)


Sum the series \[\sum_{m=1}^\infty \sum_{n=1}^\infty \frac{m^2 n}{3^m(n3^m+m3^n)}.\]

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@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 Real (nat_lit 32)
      (@instOfNatAtLeastTwo Real (nat_lit 32) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 30) (instOfNatNat (nat_lit 30)))))))


Let $A=\{(x,y):0\leq x,y<1\}$.  For $(x,y)\in A$, let \[S(x,y) = \sum_{\frac{1}{2}\leq \frac{m}{n}\leq 2} x^m y^n,\] where the sum ranges over all pairs $(m,n)$ of positive integers satisfying the indicated inequalities.  Evaluate \[\lim_{(x,y)\rightarrow (1,1), (x,y)\in A} (1-xy^2)(1-x^2y)S(x,y).\]

@Eq Real answer
  (@OfNat.ofNat Real (nat_lit 3)
    (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))

hS

S = fun x y => ∑' m : ℕ, ∑' n : ℕ, if (m > 0 ∧ n > 0 ∧ 1/2 ≤ m/n ∧ m/n ≤ 2) then x^m * y^n else 0


For an integer $n\geq 3$, let $\theta=2\pi/n$.  Evaluate the determinant of the $n\times n$ matrix $I+A$, where $I$ is the $n\times n$ identity matrix and $A=(a_{jk})$ has entries $a_{jk}=\cos(j\theta+k\theta)$ for all $j,k$.

@Eq (Nat → Real) answer fun (n_1 : Nat) =>
  @HSub.hSub Real Real Real (@instHSub Real Real.instSub)
    (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))
    (@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))
        (@Nat.cast Real Real.instNatCast n_1) (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
      (@OfNat.ofNat Real (nat_lit 4)
        (@instOfNatAtLeastTwo Real (nat_lit 4) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))))

hA

A = fun j k => Real.cos ((j.1 + 1) * theta + (k.1 + 1) * theta)


Let $A$ be a positive real number. What are the possible values of $\sum_{j=0}^\infty x_j^2$, given that $x_0,x_1,\ldots$ are positive numbers for which $\sum_{j=0}^\infty x_j=A$?

Show that the possible values comprise the interval $(0,A^2)$.

@Eq (Real → Set Real) answer fun (A_1 : Real) =>
  @Set.Ioo Real Real.instPreorder (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))
    (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid)) A_1
      (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))

{S : ℝ |
    ∃ x : ℕ → ℝ,
      (∀ j : ℕ, x j > 0) ∧
      (∑' j : ℕ, x j) = A ∧
      (∑' j : ℕ, (x j) ^ 2) = S}
  = answer A


For each integer $m$, consider the polynomial
\[P_m(x)=x^4-(2m+4)x^2+(m-2)^2.\] For what values of $m$ is $P_m(x)$
the product of two non-constant polynomials with integer coefficients?

$P_m(x)$ factors into two nonconstant polynomials over
the integers if and only if $m$ is either a square or twice a square.

@Eq (Set Int) answer
  (@setOf Int fun (m : Int) =>
    @Exists Int fun (k : Int) =>
      Or
        (@Eq Int
          (@HPow.hPow Int Nat Int (@instHPow Int Nat (@Monoid.toNatPow Int Int.instMonoid)) k
            (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
          m)
        (@Eq Int
          (@HMul.hMul Int Int Int (@instHMul Int Int.instMul) (@OfNat.ofNat Int (nat_lit 2) (@instOfNat (nat_lit 2)))
            (@HPow.hPow Int Nat Int (@instHPow Int Nat (@Monoid.toNatPow Int Int.instMonoid)) k
              (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))
          m))

hP

P = fun m : ℤ => (Polynomial.X)^4 - (Polynomial.C (2*m + 4))*(Polynomial.X)^2 + Polynomial.C ((m - 2)^2)

{m : ℤ | ∃ a b, P m = a * b ∧
(∃ n ∈ Ici 1, a.coeff n ≠ 0) ∧ (∃ n ∈ Ici 1, b.coeff n ≠ 0)} = answer


Find all pairs of real numbers $(x,y)$ satisfying the system of equations
\begin{align*}
\frac{1}{x}+\frac{1}{2y}&=(x^2+3y^2)(3x^2+y^2) \\
\frac{1}{x}-\frac{1}{2y}&=2(y^4-x^4).
\end{align*}

the set containing the pair $\left(\frac{3^{1/5} + 1}{2}, \frac{3^{1/5} - 1}{2}\right)$

Show that $x=(3^{1/5}+1)/2$ and $y=(3^{1/5}-1)/2$ is the unique solution satisfying the given equations.

@Eq (Set (Prod Real Real)) answer
  (@Singleton.singleton (Prod Real Real) (Set (Prod Real Real)) (@Set.instSingletonSet (Prod Real Real))
    (@Prod.mk Real Real
      (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
        (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
          (@HPow.hPow Real Real Real (@instHPow Real Real Real.instPow)
            (@OfNat.ofNat Real (nat_lit 3)
              (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
                (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
            (@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 5)
                (@instOfNatAtLeastTwo Real (nat_lit 5) Real.instNatCast
                  (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3))))))))
          (@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)))))))
      (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
        (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
          (@HPow.hPow Real Real Real (@instHPow Real Real Real.instPow)
            (@OfNat.ofNat Real (nat_lit 3)
              (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
                (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
            (@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 5)
                (@instOfNatAtLeastTwo Real (nat_lit 5) Real.instNatCast
                  (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3))))))))
          (@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)))))))))


For any positive integer $n$, let $\langle n \rangle$ denote the closest integer to $\sqrt{n}$. Evaluate $\sum_{n=1}^\infty \frac{2^{\langle n \rangle}+2^{-\langle n \rangle}}{2^n}$.

∑' n : Set.Ici 1, ((2 : ℝ) ^ (round (Real.sqrt n)) + (2 : ℝ) ^ (-round (Real.sqrt n))) / 2 ^ (n : ℝ) = answer


Assume that $(a_n)_{n \geq 1}$ is an increasing sequence of positive real numbers such that $\lim a_n/n=0$. Must there exist infinitely many positive integers $n$ such that $a_{n-i}+a_{n+i}<2a_n$ for $i=1,2,\ldots,n-1$?

Show that the answer is yes, there must exist infinitely many such $n$.

Tendsto (fun n : ℤ => a (n + 1) / (n + 1)) atTop (𝓝 0)

{n : ℤ | n > 0 ∧ (∀ i ∈ Set.Icc 1 (n - 1), a (n - i) + a (n + i) < 2 * a n)}.Infinite ↔ answer


Let $k$ be a fixed positive integer. The $n$-th derivative of $\frac{1}{x^k-1}$ has the form $\frac{P_n(x)}{(x^k-1)^{n+1}}$ where $P_n(x)$ is a polynomial. Find $P_n(1)$.

Show that $P_n(1)=(-k)^nn!$ for all $n \geq 0$.

@Eq (Nat → Nat → Real) answer fun (k_1 n : Nat) =>
  @HMul.hMul Real Real Real (@instHMul Real Real.instMul)
    (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
      (@Neg.neg Real Real.instNeg (@Nat.cast Real Real.instNatCast k_1)) n)
    (@Nat.cast Real Real.instNatCast (Nat.factorial n))

Pderiv

∀ n x, iteratedDeriv n (fun x' : ℝ => 1 / (x' ^ k - 1)) x = ((P n).eval x) / ((x ^ k - 1) ^ (n + 1))


Fix an integer $b \geq 2$. Let $f(1) = 1$, $f(2) = 2$, and for each
$n \geq 3$, define $f(n) = n f(d)$, where $d$ is the number of
base-$b$ digits of $n$. For which values of $b$ does
\[
\sum_{n=1}^\infty \frac{1}{f(n)}
\]
converge?

The sum converges for $b=2$ and diverges for $b \geq 3$.

@Eq (Set Nat) answer
  (@Singleton.singleton Nat (Set Nat) (@Set.instSingletonSet Nat)
    (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))

hf

∀ b : ℕ, f b 1 = 1 ∧ f b 2 = 2 ∧ ∀ n ∈ Ici 3, f b n = n * f b (Nat.digits b n).length

{b ∈ Ici 2 | ∃ L : ℝ, Tendsto (fun m : ℕ => ∑ n in Finset.Icc 1 m, 1/(f b n)) atTop (𝓝 L)} = answer


Let $n$ be a fixed positive integer. How many ways are there to write $n$ as a sum of positive integers, \[ n = a_1 + a_2 + \dots + a_k, \] with $k$ an arbitrary positive integer and $a_1 \leq a_2 \leq \dots \leq a_k \leq a_1 + 1$? For example, with $n = 4$, there are four ways: $4, 2 + 2, 1 + 1 + 2, 1 + 1 + 1 + 1$

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

Set.encard {a : ℕ → ℤ |
  ∃ k > 0, (∑ i : Fin k, a i = n) ∧
    (∀ i : Fin k, a i > 0) ∧
    (∀ i : Fin (k - 1), a i ≤ a (i + 1)) ∧
    a (k - 1) ≤ a 0 + 1 ∧ (∀ i ≥ k, a i = 0)} = answer n


Find the minimum value of $|\sin x+\cos x+\tan x+\cot x+\sec x+\csc x|$ for real numbers $x$.

@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.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 1) (@One.toOfNat1 Real Real.instOne)))

∀ x : ℝ, f x = |Real.sin x + Real.cos x + Real.tan x + 1 / Real.tan x + 1 / Real.cos x + 1 / Real.sin x|


For a set $S$ of nonnegative integers, let $r_S(n)$ denote the number of ordered pairs $(s_1,s_2)$ such that $s_1 \in S$, $s_2 \in S$, $s_1 \ne s_2$, and $s_1+s_2=n$. Is it possible to partition the nonnegative integers into two sets $A$ and $B$ in such a way that $r_A(n)=r_B(n)$ for all $n$?

r

Set ℕ → ℕ → ℕ

hr

∀ S n, r S n = ∑' s1 : S, ∑' s2 : S, if (s1 ≠ s2 ∧ s1 + s2 = n) then 1 else 0

(∃ A B : Set ℕ, A ∪ B = ℕ ∧ A ∩ B = ∅ ∧ (∀ n : ℕ, r A n = r B n)) ↔ answer


Do there exist polynomials $a(x), b(x), c(y), d(y)$ such that \[ 1 + xy + x^2y^2 = a(x)c(y) + b(x)d(y)\] holds identically?

answer = (∃ a b c d : Polynomial ℝ, (∀ x y : ℝ, 1 + x * y + x ^ 2 * y ^ 2 = a.eval x * c.eval y + b.eval x * d.eval y))


Basketball star Shanille O'Keal's team statistician keeps track of the number, $S(N)$, of successful free throws she has made in her first $N$ attempts of the season. Early in the season, $S(N)$ was less than $80\%$ of $N$, but by the end of the season, $S(N)$ was more than $80\%$ of $N$. Was there necessarily a moment in between when $S(N)$ was exactly $80\%$ of $N$?

S

(ℕ → Fin 2) → ℕ → ℝ

hS

∀ attempts, ∀ N ≥ 1, S attempts N = (∑ i : Fin N, (attempts i).1) / N

answer ↔ (∀ attempts a b,
    (1 ≤ a ∧ a < b ∧ S attempts a < 0.8 ∧ S attempts b > 0.8) →
      (∃ c : ℕ, a < c ∧ c < b ∧ S attempts c = 0.8))


Let $n$ be a positive integer, $n \ge 2$, and put $\theta = 2 \pi / n$. Define points $P_k = (k,0)$ in the $xy$-plane, for $k = 1, 2, \dots, n$. Let $R_k$ be the map that rotates the plane counterclockwise by the angle $\theta$ about the point $P_k$. Let $R$ denote the map obtained by applying, in order, $R_1$, then $R_2, \dots$, then $R_n$. For an arbitrary point $(x,y)$, find, and simplify, the coordinates of $R(x,y)$.

@Eq (Nat → Complex → Complex) answer fun (n_1 : Nat) (z : Complex) =>
  @HAdd.hAdd Complex Complex Complex (@instHAdd Complex Complex.instAdd) z
    (@Nat.cast Complex
      (@AddMonoidWithOne.toNatCast Complex (@AddGroupWithOne.toAddMonoidWithOne Complex Complex.addGroupWithOne)) n_1)

hR

R 0 = id ∧ ∀ k : ℕ, R (k + 1) = Rk (k + 1) ∘ R k

hRk

Rk = fun (k : ℕ) (Q : ℂ) ↦ k + Complex.exp (Complex.I * 2 * Real.pi / n) * (Q - k)


Evaluate $\lim_{x \to 1^-} \prod_{n=0}^\infty \left(\frac{1+x^{n+1}}{1+x^n}\right)^{x^n}$.

@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))))))
    (Real.exp (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))))

hxprod

∀ x ∈ Set.Ioo 0 1,
      Tendsto (fun N ↦ ∏ n in Finset.range N, ((1 + x ^ (n + 1)) / (1 + x ^ n)) ^ (x ^ n))
      atTop (𝓝 (xprod x))


Let $\mathbf{S} = \{(a,b) | a = 1, 2, \dots,n, b = 1,2,3\}$.
A \emph{rook tour} of $\mathbf{S}$ is a polygonal path made up of line segments connecting points $p_1, p_2, \dots, p_{3n}$ in sequence such that
\begin{enumerate}
\item[(i)] $p_i \in \mathbf{S}$,
\item[(ii)] $p_i$ and $p_{i+1}$ are a unit distance apart, for
$1 \leq i <3n$,
\item[(iii)] for each $p \in \mathbf{S}$ there is a unique $i$ such that
$p_i = p$.
\end{enumerate}
How many rook tours are there that begin at $(1,1)$
and end at $(n,1)$?

fun n ↦ if n = 1 then 0 else 2 ^ (n - 2)

Show that the number of rook tours is $0$ if $n = 1$ and $2 ^ {n - 2}$ if $n \geq 2$.

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @ite Nat (@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 Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))
    (@HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
      (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
      (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) n_1 (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))

unit

ℤ × ℤ → ℤ × ℤ → Prop

rooktour

(ℕ → ℤ × ℤ) → Prop

hunit

unit = fun (a, b) (c, d) ↦ a = c ∧ |d - b| = 1 ∨ b = d ∧ |c - a| = 1

hrooktour

rooktour = fun p ↦ (∀ P ∈ S, ∃! i, i ∈ Icc 1 (3 * n) ∧ p i = P) ∧ (∀ i ∈ Icc 1 (3 * n - 1), unit (p i) (p (i + 1))) ∧ p 0 = 0 ∧ ∀ i > 3 * n, p i = 0

{p : ℕ → ℤ × ℤ | rooktour p ∧ p 1 = (1, 1) ∧ p (3 * n) = ((n : ℤ), 1)}.encard = answer n


Show that the solution is $\pi / 8 * \log 2$.

@Eq Real answer
  (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) 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))))))))
    (@OfNat.ofNat Real (nat_lit 8)
      (@instOfNatAtLeastTwo Real (nat_lit 8) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 6) (instOfNatNat (nat_lit 6)))))))


Find a nonzero polynomial $P(x,y)$ such that $P(\lfloor a \rfloor,\lfloor 2a \rfloor)=0$ for all real numbers $a$. (Note: $\lfloor \nu \rfloor$ is the greatest integer less than or equal to $\nu$.)

Show that $P(x,y)=(y-2x)(y-2x-1)$ works.

@Eq (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring) answer
  (@HMul.hMul (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
    (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
    (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
    (@instHMul
      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
      (@Distrib.toMul
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@NonUnitalNonAssocSemiring.toDistrib
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@NonUnitalNonAssocCommSemiring.toNonUnitalNonAssocSemiring
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (@NonUnitalNonAssocCommRing.toNonUnitalNonAssocCommSemiring
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@NonUnitalCommRing.toNonUnitalNonAssocCommRing
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@CommRing.toNonUnitalCommRing
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@MvPolynomial.instCommRingMvPolynomial Real
                    (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing))))))))
    (@HSub.hSub
      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
      (@instHSub
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@SubNegMonoid.toSub
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@AddGroup.toSubNegMonoid
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (@AddGroupWithOne.toAddGroup
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@Ring.toAddGroupWithOne
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@CommRing.toRing
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@MvPolynomial.instCommRingMvPolynomial Real
                    (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing)))))))
      (@MvPolynomial.X Real (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.instCommSemiring
        (@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
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@instHMul
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@Distrib.toMul
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (@NonUnitalNonAssocSemiring.toDistrib
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@NonUnitalNonAssocCommSemiring.toNonUnitalNonAssocSemiring
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@NonUnitalNonAssocCommRing.toNonUnitalNonAssocCommSemiring
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@NonUnitalCommRing.toNonUnitalNonAssocCommRing
                    (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                      Real.instCommSemiring)
                    (@CommRing.toNonUnitalCommRing
                      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                        Real.instCommSemiring)
                      (@MvPolynomial.instCommRingMvPolynomial Real
                        (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing))))))))
        (@OfNat.ofNat
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (nat_lit 2)
          (@instOfNatAtLeastTwo
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (nat_lit 2)
            (@AddMonoidWithOne.toNatCast
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@AddGroupWithOne.toAddMonoidWithOne
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@Ring.toAddGroupWithOne
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@CommRing.toRing
                    (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                      Real.instCommSemiring)
                    (@MvPolynomial.instCommRingMvPolynomial Real
                      (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing)))))
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))
        (@MvPolynomial.X Real (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.instCommSemiring
          (@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))))))
    (@HSub.hSub
      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
      (@instHSub
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@SubNegMonoid.toSub
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@AddGroup.toSubNegMonoid
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (@AddGroupWithOne.toAddGroup
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@Ring.toAddGroupWithOne
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@CommRing.toRing
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@MvPolynomial.instCommRingMvPolynomial Real
                    (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing)))))))
      (@HSub.hSub
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (@instHSub
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@SubNegMonoid.toSub
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (@AddGroup.toSubNegMonoid
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@AddGroupWithOne.toAddGroup
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@Ring.toAddGroupWithOne
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@CommRing.toRing
                    (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                      Real.instCommSemiring)
                    (@MvPolynomial.instCommRingMvPolynomial Real
                      (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing)))))))
        (@MvPolynomial.X Real (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.instCommSemiring
          (@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
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@instHMul
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (@Distrib.toMul
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@NonUnitalNonAssocSemiring.toDistrib
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@NonUnitalNonAssocCommSemiring.toNonUnitalNonAssocSemiring
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@NonUnitalNonAssocCommRing.toNonUnitalNonAssocCommSemiring
                    (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                      Real.instCommSemiring)
                    (@NonUnitalCommRing.toNonUnitalNonAssocCommRing
                      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                        Real.instCommSemiring)
                      (@CommRing.toNonUnitalCommRing
                        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                          Real.instCommSemiring)
                        (@MvPolynomial.instCommRingMvPolynomial Real
                          (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing))))))))
          (@OfNat.ofNat
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (nat_lit 2)
            (@instOfNatAtLeastTwo
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (nat_lit 2)
              (@AddMonoidWithOne.toNatCast
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@AddGroupWithOne.toAddMonoidWithOne
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@Ring.toAddGroupWithOne
                    (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                      Real.instCommSemiring)
                    (@CommRing.toRing
                      (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                        Real.instCommSemiring)
                      (@MvPolynomial.instCommRingMvPolynomial Real
                        (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing)))))
              (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))
          (@MvPolynomial.X Real (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.instCommSemiring
            (@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
        (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
        (nat_lit 1)
        (@One.toOfNat1
          (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
          (@AddMonoidWithOne.toOne
            (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
            (@AddGroupWithOne.toAddMonoidWithOne
              (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real Real.instCommSemiring)
              (@Ring.toAddGroupWithOne
                (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                  Real.instCommSemiring)
                (@CommRing.toRing
                  (@MvPolynomial (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real
                    Real.instCommSemiring)
                  (@MvPolynomial.instCommRingMvPolynomial Real
                    (Fin (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))) Real.commRing)))))))))

∀ a : ℝ, MvPolynomial.eval (fun n : Fin 2 => if (n = 0) then (Int.floor a : ℝ) else (Int.floor (2 * a))) answer = 0


Find all positive integers $n,k_1,\dots,k_n$ such that $k_1+\cdots+k_n=5n-4$ and $\frac{1}{k_1}+\cdots+\frac{1}{k_n}=1$.

@Eq (Set (Prod Nat (Nat → Int))) answer
  (@setOf (Prod Nat (Nat → Int)) fun (x : Prod Nat (Nat → Int)) =>
    _example.match_1 (fun (x_1 : Prod Nat (Nat → Int)) => Prop) x fun (n : Nat) (k : Nat → Int) =>
      Or
        (And (@Eq Nat n (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
          (@Eq Int (k (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))
            (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1)))))
        (Or
          (And (@Eq Nat n (@OfNat.ofNat Nat (nat_lit 3) (instOfNatNat (nat_lit 3))))
            (@Eq (Set Int)
              (@Set.image Nat Int k
                (@Insert.insert Nat (Set Nat) (@Set.instInsert Nat)
                  (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))
                  (@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 2) (instOfNatNat (nat_lit 2)))))))
              (@Insert.insert Int (Set Int) (@Set.instInsert Int)
                (@OfNat.ofNat Int (nat_lit 2) (@instOfNat (nat_lit 2)))
                (@Insert.insert Int (Set Int) (@Set.instInsert Int)
                  (@OfNat.ofNat Int (nat_lit 3) (@instOfNat (nat_lit 3)))
                  (@Singleton.singleton Int (Set Int) (@Set.instSingletonSet Int)
                    (@OfNat.ofNat Int (nat_lit 6) (@instOfNat (nat_lit 6))))))))
          (And (@Eq Nat n (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))
            (∀ (i : Fin (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4)))),
              @Eq Int (k (@Fin.val (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))) i))
                (@OfNat.ofNat Int (nat_lit 4) (@instOfNat (nat_lit 4)))))))

{((n : ℕ), (k : ℕ → ℤ)) | (n > 0) ∧ (∀ i ∈ Finset.range n, k i > 0) ∧ (∑ i in Finset.range n, k i = 5 * n - 4) ∧ (∑ i : Finset.range n, (1 : ℝ) / (k i) = 1)} = answer


Find all differentiable functions $f:(0,\infty) \to (0,\infty)$ for which there is a positive real number $a$ such that $f'(\frac{a}{x})=\frac{x}{f(x)}$ for all $x>0$.

the set of functions $f$ such that $f(x) = c x^d$ for some $c > 0$ and $d > 0$, with $d = 1$ implying $c = 1$

Show that the functions are precisely $f(x)=cx^d$ for $c,d>0$ arbitrary except that we must take $c=1$ in case $d=1$.

@Eq (Set (Real → Real)) answer
  (@setOf (Real → Real) fun (f_1 : Real → Real) =>
    @Exists Real fun (c : Real) =>
      And (@GT.gt Real Real.instLT c (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))
        (@Exists Real fun (d : Real) =>
          And (@GT.gt Real Real.instLT d (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))
            (And
              (@Eq Real d (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)) →
                @Eq Real c (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
              (@Set.EqOn Real Real f_1
                (fun (x : Real) =>
                  @HMul.hMul Real Real Real (@instHMul Real Real.instMul) c
                    (@HPow.hPow Real Real Real (@instHPow Real Real Real.instPow) x d))
                (@Set.Ioi Real Real.instPreorder
                  (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero)))))))

(∃ a > 0, ∀ x > 0, deriv f (a / x) = x / f x) ↔ f ∈ answer


Find the volume of the region of points $(x,y,z)$ such that
\[
(x^2 + y^2 + z^2 + 8)^2 \leq 36(x^2 + y^2).
\]

@Eq Real answer
  (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
    (@OfNat.ofNat Real (nat_lit 6)
      (@instOfNatAtLeastTwo Real (nat_lit 6) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))))
    (@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)))))


Let $S=\{1,2,\dots,n\}$ for some integer $n>1$. Say a permutation $\pi$ of $S$ has a \emph{local maximum} at $k \in S$ if
\begin{enumerate}
\item[(i)] $\pi(k)>\pi(k+1)$ for $k=1$;
\item[(ii)] $\pi(k-1)<\pi(k)$ and $\pi(k)>\pi(k+1)$ for $1<k<n$;
\item[(iii)] $\pi(k-1)<\pi(k)$ for $k=n$.
\end{enumerate}
(For example, if $n=5$ and $\pi$ takes values at $1,2,3,4,5$ of $2,1,4,5,3$, then $\pi$ has a local maximum of 2 at $k=1$, and a local maximum of 5 at $k=4$.) What is the average number of local maxima of a permutation of $S$, averaging over all permutations of $S$?

Show that the average number of local maxima is $\frac{n+1}{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) (@Nat.cast Real Real.instNatCast n_1)
      (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
    (@OfNat.ofNat Real (nat_lit 3)
      (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))

hpnat

∀ p : Equiv.Perm (Fin n), ∀ k : Fin n, (pnat p) k = p k

hpcount

∀ p : Equiv.Perm (Fin n), pcount p = {k : Fin n | (k.1 = 0 ∨ (pnat p) (k - 1) < (pnat p) k) ∧ (k = n - 1 ∨ (pnat p) k > (pnat p) (k + 1))}.encard

(∑ p : Equiv.Perm (Fin n), pcount p) / {p : Equiv.Perm (Fin n) | true}.ncard = answer n


Let $n$ be a positive odd integer and let $\theta$ be a real number such that $\theta/\pi$ is irrational. Set $a_k=\tan(\theta+k\pi/n)$, $k=1,2,\dots,n$. Prove that $\frac{a_1+a_2+\cdots+a_n}{a_1a_2 \cdots a_n}$ is an integer, and determine its value.

(fun n : ℕ => if (n ≡ 1 [MOD 4]) then n else -n)

Show that $\frac{a_1+\cdots+a_n}{a_1 \cdots a_n}=\begin{cases} n & n \equiv 1 \pmod{4} \\ -n & n \equiv 3 \pmod{4}. \end{cases}$

@Eq (Nat → Int) answer fun (n_1 : Nat) =>
  @ite Int
    (Nat.ModEq (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))) n_1
      (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
    (@Nat.instDecidableModEq (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))) n_1
      (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
    (@Nat.cast Int instNatCastInt n_1) (@Neg.neg Int Int.instNegInt (@Nat.cast Int instNatCastInt n_1))

ha

∀ k : Set.Icc 1 n, a k = Real.tan (theta + (k * Real.pi) / n)

(∑ k : Set.Icc 1 n, a k) / (∏ k : Set.Icc 1 n, a k) = answer n


Show that the curve $x^3 + 3xy + y^3 = 1$ contains only one set of three distinct points, $A$, $B$, and $C$, which are vertices of an equilateral triangle, and find its area.

Prove that the triangle has area $\frac{3 \sqrt 3}{2}$.

@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.sqrt
        (@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 2)
      (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))

hequilateral

∀ S, equilateral S ↔ S.encard = 3 ∧
  ∃ d : ℝ, ∀ P ∈ S, ∀ Q ∈ S, P ≠ Q →
    Real.sqrt ((P.1 - Q.1)^2 + (P.2 - Q.2)^2) = d

(∃! S : Set (ℝ × ℝ), S ⊆ curve ∧ equilateral S) ∧ (∃ S : Set (ℝ × ℝ), S ⊆ curve ∧ equilateral S ∧ (MeasureTheory.volume (convexHull ℝ S)).toReal = answer)


Let $S$ be a finite set of points in the plane. A linear partition of $S$ is an unordered pair $\{A,B\}$ of subsets of $S$ such that $A \cup B=S$, $A \cap B=\emptyset$, and $A$ and $B$ lie on opposite sides of some straight line disjoint from $S$ ($A$ or $B$ may be empty). Let $L_S$ be the number of linear partitions of $S$. For each positive integer $n$, find the maximum of $L_S$ over all sets $S$ of $n$ points.

Show that the maximum is $\binom{n}{2}+1$.

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

IsLinearPartition

Finset (Fin 2 → ℝ) → Finset (Finset (Fin 2 → ℝ)) → Prop

∀ S AB, IsLinearPartition S AB ↔
      (AB.card = 2 ∧ ∃ A ∈ AB, ∃ B ∈ AB,
        A ≠ B ∧ (A ∪ B = S) ∧ (A ∩ B = ∅) ∧
        (∃ m b : ℝ,
          (∀ p ∈ A, p 1 > m * p 0 + b) ∧
          (∀ p ∈ B, p 1 < m * p 0 + b)))

hL

∀ S, L S = {AB | IsLinearPartition S AB}.encard

IsGreatest {L S | (S) (hS : S.card = n)} (answer n)


Let $Z$ denote the set of points in $\mathbb{R}^n$ whose coordinates are $0$ or $1$. (Thus $Z$ has $2^n$ elements, which are the vertices of a unit hypercube in $\mathbb{R}^n$.) Given a vector subspace $V$ of $\mathbb{R}^n$, let $Z(V)$ denote the number of members of $Z$ that lie in $V$. Let $k$ be given, $0 \leq k \leq n$. Find the maximum, over all vector subspaces $V \subseteq \mathbb{R}^n$ of dimension $k$, of the number of points in $V \cap Z$.

@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 2) (instOfNatNat (nat_lit 2))) k_1

hZ

Z = {P : Fin n → ℝ | ∀ j : Fin n, P j = 0 ∨ P j = 1}

IsGreatest
      {y | ∃ V : Subspace ℝ (Fin n → ℝ), Module.rank ℝ V = k ∧ (Z ∩ V).ncard = y}
      (answer k)


For each continuous function $f: [0,1] \to \mathbb{R}$, let $I(f) = \int_0^1 x^2 f(x)\,dx$ and $J(x) = \int_0^1 x \left(f(x)\right)^2\,dx$. Find the maximum value of $I(f) - J(f)$ over all such functions $f$.

@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 16)
      (@instOfNatAtLeastTwo Real (nat_lit 16) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 14) (instOfNatNat (nat_lit 14)))))))

hI

I = fun f ↦ ∫ x in (0)..1, x ^ 2 * (f x)

hJ

J = fun f ↦ ∫ x in (0)..1, x * (f x) ^ 2

IsGreatest {y | ∃ f : ℝ → ℝ, ContinuousOn f (Icc 0 1) ∧ I f - J f = y} answer


Let $k$ be an integer greater than 1. Suppose $a_0 > 0$, and define \[ a_{n+1} = a_n + \frac{1}{\sqrt[k]{a_n}} \] for $n > 0$. Evaluate \[\lim_{n \to \infty} \frac{a_n^{k+1}}{n^k}.\]

Show that the solution is $(\frac{k+1}{k})^k$.

@Eq (Nat → Real) answer fun (k_1 : Nat) =>
  @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) (@Nat.cast Real Real.instNatCast k_1)
        (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
      (@Nat.cast Real Real.instNatCast k_1))
    k_1

Tendsto (fun n => (a n)^(k+1)/(n ^ k)) atTop (𝓝 (answer k))


Find all values of $\alpha$ for which the curves $y = \alpha*x^2 + \alpha*x + 1/24$ and $x = \alpha*y^2 + \alpha*y + 1/24$ are tangent to each other.

@Eq (Set Real) answer
  (@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 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)))))))
    (@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 3)
          (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 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)))))))
      (@Insert.insert Real (Set Real) (@Set.instInsert Real)
        (@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 13)
              (@instOfNatAtLeastTwo Real (nat_lit 13) Real.instNatCast
                (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 11) (instOfNatNat (nat_lit 11))))))
            (Real.sqrt
              (@OfNat.ofNat Real (nat_lit 601)
                (@instOfNatAtLeastTwo Real (nat_lit 601) Real.instNatCast
                  (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 599) (instOfNatNat (nat_lit 599))))))))
          (@OfNat.ofNat Real (nat_lit 12)
            (@instOfNatAtLeastTwo Real (nat_lit 12) Real.instNatCast
              (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 10) (instOfNatNat (nat_lit 10)))))))
        (@Singleton.singleton Real (Set Real) (@Set.instSingletonSet Real)
          (@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 13)
                (@instOfNatAtLeastTwo Real (nat_lit 13) Real.instNatCast
                  (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 11) (instOfNatNat (nat_lit 11))))))
              (Real.sqrt
                (@OfNat.ofNat Real (nat_lit 601)
                  (@instOfNatAtLeastTwo Real (nat_lit 601) Real.instNatCast
                    (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 599) (instOfNatNat (nat_lit 599))))))))
            (@OfNat.ofNat Real (nat_lit 12)
              (@instOfNatAtLeastTwo Real (nat_lit 12) Real.instNatCast
                (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 10) (instOfNatNat (nat_lit 10)))))))))))

∀ f, P f ↔ ∃ x y, f x = y ∧ f y = x ∧ deriv f x * deriv f y = 1


Find the least possible area of a convex set in the plane that intersects both branches of the hyperbola $xy=1$ and both branches of the hyperbola $xy=-1$. (A set $S$ in the plane is called \emph{convex} if for any two points in $S$ the line segment connecting them is contained in $S$.)

@Eq ENNReal answer
  (@OfNat.ofNat ENNReal (nat_lit 4)
    (@instOfNatAtLeastTwo ENNReal (nat_lit 4)
      (@AddMonoidWithOne.toNatCast ENNReal
        (@AddCommMonoidWithOne.toAddMonoidWithOne ENNReal instENNRealAddCommMonoidWithOne))
      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))


Let $k$ be a positive integer. Suppose that the integers $1, 2, 3, \dots, 3k+1$ are written down in random order. What is the probability that at no time during this process, the sum of the integers that have been written up to that time is a positive integer divisible by $3$? Your answer should be in closed form, but may include factorials.

Prove that the desired probability is $\frac{k!(k+1)!}{(3k+1)(2k)!}$.

@Eq (Nat → Rat) answer fun (k_1 : Nat) =>
  @HDiv.hDiv Rat Rat Rat (@instHDiv Rat Rat.instDiv)
    (@HMul.hMul Rat Rat Rat (@instHMul Rat Rat.instMul) (@Nat.cast Rat Rat.instNatCast (Nat.factorial k_1))
      (@Nat.cast Rat Rat.instNatCast
        (Nat.factorial
          (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat) k_1
            (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))))
    (@HMul.hMul Rat Rat Rat (@instHMul Rat Rat.instMul)
      (@HAdd.hAdd Rat Rat Rat (@instHAdd Rat Rat.instAdd)
        (@HMul.hMul Rat Rat Rat (@instHMul Rat Rat.instMul) (@OfNat.ofNat Rat (nat_lit 3) (@Rat.instOfNat (nat_lit 3)))
          (@Nat.cast Rat Rat.instNatCast k_1))
        (@OfNat.ofNat Rat (nat_lit 1) (@Rat.instOfNat (nat_lit 1))))
      (@Nat.cast Rat Rat.instNatCast
        (Nat.factorial
          (@HMul.hMul Nat Nat Nat (@instHMul Nat instMulNat) (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
            k_1))))

hgoodperms

goodperms = {f ∈ perms | ¬∃ j : Fin (3 * k + 1), 3 ∣ ∑ i : Fin (3 * k + 1), ite (i ≤ j) (f i) 0}

goodperms.ncard = perms.ncard * (answer k)


A \emph{repunit} is a positive integer whose digits in base 10 are all ones. Find all polynomials $f$ with real coefficients such that if $n$ is a repunit, then so is $f(n)$.

the set of polynomials of the form $f(n) = \frac{1}{9} \left(10^c (9n + 1)^d - 1\right)$ where $d \in \mathbb{N}$ and $c \geq 1 - d$

Show that the desired polynomials $f$ are those of the form
\[
f(n) = \frac{1}{9}(10^c (9n+1)^d - 1)
\]
for integers $d \geq 0$ and $c \geq 1-d$.

@Eq (Set (@Polynomial Real Real.semiring)) answer
  (@setOf (@Polynomial Real Real.semiring) fun (f : @Polynomial Real Real.semiring) =>
    @Exists Nat fun (d : Nat) =>
      @Exists Int fun (c : Int) =>
        And
          (@GE.ge Int Int.instLEInt c
            (@HSub.hSub Int Int Int (@instHSub Int Int.instSub) (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1)))
              (@Nat.cast Int instNatCastInt d)))
          (∀ (n : Real),
            @Eq Real (@Polynomial.eval Real Real.semiring n f)
              (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
                (@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 9)
                    (@instOfNatAtLeastTwo Real (nat_lit 9) Real.instNatCast
                      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 7) (instOfNatNat (nat_lit 7)))))))
                (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
                  (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
                    (@HPow.hPow Real Int Real (@instHPow Real Int (@DivInvMonoid.toZPow Real Real.instDivInvMonoid))
                      (@OfNat.ofNat Real (nat_lit 10)
                        (@instOfNatAtLeastTwo Real (nat_lit 10) Real.instNatCast
                          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 8) (instOfNatNat (nat_lit 8))))))
                      c)
                    (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
                      (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
                        (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
                          (@OfNat.ofNat Real (nat_lit 9)
                            (@instOfNatAtLeastTwo Real (nat_lit 9) Real.instNatCast
                              (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 7) (instOfNatNat (nat_lit 7))))))
                          n)
                        (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
                      d))
                  (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne))))))

hrepunit

∀ x, repunit x ↔ x > 0 ∧ x = floor x ∧ ∀ d ∈ (digits 10 (floor x)), d = 1

hS

∀ f, f ∈ S ↔ (∀ n : ℝ, repunit n → repunit (f.eval n))


Let $x_0 = 1$ and for $n \geq 0$, let $x_{n+1} = 3x_n + \lfloor x_n \sqrt{5} \rfloor$. In particular, $x_1 = 5$, $x_2 = 26$, $x_3 = 136$, $x_4 = 712$. Find a closed-form expression for $x_{2007}$. ($\lfloor a \rfloor$ means the largest integer $\leq a$.)

@Eq Real answer
  (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
    (@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))
        (@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 2006) (instOfNatNat (nat_lit 2006))))
      (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))))))))
    (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
      (@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
              (@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)))))))
        (@OfNat.ofNat Nat (nat_lit 3997) (instOfNatNat (nat_lit 3997))))
      (@HPow.hPow Real Int Real (@instHPow Real Int (@DivInvMonoid.toZPow Real Real.instDivInvMonoid))
        (@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
              (@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)))))))
        (@Neg.neg Int Int.instNegInt (@OfNat.ofNat Int (nat_lit 3997) (@instOfNat (nat_lit 3997)))))))

hx

∀ n : ℕ, x (n + 1) = 3 * (x n) + ⌊(x n) * Real.sqrt 5⌋


Let $n$ be a positive integer. Find the number of pairs $P, Q$ of polynomials with real coefficients such that
\[
(P(X))^2 + (Q(X))^2 = X^{2n} + 1
\]
and $\deg P > \deg Q$.

Show that the number of pairs is $2^{n+1}$.

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid))
    (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
    (@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat) n_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))

{a : (Polynomial ℝ) × (Polynomial ℝ) | a.1 ^ 2 + a.2 ^ 2 = Polynomial.X ^ (2 * n) + 1 ∧ a.1.degree > a.2.degree}.ncard = answer n


Define $f : \mathbb{R} \to \mathbb{R} by $f(x) = x$ if $x \leq e$ and $f(x) = x * f(\ln(x))$ if $x > e$. Does $\sum_{n=1}^{\infty} 1/(f(n))$ converge?

hf

f = fun x => if x ≤ Real.exp 1 then x else x * (f (Real.log x))

(∃ r : ℝ, Tendsto (fun N : ℕ => ∑ n in Finset.range N, 1/(f (n + 1))) atTop (𝓝 r)) ↔ answer


What is the maximum number of rational points that can lie on a circle in $\mathbb{R}^2$ whose center is not a rational point? (A \emph{rational point} is a point both of whose coordinates are rational numbers.)

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

∀ p : EuclideanSpace ℝ (Fin 2), is_rational_point p ↔ ∃ (a b : ℚ), a = p 0 ∧ b = p 1

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

∀ (c : EuclideanSpace ℝ (Fin 2)) (r : ℝ), real_circle c r = {p | dist p c = r}

IsGreatest {n : ℕ | ∃ (c : EuclideanSpace ℝ (Fin 2)) (r : ℝ), ¬ is_rational_point c ∧ (Set.ncard {p : EuclideanSpace ℝ (Fin 2) | p ∈ real_circle c r ∧ is_rational_point p} = n)} answer


Let $F_0(x)=\ln x$. For $n \geq 0$ and $x>0$, let $F_{n+1}(x)=\int_0^x F_n(t)\,dt$. Evaluate $\lim_{n \to \infty} \frac{n!F_n(1)}{\ln n}$.

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

hFn

∀ n : ℕ, ∀ x > 0, F (n + 1) x = ∫ t in Set.Ioo 0 x, F n t

Tendsto (fun n : ℕ => ((n)! * F n 1) / Real.log n) atTop (𝓝 answer)


What is the largest possible radius of a circle contained in a $4$-dimensional hypercube of side length $1$?

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

@Eq Real answer
  (@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)))))))

H = {P : Fin 4 → ℝ | ∀ i : Fin 4, |P i| ≤ 1 / 2}

∀ r, contains r ↔
      ∃ᵉ (A : AffineSubspace ℝ (EuclideanSpace ℝ (Fin 4))) (C ∈ A),
        Module.finrank ℝ A.direction = 2 ∧
        sphere C r ∩ A ⊆ H


Find all continuously differentiable functions f : \mathbb{R} \to \mathbb{R} such that for every rational number $q$, the number $f(q)$ is rational and has the same denominator as $q$.

Show that the solution is the set of all functions of the form n + x, n - x where n is any integer.

@Eq (Set (Real → Real)) answer
  (@Union.union (Set (Real → Real)) (@Set.instUnion (Real → Real))
    (@setOf (Real → Real) fun (x : Real → Real) =>
      @Exists Int fun (n : Int) =>
        @Eq (Real → Real)
          (fun (x_1 : Real) =>
            @HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd) x_1 (@Int.cast Real Real.instIntCast n))
          x)
    (@setOf (Real → Real) fun (x : Real → Real) =>
      @Exists Int fun (n : Int) =>
        @Eq (Real → Real)
          (fun (x_1 : Real) =>
            @HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd) (@Neg.neg Real Real.instNeg x_1)
              (@Int.cast Real Real.instIntCast n))
          x))

fqsat

(ℝ → ℝ) → ℚ → Prop

hfqsat

∀ f q, fqsat f q ↔ ContDiff ℝ 1 f ∧ (∃ p : ℚ, p = f q ∧ p.den = q.den)

∀ f : (ℝ → ℝ), (∀ q : ℚ, fqsat f q) ↔ f ∈ answer


Let $f$ be a real-valued function on the plane such that for every square $ABCD$ in the plane, $f(A)+f(B)+f(C)+f(D)=0$. Does it follow that $f(P)=0$ for all points $P$ in the plane?


Functions $f,g,h$ are differentiable on some open interval around $0$
and satisfy the equations and initial conditions
\begin{gather*}
f' = 2f^2gh+\frac{1}{gh},\quad f(0)=1, \\
g'=fg^2h+\frac{4}{fh}, \quad g(0)=1, \\
h'=3fgh^2+\frac{1}{fg}, \quad h(0)=1.
\end{gather*}
Find an explicit formula for $f(x)$, valid in some open interval around $0$.

@Eq (Real → Real) answer fun (x : Real) =>
  @HMul.hMul Real Real Real (@instHMul Real Real.instMul)
    (@HPow.hPow Real Real Real (@instHPow Real Real Real.instPow)
      (@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))
        (@Neg.neg Real Real.instNeg (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
        (@OfNat.ofNat Real (nat_lit 12)
          (@instOfNatAtLeastTwo Real (nat_lit 12) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 10) (instOfNatNat (nat_lit 10))))))))
    (@HPow.hPow Real Real Real (@instHPow Real Real Real.instPow)
      (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
        (Real.sin
          (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
            (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
              (@OfNat.ofNat Real (nat_lit 6)
                (@instOfNatAtLeastTwo Real (nat_lit 6) Real.instNatCast
                  (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))))
              x)
            (@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)))))))))
        (@HPow.hPow Real Nat Real (@instHPow Real Nat (@Monoid.toNatPow Real Real.instMonoid))
          (Real.cos
            (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
              (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
                (@OfNat.ofNat Real (nat_lit 6)
                  (@instOfNatAtLeastTwo Real (nat_lit 6) Real.instNatCast
                    (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))))
                x)
              (@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)))))))))
          (@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 1) (@One.toOfNat1 Real Real.instOne))
        (@OfNat.ofNat Real (nat_lit 6)
          (@instOfNatAtLeastTwo Real (nat_lit 6) Real.instNatCast
            (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))))))

hdiff

DifferentiableOn ℝ f (Ioo a b) ∧ DifferentiableOn ℝ g (Ioo a b) ∧ DifferentiableOn ℝ h (Ioo a b)

hg

(∀ x ∈ Ioo a b, deriv g x = (f x) * (g x)^2 * (h x) + 4 / ((f x) * (h x))) ∧ g 0 = 1

∃ c d : ℝ, 0 ∈ Ioo c d ∧ ∀ x ∈ Ioo c d, f x = answer x


Let $d_n$ be the determinant of the $n \times n$ matrix whose entries, from left to right and then from top to bottom, are $\cos 1, \cos 2, \dots, \cos n^2$. (For example,\[ d_3 = \left|\begin{matrix} \cos 1 & \cos 2 & \cos 3 \\ \cos 4 & \cos 5 & \cos 6 \\  \cos 7 & \cos 8 & \cos 9 \end{matrix} \right|. \]The argument of $\cos$ is always in radians, not degrees.) Evaluate $\lim_{n\to\infty} d_n$.

@Eq Real answer (@OfNat.ofNat Real (nat_lit 0) (@Zero.toOfNat0 Real Real.instZero))

hM

∀ n : ℕ, ∀ i j : Fin n, (cos_matrix n) i j = Real.cos (1 + n * i + j)

Tendsto (fun n => (cos_matrix n).det) atTop (𝓝 answer)


Let $S$ be a set of rational numbers such that
\begin{enumerate}
\item[(a)] $0 \in S$;
\item[(b)] If $x \in S$ then $x+1\in S$ and $x-1\in S$; and
\item[(c)] If $x\in S$ and $x\not\in\{0,1\}$, then $\frac{1}{x(x-1)}\in S$.
\end{enumerate}
Must $S$ contain all rational numbers?

Prove that $S$ need not contain all rationals.


Is there a finite abelian group $G$ such that the product of the orders of all its elements is 2^{2009}?

Show that the answer is no such finite abelian group exists.

answer ↔ (∃ (G : Type*) (_ : CommGroup G) (_ : Fintype G), ∏ g : G, orderOf g = 2^2009)


A game involves jumping to the right on the real number line. If $a$ and $b$ are real numbers and $b > a$, the cost of jumping from $a$ to $b$ is $b^3-ab^2$. For what real numbers $c$ can one travel from $0$ to $1$ in a finite number of jumps with total cost exactly $c$?

Prove that the possible costs are $1/3 < c \leq 1.$

@Eq (Set Real) answer
  (@Set.Ioc Real Real.instPreorder
    (@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 3)
        (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
          (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))))
    (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))

{c : ℝ | ∃ s : ℕ → ℝ, s 0 = 0 ∧ StrictMono s ∧ (∃ n : ℕ, s n = 1 ∧ ((∑ i in Finset.range n, ((s (i + 1)) ^ 3 - (s i) * (s (i + 1)) ^ 2)) = c))} = answer


Call a subset $S$ of $\{1, 2, \dots, n\}$ \emph{mediocre} if it has the following property: Whenever $a$ and $b$ are elements of $S$ whose average is an integer, that average is also an element of $S$. Let $A(n)$ be the number of mediocre subsets of $\{1,2,\dots,n\}$. [For instance, every subset of $\{1,2,3\}$ except $\{1,3\}$ is mediocre, so $A(3) = 7$.] Find all positive integers $n$ such that $A(n+2) - 2A(n+1) + A(n) = 1$.

Show that the answer is $n = 2^k - 1$ for some integer $k$.

@Eq (Set Int) answer
  (@setOf Int fun (n : Int) =>
    @Exists Nat fun (k : Nat) =>
      And (@GE.ge Nat instLENat k (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
        (@Eq Int n
          (@HSub.hSub Int Int Int (@instHSub Int Int.instSub)
            (@HPow.hPow Int Nat Int (@instHPow Int Nat (@Monoid.toNatPow Int Int.instMonoid))
              (@OfNat.ofNat Int (nat_lit 2) (@instOfNat (nat_lit 2))) k)
            (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1))))))

hmediocre

∀ n S, mediocre n S ↔ (S ⊆ Icc 1 n) ∧ ∀ a ∈ S, ∀ b ∈ S, 2 ∣ a + b → (a + b) / 2 ∈ S

hA

A = fun n ↦ ({S : Set ℤ | mediocre n S}.ncard : ℤ)


Say that a polynomial with real coefficients in two variables, $x,y$, is \emph{balanced} if the average value of the polynomial on each circle centered at the origin is $0$. The balanced polynomials of degree at most $2009$ form a vector space $V$ over $\mathbb{R}$. Find the dimension of $V$.

Prove that the dimension of $V$ is $2020050$.

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

∀ P, IsBalanced P ↔ ∀ r > 0,
      (∫ t in (0 : ℝ)..(2 * π), eval ![r * cos t, r * sin t] P) / (2 * π * r) = 0

∀ P, P ∈ V ↔ IsBalanced P ∧ P.totalDegree ≤ 2009


Given a positive integer $n$, what is the largest $k$ such that the numbers $1,2,\dots,n$ can be put into $k$ boxes so that the sum of the numbers in each box is the same? [When $n=8$, the example $\{1,2,3,6\},\{4,8\},\{5,7\}$ shows that the largest $k$ is \emph{at least} $3$.]

Show that the largest such $k$ is $\lceil \frac{n}{2} \rceil$.

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @Nat.ceil Real Real.orderedSemiring (@FloorRing.toFloorSemiring Real Real.instLinearOrderedRing Real.instFloorRing)
    (@HDiv.hDiv Real Real Real (@instHDiv Real (@DivInvMonoid.toDiv Real Real.instDivInvMonoid))
      (@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)))))))

hkboxes

∀ k : ℕ, kboxes k =
  (∃ boxes : Finset.Icc 1 n → Fin k, ∀ i j : Fin k,
    ∑ x in Finset.univ.filter (boxes · = i), (x : ℕ) =
    ∑ x in Finset.univ.filter (boxes · = j), (x : ℕ))


Find all differentiable functions $f:\mathbb{R} \to \mathbb{R}$ such that
\[
f'(x) = \frac{f(x+n)-f(x)}{n}
\]
for all real numbers $x$ and all positive integers $n$.

{f : ℝ → ℝ | ∃ c d : ℝ, ∀ x : ℝ, f x = c*x + d}

The solution consists of all functions of the form $f(x) = cx+d$ for some real numbers $c,d$.

@Eq (Set (Real → Real)) answer
  (@setOf (Real → Real) fun (f : Real → Real) =>
    @Exists Real fun (c : Real) =>
      @Exists Real fun (d : Real) =>
        ∀ (x : Real),
          @Eq Real (f x)
            (@HAdd.hAdd Real Real Real (@instHAdd Real Real.instAdd)
              (@HMul.hMul Real Real Real (@instHMul Real Real.instMul) c x) d))

{f : ℝ → ℝ | Differentiable ℝ f ∧
∀ x : ℝ, ∀ n : ℤ, n > 0 → deriv f x = (f (x + n) - f x)/n} = answer


Is there an infinite sequence of real numbers $a_1, a_2, a_3, \dots$ such that \[ a_1^m + a_2^m + a_3^m + \cdots = m \] for every positive integer $m$?

Show that the solution is no such infinite sequence exists.

answer = (∃ a : ℕ → ℝ, ∀ m : ℕ, m > 0 → ∑' i : ℕ, (a i)^m = m)


Given that $A$, $B$, and $C$ are noncollinear points in the plane with integer coordinates such that the distances $AB$, $AC$, and $BC$ are integers, what is the smallest possible value of $AB$?

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

hABCintcoords

∀ i : Fin 2, A i = round (A i) ∧ B i = round (B i) ∧ C i = round (C i)

hABCintdists

dist A B = round (dist A B) ∧ dist A C = round (dist A C) ∧ dist B C = round (dist B C)


There are $2010$ boxes labeled $B_1, B_2, \dots, B_{2010}$, and $2010n$ balls have been distributed among them, for some positive integer $n$. You may redistribute the balls by a sequence of moves, each of which consists of choosing an $i$ and moving \emph{exactly} $i$ balls from box $B_i$ into any one other box. For which values of $n$ is it possible to reach the distribution with exactly $n$ balls in each box, regardless of the initial distribution of balls?

Prove that it is possible if and only if $n \geq 1005$.

@Eq (Set Nat) answer
  (@Singleton.singleton Nat (Set Nat) (@Set.instSingletonSet Nat)
    (@OfNat.ofNat Nat (nat_lit 1005) (instOfNatNat (nat_lit 1005))))

htrans

∀ P T, trans P T ↔ ∀ t : ℕ, t < T → ∃ i j,
            i ≠ j ∧
            P t i ≥ i.1 + 1 ∧ P (t + 1) i = P t i - (i.1 + 1) ∧ P (t + 1) j = P t j + (i.1 + 1) ∧
            ∀ k : Fin 2010, k ≠ i → k ≠ j → P (t + 1) k = P t k

(∀ B, ∑ i, B i = 2010 * n → ∃ᵉ (P) (T), P 0 = B ∧ trans P T ∧ ∀ i, P T i = n) ↔ n ∈ answer


Find all pairs of polynomials $p(x)$ and $q(x)$ with real coefficients for which $p(x)q(x+1)-p(x+1)q(x)=1$.

{(p, q) : Polynomial ℝ × Polynomial ℝ | p.degree ≤ 1 ∧ q.degree ≤ 1 ∧ p.coeff 0 * q.coeff 1 - p.coeff 1 * q.coeff 0 = 1}

Show that the pairs $(p,q)$ satisfying the given equation are those of the form $p(x)=ax+b,q(x)=cx+d$ for $a,b,c,d \in \mathbb{R}$ such that $bc-ad=1$.

@Eq (Set (Prod (@Polynomial Real Real.semiring) (@Polynomial Real Real.semiring))) answer
  (@setOf (Prod (@Polynomial Real Real.semiring) (@Polynomial Real Real.semiring))
    fun (x : Prod (@Polynomial Real Real.semiring) (@Polynomial Real Real.semiring)) =>
    _example.match_1 (fun (x_1 : Prod (@Polynomial Real Real.semiring) (@Polynomial Real Real.semiring)) => Prop) x
      fun (p_1 q_1 : @Polynomial Real Real.semiring) =>
      And
        (@LE.le (WithBot Nat) (@Preorder.toLE (WithBot Nat) (@WithBot.preorder Nat Nat.instPreorder))
          (@Polynomial.degree Real Real.semiring p_1)
          (@OfNat.ofNat (WithBot Nat) (nat_lit 1)
            (@One.toOfNat1 (WithBot Nat) (@WithBot.one Nat (@AddMonoidWithOne.toOne Nat Nat.instAddMonoidWithOne)))))
        (And
          (@LE.le (WithBot Nat) (@Preorder.toLE (WithBot Nat) (@WithBot.preorder Nat Nat.instPreorder))
            (@Polynomial.degree Real Real.semiring q_1)
            (@OfNat.ofNat (WithBot Nat) (nat_lit 1)
              (@One.toOfNat1 (WithBot Nat) (@WithBot.one Nat (@AddMonoidWithOne.toOne Nat Nat.instAddMonoidWithOne)))))
          (@Eq Real
            (@HSub.hSub Real Real Real (@instHSub Real Real.instSub)
              (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
                (@Polynomial.coeff Real Real.semiring p_1 (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))
                (@Polynomial.coeff Real Real.semiring q_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))
              (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
                (@Polynomial.coeff Real Real.semiring p_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
                (@Polynomial.coeff Real Real.semiring q_1 (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))))))
            (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))))

(∀ x : ℝ, p.eval x * q.eval (x + 1) - p.eval (x + 1) * q.eval x = 1) ↔ (p, q) ∈ answer


Is there a strictly increasing function $f: \mathbb{R} \to \mathbb{R}$ such that $f'(x) = f(f(x))$ for all $x$?

Show that the solution is no such function exists.

(∃ f : ℝ → ℝ, StrictMono f ∧ Differentiable ℝ f ∧ (∀ x : ℝ, deriv f x = f (f x))) ↔ answer


Define a \emph{growing spiral} in the plane to be a sequence of points with integer coordinates $P_0=(0,0),P_1,\dots,P_n$ such that $n \geq 2$ and:
\begin{itemize}
\item the directed line segments $P_0P_1,P_1P_2,\dots,P_{n-1}P_n$ are in the successive coordinate directions east (for $P_0P_1$), north, west, south, east, etc.;
\item the lengths of these line segments are positive and strictly increasing.
\end{itemize}
How many of the points $(x,y)$ with integer coordinates $0 \leq x \leq 2011,0 \leq y \leq 2011$ \emph{cannot} be the last point, $P_n$ of any growing spiral?

Show that there are $10053$ excluded points.

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

{p | 0 ≤ p 0 ∧ p 0 ≤ 2011 ∧ 0 ≤ p 1 ∧ p 1 ≤ 2011 ∧ ¬∃ spiral, IsSpiral spiral ∧ spiral.getLast! = p}.encard = answer


Let $a_1,a_2,\dots$ and $b_1,b_2,\dots$ be sequences of positive real numbers such that $a_1 = b_1 = 1$ and $b_n = b_{n-1} a_n - 2$ for$n=2,3,\dots$. Assume that the sequence $(b_j)$ is bounded. Prove tha \[ S = \sum_{n=1}^\infty \frac{1}{a_1...a_n} \] converges, and evaluate $S$.

@Eq Real answer
  (@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 2)
      (@instOfNatAtLeastTwo Real (nat_lit 2) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0)))))))

Tendsto (fun n => ∑ i : Fin n, 1/(∏ j : Fin (i + 1), (a j))) atTop (𝓝 answer)


Find a real number $c$ and a positive number $L$ for which $\lim_{r \to \infty} \frac{r^c \int_0^{\pi/2} x^r\sin x\,dx}{\int_0^{\pi/2} x^r\cos x\,dx}=L$.

@Eq (Prod Real Real) answer
  (@Prod.mk Real Real (@Neg.neg Real Real.instNeg (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
    (@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))))))
      Real.pi))

Tendsto (fun r : ℝ => (r ^ c * ∫ x in Set.Ioo 0 (Real.pi / 2), x ^ r * Real.sin x) / (∫ x in Set.Ioo 0 (Real.pi / 2), x ^ r * Real.cos x)) atTop (𝓝 L)


For which positive integers $n$ is there an $n \times n$ matrix with integer entries such that every dot product of a row with itself is even, while every dot product of two different rows is odd?

@Eq (Set Nat) answer (@setOf Nat fun (n_1 : Nat) => @Odd Nat Nat.instSemiring n_1)

hnmat

∀ n, nmat n ↔
      ∃ A : Matrix (Fin n) (Fin n) ℤ,
        (∀ r, Even ((A r) ⬝ᵥ (A r))) ∧
        Pairwise fun r1 r2 ↦ Odd ((A r1) ⬝ᵥ (A r2))


Let $S$ be the set of all ordered triples $(p,q,r)$ of prime numbers for which at least one rational number $x$ satisfies $px^2+qx+r=0$. Which primes appear in seven or more elements of $S$?

Show that only the primes $2$ and $5$ appear seven or more times.

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

(t.Prime ∧ ({s ∈ S | ∃ i : Fin 3, s i = t}.encard ≥ 7)) ↔ t ∈ answer


Let $f$ and $g$ be (real-valued) functions defined on an open interval containing $0$, with $g$ nonzero and continuous at $0$. If $fg$ and $f/g$ are differentiable at $0$, must $f$ be differentiable at $0$?

DifferentiableAt ℝ (fun x ↦ f x * g x) 0

DifferentiableAt ℝ (fun x ↦ f x / g x) 0


Let $f: [-1, 1] \to \mathbb{R}$ be a continuous function such that
\begin{itemize}
\item[(i)]
$f(x) = \frac{2-x^2}{2} f \left( \frac{x^2}{2-x^2} \right)$ for every $x$ in $[-1, 1]$,
\item[(ii)]
$f(0) = 1$, and
\item[(iii)]
$\lim_{x \to 1^-} \frac{f(x)}{\sqrt{1-x}}$ exists and is finite.
\end{itemize}
Prove that $f$ is unique, and express $f(x)$ in closed form.

@Eq (Real → Real) answer fun (x : Real) =>
  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)) x
        (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))))

hfsat

fsat = fun f : ℝ → ℝ => ContinuousOn f S ∧
(∀ x ∈ S, f x = ((2 - x^2)/2)*f (x^2/(2 - x^2))) ∧ f 0 = 1 ∧
(∃ y : ℝ, leftLim (fun x : ℝ => (f x)/Real.sqrt (1 - x)) 1 = y)

fsat answer ∧ ∀ f : ℝ → ℝ, fsat f → ∀ x ∈ S, f x = answer x


Let $\FF_p$ denote the field of integers modulo a prime $p$, and let $n$ be a positive integer. Let $v$ be a fixed vector in $\FF_p^n$, let $M$ be an $n \times n$ matrix with entries of $\FF_p$, and define $G: \FF_p^n \to \FF_p^n$ by $G(x) = v + Mx$. Let $G^{(k)}$ denote the $k$-fold composition of $G$ with itself, that is, $G^{(1)}(x) = G(x)$ and $G^{(k+1)}(x) = G(G^{(k)}(x))$. Determine all pairs $p, n$ for which there exist $v$ and $M$ such that the $p^n$ vectors $G^{(k)}(0)$, $k=1,2,\dots,p^n$ are distinct.

Show that the solution is the pairs $(p,n)$ with $n = 1$ as well as the single pair $(2,2)$.

@Eq (Set (Prod Nat Nat)) answer
  (@Union.union (Set (Prod Nat Nat)) (@Set.instUnion (Prod Nat Nat))
    (@setOf (Prod Nat Nat) fun (q : Prod Nat Nat) =>
      _example.match_1 (fun (q_1 : Prod Nat Nat) => Prop) q fun (n_1 snd : Nat) =>
        @Eq Nat n_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
    (@Singleton.singleton (Prod Nat Nat) (Set (Prod Nat Nat)) (@Set.instSingletonSet (Prod Nat Nat))
      (@Prod.mk Nat Nat (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
        (@OfNat.ofNat Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))))

G

Matrix (Fin n) (Fin n) F → (Fin n → F) → (Fin n → F) → (Fin n → F)

(n, p) ∈ answer ↔
    ∃ᵉ (M : Matrix (Fin n) (Fin n) F) (v : (Fin n → F)),
      ¬(∃ i j : Finset.range (p^n), i ≠ j ∧ (G M v)^[i + 1] 0 = (G M v)^[j + 1] 0)


Let $f(x,y)$ be a continuous, real-valued function on $\mathbb{R}^2$. Suppose that, for every rectangular region $R$ of area $1$, the double integral of $f(x,y)$ over $R$ equals $0$.
Must $f(x,y)$ be identically $0$?

Prove that $f(x,y)$ must be identically $0$.

hp

∀ f, p f ↔
      Continuous f ∧
      ∀ x1 x2 y1 y2 : ℝ, x2 > x1 → y2 > y1
        → (x2 - x1) * (y2 - y1) = 1 → ∫ x in x1..x2, ∫ y in y1..y2, f (x, y) = 0


A round-robin tournament of $2n$ teams lasted for $2n-1$ days, as follows. On each day, every team played one game against another team, with one team winning and one team losing in each of the $n$ games. Over the course of the tournament, each team played every other team exactly once. Can one necessarily choose one winning team from each day without choosing any team more than once?

nmatchupsgames

(n : ℕ) → (Fin (2 * n - 1) → (Fin (2 * n) → Fin (2 * n))) → Prop

nmatchupswins

(n : ℕ) → (Fin (2 * n - 1) → (Fin (2 * n) → Fin (2 * n))) → (Fin (2 * n - 1) → (Fin (2 * n) → Bool)) → Prop

hnmatchupsall

∀ n matchups, nmatchupsall n matchups ↔ ∀ t1 t2, t1 ≠ t2 → (∃ d, matchups d t1 = t2)

hnmatchupsgames

∀ n matchups, nmatchupsgames n matchups ↔ ∀ d, ∀ t, matchups d t ≠ t ∧ matchups d (matchups d t) = t

hnmatchupswins

∀ n matchups wins, nmatchupswins n matchups wins ↔ ∀ d t, wins d t = !(wins d (matchups d t))

hnmatchupswinschoices

∀ n matchups wins, nmatchupswinschoices n matchups wins ↔ ∃ choices, (∀ d, wins d (choices d)) ∧ Function.Injective choices

(∀ n ≥ 1, ∀ matchups wins,
    (nmatchupsgames n matchups ∧ nmatchupsall n matchups ∧ nmatchupswins n matchups wins) →
    nmatchupswinschoices n matchups wins) ↔ answer


Suppose that $a_0 = 1$ and that $a_{n+1} = a_n + e^{-a_n}$ for $n=0,1,2,\dots$. Does $a_n - \log n$
have a finite limit as $n \to \infty$? (Here $\log n = \log_e n = \ln n$.)

Prove that the sequence has a finite limit.

open Matrix Function Real Topology Filter

(∃ L : ℝ, Tendsto (fun n ↦ a n - Real.log n) atTop (𝓝 L)) ↔ answer


For positive integers $n$, let the numbers $c(n)$ be determined by the rules $c(1)=1$, $c(2n)=c(n)$, and $c(2n+1)=(-1)^nc(n)$. Find the value of $\sum_{n=1}^{2013} c(n)c(n+2)$.

@Eq Int answer (@Neg.neg Int Int.instNegInt (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1))))

(∑ n : Set.Icc 1 2013, c n * c (n.1 + 2)) = answer


Let $C = \bigcup_{N=1}^\infty C_N$, where $C_N$ denotes the set of those `cosine polynomials' of the form
\[
f(x) = 1 + \sum_{n=1}^N a_n \cos(2 \pi n x)
\]
for which:
\begin{enumerate}
\item[(i)]
$f(x) \geq 0$ for all real $x$, and
\item[(ii)]
$a_n = 0$ whenever $n$ is a multiple of $3$.
\end{enumerate}
Determine the maximum value of $f(0)$ as $f$ ranges through $C$, and
prove that this maximum is attained.

@Eq Real answer
  (@OfNat.ofNat Real (nat_lit 3)
    (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
      (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))

CN

ℕ → Set (ℝ → ℝ)

hCN

∀ N : ℕ, CN N =
    {f : ℝ → ℝ |
      (∀ x : ℝ, f x ≥ 0) ∧
      ∃ a : List ℝ, a.length = N + 1 ∧ (∀ n : Fin (N + 1), 3 ∣ (n : ℕ) → a[n]! = 0) ∧
      ∀ x : ℝ, f x = 1 + ∑ n in Finset.Icc 1 N, a[(n : ℕ)]! * Real.cos (2*Real.pi*n*x)}

IsGreatest {f 0 | f ∈ ⋃ N ∈ Ici 1, CN N} answer


Let $A$ be the $n \times n$ matrix whose entry in the $i$-th row and $j$-th column is $\frac{1}{\min(i,j)}$ for $1 \leq i,j \leq n$. Compute $\det(A)$.

Show that the determinant is $\frac{(-1)^{n-1}}{(n-1)!n!}$.

@Eq (Nat → Real) answer fun (n_1 : Nat) =>
  @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))
      (@Neg.neg Real Real.instNeg (@OfNat.ofNat Real (nat_lit 1) (@One.toOfNat1 Real Real.instOne)))
      (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) n_1 (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))
    (@HMul.hMul Real Real Real (@instHMul Real Real.instMul)
      (@Nat.cast Real Real.instNatCast
        (Nat.factorial
          (@HSub.hSub Nat Nat Nat (@instHSub Nat instSubNat) n_1
            (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
      (@Nat.cast Real Real.instNatCast (Nat.factorial n_1)))


Let \( a_0 = \frac{5}{2} \) and \( a_k = a_{k-1}^2 - 2 \) for \( k \geq 1 \). Compute \( \prod_{k=0}^{\infty} \left(1 - \frac{1}{a_k}\right) \) in closed form.

@Eq Real answer
  (@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 7)
      (@instOfNatAtLeastTwo Real (nat_lit 7) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 5) (instOfNatNat (nat_lit 5)))))))

Tendsto (fun n : ℕ => ∏ k in Finset.range n, (1 - 1 / a k)) atTop (𝓝 answer)


Suppose $X$ is a random variable that takes on only nonnegative integer values, with $E\left[X\right]=1$, $E\left[X^2\right]=2$, and $E\left[X^3\right]=5$. (Here $E\left[Y\right]$ denotes the expectation of the random variable $Y$.) Determine the smallest possible value of the probability of the event $X=0$.

@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 3)
      (@instOfNatAtLeastTwo Real (nat_lit 3) Real.instNatCast
        (@instNatAtLeastTwo (@OfNat.ofNat Nat (nat_lit 1) (instOfNatNat (nat_lit 1)))))))

hXrandvar

Xrandvar = (fun X : ℕ → ℝ => (∀ n : ℕ, X n ∈ Set.Icc 0 1) ∧ ∑' n : ℕ, X n = 1)

E

(ℕ → ℝ) → (ℕ → ℝ) → ℝ

hE

E = (fun (X : ℕ → ℝ) (f : ℕ → ℝ) => ∑' n : ℕ, f n * X n)

sInf {X0 : ℝ | ∃ X : ℕ → ℝ, Xrandvar X ∧ E X (fun x : ℕ => x) = 1 ∧ E X (fun x : ℕ => x ^ 2) = 2 ∧ E X (fun x : ℕ => x ^ 3) = 5 ∧ X0 = X 0} = answer


Let \( n \) be a positive integer. What is the largest \( k \) for which there exist \( n \times n \) matrices \( M_1, \ldots, M_k \) and \( N_1, \ldots, N_k \) with real entries such that for all \( i \) and \( j \), the matrix product \( M_i N_j \) has a zero entry somewhere on its diagonal if and only if \( i \neq j \)?

Show that the solution has the form k \<= n ^ n.

@Eq (Nat → Nat) answer fun (n_1 : Nat) =>
  @HPow.hPow Nat Nat Nat (@instHPow Nat Nat (@Monoid.toNatPow Nat Nat.instMonoid)) n_1 n_1

hkex

∀ k ≥ 1, kex k = ∃ M N : Fin k → Matrix (Fin n) (Fin n) ℝ, ∀ i j : Fin k, ((∃ p : Fin n, (M i * N j) p p = 0) ↔ i ≠ j)

(answer n ≥ 1 ∧ kex (answer n)) ∧ (∀ k ≥ 1, kex k → k ≤ answer n)