?

Average Error: 1.0 → 0.0
Time: 21.3s
Precision: binary64
Cost: 66752

?

\[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
\[\begin{array}{l} t_0 := \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\\ t_1 := t_0 \cdot 2\\ t_2 := \frac{\pi \cdot 2}{3} - t_0\\ 2 \cdot \left(\cos t_2 \cdot \cos t_1 - \sin t_1 \cdot \sin t_2\right) \end{array} \]
(FPCore (g h)
 :precision binary64
 (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
(FPCore (g h)
 :precision binary64
 (let* ((t_0 (/ (acos (/ (- g) h)) 3.0))
        (t_1 (* t_0 2.0))
        (t_2 (- (/ (* PI 2.0) 3.0) t_0)))
   (* 2.0 (- (* (cos t_2) (cos t_1)) (* (sin t_1) (sin t_2))))))
double code(double g, double h) {
	return 2.0 * cos((((2.0 * ((double) M_PI)) / 3.0) + (acos((-g / h)) / 3.0)));
}
double code(double g, double h) {
	double t_0 = acos((-g / h)) / 3.0;
	double t_1 = t_0 * 2.0;
	double t_2 = ((((double) M_PI) * 2.0) / 3.0) - t_0;
	return 2.0 * ((cos(t_2) * cos(t_1)) - (sin(t_1) * sin(t_2)));
}
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)));
}
public static double code(double g, double h) {
	double t_0 = Math.acos((-g / h)) / 3.0;
	double t_1 = t_0 * 2.0;
	double t_2 = ((Math.PI * 2.0) / 3.0) - t_0;
	return 2.0 * ((Math.cos(t_2) * Math.cos(t_1)) - (Math.sin(t_1) * Math.sin(t_2)));
}
def code(g, h):
	return 2.0 * math.cos((((2.0 * math.pi) / 3.0) + (math.acos((-g / h)) / 3.0)))
def code(g, h):
	t_0 = math.acos((-g / h)) / 3.0
	t_1 = t_0 * 2.0
	t_2 = ((math.pi * 2.0) / 3.0) - t_0
	return 2.0 * ((math.cos(t_2) * math.cos(t_1)) - (math.sin(t_1) * math.sin(t_2)))
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 code(g, h)
	t_0 = Float64(acos(Float64(Float64(-g) / h)) / 3.0)
	t_1 = Float64(t_0 * 2.0)
	t_2 = Float64(Float64(Float64(pi * 2.0) / 3.0) - t_0)
	return Float64(2.0 * Float64(Float64(cos(t_2) * cos(t_1)) - Float64(sin(t_1) * sin(t_2))))
end
function tmp = code(g, h)
	tmp = 2.0 * cos((((2.0 * pi) / 3.0) + (acos((-g / h)) / 3.0)));
end
function tmp = code(g, h)
	t_0 = acos((-g / h)) / 3.0;
	t_1 = t_0 * 2.0;
	t_2 = ((pi * 2.0) / 3.0) - t_0;
	tmp = 2.0 * ((cos(t_2) * cos(t_1)) - (sin(t_1) * sin(t_2)));
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]
code[g_, h_] := Block[{t$95$0 = N[(N[ArcCos[N[((-g) / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * 2.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(Pi * 2.0), $MachinePrecision] / 3.0), $MachinePrecision] - t$95$0), $MachinePrecision]}, N[(2.0 * N[(N[(N[Cos[t$95$2], $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$1], $MachinePrecision] * N[Sin[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\begin{array}{l}
t_0 := \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\\
t_1 := t_0 \cdot 2\\
t_2 := \frac{\pi \cdot 2}{3} - t_0\\
2 \cdot \left(\cos t_2 \cdot \cos t_1 - \sin t_1 \cdot \sin t_2\right)
\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 1.0

    \[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
  2. Applied egg-rr1.0

    \[\leadsto 2 \cdot \cos \color{blue}{\left(2 \cdot \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} - \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} - \frac{2 \cdot \pi}{3}\right)\right)} \]
  3. Applied egg-rr0.0

    \[\leadsto 2 \cdot \color{blue}{\left(\cos \left(\frac{2 \cdot \pi}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \cdot \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) - \sin \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) \cdot \sin \left(\frac{2 \cdot \pi}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)} \]
  4. Simplified0.0

    \[\leadsto 2 \cdot \color{blue}{\left(\cos \left(\frac{\pi \cdot 2}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \cdot \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) - \sin \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) \cdot \sin \left(\frac{\pi \cdot 2}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)} \]
    Proof

    [Start]0.0

    \[ 2 \cdot \left(\cos \left(\frac{2 \cdot \pi}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \cdot \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) - \sin \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) \cdot \sin \left(\frac{2 \cdot \pi}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right) \]
  5. Final simplification0.0

    \[\leadsto 2 \cdot \left(\cos \left(\frac{\pi \cdot 2}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \cdot \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) - \sin \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3} \cdot 2\right) \cdot \sin \left(\frac{\pi \cdot 2}{3} - \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right) \]

Alternatives

Alternative 1
Error0.0
Cost60608
\[\begin{array}{l} t_0 := 0.6666666666666666 \cdot \pi + 0.3333333333333333 \cdot \cos^{-1} \left(-\frac{g}{h}\right)\\ t_1 := \cos \left(t_0 \cdot 2\right)\\ 2 \cdot \left(\frac{1 + t_1}{2} \cdot \frac{1}{\frac{t_1 + 1}{2} \cdot \frac{1}{\cos t_0}}\right) \end{array} \]
Alternative 2
Error0.1
Cost53568
\[\begin{array}{l} t_0 := \cos^{-1} \left(-\frac{g}{h}\right)\\ t_1 := t_0 + \pi\\ 2 \cdot \left(\frac{1 + \cos \left(t_1 \cdot 1.3333333333333333 - 0.6666666666666666 \cdot t_0\right)}{2} \cdot \frac{1}{\cos \left(0.6666666666666666 \cdot t_1 - t_0 \cdot 0.3333333333333333\right)}\right) \end{array} \]
Alternative 3
Error1.0
Cost26752
\[\begin{array}{l} t_0 := \cos^{-1} \left(-\frac{g}{h}\right)\\ 2 \cdot \cos \left(0.6666666666666666 \cdot t_0 - \left(0.3333333333333333 \cdot t_0 - 0.6666666666666666 \cdot \pi\right)\right) \end{array} \]
Alternative 4
Error1.0
Cost19904
\[2 \cdot \cos \left(0.3333333333333333 \cdot \cos^{-1} \left(-\frac{g}{h}\right) + 0.6666666666666666 \cdot \pi\right) \]

Error

Reproduce?

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