(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))))
(if (<= t_0 0.0)
1.0
(if (<= t_0 2e-123)
(/ (+ (* x x) (* y (* y -4.0))) (+ t_0 (* x x)))
(if (<= t_0 1e-27)
1.0
(if (<= t_0 2e+206)
(/ (fma x x (* -4.0 (* y y))) (fma x x t_0))
(fma 0.5 (pow (/ x y) 2.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 tmp;
if (t_0 <= 0.0) {
tmp = 1.0;
} else if (t_0 <= 2e-123) {
tmp = ((x * x) + (y * (y * -4.0))) / (t_0 + (x * x));
} else if (t_0 <= 1e-27) {
tmp = 1.0;
} else if (t_0 <= 2e+206) {
tmp = fma(x, x, (-4.0 * (y * y))) / fma(x, x, t_0);
} else {
tmp = fma(0.5, pow((x / y), 2.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)) tmp = 0.0 if (t_0 <= 0.0) tmp = 1.0; elseif (t_0 <= 2e-123) tmp = Float64(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(t_0 + Float64(x * x))); elseif (t_0 <= 1e-27) tmp = 1.0; elseif (t_0 <= 2e+206) tmp = Float64(fma(x, x, Float64(-4.0 * Float64(y * y))) / fma(x, x, t_0)); else tmp = fma(0.5, (Float64(x / y) ^ 2.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]}, If[LessEqual[t$95$0, 0.0], 1.0, If[LessEqual[t$95$0, 2e-123], N[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-27], 1.0, If[LessEqual[t$95$0, 2e+206], N[(N[(x * x + N[(-4.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * x + t$95$0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[N[(x / y), $MachinePrecision], 2.0], $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)\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-123}:\\
\;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\
\mathbf{elif}\;t_0 \leq 10^{-27}:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+206}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x, -4 \cdot \left(y \cdot y\right)\right)}{\mathsf{fma}\left(x, x, t_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, {\left(\frac{x}{y}\right)}^{2}, -1\right)\\
\end{array}
| Original | 31.9 |
|---|---|
| Target | 31.5 |
| Herbie | 12.5 |
if (*.f64 (*.f64 y 4) y) < 0.0 or 2.0000000000000001e-123 < (*.f64 (*.f64 y 4) y) < 1e-27Initial program 27.0
Taylor expanded in x around inf 11.8
if 0.0 < (*.f64 (*.f64 y 4) y) < 2.0000000000000001e-123Initial program 16.4
if 1e-27 < (*.f64 (*.f64 y 4) y) < 2.0000000000000001e206Initial program 16.0
Simplified16.0
if 2.0000000000000001e206 < (*.f64 (*.f64 y 4) y) Initial program 52.4
Taylor expanded in x around 0 15.7
Simplified9.8
Applied egg-rr9.4
Final simplification12.5
herbie shell --seed 2022190
(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))))