(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 (/ (fma y (* y -4.0) (* x x)) (fma x x t_0))))
(if (<= t_0 5e-219)
1.0
(if (<= t_0 5e-168)
t_1
(if (<= t_0 5e-80)
(fma -8.0 (/ y (/ (* x x) y)) 1.0)
(if (<= t_0 5e+161) t_1 (fma (/ x y) (/ (* x 0.5) 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 = y * (y * 4.0);
double t_1 = fma(y, (y * -4.0), (x * x)) / fma(x, x, t_0);
double tmp;
if (t_0 <= 5e-219) {
tmp = 1.0;
} else if (t_0 <= 5e-168) {
tmp = t_1;
} else if (t_0 <= 5e-80) {
tmp = fma(-8.0, (y / ((x * x) / y)), 1.0);
} else if (t_0 <= 5e+161) {
tmp = t_1;
} else {
tmp = fma((x / y), ((x * 0.5) / 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(y * Float64(y * 4.0)) t_1 = Float64(fma(y, Float64(y * -4.0), Float64(x * x)) / fma(x, x, t_0)) tmp = 0.0 if (t_0 <= 5e-219) tmp = 1.0; elseif (t_0 <= 5e-168) tmp = t_1; elseif (t_0 <= 5e-80) tmp = fma(-8.0, Float64(y / Float64(Float64(x * x) / y)), 1.0); elseif (t_0 <= 5e+161) tmp = t_1; else tmp = fma(Float64(x / y), Float64(Float64(x * 0.5) / 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[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(x * x + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e-219], 1.0, If[LessEqual[t$95$0, 5e-168], t$95$1, If[LessEqual[t$95$0, 5e-80], N[(-8.0 * N[(y / N[(N[(x * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$0, 5e+161], t$95$1, N[(N[(x / y), $MachinePrecision] * N[(N[(x * 0.5), $MachinePrecision] / y), $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 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, t_0\right)}\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{-219}:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-168}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-80}:\\
\;\;\;\;\mathsf{fma}\left(-8, \frac{y}{\frac{x \cdot x}{y}}, 1\right)\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+161}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x \cdot 0.5}{y}, -1\right)\\
\end{array}
| Original | 31.2 |
|---|---|
| Target | 30.9 |
| Herbie | 12.9 |
if (*.f64 (*.f64 y 4) y) < 5.0000000000000002e-219Initial program 26.6
Simplified26.6
Taylor expanded in y around 0 10.6
if 5.0000000000000002e-219 < (*.f64 (*.f64 y 4) y) < 5.00000000000000001e-168 or 5e-80 < (*.f64 (*.f64 y 4) y) < 4.9999999999999997e161Initial program 15.3
Simplified15.3
if 5.00000000000000001e-168 < (*.f64 (*.f64 y 4) y) < 5e-80Initial program 16.0
Simplified16.0
Taylor expanded in y around 0 26.2
Simplified26.2
if 4.9999999999999997e161 < (*.f64 (*.f64 y 4) y) Initial program 49.0
Simplified49.0
Taylor expanded in y around inf 16.9
Simplified10.8
Final simplification12.9
herbie shell --seed 2022210
(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))))