| Alternative 1 | |
|---|---|
| Accuracy | 79.8% |
| Cost | 8016 |
(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) t_0) (+ (* x x) t_0))))
(if (<= (* x x) 5e-307)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= (* x x) 5e-217)
t_1
(if (<= (* x x) 2e-161)
(/ 1.0 (fma (/ (/ x y) (/ y x)) -0.5 -1.0))
(if (<= (* x x) 1e+162) t_1 (fma (* (/ y x) (/ y x)) -8.0 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) - t_0) / ((x * x) + t_0);
double tmp;
if ((x * x) <= 5e-307) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if ((x * x) <= 5e-217) {
tmp = t_1;
} else if ((x * x) <= 2e-161) {
tmp = 1.0 / fma(((x / y) / (y / x)), -0.5, -1.0);
} else if ((x * x) <= 1e+162) {
tmp = t_1;
} else {
tmp = fma(((y / x) * (y / x)), -8.0, 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) - t_0) / Float64(Float64(x * x) + t_0)) tmp = 0.0 if (Float64(x * x) <= 5e-307) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (Float64(x * x) <= 5e-217) tmp = t_1; elseif (Float64(x * x) <= 2e-161) tmp = Float64(1.0 / fma(Float64(Float64(x / y) / Float64(y / x)), -0.5, -1.0)); elseif (Float64(x * x) <= 1e+162) tmp = t_1; else tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 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] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-307], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 5e-217], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e-161], N[(1.0 / N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] * -0.5 + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+162], t$95$1, N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 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 - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-307}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-217}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-161}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{\frac{x}{y}}{\frac{y}{x}}, -0.5, -1\right)}\\
\mathbf{elif}\;x \cdot x \leq 10^{+162}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
| Original | 50.0% |
|---|---|
| Target | 50.4% |
| Herbie | 79.8% |
if (*.f64 x x) < 5.00000000000000014e-307Initial program 51.6%
Taylor expanded in x around 0 76.7%
Simplified88.2%
[Start]76.7 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]76.7 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]76.7 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]76.7 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]88.2 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]88.2 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
if 5.00000000000000014e-307 < (*.f64 x x) < 5.0000000000000002e-217 or 2.00000000000000006e-161 < (*.f64 x x) < 9.9999999999999994e161Initial program 74.4%
if 5.0000000000000002e-217 < (*.f64 x x) < 2.00000000000000006e-161Initial program 75.2%
Applied egg-rr75.2%
[Start]75.2 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
clear-num [=>]75.2 | \[ \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}
\] |
inv-pow [=>]75.2 | \[ \color{blue}{{\left(\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}\right)}^{-1}}
\] |
fma-def [=>]75.2 | \[ {\left(\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}\right)}^{-1}
\] |
*-commutative [=>]75.2 | \[ {\left(\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}\right)}^{-1}
\] |
sub-neg [=>]75.2 | \[ {\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{\color{blue}{x \cdot x + \left(-\left(y \cdot 4\right) \cdot y\right)}}\right)}^{-1}
\] |
+-commutative [=>]75.2 | \[ {\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{\color{blue}{\left(-\left(y \cdot 4\right) \cdot y\right) + x \cdot x}}\right)}^{-1}
\] |
*-commutative [=>]75.2 | \[ {\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{\left(-\color{blue}{y \cdot \left(y \cdot 4\right)}\right) + x \cdot x}\right)}^{-1}
\] |
distribute-rgt-neg-in [=>]75.2 | \[ {\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{\color{blue}{y \cdot \left(-y \cdot 4\right)} + x \cdot x}\right)}^{-1}
\] |
fma-def [=>]75.2 | \[ {\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{\color{blue}{\mathsf{fma}\left(y, -y \cdot 4, x \cdot x\right)}}\right)}^{-1}
\] |
distribute-rgt-neg-in [=>]75.2 | \[ {\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(y, \color{blue}{y \cdot \left(-4\right)}, x \cdot x\right)}\right)}^{-1}
\] |
metadata-eval [=>]75.2 | \[ {\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(y, y \cdot \color{blue}{-4}, x \cdot x\right)}\right)}^{-1}
\] |
Taylor expanded in x around 0 65.5%
Simplified65.4%
[Start]65.5 | \[ {\left(-0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1\right)}^{-1}
\] |
|---|---|
fma-neg [=>]65.5 | \[ {\color{blue}{\left(\mathsf{fma}\left(-0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)\right)}}^{-1}
\] |
unpow2 [=>]65.5 | \[ {\left(\mathsf{fma}\left(-0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)\right)}^{-1}
\] |
unpow2 [=>]65.5 | \[ {\left(\mathsf{fma}\left(-0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)\right)}^{-1}
\] |
times-frac [=>]65.4 | \[ {\left(\mathsf{fma}\left(-0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)\right)}^{-1}
\] |
metadata-eval [=>]65.4 | \[ {\left(\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)\right)}^{-1}
\] |
Applied egg-rr65.4%
[Start]65.4 | \[ {\left(\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\right)}^{-1}
\] |
|---|---|
add-log-exp [=>]65.6 | \[ \color{blue}{\log \left(e^{{\left(\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\right)}^{-1}}\right)}
\] |
*-un-lft-identity [=>]65.6 | \[ \log \color{blue}{\left(1 \cdot e^{{\left(\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\right)}^{-1}}\right)}
\] |
log-prod [=>]65.6 | \[ \color{blue}{\log 1 + \log \left(e^{{\left(\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\right)}^{-1}}\right)}
\] |
metadata-eval [=>]65.6 | \[ \color{blue}{0} + \log \left(e^{{\left(\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\right)}^{-1}}\right)
\] |
add-log-exp [<=]65.4 | \[ 0 + \color{blue}{{\left(\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\right)}^{-1}}
\] |
unpow-1 [=>]65.4 | \[ 0 + \color{blue}{\frac{1}{\mathsf{fma}\left(-0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)}}
\] |
pow2 [=>]65.4 | \[ 0 + \frac{1}{\mathsf{fma}\left(-0.5, \color{blue}{{\left(\frac{x}{y}\right)}^{2}}, -1\right)}
\] |
Simplified65.4%
[Start]65.4 | \[ 0 + \frac{1}{\mathsf{fma}\left(-0.5, {\left(\frac{x}{y}\right)}^{2}, -1\right)}
\] |
|---|---|
+-lft-identity [=>]65.4 | \[ \color{blue}{\frac{1}{\mathsf{fma}\left(-0.5, {\left(\frac{x}{y}\right)}^{2}, -1\right)}}
\] |
fma-udef [=>]65.4 | \[ \frac{1}{\color{blue}{-0.5 \cdot {\left(\frac{x}{y}\right)}^{2} + -1}}
\] |
unpow2 [=>]65.4 | \[ \frac{1}{-0.5 \cdot \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right)} + -1}
\] |
times-frac [<=]65.5 | \[ \frac{1}{-0.5 \cdot \color{blue}{\frac{x \cdot x}{y \cdot y}} + -1}
\] |
unpow2 [<=]65.5 | \[ \frac{1}{-0.5 \cdot \frac{\color{blue}{{x}^{2}}}{y \cdot y} + -1}
\] |
unpow2 [<=]65.5 | \[ \frac{1}{-0.5 \cdot \frac{{x}^{2}}{\color{blue}{{y}^{2}}} + -1}
\] |
*-commutative [=>]65.5 | \[ \frac{1}{\color{blue}{\frac{{x}^{2}}{{y}^{2}} \cdot -0.5} + -1}
\] |
fma-def [=>]65.5 | \[ \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{{x}^{2}}{{y}^{2}}, -0.5, -1\right)}}
\] |
unpow2 [=>]65.5 | \[ \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{x \cdot x}}{{y}^{2}}, -0.5, -1\right)}
\] |
unpow2 [=>]65.5 | \[ \frac{1}{\mathsf{fma}\left(\frac{x \cdot x}{\color{blue}{y \cdot y}}, -0.5, -1\right)}
\] |
times-frac [=>]65.4 | \[ \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -0.5, -1\right)}
\] |
unpow2 [<=]65.4 | \[ \frac{1}{\mathsf{fma}\left(\color{blue}{{\left(\frac{x}{y}\right)}^{2}}, -0.5, -1\right)}
\] |
Applied egg-rr65.4%
[Start]65.4 | \[ \frac{1}{\mathsf{fma}\left({\left(\frac{x}{y}\right)}^{2}, -0.5, -1\right)}
\] |
|---|---|
unpow2 [=>]65.4 | \[ \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -0.5, -1\right)}
\] |
clear-num [=>]65.4 | \[ \frac{1}{\mathsf{fma}\left(\frac{x}{y} \cdot \color{blue}{\frac{1}{\frac{y}{x}}}, -0.5, -1\right)}
\] |
un-div-inv [=>]65.4 | \[ \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{\frac{x}{y}}{\frac{y}{x}}}, -0.5, -1\right)}
\] |
if 9.9999999999999994e161 < (*.f64 x x) Initial program 24.7%
Taylor expanded in x around inf 72.2%
Simplified80.7%
[Start]72.2 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]72.2 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
distribute-rgt-out-- [=>]72.2 | \[ 1 + \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot \left(-4 - 4\right)}
\] |
metadata-eval [=>]72.2 | \[ 1 + \frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-8}
\] |
*-commutative [<=]72.2 | \[ 1 + \color{blue}{-8 \cdot \frac{{y}^{2}}{{x}^{2}}}
\] |
+-commutative [<=]72.2 | \[ \color{blue}{-8 \cdot \frac{{y}^{2}}{{x}^{2}} + 1}
\] |
*-commutative [=>]72.2 | \[ \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot -8} + 1
\] |
fma-def [=>]72.2 | \[ \color{blue}{\mathsf{fma}\left(\frac{{y}^{2}}{{x}^{2}}, -8, 1\right)}
\] |
unpow2 [=>]72.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{y \cdot y}}{{x}^{2}}, -8, 1\right)
\] |
unpow2 [=>]72.2 | \[ \mathsf{fma}\left(\frac{y \cdot y}{\color{blue}{x \cdot x}}, -8, 1\right)
\] |
times-frac [=>]80.7 | \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right)
\] |
Final simplification79.8%
| Alternative 1 | |
|---|---|
| Accuracy | 79.8% |
| Cost | 8016 |
| Alternative 2 | |
|---|---|
| Accuracy | 79.6% |
| Cost | 7236 |
| Alternative 3 | |
|---|---|
| Accuracy | 79.4% |
| Cost | 2256 |
| Alternative 4 | |
|---|---|
| Accuracy | 74.4% |
| Cost | 1484 |
| Alternative 5 | |
|---|---|
| Accuracy | 74.7% |
| Cost | 1484 |
| Alternative 6 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 1224 |
| Alternative 7 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 328 |
| Alternative 8 | |
|---|---|
| Accuracy | 50.6% |
| Cost | 64 |
herbie shell --seed 2023151
(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))))