| Alternative 1 | |
|---|---|
| Error | 13.3 |
| Cost | 7768 |
(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 (/ (+ (* x x) (* y (* y -4.0))) (+ (* x x) t_0)))
(t_2 (fma (* (/ x y) (/ x y)) 0.5 -1.0)))
(if (<= x -8.5e+113)
(+ (* y (* (/ -4.0 x) (/ y x))) 1.0)
(if (<= x -1.15e-161)
(/ (fma y (* y -4.0) (* x x)) (fma x x t_0))
(if (<= x 6.2e-38)
t_2
(if (<= x 1.75e+42)
t_1
(if (<= x 1.66e+87)
t_2
(if (<= x 2.15e+146)
t_1
(fma -8.0 (* (/ y x) (/ y x)) 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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + t_0);
double t_2 = fma(((x / y) * (x / y)), 0.5, -1.0);
double tmp;
if (x <= -8.5e+113) {
tmp = (y * ((-4.0 / x) * (y / x))) + 1.0;
} else if (x <= -1.15e-161) {
tmp = fma(y, (y * -4.0), (x * x)) / fma(x, x, t_0);
} else if (x <= 6.2e-38) {
tmp = t_2;
} else if (x <= 1.75e+42) {
tmp = t_1;
} else if (x <= 1.66e+87) {
tmp = t_2;
} else if (x <= 2.15e+146) {
tmp = t_1;
} else {
tmp = fma(-8.0, ((y / x) * (y / x)), 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(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(Float64(x * x) + t_0)) t_2 = fma(Float64(Float64(x / y) * Float64(x / y)), 0.5, -1.0) tmp = 0.0 if (x <= -8.5e+113) tmp = Float64(Float64(y * Float64(Float64(-4.0 / x) * Float64(y / x))) + 1.0); elseif (x <= -1.15e-161) tmp = Float64(fma(y, Float64(y * -4.0), Float64(x * x)) / fma(x, x, t_0)); elseif (x <= 6.2e-38) tmp = t_2; elseif (x <= 1.75e+42) tmp = t_1; elseif (x <= 1.66e+87) tmp = t_2; elseif (x <= 2.15e+146) tmp = t_1; else tmp = fma(-8.0, Float64(Float64(y / x) * Float64(y / x)), 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[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] * 0.5 + -1.0), $MachinePrecision]}, If[LessEqual[x, -8.5e+113], N[(N[(y * N[(N[(-4.0 / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, -1.15e-161], N[(N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(x * x + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.2e-38], t$95$2, If[LessEqual[x, 1.75e+42], t$95$1, If[LessEqual[x, 1.66e+87], t$95$2, If[LessEqual[x, 2.15e+146], t$95$1, N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $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)\\
t_1 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + t_0}\\
t_2 := \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, -1\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{+113}:\\
\;\;\;\;y \cdot \left(\frac{-4}{x} \cdot \frac{y}{x}\right) + 1\\
\mathbf{elif}\;x \leq -1.15 \cdot 10^{-161}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, t_0\right)}\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-38}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{+42}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.66 \cdot 10^{+87}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 2.15 \cdot 10^{+146}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-8, \frac{y}{x} \cdot \frac{y}{x}, 1\right)\\
\end{array}
| Original | 31.5 |
|---|---|
| Target | 31.3 |
| Herbie | 13.1 |
if x < -8.5000000000000001e113Initial program 54.5
Taylor expanded in x around inf 55.0
Simplified55.0
[Start]55.0 | \[ \frac{{x}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
unpow2 [=>]55.0 | \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
Taylor expanded in x around inf 16.6
Simplified16.6
[Start]16.6 | \[ 1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate-*r/ [=>]16.6 | \[ 1 + \color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}}
\] |
unpow2 [=>]16.6 | \[ 1 + \frac{-4 \cdot \color{blue}{\left(y \cdot y\right)}}{{x}^{2}}
\] |
unpow2 [=>]16.6 | \[ 1 + \frac{-4 \cdot \left(y \cdot y\right)}{\color{blue}{x \cdot x}}
\] |
Taylor expanded in y around 0 16.6
Simplified10.4
[Start]16.6 | \[ 1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
+-commutative [=>]16.6 | \[ \color{blue}{-4 \cdot \frac{{y}^{2}}{{x}^{2}} + 1}
\] |
associate-*r/ [=>]16.6 | \[ \color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}} + 1
\] |
unpow2 [=>]16.6 | \[ \frac{-4 \cdot \color{blue}{\left(y \cdot y\right)}}{{x}^{2}} + 1
\] |
associate-*r* [=>]16.6 | \[ \frac{\color{blue}{\left(-4 \cdot y\right) \cdot y}}{{x}^{2}} + 1
\] |
unpow2 [=>]16.6 | \[ \frac{\left(-4 \cdot y\right) \cdot y}{\color{blue}{x \cdot x}} + 1
\] |
associate-*l/ [<=]10.8 | \[ \color{blue}{\frac{-4 \cdot y}{x \cdot x} \cdot y} + 1
\] |
*-commutative [=>]10.8 | \[ \color{blue}{y \cdot \frac{-4 \cdot y}{x \cdot x}} + 1
\] |
times-frac [=>]10.4 | \[ y \cdot \color{blue}{\left(\frac{-4}{x} \cdot \frac{y}{x}\right)} + 1
\] |
if -8.5000000000000001e113 < x < -1.15e-161Initial program 15.5
Simplified15.5
[Start]15.5 | \[ \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 [=>]15.5 | \[ \frac{\color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [=>]15.5 | \[ \frac{\color{blue}{\left(-y \cdot 4\right) \cdot y + x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]15.5 | \[ \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 [=>]15.5 | \[ \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 [=>]15.5 | \[ \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 [=>]15.5 | \[ \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 [=>]15.5 | \[ \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 [=>]15.5 | \[ \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)}
\] |
if -1.15e-161 < x < 6.19999999999999966e-38 or 1.75000000000000012e42 < x < 1.65999999999999994e87Initial program 26.6
Simplified26.6
[Start]26.6 | \[ \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 [=>]26.6 | \[ \frac{\color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [=>]26.6 | \[ \frac{\color{blue}{\left(-y \cdot 4\right) \cdot y + x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]26.6 | \[ \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 [=>]26.6 | \[ \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 [=>]26.6 | \[ \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 [=>]26.6 | \[ \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 [=>]26.6 | \[ \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 [=>]26.6 | \[ \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 19.2
Simplified13.9
[Start]19.2 | \[ 0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - \left(-0.25 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right)
\] |
|---|---|
associate--r+ [=>]19.2 | \[ \color{blue}{\left(0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - -0.25 \cdot \frac{{x}^{2}}{{y}^{2}}\right) - 1}
\] |
distribute-rgt-out-- [=>]19.2 | \[ \color{blue}{\frac{{x}^{2}}{{y}^{2}} \cdot \left(0.25 - -0.25\right)} - 1
\] |
metadata-eval [=>]19.2 | \[ \frac{{x}^{2}}{{y}^{2}} \cdot \color{blue}{0.5} - 1
\] |
fma-neg [=>]19.2 | \[ \color{blue}{\mathsf{fma}\left(\frac{{x}^{2}}{{y}^{2}}, 0.5, -1\right)}
\] |
unpow2 [=>]19.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{x \cdot x}}{{y}^{2}}, 0.5, -1\right)
\] |
unpow2 [=>]19.2 | \[ \mathsf{fma}\left(\frac{x \cdot x}{\color{blue}{y \cdot y}}, 0.5, -1\right)
\] |
times-frac [=>]13.9 | \[ \mathsf{fma}\left(\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, 0.5, -1\right)
\] |
metadata-eval [=>]13.9 | \[ \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, \color{blue}{-1}\right)
\] |
if 6.19999999999999966e-38 < x < 1.75000000000000012e42 or 1.65999999999999994e87 < x < 2.1499999999999999e146Initial program 14.3
if 2.1499999999999999e146 < x Initial program 62.1
Simplified62.1
[Start]62.1 | \[ \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 [=>]62.1 | \[ \frac{\color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [=>]62.1 | \[ \frac{\color{blue}{\left(-y \cdot 4\right) \cdot y + x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]62.1 | \[ \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 [=>]62.1 | \[ \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 [=>]62.1 | \[ \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 [=>]62.1 | \[ \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 [=>]62.1 | \[ \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 [=>]62.1 | \[ \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 0 16.9
Simplified8.8
[Start]16.9 | \[ -8 \cdot \frac{{y}^{2}}{{x}^{2}} + 1
\] |
|---|---|
fma-def [=>]16.9 | \[ \color{blue}{\mathsf{fma}\left(-8, \frac{{y}^{2}}{{x}^{2}}, 1\right)}
\] |
unpow2 [=>]16.9 | \[ \mathsf{fma}\left(-8, \frac{\color{blue}{y \cdot y}}{{x}^{2}}, 1\right)
\] |
unpow2 [=>]16.9 | \[ \mathsf{fma}\left(-8, \frac{y \cdot y}{\color{blue}{x \cdot x}}, 1\right)
\] |
times-frac [=>]8.8 | \[ \mathsf{fma}\left(-8, \color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, 1\right)
\] |
Final simplification13.1
| Alternative 1 | |
|---|---|
| Error | 13.3 |
| Cost | 7768 |
| Alternative 2 | |
|---|---|
| Error | 13.1 |
| Cost | 7768 |
| Alternative 3 | |
|---|---|
| Error | 17.2 |
| Cost | 2524 |
| Alternative 4 | |
|---|---|
| Error | 17.2 |
| Cost | 2524 |
| Alternative 5 | |
|---|---|
| Error | 13.3 |
| Cost | 2008 |
| Alternative 6 | |
|---|---|
| Error | 17.4 |
| Cost | 1884 |
| Alternative 7 | |
|---|---|
| Error | 16.6 |
| Cost | 592 |
| Alternative 8 | |
|---|---|
| Error | 31.9 |
| Cost | 64 |
herbie shell --seed 2023027
(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))))