| Alternative 1 | |
|---|---|
| Accuracy | 79.3% |
| 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)))
(t_2 (fma 0.5 (* (/ x y) (/ x y)) -1.0)))
(if (<= (* x x) 2e-304)
t_2
(if (<= (* x x) 5e-247)
t_1
(if (<= (* x x) 5e-31)
t_2
(if (<= (* x x) 1e+274)
t_1
(fma (log1p (pow (/ y x) 2.0)) -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 t_2 = fma(0.5, ((x / y) * (x / y)), -1.0);
double tmp;
if ((x * x) <= 2e-304) {
tmp = t_2;
} else if ((x * x) <= 5e-247) {
tmp = t_1;
} else if ((x * x) <= 5e-31) {
tmp = t_2;
} else if ((x * x) <= 1e+274) {
tmp = t_1;
} else {
tmp = fma(log1p(pow((y / x), 2.0)), -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)) t_2 = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0) tmp = 0.0 if (Float64(x * x) <= 2e-304) tmp = t_2; elseif (Float64(x * x) <= 5e-247) tmp = t_1; elseif (Float64(x * x) <= 5e-31) tmp = t_2; elseif (Float64(x * x) <= 1e+274) tmp = t_1; else tmp = fma(log1p((Float64(y / x) ^ 2.0)), -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]}, Block[{t$95$2 = N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-304], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 5e-247], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 5e-31], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 1e+274], t$95$1, N[(N[Log[1 + N[Power[N[(y / x), $MachinePrecision], 2.0], $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}\\
t_2 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-304}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-247}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-31}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 10^{+274}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right), -8, 1\right)\\
\end{array}
| Original | 51.5% |
|---|---|
| Target | 51.9% |
| Herbie | 79.6% |
if (*.f64 x x) < 1.99999999999999994e-304 or 4.99999999999999978e-247 < (*.f64 x x) < 5e-31Initial program 63.2%
Taylor expanded in x around 0 71.1%
Simplified78.1%
[Start]71.1 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]71.1 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]71.1 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]71.1 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]78.1 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]78.1 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
if 1.99999999999999994e-304 < (*.f64 x x) < 4.99999999999999978e-247 or 5e-31 < (*.f64 x x) < 9.99999999999999921e273Initial program 75.0%
if 9.99999999999999921e273 < (*.f64 x x) Initial program 7.8%
Taylor expanded in x around inf 74.2%
Simplified85.9%
[Start]74.2 | \[ \left(1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}\right) - 4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
associate--l+ [=>]74.2 | \[ \color{blue}{1 + \left(-4 \cdot \frac{{y}^{2}}{{x}^{2}} - 4 \cdot \frac{{y}^{2}}{{x}^{2}}\right)}
\] |
distribute-rgt-out-- [=>]74.2 | \[ 1 + \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot \left(-4 - 4\right)}
\] |
metadata-eval [=>]74.2 | \[ 1 + \frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-8}
\] |
*-commutative [<=]74.2 | \[ 1 + \color{blue}{-8 \cdot \frac{{y}^{2}}{{x}^{2}}}
\] |
+-commutative [<=]74.2 | \[ \color{blue}{-8 \cdot \frac{{y}^{2}}{{x}^{2}} + 1}
\] |
*-commutative [=>]74.2 | \[ \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot -8} + 1
\] |
fma-def [=>]74.2 | \[ \color{blue}{\mathsf{fma}\left(\frac{{y}^{2}}{{x}^{2}}, -8, 1\right)}
\] |
unpow2 [=>]74.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{y \cdot y}}{{x}^{2}}, -8, 1\right)
\] |
unpow2 [=>]74.2 | \[ \mathsf{fma}\left(\frac{y \cdot y}{\color{blue}{x \cdot x}}, -8, 1\right)
\] |
times-frac [=>]85.9 | \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right)
\] |
Applied egg-rr85.0%
[Start]85.9 | \[ \mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)
\] |
|---|---|
add-log-exp [=>]85.0 | \[ \mathsf{fma}\left(\color{blue}{\log \left(e^{\frac{y}{x} \cdot \frac{y}{x}}\right)}, -8, 1\right)
\] |
pow2 [=>]85.0 | \[ \mathsf{fma}\left(\log \left(e^{\color{blue}{{\left(\frac{y}{x}\right)}^{2}}}\right), -8, 1\right)
\] |
Taylor expanded in y around 0 74.2%
Simplified86.9%
[Start]74.2 | \[ \mathsf{fma}\left(\log \left(1 + \frac{{y}^{2}}{{x}^{2}}\right), -8, 1\right)
\] |
|---|---|
unpow2 [=>]74.2 | \[ \mathsf{fma}\left(\log \left(1 + \frac{\color{blue}{y \cdot y}}{{x}^{2}}\right), -8, 1\right)
\] |
unpow2 [=>]74.2 | \[ \mathsf{fma}\left(\log \left(1 + \frac{y \cdot y}{\color{blue}{x \cdot x}}\right), -8, 1\right)
\] |
times-frac [=>]86.9 | \[ \mathsf{fma}\left(\log \left(1 + \color{blue}{\frac{y}{x} \cdot \frac{y}{x}}\right), -8, 1\right)
\] |
unpow2 [<=]86.9 | \[ \mathsf{fma}\left(\log \left(1 + \color{blue}{{\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right)
\] |
Applied egg-rr86.9%
[Start]86.9 | \[ \mathsf{fma}\left(\log \left(1 + {\left(\frac{y}{x}\right)}^{2}\right), -8, 1\right)
\] |
|---|---|
*-un-lft-identity [=>]86.9 | \[ \mathsf{fma}\left(\log \color{blue}{\left(1 \cdot \left(1 + {\left(\frac{y}{x}\right)}^{2}\right)\right)}, -8, 1\right)
\] |
*-commutative [=>]86.9 | \[ \mathsf{fma}\left(\log \color{blue}{\left(\left(1 + {\left(\frac{y}{x}\right)}^{2}\right) \cdot 1\right)}, -8, 1\right)
\] |
log-prod [=>]86.9 | \[ \mathsf{fma}\left(\color{blue}{\log \left(1 + {\left(\frac{y}{x}\right)}^{2}\right) + \log 1}, -8, 1\right)
\] |
log1p-def [=>]86.9 | \[ \mathsf{fma}\left(\color{blue}{\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right)} + \log 1, -8, 1\right)
\] |
metadata-eval [=>]86.9 | \[ \mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right) + \color{blue}{0}, -8, 1\right)
\] |
Simplified86.9%
[Start]86.9 | \[ \mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right) + 0, -8, 1\right)
\] |
|---|---|
+-rgt-identity [=>]86.9 | \[ \mathsf{fma}\left(\color{blue}{\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right)}, -8, 1\right)
\] |
Final simplification79.6%
| Alternative 1 | |
|---|---|
| Accuracy | 79.3% |
| Cost | 8016 |
| Alternative 2 | |
|---|---|
| Accuracy | 79.2% |
| Cost | 7756 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 2256 |
| Alternative 4 | |
|---|---|
| Accuracy | 74.9% |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Accuracy | 74.7% |
| Cost | 328 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.9% |
| Cost | 64 |
herbie shell --seed 2023146
(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))))