| Alternative 1 | |
|---|---|
| Error | 13.3 |
| 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 (/ (+ (* x x) (* y (* y -4.0))) (+ t_0 (* x x))))
(t_2 (fma (* 2.0 (log (fma 0.5 (pow (/ y x) 2.0) 1.0))) -8.0 1.0)))
(if (<= t_0 1e-312)
t_2
(if (<= t_0 4e-248)
t_1
(if (<= t_0 4e-40)
t_2
(if (<= t_0 2e+279) t_1 (fma (* (/ x y) (/ x y)) 0.5 -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))) / (t_0 + (x * x));
double t_2 = fma((2.0 * log(fma(0.5, pow((y / x), 2.0), 1.0))), -8.0, 1.0);
double tmp;
if (t_0 <= 1e-312) {
tmp = t_2;
} else if (t_0 <= 4e-248) {
tmp = t_1;
} else if (t_0 <= 4e-40) {
tmp = t_2;
} else if (t_0 <= 2e+279) {
tmp = t_1;
} else {
tmp = fma(((x / y) * (x / y)), 0.5, -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(t_0 + Float64(x * x))) t_2 = fma(Float64(2.0 * log(fma(0.5, (Float64(y / x) ^ 2.0), 1.0))), -8.0, 1.0) tmp = 0.0 if (t_0 <= 1e-312) tmp = t_2; elseif (t_0 <= 4e-248) tmp = t_1; elseif (t_0 <= 4e-40) tmp = t_2; elseif (t_0 <= 2e+279) tmp = t_1; else tmp = fma(Float64(Float64(x / y) * Float64(x / y)), 0.5, -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[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 * N[Log[N[(0.5 * N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-312], t$95$2, If[LessEqual[t$95$0, 4e-248], t$95$1, If[LessEqual[t$95$0, 4e-40], t$95$2, If[LessEqual[t$95$0, 2e+279], t$95$1, N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] * 0.5 + -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)}{t_0 + x \cdot x}\\
t_2 := \mathsf{fma}\left(2 \cdot \log \left(\mathsf{fma}\left(0.5, {\left(\frac{y}{x}\right)}^{2}, 1\right)\right), -8, 1\right)\\
\mathbf{if}\;t_0 \leq 10^{-312}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-248}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-40}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+279}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, -1\right)\\
\end{array}
| Original | 31.5 |
|---|---|
| Target | 31.2 |
| Herbie | 13.0 |
if (*.f64 (*.f64 y 4) y) < 9.9999999999847e-313 or 3.99999999999999992e-248 < (*.f64 (*.f64 y 4) y) < 3.9999999999999997e-40Initial program 24.8
Simplified25.0
[Start]24.8 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]24.8 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]24.8 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{y \cdot \left(y \cdot 4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
associate-*r* [=>]25.0 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{\left(y \cdot y\right) \cdot 4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
distribute-rgt-neg-in [=>]25.0 | \[ \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(-4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
metadata-eval [=>]25.0 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot \color{blue}{-4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]25.0 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]25.0 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in x around inf 18.7
Simplified14.3
[Start]18.7 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]18.7 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
+-commutative [=>]18.7 | \[ \color{blue}{\left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + 1}
\] |
distribute-rgt-out-- [=>]18.7 | \[ \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot \left(-4 - 4\right)} + 1
\] |
metadata-eval [=>]18.7 | \[ \frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-8} + 1
\] |
fma-def [=>]18.7 | \[ \color{blue}{\mathsf{fma}\left(\frac{{y}^{2}}{{x}^{2}}, -8, 1\right)}
\] |
unpow2 [=>]18.7 | \[ \mathsf{fma}\left(\frac{\color{blue}{y \cdot y}}{{x}^{2}}, -8, 1\right)
\] |
unpow2 [=>]18.7 | \[ \mathsf{fma}\left(\frac{y \cdot y}{\color{blue}{x \cdot x}}, -8, 1\right)
\] |
times-frac [=>]14.3 | \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right)
\] |
Applied egg-rr14.9
Applied egg-rr14.9
Simplified14.9
[Start]14.9 | \[ \mathsf{fma}\left(\log \left(\sqrt{e^{{\left(\frac{y}{x}\right)}^{2}}}\right) + \log \left(\sqrt{e^{{\left(\frac{y}{x}\right)}^{2}}}\right), -8, 1\right)
\] |
|---|---|
count-2 [=>]14.9 | \[ \mathsf{fma}\left(\color{blue}{2 \cdot \log \left(\sqrt{e^{{\left(\frac{y}{x}\right)}^{2}}}\right)}, -8, 1\right)
\] |
Taylor expanded in y around 0 18.4
Simplified13.5
[Start]18.4 | \[ \mathsf{fma}\left(2 \cdot \log \left(1 + 0.5 \cdot \frac{{y}^{2}}{{x}^{2}}\right), -8, 1\right)
\] |
|---|---|
+-commutative [=>]18.4 | \[ \mathsf{fma}\left(2 \cdot \log \color{blue}{\left(0.5 \cdot \frac{{y}^{2}}{{x}^{2}} + 1\right)}, -8, 1\right)
\] |
unpow2 [=>]18.4 | \[ \mathsf{fma}\left(2 \cdot \log \left(0.5 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} + 1\right), -8, 1\right)
\] |
unpow2 [=>]18.4 | \[ \mathsf{fma}\left(2 \cdot \log \left(0.5 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} + 1\right), -8, 1\right)
\] |
times-frac [=>]13.5 | \[ \mathsf{fma}\left(2 \cdot \log \left(0.5 \cdot \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)} + 1\right), -8, 1\right)
\] |
unpow2 [<=]13.5 | \[ \mathsf{fma}\left(2 \cdot \log \left(0.5 \cdot \color{blue}{{\left(\frac{y}{x}\right)}^{2}} + 1\right), -8, 1\right)
\] |
fma-def [=>]13.5 | \[ \mathsf{fma}\left(2 \cdot \log \color{blue}{\left(\mathsf{fma}\left(0.5, {\left(\frac{y}{x}\right)}^{2}, 1\right)\right)}, -8, 1\right)
\] |
if 9.9999999999847e-313 < (*.f64 (*.f64 y 4) y) < 3.99999999999999992e-248 or 3.9999999999999997e-40 < (*.f64 (*.f64 y 4) y) < 2.00000000000000012e279Initial program 16.1
if 2.00000000000000012e279 < (*.f64 (*.f64 y 4) y) Initial program 59.9
Simplified59.9
[Start]59.9 | \[ \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 [=>]59.9 | \[ \frac{\color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
+-commutative [=>]59.9 | \[ \frac{\color{blue}{\left(-y \cdot 4\right) \cdot y + x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]59.9 | \[ \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 [=>]59.9 | \[ \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 [=>]59.9 | \[ \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 [=>]59.9 | \[ \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 [=>]59.9 | \[ \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 [=>]59.9 | \[ \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 16.7
Simplified8.5
[Start]16.7 | \[ 0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - \left(-0.25 \cdot \frac{{x}^{2}}{{y}^{2}} + 1\right)
\] |
|---|---|
associate--r+ [=>]16.7 | \[ \color{blue}{\left(0.25 \cdot \frac{{x}^{2}}{{y}^{2}} - -0.25 \cdot \frac{{x}^{2}}{{y}^{2}}\right) - 1}
\] |
distribute-rgt-out-- [=>]16.7 | \[ \color{blue}{\frac{{x}^{2}}{{y}^{2}} \cdot \left(0.25 - -0.25\right)} - 1
\] |
metadata-eval [=>]16.7 | \[ \frac{{x}^{2}}{{y}^{2}} \cdot \color{blue}{0.5} - 1
\] |
fma-neg [=>]16.7 | \[ \color{blue}{\mathsf{fma}\left(\frac{{x}^{2}}{{y}^{2}}, 0.5, -1\right)}
\] |
unpow2 [=>]16.7 | \[ \mathsf{fma}\left(\frac{\color{blue}{x \cdot x}}{{y}^{2}}, 0.5, -1\right)
\] |
unpow2 [=>]16.7 | \[ \mathsf{fma}\left(\frac{x \cdot x}{\color{blue}{y \cdot y}}, 0.5, -1\right)
\] |
times-frac [=>]8.5 | \[ \mathsf{fma}\left(\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, 0.5, -1\right)
\] |
metadata-eval [=>]8.5 | \[ \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, \color{blue}{-1}\right)
\] |
Final simplification13.0
| Alternative 1 | |
|---|---|
| Error | 13.3 |
| Cost | 8528 |
| Alternative 2 | |
|---|---|
| Error | 13.3 |
| Cost | 2768 |
| Alternative 3 | |
|---|---|
| Error | 16.2 |
| Cost | 1233 |
| Alternative 4 | |
|---|---|
| Error | 16.5 |
| Cost | 1232 |
| Alternative 5 | |
|---|---|
| Error | 16.7 |
| Cost | 592 |
| Alternative 6 | |
|---|---|
| Error | 31.9 |
| Cost | 64 |
herbie shell --seed 2023187
(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))))