2-ancestry mixing, negative discriminant

Percentage Accurate: 98.5% → 99.9%
Time: 5.9s
Alternatives: 4
Speedup: N/A×

Specification

?
\[\begin{array}{l} \\ 2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \end{array} \]
(FPCore (g h)
 :precision binary64
 (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
double code(double g, double h) {
	return 2.0 * cos((((2.0 * ((double) M_PI)) / 3.0) + (acos((-g / h)) / 3.0)));
}
public static double code(double g, double h) {
	return 2.0 * Math.cos((((2.0 * Math.PI) / 3.0) + (Math.acos((-g / h)) / 3.0)));
}
def code(g, h):
	return 2.0 * math.cos((((2.0 * math.pi) / 3.0) + (math.acos((-g / h)) / 3.0)))
function code(g, h)
	return Float64(2.0 * cos(Float64(Float64(Float64(2.0 * pi) / 3.0) + Float64(acos(Float64(Float64(-g) / h)) / 3.0))))
end
function tmp = code(g, h)
	tmp = 2.0 * cos((((2.0 * pi) / 3.0) + (acos((-g / h)) / 3.0)));
end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[(N[(2.0 * Pi), $MachinePrecision] / 3.0), $MachinePrecision] + N[(N[ArcCos[N[((-g) / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \end{array} \]
(FPCore (g h)
 :precision binary64
 (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
double code(double g, double h) {
	return 2.0 * cos((((2.0 * ((double) M_PI)) / 3.0) + (acos((-g / h)) / 3.0)));
}
public static double code(double g, double h) {
	return 2.0 * Math.cos((((2.0 * Math.PI) / 3.0) + (Math.acos((-g / h)) / 3.0)));
}
def code(g, h):
	return 2.0 * math.cos((((2.0 * math.pi) / 3.0) + (math.acos((-g / h)) / 3.0)))
function code(g, h)
	return Float64(2.0 * cos(Float64(Float64(Float64(2.0 * pi) / 3.0) + Float64(acos(Float64(Float64(-g) / h)) / 3.0))))
end
function tmp = code(g, h)
	tmp = 2.0 * cos((((2.0 * pi) / 3.0) + (acos((-g / h)) / 3.0)));
end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[(N[(2.0 * Pi), $MachinePrecision] / 3.0), $MachinePrecision] + N[(N[ArcCos[N[((-g) / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\end{array}

Alternative 1: 99.9% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\\ \sin \left(\pi \cdot 1.1666666666666667\right) \cdot \sin \left(\mathsf{fma}\left({\left({\pi}^{0.3333333333333333}\right)}^{2}, \frac{{\pi}^{0.3333333333333333}}{2}, 0.3333333333333333 \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right)\right)\right) - \left(\sin \left(\frac{t\_0}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{0.5}, {\pi}^{0.5}, t\_0\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \end{array} \end{array} \]
(FPCore (g h)
 :precision binary64
 (let* ((t_0 (acos (/ (* -1.0 g) h))))
   (-
    (*
     (sin (* PI 1.1666666666666667))
     (sin
      (fma
       (pow (pow PI 0.3333333333333333) 2.0)
       (/ (pow PI 0.3333333333333333) 2.0)
       (* 0.3333333333333333 (acos (/ (* g -1.0) h))))))
    (-
     (* (sin (/ t_0 3.0)) (sin (* 0.6666666666666666 PI)))
     (sin
      (/
       (fma (fma (* 2.0 (pow PI 0.5)) (pow PI 0.5) t_0) 2.0 (* 3.0 PI))
       6.0))))))
double code(double g, double h) {
	double t_0 = acos(((-1.0 * g) / h));
	return (sin((((double) M_PI) * 1.1666666666666667)) * sin(fma(pow(pow(((double) M_PI), 0.3333333333333333), 2.0), (pow(((double) M_PI), 0.3333333333333333) / 2.0), (0.3333333333333333 * acos(((g * -1.0) / h)))))) - ((sin((t_0 / 3.0)) * sin((0.6666666666666666 * ((double) M_PI)))) - sin((fma(fma((2.0 * pow(((double) M_PI), 0.5)), pow(((double) M_PI), 0.5), t_0), 2.0, (3.0 * ((double) M_PI))) / 6.0)));
}
function code(g, h)
	t_0 = acos(Float64(Float64(-1.0 * g) / h))
	return Float64(Float64(sin(Float64(pi * 1.1666666666666667)) * sin(fma(((pi ^ 0.3333333333333333) ^ 2.0), Float64((pi ^ 0.3333333333333333) / 2.0), Float64(0.3333333333333333 * acos(Float64(Float64(g * -1.0) / h)))))) - Float64(Float64(sin(Float64(t_0 / 3.0)) * sin(Float64(0.6666666666666666 * pi))) - sin(Float64(fma(fma(Float64(2.0 * (pi ^ 0.5)), (pi ^ 0.5), t_0), 2.0, Float64(3.0 * pi)) / 6.0))))
end
code[g_, h_] := Block[{t$95$0 = N[ArcCos[N[(N[(-1.0 * g), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Sin[N[(Pi * 1.1666666666666667), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[Power[N[Power[Pi, 0.3333333333333333], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[Pi, 0.3333333333333333], $MachinePrecision] / 2.0), $MachinePrecision] + N[(0.3333333333333333 * N[ArcCos[N[(N[(g * -1.0), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[N[(t$95$0 / 3.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.6666666666666666 * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[Sin[N[(N[(N[(N[(2.0 * N[Power[Pi, 0.5], $MachinePrecision]), $MachinePrecision] * N[Power[Pi, 0.5], $MachinePrecision] + t$95$0), $MachinePrecision] * 2.0 + N[(3.0 * Pi), $MachinePrecision]), $MachinePrecision] / 6.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\\
\sin \left(\pi \cdot 1.1666666666666667\right) \cdot \sin \left(\mathsf{fma}\left({\left({\pi}^{0.3333333333333333}\right)}^{2}, \frac{{\pi}^{0.3333333333333333}}{2}, 0.3333333333333333 \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right)\right)\right) - \left(\sin \left(\frac{t\_0}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{0.5}, {\pi}^{0.5}, t\_0\right), 2, 3 \cdot \pi\right)}{6}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 98.4%

    \[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
  2. Add Preprocessing
  3. Applied rewrites97.5%

    \[\leadsto \color{blue}{\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{0.5}, {\pi}^{0.5}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right)} \]
  4. Taylor expanded in g around 0

    \[\leadsto \color{blue}{\cos \left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) \cdot \sin \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + \frac{2}{3} \cdot \mathsf{PI}\left(\right)\right)} - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
  5. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \sin \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + \frac{2}{3} \cdot \mathsf{PI}\left(\right)\right) \cdot \color{blue}{\cos \left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right)} - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    2. lower-*.f64N/A

      \[\leadsto \sin \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + \frac{2}{3} \cdot \mathsf{PI}\left(\right)\right) \cdot \color{blue}{\cos \left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right)} - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    3. lower-sin.f64N/A

      \[\leadsto \sin \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + \frac{2}{3} \cdot \mathsf{PI}\left(\right)\right) \cdot \cos \color{blue}{\left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right)} - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    4. distribute-rgt-outN/A

      \[\leadsto \sin \left(\mathsf{PI}\left(\right) \cdot \left(\frac{1}{2} + \frac{2}{3}\right)\right) \cdot \cos \left(\color{blue}{\frac{1}{3}} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    5. lower-*.f64N/A

      \[\leadsto \sin \left(\mathsf{PI}\left(\right) \cdot \left(\frac{1}{2} + \frac{2}{3}\right)\right) \cdot \cos \left(\color{blue}{\frac{1}{3}} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    6. lift-PI.f64N/A

      \[\leadsto \sin \left(\pi \cdot \left(\frac{1}{2} + \frac{2}{3}\right)\right) \cdot \cos \left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \cos \left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    8. sin-+PI/2-revN/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    9. lower-sin.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
  6. Applied rewrites98.5%

    \[\leadsto \color{blue}{\sin \left(\pi \cdot 1.1666666666666667\right) \cdot \sin \left(\mathsf{fma}\left(0.3333333333333333, \cos^{-1} \left(\frac{g \cdot -1}{h}\right), \frac{\pi}{2}\right)\right)} - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{0.5}, {\pi}^{0.5}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
  7. Step-by-step derivation
    1. lift-fma.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{1}{3} \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right) + \frac{\pi}{2}\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    2. lift-acos.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{1}{3} \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right) + \frac{\pi}{2}\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    3. lift-*.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{1}{3} \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right) + \frac{\pi}{2}\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    4. lift-/.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{1}{3} \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right) + \frac{\pi}{2}\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    5. +-commutativeN/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\pi}{2} + \frac{1}{3} \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    6. acos-asinN/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\pi}{2} + \frac{1}{3} \cdot \left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\frac{g \cdot -1}{h}\right)\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    7. associate-*l/N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\pi}{2} + \frac{1}{3} \cdot \left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\frac{g}{h} \cdot -1\right)\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\pi}{2} + \frac{1}{3} \cdot \left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(-1 \cdot \frac{g}{h}\right)\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    9. acos-asinN/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\pi}{2} + \frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    10. lift-PI.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\mathsf{PI}\left(\right)}{2} + \frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    11. lift-/.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\mathsf{PI}\left(\right)}{2} + \frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    12. add-cube-cbrtN/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\frac{\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \sqrt[3]{\mathsf{PI}\left(\right)}}{2} + \frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    13. associate-/l*N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \frac{\sqrt[3]{\mathsf{PI}\left(\right)}}{2} + \frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
    14. lower-fma.f64N/A

      \[\leadsto \sin \left(\pi \cdot \frac{7}{6}\right) \cdot \sin \left(\mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}, \frac{\sqrt[3]{\mathsf{PI}\left(\right)}}{2}, \frac{1}{3} \cdot \cos^{-1} \left(-1 \cdot \frac{g}{h}\right)\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{\frac{1}{2}}, {\pi}^{\frac{1}{2}}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
  8. Applied rewrites99.9%

    \[\leadsto \sin \left(\pi \cdot 1.1666666666666667\right) \cdot \sin \left(\mathsf{fma}\left({\left({\pi}^{0.3333333333333333}\right)}^{2}, \frac{{\pi}^{0.3333333333333333}}{2}, 0.3333333333333333 \cdot \cos^{-1} \left(\frac{g \cdot -1}{h}\right)\right)\right) - \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right) - \sin \left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(2 \cdot {\pi}^{0.5}, {\pi}^{0.5}, \cos^{-1} \left(\frac{-1 \cdot g}{h}\right)\right), 2, 3 \cdot \pi\right)}{6}\right)\right) \]
  9. Add Preprocessing

Alternative 2: 99.9% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\\ t_1 := \cos t\_0\\ t_2 := t\_1 \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\\ t_3 := \sin t\_0 \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\\ 2 \cdot \frac{{t\_2}^{3} - {t\_3}^{3}}{\mathsf{fma}\left(t\_2, t\_2, \mathsf{fma}\left(t\_3, t\_3, \left(t\_1 \cdot \cos \left(\frac{\pi}{3} \cdot 2\right)\right) \cdot t\_3\right)\right)} \end{array} \end{array} \]
(FPCore (g h)
 :precision binary64
 (let* ((t_0 (/ (acos (/ (* -1.0 g) h)) 3.0))
        (t_1 (cos t_0))
        (t_2 (* t_1 (sin (fma (/ PI 3.0) 2.0 (/ PI 2.0)))))
        (t_3 (* (sin t_0) (sin (* 0.6666666666666666 PI)))))
   (*
    2.0
    (/
     (- (pow t_2 3.0) (pow t_3 3.0))
     (fma t_2 t_2 (fma t_3 t_3 (* (* t_1 (cos (* (/ PI 3.0) 2.0))) t_3)))))))
double code(double g, double h) {
	double t_0 = acos(((-1.0 * g) / h)) / 3.0;
	double t_1 = cos(t_0);
	double t_2 = t_1 * sin(fma((((double) M_PI) / 3.0), 2.0, (((double) M_PI) / 2.0)));
	double t_3 = sin(t_0) * sin((0.6666666666666666 * ((double) M_PI)));
	return 2.0 * ((pow(t_2, 3.0) - pow(t_3, 3.0)) / fma(t_2, t_2, fma(t_3, t_3, ((t_1 * cos(((((double) M_PI) / 3.0) * 2.0))) * t_3))));
}
function code(g, h)
	t_0 = Float64(acos(Float64(Float64(-1.0 * g) / h)) / 3.0)
	t_1 = cos(t_0)
	t_2 = Float64(t_1 * sin(fma(Float64(pi / 3.0), 2.0, Float64(pi / 2.0))))
	t_3 = Float64(sin(t_0) * sin(Float64(0.6666666666666666 * pi)))
	return Float64(2.0 * Float64(Float64((t_2 ^ 3.0) - (t_3 ^ 3.0)) / fma(t_2, t_2, fma(t_3, t_3, Float64(Float64(t_1 * cos(Float64(Float64(pi / 3.0) * 2.0))) * t_3)))))
end
code[g_, h_] := Block[{t$95$0 = N[(N[ArcCos[N[(N[(-1.0 * g), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]}, Block[{t$95$1 = N[Cos[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[Sin[N[(N[(Pi / 3.0), $MachinePrecision] * 2.0 + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[t$95$0], $MachinePrecision] * N[Sin[N[(0.6666666666666666 * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(2.0 * N[(N[(N[Power[t$95$2, 3.0], $MachinePrecision] - N[Power[t$95$3, 3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$2 * t$95$2 + N[(t$95$3 * t$95$3 + N[(N[(t$95$1 * N[Cos[N[(N[(Pi / 3.0), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\\
t_1 := \cos t\_0\\
t_2 := t\_1 \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\\
t_3 := \sin t\_0 \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\\
2 \cdot \frac{{t\_2}^{3} - {t\_3}^{3}}{\mathsf{fma}\left(t\_2, t\_2, \mathsf{fma}\left(t\_3, t\_3, \left(t\_1 \cdot \cos \left(\frac{\pi}{3} \cdot 2\right)\right) \cdot t\_3\right)\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 98.4%

    \[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
  2. Add Preprocessing
  3. Applied rewrites99.8%

    \[\leadsto 2 \cdot \color{blue}{\frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\right)\right)\right)}} \]
  4. Step-by-step derivation
    1. lift-sin.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \color{blue}{\sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)}\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    2. lift-fma.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \color{blue}{\left(\frac{\pi}{3} \cdot 2 + \frac{\pi}{2}\right)}\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    3. lift-PI.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{3} \cdot 2 + \frac{\pi}{2}\right)\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    4. lift-/.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\color{blue}{\frac{\mathsf{PI}\left(\right)}{3}} \cdot 2 + \frac{\pi}{2}\right)\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    5. lift-PI.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{\mathsf{PI}\left(\right)}{3} \cdot 2 + \frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right)\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    6. lift-/.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{\mathsf{PI}\left(\right)}{3} \cdot 2 + \color{blue}{\frac{\mathsf{PI}\left(\right)}{2}}\right)\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    7. lift-/.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\color{blue}{\frac{\mathsf{PI}\left(\right)}{3}} \cdot 2 + \frac{\mathsf{PI}\left(\right)}{2}\right)\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    8. lift-PI.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{\color{blue}{\pi}}{3} \cdot 2 + \frac{\mathsf{PI}\left(\right)}{2}\right)\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    9. sin-+PI/2N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \color{blue}{\cos \left(\frac{\pi}{3} \cdot 2\right)}\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    10. lower-cos.f64N/A

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \color{blue}{\cos \left(\frac{\pi}{3} \cdot 2\right)}\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\frac{2}{3} \cdot \pi\right)\right)\right)\right)} \]
    11. lower-*.f6499.9

      \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \cos \color{blue}{\left(\frac{\pi}{3} \cdot 2\right)}\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\right)\right)\right)} \]
  5. Applied rewrites99.9%

    \[\leadsto 2 \cdot \frac{{\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right)\right)}^{3} - {\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\right)}^{3}}{\mathsf{fma}\left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(\mathsf{fma}\left(\frac{\pi}{3}, 2, \frac{\pi}{2}\right)\right), \mathsf{fma}\left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right), \sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right), \left(\cos \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \color{blue}{\cos \left(\frac{\pi}{3} \cdot 2\right)}\right) \cdot \left(\sin \left(\frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \cdot \sin \left(0.6666666666666666 \cdot \pi\right)\right)\right)\right)} \]
  6. Add Preprocessing

Alternative 3: 98.5% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -1 \cdot \frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-1 \cdot -9}\\ 2 \cdot \left(\cos \left(\frac{t\_0 + t\_0}{2}\right) \cdot \cos \left(\frac{0}{2}\right)\right) \end{array} \end{array} \]
(FPCore (g h)
 :precision binary64
 (let* ((t_0
         (*
          -1.0
          (/
           (fma (acos (/ (* -1.0 g) h)) -3.0 (* 3.0 (* -2.0 PI)))
           (* -1.0 -9.0)))))
   (* 2.0 (* (cos (/ (+ t_0 t_0) 2.0)) (cos (/ 0.0 2.0))))))
double code(double g, double h) {
	double t_0 = -1.0 * (fma(acos(((-1.0 * g) / h)), -3.0, (3.0 * (-2.0 * ((double) M_PI)))) / (-1.0 * -9.0));
	return 2.0 * (cos(((t_0 + t_0) / 2.0)) * cos((0.0 / 2.0)));
}
function code(g, h)
	t_0 = Float64(-1.0 * Float64(fma(acos(Float64(Float64(-1.0 * g) / h)), -3.0, Float64(3.0 * Float64(-2.0 * pi))) / Float64(-1.0 * -9.0)))
	return Float64(2.0 * Float64(cos(Float64(Float64(t_0 + t_0) / 2.0)) * cos(Float64(0.0 / 2.0))))
end
code[g_, h_] := Block[{t$95$0 = N[(-1.0 * N[(N[(N[ArcCos[N[(N[(-1.0 * g), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision] * -3.0 + N[(3.0 * N[(-2.0 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(2.0 * N[(N[Cos[N[(N[(t$95$0 + t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -1 \cdot \frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-1 \cdot -9}\\
2 \cdot \left(\cos \left(\frac{t\_0 + t\_0}{2}\right) \cdot \cos \left(\frac{0}{2}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 98.4%

    \[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
  2. Add Preprocessing
  3. Applied rewrites98.5%

    \[\leadsto \color{blue}{2 \cdot \left(\cos \left(\frac{\frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-9} + \frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-9}}{2}\right) \cdot \cos \left(\frac{\frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-9} - \frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-9}}{2}\right)\right)} \]
  4. Final simplification98.5%

    \[\leadsto 2 \cdot \left(\cos \left(\frac{-1 \cdot \frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-1 \cdot -9} + -1 \cdot \frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-1 \cdot g}{h}\right), -3, 3 \cdot \left(-2 \cdot \pi\right)\right)}{-1 \cdot -9}}{2}\right) \cdot \cos \left(\frac{0}{2}\right)\right) \]
  5. Add Preprocessing

Alternative 4: 98.5% accurate, N/A× speedup?

\[\begin{array}{l} \\ 2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \end{array} \]
(FPCore (g h)
 :precision binary64
 (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (* -1.0 g) h)) 3.0)))))
double code(double g, double h) {
	return 2.0 * cos((((2.0 * ((double) M_PI)) / 3.0) + (acos(((-1.0 * g) / h)) / 3.0)));
}
public static double code(double g, double h) {
	return 2.0 * Math.cos((((2.0 * Math.PI) / 3.0) + (Math.acos(((-1.0 * g) / h)) / 3.0)));
}
def code(g, h):
	return 2.0 * math.cos((((2.0 * math.pi) / 3.0) + (math.acos(((-1.0 * g) / h)) / 3.0)))
function code(g, h)
	return Float64(2.0 * cos(Float64(Float64(Float64(2.0 * pi) / 3.0) + Float64(acos(Float64(Float64(-1.0 * g) / h)) / 3.0))))
end
function tmp = code(g, h)
	tmp = 2.0 * cos((((2.0 * pi) / 3.0) + (acos(((-1.0 * g) / h)) / 3.0)));
end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[(N[(2.0 * Pi), $MachinePrecision] / 3.0), $MachinePrecision] + N[(N[ArcCos[N[(N[(-1.0 * g), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right)
\end{array}
Derivation
  1. Initial program 98.4%

    \[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
  2. Add Preprocessing
  3. Final simplification98.4%

    \[\leadsto 2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-1 \cdot g}{h}\right)}{3}\right) \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025065 
(FPCore (g h)
  :name "2-ancestry mixing, negative discriminant"
  :precision binary64
  (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))