| Alternative 1 | |
|---|---|
| Accuracy | 78.9% |
| 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
(+
(/ x (+ x (* (/ 1.0 x) (* 4.0 (* y y)))))
(/ (* y (* y -4.0)) (fma x x (* y (* y 4.0)))))))
(if (<= y -7e+153)
(+ (* (/ x y) (/ x (* y 4.0))) -1.0)
(if (<= y -1.85e-141)
t_0
(if (<= y 4e-189)
(fma (* (/ y x) (/ y x)) -8.0 1.0)
(if (<= y 6.6e+153) t_0 (fma 0.5 (* (/ x y) (/ x y)) -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 = (x / (x + ((1.0 / x) * (4.0 * (y * y))))) + ((y * (y * -4.0)) / fma(x, x, (y * (y * 4.0))));
double tmp;
if (y <= -7e+153) {
tmp = ((x / y) * (x / (y * 4.0))) + -1.0;
} else if (y <= -1.85e-141) {
tmp = t_0;
} else if (y <= 4e-189) {
tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
} else if (y <= 6.6e+153) {
tmp = t_0;
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -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(x / Float64(x + Float64(Float64(1.0 / x) * Float64(4.0 * Float64(y * y))))) + Float64(Float64(y * Float64(y * -4.0)) / fma(x, x, Float64(y * Float64(y * 4.0))))) tmp = 0.0 if (y <= -7e+153) tmp = Float64(Float64(Float64(x / y) * Float64(x / Float64(y * 4.0))) + -1.0); elseif (y <= -1.85e-141) tmp = t_0; elseif (y <= 4e-189) tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0); elseif (y <= 6.6e+153) tmp = t_0; else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -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[(N[(x / N[(x + N[(N[(1.0 / x), $MachinePrecision] * N[(4.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision] / N[(x * x + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7e+153], N[(N[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, -1.85e-141], t$95$0, If[LessEqual[y, 4e-189], N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision], If[LessEqual[y, 6.6e+153], t$95$0, N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $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 := \frac{x}{x + \frac{1}{x} \cdot \left(4 \cdot \left(y \cdot y\right)\right)} + \frac{y \cdot \left(y \cdot -4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\
\mathbf{if}\;y \leq -7 \cdot 10^{+153}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y \cdot 4} + -1\\
\mathbf{elif}\;y \leq -1.85 \cdot 10^{-141}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-189}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{+153}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
| Original | 51.0% |
|---|---|
| Target | 51.4% |
| Herbie | 93.5% |
if y < -6.9999999999999998e153Initial program 0.0%
Taylor expanded in x around 0 0.0%
Simplified0.0%
[Start]0.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{4 \cdot {y}^{2}}
\] |
|---|---|
*-commutative [=>]0.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{{y}^{2} \cdot 4}}
\] |
unpow2 [=>]0.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\left(y \cdot y\right)} \cdot 4}
\] |
associate-*r* [<=]0.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}}
\] |
Applied egg-rr88.0%
[Start]0.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{y \cdot \left(y \cdot 4\right)}
\] |
|---|---|
*-commutative [<=]0.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\left(y \cdot 4\right) \cdot y}}
\] |
div-sub [=>]0.0 | \[ \color{blue}{\frac{x \cdot x}{\left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}}
\] |
*-commutative [=>]0.0 | \[ \frac{x \cdot x}{\color{blue}{y \cdot \left(y \cdot 4\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}
\] |
times-frac [=>]0.0 | \[ \color{blue}{\frac{x}{y} \cdot \frac{x}{y \cdot 4}} - \frac{\left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}
\] |
*-inverses [=>]88.0 | \[ \frac{x}{y} \cdot \frac{x}{y \cdot 4} - \color{blue}{1}
\] |
if -6.9999999999999998e153 < y < -1.85e-141 or 4.00000000000000027e-189 < y < 6.59999999999999989e153Initial program 74.1%
Applied egg-rr73.7%
[Start]74.1 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
div-sub [=>]74.1 | \[ \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}
\] |
sub-neg [=>]74.1 | \[ \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} + \left(-\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}
\] |
fma-def [=>]74.1 | \[ \frac{x \cdot x}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} + \left(-\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)
\] |
*-commutative [=>]74.1 | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)} + \left(-\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)
\] |
associate-/l* [=>]73.9 | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\color{blue}{\frac{y \cdot 4}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{y}}}\right)
\] |
associate-/r/ [=>]73.7 | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\color{blue}{\frac{y \cdot 4}{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot y}\right)
\] |
fma-def [=>]73.7 | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\frac{y \cdot 4}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} \cdot y\right)
\] |
*-commutative [=>]73.7 | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\frac{y \cdot 4}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)} \cdot y\right)
\] |
Simplified74.8%
[Start]73.7 | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\frac{y \cdot 4}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \cdot y\right)
\] |
|---|---|
sub-neg [<=]73.7 | \[ \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y \cdot 4}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \cdot y}
\] |
associate-/l* [=>]74.5 | \[ \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x}}} - \frac{y \cdot 4}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \cdot y
\] |
associate-*l/ [=>]74.8 | \[ \frac{x}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x}} - \color{blue}{\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}}
\] |
*-commutative [<=]74.8 | \[ \frac{x}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x}} - \frac{\color{blue}{y \cdot \left(y \cdot 4\right)}}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
Applied egg-rr74.6%
[Start]74.8 | \[ \frac{x}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
|---|---|
div-inv [=>]74.7 | \[ \frac{x}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right) \cdot \frac{1}{x}}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
*-commutative [=>]74.7 | \[ \frac{x}{\color{blue}{\frac{1}{x} \cdot \mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
fma-udef [=>]74.7 | \[ \frac{x}{\frac{1}{x} \cdot \color{blue}{\left(x \cdot x + y \cdot \left(y \cdot 4\right)\right)}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
distribute-lft-in [=>]74.6 | \[ \frac{x}{\color{blue}{\frac{1}{x} \cdot \left(x \cdot x\right) + \frac{1}{x} \cdot \left(y \cdot \left(y \cdot 4\right)\right)}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
associate-*r* [=>]74.6 | \[ \frac{x}{\frac{1}{x} \cdot \left(x \cdot x\right) + \frac{1}{x} \cdot \color{blue}{\left(\left(y \cdot y\right) \cdot 4\right)}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
*-commutative [=>]74.6 | \[ \frac{x}{\frac{1}{x} \cdot \left(x \cdot x\right) + \frac{1}{x} \cdot \color{blue}{\left(4 \cdot \left(y \cdot y\right)\right)}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
Taylor expanded in x around 0 98.9%
if -1.85e-141 < y < 4.00000000000000027e-189Initial program 54.5%
Simplified54.3%
[Start]54.5 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]54.5 | \[ \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 [=>]54.5 | \[ \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* [=>]54.3 | \[ \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 [=>]54.3 | \[ \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 [=>]54.3 | \[ \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 [=>]54.3 | \[ \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 [=>]54.3 | \[ \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 75.7%
Simplified88.4%
[Start]75.7 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]75.7 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
+-commutative [=>]75.7 | \[ \color{blue}{\left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + 1}
\] |
distribute-rgt-out-- [=>]75.7 | \[ \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot \left(-4 - 4\right)} + 1
\] |
metadata-eval [=>]75.7 | \[ \frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-8} + 1
\] |
fma-def [=>]75.7 | \[ \color{blue}{\mathsf{fma}\left(\frac{{y}^{2}}{{x}^{2}}, -8, 1\right)}
\] |
unpow2 [=>]75.7 | \[ \mathsf{fma}\left(\frac{\color{blue}{y \cdot y}}{{x}^{2}}, -8, 1\right)
\] |
unpow2 [=>]75.7 | \[ \mathsf{fma}\left(\frac{y \cdot y}{\color{blue}{x \cdot x}}, -8, 1\right)
\] |
times-frac [=>]88.4 | \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right)
\] |
if 6.59999999999999989e153 < y Initial program 0.0%
Simplified0.0%
[Start]0.0 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]0.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 [=>]0.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* [=>]0.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 [=>]0.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 [=>]0.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 [=>]0.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 [=>]0.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 73.5%
Simplified86.3%
[Start]73.5 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]73.5 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]73.5 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]73.5 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]86.3 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]86.3 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
Final simplification93.5%
| Alternative 1 | |
|---|---|
| Accuracy | 78.9% |
| Cost | 7372 |
| Alternative 2 | |
|---|---|
| Accuracy | 79.0% |
| Cost | 2008 |
| Alternative 3 | |
|---|---|
| Accuracy | 73.5% |
| Cost | 1232 |
| Alternative 4 | |
|---|---|
| Accuracy | 73.7% |
| Cost | 1232 |
| Alternative 5 | |
|---|---|
| Accuracy | 73.6% |
| Cost | 592 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.2% |
| Cost | 64 |
herbie shell --seed 2023137
(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))))