
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y): return (1.0 - x) + (y * math.sqrt(x))
function code(x, y) return Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) end
function tmp = code(x, y) tmp = (1.0 - x) + (y * sqrt(x)); end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y): return (1.0 - x) + (y * math.sqrt(x))
function code(x, y) return Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) end
function tmp = code(x, y) tmp = (1.0 - x) + (y * sqrt(x)); end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y): return (1.0 - x) + (y * math.sqrt(x))
function code(x, y) return Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) end
function tmp = code(x, y) tmp = (1.0 - x) + (y * sqrt(x)); end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}
Initial program 99.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.02e+54) (not (<= y 1.08e+63))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.02e+54) || !(y <= 1.08e+63)) {
tmp = 1.0 + (y * sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.02d+54)) .or. (.not. (y <= 1.08d+63))) then
tmp = 1.0d0 + (y * sqrt(x))
else
tmp = 1.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.02e+54) || !(y <= 1.08e+63)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.02e+54) or not (y <= 1.08e+63): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.02e+54) || !(y <= 1.08e+63)) tmp = Float64(1.0 + Float64(y * sqrt(x))); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.02e+54) || ~((y <= 1.08e+63))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.02e+54], N[Not[LessEqual[y, 1.08e+63]], $MachinePrecision]], N[(1.0 + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+54} \lor \neg \left(y \leq 1.08 \cdot 10^{+63}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.02e54 or 1.08e63 < y Initial program 99.6%
Taylor expanded in x around 0 94.2%
if -1.02e54 < y < 1.08e63Initial program 100.0%
add-sqr-sqrt100.0%
pow2100.0%
pow1/2100.0%
sqrt-pow1100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 99.3%
Final simplification97.2%
(FPCore (x y) :precision binary64 (if (or (<= y -1.95e+76) (not (<= y 7.6e+63))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.95e+76) || !(y <= 7.6e+63)) {
tmp = y * sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.95d+76)) .or. (.not. (y <= 7.6d+63))) then
tmp = y * sqrt(x)
else
tmp = 1.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.95e+76) || !(y <= 7.6e+63)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.95e+76) or not (y <= 7.6e+63): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.95e+76) || !(y <= 7.6e+63)) tmp = Float64(y * sqrt(x)); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.95e+76) || ~((y <= 7.6e+63))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.95e+76], N[Not[LessEqual[y, 7.6e+63]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+76} \lor \neg \left(y \leq 7.6 \cdot 10^{+63}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.94999999999999995e76 or 7.6000000000000002e63 < y Initial program 99.6%
Taylor expanded in x around inf 84.5%
associate--l+84.5%
distribute-rgt-in84.5%
Simplified99.5%
sqrt-div99.4%
metadata-eval99.4%
un-div-inv99.5%
Applied egg-rr99.5%
frac-2neg99.5%
clear-num99.4%
frac-2neg99.4%
clear-num99.4%
pow199.4%
pow1/299.4%
pow-div99.5%
metadata-eval99.5%
pow1/299.5%
associate-*l/99.5%
*-un-lft-identity99.5%
pow1/299.5%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in y around inf 90.7%
if -1.94999999999999995e76 < y < 7.6000000000000002e63Initial program 100.0%
add-sqr-sqrt100.0%
pow2100.0%
pow1/2100.0%
sqrt-pow1100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 97.4%
Final simplification94.8%
(FPCore (x y) :precision binary64 (if (<= x 1.0) (+ 1.0 (/ y (pow x -0.5))) (- (* y (sqrt x)) x)))
double code(double x, double y) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 + (y / pow(x, -0.5));
} else {
tmp = (y * sqrt(x)) - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 1.0d0 + (y / (x ** (-0.5d0)))
else
tmp = (y * sqrt(x)) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 + (y / Math.pow(x, -0.5));
} else {
tmp = (y * Math.sqrt(x)) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.0: tmp = 1.0 + (y / math.pow(x, -0.5)) else: tmp = (y * math.sqrt(x)) - x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 + Float64(y / (x ^ -0.5))); else tmp = Float64(Float64(y * sqrt(x)) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.0) tmp = 1.0 + (y / (x ^ -0.5)); else tmp = (y * sqrt(x)) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.0], N[(1.0 + N[(y / N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 + \frac{y}{{x}^{-0.5}}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \sqrt{x} - x\\
\end{array}
\end{array}
if x < 1Initial program 99.8%
Taylor expanded in x around inf 88.6%
associate--l+88.6%
distribute-rgt-in88.6%
Simplified99.7%
sqrt-div99.7%
metadata-eval99.7%
un-div-inv99.7%
Applied egg-rr99.7%
frac-2neg99.7%
clear-num99.7%
frac-2neg99.7%
clear-num99.7%
pow199.7%
pow1/299.7%
pow-div99.7%
metadata-eval99.7%
pow1/299.7%
associate-*l/99.8%
*-un-lft-identity99.8%
pow1/299.8%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.1%
if 1 < x Initial program 99.9%
Taylor expanded in x around inf 98.5%
neg-mul-198.5%
Simplified98.5%
Final simplification98.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= x 1.0) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
double tmp;
if (x <= 1.0) {
tmp = 1.0 + t_0;
} else {
tmp = t_0 - x;
}
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 = y * sqrt(x)
if (x <= 1.0d0) then
tmp = 1.0d0 + t_0
else
tmp = t_0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * Math.sqrt(x);
double tmp;
if (x <= 1.0) {
tmp = 1.0 + t_0;
} else {
tmp = t_0 - x;
}
return tmp;
}
def code(x, y): t_0 = y * math.sqrt(x) tmp = 0 if x <= 1.0: tmp = 1.0 + t_0 else: tmp = t_0 - x return tmp
function code(x, y) t_0 = Float64(y * sqrt(x)) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 + t_0); else tmp = Float64(t_0 - x); end return tmp end
function tmp_2 = code(x, y) t_0 = y * sqrt(x); tmp = 0.0; if (x <= 1.0) tmp = 1.0 + t_0; else tmp = t_0 - x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.0], N[(1.0 + t$95$0), $MachinePrecision], N[(t$95$0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \sqrt{x}\\
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if x < 1Initial program 99.8%
Taylor expanded in x around 0 99.0%
if 1 < x Initial program 99.9%
Taylor expanded in x around inf 98.5%
neg-mul-198.5%
Simplified98.5%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (<= y -3.8e+145) (/ (* y (- x)) y) (if (<= y 9.2e+87) (- 1.0 x) (/ (+ y (* x y)) y))))
double code(double x, double y) {
double tmp;
if (y <= -3.8e+145) {
tmp = (y * -x) / y;
} else if (y <= 9.2e+87) {
tmp = 1.0 - x;
} else {
tmp = (y + (x * y)) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-3.8d+145)) then
tmp = (y * -x) / y
else if (y <= 9.2d+87) then
tmp = 1.0d0 - x
else
tmp = (y + (x * y)) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.8e+145) {
tmp = (y * -x) / y;
} else if (y <= 9.2e+87) {
tmp = 1.0 - x;
} else {
tmp = (y + (x * y)) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.8e+145: tmp = (y * -x) / y elif y <= 9.2e+87: tmp = 1.0 - x else: tmp = (y + (x * y)) / y return tmp
function code(x, y) tmp = 0.0 if (y <= -3.8e+145) tmp = Float64(Float64(y * Float64(-x)) / y); elseif (y <= 9.2e+87) tmp = Float64(1.0 - x); else tmp = Float64(Float64(y + Float64(x * y)) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.8e+145) tmp = (y * -x) / y; elseif (y <= 9.2e+87) tmp = 1.0 - x; else tmp = (y + (x * y)) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.8e+145], N[(N[(y * (-x)), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 9.2e+87], N[(1.0 - x), $MachinePrecision], N[(N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+145}:\\
\;\;\;\;\frac{y \cdot \left(-x\right)}{y}\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{+87}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{y + x \cdot y}{y}\\
\end{array}
\end{array}
if y < -3.80000000000000012e145Initial program 99.6%
Taylor expanded in y around inf 99.6%
associate--l+99.6%
div-sub99.6%
Simplified99.6%
Taylor expanded in y around 0 3.1%
associate-*r/20.6%
Applied egg-rr20.6%
Taylor expanded in x around inf 21.8%
mul-1-neg21.8%
*-commutative21.8%
distribute-rgt-neg-in21.8%
Simplified21.8%
if -3.80000000000000012e145 < y < 9.2000000000000007e87Initial program 99.9%
add-sqr-sqrt99.9%
pow299.9%
pow1/299.9%
sqrt-pow199.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 87.9%
if 9.2000000000000007e87 < y Initial program 99.6%
Taylor expanded in y around inf 99.6%
associate--l+99.6%
div-sub99.6%
Simplified99.6%
Taylor expanded in y around 0 5.2%
associate-*r/5.1%
Applied egg-rr5.1%
sub-neg5.1%
distribute-lft-in5.1%
*-rgt-identity5.1%
add-sqr-sqrt0.0%
sqrt-unprod27.6%
sqr-neg27.6%
sqrt-unprod27.6%
add-sqr-sqrt27.6%
Applied egg-rr27.6%
Final simplification68.4%
(FPCore (x y) :precision binary64 (if (<= y -1.8e+143) (/ (* y (- x)) y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if (y <= -1.8e+143) {
tmp = (y * -x) / y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.8d+143)) then
tmp = (y * -x) / y
else
tmp = 1.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.8e+143) {
tmp = (y * -x) / y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.8e+143: tmp = (y * -x) / y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.8e+143) tmp = Float64(Float64(y * Float64(-x)) / y); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.8e+143) tmp = (y * -x) / y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.8e+143], N[(N[(y * (-x)), $MachinePrecision] / y), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+143}:\\
\;\;\;\;\frac{y \cdot \left(-x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.8e143Initial program 99.6%
Taylor expanded in y around inf 99.6%
associate--l+99.6%
div-sub99.6%
Simplified99.6%
Taylor expanded in y around 0 3.1%
associate-*r/20.6%
Applied egg-rr20.6%
Taylor expanded in x around inf 21.8%
mul-1-neg21.8%
*-commutative21.8%
distribute-rgt-neg-in21.8%
Simplified21.8%
if -1.8e143 < y Initial program 99.9%
add-sqr-sqrt99.8%
pow299.8%
pow1/299.8%
sqrt-pow199.8%
metadata-eval99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 72.7%
(FPCore (x y) :precision binary64 (if (<= x 1.0) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 1.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 1.0d0
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.0], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 1Initial program 99.8%
Taylor expanded in x around 0 99.0%
Taylor expanded in y around 0 63.1%
if 1 < x Initial program 99.9%
Taylor expanded in y around inf 76.8%
associate--l+76.8%
div-sub76.8%
Simplified76.8%
Taylor expanded in y around 0 36.9%
Taylor expanded in x around inf 58.6%
neg-mul-158.6%
Simplified58.6%
(FPCore (x y) :precision binary64 (- 1.0 x))
double code(double x, double y) {
return 1.0 - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - x
end function
public static double code(double x, double y) {
return 1.0 - x;
}
def code(x, y): return 1.0 - x
function code(x, y) return Float64(1.0 - x) end
function tmp = code(x, y) tmp = 1.0 - x; end
code[x_, y_] := N[(1.0 - x), $MachinePrecision]
\begin{array}{l}
\\
1 - x
\end{array}
Initial program 99.8%
add-sqr-sqrt99.7%
pow299.7%
pow1/299.7%
sqrt-pow199.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 62.1%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 72.2%
Taylor expanded in y around 0 34.8%
herbie shell --seed 2024145
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))