
(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 8 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 (fma y (sqrt x) (- 1.0 x)))
double code(double x, double y) {
return fma(y, sqrt(x), (1.0 - x));
}
function code(x, y) return fma(y, sqrt(x), Float64(1.0 - x)) end
code[x_, y_] := N[(y * N[Sqrt[x], $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \sqrt{x}, 1 - x\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.4e+19) (not (<= y 1.56e+49))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e+19) || !(y <= 1.56e+49)) {
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.4d+19)) .or. (.not. (y <= 1.56d+49))) 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.4e+19) || !(y <= 1.56e+49)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e+19) or not (y <= 1.56e+49): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e+19) || !(y <= 1.56e+49)) 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.4e+19) || ~((y <= 1.56e+49))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e+19], N[Not[LessEqual[y, 1.56e+49]], $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.4 \cdot 10^{+19} \lor \neg \left(y \leq 1.56 \cdot 10^{+49}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.4e19 or 1.56e49 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.3%
associate-*l*99.4%
fma-def99.4%
pow1/299.4%
sqrt-pow199.6%
metadata-eval99.6%
pow1/299.6%
sqrt-pow199.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in x around 0 95.9%
if -1.4e19 < y < 1.56e49Initial program 100.0%
Taylor expanded in y around 0 99.4%
Final simplification97.9%
(FPCore (x y) :precision binary64 (if (or (<= y -3.5e+96) (not (<= y 2.8e+71))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -3.5e+96) || !(y <= 2.8e+71)) {
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 <= (-3.5d+96)) .or. (.not. (y <= 2.8d+71))) 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 <= -3.5e+96) || !(y <= 2.8e+71)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.5e+96) or not (y <= 2.8e+71): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.5e+96) || !(y <= 2.8e+71)) 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 <= -3.5e+96) || ~((y <= 2.8e+71))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.5e+96], N[Not[LessEqual[y, 2.8e+71]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+96} \lor \neg \left(y \leq 2.8 \cdot 10^{+71}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -3.4999999999999999e96 or 2.80000000000000002e71 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.3%
associate-*l*99.4%
fma-def99.4%
pow1/299.4%
sqrt-pow199.6%
metadata-eval99.6%
pow1/299.6%
sqrt-pow199.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in y around inf 93.7%
if -3.4999999999999999e96 < y < 2.80000000000000002e71Initial program 100.0%
Taylor expanded in y around 0 95.8%
Final simplification95.0%
(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 (<= y 2.7e+143) (- 1.0 x) (pow y 2.0)))
double code(double x, double y) {
double tmp;
if (y <= 2.7e+143) {
tmp = 1.0 - x;
} else {
tmp = pow(y, 2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.7d+143) then
tmp = 1.0d0 - x
else
tmp = y ** 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.7e+143) {
tmp = 1.0 - x;
} else {
tmp = Math.pow(y, 2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.7e+143: tmp = 1.0 - x else: tmp = math.pow(y, 2.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.7e+143) tmp = Float64(1.0 - x); else tmp = y ^ 2.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.7e+143) tmp = 1.0 - x; else tmp = y ^ 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.7e+143], N[(1.0 - x), $MachinePrecision], N[Power[y, 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.7 \cdot 10^{+143}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;{y}^{2}\\
\end{array}
\end{array}
if y < 2.7000000000000002e143Initial program 99.9%
Taylor expanded in y around 0 74.2%
if 2.7000000000000002e143 < y Initial program 99.6%
flip-+36.2%
div-sub36.2%
pow236.2%
*-commutative36.2%
*-commutative36.2%
swap-sqr8.9%
add-sqr-sqrt8.8%
pow28.8%
Applied egg-rr8.8%
div-sub8.8%
*-commutative8.8%
Simplified8.8%
Taylor expanded in y around inf 9.5%
mul-1-neg9.5%
*-commutative9.5%
distribute-rgt-neg-in9.5%
Simplified9.5%
Taylor expanded in x around inf 38.5%
Final simplification69.3%
(FPCore (x y) :precision binary64 (if (<= x 6.1) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 6.1) {
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 <= 6.1d0) 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 <= 6.1) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 6.1: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 6.1) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 6.1) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 6.1], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 6.0999999999999996Initial program 99.8%
Taylor expanded in x around 0 64.1%
if 6.0999999999999996 < x Initial program 99.9%
Taylor expanded in x around inf 63.9%
neg-mul-163.9%
Simplified63.9%
Final simplification64.0%
(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.9%
Taylor expanded in y around 0 64.4%
Final simplification64.4%
(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 2023310
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))