
(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 7 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.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1e+42) (not (<= y 7.6e+25))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1e+42) || !(y <= 7.6e+25)) {
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 <= (-1d+42)) .or. (.not. (y <= 7.6d+25))) 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 <= -1e+42) || !(y <= 7.6e+25)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1e+42) or not (y <= 7.6e+25): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1e+42) || !(y <= 7.6e+25)) 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 <= -1e+42) || ~((y <= 7.6e+25))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1e+42], N[Not[LessEqual[y, 7.6e+25]], $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 \cdot 10^{+42} \lor \neg \left(y \leq 7.6 \cdot 10^{+25}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.00000000000000004e42 or 7.6000000000000001e25 < y Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
add-sqr-sqrt99.2%
associate-*l*99.2%
fma-def99.2%
pow1/299.2%
sqrt-pow199.3%
metadata-eval99.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 95.3%
if -1.00000000000000004e42 < y < 7.6000000000000001e25Initial program 100.0%
Taylor expanded in y around 0 99.4%
Final simplification97.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.3e+73) (not (<= y 5.5e+54))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.3e+73) || !(y <= 5.5e+54)) {
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.3d+73)) .or. (.not. (y <= 5.5d+54))) 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.3e+73) || !(y <= 5.5e+54)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.3e+73) or not (y <= 5.5e+54): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.3e+73) || !(y <= 5.5e+54)) 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.3e+73) || ~((y <= 5.5e+54))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.3e+73], N[Not[LessEqual[y, 5.5e+54]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{+73} \lor \neg \left(y \leq 5.5 \cdot 10^{+54}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.3e73 or 5.50000000000000026e54 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.1%
associate-*l*99.2%
fma-def99.2%
pow1/299.2%
sqrt-pow199.3%
metadata-eval99.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in y around inf 90.0%
if -1.3e73 < y < 5.50000000000000026e54Initial program 100.0%
Taylor expanded in y around 0 97.7%
Final simplification94.8%
(FPCore (x y) :precision binary64 (if (<= y -3.2e+133) (* y (* x (- y))) (if (<= y 4.3e+156) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -3.2e+133) {
tmp = y * (x * -y);
} else if (y <= 4.3e+156) {
tmp = 1.0 - x;
} else {
tmp = 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.2d+133)) then
tmp = y * (x * -y)
else if (y <= 4.3d+156) then
tmp = 1.0d0 - x
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.2e+133) {
tmp = y * (x * -y);
} else if (y <= 4.3e+156) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.2e+133: tmp = y * (x * -y) elif y <= 4.3e+156: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -3.2e+133) tmp = Float64(y * Float64(x * Float64(-y))); elseif (y <= 4.3e+156) tmp = Float64(1.0 - x); else tmp = Float64(y * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.2e+133) tmp = y * (x * -y); elseif (y <= 4.3e+156) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.2e+133], N[(y * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.3e+156], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+133}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{+156}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -3.19999999999999997e133Initial program 99.6%
flip-+30.5%
div-sub30.5%
pow230.5%
associate--l-30.5%
*-commutative30.5%
*-commutative30.5%
swap-sqr13.5%
add-sqr-sqrt13.4%
associate--l-13.4%
Applied egg-rr13.4%
div-sub13.4%
associate--r+13.4%
*-commutative13.4%
Simplified13.4%
Taylor expanded in y around inf 14.9%
mul-1-neg14.9%
unpow214.9%
distribute-rgt-neg-in14.9%
distribute-rgt-neg-in14.9%
Simplified14.9%
Taylor expanded in x around 0 29.9%
unpow229.9%
associate-*r*30.3%
associate-*r*30.3%
neg-mul-130.3%
*-commutative30.3%
distribute-rgt-neg-in30.3%
Simplified30.3%
if -3.19999999999999997e133 < y < 4.29999999999999985e156Initial program 99.9%
Taylor expanded in y around 0 84.2%
if 4.29999999999999985e156 < y Initial program 99.7%
flip-+33.2%
div-sub33.2%
pow233.2%
associate--l-33.2%
*-commutative33.2%
*-commutative33.2%
swap-sqr3.6%
add-sqr-sqrt3.6%
associate--l-3.6%
Applied egg-rr3.6%
div-sub3.6%
associate--r+3.6%
*-commutative3.6%
Simplified3.6%
Taylor expanded in y around inf 3.8%
mul-1-neg3.8%
unpow23.8%
distribute-rgt-neg-in3.8%
distribute-rgt-neg-in3.8%
Simplified3.8%
Taylor expanded in x around inf 31.9%
unpow231.9%
Simplified31.9%
Final simplification71.8%
(FPCore (x y) :precision binary64 (if (<= y 1.85e+156) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 1.85e+156) {
tmp = 1.0 - x;
} else {
tmp = 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 <= 1.85d+156) then
tmp = 1.0d0 - x
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.85e+156) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.85e+156: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.85e+156) tmp = Float64(1.0 - x); else tmp = Float64(y * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.85e+156) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.85e+156], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{+156}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 1.85000000000000001e156Initial program 99.9%
Taylor expanded in y around 0 74.1%
if 1.85000000000000001e156 < y Initial program 99.7%
flip-+33.2%
div-sub33.2%
pow233.2%
associate--l-33.2%
*-commutative33.2%
*-commutative33.2%
swap-sqr3.6%
add-sqr-sqrt3.6%
associate--l-3.6%
Applied egg-rr3.6%
div-sub3.6%
associate--r+3.6%
*-commutative3.6%
Simplified3.6%
Taylor expanded in y around inf 3.8%
mul-1-neg3.8%
unpow23.8%
distribute-rgt-neg-in3.8%
distribute-rgt-neg-in3.8%
Simplified3.8%
Taylor expanded in x around inf 31.9%
unpow231.9%
Simplified31.9%
Final simplification68.8%
(FPCore (x y) :precision binary64 (if (<= x 8400000000.0) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 8400000000.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 <= 8400000000.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 <= 8400000000.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 8400000000.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 8400000000.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 8400000000.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 8400000000.0], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8400000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 8.4e9Initial program 99.8%
Taylor expanded in x around 0 61.4%
if 8.4e9 < x Initial program 99.9%
Taylor expanded in x around inf 66.1%
mul-1-neg66.1%
Simplified66.1%
Final simplification63.5%
(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.9%
Taylor expanded in x around 0 34.0%
Final simplification34.0%
herbie shell --seed 2023297
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))