| Alternative 1 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 8528 |
(FPCore (x y) :precision binary64 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0)))
(t_1 (pow (/ x y) 2.0))
(t_2 (/ (fma 0.25 t_1 -1.0) (sqrt (fma t_1 0.5 1.0))))
(t_3 (- (* x x) t_0)))
(if (<= (* x x) 5e-318)
t_2
(if (<= (* x x) 4e-267)
(/ t_3 (+ (* x x) t_0))
(if (<= (* x x) 2e-107)
t_2
(if (<= (* x x) 4e+306)
(/ t_3 (fma x x t_0))
(fma (* (/ y x) (/ y x)) -8.0 1.0)))))))double code(double x, double y) {
return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = pow((x / y), 2.0);
double t_2 = fma(0.25, t_1, -1.0) / sqrt(fma(t_1, 0.5, 1.0));
double t_3 = (x * x) - t_0;
double tmp;
if ((x * x) <= 5e-318) {
tmp = t_2;
} else if ((x * x) <= 4e-267) {
tmp = t_3 / ((x * x) + t_0);
} else if ((x * x) <= 2e-107) {
tmp = t_2;
} else if ((x * x) <= 4e+306) {
tmp = t_3 / fma(x, x, t_0);
} else {
tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
}
return tmp;
}
function code(x, y) return Float64(Float64(Float64(x * x) - Float64(Float64(y * 4.0) * y)) / Float64(Float64(x * x) + Float64(Float64(y * 4.0) * y))) end
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(x / y) ^ 2.0 t_2 = Float64(fma(0.25, t_1, -1.0) / sqrt(fma(t_1, 0.5, 1.0))) t_3 = Float64(Float64(x * x) - t_0) tmp = 0.0 if (Float64(x * x) <= 5e-318) tmp = t_2; elseif (Float64(x * x) <= 4e-267) tmp = Float64(t_3 / Float64(Float64(x * x) + t_0)); elseif (Float64(x * x) <= 2e-107) tmp = t_2; elseif (Float64(x * x) <= 4e+306) tmp = Float64(t_3 / fma(x, x, t_0)); else tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0); end return tmp end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[(0.25 * t$95$1 + -1.0), $MachinePrecision] / N[Sqrt[N[(t$95$1 * 0.5 + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-318], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 4e-267], N[(t$95$3 / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-107], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 4e+306], N[(t$95$3 / N[(x * x + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]]]]]]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := {\left(\frac{x}{y}\right)}^{2}\\
t_2 := \frac{\mathsf{fma}\left(0.25, t_1, -1\right)}{\sqrt{\mathsf{fma}\left(t_1, 0.5, 1\right)}}\\
t_3 := x \cdot x - t_0\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-318}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{-267}:\\
\;\;\;\;\frac{t_3}{x \cdot x + t_0}\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-107}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+306}:\\
\;\;\;\;\frac{t_3}{\mathsf{fma}\left(x, x, t_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
| Original | 50.1% |
|---|---|
| Target | 50.5% |
| Herbie | 80.3% |
if (*.f64 x x) < 4.9999987e-318 or 3.9999999999999999e-267 < (*.f64 x x) < 2e-107Initial program 59.4%
Simplified59.4%
[Start]59.4 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
*-commutative [=>]59.4 | \[ \frac{x \cdot x - \color{blue}{y \cdot \left(y \cdot 4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]59.4 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]59.4 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in x around 0 73.1%
Simplified80.6%
[Start]73.1 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]73.1 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]73.1 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]73.1 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]80.6 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]80.6 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
Applied egg-rr80.6%
[Start]80.6 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)
\] |
|---|---|
fma-udef [=>]80.6 | \[ \color{blue}{0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1}
\] |
*-commutative [=>]80.6 | \[ \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right) \cdot 0.5} + -1
\] |
pow2 [=>]80.6 | \[ \color{blue}{{\left(\frac{x}{y}\right)}^{2}} \cdot 0.5 + -1
\] |
Applied egg-rr80.4%
[Start]80.6 | \[ {\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1
\] |
|---|---|
flip-+ [=>]80.4 | \[ \color{blue}{\frac{\left({\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) \cdot \left({\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) - -1 \cdot -1}{{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 - -1}}
\] |
add-sqr-sqrt [=>]80.4 | \[ \frac{\left({\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) \cdot \left({\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) - -1 \cdot -1}{\color{blue}{\sqrt{{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 - -1} \cdot \sqrt{{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 - -1}}}
\] |
associate-/r* [=>]80.4 | \[ \color{blue}{\frac{\frac{\left({\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) \cdot \left({\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) - -1 \cdot -1}{\sqrt{{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 - -1}}}{\sqrt{{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 - -1}}}
\] |
Taylor expanded in x around 0 73.2%
Simplified80.9%
[Start]73.2 | \[ \frac{0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - 1}{\sqrt{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, 0.5, 1\right)}}
\] |
|---|---|
fma-neg [=>]73.2 | \[ \frac{\color{blue}{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{y}^{2}}, -1\right)}}{\sqrt{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, 0.5, 1\right)}}
\] |
unpow2 [=>]73.2 | \[ \frac{\mathsf{fma}\left(0.25, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)}{\sqrt{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, 0.5, 1\right)}}
\] |
unpow2 [=>]73.2 | \[ \frac{\mathsf{fma}\left(0.25, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)}{\sqrt{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, 0.5, 1\right)}}
\] |
times-frac [=>]80.9 | \[ \frac{\mathsf{fma}\left(0.25, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)}{\sqrt{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, 0.5, 1\right)}}
\] |
unpow2 [<=]80.9 | \[ \frac{\mathsf{fma}\left(0.25, \color{blue}{{\left(\frac{x}{y}\right)}^{2}}, -1\right)}{\sqrt{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, 0.5, 1\right)}}
\] |
metadata-eval [=>]80.9 | \[ \frac{\mathsf{fma}\left(0.25, {\left(\frac{x}{y}\right)}^{2}, \color{blue}{-1}\right)}{\sqrt{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, 0.5, 1\right)}}
\] |
if 4.9999987e-318 < (*.f64 x x) < 3.9999999999999999e-267Initial program 73.9%
if 2e-107 < (*.f64 x x) < 4.00000000000000007e306Initial program 74.2%
Simplified74.2%
[Start]74.2 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
*-commutative [=>]74.2 | \[ \frac{x \cdot x - \color{blue}{y \cdot \left(y \cdot 4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]74.2 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]74.2 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
if 4.00000000000000007e306 < (*.f64 x x) Initial program 0.2%
Simplified0.2%
[Start]0.2 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
*-commutative [=>]0.2 | \[ \frac{x \cdot x - \color{blue}{y \cdot \left(y \cdot 4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]0.2 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]0.2 | \[ \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in x around inf 76.1%
Simplified88.6%
[Start]76.1 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]76.1 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
+-commutative [=>]76.1 | \[ \color{blue}{\left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + 1}
\] |
distribute-rgt-out-- [=>]76.1 | \[ \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot \left(-4 - 4\right)} + 1
\] |
metadata-eval [=>]76.1 | \[ \frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-8} + 1
\] |
fma-def [=>]76.1 | \[ \color{blue}{\mathsf{fma}\left(\frac{{y}^{2}}{{x}^{2}}, -8, 1\right)}
\] |
unpow2 [=>]76.1 | \[ \mathsf{fma}\left(\frac{\color{blue}{y \cdot y}}{{x}^{2}}, -8, 1\right)
\] |
unpow2 [=>]76.1 | \[ \mathsf{fma}\left(\frac{y \cdot y}{\color{blue}{x \cdot x}}, -8, 1\right)
\] |
times-frac [=>]88.6 | \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right)
\] |
Final simplification80.3%
| Alternative 1 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 8528 |
| Alternative 2 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 8016 |
| Alternative 3 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 2256 |
| Alternative 4 | |
|---|---|
| Accuracy | 75.2% |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Accuracy | 75.6% |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Accuracy | 74.7% |
| Cost | 328 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.2% |
| Cost | 64 |
herbie shell --seed 2023138
(FPCore (x y)
:name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))
(/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))