
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
(FPCore (v)
:precision binary64
(let* ((t_0 (/ (+ 1.0 (* (* v v) -5.0)) (+ (* v v) -1.0)))
(t_1 (acos t_0))
(t_2 (/ (* PI PI) 4.0))
(t_3 (+ (/ PI 2.0) t_1))
(t_4 (asin t_0)))
(/
(-
(/ (* PI (* PI PI)) 8.0)
(pow (- (/ t_2 t_3) (/ (pow t_1 2.0) t_3)) 3.0))
(+ t_2 (* t_4 (+ (/ PI 2.0) t_4))))))
double code(double v) {
double t_0 = (1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0);
double t_1 = acos(t_0);
double t_2 = (((double) M_PI) * ((double) M_PI)) / 4.0;
double t_3 = (((double) M_PI) / 2.0) + t_1;
double t_4 = asin(t_0);
return (((((double) M_PI) * (((double) M_PI) * ((double) M_PI))) / 8.0) - pow(((t_2 / t_3) - (pow(t_1, 2.0) / t_3)), 3.0)) / (t_2 + (t_4 * ((((double) M_PI) / 2.0) + t_4)));
}
public static double code(double v) {
double t_0 = (1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0);
double t_1 = Math.acos(t_0);
double t_2 = (Math.PI * Math.PI) / 4.0;
double t_3 = (Math.PI / 2.0) + t_1;
double t_4 = Math.asin(t_0);
return (((Math.PI * (Math.PI * Math.PI)) / 8.0) - Math.pow(((t_2 / t_3) - (Math.pow(t_1, 2.0) / t_3)), 3.0)) / (t_2 + (t_4 * ((Math.PI / 2.0) + t_4)));
}
def code(v): t_0 = (1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0) t_1 = math.acos(t_0) t_2 = (math.pi * math.pi) / 4.0 t_3 = (math.pi / 2.0) + t_1 t_4 = math.asin(t_0) return (((math.pi * (math.pi * math.pi)) / 8.0) - math.pow(((t_2 / t_3) - (math.pow(t_1, 2.0) / t_3)), 3.0)) / (t_2 + (t_4 * ((math.pi / 2.0) + t_4)))
function code(v) t_0 = Float64(Float64(1.0 + Float64(Float64(v * v) * -5.0)) / Float64(Float64(v * v) + -1.0)) t_1 = acos(t_0) t_2 = Float64(Float64(pi * pi) / 4.0) t_3 = Float64(Float64(pi / 2.0) + t_1) t_4 = asin(t_0) return Float64(Float64(Float64(Float64(pi * Float64(pi * pi)) / 8.0) - (Float64(Float64(t_2 / t_3) - Float64((t_1 ^ 2.0) / t_3)) ^ 3.0)) / Float64(t_2 + Float64(t_4 * Float64(Float64(pi / 2.0) + t_4)))) end
function tmp = code(v) t_0 = (1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0); t_1 = acos(t_0); t_2 = (pi * pi) / 4.0; t_3 = (pi / 2.0) + t_1; t_4 = asin(t_0); tmp = (((pi * (pi * pi)) / 8.0) - (((t_2 / t_3) - ((t_1 ^ 2.0) / t_3)) ^ 3.0)) / (t_2 + (t_4 * ((pi / 2.0) + t_4))); end
code[v_] := Block[{t$95$0 = N[(N[(1.0 + N[(N[(v * v), $MachinePrecision] * -5.0), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[ArcCos[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(N[(Pi * Pi), $MachinePrecision] / 4.0), $MachinePrecision]}, Block[{t$95$3 = N[(N[(Pi / 2.0), $MachinePrecision] + t$95$1), $MachinePrecision]}, Block[{t$95$4 = N[ArcSin[t$95$0], $MachinePrecision]}, N[(N[(N[(N[(Pi * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] / 8.0), $MachinePrecision] - N[Power[N[(N[(t$95$2 / t$95$3), $MachinePrecision] - N[(N[Power[t$95$1, 2.0], $MachinePrecision] / t$95$3), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$2 + N[(t$95$4 * N[(N[(Pi / 2.0), $MachinePrecision] + t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\\
t_1 := \cos^{-1} t\_0\\
t_2 := \frac{\pi \cdot \pi}{4}\\
t_3 := \frac{\pi}{2} + t\_1\\
t_4 := \sin^{-1} t\_0\\
\frac{\frac{\pi \cdot \left(\pi \cdot \pi\right)}{8} - {\left(\frac{t\_2}{t\_3} - \frac{{t\_1}^{2}}{t\_3}\right)}^{3}}{t\_2 + t\_4 \cdot \left(\frac{\pi}{2} + t\_4\right)}
\end{array}
\end{array}
Initial program 99.2%
Applied egg-rr99.2%
asin-acosN/A
flip--N/A
frac-timesN/A
metadata-evalN/A
div-subN/A
Applied egg-rr99.3%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* (* v v) 5.0)) (+ (* v v) -1.0))))
double code(double v) {
return acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - ((v * v) * 5.0d0)) / ((v * v) + (-1.0d0))))
end function
public static double code(double v) {
return Math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
def code(v): return math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(Float64(v * v) * 5.0)) / Float64(Float64(v * v) + -1.0))) end
function tmp = code(v) tmp = acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(N[(v * v), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right)
\end{array}
Initial program 99.2%
Final simplification99.2%
(FPCore (v) :precision binary64 (- PI (acos (+ 1.0 (* v (* v -4.0))))))
double code(double v) {
return ((double) M_PI) - acos((1.0 + (v * (v * -4.0))));
}
public static double code(double v) {
return Math.PI - Math.acos((1.0 + (v * (v * -4.0))));
}
def code(v): return math.pi - math.acos((1.0 + (v * (v * -4.0))))
function code(v) return Float64(pi - acos(Float64(1.0 + Float64(v * Float64(v * -4.0))))) end
function tmp = code(v) tmp = pi - acos((1.0 + (v * (v * -4.0)))); end
code[v_] := N[(Pi - N[ArcCos[N[(1.0 + N[(v * N[(v * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi - \cos^{-1} \left(1 + v \cdot \left(v \cdot -4\right)\right)
\end{array}
Initial program 99.2%
frac-2negN/A
distribute-frac-negN/A
acos-negN/A
--lowering--.f64N/A
PI-lowering-PI.f64N/A
acos-lowering-acos.f64N/A
/-lowering-/.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
neg-sub0N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
--lowering--.f64N/A
*-lowering-*.f6499.2%
Applied egg-rr99.2%
Taylor expanded in v around 0
+-lowering-+.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6498.6%
Simplified98.6%
(FPCore (v) :precision binary64 (acos (+ -1.0 (* 4.0 (* v v)))))
double code(double v) {
return acos((-1.0 + (4.0 * (v * v))));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((-1.0d0) + (4.0d0 * (v * v))))
end function
public static double code(double v) {
return Math.acos((-1.0 + (4.0 * (v * v))));
}
def code(v): return math.acos((-1.0 + (4.0 * (v * v))))
function code(v) return acos(Float64(-1.0 + Float64(4.0 * Float64(v * v)))) end
function tmp = code(v) tmp = acos((-1.0 + (4.0 * (v * v)))); end
code[v_] := N[ArcCos[N[(-1.0 + N[(4.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(-1 + 4 \cdot \left(v \cdot v\right)\right)
\end{array}
Initial program 99.2%
Taylor expanded in v around 0
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6498.6%
Simplified98.6%
Final simplification98.6%
(FPCore (v) :precision binary64 (acos -1.0))
double code(double v) {
return acos(-1.0);
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos((-1.0d0))
end function
public static double code(double v) {
return Math.acos(-1.0);
}
def code(v): return math.acos(-1.0)
function code(v) return acos(-1.0) end
function tmp = code(v) tmp = acos(-1.0); end
code[v_] := N[ArcCos[-1.0], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} -1
\end{array}
Initial program 99.2%
Taylor expanded in v around 0
Simplified98.1%
herbie shell --seed 2024192
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))