/*
 * Zorbage: an algebraic data hierarchy for use in numeric processing.
 *
 * Copyright (C) 2016-2020 Barry DeZonia
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package nom.bdezonia.zorbage.algorithm;

import nom.bdezonia.zorbage.algebra.Algebra;
import nom.bdezonia.zorbage.algebra.Multiplication;
import nom.bdezonia.zorbage.datasource.IndexedDataSource;

/**
 * 
 * @author Barry DeZonia
 *
 */
public class GeometricMean {

	// https://mathworld.wolfram.com/GeometricMean.html
	
	/**
	 * 
	 * @param alg
	 * @param list
	 * @param result
	 */
	public static <T extends Algebra<T,U> & Multiplication<U>, U>
		void compute(T alg, IndexedDataSource<U> list, U result)
	{
		long sz = list.size();
		if (sz == 0) {
			alg.zero().call(result);
			return;
		}

		// TODO
		//U tmp = alg.construct();
		//Product.compute(alg, list, tmp);        // These two lines are a naive approach and may easily overflow
		//alg.nthRoot().call(sz, tmp, result);    // It may be best to use this with high prec algebras

		throw new UnsupportedOperationException("not yet implemented");
	}
}

@@ -1506,66 +1506,200 @@
 ra.A
-lgebra;%0Aimport nom.bdezonia.zorbage.algebra.Multiplication
+ddition;%0Aimport nom.bdezonia.zorbage.algebra.Algebra;%0Aimport nom.bdezonia.zorbage.algebra.Exponential;%0Aimport nom.bdezonia.zorbage.algebra.Invertible;%0Aimport nom.bdezonia.zorbage.algebra.Unity
 ;%0Aim
@@ -1989,22 +1989,60 @@
 %3E & 
-Multiplication
+Addition%3CU%3E & Unity%3CU%3E & Exponential%3CU%3E & Invertible
 %3CU%3E,
@@ -2196,28 +2196,18 @@
 %09%09%7D%0A
-%0A
 %09%09
-// TODO%0A%09%09//U tmp
+%0A%09%09U sum
  = a
@@ -2228,129 +2228,217 @@
 ;%0A%09%09
-//Product.compute(alg, list, tmp);        // These two lines are a naive approach and may easily overflow%0A%09%09//
+U count = alg.construct();%0A%09%09U value = alg.construct();%0A%09%09U one = alg.construct();%0A%09%09alg.unity().call(one);%0A%0A%09%09for (long i = 0; i %3C sz; i++) %7B%0A%09%09%09list.get(i, value);%0A%09%09%09alg.log().call(value, value);%0A%09%09%09
 alg.
-nthRoot
+add
 ().c
@@ -2446,146 +2446,143 @@
 ll(s
-z, tmp, result);    // It may be best to use this with high prec algebras%0A%0A%09%09throw new UnsupportedOperationException(%22not yet implemented%22
+um, value, sum);%0A%09%09%09alg.add().call(count, one, count);%0A%09%09%7D%0A%09%09%0A%09%09alg.divide().call(sum, count, value);%0A%09%09%0A%09%09alg.exp().call(value, result
 );%0A%09

Define an algorithm for computing the geometric mean