
(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 3 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 (asin (/ g h))))
(+
(/
1.0
(/
(sqrt 0.3333333333333333)
(cos (+ (* -0.3333333333333333 t_0) (* PI -0.6666666666666666)))))
(sin (+ (* PI -0.6666666666666666) (/ t_0 -3.0))))))
double code(double g, double h) {
double t_0 = asin((g / h));
return (1.0 / (sqrt(0.3333333333333333) / cos(((-0.3333333333333333 * t_0) + (((double) M_PI) * -0.6666666666666666))))) + sin(((((double) M_PI) * -0.6666666666666666) + (t_0 / -3.0)));
}
public static double code(double g, double h) {
double t_0 = Math.asin((g / h));
return (1.0 / (Math.sqrt(0.3333333333333333) / Math.cos(((-0.3333333333333333 * t_0) + (Math.PI * -0.6666666666666666))))) + Math.sin(((Math.PI * -0.6666666666666666) + (t_0 / -3.0)));
}
def code(g, h): t_0 = math.asin((g / h)) return (1.0 / (math.sqrt(0.3333333333333333) / math.cos(((-0.3333333333333333 * t_0) + (math.pi * -0.6666666666666666))))) + math.sin(((math.pi * -0.6666666666666666) + (t_0 / -3.0)))
function code(g, h) t_0 = asin(Float64(g / h)) return Float64(Float64(1.0 / Float64(sqrt(0.3333333333333333) / cos(Float64(Float64(-0.3333333333333333 * t_0) + Float64(pi * -0.6666666666666666))))) + sin(Float64(Float64(pi * -0.6666666666666666) + Float64(t_0 / -3.0)))) end
function tmp = code(g, h) t_0 = asin((g / h)); tmp = (1.0 / (sqrt(0.3333333333333333) / cos(((-0.3333333333333333 * t_0) + (pi * -0.6666666666666666))))) + sin(((pi * -0.6666666666666666) + (t_0 / -3.0))); end
code[g_, h_] := Block[{t$95$0 = N[ArcSin[N[(g / h), $MachinePrecision]], $MachinePrecision]}, N[(N[(1.0 / N[(N[Sqrt[0.3333333333333333], $MachinePrecision] / N[Cos[N[(N[(-0.3333333333333333 * t$95$0), $MachinePrecision] + N[(Pi * -0.6666666666666666), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Sin[N[(N[(Pi * -0.6666666666666666), $MachinePrecision] + N[(t$95$0 / -3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(\frac{g}{h}\right)\\
\frac{1}{\frac{\sqrt{0.3333333333333333}}{\cos \left(-0.3333333333333333 \cdot t\_0 + \pi \cdot -0.6666666666666666\right)}} + \sin \left(\pi \cdot -0.6666666666666666 + \frac{t\_0}{-3}\right)
\end{array}
\end{array}
Initial program 98.4%
*-lowering-*.f64N/A
cos-lowering-cos.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
metadata-evalN/A
/-lowering-/.f64N/A
acos-lowering-acos.f64N/A
distribute-frac-negN/A
distribute-neg-frac2N/A
neg-mul-1N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6498.4%
Simplified98.4%
Applied egg-rr98.4%
distribute-lft-inN/A
associate-*r*N/A
clear-numN/A
associate-/r/N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-neg-inN/A
neg-mul-1N/A
remove-double-negN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
Applied egg-rr98.4%
*-commutativeN/A
pow1/2N/A
metadata-evalN/A
pow-flipN/A
un-div-invN/A
*-commutativeN/A
metadata-evalN/A
cancel-sign-sub-invN/A
*-commutativeN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
pow-lowering-pow.f64N/A
cos-lowering-cos.f64N/A
sub-negN/A
Applied egg-rr100.0%
Taylor expanded in g around 0
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
cos-lowering-cos.f64N/A
+-commutativeN/A
metadata-evalN/A
distribute-lft-neg-inN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
asin-lowering-asin.f64N/A
/-lowering-/.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f64N/A
PI-lowering-PI.f64100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (g h) :precision binary64 (let* ((t_0 (+ (* PI -0.6666666666666666) (/ (asin (/ g h)) -3.0)))) (+ (sin t_0) (* (sqrt 3.0) (cos t_0)))))
double code(double g, double h) {
double t_0 = (((double) M_PI) * -0.6666666666666666) + (asin((g / h)) / -3.0);
return sin(t_0) + (sqrt(3.0) * cos(t_0));
}
public static double code(double g, double h) {
double t_0 = (Math.PI * -0.6666666666666666) + (Math.asin((g / h)) / -3.0);
return Math.sin(t_0) + (Math.sqrt(3.0) * Math.cos(t_0));
}
def code(g, h): t_0 = (math.pi * -0.6666666666666666) + (math.asin((g / h)) / -3.0) return math.sin(t_0) + (math.sqrt(3.0) * math.cos(t_0))
function code(g, h) t_0 = Float64(Float64(pi * -0.6666666666666666) + Float64(asin(Float64(g / h)) / -3.0)) return Float64(sin(t_0) + Float64(sqrt(3.0) * cos(t_0))) end
function tmp = code(g, h) t_0 = (pi * -0.6666666666666666) + (asin((g / h)) / -3.0); tmp = sin(t_0) + (sqrt(3.0) * cos(t_0)); end
code[g_, h_] := Block[{t$95$0 = N[(N[(Pi * -0.6666666666666666), $MachinePrecision] + N[(N[ArcSin[N[(g / h), $MachinePrecision]], $MachinePrecision] / -3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Sin[t$95$0], $MachinePrecision] + N[(N[Sqrt[3.0], $MachinePrecision] * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot -0.6666666666666666 + \frac{\sin^{-1} \left(\frac{g}{h}\right)}{-3}\\
\sin t\_0 + \sqrt{3} \cdot \cos t\_0
\end{array}
\end{array}
Initial program 98.4%
*-lowering-*.f64N/A
cos-lowering-cos.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
metadata-evalN/A
/-lowering-/.f64N/A
acos-lowering-acos.f64N/A
distribute-frac-negN/A
distribute-neg-frac2N/A
neg-mul-1N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6498.4%
Simplified98.4%
Applied egg-rr98.4%
distribute-lft-inN/A
associate-*r*N/A
clear-numN/A
associate-/r/N/A
metadata-evalN/A
associate-*r*N/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-neg-inN/A
neg-mul-1N/A
remove-double-negN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (g h) :precision binary64 (* 2.0 (cos (+ (* PI 0.6666666666666666) (/ (acos (/ (/ g -1.0) h)) 3.0)))))
double code(double g, double h) {
return 2.0 * cos(((((double) M_PI) * 0.6666666666666666) + (acos(((g / -1.0) / h)) / 3.0)));
}
public static double code(double g, double h) {
return 2.0 * Math.cos(((Math.PI * 0.6666666666666666) + (Math.acos(((g / -1.0) / h)) / 3.0)));
}
def code(g, h): return 2.0 * math.cos(((math.pi * 0.6666666666666666) + (math.acos(((g / -1.0) / h)) / 3.0)))
function code(g, h) return Float64(2.0 * cos(Float64(Float64(pi * 0.6666666666666666) + Float64(acos(Float64(Float64(g / -1.0) / h)) / 3.0)))) end
function tmp = code(g, h) tmp = 2.0 * cos(((pi * 0.6666666666666666) + (acos(((g / -1.0) / h)) / 3.0))); end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[(Pi * 0.6666666666666666), $MachinePrecision] + N[(N[ArcCos[N[(N[(g / -1.0), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \cos \left(\pi \cdot 0.6666666666666666 + \frac{\cos^{-1} \left(\frac{\frac{g}{-1}}{h}\right)}{3}\right)
\end{array}
Initial program 98.4%
*-lowering-*.f64N/A
cos-lowering-cos.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
metadata-evalN/A
/-lowering-/.f64N/A
acos-lowering-acos.f64N/A
distribute-frac-negN/A
distribute-neg-frac2N/A
neg-mul-1N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6498.4%
Simplified98.4%
herbie shell --seed 2024159
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))