| Alternative 1 | |
|---|---|
| Error | 4.6 |
| Cost | 7372 |
(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) (* (/ x y) (/ x 4.0))))
(/ x (/ (- (* (* y y) -4.0) (* x x)) x))))
(t_1 (+ 1.0 (* (* y (/ (/ y x) x)) -8.0))))
(if (<= x -1.35e+154)
t_1
(if (<= x -2.3e-116)
t_0
(if (<= x 7e-171)
(fma 0.5 (exp (log (pow (/ x y) 2.0))) -1.0)
(if (<= x 4.6e+152) t_0 t_1))))))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 - ((x / y) * (x / 4.0)))) - (x / ((((y * y) * -4.0) - (x * x)) / x));
double t_1 = 1.0 + ((y * ((y / x) / x)) * -8.0);
double tmp;
if (x <= -1.35e+154) {
tmp = t_1;
} else if (x <= -2.3e-116) {
tmp = t_0;
} else if (x <= 7e-171) {
tmp = fma(0.5, exp(log(pow((x / y), 2.0))), -1.0);
} else if (x <= 4.6e+152) {
tmp = t_0;
} else {
tmp = t_1;
}
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(y / Float64(Float64(-y) - Float64(Float64(x / y) * Float64(x / 4.0)))) - Float64(x / Float64(Float64(Float64(Float64(y * y) * -4.0) - Float64(x * x)) / x))) t_1 = Float64(1.0 + Float64(Float64(y * Float64(Float64(y / x) / x)) * -8.0)) tmp = 0.0 if (x <= -1.35e+154) tmp = t_1; elseif (x <= -2.3e-116) tmp = t_0; elseif (x <= 7e-171) tmp = fma(0.5, exp(log((Float64(x / y) ^ 2.0))), -1.0); elseif (x <= 4.6e+152) tmp = t_0; else tmp = t_1; 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[(y / N[((-y) - N[(N[(x / y), $MachinePrecision] * N[(x / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x / N[(N[(N[(N[(y * y), $MachinePrecision] * -4.0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(y * N[(N[(y / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] * -8.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.35e+154], t$95$1, If[LessEqual[x, -2.3e-116], t$95$0, If[LessEqual[x, 7e-171], N[(0.5 * N[Exp[N[Log[N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[x, 4.6e+152], t$95$0, t$95$1]]]]]]
\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 := \frac{y}{\left(-y\right) - \frac{x}{y} \cdot \frac{x}{4}} - \frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\\
t_1 := 1 + \left(y \cdot \frac{\frac{y}{x}}{x}\right) \cdot -8\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{-116}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-171}:\\
\;\;\;\;\mathsf{fma}\left(0.5, e^{\log \left({\left(\frac{x}{y}\right)}^{2}\right)}, -1\right)\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{+152}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
| Original | 31.8 |
|---|---|
| Target | 31.6 |
| Herbie | 4.6 |
if x < -1.35000000000000003e154 or 4.5999999999999997e152 < x Initial program 63.9
Taylor expanded in x around inf 17.7
Simplified17.7
[Start]17.7 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]17.7 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
unpow2 [=>]17.7 | \[ 1 + \left(-4 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
unpow2 [=>]17.7 | \[ 1 + \left(-4 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)
\] |
associate-*r/ [=>]17.7 | \[ 1 + \left(-4 \cdot \frac{y \cdot y}{x \cdot x} - \color{blue}{\frac{4 \cdot {y}^{2}}{{x}^{2}}}\right)
\] |
*-commutative [=>]17.7 | \[ 1 + \left(-4 \cdot \frac{y \cdot y}{x \cdot x} - \frac{\color{blue}{{y}^{2} \cdot 4}}{{x}^{2}}\right)
\] |
unpow2 [=>]17.7 | \[ 1 + \left(-4 \cdot \frac{y \cdot y}{x \cdot x} - \frac{\color{blue}{\left(y \cdot y\right)} \cdot 4}{{x}^{2}}\right)
\] |
associate-*r* [<=]17.7 | \[ 1 + \left(-4 \cdot \frac{y \cdot y}{x \cdot x} - \frac{\color{blue}{y \cdot \left(y \cdot 4\right)}}{{x}^{2}}\right)
\] |
unpow2 [=>]17.7 | \[ 1 + \left(-4 \cdot \frac{y \cdot y}{x \cdot x} - \frac{y \cdot \left(y \cdot 4\right)}{\color{blue}{x \cdot x}}\right)
\] |
Taylor expanded in y around 0 17.7
Simplified8.5
[Start]17.7 | \[ 1 + -8 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
*-commutative [=>]17.7 | \[ 1 + \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot -8}
\] |
unpow2 [=>]17.7 | \[ 1 + \frac{\color{blue}{y \cdot y}}{{x}^{2}} \cdot -8
\] |
unpow2 [=>]17.7 | \[ 1 + \frac{y \cdot y}{\color{blue}{x \cdot x}} \cdot -8
\] |
associate-*r/ [<=]9.1 | \[ 1 + \color{blue}{\left(y \cdot \frac{y}{x \cdot x}\right)} \cdot -8
\] |
associate-/r* [=>]8.5 | \[ 1 + \left(y \cdot \color{blue}{\frac{\frac{y}{x}}{x}}\right) \cdot -8
\] |
if -1.35000000000000003e154 < x < -2.30000000000000002e-116 or 6.99999999999999988e-171 < x < 4.5999999999999997e152Initial program 16.7
Applied egg-rr17.1
Applied egg-rr16.7
Simplified16.4
[Start]16.7 | \[ \left(0 - \frac{x \cdot x}{y \cdot \left(y \cdot -4\right) - x \cdot x}\right) - \frac{y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot -4\right) - x \cdot x}
\] |
|---|---|
sub0-neg [=>]16.7 | \[ \color{blue}{\left(-\frac{x \cdot x}{y \cdot \left(y \cdot -4\right) - x \cdot x}\right)} - \frac{y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot -4\right) - x \cdot x}
\] |
associate-/l* [=>]16.9 | \[ \left(-\color{blue}{\frac{x}{\frac{y \cdot \left(y \cdot -4\right) - x \cdot x}{x}}}\right) - \frac{y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot -4\right) - x \cdot x}
\] |
associate-*r* [=>]16.9 | \[ \left(-\frac{x}{\frac{\color{blue}{\left(y \cdot y\right) \cdot -4} - x \cdot x}{x}}\right) - \frac{y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot -4\right) - x \cdot x}
\] |
associate-/l* [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \color{blue}{\frac{y}{\frac{y \cdot \left(y \cdot -4\right) - x \cdot x}{y \cdot -4}}}
\] |
associate-*r* [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{y}{\frac{\color{blue}{\left(y \cdot y\right) \cdot -4} - x \cdot x}{y \cdot -4}}
\] |
Applied egg-rr16.5
Simplified0.3
[Start]16.5 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \left(-y\right) \cdot \frac{1}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \left(-\frac{-0.25}{y}\right)}
\] |
|---|---|
associate-*r/ [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \color{blue}{\frac{\left(-y\right) \cdot 1}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \left(-\frac{-0.25}{y}\right)}}
\] |
*-rgt-identity [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{\color{blue}{-y}}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \left(-\frac{-0.25}{y}\right)}
\] |
distribute-neg-frac [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \color{blue}{\frac{--0.25}{y}}}
\] |
metadata-eval [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \frac{\color{blue}{0.25}}{y}}
\] |
metadata-eval [<=]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \frac{\color{blue}{\frac{1}{4}}}{y}}
\] |
associate-/r* [<=]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \color{blue}{\frac{1}{4 \cdot y}}}
\] |
*-commutative [<=]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot \frac{1}{\color{blue}{y \cdot 4}}}
\] |
associate-*r/ [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\color{blue}{\frac{\left(y \cdot \left(y \cdot -4\right) - x \cdot x\right) \cdot 1}{y \cdot 4}}}
\] |
*-rgt-identity [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\frac{\color{blue}{y \cdot \left(y \cdot -4\right) - x \cdot x}}{y \cdot 4}}
\] |
div-sub [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\color{blue}{\frac{y \cdot \left(y \cdot -4\right)}{y \cdot 4} - \frac{x \cdot x}{y \cdot 4}}}
\] |
associate-*r* [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\frac{\color{blue}{\left(y \cdot y\right) \cdot -4}}{y \cdot 4} - \frac{x \cdot x}{y \cdot 4}}
\] |
times-frac [=>]16.4 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\color{blue}{\frac{y \cdot y}{y} \cdot \frac{-4}{4}} - \frac{x \cdot x}{y \cdot 4}}
\] |
associate-/l* [=>]0.3 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\color{blue}{\frac{y}{\frac{y}{y}}} \cdot \frac{-4}{4} - \frac{x \cdot x}{y \cdot 4}}
\] |
*-inverses [=>]0.3 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\frac{y}{\color{blue}{1}} \cdot \frac{-4}{4} - \frac{x \cdot x}{y \cdot 4}}
\] |
/-rgt-identity [=>]0.3 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\color{blue}{y} \cdot \frac{-4}{4} - \frac{x \cdot x}{y \cdot 4}}
\] |
metadata-eval [=>]0.3 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{y \cdot \color{blue}{-1} - \frac{x \cdot x}{y \cdot 4}}
\] |
*-commutative [<=]0.3 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\color{blue}{-1 \cdot y} - \frac{x \cdot x}{y \cdot 4}}
\] |
neg-mul-1 [<=]0.3 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\color{blue}{\left(-y\right)} - \frac{x \cdot x}{y \cdot 4}}
\] |
times-frac [=>]0.3 | \[ \left(-\frac{x}{\frac{\left(y \cdot y\right) \cdot -4 - x \cdot x}{x}}\right) - \frac{-y}{\left(-y\right) - \color{blue}{\frac{x}{y} \cdot \frac{x}{4}}}
\] |
if -2.30000000000000002e-116 < x < 6.99999999999999988e-171Initial program 29.3
Taylor expanded in x around 0 16.0
Simplified9.3
[Start]16.0 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]16.0 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]16.0 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]16.0 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
associate-/r* [=>]9.3 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{\frac{x \cdot x}{y}}{y}}, -1\right)
\] |
metadata-eval [=>]9.3 | \[ \mathsf{fma}\left(0.5, \frac{\frac{x \cdot x}{y}}{y}, \color{blue}{-1}\right)
\] |
Applied egg-rr8.7
Final simplification4.6
| Alternative 1 | |
|---|---|
| Error | 4.6 |
| Cost | 7372 |
| Alternative 2 | |
|---|---|
| Error | 12.7 |
| Cost | 2896 |
| Alternative 3 | |
|---|---|
| Error | 12.7 |
| Cost | 2768 |
| Alternative 4 | |
|---|---|
| Error | 16.4 |
| Cost | 2645 |
| Alternative 5 | |
|---|---|
| Error | 4.7 |
| Cost | 2192 |
| Alternative 6 | |
|---|---|
| Error | 16.6 |
| Cost | 1232 |
| Alternative 7 | |
|---|---|
| Error | 17.7 |
| Cost | 856 |
| Alternative 8 | |
|---|---|
| Error | 31.5 |
| Cost | 64 |
herbie shell --seed 2023073
(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))))