text:
package org.hipparchus.special.elliptic.legendre;

import java.util.function.DoubleFunction;
import java.util.function.Function;

import org.hipparchus.CalculusFieldElement;
import org.hipparchus.analysis.CalculusFieldUnivariateFunction;
import org.hipparchus.complex.Complex;
import org.hipparchus.complex.ComplexUnivariateIntegrator;
import org.hipparchus.complex.FieldComplex;
import org.hipparchus.complex.FieldComplexUnivariateIntegrator;
import org.hipparchus.special.elliptic.carlson.CarlsonEllipticIntegral;
import org.hipparchus.util.FastMath;
import org.hipparchus.util.MathUtils;

/** Complete and incomplete elliptic integrals in Legendre form.
 *

 * The elliptic integrals are related to Jacobi elliptic functions.
 *

 *

 * <emph>
 * BEWARE! Elliptic integrals for complex numbers in the incomplete case
 * are considered experimental for now, they have known issues:
 * issue 151
 * and issue 152.
 * </emph>
 *

 *

 * There are different conventions to interpret the arguments of
 * Legendre elliptic integrals. In mathematical texts, these conventions show
 * up using the separator between arguments. So for example for the incomplete
 * integral of the first kind F we have:
 *

 *
F(φ, k): the first argument φ is an angle and the second argument k
 *       is the elliptic modulus: this is the trigonometric form of the integral

 *
F(φ; m): the first argument φ is an angle and the second argument m=k²
 *       is the parameter: this is also a trigonometric form of the integral

 *
F(x|m): the first argument x=sin(φ) is not an angle anymore and the
 *       second argument m=k² is the parameter: this is the Legendre form

 *
F(φ\α): the first argument φ is an angle and the second argument α is the
 *       modular angle

 *

 * As we have no separator in a method call, we have to adopt one convention
 * and stick to it. In Hipparchus, we adopted the Legendre form (i.e. F(x|m),
 * with x=sin(φ) and m=k². These conventions are consistent with Wolfram Alpha
 * functions EllipticF, EllipticE, ElliptiPI…
 *

 * @see Elliptic Integrals (Wikipedia)
 * @see Complete Elliptic Integrals of the First Kind (MathWorld)
 * @see Complete Elliptic Integrals of the Second Kind (MathWorld)
 * @see Elliptic Integrals of the First Kind (MathWorld)
 * @see Elliptic Integrals of the Second Kind (MathWorld)
 * @see Elliptic Integrals of the Third Kind (MathWorld)
 * @since 2.0
 */
public class LegendreEllipticIntegral {

    /** Private constructor for a utility class.
     */
    private LegendreEllipticIntegral() {
        // nothing to do
    }

    /** Get the nome q.
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return nome q
     */
    public static double nome(final double m) {
        if (m < 1.0e-16) {
            // first terms of infinite series in Abramowitz and Stegun 17.3.21
            final double m16 = m * 0.0625;
            return m16 * (1 + 8 * m16);
        } else {
            return FastMath.exp(-FastMath.PI * bigKPrime(m) / bigK(m));
        }
    }

    /** Get the nome q.
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return nome q
     */
    public static <T extends CalculusFieldElement<T>> T nome(final T m) {
        final T one = m.getField().getOne();
        if (m.norm() < 100 * one.ulp().getReal()) {
            // first terms of infinite series in Abramowitz and Stegun 17.3.21
            final T m16 = m.multiply(0.0625);
            return m16.multiply(m16.multiply(8).add(1));
        } else {
            return FastMath.exp(bigKPrime(m).divide(bigK(m)).multiply(one.getPi().negate()));
        }
    }

    /** Get the complete elliptic integral of the first kind K(m).
     *

     * The complete elliptic integral of the first kind K(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     * it corresponds to the real quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the first kind K(m)
     * @see #bigKPrime(double)
     * @see #bigF(double, double)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static double bigK(final double m) {
        if (m < 1.0e-8) {
            // first terms of infinite series in Abramowitz and Stegun 17.3.11
            return (1 + 0.25 * m) * MathUtils.SEMI_PI;
        } else {
            return CarlsonEllipticIntegral.rF(0, 1.0 - m, 1);
        }
    }

    /** Get the complete elliptic integral of the first kind K(m).
     *

     * The complete elliptic integral of the first kind K(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     * it corresponds to the real quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the first kind K(m)
     * @see #bigKPrime(CalculusFieldElement)
     * @see #bigF(CalculusFieldElement, CalculusFieldElement)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> T bigK(final T m) {
        final T zero = m.getField().getZero();
        final T one  = m.getField().getOne();
        if (m.norm() < 1.0e7 * one.ulp().getReal()) {

            // first terms of infinite series in Abramowitz and Stegun 17.3.11
            return one.add(m.multiply(0.25)).multiply(zero.getPi().multiply(0.5));

        } else {
            return CarlsonEllipticIntegral.rF(zero, one.subtract(m), one);
        }
    }

    /** Get the complete elliptic integral of the first kind K(m).
     *

     * The complete elliptic integral of the first kind K(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     * it corresponds to the real quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the first kind K(m)
     * @see #bigKPrime(Complex)
     * @see #bigF(Complex, Complex)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigK(final Complex m) {
        if (m.norm() < 1.0e-8) {
            // first terms of infinite series in Abramowitz and Stegun 17.3.11
            return Complex.ONE.add(m.multiply(0.25)).multiply(MathUtils.SEMI_PI);
        } else {
            return CarlsonEllipticIntegral.rF(Complex.ZERO, Complex.ONE.subtract(m), Complex.ONE);
        }
    }

    /** Get the complete elliptic integral of the first kind K(m).
     *

     * The complete elliptic integral of the first kind K(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     * it corresponds to the real quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the first kind K(m)
     * @see #bigKPrime(FieldComplex)
     * @see #bigF(FieldComplex, FieldComplex)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigK(final FieldComplex<T> m) {
        final FieldComplex<T> zero = m.getField().getZero();
        final FieldComplex<T> one  = m.getField().getOne();
        if (m.norm() < 1.0e7 * one.ulp().getReal()) {

            // first terms of infinite series in Abramowitz and Stegun 17.3.11
            return one.add(m.multiply(0.25)).multiply(zero.getPi().multiply(0.5));

        } else {
            return CarlsonEllipticIntegral.rF(zero, one.subtract(m), one);
        }
    }

    /** Get the complete elliptic integral of the first kind K'(m).
     *

     * The complete elliptic integral of the first kind K'(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-(1-m) \sin^2\theta}}
     * \]
     * it corresponds to the imaginary quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the first kind K'(m)
     * @see #bigK(double)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static double bigKPrime(final double m) {
        return CarlsonEllipticIntegral.rF(0, m, 1);
    }

    /** Get the complete elliptic integral of the first kind K'(m).
     *

     * The complete elliptic integral of the first kind K'(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-(1-m) \sin^2\theta}}
     * \]
     * it corresponds to the imaginary quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the first kind K'(m)
     * @see #bigK(CalculusFieldElement)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> T bigKPrime(final T m) {
        final T zero = m.getField().getZero();
        final T one  = m.getField().getOne();
        return CarlsonEllipticIntegral.rF(zero, m, one);
    }

    /** Get the complete elliptic integral of the first kind K'(m).
     *

     * The complete elliptic integral of the first kind K'(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-(1-m) \sin^2\theta}}
     * \]
     * it corresponds to the imaginary quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the first kind K'(m)
     * @see #bigK(Complex)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigKPrime(final Complex m) {
        return CarlsonEllipticIntegral.rF(Complex.ZERO, m, Complex.ONE);
    }

    /** Get the complete elliptic integral of the first kind K'(m).
     *

     * The complete elliptic integral of the first kind K'(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-(1-m) \sin^2\theta}}
     * \]
     * it corresponds to the imaginary quarter-period of Jacobi elliptic functions
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the first kind K'(m)
     * @see #bigK(FieldComplex)
     * @see Complete Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigKPrime(final FieldComplex<T> m) {
        final FieldComplex<T> zero = m.getField().getZero();
        final FieldComplex<T> one  = m.getField().getOne();
        return CarlsonEllipticIntegral.rF(zero, m, one);
    }

    /** Get the complete elliptic integral of the second kind E(m).
     *

     * The complete elliptic integral of the second kind E(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the second kind E(m)
     * @see #bigE(double, double)
     * @see Complete Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static double bigE(final double m) {
        return CarlsonEllipticIntegral.rG(0, 1 - m, 1) * 2;
    }

    /** Get the complete elliptic integral of the second kind E(m).
     *

     * The complete elliptic integral of the second kind E(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the second kind E(m)
     * @see #bigE(CalculusFieldElement, CalculusFieldElement)
     * @see Complete Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> T bigE(final T m) {
        final T zero = m.getField().getZero();
        final T one  = m.getField().getOne();
        return CarlsonEllipticIntegral.rG(zero, one.subtract(m), one).multiply(2);
    }

    /** Get the complete elliptic integral of the second kind E(m).
     *

     * The complete elliptic integral of the second kind E(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the second kind E(m)
     * @see #bigE(Complex, Complex)
     * @see Complete Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigE(final Complex m) {
        return CarlsonEllipticIntegral.rG(Complex.ZERO,
                                          Complex.ONE.subtract(m),
                                          Complex.ONE).multiply(2);
    }

    /** Get the complete elliptic integral of the second kind E(m).
     *

     * The complete elliptic integral of the second kind E(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the second kind E(m)
     * @see #bigE(FieldComplex, FieldComplex)
     * @see Complete Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigE(final FieldComplex<T> m) {
        final FieldComplex<T> zero = m.getField().getZero();
        final FieldComplex<T> one  = m.getField().getOne();
        return CarlsonEllipticIntegral.rG(zero, one.subtract(m), one).multiply(2);
    }

    /** Get the complete elliptic integral D(m) = [K(m) - E(m)]/m.
     *

     * The complete elliptic integral D(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral D(m)
     * @see #bigD(double, double)
     */
    public static double bigD(final double m) {
        return CarlsonEllipticIntegral.rD(0, 1 - m, 1) / 3;
    }

    /** Get the complete elliptic integral D(m) = [K(m) - E(m)]/m.
     *

     * The complete elliptic integral D(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral D(m)
     * @see #bigD(CalculusFieldElement, CalculusFieldElement)
     */
    public static <T extends CalculusFieldElement<T>> T bigD(final T m) {
        final T zero = m.getField().getZero();
        final T one  = m.getField().getOne();
        return CarlsonEllipticIntegral.rD(zero, one.subtract(m), one).divide(3);
    }

    /** Get the complete elliptic integral D(m) = [K(m) - E(m)]/m.
     *

     * The complete elliptic integral D(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral D(m)
     * @see #bigD(Complex, Complex)
     */
    public static Complex bigD(final Complex m) {
        return CarlsonEllipticIntegral.rD(Complex.ZERO, Complex.ONE.subtract(m), Complex.ONE).divide(3);
    }

    /** Get the complete elliptic integral D(m) = [K(m) - E(m)]/m.
     *

     * The complete elliptic integral D(m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral D(m)
     * @see #bigD(FieldComplex, FieldComplex)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigD(final FieldComplex<T> m) {
        final FieldComplex<T> zero = m.getField().getZero();
        final FieldComplex<T> one  = m.getField().getOne();
        return CarlsonEllipticIntegral.rD(zero, one.subtract(m), one).divide(3);
    }

    /** Get the complete elliptic integral of the third kind Π(n, m).
     *

     * The complete elliptic integral of the third kind Π(n, m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the third kind Π(n, m)
     * @see #bigPi(double, double, double)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static double bigPi(final double n, final double m) {
        final double kPrime2 = 1 - m;
        final double delta   = n * (m - n) * (n - 1);
        return CarlsonEllipticIntegral.rF(0, kPrime2, 1) +
               CarlsonEllipticIntegral.rJ(0, kPrime2, 1, 1 - n, delta) * n / 3;
    }

    /** Get the complete elliptic integral of the third kind Π(n, m).
     *

     * The complete elliptic integral of the third kind Π(n, m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the third kind Π(n, m)
     * @see #bigPi(CalculusFieldElement, CalculusFieldElement, CalculusFieldElement)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> T bigPi(final T n, final T m) {
        final T zero    = m.getField().getZero();
        final T one     = m.getField().getOne();
        final T kPrime2 = one.subtract(m);
        final T delta   = n.multiply(m.subtract(n)).multiply(n.subtract(1));
        return CarlsonEllipticIntegral.rF(zero, kPrime2, one).
               add(CarlsonEllipticIntegral.rJ(zero, kPrime2, one, one.subtract(n), delta).multiply(n).divide(3));
    }

    /** Get the complete elliptic integral of the third kind Π(n, m).
     *

     * The complete elliptic integral of the third kind Π(n, m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return complete elliptic integral of the third kind Π(n, m)
     * @see #bigPi(Complex, Complex, Complex)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigPi(final Complex n, final Complex m) {
        final Complex kPrime2 = Complex.ONE.subtract(m);
        final Complex delta   = n.multiply(m.subtract(n)).multiply(n.subtract(1));
        return CarlsonEllipticIntegral.rF(Complex.ZERO, kPrime2, Complex.ONE).
               add(CarlsonEllipticIntegral.rJ(Complex.ZERO, kPrime2, Complex.ONE, Complex.ONE.subtract(n), delta).multiply(n).divide(3));
    }

    /** Get the complete elliptic integral of the third kind Π(n, m).
     *

     * The complete elliptic integral of the third kind Π(n, m) is
     * \[
     *    \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return complete elliptic integral of the third kind Π(n, m)
     * @see #bigPi(FieldComplex, FieldComplex, FieldComplex)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigPi(final FieldComplex<T> n, final FieldComplex<T> m) {
        final FieldComplex<T> zero    = m.getField().getZero();
        final FieldComplex<T> one     = m.getField().getOne();
        final FieldComplex<T> kPrime2 = one.subtract(m);
        final FieldComplex<T> delta   = n.multiply(m.subtract(n)).multiply(n.subtract(1));
        return CarlsonEllipticIntegral.rF(zero, kPrime2, one).
               add(CarlsonEllipticIntegral.rJ(zero, kPrime2, one, one.subtract(n), delta).multiply(n).divide(3));
    }

    /** Get the incomplete elliptic integral of the first kind F(φ, m).
     *

     * The incomplete elliptic integral of the first kind F(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral of the first kind F(φ, m)
     * @see #bigK(double)
     * @see Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static double bigF(final double phi, final double m) {

        // argument reduction
        final DoubleArgumentReduction ar = new DoubleArgumentReduction(phi, m, n -> bigK(n));

        // integrate part between 0 and π/2
        final double cM1 = ar.csc2 - 1.0;
        final double cMm = ar.csc2 - m;
        final double incomplete =  CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete - incomplete : ar.complete + incomplete;

    }

    /** Get the incomplete elliptic integral of the first kind F(φ, m).
     *

     * The incomplete elliptic integral of the first kind F(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the first kind F(φ, m)
     * @see #bigK(CalculusFieldElement)
     * @see Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> T bigF(final T phi, final T m) {

        // argument reduction
        final FieldArgumentReduction<T> ar = new FieldArgumentReduction<>(phi, m, n -> bigK(n));

        // integrate part between 0 and π/2
        final T cM1        = ar.csc2.subtract(1);
        final T cMm        = ar.csc2.subtract(m);
        final T incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the first kind F(φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the first kind F(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral of the first kind F(φ, m)
     * @see #bigK(Complex)
     * @see Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigF(final Complex phi, final Complex m) {

        // argument reduction
        final FieldArgumentReduction<Complex> ar = new FieldArgumentReduction<>(phi, m, n -> bigK(n));

        // integrate part between 0 and π/2
        final Complex cM1        = ar.csc2.subtract(1);
        final Complex cMm        = ar.csc2.subtract(m);
        final Complex incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the first kind F(φ, m) using numerical integration.
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the first kind F(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on numerical integration.
     * If integration path comes too close to a pole of the integrand, then integration will fail
     * with a {@link org.hipparchus.exception.MathIllegalStateException MathIllegalStateException}
     * even for very large {@code maxEval}. This is normal behavior.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param integrator integrator to use
     * @param maxEval maximum number of evaluations (real and imaginary
     * parts are evaluated separately, so up to twice this number may be used)
     * @return incomplete elliptic integral of the first kind F(φ, m)
     * @see #bigK(Complex)
     * @see Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigF(final Complex phi, final Complex m,
                               final ComplexUnivariateIntegrator integrator, final int maxEval) {
        return integrator.integrate(maxEval, new First<>(m), phi.getField().getZero(), phi);
    }

    /** Get the incomplete elliptic integral of the first kind F(φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the first kind F(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the first kind F(φ, m)
     * @see #bigK(CalculusFieldElement)
     * @see Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigF(final FieldComplex<T> phi, final FieldComplex<T> m) {

        // argument reduction
        final FieldArgumentReduction<FieldComplex<T>> ar = new FieldArgumentReduction<>(phi, m, n -> bigK(n));

        // integrate part between 0 and π/2
        final FieldComplex<T> cM1        = ar.csc2.subtract(1);
        final FieldComplex<T> cMm        = ar.csc2.subtract(m);
        final FieldComplex<T> incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the first kind F(φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the first kind F(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on numerical integration.
     * If integration path comes too close to a pole of the integrand, then integration will fail
     * with a {@link org.hipparchus.exception.MathIllegalStateException MathIllegalStateException}
     * even for very large {@code maxEval}. This is normal behavior.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param integrator integrator to use
     * @param maxEval maximum number of evaluations (real and imaginary
     * parts are evaluated separately, so up to twice this number may be used)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the first kind F(φ, m)
     * @see #bigK(CalculusFieldElement)
     * @see Elliptic Integrals of the First Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigF(final FieldComplex<T> phi, final FieldComplex<T> m,
                                                                           final FieldComplexUnivariateIntegrator<T> integrator,
                                                                           final int maxEval) {
        return integrator.integrate(maxEval, new First<>(m), phi.getField().getZero(), phi);
    }

    /** Get the incomplete elliptic integral of the second kind E(φ, m).
     *

     * The incomplete elliptic integral of the second kind E(φ, m) is
     * \[
     *    \int_0^{\phi} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral of the second kind E(φ, m)
     * @see #bigE(double)
     * @see Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static double bigE(final double phi, final double m) {

        // argument reduction
        final DoubleArgumentReduction ar = new DoubleArgumentReduction(phi, m, n -> bigE(n));

        // integrate part between 0 and π/2
        final double cM1        = ar.csc2 - 1.0;
        final double cMm        = ar.csc2 - m;
        final double incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2) -
                                  CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2) * (m / 3);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete - incomplete : ar.complete + incomplete;

    }

    /** Get the incomplete elliptic integral of the second kind E(φ, m).
     *

     * The incomplete elliptic integral of the second kind E(φ, m) is
     * \[
     *    \int_0^{\phi} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the second kind E(φ, m)
     * @see #bigE(CalculusFieldElement)
     * @see Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> T bigE(final T phi, final T m) {

        // argument reduction
        final FieldArgumentReduction<T> ar = new FieldArgumentReduction<>(phi, m, n -> bigE(n));

        // integrate part between 0 and π/2
        final T cM1        = ar.csc2.subtract(1);
        final T cMm        = ar.csc2.subtract(m);
        final T incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2).
                             subtract(CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2).multiply(m.divide(3)));

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the second kind E(φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the second kind E(φ, m) is
     * \[
     *    \int_0^{\phi} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral of the second kind E(φ, m)
     * @see #bigE(Complex)
     * @see Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigE(final Complex phi, final Complex m) {

        // argument reduction
        final FieldArgumentReduction<Complex> ar = new FieldArgumentReduction<>(phi, m, n -> bigE(n));

        // integrate part between 0 and π/2
        final Complex cM1        = ar.csc2.subtract(1);
        final Complex cMm        = ar.csc2.subtract(m);
        final Complex incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2).
                                   subtract(CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2).multiply(m.divide(3)));

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the second kind E(φ, m) using numerical integration.
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the second kind E(φ, m) is
     * \[
     *    \int_0^{\phi} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on numerical integration.
     * If integration path comes too close to a pole of the integrand, then integration will fail
     * with a {@link org.hipparchus.exception.MathIllegalStateException MathIllegalStateException}
     * even for very large {@code maxEval}. This is normal behavior.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param integrator integrator to use
     * @param maxEval maximum number of evaluations (real and imaginary
     * parts are evaluated separately, so up to twice this number may be used)
     * @return incomplete elliptic integral of the second kind E(φ, m)
     * @see #bigE(Complex)
     * @see Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigE(final Complex phi, final Complex m,
                               final ComplexUnivariateIntegrator integrator, final int maxEval) {
        return integrator.integrate(maxEval, new Second<>(m), phi.getField().getZero(), phi);
    }

    /** Get the incomplete elliptic integral of the second kind E(φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the second kind E(φ, m) is
     * \[
     *    \int_0^{\phi} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the second kind E(φ, m)
     * @see #bigE(FieldComplex)
     * @see Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigE(final FieldComplex<T> phi, final FieldComplex<T> m) {

        // argument reduction
        final FieldArgumentReduction<FieldComplex<T>> ar = new FieldArgumentReduction<>(phi, m, n -> bigE(n));

        // integrate part between 0 and π/2
        final FieldComplex<T> cM1        = ar.csc2.subtract(1);
        final FieldComplex<T> cMm        = ar.csc2.subtract(m);
        final FieldComplex<T> incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2).
                                           subtract(CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2).multiply(m.divide(3)));

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the second kind E(φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the second kind E(φ, m) is
     * \[
     *    \int_0^{\phi} \sqrt{1-m \sin^2\theta} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on numerical integration.
     * If integration path comes too close to a pole of the integrand, then integration will fail
     * with a {@link org.hipparchus.exception.MathIllegalStateException MathIllegalStateException}
     * even for very large {@code maxEval}. This is normal behavior.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param integrator integrator to use
     * @param maxEval maximum number of evaluations (real and imaginary
     * parts are evaluated separately, so up to twice this number may be used)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the second kind E(φ, m)
     * @see #bigE(FieldComplex)
     * @see Elliptic Integrals of the Second Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigE(final FieldComplex<T> phi, final FieldComplex<T> m,
                                                                           final FieldComplexUnivariateIntegrator<T> integrator,
                                                                           final int maxEval) {
        return integrator.integrate(maxEval, new Second<>(m), phi.getField().getZero(), phi);
    }

    /** Get the incomplete elliptic integral D(φ, m) = [F(φ, m) - E(φ, m)]/m.
     *

     * The incomplete elliptic integral D(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral D(φ, m)
     * @see #bigD(double)
     */
    public static double bigD(final double phi, final double m) {

        // argument reduction
        final DoubleArgumentReduction ar = new DoubleArgumentReduction(phi, m, n -> bigD(n));

        // integrate part between 0 and π/2
        final double cM1        = ar.csc2 - 1.0;
        final double cMm        = ar.csc2 - m;
        final double incomplete = CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2) / 3;

        // combine complete and incomplete parts
        return ar.negate ? ar.complete - incomplete : ar.complete + incomplete;

    }

    /** Get the incomplete elliptic integral D(φ, m) = [F(φ, m) - E(φ, m)]/m.
     *

     * The incomplete elliptic integral D(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral D(φ, m)
     * @see #bigD(CalculusFieldElement)
     */
    public static <T extends CalculusFieldElement<T>> T bigD(final T phi, final T m) {

        // argument reduction
        final FieldArgumentReduction<T> ar = new FieldArgumentReduction<>(phi, m, n -> bigD(n));

        // integrate part between 0 and π/2
        final T cM1        = ar.csc2.subtract(1);
        final T cMm        = ar.csc2.subtract(m);
        final T incomplete = CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2).divide(3);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral D(φ, m) = [F(φ, m) - E(φ, m)]/m.
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral D(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral D(φ, m)
     * @see #bigD(Complex)
     */
    public static Complex bigD(final Complex phi, final Complex m) {

        // argument reduction
        final FieldArgumentReduction<Complex> ar = new FieldArgumentReduction<>(phi, m, n -> bigD(n));

        // integrate part between 0 and π/2
        final Complex cM1        = ar.csc2.subtract(1);
        final Complex cMm        = ar.csc2.subtract(m);
        final Complex incomplete = CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2).divide(3);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral D(φ, m) = [F(φ, m) - E(φ, m)]/m.
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral D(φ, m) is
     * \[
     *    \int_0^{\phi} \frac{\sin^2\theta}{\sqrt{1-m \sin^2\theta}} d\theta
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral D(φ, m)
     * @see #bigD(CalculusFieldElement)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigD(final FieldComplex<T> phi, final FieldComplex<T> m) {

        // argument reduction
        final FieldArgumentReduction<FieldComplex<T>> ar = new FieldArgumentReduction<>(phi, m, n -> bigD(n));

        // integrate part between 0 and π/2
        final FieldComplex<T> cM1        = ar.csc2.subtract(1);
        final FieldComplex<T> cMm        = ar.csc2.subtract(m);
        final FieldComplex<T> incomplete = CarlsonEllipticIntegral.rD(cM1, cMm, ar.csc2).divide(3);

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the third kind Π(n, φ, m).
     *

     * The incomplete elliptic integral of the third kind Π(n, φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral of the third kind Π(n, φ, m)
     * @see #bigPi(double, double)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static double bigPi(final double n, final double phi, final double m) {

        // argument reduction
        final DoubleArgumentReduction ar = new DoubleArgumentReduction(phi, m, parameter -> bigPi(n, parameter));

        // integrate part between 0 and π/2
        final double cM1        = ar.csc2 - 1.0;
        final double cMm        = ar.csc2 - m;
        final double cMn        = ar.csc2 - n;
        final double delta      = n * (m - n) * (n - 1);
        final double incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2) +
                                  CarlsonEllipticIntegral.rJ(cM1, cMm, ar.csc2, cMn, delta) * n / 3;

        // combine complete and incomplete parts
        return ar.negate ? ar.complete - incomplete : ar.complete + incomplete;

    }

    /** Get the incomplete elliptic integral of the third kind Π(n, φ, m).
     *

     * The incomplete elliptic integral of the third kind Π(n, φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the third kind Π(n, φ, m)
     * @see #bigPi(CalculusFieldElement, CalculusFieldElement)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> T bigPi(final T n, final T phi, final T m) {

        // argument reduction
        final FieldArgumentReduction<T> ar = new FieldArgumentReduction<>(phi, m, parameter -> bigPi(n, parameter));

        // integrate part between 0 and π/2
        final T cM1        = ar.csc2.subtract(1);
        final T cMm        = ar.csc2.subtract(m);
        final T cMn        = ar.csc2.subtract(n);
        final T delta      = n.multiply(m.subtract(n)).multiply(n.subtract(1));
        final T incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2).
                             add(CarlsonEllipticIntegral.rJ(cM1, cMm, ar.csc2, cMn, delta).multiply(n).divide(3));

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the third kind Π(n, φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the third kind Π(n, φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @return incomplete elliptic integral of the third kind Π(n, φ, m)
     * @see #bigPi(Complex, Complex)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigPi(final Complex n, final Complex phi, final Complex m) {

        // argument reduction
        final FieldArgumentReduction<Complex> ar = new FieldArgumentReduction<>(phi, m, parameter -> bigPi(n, parameter));

        // integrate part between 0 and π/2
        final Complex cM1        = ar.csc2.subtract(1);
        final Complex cMm        = ar.csc2.subtract(m);
        final Complex cMn        = ar.csc2.subtract(n);
        final Complex delta      = n.multiply(m.subtract(n)).multiply(n.subtract(1));
        final Complex incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2).
                                   add(CarlsonEllipticIntegral.rJ(cM1, cMm, ar.csc2, cMn, delta).multiply(n).divide(3));

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the third kind Π(n, φ, m) using numerical integration.
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the third kind Π(n, φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on numerical integration.
     * If integration path comes too close to a pole of the integrand, then integration will fail
     * with a {@link org.hipparchus.exception.MathIllegalStateException MathIllegalStateException}
     * even for very large {@code maxEval}. This is normal behavior.
     *

     * @param n elliptic characteristic
     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param integrator integrator to use
     * @param maxEval maximum number of evaluations (real and imaginary
     * @return incomplete elliptic integral of the third kind Π(n, φ, m)
     * @see #bigPi(Complex, Complex)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static Complex bigPi(final Complex n, final Complex phi, final Complex m,
                                final ComplexUnivariateIntegrator integrator, final int maxEval) {
         return integrator.integrate(maxEval, new Third<>(n, m), phi.getField().getZero(), phi);
    }

    /** Get the incomplete elliptic integral of the third kind Π(n, φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the third kind Π(n, φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on {@link CarlsonEllipticIntegral
     * Carlson elliptic integrals}.
     *

     * @param n elliptic characteristic
     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the third kind Π(n, φ, m)
     * @see #bigPi(FieldComplex, FieldComplex)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigPi(final FieldComplex<T> n,
                                                                            final FieldComplex<T> phi,
                                                                            final FieldComplex<T> m) {

        // argument reduction
        final FieldArgumentReduction<FieldComplex<T>> ar = new FieldArgumentReduction<>(phi, m, parameter -> bigPi(n, parameter));

        // integrate part between 0 and π/2
        final FieldComplex<T> cM1        = ar.csc2.subtract(1);
        final FieldComplex<T> cMm        = ar.csc2.subtract(m);
        final FieldComplex<T> cMn        = ar.csc2.subtract(n);
        final FieldComplex<T> delta      = n.multiply(m.subtract(n)).multiply(n.subtract(1));
        final FieldComplex<T> incomplete = CarlsonEllipticIntegral.rF(cM1, cMm, ar.csc2).
                                           add(CarlsonEllipticIntegral.rJ(cM1, cMm, ar.csc2, cMn, delta).multiply(n).divide(3));

        // combine complete and incomplete parts
        return ar.negate ? ar.complete.subtract(incomplete) : ar.complete.add(incomplete);

    }

    /** Get the incomplete elliptic integral of the third kind Π(n, φ, m).
     *

     * <emph>
     * BEWARE! Elliptic integrals for complex numbers in the incomplete case
     * are considered experimental for now, they have known issues.
     * </emph>
     *

     *

     * The incomplete elliptic integral of the third kind Π(n, φ, m) is
     * \[
     *    \int_0^{\phi} \frac{d\theta}{\sqrt{1-m \sin^2\theta}(1-n \sin^2\theta)}
     * \]
     *

     *

     * The algorithm for evaluating the functions is based on numerical integration.
     * If integration path comes too close to a pole of the integrand, then integration will fail
     * with a {@link org.hipparchus.exception.MathIllegalStateException MathIllegalStateException}
     * even for very large {@code maxEval}. This is normal behavior.
     *

     * @param n elliptic characteristic
     * @param phi amplitude (i.e. upper bound of the integral)
     * @param m parameter (m=k² where k is the elliptic modulus)
     * @param integrator integrator to use
     * @param maxEval maximum number of evaluations (real and imaginary
     * parts are evaluated separately, so up to twice this number may be used)
     * @param <T> the type of the field elements
     * @return incomplete elliptic integral of the third kind Π(n, φ, m)
     * @see #bigPi(FieldComplex, FieldComplex)
     * @see Elliptic Integrals of the Third Kind (MathWorld)
     * @see Elliptic Integrals (Wikipedia)
     */
    public static <T extends CalculusFieldElement<T>> FieldComplex<T> bigPi(final FieldComplex<T> n,
                                                                            final FieldComplex<T> phi,
                                                                            final FieldComplex<T> m,
                                                                            final FieldComplexUnivariateIntegrator<T> integrator,
                                                                            final int maxEval) {
        return integrator.integrate(maxEval, new Third<>(n, m), phi.getField().getZero(), phi);
    }

    /** Argument reduction for an incomplete integral. */
    private static class DoubleArgumentReduction {

        /** Complete part. */
        private final double complete;

        /** Squared cosecant of the Jacobi amplitude. */
        private final double csc2;

        /** Indicator for negated Jacobi amplitude. */
        private boolean negate;

        /** Simple constructor.
         * @param phi amplitude (i.e. upper bound of the integral)
         * @param m parameter (m=k² where k is the elliptic modulus)
         * @param integral provider for complete integral
         */
        DoubleArgumentReduction(final double phi, final double m, final DoubleFunction<Double> integral) {
            final double sin = FastMath.sin(phi);
            final int    p   = (int) FastMath.rint(phi / FastMath.PI);
            complete         = p == 0 ? 0 : integral.apply(m) * 2 * p;
            negate           = sin < 0 ^ (p & 0x1) == 1;
            csc2             = 1.0 / (sin * sin);
        }

    }

    /** Argument reduction for an incomplete integral.
     * @param <T> type fo the field elements
     */
    private static class FieldArgumentReduction<T extends CalculusFieldElement<T>> {

        /** Complete part. */
        private final T complete;

        /** Squared cosecant of the Jacobi amplitude. */
        private final T csc2;

        /** Indicator for negated Jacobi amplitude. */
        private boolean negate;

        /** Simple constructor.
         * @param phi amplitude (i.e. upper bound of the integral)
         * @param m parameter (m=k² where k is the elliptic modulus)
         * @param integral provider for complete integral
         */
        FieldArgumentReduction(final T phi, final T m, final Function<T, T> integral) {
            final T   sin = FastMath.sin(phi);
            final int p   = (int) FastMath.rint(phi.getReal() / FastMath.PI);
            complete      = p == 0 ? phi.getField().getZero() : integral.apply(m).multiply(2 * p);
            negate        = sin.getReal() < 0 ^ (p & 0x1) == 1;
            csc2          = sin.multiply(sin).reciprocal();
        }

    }

    /** Integrand for elliptic integrals of the first kind.
     * @param <T> type of the field elements
     */
    private static class First<T extends CalculusFieldElement<T>> implements CalculusFieldUnivariateFunction<T> {

        /** Parameter. */
        private final T m;

        /** Simple constructor.
         * @param m parameter (m=k² where k is the elliptic modulus)
         */
        First(final T m) {
            this.m = m;
        }

        /** {@inheritDoc} */
        @Override
        public T value(final T theta) {
            final T sin  = theta.sin();
            final T sin2 = sin.multiply(sin);
            return sin2.multiply(m).negate().add(1).sqrt().reciprocal();
        }

    }

    /** Integrand for elliptic integrals of the second kind.
     * @param <T> type of the field elements
     */
    private static class Second<T extends CalculusFieldElement<T>> implements CalculusFieldUnivariateFunction<T> {

        /** Parameter. */
        private final T m;

        /** Simple constructor.
         * @param m parameter (m=k² where k is the elliptic modulus)
         */
        Second(final T m) {
            this.m = m;
        }

        /** {@inheritDoc} */
        @Override
        public T value(final T theta) {
            final T sin = theta.sin();
            final T sin2 = sin.multiply(sin);
            return sin2.multiply(m).negate().add(1).sqrt();
        }

    }

    /** Integrand for elliptic integrals of the second kind.
     * @param <T> type of the field elements
     */
    private static class Third<T extends CalculusFieldElement<T>> implements CalculusFieldUnivariateFunction<T> {

        /** Elliptic characteristic. */
        private final T n;

        /** Parameter. */
        private final T m;

        /** Simple constructor.
         * @param n elliptic characteristic
         * @param m parameter (m=k² where k is the elliptic modulus)
         */
        Third(final T n, final T m) {
            this.n = n;
            this.m = m;
        }

        /** {@inheritDoc} */
        @Override
        public T value(final T theta) {
            final T sin  = theta.sin();
            final T sin2 = sin.multiply(sin);
            final T d1   = sin2.multiply(m).negate().add(1).sqrt();
            final T da   = sin2.multiply(n).negate().add(1);
            return d1.multiply(da).reciprocal();
        }

    }
}


text:
<?php namespace Phonedotcom\Sdk\Models\Event\Log;

use Phonedotcom\Sdk\Models\Event\Log;

class SmsNewInboundEntry extends Log
{
    protected static $singleServiceType = 'sms.new.inbound';

    protected $staticRelationMap = [
        'sms' => 'Phonedotcom\Sdk\Models\Sms'
    ];
}

redpajama_set_name: RedPajamaGithub


text:
package v1

import (
	schedulingv1 "k8s.io/api/scheduling/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName is the group name use in this package
const GroupName = "scheduling.k8s.io"

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
	return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
	localSchemeBuilder = &schedulingv1.SchemeBuilder
	// AddToScheme applies all the stored functions to the scheme.
	AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
	// We only register manually written functions here. The registration of the
	// generated functions takes place in the generated files. The separation
	// makes the code compile even when the generated files are missing.
	localSchemeBuilder.Register(RegisterDefaults)
}


text:
<!DOCTYPE html>
<TITLE> QC sub-50004 recon_all </TITLE>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

        recon_all

View:

MNI_LM

MNI_surf_Ax

MNI_surf_Sag

MNI_surf_Cor

aseg_Ax

aseg_Sag

aseg_Cor

Index

QC sub-50004 recon_all

Midthickness Surfaces in MNI Space - with Automatic Parcellation (aparc)

White and Pial Surfaces in MNI Space

Freesurfer Automatic Segementation (aseg) in "Native" T1w Space

Midthickness Surfaces in "Native" T1w Space - with Automatic Parcellation (aparc)

White and Pial Surfaces in "Native" T1w Space

Freesurfer Curvature (curv) in "Native" T1w Space

Cortical Thickness in "Native" T1w Space


text:
'use strict';

angular.module('myApp.Beers.Service', [])
.service('BeerService', BeerService);

// Service
function BeerService($http) {
  var httpRequest = {
        url: 'http://localhost:3000/api/beers'
      , method: 'GET'
      }
    ;

  this.list = function(){
    return $http(httpRequest);
  }

};

// Injeção de dependências
BeerListController.$inject = ['$http'];


text:
package main

import (
	"github.com/patrobinson/go-fish/ruleHelpers"
	es "github.com/patrobinson/go-fish/testdata/eventStructs"
)

type aRule struct {
	rulehelpers.BasicRule
}

func (r *aRule) Process(thing interface{}) interface{} {
	foo, ok := thing.(es.ExampleType)
	if ok && foo.Str == "a" {
		return true
	}
	return false
}

func (r *aRule) String() string { return "aRule" }

var Rule aRule


text:
class Role < ApplicationRecord
  has_many :api_subject_roles, dependent: :destroy
  has_many :api_subjects, through: :api_subject_roles, dependent: :destroy

  has_many :subject_roles, dependent: :destroy
  has_many :subjects, through: :subject_roles, dependent: :destroy

  has_many :permissions, dependent: :destroy

  valhammer
end


text:
This directory contains an example web-application that can be deployed on Tomcat or another
J2EE app-server. It highlights several best practices, described [below](#features).

## Preparation

Start by editing `src/main/resources/log4j.properties`, adding your desired appenders to the
"com.kdgregory" logger configuration. For example, to enable CloudWatch Logs output:

```
log4j.logger.com.kdgregory=DEBUG, cloudwatch
```

If you enable Kinesis or SNS, you will also need to create the destinations; for CloudWatch
Logs the destination is auto-created. You can create them using the CloudFormation templates
[here](../cloudformation), manually, or by enabling the auto-create feature on the appenders.

> *BEWARE!* You will be charged for all AWS services used by this example. I have tried to keep
  the costs minimal, and some services (such as CloudWatch) may be covered under a free tier.
  However, *you are responsible for all charges*.

## Building and running the example

To build the example program, use Maven:

```
mvn clean package
```

This will produce a WAR in the `target` directory, which you can then deploy to Tomcat or
another application server (the WAR name starts with `log4j1-aws-appenders-webapp`, and
ends with the current library version number).

You can also run using the Jetty plugin:

```
mvn jetty:run
```

This runs the server in the current terminal, accepting requests at http://localhost:8080/.
All logging is sent to the terminal; note that Jetty has its own logging configuration,
which just prefixes messages with the logging level (eg, "INFO"). You won't see the webapp's
own logging until you invoke one of its operations.

## Features

### Use a Context Listener to initialize and shut down Log4J

A [context listener](https://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html)
provides a way for the application to set up and tear down its environment. The
[example listener](src/main/java/com/kdgregory/log4j/aws/example/ExampleContextListener.java)
does the following things:

* On initialization, look for an external Log4J configuration file

  While it's easy to include logging configuration in the JAR, as I do in this example,
  that is not necessarily a good idea because it means you have to rebuild and redeploy
  to change that configuration (for example, to enable debugging). A better approach is
  to store the logging configuration in an external file, which can be updated without
  a full redeploy.

  To support that use case, the example looks for a servlet initialization parameter
  named `log4j.config.location`. If it finds that parameter, and the parameter's value
  is a file on the filesystem, the context listener will initialize Log4J using that
  file. If the parameter isn't set, or doesn't point to a file, the application will
  fall back to using the compiled-in configuration.

* On termination, shut down Log4J

  As descriped in more detail [here](../../docs/tomcat.md), you must explicitly shut
  down Log4J when undeploying a web-application. If you don't then the writer thread
  will keep running, holding onto the old deployment, and Tomcat will eventually run
  out of memory.

### Track requests via the Mapped Diagnostic Context

When looking at a web-app's logs, it's extremely useful to isolate all messages that belong to
a single request. If you add a unique identifier to Log4J's mapped diagnostic context, this
will happen automatically.

An easy way to do this is with a [servlet filter](src/main/java/com/kdgregory/log4j/aws/example/RequestIdFilter.java):
when a request arrives the filter generates a UUID and stores it in the MDC; when the request
is done the filter removes the UUID from the MDC. Note that the filter checks the request's
dispatcher type: we want to generate an ID for initial requests, but reuse an existing ID
for forwards and includes that are triggered by the original request.

The filter also adds the UUID as a request attribute. In a micro-service architecture, you could
then add the attribute as a header for any subsidiary requests, and track its progress through
the various services that it calls. To do that, the filter would first look for the header, and
use its value rather than generate a UUID. And if you use an Application Load Balancer, you can
[configure it](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html)
to generate a unique ID for you when the request is first handled.


text:
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
RUN apt -y update && apt -y upgrade && \
    apt -y install build-essential git m4 scons zlib1g zlib1g-dev \
    libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev \
    python3-dev python-is-python3 doxygen libboost-all-dev \
    libhdf5-serial-dev python3-pydot libpng-dev libelf-dev pkg-config pip \
    python3-venv wget

RUN mkdir /systemc
WORKDIR /systemc
RUN wget https://www.accellera.org/images/downloads/standards/systemc/systemc-2.3.3.tar.gz; \
    tar xf systemc-2.3.3.tar.gz

WORKDIR /systemc/systemc-2.3.3
RUN mkdir objdir
WORKDIR objdir
ENV CXX="g++"
ENV CXXFLAGS="-std=c++17"

RUN ../configure --prefix=/opt/systemc
RUN make -j8 && make install
RUN make clean

WORKDIR /
RUN rm -rf /systemc/systemc-2.3.3/objdir


text:
package com.sdcuike.practice.type.handler;

import com.sdcuike.mybatis.type.EnumValueTypeHandler;
import com.sdcuike.practice.domain.CompanyType;
import org.apache.ibatis.type.MappedTypes;

/**
 * Created by beaver on 2017/4/19.
 */
@MappedTypes(CompanyType.class)
public class CompanyTypeTypeHandler extends EnumValueTypeHandler {
}


text:
    Stats

    Challenges

    Resources

    Job Board


text:
import * as Sentry from "@sentry/node";
import { IAccountDocument, MineSkinError } from "../typings";
import { AccountType } from "../typings/db/IAccountDocument";
import { GenerateType } from "../typings/db/ISkinDocument";
import { Discord, OWNER_CHANNEL, SUPPORT_CHANNEL } from "./Discord";
import { Email } from "./Email";
import { MineSkinMetrics } from "./metrics";

const ERROR_THRESHOLD = 3;

export class Notifications {

    protected static async sendEmailAndDiscord(account: IAccountDocument,
                                               simpleMessage: (account: IAccountDocument, email: boolean) => string,
                                               publicMessage: (account: IAccountDocument) => string,
                                               htmlMessage: (account: IAccountDocument) => string,
                                               subject: (account: IAccountDocument) => string) {
        if (account.discordUser && !account.discordMessageSent) {
            try {
                await Discord.sendDiscordDirectMessage(simpleMessage(account, false), account.discordUser, async () => {
                    if (publicMessage && (!account.sendEmails || !account.email)) {
                        await Discord.postDiscordMessage(publicMessage(account), OWNER_CHANNEL);

                        (await MineSkinMetrics.get()).accountNotifications
                            .tag('type', 'discord_public')
                            .tag('account', `${ account.id }`)
                            .tag('account_type', account.accountType || 'unknown')
                            .inc();
                    }
                });

                account.discordMessageSent = true;

                (await MineSkinMetrics.get()).accountNotifications
                    .tag('type', 'discord')
                    .tag('account', `${ account.id }`)
                    .tag('account_type', account.accountType || 'unknown')
                    .inc();
            } catch (e) {
                Sentry.captureException(e);
            }
        }
        if (account.sendEmails && account.email && !account.emailSent) {
            try {
                await Email.sendEmail(account.email, simpleMessage(account, true), htmlMessage(account), subject(account));

                account.emailSent = true;

                (await MineSkinMetrics.get()).accountNotifications
                    .tag('type', 'email')
                    .tag('account', `${ account.id }`)
                    .tag('account_type', account.accountType || 'unknown')
                    .inc();
            } catch (e) {
                Sentry.captureException(e);
            }
        }
    }

    protected static supportLink(email: boolean): string {
        return "For further assistance feel free to ask " + (email ? "on https://yeleha.co/discord" : "in <#" + SUPPORT_CHANNEL + ">") + " 🙂"
    }

    protected static accountInfo(acc: IAccountDocument, html: boolean): string {
        if (html) {
            return `

Affected Account: ${ acc.playername || acc.uuid } (${ acc.getEmail() })

Account Type: ${ acc.getAccountType() }

Last Error Code: ${ acc.lastErrorCode }

            `
        } else {
            return `
  Affected Account: ${ acc.playername || acc.uuid } (${ acc.getEmail() })
  Account Type: ${ acc.getAccountType() }
  Last Error Code: ${ acc.lastErrorCode }
            `
        }
    }

    protected static trimmedAccountInfo(acc: IAccountDocument): string {
        return "  Account (trimmed): " + (acc.playername || acc.uuid || "").substr(0, 4) + "\\*\\*\\*\\*\n";
    }

    protected static publicPrefix(acc: IAccountDocument): string {
        return `Hey <@${ acc.discordUser }>! I tried to send a private message but couldn't reach you :(\n`
    }

    static notifyMissingCredentials(account: IAccountDocument): void {
        // Log Channel
        Discord.postDiscordMessage("⚠ 👤 Account #" + account.id + " just lost its access token\n" +
            "  Current Server: " + account.lastRequestServer + "/" + account.requestServer + "\n" +
            "  Account Type: " + account.getAccountType() + "\n" +
            "  Current Success/Error: " + account.successCounter + "/" + account.errorCounter + "\n" +
            "  Total Success/Error: " + account.totalSuccessCounter + "/" + account.totalErrorCounter + "\n" +
            "  Account Added: " + new Date((account.timeAdded || 0) * 1000).toUTCString() + "\n" +
            "  Linked to " + account.email + "/<@" + account.discordUser + ">");

        if (account.errorCounter < ERROR_THRESHOLD) return;

        this.sendEmailAndDiscord(account,
            (acc, email) => `
Hi there!
This is an automated notification that MineSkin lost access to one of your accounts and has been disabled
${ this.accountInfo(acc, false) }

The account won't be used for skin generation until the issues are resolved.

It's recommended to check if Mojang/Microsoft is having issues. If that's the case, you're probably fine ignoring this message for the time being.
https://downdetector.com/status/minecraft/

Please log back in to your account at https://mineskin.org/account/minecraft?email=${account.email}

${ account.getAccountType() === AccountType.MICROSOFT ? "You should also check https://account.live.com/Activity" : "" }
${ this.supportLink(email) }
            `,
            acc => `
${ this.publicPrefix(acc) }
MineSkin just lost access to one of your accounts (${ acc.getAccountType() })\n
${ this.trimmedAccountInfo(acc) }
Please log back in at https://mineskin.org/account/minecraft\n
            `,
            acc => `

Hi there!

This is an automated notification that MineSkin lost access to one of your accounts and has been disabled

${ this.accountInfo(acc, true) }

The account won't be used for skin generation until the issues are resolved.

Please log back in to your account at mineskin.org/account

${ account.getAccountType() === AccountType.MICROSOFT ? "
You should also check account.live.com/Activity
" : "" }

${ this.supportLink(true) }

            `,
            acc => `MineSkin Notification ${ acc.playername || acc.uuid }`)
    }

    static notifyLoginFailed(account: IAccountDocument, err: MineSkinError): void {
        // Log channel
        Discord.postDiscordMessage("⚠ 👤 Account #" + account.id + " failed to login\n" +
            "  UUID: " + account.uuid + "\n" +
            "  Error: " + err.msg + "\n" +
            "  Current Server: " + account.lastRequestServer + "/" + account.requestServer + "\n" +
            "  Account Type: " + account.getAccountType() + "\n" +
            "  Total Success/Error: " + account.totalSuccessCounter + "/" + account.totalErrorCounter + "\n" +
            "  Account Added: " + new Date((account.timeAdded || 0) * 1000).toUTCString() + "\n" +
            "  Linked to " + account.email + "/<@" + account.discordUser + ">");

        this.sendEmailAndDiscord(account,
            (acc, email) => `
Hi there!
This is an automated notification that MineSkin just failed to login to your account
${ this.accountInfo(acc, false) }

The account won't be used for skin generation until the issues are resolved

Please try to login at https://www.minecraft.net/login and check if there are any issues with your account and then log back in to your account at https://mineskin.org/account?email=${account.email}

${ account.getAccountType() === AccountType.MICROSOFT ? "You should also check https://account.live.com/Activity" : "" }
${ this.supportLink(email) }
            `,
            acc => `
${ this.publicPrefix(acc) }
MineSkin just failed to login to one of your accounts (${ acc.getAccountType() })\n
${ this.trimmedAccountInfo(acc) }
Please log back in at https://mineskin.org/account/minecraft\n
            `,
            acc => `

Hi there!

This is an automated notification that MineSkin just failed to login to your account

${ this.accountInfo(acc, true) }

The account won't be used for skin generation until the issues are resolved.

Please try to login at minecraft.net and check if there are any issues with your account and then log back in to your account at mineskin.org/account

${ account.getAccountType() === AccountType.MICROSOFT ? "
You should also check account.live.com/Activity
" : "" }

${ this.supportLink(true) }

            `,
            acc => `MineSkin Notification ${ acc.playername || acc.uuid }`)
    }

    static notifyHighErrorCount(account: IAccountDocument, lastType: GenerateType, err: any): void {
        // Log channel
        Discord.postDiscordMessage("⚠ 👤 Account #" + account.id + " has " + account.errorCounter + " errors!\n" +
            "  Current Server: " + account.lastRequestServer + "/" + account.requestServer + "\n" +
            "  Account Type: " + account.getAccountType() + "\n" +
            "  Latest Type: " + lastType + "\n" +
            "  Latest Cause: " + (err.code || err.msg || "n/a") + "\n" +
            "  Total Success/Error: " + account.totalSuccessCounter + "/" + account.totalErrorCounter + "\n" +
            "  Total Success/Error: " + account.totalSuccessCounter + "/" + account.totalErrorCounter + "\n" +
            "  Account Added: " + new Date((account.timeAdded || 0) * 1000).toUTCString() + "\n" +
            "  Linked to " + account.email + "/<@" + account.discordUser + ">");

        if (account.errorCounter < ERROR_THRESHOLD) return;

        this.sendEmailAndDiscord(account,
            (acc, email) => `
Hi there!
This is an automated notification that one of your MineSkin accounts been disabled since it failed to properly generate skin data recently.
${ this.accountInfo(acc, false) }

The account won't be used for skin generation until the issues are resolved.

Please make sure the configured credentials & security questions are correct at https://mineskin.org/account?email=${account.email}

${ account.getAccountType() === AccountType.MICROSOFT ? "You should also check https://account.live.com/Activity" : "" }
${ this.supportLink(email) }
            `,
            acc => `
${ this.publicPrefix(acc) }
One of your accounts (${ acc.getAccountType() }) was just disabled since it failed to properly generate skin data recently.
${ this.trimmedAccountInfo(acc) }
Please log back in at https://mineskin.org/account/minecraft
            `,
            acc => `

Hi there!

This is an automated notification that one of your MineSkin accounts been disabled since it failed to properly generate skin data recently.

${ this.accountInfo(acc, true) }

The account won't be used for skin generation until the issues are resolved.

Please make sure the configured credentials & security questions are correct at mineskin.org/account

${ account.getAccountType() === AccountType.MICROSOFT ? "
You should also check account.live.com/Activity
" : "" }

${ this.supportLink(true) }

            `,
            acc => `MineSkin Notification ${ acc.playername || acc.uuid }`)
    }

}


text:
select c1.cohort_definition_id,
  814 as analysis_id,
  cast( '' as varchar(1) ) as stratum_1, cast( '' as varchar(1) ) as stratum_2, cast( '' as varchar(1) ) as stratum_3, cast( '' as varchar(1) ) as stratum_4,
  COUNT_BIG(o1.observation_id) as count_value
into #results_814
from
@CDM_schema.observation o1
inner join #HERACLES_cohort_subject c1
on o1.person_id = c1.subject_id
where o1.value_as_number is null
and o1.value_as_string is null
and o1.value_as_concept_id is null
group by c1.cohort_definition_id
;


text:
from b import bar

bar("5")


text:
CREATE TABLE LocValMap (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  loc varchar(256) not null,
  lat double not null,
  lng double not null,
  extrakey varchar(129),
  url varchar(256) not null,
  createdat date
);


text:
package net.clanwolf.c3.client.action;

public enum ACTIONS {
	APPLICATION_EXIT_REQUEST,
	APPLICATION_EXIT,
	APPLICATION_STARTUP,

	CURSOR_REQUEST_NORMAL,
	CURSOR_REQUEST_WAIT,

	SET_STATUS_TEXT,
	SET_CONSOLE_OPACITY,
	SET_CONSOLE_OUTPUT_LINE,

	CHANGE_LANGUAGE,

	ONLINECHECK_STARTED,
	ONLINECHECK_FINISHED,
	DATABASECONNECTIONCHECK_STARTED,
	DATABASECONNECTIONCHECK_FINISHED,
	LOGINCHECK_STARTED,
	LOGINCHECK_FINISHED,

	READY_TO_LOGIN,
	LOGGING_OFF,
	LOGGED_OFF_COMPLETE,
	LOGGED_OFF_AFTER_DOUBLE_LOGIN_COMPLETE,
	LOGGED_ON,
	LOGON_RUNNING,
	LOGON_FINISHED_SUCCESSFULL,
	LOGON_FINISHED_WITH_ERROR,

	MOUSE_MOVED,

	MUSIC_SELECTION_CHANGED,

	START_SPEECH_SPECTRUM,
	STOP_SPEECH_SPECTRUM,
	PANE_CREATION_BEGINS,
	PANE_CREATION_FINISHED,
	PANE_DESTRUCTION_FINISHED,
	PANE_DESTROY_CURRENT,

	SAVE_ROLEPLAY_STORY_OK,
	SAVE_ROLEPLAY_STORY_ERR,
	DELETE_ROLEPLAY_STORY_OK,
	DELETE_ROLEPLAY_STORY_ERR,
	GET_ROLEPLAY_ALLSTORIES,
	GET_ROLEPLAY_ALLCHARACTER,
	ROLEPLAY_NEXT_STEP,
	ROLEPLAY_NEXT_STEP_CHANGE_PANE,

	NOISE,
	ACTION_SUCCESSFULLY_EXECUTED,
	SHOW_MESSAGE,
	CURSOR_REQUEST_NORMAL_MESSAGE,
	CURSOR_REQUEST_WAIT_MESSAGE,
	SHOW_MESSAGE_WAS_ANSWERED,
	START_ROLEPLAY,

	NEW_UNIVERSE_RECEIVED;

	private ACTIONS() {
		// do nothing
	}

	public String getNameKey() {
		return "ACTIONS." + name() + ".name";
	}

	public String getToolTipKey() {
		return "ACTIONS." + name() + ".toolTip";
	}

	public String getDescriptionKey() {
		return "ACTIONS." + name() + ".description";
	}

	public String getAcceleratorKey() {
		return "ACTIONS." + name() + ".accelerator";
	}

	public String getMnemonicIndex() {
		return "ACTIONS." + name() + ".mnemonicIndex";
	}
}


text:
<?php

namespace Facebook\Libphutil;

/**
 * @group event
 */
abstract class PhutilEventConstants {

}


text:
; namespace DebugStub
; optionally exclude this serial version

; All information relating to our serial usage should be documented in this comment.
; http://wiki.osdev.org/Serial_ports
; We do not use IRQs for debugstub serial. This is becuase DebugStub (DS)
; MUST be:
; - As simple as possible
; - Interact as minimal as possible wtih normal Cosmos code because
; the debugstub must *always* work even if the normal code is fubarred
; The serial port that is used for DS should be 'hidden' from Cosmos main
; so that Cosmos main pretends it does not exist.
; IRQs would create a clash/mix of code.
; This does make the serial code in DebugStub inefficient, but its well worth
; the benefits received by following these rules.
; Baud rate is set to 115200. Likely our code could not exceed this rate
; anyways the way it is written and there are compatibility issues on some
; hardware above this rate.
; We assume a minimum level of a 16550A, which should be no problem on any
; common hardware today. VMWare emulates the 16550A
; We do not handle flow control for outbound data (DS --> DC).
; The DebugConnector (DC, the code in the Visual Studio side) however is threaded
; and easily should be able to receive data faster than we can send it.
; Most things are transactional with data being sent only when asked for, but
; with tracing we do send a data directly.
; Currently there is no inbound flow control either (DC --> DS)
; For now we assume all commands in bound are 16 bytes or less to ensure
; that they fit in the FIFO. Commands in DS must wait for a command ID ACK
; before sending another command.
; See notes in ProcessCommand.
; http://www.nondot.org/sabre/os/files/Communication/ser_port.txt

; //! %ifndef Exclude_IOPort_Based_SerialInit
%ifndef Exclude_IOPort_Based_SerialInit

; Todo Auto params
; Todo ebp frame ptr auto etc
; function InitSerial {
DebugStub_InitSerial:
	; Disable interrupts
  ; DX = 1
  Mov DX, 0x1
	; AL = 0
	Mov AL, 0x0
  ; WriteRegister()
  Call DebugStub_WriteRegister

	; Enable DLAB (set baud rate divisor)
	; DX = 3
	Mov DX, 0x3
	; AL = $80
	Mov AL, 0x80
	; WriteRegister()
	Call DebugStub_WriteRegister

	; 0x01, 0x00 - 115200
	; 0x02, 0x00 - 57600
	; 0x03, 0x00 - 38400
	; Set divisor (lo byte)
	; DX = 0
	Mov DX, 0x0
	; AL = $01
	Mov AL, 0x1
	; WriteRegister()
	Call DebugStub_WriteRegister

	; hi byte
	; DX = 1
	Mov DX, 0x1
	; AL = $00
	Mov AL, 0x0
	; WriteRegister()
	Call DebugStub_WriteRegister

	; 8N1
	; DX = 3
	Mov DX, 0x3
	; AL = $03
	Mov AL, 0x3
	; WriteRegister()
	Call DebugStub_WriteRegister

	; Enable FIFO, clear them
	; Set 14-byte threshold for IRQ.
	; We dont use IRQ, but you cant set it to 0
	; either. IRQ is enabled/disabled separately
  ; DX = 2
  Mov DX, 0x2
	; AL = $C7
	Mov AL, 0xC7
	; WriteRegister()
	Call DebugStub_WriteRegister

	; 0x20 AFE Automatic Flow control Enable - 16550 (VMWare uses 16550A) is most common and does not support it
	; 0x02 RTS
	; 0x01 DTR
	; Send 0x03 if no AFE
	; DX = 4
	Mov DX, 0x4
	; AL = $03
	Mov AL, 0x3
	; WriteRegister()
	Call DebugStub_WriteRegister
; }
DebugStub_InitSerial_Exit:
Mov DWORD [INTS_LastKnownAddress], DebugStub_InitSerial_Exit
Ret

; Modifies: AL, DX
; function ComReadAL {
DebugStub_ComReadAL:
	; DX = 5
	Mov DX, 0x5
; Wait:
DebugStub_ComReadAL_Wait:
    ; ReadRegister()
    Call DebugStub_ReadRegister
    ; AL test $01
    Test AL, 0x1
    ; if 0 goto Wait

	; DX = 0
	Mov DX, 0x0
  ; ReadRegister()
  Call DebugStub_ReadRegister
; }
DebugStub_ComReadAL_Exit:
Mov DWORD [INTS_LastKnownAddress], DebugStub_ComReadAL_Exit
Ret

; function ComWrite8 {
DebugStub_ComWrite8:
	; Input: ESI
	; Output: None
	; Modifies: EAX, EDX
	; Sends byte at [ESI] to com port and does esi + 1
	; This sucks to use the stack, but x86 can only read and write ports from AL and
	; we need to read a port before we can write out the value to another port.
	; The overhead is a lot, but compared to the speed of the serial and the fact
	; that we wait on the serial port anyways, its a wash.
	; This could be changed to use interrupts, but that then complicates
	; the code and causes interaction with other code. DebugStub should be
	; as isolated as possible from any other code.

	; Sucks again to use DX just for this, but x86 only supports
	; 8 bit address for literals on ports
	; DX = 5
	Mov DX, 0x5

	; Wait for serial port to be ready
	; Bit 5 (0x20) test for Transmit Holding Register to be empty.
; Wait:
DebugStub_ComWrite8_Wait:
    ; ReadRegister()
    Call DebugStub_ReadRegister
	  ; AL test $20
	  Test AL, 0x20
	  ; if 0 goto Wait

  ; Set address of port
	; DX = 0
	Mov DX, 0x0
	; Get byte to send
  ; AL = [ESI]
  Mov AL, BYTE [ESI]
	; Send the byte
	; WriteRegister()
	Call DebugStub_WriteRegister

	; ESI++
	Inc ESI
; }
DebugStub_ComWrite8_Exit:
Mov DWORD [INTS_LastKnownAddress], DebugStub_ComWrite8_Exit
Ret

; //! %endif
%endif


text:
export const PERMISSION_GRANTED = `granted`;
export const PERMISSION_DENIED = `denied`;

const browserUtilities = {
  PERMISSION_GRANTED,
  PERMISSION_DENIED,
  isBrowserHidden,
  isNotificationSupported,
  requestPermissionForNotifications,
  spawnNotification
};

/**
 * Returns true if the main browser window is hidden, minimized,
 * or in the background; false otherwise.
 *
 * @returns {boolean} hidden
 */
export function isBrowserHidden() {
  return document.webkitHidden || document.mozHidden || document.msHidden || document.hidden || !document.hasFocus();
}

/**
 * Checks if native browser notifications are supported
 *
 * @export
 * @returns {bool}
 */
export function isNotificationSupported() {
  return window && window.Notification;
}

export function requestPermissionForNotifications(callback) {
  return window.Notification.requestPermission(callback);
}

/**
 * Displays a browser notification and automatically closes after timeout
 *
 * @param {String} theBody body of the notification
 * @param {String} theIcon the url of the icon to display
 * @param {String} theTitle
 * @param {Integer} timeoutLength non-zero amount of time to display the notification
 *
 * @returns {Object} Browser notification object
 *
 */
export function spawnNotification(theBody, theIcon, theTitle, timeoutLength) {
  const options = {
    body: theBody,
    icon: theIcon
  };
  const browserNotification = new Notification(theTitle, options);
  if (timeoutLength) {
    setTimeout(() => {
      browserNotification.close();
    }, timeoutLength);
  }

  return browserNotification;
}

export default browserUtilities;


text:
/*
 * Module Name: afd main
 *
 * Filename: externs.h
 *
 * Abstract:
 *
 * Structures
 *
 */

extern VMAFD_GLOBALS gVmafdGlobals;

extern VECS_SRV_STORE_MAP gVecsGlobalStoreMap[64];


text:
describe Fastlane do
  describe Fastlane::FastFile do
    describe "ensure_no_debug_code" do
      it "doesn't raise an exception if nothing was found" do
        result = Fastlane::FastFile.new.parse("lane :test do
          ensure_no_debug_code(text: 'pry', path: '.', extension: 'rb')
        end").runner.execute(:test)
        expect(result).to eq("grep -R 'pry' '#{File.absolute_path('../')}'")
      end
    end
  end
end