| Alternative 1 | |
|---|---|
| Accuracy | 8.4% |
| Cost | 26432 |
\[\frac{\pi}{2} + 2 \cdot \left(\cos^{-1} \left(\sqrt{0.5 - 0.5 \cdot x}\right) - \pi \cdot 0.5\right)
\]

(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
(FPCore (x)
:precision binary64
(if (<= x -1.65e-162)
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0)))))
(if (<= x 1.7e-162)
(+ (/ PI 2.0) (* 2.0 (+ 1.0 (- -1.0 (asin (sqrt 0.5))))))
(- (/ PI 2.0) (* 2.0 (asin (/ 1.0 (sqrt (/ 2.0 (- 1.0 x))))))))))double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
}
double code(double x) {
double tmp;
if (x <= -1.65e-162) {
tmp = (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
} else if (x <= 1.7e-162) {
tmp = (((double) M_PI) / 2.0) + (2.0 * (1.0 + (-1.0 - asin(sqrt(0.5)))));
} else {
tmp = (((double) M_PI) / 2.0) - (2.0 * asin((1.0 / sqrt((2.0 / (1.0 - x))))));
}
return tmp;
}
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) {
double tmp;
if (x <= -1.65e-162) {
tmp = (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
} else if (x <= 1.7e-162) {
tmp = (Math.PI / 2.0) + (2.0 * (1.0 + (-1.0 - Math.asin(Math.sqrt(0.5)))));
} else {
tmp = (Math.PI / 2.0) - (2.0 * Math.asin((1.0 / Math.sqrt((2.0 / (1.0 - x))))));
}
return tmp;
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0))))
def code(x): tmp = 0 if x <= -1.65e-162: tmp = (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0)))) elif x <= 1.7e-162: tmp = (math.pi / 2.0) + (2.0 * (1.0 + (-1.0 - math.asin(math.sqrt(0.5))))) else: tmp = (math.pi / 2.0) - (2.0 * math.asin((1.0 / math.sqrt((2.0 / (1.0 - x)))))) return tmp
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) tmp = 0.0 if (x <= -1.65e-162) tmp = Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0))))); elseif (x <= 1.7e-162) tmp = Float64(Float64(pi / 2.0) + Float64(2.0 * Float64(1.0 + Float64(-1.0 - asin(sqrt(0.5)))))); else tmp = Float64(Float64(pi / 2.0) - Float64(2.0 * asin(Float64(1.0 / sqrt(Float64(2.0 / Float64(1.0 - x))))))); end return tmp end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.65e-162) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); elseif (x <= 1.7e-162) tmp = (pi / 2.0) + (2.0 * (1.0 + (-1.0 - asin(sqrt(0.5))))); else tmp = (pi / 2.0) - (2.0 * asin((1.0 / sqrt((2.0 / (1.0 - x)))))); end tmp_2 = tmp; 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_] := If[LessEqual[x, -1.65e-162], 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], If[LessEqual[x, 1.7e-162], N[(N[(Pi / 2.0), $MachinePrecision] + N[(2.0 * N[(1.0 + N[(-1.0 - N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[(1.0 / N[Sqrt[N[(2.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-162}:\\
\;\;\;\;\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-162}:\\
\;\;\;\;\frac{\pi}{2} + 2 \cdot \left(1 + \left(-1 - \sin^{-1} \left(\sqrt{0.5}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{1}{\sqrt{\frac{2}{1 - x}}}\right)\\
\end{array}
Results
| Original | 6.9% |
|---|---|
| Target | 100.0% |
| Herbie | 9.9% |
if x < -1.65000000000000007e-162Initial program 10.6%
if -1.65000000000000007e-162 < x < 1.7e-162Initial program 3.3%
Taylor expanded in x around 0 3.3%
Applied egg-rr7.1%
[Start]3.3 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{0.5}\right)
\] |
|---|---|
expm1-log1p-u [=>]3.3 | \[ \frac{\pi}{2} - 2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin^{-1} \left(\sqrt{0.5}\right)\right)\right)}
\] |
expm1-udef [=>]3.3 | \[ \frac{\pi}{2} - 2 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sin^{-1} \left(\sqrt{0.5}\right)\right)} - 1\right)}
\] |
log1p-udef [=>]7.1 | \[ \frac{\pi}{2} - 2 \cdot \left(e^{\color{blue}{\log \left(1 + \sin^{-1} \left(\sqrt{0.5}\right)\right)}} - 1\right)
\] |
add-exp-log [<=]7.1 | \[ \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\left(1 + \sin^{-1} \left(\sqrt{0.5}\right)\right)} - 1\right)
\] |
if 1.7e-162 < x Initial program 6.2%
Applied egg-rr10.7%
[Start]6.2 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\] |
|---|---|
clear-num [=>]6.2 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{\frac{2}{1 - x}}}}\right)
\] |
sqrt-div [=>]10.7 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1}}{\sqrt{\frac{2}{1 - x}}}\right)}
\] |
metadata-eval [=>]10.7 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{\color{blue}{1}}{\sqrt{\frac{2}{1 - x}}}\right)
\] |
Final simplification8.9%
| Alternative 1 | |
|---|---|
| Accuracy | 8.4% |
| Cost | 26432 |
| Alternative 2 | |
|---|---|
| Accuracy | 9.2% |
| Cost | 20105 |
| Alternative 3 | |
|---|---|
| Accuracy | 5.8% |
| Cost | 19844 |
| Alternative 4 | |
|---|---|
| Accuracy | 6.9% |
| Cost | 19840 |
| Alternative 5 | |
|---|---|
| Accuracy | 4.1% |
| Cost | 19584 |
herbie shell --seed 2023160
(FPCore (x)
:name "Ian Simplification"
:precision binary64
:herbie-target
(asin x)
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))