
(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.8e+81) (not (<= y 3.05e+60))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.8e+81) || !(y <= 3.05e+60)) {
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.8d+81)) .or. (.not. (y <= 3.05d+60))) 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.8e+81) || !(y <= 3.05e+60)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.8e+81) or not (y <= 3.05e+60): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.8e+81) || !(y <= 3.05e+60)) 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.8e+81) || ~((y <= 3.05e+60))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.8e+81], N[Not[LessEqual[y, 3.05e+60]], $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.8 \cdot 10^{+81} \lor \neg \left(y \leq 3.05 \cdot 10^{+60}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.80000000000000003e81 or 3.05e60 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.3%
associate-*l*99.2%
fma-def99.2%
pow1/299.2%
sqrt-pow199.3%
metadata-eval99.3%
pow1/299.3%
sqrt-pow199.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 97.3%
if -1.80000000000000003e81 < y < 3.05e60Initial program 100.0%
Taylor expanded in y around 0 96.4%
Final simplification96.8%
(FPCore (x y) :precision binary64 (if (or (<= y -3.8e+82) (not (<= y 3.7e+80))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -3.8e+82) || !(y <= 3.7e+80)) {
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.8d+82)) .or. (.not. (y <= 3.7d+80))) 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.8e+82) || !(y <= 3.7e+80)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.8e+82) or not (y <= 3.7e+80): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.8e+82) || !(y <= 3.7e+80)) 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.8e+82) || ~((y <= 3.7e+80))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.8e+82], N[Not[LessEqual[y, 3.7e+80]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+82} \lor \neg \left(y \leq 3.7 \cdot 10^{+80}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -3.80000000000000033e82 or 3.69999999999999996e80 < y Initial program 99.7%
Taylor expanded in y around inf 97.8%
if -3.80000000000000033e82 < y < 3.69999999999999996e80Initial program 100.0%
Taylor expanded in y around 0 94.8%
Final simplification96.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.35e+126) (* x (* y (- y))) (if (<= y 1e+111) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -2.35e+126) {
tmp = x * (y * -y);
} else if (y <= 1e+111) {
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 <= (-2.35d+126)) then
tmp = x * (y * -y)
else if (y <= 1d+111) 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 <= -2.35e+126) {
tmp = x * (y * -y);
} else if (y <= 1e+111) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.35e+126: tmp = x * (y * -y) elif y <= 1e+111: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.35e+126) tmp = Float64(x * Float64(y * Float64(-y))); elseif (y <= 1e+111) 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 <= -2.35e+126) tmp = x * (y * -y); elseif (y <= 1e+111) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.35e+126], N[(x * N[(y * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1e+111], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.35 \cdot 10^{+126}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \leq 10^{+111}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -2.3499999999999999e126Initial program 99.7%
flip-+33.3%
div-sub33.3%
pow233.3%
*-commutative33.3%
*-commutative33.3%
swap-sqr10.7%
add-sqr-sqrt10.7%
Applied egg-rr10.7%
div-sub10.7%
Simplified10.7%
Taylor expanded in y around inf 11.3%
unpow211.3%
associate-*r*11.3%
neg-mul-111.3%
Simplified11.3%
Taylor expanded in x around 0 24.6%
unpow224.6%
*-commutative24.6%
neg-mul-124.6%
distribute-rgt-neg-in24.6%
distribute-rgt-neg-in24.6%
Simplified24.6%
if -2.3499999999999999e126 < y < 9.99999999999999957e110Initial program 100.0%
Taylor expanded in y around 0 88.2%
if 9.99999999999999957e110 < y Initial program 99.7%
flip-+34.5%
div-sub34.5%
pow234.5%
*-commutative34.5%
*-commutative34.5%
swap-sqr17.9%
add-sqr-sqrt18.0%
Applied egg-rr18.0%
div-sub18.0%
Simplified18.0%
Taylor expanded in y around inf 19.0%
unpow219.0%
associate-*r*19.0%
neg-mul-119.0%
Simplified19.0%
Taylor expanded in x around inf 22.3%
unpow222.3%
Simplified22.3%
Final simplification64.2%
(FPCore (x y) :precision binary64 (if (<= y 1e+111) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 1e+111) {
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 <= 1d+111) 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 <= 1e+111) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1e+111: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 1e+111) 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 <= 1e+111) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1e+111], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{+111}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 9.99999999999999957e110Initial program 99.9%
Taylor expanded in y around 0 66.6%
if 9.99999999999999957e110 < y Initial program 99.7%
flip-+34.5%
div-sub34.5%
pow234.5%
*-commutative34.5%
*-commutative34.5%
swap-sqr17.9%
add-sqr-sqrt18.0%
Applied egg-rr18.0%
div-sub18.0%
Simplified18.0%
Taylor expanded in y around inf 19.0%
unpow219.0%
associate-*r*19.0%
neg-mul-119.0%
Simplified19.0%
Taylor expanded in x around inf 22.3%
unpow222.3%
Simplified22.3%
Final simplification59.7%
(FPCore (x y) :precision binary64 (if (<= x 13.2) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 13.2) {
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 <= 13.2d0) 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 <= 13.2) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 13.2: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 13.2) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 13.2) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 13.2], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 13.2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 13.199999999999999Initial program 99.8%
Taylor expanded in x around 0 56.2%
if 13.199999999999999 < x Initial program 99.9%
Taylor expanded in x around inf 55.8%
neg-mul-155.8%
Simplified55.8%
Final simplification56.0%
(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 29.4%
Final simplification29.4%
herbie shell --seed 2023171
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))