
(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-define99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y -1.8e+46) (* y (sqrt x)) (if (<= y 2.3e+81) (- 1.0 x) (/ 1.0 (/ (pow x -0.5) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.8e+46) {
tmp = y * sqrt(x);
} else if (y <= 2.3e+81) {
tmp = 1.0 - x;
} else {
tmp = 1.0 / (pow(x, -0.5) / 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.8d+46)) then
tmp = y * sqrt(x)
else if (y <= 2.3d+81) then
tmp = 1.0d0 - x
else
tmp = 1.0d0 / ((x ** (-0.5d0)) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.8e+46) {
tmp = y * Math.sqrt(x);
} else if (y <= 2.3e+81) {
tmp = 1.0 - x;
} else {
tmp = 1.0 / (Math.pow(x, -0.5) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.8e+46: tmp = y * math.sqrt(x) elif y <= 2.3e+81: tmp = 1.0 - x else: tmp = 1.0 / (math.pow(x, -0.5) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.8e+46) tmp = Float64(y * sqrt(x)); elseif (y <= 2.3e+81) tmp = Float64(1.0 - x); else tmp = Float64(1.0 / Float64((x ^ -0.5) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.8e+46) tmp = y * sqrt(x); elseif (y <= 2.3e+81) tmp = 1.0 - x; else tmp = 1.0 / ((x ^ -0.5) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.8e+46], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.3e+81], N[(1.0 - x), $MachinePrecision], N[(1.0 / N[(N[Power[x, -0.5], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+46}:\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+81}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{{x}^{-0.5}}{y}}\\
\end{array}
\end{array}
if y < -1.7999999999999999e46Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-sqr-sqrt99.2%
associate-*l*99.2%
fma-define99.2%
pow1/299.2%
sqrt-pow199.4%
metadata-eval99.4%
pow1/299.4%
sqrt-pow199.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in y around inf 89.6%
if -1.7999999999999999e46 < y < 2.2999999999999999e81Initial program 100.0%
Taylor expanded in y around 0 95.9%
if 2.2999999999999999e81 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.2%
associate-*l*99.3%
fma-define99.3%
pow1/299.3%
sqrt-pow199.4%
metadata-eval99.4%
pow1/299.4%
sqrt-pow199.4%
metadata-eval99.4%
Applied egg-rr99.4%
Applied egg-rr99.6%
Taylor expanded in y around inf 88.4%
associate-*r/88.6%
*-rgt-identity88.6%
Simplified88.6%
Taylor expanded in y around 0 88.4%
associate-*r/88.6%
*-rgt-identity88.6%
unpow1/288.6%
rem-exp-log84.3%
rec-exp84.3%
exp-prod84.3%
*-commutative84.3%
neg-mul-184.3%
associate-*r*84.3%
metadata-eval84.3%
log-pow84.3%
rem-exp-log88.6%
Simplified88.6%
Final simplification93.3%
(FPCore (x y) :precision binary64 (if (or (<= y -1.95e+46) (not (<= y 1.82e+81))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.95e+46) || !(y <= 1.82e+81)) {
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.95d+46)) .or. (.not. (y <= 1.82d+81))) 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.95e+46) || !(y <= 1.82e+81)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.95e+46) or not (y <= 1.82e+81): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.95e+46) || !(y <= 1.82e+81)) 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.95e+46) || ~((y <= 1.82e+81))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.95e+46], N[Not[LessEqual[y, 1.82e+81]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+46} \lor \neg \left(y \leq 1.82 \cdot 10^{+81}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.94999999999999997e46 or 1.82000000000000003e81 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.2%
associate-*l*99.2%
fma-define99.2%
pow1/299.2%
sqrt-pow199.4%
metadata-eval99.4%
pow1/299.4%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in y around inf 89.1%
if -1.94999999999999997e46 < y < 1.82000000000000003e81Initial program 100.0%
Taylor expanded in y around 0 95.9%
Final simplification93.3%
(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 (<= x 0.92) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 0.92) {
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 <= 0.92d0) 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 <= 0.92) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.92: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 0.92) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.92) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.92], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.92:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 0.92000000000000004Initial program 99.9%
Taylor expanded in x around 0 59.3%
if 0.92000000000000004 < x Initial program 99.9%
Taylor expanded in x around inf 62.9%
neg-mul-162.9%
Simplified62.9%
Final simplification61.2%
(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 62.4%
Final simplification62.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 28.6%
Final simplification28.6%
herbie shell --seed 2024039
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))