| Alternative 1 | |
|---|---|
| Error | 19.71% |
| Cost | 7572 |
(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 (+ (* (pow (/ x y) 2.0) 0.5) -1.0))
(t_1 (+ (* x x) (* y (* y 4.0)))))
(if (<= y -1.45e+123)
t_0
(if (<= y -6.5e-143)
(/ (fma y (* y -4.0) (* x x)) t_1)
(if (<= y 1.05e-35)
(+ 1.0 (* (/ y x) (* y (/ -8.0 x))))
(if (<= y 2.5e+113)
(/ (+ (* x x) (* y (* y -4.0))) t_1)
(if (<= y 4.3e+133) 1.0 t_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 = (pow((x / y), 2.0) * 0.5) + -1.0;
double t_1 = (x * x) + (y * (y * 4.0));
double tmp;
if (y <= -1.45e+123) {
tmp = t_0;
} else if (y <= -6.5e-143) {
tmp = fma(y, (y * -4.0), (x * x)) / t_1;
} else if (y <= 1.05e-35) {
tmp = 1.0 + ((y / x) * (y * (-8.0 / x)));
} else if (y <= 2.5e+113) {
tmp = ((x * x) + (y * (y * -4.0))) / t_1;
} else if (y <= 4.3e+133) {
tmp = 1.0;
} else {
tmp = t_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(Float64((Float64(x / y) ^ 2.0) * 0.5) + -1.0) t_1 = Float64(Float64(x * x) + Float64(y * Float64(y * 4.0))) tmp = 0.0 if (y <= -1.45e+123) tmp = t_0; elseif (y <= -6.5e-143) tmp = Float64(fma(y, Float64(y * -4.0), Float64(x * x)) / t_1); elseif (y <= 1.05e-35) tmp = Float64(1.0 + Float64(Float64(y / x) * Float64(y * Float64(-8.0 / x)))); elseif (y <= 2.5e+113) tmp = Float64(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / t_1); elseif (y <= 4.3e+133) tmp = 1.0; else tmp = t_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[(N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.45e+123], t$95$0, If[LessEqual[y, -6.5e-143], N[(N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[y, 1.05e-35], N[(1.0 + N[(N[(y / x), $MachinePrecision] * N[(y * N[(-8.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.5e+113], N[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[y, 4.3e+133], 1.0, t$95$0]]]]]]]
\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 := {\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\
t_1 := x \cdot x + y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;y \leq -1.45 \cdot 10^{+123}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -6.5 \cdot 10^{-143}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{t_1}\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-35}:\\
\;\;\;\;1 + \frac{y}{x} \cdot \left(y \cdot \frac{-8}{x}\right)\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+113}:\\
\;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_1}\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{+133}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
| Original | 49.08% |
|---|---|
| Target | 48.62% |
| Herbie | 19.7% |
if y < -1.45000000000000005e123 or 4.29999999999999994e133 < y Initial program 89.25
Simplified89.25
[Start]89.25 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
cancel-sign-sub-inv [=>]89.25 | \[ \frac{\color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [=>]89.25 | \[ \frac{\color{blue}{\left(-y \cdot 4\right) \cdot y + x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]89.25 | \[ \frac{\color{blue}{y \cdot \left(-y \cdot 4\right)} + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]89.25 | \[ \frac{\color{blue}{\mathsf{fma}\left(y, -y \cdot 4, x \cdot x\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
distribute-rgt-neg-in [=>]89.25 | \[ \frac{\mathsf{fma}\left(y, \color{blue}{y \cdot \left(-4\right)}, x \cdot x\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
metadata-eval [=>]89.25 | \[ \frac{\mathsf{fma}\left(y, y \cdot \color{blue}{-4}, x \cdot x\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]89.25 | \[ \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]89.25 | \[ \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in y around inf 26
Simplified14.5
[Start]26 | \[ 0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - \left(-0.25 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right)
\] |
|---|---|
associate--r+ [=>]26 | \[ \color{blue}{\left(0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - -0.25 \cdot \frac{{x}^{2}}{{y}^{2}}\right) - 1}
\] |
distribute-rgt-out-- [=>]26 | \[ \color{blue}{\frac{{x}^{2}}{{y}^{2}} \cdot \left(0.25 - -0.25\right)} - 1
\] |
metadata-eval [=>]26 | \[ \frac{{x}^{2}}{{y}^{2}} \cdot \color{blue}{0.5} - 1
\] |
fma-neg [=>]26 | \[ \color{blue}{\mathsf{fma}\left(\frac{{x}^{2}}{{y}^{2}}, 0.5, -1\right)}
\] |
unpow2 [=>]26 | \[ \mathsf{fma}\left(\frac{\color{blue}{x \cdot x}}{{y}^{2}}, 0.5, -1\right)
\] |
unpow2 [=>]26 | \[ \mathsf{fma}\left(\frac{x \cdot x}{\color{blue}{y \cdot y}}, 0.5, -1\right)
\] |
times-frac [=>]14.5 | \[ \mathsf{fma}\left(\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, 0.5, -1\right)
\] |
metadata-eval [=>]14.5 | \[ \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, \color{blue}{-1}\right)
\] |
Applied egg-rr14.5
if -1.45000000000000005e123 < y < -6.4999999999999999e-143Initial program 22.7
Taylor expanded in x around 0 22.7
Simplified22.7
[Start]22.7 | \[ \frac{-4 \cdot {y}^{2} + {x}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
unpow2 [=>]22.7 | \[ \frac{-4 \cdot {y}^{2} + \color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]22.7 | \[ \frac{\color{blue}{{y}^{2} \cdot -4} + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
unpow2 [=>]22.7 | \[ \frac{\color{blue}{\left(y \cdot y\right)} \cdot -4 + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
associate-*r* [<=]22.7 | \[ \frac{\color{blue}{y \cdot \left(y \cdot -4\right)} + x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]22.7 | \[ \frac{\color{blue}{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
if -6.4999999999999999e-143 < y < 1.05e-35Initial program 41.12
Applied egg-rr42.84
Taylor expanded in x around inf 25.99
Simplified26.09
[Start]25.99 | \[ 1 + -1 \cdot \frac{4 \cdot {y}^{2} - -4 \cdot {y}^{2}}{{x}^{2}}
\] |
|---|---|
mul-1-neg [=>]25.99 | \[ 1 + \color{blue}{\left(-\frac{4 \cdot {y}^{2} - -4 \cdot {y}^{2}}{{x}^{2}}\right)}
\] |
unsub-neg [=>]25.99 | \[ \color{blue}{1 - \frac{4 \cdot {y}^{2} - -4 \cdot {y}^{2}}{{x}^{2}}}
\] |
distribute-rgt-out-- [=>]25.99 | \[ 1 - \frac{\color{blue}{{y}^{2} \cdot \left(4 - -4\right)}}{{x}^{2}}
\] |
metadata-eval [=>]25.99 | \[ 1 - \frac{{y}^{2} \cdot \color{blue}{8}}{{x}^{2}}
\] |
unpow2 [=>]25.99 | \[ 1 - \frac{{y}^{2} \cdot 8}{\color{blue}{x \cdot x}}
\] |
associate-/l* [=>]26.09 | \[ 1 - \color{blue}{\frac{{y}^{2}}{\frac{x \cdot x}{8}}}
\] |
unpow2 [=>]26.09 | \[ 1 - \frac{\color{blue}{y \cdot y}}{\frac{x \cdot x}{8}}
\] |
Applied egg-rr18.2
if 1.05e-35 < y < 2.5e113Initial program 25.18
if 2.5e113 < y < 4.29999999999999994e133Initial program 27.75
Taylor expanded in x around inf 66.2
Final simplification19.7
| Alternative 1 | |
|---|---|
| Error | 19.71% |
| Cost | 7572 |
| Alternative 2 | |
|---|---|
| Error | 19.9% |
| Cost | 1744 |
| Alternative 3 | |
|---|---|
| Error | 26.4% |
| Cost | 1233 |
| Alternative 4 | |
|---|---|
| Error | 26.2% |
| Cost | 1233 |
| Alternative 5 | |
|---|---|
| Error | 26.87% |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Error | 26.82% |
| Cost | 592 |
| Alternative 7 | |
|---|---|
| Error | 49.61% |
| Cost | 64 |
herbie shell --seed 2023121
(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))))