# Numerical testing of Hardy's inequality

I want to check the following, Hardy's most fundamental inequality, by using Mathematica:

$$\sum_{n=1}^\infty \left(\frac{A_n}{n}\right)^p<\left(\frac{p}{p-1}\right)^p\sum_{n=1}^\infty a_n^p$$ where $p>1,$ $a_n\geq0$ and $A_n=a_1+a_2+\cdots+a_n$

I tried:

hardy[l_List, p_] := Module[{i, n = Length[l]},
Sum[(Sum[l[[i]], {i, n}]/n)^p, {n, 1, Infinity}] <
(p/(p - 1))^p Sum[l[[i]]^p, {n, 1, Infinity}]]

hardy[Table[1/n^2, {n, 1, Infinity}], 2]


but there is an error message.

I want to do something like this:

define random sequence randomSeq $a_n$, then

define

sum1[p_,randomSeq_]:=$\sum_{n=1}^\infty \left(\frac{A_n}{n}\right)^p$

sum2[p_,randomSeq_]:=$\left(\frac{p}{p-1}\right)^p\sum_{n=1}^\infty a_n^p$

then

Plot[{sum1[p,randomSeq], sum2[p,randomSeq]}, {p, 2, 100}]

• When you do Table[1/n^2, {n, 1, Infinity}] you are asking MMA to make an infinitely long array. It can't do that of course. You can try to take the difference between the LHS and RHS of the inequality and plot it for larger and larger a[n]-tables, and see whether it tends to something negative. – Marius Ladegård Meyer Jun 9 '16 at 21:19

Here's a solution if you're willing to truncate the infinite sums.

(* a deterministic random sequence... *)
a[n_] := a[n] = BlockRandom[SeedRandom[n]; RandomReal[]/n]

A[n_] := A[n] = Total[a /@ Range[n]]

lhs[p_?NumericQ, cap_] := Sum[(A[n]/n)^p, {n, 1, cap}]

rhs[p_?NumericQ, cap_] := (p/(p - 1))^p Sum[a[n]^p, {n, 1, cap}]

Plot[{lhs[p, 1000], rhs[p, 1000]}, {p, 1, 4}] 