How to resolve the algorithm Averages/Pythagorean means step by step in the E programming language

Published on 12 May 2024 09:40 PM
#E

How to resolve the algorithm Averages/Pythagorean means step by step in the E programming language

Table of Contents

Problem Statement

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Pythagorean means step by step in the E programming language

Source code in the e programming language

def makeMean(base, include, finish) {
    return def mean(numbers) {
        var count := 0
        var acc := base
        for x in numbers {
            acc := include(acc, x)
            count += 1
        }
        return finish(acc, count)
    }
}

def A := makeMean(0, fn b,x { b+x   }, fn acc,n { acc / n      })
def G := makeMean(1, fn b,x { b*x   }, fn acc,n { acc ** (1/n) })
def H := makeMean(0, fn b,x { b+1/x }, fn acc,n { n / acc      })

? A(1..10)
# value: 5.5

? G(1..10)
# value: 4.528728688116765

? H(1..10)
# value: 3.414171521474055

  

You may also check:How to resolve the algorithm Factorial step by step in the E programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the E programming language
You may also check:How to resolve the algorithm Stair-climbing puzzle step by step in the E programming language
You may also check:How to resolve the algorithm First-class functions step by step in the E programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the E programming language