
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= x 6.2e-153)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= x 5.5e+116)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(fma (* (/ y x) (/ y x)) -8.0 1.0)))))x = abs(x);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (x <= 6.2e-153) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if (x <= 5.5e+116) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
}
return tmp;
}
x = abs(x) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (x <= 6.2e-153) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (x <= 5.5e+116) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0); end return tmp end
NOTE: x should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 6.2e-153], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[x, 5.5e+116], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \leq 6.2 \cdot 10^{-153}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{+116}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
\end{array}
if x < 6.1999999999999999e-153Initial program 51.9%
Taylor expanded in x around 0 47.4%
fma-neg47.4%
unpow247.4%
unpow247.4%
times-frac60.7%
metadata-eval60.7%
Simplified60.7%
if 6.1999999999999999e-153 < x < 5.50000000000000035e116Initial program 81.8%
if 5.50000000000000035e116 < x Initial program 11.6%
Taylor expanded in x around inf 81.5%
associate--l+81.5%
distribute-rgt-out--81.5%
metadata-eval81.5%
*-commutative81.5%
+-commutative81.5%
*-commutative81.5%
fma-def81.5%
unpow281.5%
unpow281.5%
times-frac86.8%
Simplified86.8%
Final simplification69.6%
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= x 1.5e-152)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= x 8.8e+116)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))))x = abs(x);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (x <= 1.5e-152) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if (x <= 8.8e+116) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
x = abs(x) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (x <= 1.5e-152) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (x <= 8.8e+116) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
NOTE: x should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.5e-152], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[x, 8.8e+116], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \leq 1.5 \cdot 10^{-152}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{+116}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if x < 1.5e-152Initial program 51.9%
Taylor expanded in x around 0 47.4%
fma-neg47.4%
unpow247.4%
unpow247.4%
times-frac60.7%
metadata-eval60.7%
Simplified60.7%
if 1.5e-152 < x < 8.799999999999999e116Initial program 81.8%
if 8.799999999999999e116 < x Initial program 11.6%
Taylor expanded in x around inf 11.7%
unpow211.7%
Simplified11.7%
Taylor expanded in x around inf 81.5%
unpow281.5%
unpow281.5%
times-frac86.8%
unpow286.8%
Simplified86.8%
unpow286.8%
clear-num86.8%
un-div-inv86.8%
Applied egg-rr86.8%
Final simplification69.6%
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 5e-305)
(+ -1.0 (/ (/ (/ x y) (/ y x)) 4.0))
(if (<= (* x x) 1e+231)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))))x = abs(x);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 5e-305) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else if ((x * x) <= 1e+231) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * (y * 4.0d0)
if ((x * x) <= 5d-305) then
tmp = (-1.0d0) + (((x / y) / (y / x)) / 4.0d0)
else if ((x * x) <= 1d+231) then
tmp = ((x * x) - t_0) / ((x * x) + t_0)
else
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 5e-305) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else if ((x * x) <= 1e+231) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
x = abs(x) def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if (x * x) <= 5e-305: tmp = -1.0 + (((x / y) / (y / x)) / 4.0) elif (x * x) <= 1e+231: tmp = ((x * x) - t_0) / ((x * x) + t_0) else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
x = abs(x) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 5e-305) tmp = Float64(-1.0 + Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0)); elseif (Float64(x * x) <= 1e+231) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
x = abs(x) function tmp_2 = code(x, y) t_0 = y * (y * 4.0); tmp = 0.0; if ((x * x) <= 5e-305) tmp = -1.0 + (((x / y) / (y / x)) / 4.0); elseif ((x * x) <= 1e+231) tmp = ((x * x) - t_0) / ((x * x) + t_0); else tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-305], N[(-1.0 + N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+231], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-305}:\\
\;\;\;\;-1 + \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4}\\
\mathbf{elif}\;x \cdot x \leq 10^{+231}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 4.99999999999999985e-305Initial program 52.9%
Taylor expanded in x around 0 52.9%
*-commutative52.9%
unpow252.9%
associate-*r*52.9%
Simplified52.9%
div-sub52.9%
associate-*r*52.9%
associate-/r*52.9%
frac-times52.9%
pow252.9%
*-commutative52.9%
*-inverses89.9%
Applied egg-rr89.9%
unpow289.9%
clear-num89.9%
un-div-inv89.9%
Applied egg-rr89.9%
if 4.99999999999999985e-305 < (*.f64 x x) < 1.0000000000000001e231Initial program 84.5%
if 1.0000000000000001e231 < (*.f64 x x) Initial program 9.6%
Taylor expanded in x around inf 9.7%
unpow29.7%
Simplified9.7%
Taylor expanded in x around inf 74.8%
unpow274.8%
unpow274.8%
times-frac82.5%
unpow282.5%
Simplified82.5%
unpow282.5%
clear-num82.5%
un-div-inv82.5%
Applied egg-rr82.5%
Final simplification85.3%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (or (<= (* x x) 2e-201) (and (not (<= (* x x) 5e-26)) (<= (* x x) 5e+41))) (+ -1.0 (/ (/ (/ x y) (/ y x)) 4.0)) (+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))
x = abs(x);
double code(double x, double y) {
double tmp;
if (((x * x) <= 2e-201) || (!((x * x) <= 5e-26) && ((x * x) <= 5e+41))) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((x * x) <= 2d-201) .or. (.not. ((x * x) <= 5d-26)) .and. ((x * x) <= 5d+41)) then
tmp = (-1.0d0) + (((x / y) / (y / x)) / 4.0d0)
else
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if (((x * x) <= 2e-201) || (!((x * x) <= 5e-26) && ((x * x) <= 5e+41))) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if ((x * x) <= 2e-201) or (not ((x * x) <= 5e-26) and ((x * x) <= 5e+41)): tmp = -1.0 + (((x / y) / (y / x)) / 4.0) else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
x = abs(x) function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 2e-201) || (!(Float64(x * x) <= 5e-26) && (Float64(x * x) <= 5e+41))) tmp = Float64(-1.0 + Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0)); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if (((x * x) <= 2e-201) || (~(((x * x) <= 5e-26)) && ((x * x) <= 5e+41))) tmp = -1.0 + (((x / y) / (y / x)) / 4.0); else tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 2e-201], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 5e-26]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 5e+41]]], N[(-1.0 + N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-201} \lor \neg \left(x \cdot x \leq 5 \cdot 10^{-26}\right) \land x \cdot x \leq 5 \cdot 10^{+41}:\\
\;\;\;\;-1 + \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.99999999999999989e-201 or 5.00000000000000019e-26 < (*.f64 x x) < 5.00000000000000022e41Initial program 60.0%
Taylor expanded in x around 0 49.1%
*-commutative49.1%
unpow249.1%
associate-*r*49.1%
Simplified49.1%
div-sub48.8%
associate-*r*48.8%
associate-/r*48.8%
frac-times48.8%
pow248.8%
*-commutative48.8%
*-inverses82.5%
Applied egg-rr82.5%
unpow282.5%
clear-num82.5%
un-div-inv82.5%
Applied egg-rr82.5%
if 1.99999999999999989e-201 < (*.f64 x x) < 5.00000000000000019e-26 or 5.00000000000000022e41 < (*.f64 x x) Initial program 45.7%
Taylor expanded in x around inf 35.5%
unpow235.5%
Simplified35.5%
Taylor expanded in x around inf 71.6%
unpow271.6%
unpow271.6%
times-frac75.9%
unpow275.9%
Simplified75.9%
unpow275.9%
clear-num75.9%
un-div-inv75.9%
Applied egg-rr75.9%
Final simplification78.6%
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (<= x 2e-102)
-1.0
(if (or (<= x 3.5e-13) (not (<= x 5.4e+20)))
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))
-1.0)))x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 2e-102) {
tmp = -1.0;
} else if ((x <= 3.5e-13) || !(x <= 5.4e+20)) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 2d-102) then
tmp = -1.0d0
else if ((x <= 3.5d-13) .or. (.not. (x <= 5.4d+20))) then
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
else
tmp = -1.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if (x <= 2e-102) {
tmp = -1.0;
} else if ((x <= 3.5e-13) || !(x <= 5.4e+20)) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if x <= 2e-102: tmp = -1.0 elif (x <= 3.5e-13) or not (x <= 5.4e+20): tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) else: tmp = -1.0 return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 2e-102) tmp = -1.0; elseif ((x <= 3.5e-13) || !(x <= 5.4e+20)) tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); else tmp = -1.0; end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2e-102) tmp = -1.0; elseif ((x <= 3.5e-13) || ~((x <= 5.4e+20))) tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); else tmp = -1.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[x, 2e-102], -1.0, If[Or[LessEqual[x, 3.5e-13], N[Not[LessEqual[x, 5.4e+20]], $MachinePrecision]], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{-102}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-13} \lor \neg \left(x \leq 5.4 \cdot 10^{+20}\right):\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < 1.99999999999999987e-102 or 3.5000000000000002e-13 < x < 5.4e20Initial program 53.7%
Taylor expanded in x around 0 59.2%
if 1.99999999999999987e-102 < x < 3.5000000000000002e-13 or 5.4e20 < x Initial program 47.0%
Taylor expanded in x around inf 35.5%
unpow235.5%
Simplified35.5%
Taylor expanded in x around inf 71.9%
unpow271.9%
unpow271.9%
times-frac74.7%
unpow274.7%
Simplified74.7%
unpow274.7%
clear-num74.7%
un-div-inv74.7%
Applied egg-rr74.7%
Final simplification64.3%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= x 1.5e-99) -1.0 (if (<= x 5e-16) 1.0 (if (<= x 1e+21) -1.0 1.0))))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 1.5e-99) {
tmp = -1.0;
} else if (x <= 5e-16) {
tmp = 1.0;
} else if (x <= 1e+21) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.5d-99) then
tmp = -1.0d0
else if (x <= 5d-16) then
tmp = 1.0d0
else if (x <= 1d+21) then
tmp = -1.0d0
else
tmp = 1.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if (x <= 1.5e-99) {
tmp = -1.0;
} else if (x <= 5e-16) {
tmp = 1.0;
} else if (x <= 1e+21) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if x <= 1.5e-99: tmp = -1.0 elif x <= 5e-16: tmp = 1.0 elif x <= 1e+21: tmp = -1.0 else: tmp = 1.0 return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 1.5e-99) tmp = -1.0; elseif (x <= 5e-16) tmp = 1.0; elseif (x <= 1e+21) tmp = -1.0; else tmp = 1.0; end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.5e-99) tmp = -1.0; elseif (x <= 5e-16) tmp = 1.0; elseif (x <= 1e+21) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[x, 1.5e-99], -1.0, If[LessEqual[x, 5e-16], 1.0, If[LessEqual[x, 1e+21], -1.0, 1.0]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{-99}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-16}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 10^{+21}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.50000000000000003e-99 or 5.0000000000000004e-16 < x < 1e21Initial program 54.0%
Taylor expanded in x around 0 59.4%
if 1.50000000000000003e-99 < x < 5.0000000000000004e-16 or 1e21 < x Initial program 46.3%
Taylor expanded in x around inf 75.4%
Final simplification64.4%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 -1.0)
x = abs(x);
double code(double x, double y) {
return -1.0;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
x = Math.abs(x);
public static double code(double x, double y) {
return -1.0;
}
x = abs(x) def code(x, y): return -1.0
x = abs(x) function code(x, y) return -1.0 end
x = abs(x) function tmp = code(x, y) tmp = -1.0; end
NOTE: x should be positive before calling this function code[x_, y_] := -1.0
\begin{array}{l}
x = |x|\\
\\
-1
\end{array}
Initial program 51.6%
Taylor expanded in x around 0 49.0%
Final simplification49.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (* y y) 4.0))
(t_1 (+ (* x x) t_0))
(t_2 (/ t_0 t_1))
(t_3 (* (* y 4.0) y)))
(if (< (/ (- (* x x) t_3) (+ (* x x) t_3)) 0.9743233849626781)
(- (/ (* x x) t_1) t_2)
(- (pow (/ x (sqrt t_1)) 2.0) t_2))))
double code(double x, double y) {
double t_0 = (y * y) * 4.0;
double t_1 = (x * x) + t_0;
double t_2 = t_0 / t_1;
double t_3 = (y * 4.0) * y;
double tmp;
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
tmp = ((x * x) / t_1) - t_2;
} else {
tmp = pow((x / sqrt(t_1)), 2.0) - t_2;
}
return tmp;
}
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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = (y * y) * 4.0d0
t_1 = (x * x) + t_0
t_2 = t_0 / t_1
t_3 = (y * 4.0d0) * y
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781d0) then
tmp = ((x * x) / t_1) - t_2
else
tmp = ((x / sqrt(t_1)) ** 2.0d0) - t_2
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * y) * 4.0;
double t_1 = (x * x) + t_0;
double t_2 = t_0 / t_1;
double t_3 = (y * 4.0) * y;
double tmp;
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
tmp = ((x * x) / t_1) - t_2;
} else {
tmp = Math.pow((x / Math.sqrt(t_1)), 2.0) - t_2;
}
return tmp;
}
def code(x, y): t_0 = (y * y) * 4.0 t_1 = (x * x) + t_0 t_2 = t_0 / t_1 t_3 = (y * 4.0) * y tmp = 0 if (((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781: tmp = ((x * x) / t_1) - t_2 else: tmp = math.pow((x / math.sqrt(t_1)), 2.0) - t_2 return tmp
function code(x, y) t_0 = Float64(Float64(y * y) * 4.0) t_1 = Float64(Float64(x * x) + t_0) t_2 = Float64(t_0 / t_1) t_3 = Float64(Float64(y * 4.0) * y) tmp = 0.0 if (Float64(Float64(Float64(x * x) - t_3) / Float64(Float64(x * x) + t_3)) < 0.9743233849626781) tmp = Float64(Float64(Float64(x * x) / t_1) - t_2); else tmp = Float64((Float64(x / sqrt(t_1)) ^ 2.0) - t_2); end return tmp end
function tmp_2 = code(x, y) t_0 = (y * y) * 4.0; t_1 = (x * x) + t_0; t_2 = t_0 / t_1; t_3 = (y * 4.0) * y; tmp = 0.0; if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) tmp = ((x * x) / t_1) - t_2; else tmp = ((x / sqrt(t_1)) ^ 2.0) - t_2; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] * 4.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, If[Less[N[(N[(N[(x * x), $MachinePrecision] - t$95$3), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$3), $MachinePrecision]), $MachinePrecision], 0.9743233849626781], N[(N[(N[(x * x), $MachinePrecision] / t$95$1), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[Power[N[(x / N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - t$95$2), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot y\right) \cdot 4\\
t_1 := x \cdot x + t_0\\
t_2 := \frac{t_0}{t_1}\\
t_3 := \left(y \cdot 4\right) \cdot y\\
\mathbf{if}\;\frac{x \cdot x - t_3}{x \cdot x + t_3} < 0.9743233849626781:\\
\;\;\;\;\frac{x \cdot x}{t_1} - t_2\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{x}{\sqrt{t_1}}\right)}^{2} - t_2\\
\end{array}
\end{array}
herbie shell --seed 2023230
(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))))