| Alternative 1 | |
|---|---|
| Error | 14.9 |
| Cost | 3544 |
(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)) (- (* y (* y -4.0)) (* x x)))
(/ x (- (/ (* y -4.0) (/ x y)) x)))))
(if (<= y -6.6e+153)
(+ (* (/ x y) (/ x (* y 4.0))) -1.0)
(if (<= y -1.2e-145)
t_0
(if (<= y 3.5e-177)
(- 1.0 (* (/ y x) (/ (* y 4.0) x)))
(if (<= y 1.05e+139) t_0 (+ (* (/ (/ 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)) / ((y * (y * -4.0)) - (x * x))) - (x / (((y * -4.0) / (x / y)) - x));
double tmp;
if (y <= -6.6e+153) {
tmp = ((x / y) * (x / (y * 4.0))) + -1.0;
} else if (y <= -1.2e-145) {
tmp = t_0;
} else if (y <= 3.5e-177) {
tmp = 1.0 - ((y / x) * ((y * 4.0) / x));
} else if (y <= 1.05e+139) {
tmp = t_0;
} else {
tmp = (((x / (y / x)) / y) * 0.5) + -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) - ((y * 4.0d0) * y)) / ((x * x) + ((y * 4.0d0) * y))
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = ((y * (y * 4.0d0)) / ((y * (y * (-4.0d0))) - (x * x))) - (x / (((y * (-4.0d0)) / (x / y)) - x))
if (y <= (-6.6d+153)) then
tmp = ((x / y) * (x / (y * 4.0d0))) + (-1.0d0)
else if (y <= (-1.2d-145)) then
tmp = t_0
else if (y <= 3.5d-177) then
tmp = 1.0d0 - ((y / x) * ((y * 4.0d0) / x))
else if (y <= 1.05d+139) then
tmp = t_0
else
tmp = (((x / (y / x)) / y) * 0.5d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
public static double code(double x, double y) {
double t_0 = ((y * (y * 4.0)) / ((y * (y * -4.0)) - (x * x))) - (x / (((y * -4.0) / (x / y)) - x));
double tmp;
if (y <= -6.6e+153) {
tmp = ((x / y) * (x / (y * 4.0))) + -1.0;
} else if (y <= -1.2e-145) {
tmp = t_0;
} else if (y <= 3.5e-177) {
tmp = 1.0 - ((y / x) * ((y * 4.0) / x));
} else if (y <= 1.05e+139) {
tmp = t_0;
} else {
tmp = (((x / (y / x)) / y) * 0.5) + -1.0;
}
return tmp;
}
def code(x, y): return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))
def code(x, y): t_0 = ((y * (y * 4.0)) / ((y * (y * -4.0)) - (x * x))) - (x / (((y * -4.0) / (x / y)) - x)) tmp = 0 if y <= -6.6e+153: tmp = ((x / y) * (x / (y * 4.0))) + -1.0 elif y <= -1.2e-145: tmp = t_0 elif y <= 3.5e-177: tmp = 1.0 - ((y / x) * ((y * 4.0) / x)) elif y <= 1.05e+139: tmp = t_0 else: tmp = (((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(Float64(Float64(y * Float64(y * 4.0)) / Float64(Float64(y * Float64(y * -4.0)) - Float64(x * x))) - Float64(x / Float64(Float64(Float64(y * -4.0) / Float64(x / y)) - x))) tmp = 0.0 if (y <= -6.6e+153) tmp = Float64(Float64(Float64(x / y) * Float64(x / Float64(y * 4.0))) + -1.0); elseif (y <= -1.2e-145) tmp = t_0; elseif (y <= 3.5e-177) tmp = Float64(1.0 - Float64(Float64(y / x) * Float64(Float64(y * 4.0) / x))); elseif (y <= 1.05e+139) tmp = t_0; else tmp = Float64(Float64(Float64(Float64(x / Float64(y / x)) / y) * 0.5) + -1.0); end return tmp end
function tmp = code(x, y) tmp = ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)); end
function tmp_2 = code(x, y) t_0 = ((y * (y * 4.0)) / ((y * (y * -4.0)) - (x * x))) - (x / (((y * -4.0) / (x / y)) - x)); tmp = 0.0; if (y <= -6.6e+153) tmp = ((x / y) * (x / (y * 4.0))) + -1.0; elseif (y <= -1.2e-145) tmp = t_0; elseif (y <= 3.5e-177) tmp = 1.0 - ((y / x) * ((y * 4.0) / x)); elseif (y <= 1.05e+139) tmp = t_0; else tmp = (((x / (y / x)) / y) * 0.5) + -1.0; end tmp_2 = 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[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision] / N[(N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x / N[(N[(N[(y * -4.0), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.6e+153], N[(N[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, -1.2e-145], t$95$0, If[LessEqual[y, 3.5e-177], N[(1.0 - N[(N[(y / x), $MachinePrecision] * N[(N[(y * 4.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.05e+139], t$95$0, N[(N[(N[(N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] * 0.5), $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 := \frac{y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot -4\right) - x \cdot x} - \frac{x}{\frac{y \cdot -4}{\frac{x}{y}} - x}\\
\mathbf{if}\;y \leq -6.6 \cdot 10^{+153}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\
\mathbf{elif}\;y \leq -1.2 \cdot 10^{-145}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-177}:\\
\;\;\;\;1 - \frac{y}{x} \cdot \frac{y \cdot 4}{x}\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+139}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{\frac{y}{x}}}{y} \cdot 0.5 + -1\\
\end{array}
Results
| Original | 32.2 |
|---|---|
| Target | 31.9 |
| Herbie | 4.3 |
if y < -6.59999999999999989e153Initial program 64.0
Taylor expanded in x around 0 64.0
Simplified64.0
[Start]64.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{4 \cdot {y}^{2}}
\] |
|---|---|
*-commutative [=>]64.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{{y}^{2} \cdot 4}}
\] |
unpow2 [=>]64.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\left(y \cdot y\right)} \cdot 4}
\] |
associate-*r* [<=]64.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}}
\] |
Applied egg-rr7.1
if -6.59999999999999989e153 < y < -1.20000000000000008e-145 or 3.5000000000000002e-177 < y < 1.0499999999999999e139Initial program 16.6
Applied egg-rr17.0
Applied egg-rr16.6
Simplified16.2
[Start]16.6 | \[ \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.6 | \[ \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.2 | \[ \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}
\] |
Applied egg-rr0.5
if -1.20000000000000008e-145 < y < 3.5000000000000002e-177Initial program 31.2
Taylor expanded in x around inf 31.9
Simplified31.9
[Start]31.9 | \[ \frac{{x}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
unpow2 [=>]31.9 | \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
Taylor expanded in x around inf 15.9
Simplified15.9
[Start]15.9 | \[ 1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate-*r/ [=>]15.9 | \[ 1 + \color{blue}{\frac{-4 \cdot {y}^{2}}{{x}^{2}}}
\] |
unpow2 [=>]15.9 | \[ 1 + \frac{-4 \cdot \color{blue}{\left(y \cdot y\right)}}{{x}^{2}}
\] |
unpow2 [=>]15.9 | \[ 1 + \frac{-4 \cdot \left(y \cdot y\right)}{\color{blue}{x \cdot x}}
\] |
Applied egg-rr8.8
if 1.0499999999999999e139 < y Initial program 60.0
Simplified60.0
[Start]60.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]60.0 | \[ \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 [=>]60.0 | \[ \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* [=>]60.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 [=>]60.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 [=>]60.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 [=>]60.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 [=>]60.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 0 15.5
Simplified7.6
[Start]15.5 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]15.5 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]15.5 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]15.5 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]7.6 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]7.6 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
Applied egg-rr7.6
Applied egg-rr7.7
Final simplification4.3
| Alternative 1 | |
|---|---|
| Error | 14.9 |
| Cost | 3544 |
| Alternative 2 | |
|---|---|
| Error | 17.8 |
| Cost | 1762 |
| Alternative 3 | |
|---|---|
| Error | 17.9 |
| Cost | 1761 |
| Alternative 4 | |
|---|---|
| Error | 17.8 |
| Cost | 1760 |
| Alternative 5 | |
|---|---|
| Error | 16.9 |
| Cost | 1233 |
| Alternative 6 | |
|---|---|
| Error | 17.1 |
| Cost | 592 |
| Alternative 7 | |
|---|---|
| Error | 31.2 |
| Cost | 64 |
herbie shell --seed 2023046
(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))))