| Alternative 1 | |
|---|---|
| Accuracy | 8.3% |
| Cost | 39232 |
\[\log \left(e^{0.5 \cdot \pi + -2 \cdot \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5 - 0.5 \cdot x}\right)\right)}\right)
\]

(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
(FPCore (x) :precision binary64 (log (exp (+ (* 0.5 PI) (* -2.0 (- (* 0.5 PI) (acos (sqrt (- 0.5 (* 0.5 x))))))))))
double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
}
double code(double x) {
return log(exp(((0.5 * ((double) M_PI)) + (-2.0 * ((0.5 * ((double) M_PI)) - acos(sqrt((0.5 - (0.5 * x)))))))));
}
public static double code(double x) {
return (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
}
public static double code(double x) {
return Math.log(Math.exp(((0.5 * Math.PI) + (-2.0 * ((0.5 * Math.PI) - Math.acos(Math.sqrt((0.5 - (0.5 * x)))))))));
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0))))
def code(x): return math.log(math.exp(((0.5 * math.pi) + (-2.0 * ((0.5 * math.pi) - math.acos(math.sqrt((0.5 - (0.5 * x)))))))))
function code(x) return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0))))) end
function code(x) return log(exp(Float64(Float64(0.5 * pi) + Float64(-2.0 * Float64(Float64(0.5 * pi) - acos(sqrt(Float64(0.5 - Float64(0.5 * x))))))))) end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); end
function tmp = code(x) tmp = log(exp(((0.5 * pi) + (-2.0 * ((0.5 * pi) - acos(sqrt((0.5 - (0.5 * x))))))))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[N[(N[(1.0 - x), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[Log[N[Exp[N[(N[(0.5 * Pi), $MachinePrecision] + N[(-2.0 * N[(N[(0.5 * Pi), $MachinePrecision] - N[ArcCos[N[Sqrt[N[(0.5 - N[(0.5 * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\log \left(e^{0.5 \cdot \pi + -2 \cdot \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5 - 0.5 \cdot x}\right)\right)}\right)
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 6.8% |
|---|---|
| Target | 100.0% |
| Herbie | 8.3% |
Initial program 6.3%
Applied egg-rr6.3%
[Start]6.3% | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\] |
|---|---|
add-log-exp [=>]6.3% | \[ \color{blue}{\log \left(e^{\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)}\right)}
\] |
sub-neg [=>]6.3% | \[ \log \left(e^{\color{blue}{\frac{\pi}{2} + \left(-2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right)}}\right)
\] |
+-commutative [=>]6.3% | \[ \log \left(e^{\color{blue}{\left(-2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) + \frac{\pi}{2}}}\right)
\] |
*-commutative [=>]6.3% | \[ \log \left(e^{\left(-\color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \cdot 2}\right) + \frac{\pi}{2}}\right)
\] |
distribute-rgt-neg-in [=>]6.3% | \[ \log \left(e^{\color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \cdot \left(-2\right)} + \frac{\pi}{2}}\right)
\] |
fma-def [=>]6.3% | \[ \log \left(e^{\color{blue}{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right), -2, \frac{\pi}{2}\right)}}\right)
\] |
div-sub [=>]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2} - \frac{x}{2}}}\right), -2, \frac{\pi}{2}\right)}\right)
\] |
metadata-eval [=>]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{0.5} - \frac{x}{2}}\right), -2, \frac{\pi}{2}\right)}\right)
\] |
div-inv [=>]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 - \color{blue}{x \cdot \frac{1}{2}}}\right), -2, \frac{\pi}{2}\right)}\right)
\] |
metadata-eval [=>]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 - x \cdot \color{blue}{0.5}}\right), -2, \frac{\pi}{2}\right)}\right)
\] |
metadata-eval [=>]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 - x \cdot 0.5}\right), \color{blue}{-2}, \frac{\pi}{2}\right)}\right)
\] |
div-inv [=>]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 - x \cdot 0.5}\right), -2, \color{blue}{\pi \cdot \frac{1}{2}}\right)}\right)
\] |
metadata-eval [=>]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 - x \cdot 0.5}\right), -2, \pi \cdot \color{blue}{0.5}\right)}\right)
\] |
Applied egg-rr8.1%
[Start]6.3% | \[ \log \left(e^{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 - x \cdot 0.5}\right), -2, \pi \cdot 0.5\right)}\right)
\] |
|---|---|
asin-acos [=>]8.1% | \[ \log \left(e^{\mathsf{fma}\left(\color{blue}{\frac{\pi}{2} - \cos^{-1} \left(\sqrt{0.5 - x \cdot 0.5}\right)}, -2, \pi \cdot 0.5\right)}\right)
\] |
div-inv [=>]8.1% | \[ \log \left(e^{\mathsf{fma}\left(\color{blue}{\pi \cdot \frac{1}{2}} - \cos^{-1} \left(\sqrt{0.5 - x \cdot 0.5}\right), -2, \pi \cdot 0.5\right)}\right)
\] |
metadata-eval [=>]8.1% | \[ \log \left(e^{\mathsf{fma}\left(\pi \cdot \color{blue}{0.5} - \cos^{-1} \left(\sqrt{0.5 - x \cdot 0.5}\right), -2, \pi \cdot 0.5\right)}\right)
\] |
*-commutative [=>]8.1% | \[ \log \left(e^{\mathsf{fma}\left(\pi \cdot 0.5 - \cos^{-1} \left(\sqrt{0.5 - \color{blue}{0.5 \cdot x}}\right), -2, \pi \cdot 0.5\right)}\right)
\] |
Taylor expanded in x around 0 8.1%
Final simplification8.1%
| Alternative 1 | |
|---|---|
| Accuracy | 8.3% |
| Cost | 39232 |
| Alternative 2 | |
|---|---|
| Accuracy | 8.3% |
| Cost | 26432 |
| Alternative 3 | |
|---|---|
| Accuracy | 6.8% |
| Cost | 19968 |
| Alternative 4 | |
|---|---|
| Accuracy | 6.8% |
| Cost | 19840 |
| Alternative 5 | |
|---|---|
| Accuracy | 4.0% |
| Cost | 19712 |
| Alternative 6 | |
|---|---|
| Accuracy | 4.1% |
| Cost | 19584 |
herbie shell --seed 2023178
(FPCore (x)
:name "Ian Simplification"
:precision binary64
:herbie-target
(asin x)
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))