
(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 (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 -8.5e+19) (not (<= y 1.2e+17))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -8.5e+19) || !(y <= 1.2e+17)) {
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 <= (-8.5d+19)) .or. (.not. (y <= 1.2d+17))) 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 <= -8.5e+19) || !(y <= 1.2e+17)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8.5e+19) or not (y <= 1.2e+17): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -8.5e+19) || !(y <= 1.2e+17)) 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 <= -8.5e+19) || ~((y <= 1.2e+17))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -8.5e+19], N[Not[LessEqual[y, 1.2e+17]], $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 -8.5 \cdot 10^{+19} \lor \neg \left(y \leq 1.2 \cdot 10^{+17}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -8.5e19 or 1.2e17 < y Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-sqr-sqrt99.4%
associate-*l*99.4%
fma-def99.4%
pow1/299.4%
sqrt-pow199.5%
metadata-eval99.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 90.6%
if -8.5e19 < y < 1.2e17Initial program 100.0%
Taylor expanded in y around 0 99.1%
Final simplification94.9%
(FPCore (x y) :precision binary64 (if (or (<= y -4.5e+84) (not (<= y 4.2e+59))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -4.5e+84) || !(y <= 4.2e+59)) {
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 <= (-4.5d+84)) .or. (.not. (y <= 4.2d+59))) 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 <= -4.5e+84) || !(y <= 4.2e+59)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.5e+84) or not (y <= 4.2e+59): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.5e+84) || !(y <= 4.2e+59)) 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 <= -4.5e+84) || ~((y <= 4.2e+59))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.5e+84], N[Not[LessEqual[y, 4.2e+59]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+84} \lor \neg \left(y \leq 4.2 \cdot 10^{+59}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -4.4999999999999997e84 or 4.19999999999999968e59 < y Initial program 99.8%
Taylor expanded in y around inf 90.6%
if -4.4999999999999997e84 < y < 4.19999999999999968e59Initial program 100.0%
Taylor expanded in y around 0 92.5%
Final simplification91.8%
(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 4e+147) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 4e+147) {
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 <= 4d+147) 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 <= 4e+147) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4e+147: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 4e+147) 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 <= 4e+147) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4e+147], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4 \cdot 10^{+147}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 3.9999999999999999e147Initial program 99.9%
Taylor expanded in y around 0 67.3%
if 3.9999999999999999e147 < y Initial program 99.7%
flip-+29.5%
div-sub29.5%
pow229.5%
*-commutative29.5%
*-commutative29.5%
swap-sqr3.5%
add-sqr-sqrt3.5%
Applied egg-rr3.5%
div-sub3.5%
Simplified3.5%
Taylor expanded in x around 0 4.4%
associate-*r*4.4%
neg-mul-14.4%
unpow24.4%
Simplified4.4%
Taylor expanded in y around inf 4.4%
*-commutative4.4%
associate-*r*4.4%
mul-1-neg4.4%
unpow24.4%
associate-*r*30.2%
Simplified30.2%
Taylor expanded in x around inf 28.6%
unpow228.6%
Simplified28.6%
Final simplification62.3%
(FPCore (x y) :precision binary64 (if (<= x 7400.0) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 7400.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 <= 7400.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 <= 7400.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 7400.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 7400.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 7400.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 7400.0], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7400:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 7400Initial program 99.9%
Taylor expanded in x around 0 53.4%
if 7400 < x Initial program 99.9%
Taylor expanded in x around inf 61.2%
neg-mul-161.2%
Simplified61.2%
Final simplification57.2%
(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 28.1%
Final simplification28.1%
herbie shell --seed 2023199
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))