
(FPCore (x y) :precision binary64 (sqrt (+ (* x x) y)))
double code(double x, double y) {
return sqrt(((x * x) + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(((x * x) + y))
end function
public static double code(double x, double y) {
return Math.sqrt(((x * x) + y));
}
def code(x, y): return math.sqrt(((x * x) + y))
function code(x, y) return sqrt(Float64(Float64(x * x) + y)) end
function tmp = code(x, y) tmp = sqrt(((x * x) + y)); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x \cdot x + y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (sqrt (+ (* x x) y)))
double code(double x, double y) {
return sqrt(((x * x) + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(((x * x) + y))
end function
public static double code(double x, double y) {
return Math.sqrt(((x * x) + y));
}
def code(x, y): return math.sqrt(((x * x) + y))
function code(x, y) return sqrt(Float64(Float64(x * x) + y)) end
function tmp = code(x, y) tmp = sqrt(((x * x) + y)); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x \cdot x + y}
\end{array}
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= (* x x) 4e+257) (sqrt (fma x x y)) x))
x = abs(x);
double code(double x, double y) {
double tmp;
if ((x * x) <= 4e+257) {
tmp = sqrt(fma(x, x, y));
} else {
tmp = x;
}
return tmp;
}
x = abs(x) function code(x, y) tmp = 0.0 if (Float64(x * x) <= 4e+257) tmp = sqrt(fma(x, x, y)); else tmp = x; end return tmp end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 4e+257], N[Sqrt[N[(x * x + y), $MachinePrecision]], $MachinePrecision], x]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{+257}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(x, x, y\right)}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 x x) < 4.00000000000000012e257Initial program 100.0%
fma-def100.0%
Simplified100.0%
if 4.00000000000000012e257 < (*.f64 x x) Initial program 16.2%
Taylor expanded in x around inf 47.7%
Final simplification79.0%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= (* x x) 4e+257) (sqrt (+ (* x x) y)) x))
x = abs(x);
double code(double x, double y) {
double tmp;
if ((x * x) <= 4e+257) {
tmp = sqrt(((x * x) + y));
} else {
tmp = x;
}
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) <= 4d+257) then
tmp = sqrt(((x * x) + y))
else
tmp = x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 4e+257) {
tmp = Math.sqrt(((x * x) + y));
} else {
tmp = x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if (x * x) <= 4e+257: tmp = math.sqrt(((x * x) + y)) else: tmp = x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (Float64(x * x) <= 4e+257) tmp = sqrt(Float64(Float64(x * x) + y)); else tmp = x; end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 4e+257) tmp = sqrt(((x * x) + y)); else tmp = x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 4e+257], N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision], x]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{+257}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 x x) < 4.00000000000000012e257Initial program 100.0%
if 4.00000000000000012e257 < (*.f64 x x) Initial program 16.2%
Taylor expanded in x around inf 47.7%
Final simplification79.0%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (or (<= x 2e-54) (and (not (<= x 7e-37)) (<= x 1.4e-17))) (sqrt y) (+ x (* 0.5 (/ y x)))))
x = abs(x);
double code(double x, double y) {
double tmp;
if ((x <= 2e-54) || (!(x <= 7e-37) && (x <= 1.4e-17))) {
tmp = sqrt(y);
} else {
tmp = x + (0.5 * (y / x));
}
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-54) .or. (.not. (x <= 7d-37)) .and. (x <= 1.4d-17)) then
tmp = sqrt(y)
else
tmp = x + (0.5d0 * (y / x))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if ((x <= 2e-54) || (!(x <= 7e-37) && (x <= 1.4e-17))) {
tmp = Math.sqrt(y);
} else {
tmp = x + (0.5 * (y / x));
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if (x <= 2e-54) or (not (x <= 7e-37) and (x <= 1.4e-17)): tmp = math.sqrt(y) else: tmp = x + (0.5 * (y / x)) return tmp
x = abs(x) function code(x, y) tmp = 0.0 if ((x <= 2e-54) || (!(x <= 7e-37) && (x <= 1.4e-17))) tmp = sqrt(y); else tmp = Float64(x + Float64(0.5 * Float64(y / x))); end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if ((x <= 2e-54) || (~((x <= 7e-37)) && (x <= 1.4e-17))) tmp = sqrt(y); else tmp = x + (0.5 * (y / x)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[Or[LessEqual[x, 2e-54], And[N[Not[LessEqual[x, 7e-37]], $MachinePrecision], LessEqual[x, 1.4e-17]]], N[Sqrt[y], $MachinePrecision], N[(x + N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{-54} \lor \neg \left(x \leq 7 \cdot 10^{-37}\right) \land x \leq 1.4 \cdot 10^{-17}:\\
\;\;\;\;\sqrt{y}\\
\mathbf{else}:\\
\;\;\;\;x + 0.5 \cdot \frac{y}{x}\\
\end{array}
\end{array}
if x < 2.0000000000000001e-54 or 7.0000000000000003e-37 < x < 1.3999999999999999e-17Initial program 73.1%
Taylor expanded in x around 0 47.3%
if 2.0000000000000001e-54 < x < 7.0000000000000003e-37 or 1.3999999999999999e-17 < x Initial program 53.9%
Taylor expanded in x around inf 93.6%
Final simplification63.8%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (+ x (* 0.5 (/ y x))))
x = abs(x);
double code(double x, double y) {
return x + (0.5 * (y / x));
}
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 = x + (0.5d0 * (y / x))
end function
x = Math.abs(x);
public static double code(double x, double y) {
return x + (0.5 * (y / x));
}
x = abs(x) def code(x, y): return x + (0.5 * (y / x))
x = abs(x) function code(x, y) return Float64(x + Float64(0.5 * Float64(y / x))) end
x = abs(x) function tmp = code(x, y) tmp = x + (0.5 * (y / x)); end
NOTE: x should be positive before calling this function code[x_, y_] := N[(x + N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
x + 0.5 \cdot \frac{y}{x}
\end{array}
Initial program 66.3%
Taylor expanded in x around inf 36.7%
Final simplification36.7%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 x)
x = abs(x);
double code(double x, double y) {
return x;
}
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 = x
end function
x = Math.abs(x);
public static double code(double x, double y) {
return x;
}
x = abs(x) def code(x, y): return x
x = abs(x) function code(x, y) return x end
x = abs(x) function tmp = code(x, y) tmp = x; end
NOTE: x should be positive before calling this function code[x_, y_] := x
\begin{array}{l}
x = |x|\\
\\
x
\end{array}
Initial program 66.3%
Taylor expanded in x around inf 36.7%
Final simplification36.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (* 0.5 (/ y x)) x)))
(if (< x -1.5097698010472593e+153)
(- t_0)
(if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) t_0))))
double code(double x, double y) {
double t_0 = (0.5 * (y / x)) + x;
double tmp;
if (x < -1.5097698010472593e+153) {
tmp = -t_0;
} else if (x < 5.582399551122541e+57) {
tmp = sqrt(((x * x) + y));
} else {
tmp = t_0;
}
return tmp;
}
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 = (0.5d0 * (y / x)) + x
if (x < (-1.5097698010472593d+153)) then
tmp = -t_0
else if (x < 5.582399551122541d+57) then
tmp = sqrt(((x * x) + y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (0.5 * (y / x)) + x;
double tmp;
if (x < -1.5097698010472593e+153) {
tmp = -t_0;
} else if (x < 5.582399551122541e+57) {
tmp = Math.sqrt(((x * x) + y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (0.5 * (y / x)) + x tmp = 0 if x < -1.5097698010472593e+153: tmp = -t_0 elif x < 5.582399551122541e+57: tmp = math.sqrt(((x * x) + y)) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(0.5 * Float64(y / x)) + x) tmp = 0.0 if (x < -1.5097698010472593e+153) tmp = Float64(-t_0); elseif (x < 5.582399551122541e+57) tmp = sqrt(Float64(Float64(x * x) + y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (0.5 * (y / x)) + x; tmp = 0.0; if (x < -1.5097698010472593e+153) tmp = -t_0; elseif (x < 5.582399551122541e+57) tmp = sqrt(((x * x) + y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, If[Less[x, -1.5097698010472593e+153], (-t$95$0), If[Less[x, 5.582399551122541e+57], N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{y}{x} + x\\
\mathbf{if}\;x < -1.5097698010472593 \cdot 10^{+153}:\\
\;\;\;\;-t_0\\
\mathbf{elif}\;x < 5.582399551122541 \cdot 10^{+57}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
herbie shell --seed 2023240
(FPCore (x y)
:name "Linear.Quaternion:$clog from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< x -1.5097698010472593e+153) (- (+ (* 0.5 (/ y x)) x)) (if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) (+ (* 0.5 (/ y x)) x)))
(sqrt (+ (* x x) y)))