
(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 -6.8e+44) (not (<= y 4.1e+41))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -6.8e+44) || !(y <= 4.1e+41)) {
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 <= (-6.8d+44)) .or. (.not. (y <= 4.1d+41))) 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 <= -6.8e+44) || !(y <= 4.1e+41)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.8e+44) or not (y <= 4.1e+41): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.8e+44) || !(y <= 4.1e+41)) 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 <= -6.8e+44) || ~((y <= 4.1e+41))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.8e+44], N[Not[LessEqual[y, 4.1e+41]], $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 -6.8 \cdot 10^{+44} \lor \neg \left(y \leq 4.1 \cdot 10^{+41}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -6.8e44 or 4.1000000000000004e41 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.3%
associate-*l*99.3%
fma-def99.3%
pow1/299.3%
sqrt-pow199.4%
metadata-eval99.4%
pow1/299.4%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 97.6%
if -6.8e44 < y < 4.1000000000000004e41Initial program 100.0%
Taylor expanded in y around 0 99.1%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= y -4.8e+57) (* y (sqrt x)) (if (<= y 1.25e+44) (- 1.0 x) (/ y (pow x -0.5)))))
double code(double x, double y) {
double tmp;
if (y <= -4.8e+57) {
tmp = y * sqrt(x);
} else if (y <= 1.25e+44) {
tmp = 1.0 - x;
} else {
tmp = y / pow(x, -0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-4.8d+57)) then
tmp = y * sqrt(x)
else if (y <= 1.25d+44) then
tmp = 1.0d0 - x
else
tmp = y / (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.8e+57) {
tmp = y * Math.sqrt(x);
} else if (y <= 1.25e+44) {
tmp = 1.0 - x;
} else {
tmp = y / Math.pow(x, -0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.8e+57: tmp = y * math.sqrt(x) elif y <= 1.25e+44: tmp = 1.0 - x else: tmp = y / math.pow(x, -0.5) return tmp
function code(x, y) tmp = 0.0 if (y <= -4.8e+57) tmp = Float64(y * sqrt(x)); elseif (y <= 1.25e+44) tmp = Float64(1.0 - x); else tmp = Float64(y / (x ^ -0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.8e+57) tmp = y * sqrt(x); elseif (y <= 1.25e+44) tmp = 1.0 - x; else tmp = y / (x ^ -0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.8e+57], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.25e+44], N[(1.0 - x), $MachinePrecision], N[(y / N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+57}:\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{+44}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{{x}^{-0.5}}\\
\end{array}
\end{array}
if y < -4.80000000000000009e57Initial program 99.7%
Taylor expanded in y around inf 89.0%
if -4.80000000000000009e57 < y < 1.2499999999999999e44Initial program 100.0%
Taylor expanded in y around 0 98.5%
if 1.2499999999999999e44 < 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.5%
metadata-eval99.5%
pow1/299.5%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
fma-udef99.3%
associate-*r*99.4%
pow-prod-up99.7%
metadata-eval99.7%
pow1/299.7%
*-commutative99.7%
+-commutative99.7%
flip-+49.5%
swap-sqr32.2%
add-sqr-sqrt32.3%
unpow232.3%
*-commutative32.3%
clear-num32.2%
clear-num32.3%
Applied egg-rr99.7%
Taylor expanded in y around inf 87.8%
inv-pow87.8%
inv-pow87.8%
unpow-prod-down87.5%
inv-pow87.5%
inv-pow87.5%
metadata-eval87.5%
sqrt-div87.5%
unpow-prod-down87.5%
inv-pow87.5%
inv-pow87.5%
pow-flip87.5%
metadata-eval87.5%
pow187.5%
inv-pow87.5%
sqrt-pow187.6%
metadata-eval87.6%
Applied egg-rr87.6%
unpow-187.6%
associate-*r/87.9%
*-rgt-identity87.9%
Simplified87.9%
Final simplification94.4%
(FPCore (x y) :precision binary64 (if (or (<= y -4.8e+57) (not (<= y 1.15e+41))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -4.8e+57) || !(y <= 1.15e+41)) {
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.8d+57)) .or. (.not. (y <= 1.15d+41))) 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.8e+57) || !(y <= 1.15e+41)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.8e+57) or not (y <= 1.15e+41): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.8e+57) || !(y <= 1.15e+41)) 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.8e+57) || ~((y <= 1.15e+41))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.8e+57], N[Not[LessEqual[y, 1.15e+41]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+57} \lor \neg \left(y \leq 1.15 \cdot 10^{+41}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -4.80000000000000009e57 or 1.1499999999999999e41 < y Initial program 99.7%
Taylor expanded in y around inf 88.5%
if -4.80000000000000009e57 < y < 1.1499999999999999e41Initial program 100.0%
Taylor expanded in y around 0 98.5%
Final simplification94.4%
(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 64.8%
if 1 < x Initial program 99.9%
Taylor expanded in x around inf 60.9%
mul-1-neg60.9%
Simplified60.9%
Final simplification62.8%
(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.0%
Final simplification64.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 31.9%
Final simplification31.9%
herbie shell --seed 2023257
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))