(original) (raw)

#!/usr/bin/env setl -- -- Averages/Pythagorean means in SETL. -- From -- http://rosettacode.org/wiki/Averages/Pythagorean\_means -- (edited) -- """ -- Compute all three of the Pythagorean means of the set of integers -- 1 through 10. -- Show that A(x1,..,xn) >= G(x1,..,xn) >= H(x1,..,x_n) for this set -- of positive integers. -- -- * A: The most common of the three means, the arithmetic mean, is the -- sum of the list divided by its length. -- -- * G: The geometric mean is the nth root of the product of the list. -- -- * H: The harmonic mean is n divided by the sum of the reciprocal -- of each item in the list. -- """ -- -- This SETL program was created by Hakan Kjellerstrand (hakank@bonetmail.com) -- Also see my SETL page: http://www.hakank.org/setl/ -- x := [1..10]; a := mean_A(x); g := mean_G(x); h := mean_H(x); print("A:", a,"G:", g,"H:", h); print(a >= g and g >= h); proc mean_A(x); return +/x/#x; end proc; proc mean_G(x); return (*/x)**(1/#x); end proc; proc mean_H(x); return #x/+/[1/i:i in x]; end proc;