| Alternative 1 | |
|---|---|
| Error | 16.3 |
| Cost | 328 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-20}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+68}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\]
(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 4.0) y)) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
(if (<= y -1.1e+98)
-1.0
(if (<= y -5.9e-125)
t_1
(if (<= y 1e-156)
1.0
(if (<= y 7.5e+18) t_1 (if (<= y 1.15e+69) 1.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 * 4.0) * y;
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double tmp;
if (y <= -1.1e+98) {
tmp = -1.0;
} else if (y <= -5.9e-125) {
tmp = t_1;
} else if (y <= 1e-156) {
tmp = 1.0;
} else if (y <= 7.5e+18) {
tmp = t_1;
} else if (y <= 1.15e+69) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) - ((y * 4.0d0) * y)) / ((x * x) + ((y * 4.0d0) * y))
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (y * 4.0d0) * y
t_1 = ((x * x) - t_0) / ((x * x) + t_0)
if (y <= (-1.1d+98)) then
tmp = -1.0d0
else if (y <= (-5.9d-125)) then
tmp = t_1
else if (y <= 1d-156) then
tmp = 1.0d0
else if (y <= 7.5d+18) then
tmp = t_1
else if (y <= 1.15d+69) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double tmp;
if (y <= -1.1e+98) {
tmp = -1.0;
} else if (y <= -5.9e-125) {
tmp = t_1;
} else if (y <= 1e-156) {
tmp = 1.0;
} else if (y <= 7.5e+18) {
tmp = t_1;
} else if (y <= 1.15e+69) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))
def code(x, y): t_0 = (y * 4.0) * y t_1 = ((x * x) - t_0) / ((x * x) + t_0) tmp = 0 if y <= -1.1e+98: tmp = -1.0 elif y <= -5.9e-125: tmp = t_1 elif y <= 1e-156: tmp = 1.0 elif y <= 7.5e+18: tmp = t_1 elif y <= 1.15e+69: tmp = 1.0 else: tmp = -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(y * 4.0) * y) t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) tmp = 0.0 if (y <= -1.1e+98) tmp = -1.0; elseif (y <= -5.9e-125) tmp = t_1; elseif (y <= 1e-156) tmp = 1.0; elseif (y <= 7.5e+18) tmp = t_1; elseif (y <= 1.15e+69) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp = code(x, y) tmp = ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)); end
function tmp_2 = code(x, y) t_0 = (y * 4.0) * y; t_1 = ((x * x) - t_0) / ((x * x) + t_0); tmp = 0.0; if (y <= -1.1e+98) tmp = -1.0; elseif (y <= -5.9e-125) tmp = t_1; elseif (y <= 1e-156) tmp = 1.0; elseif (y <= 7.5e+18) tmp = t_1; elseif (y <= 1.15e+69) tmp = 1.0; else tmp = -1.0; end tmp_2 = 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[(y * 4.0), $MachinePrecision] * y), $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[y, -1.1e+98], -1.0, If[LessEqual[y, -5.9e-125], t$95$1, If[LessEqual[y, 1e-156], 1.0, If[LessEqual[y, 7.5e+18], t$95$1, If[LessEqual[y, 1.15e+69], 1.0, -1.0]]]]]]]
\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 := \left(y \cdot 4\right) \cdot y\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;y \leq -1.1 \cdot 10^{+98}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq -5.9 \cdot 10^{-125}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 10^{-156}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+18}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+69}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
Results
| Original | 31.9 |
|---|---|
| Target | 31.7 |
| Herbie | 13.1 |
if y < -1.10000000000000004e98 or 1.15000000000000008e69 < y Initial program 49.4
Taylor expanded in x around 0 11.6
if -1.10000000000000004e98 < y < -5.89999999999999959e-125 or 1.00000000000000004e-156 < y < 7.5e18Initial program 15.5
if -5.89999999999999959e-125 < y < 1.00000000000000004e-156 or 7.5e18 < y < 1.15000000000000008e69Initial program 27.8
Taylor expanded in x around inf 12.3
Final simplification13.1
| Alternative 1 | |
|---|---|
| Error | 16.3 |
| Cost | 328 |
| Alternative 2 | |
|---|---|
| Error | 31.8 |
| Cost | 64 |
herbie shell --seed 2023090
(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))))