| Alternative 1 | |
|---|---|
| Error | 16.7 |
| Cost | 328 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-5}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+25}:\\
\;\;\;\;-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 (* y 4.0))) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
(if (<= (* x x) 1.55e-267)
-1.0
(if (<= (* x x) 1.9e-81)
t_1
(if (<= (* x x) 5.8e-16) -1.0 (if (<= (* x x) 3.7e+264) t_1 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) <= 1.55e-267) {
tmp = -1.0;
} else if ((x * x) <= 1.9e-81) {
tmp = t_1;
} else if ((x * x) <= 5.8e-16) {
tmp = -1.0;
} else if ((x * x) <= 3.7e+264) {
tmp = t_1;
} 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 * (y * 4.0d0)
t_1 = ((x * x) - t_0) / ((x * x) + t_0)
if ((x * x) <= 1.55d-267) then
tmp = -1.0d0
else if ((x * x) <= 1.9d-81) then
tmp = t_1
else if ((x * x) <= 5.8d-16) then
tmp = -1.0d0
else if ((x * x) <= 3.7d+264) then
tmp = t_1
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 * (y * 4.0);
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double tmp;
if ((x * x) <= 1.55e-267) {
tmp = -1.0;
} else if ((x * x) <= 1.9e-81) {
tmp = t_1;
} else if ((x * x) <= 5.8e-16) {
tmp = -1.0;
} else if ((x * x) <= 3.7e+264) {
tmp = t_1;
} 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 * (y * 4.0) t_1 = ((x * x) - t_0) / ((x * x) + t_0) tmp = 0 if (x * x) <= 1.55e-267: tmp = -1.0 elif (x * x) <= 1.9e-81: tmp = t_1 elif (x * x) <= 5.8e-16: tmp = -1.0 elif (x * x) <= 3.7e+264: tmp = t_1 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(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) <= 1.55e-267) tmp = -1.0; elseif (Float64(x * x) <= 1.9e-81) tmp = t_1; elseif (Float64(x * x) <= 5.8e-16) tmp = -1.0; elseif (Float64(x * x) <= 3.7e+264) tmp = t_1; 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 * (y * 4.0); t_1 = ((x * x) - t_0) / ((x * x) + t_0); tmp = 0.0; if ((x * x) <= 1.55e-267) tmp = -1.0; elseif ((x * x) <= 1.9e-81) tmp = t_1; elseif ((x * x) <= 5.8e-16) tmp = -1.0; elseif ((x * x) <= 3.7e+264) tmp = t_1; 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[(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], 1.55e-267], -1.0, If[LessEqual[N[(x * x), $MachinePrecision], 1.9e-81], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 5.8e-16], -1.0, If[LessEqual[N[(x * x), $MachinePrecision], 3.7e+264], t$95$1, 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 := 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 1.55 \cdot 10^{-267}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \cdot x \leq 1.9 \cdot 10^{-81}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 5.8 \cdot 10^{-16}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \cdot x \leq 3.7 \cdot 10^{+264}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
Results
| Original | 31.5 |
|---|---|
| Target | 31.2 |
| Herbie | 13.2 |
if (*.f64 x x) < 1.5500000000000001e-267 or 1.8999999999999999e-81 < (*.f64 x x) < 5.7999999999999996e-16Initial program 26.6
Taylor expanded in x around 0 12.7
if 1.5500000000000001e-267 < (*.f64 x x) < 1.8999999999999999e-81 or 5.7999999999999996e-16 < (*.f64 x x) < 3.6999999999999999e264Initial program 16.1
if 3.6999999999999999e264 < (*.f64 x x) Initial program 57.9
Taylor expanded in x around inf 9.9
Final simplification13.2
| Alternative 1 | |
|---|---|
| Error | 16.7 |
| Cost | 328 |
| Alternative 2 | |
|---|---|
| Error | 32.1 |
| Cost | 64 |
herbie shell --seed 2023060
(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))))