Task[edit]
Compute all three of the Pythagorean means of the set of integers 1 through 10 (inclusive).

Show that 



A
(

x

1


,
…
,

x

n


)
≥
G
(

x

1


,
…
,

x

n


)
≥
H
(

x

1


,
…
,

x

n


)


{\displaystyle A(x_{1},\ldots ,x_{n})\geq G(x_{1},\ldots ,x_{n})\geq H(x_{1},\ldots ,x_{n})}

 for this set of positive integers.

 The most common of the three means, the arithmetic mean, is the sum of the list divided by its length:
 



A
(

x

1


,
…
,

x

n


)
=




x

1


+
⋯
+

x

n



n




{\displaystyle A(x_{1},\ldots ,x_{n})={\frac {x_{1}+\cdots +x_{n}}{n}}}


 The geometric mean is the 



n


{\displaystyle n}

th root of the product of the list:
 



G
(

x

1


,
…
,

x

n


)
=




x

1


⋯

x

n




n





{\displaystyle G(x_{1},\ldots ,x_{n})={\sqrt[{n}]{x_{1}\cdots x_{n}}}}


 The harmonic mean is 



n


{\displaystyle n}

 divided by the sum of the reciprocal of each item in the list:
 



H
(

x

1


,
…
,

x

n


)
=


n



1

x

1




+
⋯
+


1

x

n









{\displaystyle H(x_{1},\ldots ,x_{n})={\frac {n}{{\frac {1}{x_{1}}}+\cdots +{\frac {1}{x_{n}}}}}}




See also
Tasks for calculating statistical measures



in one go
moving (sliding window)
moving (cumulative)

Mean
Arithmetic

Statistics/Basic
Averages/Arithmetic mean
Averages/Pythagorean means


Averages/Simple moving average




Geometric

Averages/Pythagorean means




Harmonic

Averages/Pythagorean means




Quadratic

Averages/Root mean square




Circular

Averages/Mean angle
Averages/Mean time of day




Median

Averages/Median




Mode

Averages/Mode




Standard deviation

Statistics/Basic



Cumulative standard deviation






 
#include <hopper.h>
 
/* An example of definitions in pseudo-natural language, with synonimous.
   These definitions can be inside a definition file (xxxx.h) */
#define getasinglelistof(_X_)   {_X_},
#synon  getasinglelistof        getalistof
#define integerrandomnumbers    _V1000_=-1,rand array(_V1000_),mulby(10),ceil,
#define randomnumbers           _V1000_=-1,rand array(_V1000_)
#define rememberitin(_X_)       _X_=0,cpy(_X_)
#synon  rememberitin            rememberthisnumbersin
#define rememberas(_X_)         mov(_X_)
#define remember(_X_)           {_X_}
//#synon  remember            with   ---> this exist in HOPPER.H
#defn   nowconsiderthis(_X_)    #ATOM#CMPLX,print
#synon  nowconsiderthis         nowconsider,considerthis,consider,nowputtext,puttext,andprint
#define andprintwithanewline    {"\n"}print
#synon  andprintwithanewline    printwithanewline
//#defn   andprint(_X_)           #ATOM#CMPLX,print
#define putanewline             {"\n"}
#define withanewline            "\n"
#define andprintit              print
#synon  andprintit              printit,andprint
#define showit                  show
#define afterdoingit            emptystack?,not,do{ {"I cannot continue due to retentive data "},throw(1001) }
#synon  afterdoingit            secondly,finally
#define then                    emptystack?do{ {"I cannot continue because data is missing "},throw(1000) }
/* why "#context" and not "#define"?
   becose "#context" need a value in the stack for continue. 
   Internally, "domeanit" tranform to "gosub(calculatearithmeticmean)",
   and "gosub" works only if it finds a data in the stack */
#context  calculatethegeometricmean
#synon    calculatethegeometricmean   calculategeometricmean,getgeometricmean
#context  calculatetheharmonicmean
#synon    calculatetheharmonicmean    calculateharmonicmean,getharmonicmean
#context  calculatearitmethicmean
#synon    calculatearitmethicmean     calculatesinglemean,calculatemean,domeanit
 
main:
  consider this ("Arithmetic Mean: ")
  get a list of '10,10' integer random numbers; remember this numbers in 'list of numbers';
  then, do mean it, and print with a new line.
  after doing it, consider ("Geometric Mean: "), remember 'list of numbers', calculate the geometric mean;
  then, put a new line, and print it.
  /*
       Okay. This can be a bit long, if we have to write the program;
       But what if we just had to talk, and the language interpreter takes care of the rest?
  */
  secondly, now consider ("Harmonic Mean: "), with 'list of numbers', get harmonic mean, and print with a new line.
  finally, put text ("Original Array:\n"), and print (list of numbers, with a new line)
exit(0)
.locals
calculate aritmethic mean:
  stats(MEAN)
back
calculate the geometric mean:
  stats(GEOMEAN)
back
calculatetheharmonicmean:
  stats(HARMEAN)
back
 