| Alternative 1 | |
|---|---|
| Error | 59.5 |
| Cost | 20928 |
\[\begin{array}{l}
t_0 := -1 - \cos^{-1} \left(1 - x\right)\\
\left(0 - \frac{1}{t_0} \cdot \left(\left(1 + t_0 \cdot t_0\right) + -1\right)\right) - 1
\end{array}
\]
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
(FPCore (x) :precision binary64 (let* ((t_0 (- -1.0 (acos (- 1.0 x)))) (t_1 (/ 1.0 t_0))) (- (- 0.0 (* t_1 (* t_1 (* (* t_0 t_0) t_0)))) 1.0)))
double code(double x) {
return acos((1.0 - x));
}
double code(double x) {
double t_0 = -1.0 - acos((1.0 - x));
double t_1 = 1.0 / t_0;
return (0.0 - (t_1 * (t_1 * ((t_0 * t_0) * t_0)))) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos((1.0d0 - x))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
t_0 = (-1.0d0) - acos((1.0d0 - x))
t_1 = 1.0d0 / t_0
code = (0.0d0 - (t_1 * (t_1 * ((t_0 * t_0) * t_0)))) - 1.0d0
end function
public static double code(double x) {
return Math.acos((1.0 - x));
}
public static double code(double x) {
double t_0 = -1.0 - Math.acos((1.0 - x));
double t_1 = 1.0 / t_0;
return (0.0 - (t_1 * (t_1 * ((t_0 * t_0) * t_0)))) - 1.0;
}
def code(x): return math.acos((1.0 - x))
def code(x): t_0 = -1.0 - math.acos((1.0 - x)) t_1 = 1.0 / t_0 return (0.0 - (t_1 * (t_1 * ((t_0 * t_0) * t_0)))) - 1.0
function code(x) return acos(Float64(1.0 - x)) end
function code(x) t_0 = Float64(-1.0 - acos(Float64(1.0 - x))) t_1 = Float64(1.0 / t_0) return Float64(Float64(0.0 - Float64(t_1 * Float64(t_1 * Float64(Float64(t_0 * t_0) * t_0)))) - 1.0) end
function tmp = code(x) tmp = acos((1.0 - x)); end
function tmp = code(x) t_0 = -1.0 - acos((1.0 - x)); t_1 = 1.0 / t_0; tmp = (0.0 - (t_1 * (t_1 * ((t_0 * t_0) * t_0)))) - 1.0; end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(-1.0 - N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / t$95$0), $MachinePrecision]}, N[(N[(0.0 - N[(t$95$1 * N[(t$95$1 * N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]]
\cos^{-1} \left(1 - x\right)
\begin{array}{l}
t_0 := -1 - \cos^{-1} \left(1 - x\right)\\
t_1 := \frac{1}{t_0}\\
\left(0 - t_1 \cdot \left(t_1 \cdot \left(\left(t_0 \cdot t_0\right) \cdot t_0\right)\right)\right) - 1
\end{array}
Results
| Original | 59.5 |
|---|---|
| Target | 0.0 |
| Herbie | 59.5 |
Initial program 59.5
Applied egg-rr59.5
Applied egg-rr59.5
Applied egg-rr59.5
Applied egg-rr59.5
Final simplification59.5
| Alternative 1 | |
|---|---|
| Error | 59.5 |
| Cost | 20928 |
| Alternative 2 | |
|---|---|
| Error | 59.5 |
| Cost | 20672 |
| Alternative 3 | |
|---|---|
| Error | 59.5 |
| Cost | 6848 |
| Alternative 4 | |
|---|---|
| Error | 59.5 |
| Cost | 6592 |
herbie shell --seed 2023077
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
:herbie-target
(* 2.0 (asin (sqrt (/ x 2.0))))
(acos (- 1.0 x)))