
(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:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (g h)
:precision binary64
(let* ((t_0 (acos (- 0.0 (/ g h))))
(t_1 (/ t_0 -3.0))
(t_2 (+ (* PI 0.6666666666666666) t_1)))
(*
(*
(/
2.0
(cos (/ (+ (/ (pow t_0 2.0) 9.0) (* 0.4444444444444444 (* PI PI))) t_2)))
(cos (- (* PI 0.6666666666666666) t_1)))
(cos (/ (+ (pow (/ t_0 3.0) 2.0) (* PI (* PI 0.4444444444444444))) t_2)))))
double code(double g, double h) {
double t_0 = acos((0.0 - (g / h)));
double t_1 = t_0 / -3.0;
double t_2 = (((double) M_PI) * 0.6666666666666666) + t_1;
return ((2.0 / cos((((pow(t_0, 2.0) / 9.0) + (0.4444444444444444 * (((double) M_PI) * ((double) M_PI)))) / t_2))) * cos(((((double) M_PI) * 0.6666666666666666) - t_1))) * cos(((pow((t_0 / 3.0), 2.0) + (((double) M_PI) * (((double) M_PI) * 0.4444444444444444))) / t_2));
}
public static double code(double g, double h) {
double t_0 = Math.acos((0.0 - (g / h)));
double t_1 = t_0 / -3.0;
double t_2 = (Math.PI * 0.6666666666666666) + t_1;
return ((2.0 / Math.cos((((Math.pow(t_0, 2.0) / 9.0) + (0.4444444444444444 * (Math.PI * Math.PI))) / t_2))) * Math.cos(((Math.PI * 0.6666666666666666) - t_1))) * Math.cos(((Math.pow((t_0 / 3.0), 2.0) + (Math.PI * (Math.PI * 0.4444444444444444))) / t_2));
}
def code(g, h): t_0 = math.acos((0.0 - (g / h))) t_1 = t_0 / -3.0 t_2 = (math.pi * 0.6666666666666666) + t_1 return ((2.0 / math.cos((((math.pow(t_0, 2.0) / 9.0) + (0.4444444444444444 * (math.pi * math.pi))) / t_2))) * math.cos(((math.pi * 0.6666666666666666) - t_1))) * math.cos(((math.pow((t_0 / 3.0), 2.0) + (math.pi * (math.pi * 0.4444444444444444))) / t_2))
function code(g, h) t_0 = acos(Float64(0.0 - Float64(g / h))) t_1 = Float64(t_0 / -3.0) t_2 = Float64(Float64(pi * 0.6666666666666666) + t_1) return Float64(Float64(Float64(2.0 / cos(Float64(Float64(Float64((t_0 ^ 2.0) / 9.0) + Float64(0.4444444444444444 * Float64(pi * pi))) / t_2))) * cos(Float64(Float64(pi * 0.6666666666666666) - t_1))) * cos(Float64(Float64((Float64(t_0 / 3.0) ^ 2.0) + Float64(pi * Float64(pi * 0.4444444444444444))) / t_2))) end
function tmp = code(g, h) t_0 = acos((0.0 - (g / h))); t_1 = t_0 / -3.0; t_2 = (pi * 0.6666666666666666) + t_1; tmp = ((2.0 / cos(((((t_0 ^ 2.0) / 9.0) + (0.4444444444444444 * (pi * pi))) / t_2))) * cos(((pi * 0.6666666666666666) - t_1))) * cos(((((t_0 / 3.0) ^ 2.0) + (pi * (pi * 0.4444444444444444))) / t_2)); end
code[g_, h_] := Block[{t$95$0 = N[ArcCos[N[(0.0 - N[(g / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / -3.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(Pi * 0.6666666666666666), $MachinePrecision] + t$95$1), $MachinePrecision]}, N[(N[(N[(2.0 / N[Cos[N[(N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] / 9.0), $MachinePrecision] + N[(0.4444444444444444 * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(Pi * 0.6666666666666666), $MachinePrecision] - t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(N[Power[N[(t$95$0 / 3.0), $MachinePrecision], 2.0], $MachinePrecision] + N[(Pi * N[(Pi * 0.4444444444444444), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(0 - \frac{g}{h}\right)\\
t_1 := \frac{t\_0}{-3}\\
t_2 := \pi \cdot 0.6666666666666666 + t\_1\\
\left(\frac{2}{\cos \left(\frac{\frac{{t\_0}^{2}}{9} + 0.4444444444444444 \cdot \left(\pi \cdot \pi\right)}{t\_2}\right)} \cdot \cos \left(\pi \cdot 0.6666666666666666 - t\_1\right)\right) \cdot \cos \left(\frac{{\left(\frac{t\_0}{3}\right)}^{2} + \pi \cdot \left(\pi \cdot 0.4444444444444444\right)}{t\_2}\right)
\end{array}
\end{array}
Initial program 98.4%
Simplified0
Applied egg-rr0
Applied egg-rr0
Applied egg-rr0
Applied egg-rr0
(FPCore (g h)
:precision binary64
(*
2.0
(cos
(fma
(cbrt (* PI (* PI PI)))
0.6666666666666666
(/ (acos (- 0.0 (/ g h))) 3.0)))))
double code(double g, double h) {
return 2.0 * cos(fma(cbrt((((double) M_PI) * (((double) M_PI) * ((double) M_PI)))), 0.6666666666666666, (acos((0.0 - (g / h))) / 3.0)));
}
function code(g, h) return Float64(2.0 * cos(fma(cbrt(Float64(pi * Float64(pi * pi))), 0.6666666666666666, Float64(acos(Float64(0.0 - Float64(g / h))) / 3.0)))) end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[Power[N[(Pi * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * 0.6666666666666666 + N[(N[ArcCos[N[(0.0 - N[(g / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \cos \left(\mathsf{fma}\left(\sqrt[3]{\pi \cdot \left(\pi \cdot \pi\right)}, 0.6666666666666666, \frac{\cos^{-1} \left(0 - \frac{g}{h}\right)}{3}\right)\right)
\end{array}
Initial program 98.4%
Simplified0
Applied egg-rr0
Applied egg-rr0
(FPCore (g h) :precision binary64 (* 2.0 (cos (fma PI 0.6666666666666666 (/ (acos (- 0.0 (/ g h))) 3.0)))))
double code(double g, double h) {
return 2.0 * cos(fma(((double) M_PI), 0.6666666666666666, (acos((0.0 - (g / h))) / 3.0)));
}
function code(g, h) return Float64(2.0 * cos(fma(pi, 0.6666666666666666, Float64(acos(Float64(0.0 - Float64(g / h))) / 3.0)))) end
code[g_, h_] := N[(2.0 * N[Cos[N[(Pi * 0.6666666666666666 + N[(N[ArcCos[N[(0.0 - N[(g / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \cos \left(\mathsf{fma}\left(\pi, 0.6666666666666666, \frac{\cos^{-1} \left(0 - \frac{g}{h}\right)}{3}\right)\right)
\end{array}
Initial program 98.4%
Simplified0
Applied egg-rr0
(FPCore (g h) :precision binary64 (* 2.0 (cos (+ (* PI 0.6666666666666666) (/ (acos (/ g (- 0.0 h))) 3.0)))))
double code(double g, double h) {
return 2.0 * cos(((((double) M_PI) * 0.6666666666666666) + (acos((g / (0.0 - h))) / 3.0)));
}
public static double code(double g, double h) {
return 2.0 * Math.cos(((Math.PI * 0.6666666666666666) + (Math.acos((g / (0.0 - h))) / 3.0)));
}
def code(g, h): return 2.0 * math.cos(((math.pi * 0.6666666666666666) + (math.acos((g / (0.0 - h))) / 3.0)))
function code(g, h) return Float64(2.0 * cos(Float64(Float64(pi * 0.6666666666666666) + Float64(acos(Float64(g / Float64(0.0 - h))) / 3.0)))) end
function tmp = code(g, h) tmp = 2.0 * cos(((pi * 0.6666666666666666) + (acos((g / (0.0 - h))) / 3.0))); end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[(Pi * 0.6666666666666666), $MachinePrecision] + N[(N[ArcCos[N[(g / N[(0.0 - h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \cos \left(\pi \cdot 0.6666666666666666 + \frac{\cos^{-1} \left(\frac{g}{0 - h}\right)}{3}\right)
\end{array}
Initial program 98.4%
Simplified0
herbie shell --seed 2024110
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))