| Alternative 1 | |
|---|---|
| Accuracy | 80.6% |
| Cost | 14216 |
(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))))
(if (<= t_0 1e-231)
(pow (cbrt (+ (* (pow (/ y x) 2.0) -4.0) 1.0)) 3.0)
(if (<= t_0 5e+244)
(/ (+ (* x x) (* y (* y -4.0))) (+ t_0 (* x x)))
(fma 0.25 (+ (+ 1.0 (pow (/ x y) 2.0)) -1.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 tmp;
if (t_0 <= 1e-231) {
tmp = pow(cbrt(((pow((y / x), 2.0) * -4.0) + 1.0)), 3.0);
} else if (t_0 <= 5e+244) {
tmp = ((x * x) + (y * (y * -4.0))) / (t_0 + (x * x));
} else {
tmp = fma(0.25, ((1.0 + pow((x / y), 2.0)) + -1.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)) tmp = 0.0 if (t_0 <= 1e-231) tmp = cbrt(Float64(Float64((Float64(y / x) ^ 2.0) * -4.0) + 1.0)) ^ 3.0; elseif (t_0 <= 5e+244) tmp = Float64(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(t_0 + Float64(x * x))); else tmp = fma(0.25, Float64(Float64(1.0 + (Float64(x / y) ^ 2.0)) + -1.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]}, If[LessEqual[t$95$0, 1e-231], N[Power[N[Power[N[(N[(N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] * -4.0), $MachinePrecision] + 1.0), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision], If[LessEqual[t$95$0, 5e+244], N[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.25 * N[(N[(1.0 + N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + -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)\\
\mathbf{if}\;t_0 \leq 10^{-231}:\\
\;\;\;\;{\left(\sqrt[3]{{\left(\frac{y}{x}\right)}^{2} \cdot -4 + 1}\right)}^{3}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+244}:\\
\;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.25, \left(1 + {\left(\frac{x}{y}\right)}^{2}\right) + -1, -1\right)\\
\end{array}
| Original | 50.4% |
|---|---|
| Target | 50.7% |
| Herbie | 80.6% |
if (*.f64 (*.f64 y 4) y) < 9.9999999999999999e-232Initial program 58.1%
Taylor expanded in x around inf 51.0%
Simplified51.0%
[Start]51.0 | \[ \frac{{x}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
unpow2 [=>]51.0 | \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
Taylor expanded in x around inf 74.9%
Simplified74.9%
[Start]74.9 | \[ 1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate-*r/ [=>]74.9 | \[ 1 + \color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}}
\] |
unpow2 [=>]74.9 | \[ 1 + \frac{-4 \cdot \color{blue}{\left(y \cdot y\right)}}{{x}^{2}}
\] |
unpow2 [=>]74.9 | \[ 1 + \frac{-4 \cdot \left(y \cdot y\right)}{\color{blue}{x \cdot x}}
\] |
Applied egg-rr84.1%
[Start]74.9 | \[ 1 + \frac{-4 \cdot \left(y \cdot y\right)}{x \cdot x}
\] |
|---|---|
associate-*r* [=>]74.9 | \[ 1 + \frac{\color{blue}{\left(-4 \cdot y\right) \cdot y}}{x \cdot x}
\] |
times-frac [=>]84.1 | \[ 1 + \color{blue}{\frac{-4 \cdot y}{x} \cdot \frac{y}{x}}
\] |
Applied egg-rr84.1%
[Start]84.1 | \[ 1 + \frac{-4 \cdot y}{x} \cdot \frac{y}{x}
\] |
|---|---|
add-cube-cbrt [=>]84.1 | \[ \color{blue}{\left(\sqrt[3]{1 + \frac{-4 \cdot y}{x} \cdot \frac{y}{x}} \cdot \sqrt[3]{1 + \frac{-4 \cdot y}{x} \cdot \frac{y}{x}}\right) \cdot \sqrt[3]{1 + \frac{-4 \cdot y}{x} \cdot \frac{y}{x}}}
\] |
pow3 [=>]84.1 | \[ \color{blue}{{\left(\sqrt[3]{1 + \frac{-4 \cdot y}{x} \cdot \frac{y}{x}}\right)}^{3}}
\] |
+-commutative [=>]84.1 | \[ {\left(\sqrt[3]{\color{blue}{\frac{-4 \cdot y}{x} \cdot \frac{y}{x} + 1}}\right)}^{3}
\] |
clear-num [=>]84.1 | \[ {\left(\sqrt[3]{\color{blue}{\frac{1}{\frac{x}{-4 \cdot y}}} \cdot \frac{y}{x} + 1}\right)}^{3}
\] |
associate-*l/ [=>]84.1 | \[ {\left(\sqrt[3]{\color{blue}{\frac{1 \cdot \frac{y}{x}}{\frac{x}{-4 \cdot y}}} + 1}\right)}^{3}
\] |
*-un-lft-identity [<=]84.1 | \[ {\left(\sqrt[3]{\frac{\color{blue}{\frac{y}{x}}}{\frac{x}{-4 \cdot y}} + 1}\right)}^{3}
\] |
associate-/l/ [<=]84.1 | \[ {\left(\sqrt[3]{\frac{\frac{y}{x}}{\color{blue}{\frac{\frac{x}{y}}{-4}}} + 1}\right)}^{3}
\] |
associate-/r/ [=>]84.1 | \[ {\left(\sqrt[3]{\color{blue}{\frac{\frac{y}{x}}{\frac{x}{y}} \cdot -4} + 1}\right)}^{3}
\] |
un-div-inv [<=]84.1 | \[ {\left(\sqrt[3]{\color{blue}{\left(\frac{y}{x} \cdot \frac{1}{\frac{x}{y}}\right)} \cdot -4 + 1}\right)}^{3}
\] |
clear-num [<=]84.1 | \[ {\left(\sqrt[3]{\left(\frac{y}{x} \cdot \color{blue}{\frac{y}{x}}\right) \cdot -4 + 1}\right)}^{3}
\] |
pow2 [=>]84.1 | \[ {\left(\sqrt[3]{\color{blue}{{\left(\frac{y}{x}\right)}^{2}} \cdot -4 + 1}\right)}^{3}
\] |
if 9.9999999999999999e-232 < (*.f64 (*.f64 y 4) y) < 5.00000000000000022e244Initial program 74.8%
if 5.00000000000000022e244 < (*.f64 (*.f64 y 4) y) Initial program 11.3%
Taylor expanded in x around 0 10.9%
Simplified10.9%
[Start]10.9 | \[ \frac{-4 \cdot {y}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
*-commutative [=>]10.9 | \[ \frac{\color{blue}{{y}^{2} \cdot -4}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
unpow2 [=>]10.9 | \[ \frac{\color{blue}{\left(y \cdot y\right)} \cdot -4}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
associate-*r* [<=]10.9 | \[ \frac{\color{blue}{y \cdot \left(y \cdot -4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
Taylor expanded in y around inf 72.8%
Simplified84.2%
[Start]72.8 | \[ 0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]72.8 | \[ \color{blue}{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]72.8 | \[ \mathsf{fma}\left(0.25, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]72.8 | \[ \mathsf{fma}\left(0.25, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]84.2 | \[ \mathsf{fma}\left(0.25, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]84.2 | \[ \mathsf{fma}\left(0.25, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
Applied egg-rr84.2%
[Start]84.2 | \[ \mathsf{fma}\left(0.25, \frac{x}{y} \cdot \frac{x}{y}, -1\right)
\] |
|---|---|
expm1-log1p-u [=>]84.2 | \[ \mathsf{fma}\left(0.25, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x}{y} \cdot \frac{x}{y}\right)\right)}, -1\right)
\] |
expm1-udef [=>]84.2 | \[ \mathsf{fma}\left(0.25, \color{blue}{e^{\mathsf{log1p}\left(\frac{x}{y} \cdot \frac{x}{y}\right)} - 1}, -1\right)
\] |
log1p-udef [=>]84.2 | \[ \mathsf{fma}\left(0.25, e^{\color{blue}{\log \left(1 + \frac{x}{y} \cdot \frac{x}{y}\right)}} - 1, -1\right)
\] |
add-exp-log [<=]84.2 | \[ \mathsf{fma}\left(0.25, \color{blue}{\left(1 + \frac{x}{y} \cdot \frac{x}{y}\right)} - 1, -1\right)
\] |
pow2 [=>]84.2 | \[ \mathsf{fma}\left(0.25, \left(1 + \color{blue}{{\left(\frac{x}{y}\right)}^{2}}\right) - 1, -1\right)
\] |
Final simplification80.6%
| Alternative 1 | |
|---|---|
| Accuracy | 80.6% |
| Cost | 14216 |
| Alternative 2 | |
|---|---|
| Accuracy | 80.6% |
| Cost | 7752 |
| Alternative 3 | |
|---|---|
| Accuracy | 80.6% |
| Cost | 7752 |
| Alternative 4 | |
|---|---|
| Accuracy | 80.4% |
| Cost | 1992 |
| Alternative 5 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 328 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.2% |
| Cost | 64 |
herbie shell --seed 2023135
(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))))