
(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 Float64(fma(y, sqrt(x), 1.0) - x) end
code[x_, y_] := N[(N[(y * N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \sqrt{x}, 1\right) - x
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
associate-+r-N/A
lower--.f64N/A
lift-*.f64N/A
lower-fma.f6499.9
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (if (<= (+ (* y (sqrt x)) (- 1.0 x)) -1000.0) (- x) (+ x 1.0)))
double code(double x, double y) {
double tmp;
if (((y * sqrt(x)) + (1.0 - x)) <= -1000.0) {
tmp = -x;
} else {
tmp = x + 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((y * sqrt(x)) + (1.0d0 - x)) <= (-1000.0d0)) then
tmp = -x
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((y * Math.sqrt(x)) + (1.0 - x)) <= -1000.0) {
tmp = -x;
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((y * math.sqrt(x)) + (1.0 - x)) <= -1000.0: tmp = -x else: tmp = x + 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(y * sqrt(x)) + Float64(1.0 - x)) <= -1000.0) tmp = Float64(-x); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((y * sqrt(x)) + (1.0 - x)) <= -1000.0) tmp = -x; else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision], -1000.0], (-x), N[(x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \sqrt{x} + \left(1 - x\right) \leq -1000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -1e3Initial program 99.9%
Taylor expanded in y around 0
lower--.f6470.4
Applied rewrites70.4%
Taylor expanded in x around inf
Applied rewrites70.2%
if -1e3 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.9%
Applied rewrites89.1%
Taylor expanded in y around 0
lower-+.f6466.4
Applied rewrites66.4%
Final simplification68.4%
(FPCore (x y) :precision binary64 (if (<= (+ (* y (sqrt x)) (- 1.0 x)) -1000.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (((y * sqrt(x)) + (1.0 - x)) <= -1000.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((y * sqrt(x)) + (1.0d0 - x)) <= (-1000.0d0)) then
tmp = -x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((y * Math.sqrt(x)) + (1.0 - x)) <= -1000.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((y * math.sqrt(x)) + (1.0 - x)) <= -1000.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(y * sqrt(x)) + Float64(1.0 - x)) <= -1000.0) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((y * sqrt(x)) + (1.0 - x)) <= -1000.0) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision], -1000.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \sqrt{x} + \left(1 - x\right) \leq -1000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -1e3Initial program 99.9%
Taylor expanded in y around 0
lower--.f6470.4
Applied rewrites70.4%
Taylor expanded in x around inf
Applied rewrites70.2%
if -1e3 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.9%
Taylor expanded in y around 0
lower--.f6466.2
Applied rewrites66.2%
Taylor expanded in x around 0
Applied rewrites65.8%
Final simplification68.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma (sqrt x) y 1.0))) (if (<= y -2.1e+85) t_0 (if (<= y 3e+76) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = fma(sqrt(x), y, 1.0);
double tmp;
if (y <= -2.1e+85) {
tmp = t_0;
} else if (y <= 3e+76) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(sqrt(x), y, 1.0) tmp = 0.0 if (y <= -2.1e+85) tmp = t_0; elseif (y <= 3e+76) tmp = Float64(1.0 - x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision]}, If[LessEqual[y, -2.1e+85], t$95$0, If[LessEqual[y, 3e+76], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\mathbf{if}\;y \leq -2.1 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+76}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.1000000000000001e85 or 2.9999999999999998e76 < y Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6498.6
Applied rewrites98.6%
if -2.1000000000000001e85 < y < 2.9999999999999998e76Initial program 100.0%
Taylor expanded in y around 0
lower--.f6496.7
Applied rewrites96.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= y -3.8e+86) t_0 (if (<= y 5.1e+110) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
double tmp;
if (y <= -3.8e+86) {
tmp = t_0;
} else if (y <= 5.1e+110) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * sqrt(x)
if (y <= (-3.8d+86)) then
tmp = t_0
else if (y <= 5.1d+110) then
tmp = 1.0d0 - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * Math.sqrt(x);
double tmp;
if (y <= -3.8e+86) {
tmp = t_0;
} else if (y <= 5.1e+110) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * math.sqrt(x) tmp = 0 if y <= -3.8e+86: tmp = t_0 elif y <= 5.1e+110: tmp = 1.0 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * sqrt(x)) tmp = 0.0 if (y <= -3.8e+86) tmp = t_0; elseif (y <= 5.1e+110) tmp = Float64(1.0 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * sqrt(x); tmp = 0.0; if (y <= -3.8e+86) tmp = t_0; elseif (y <= 5.1e+110) tmp = 1.0 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.8e+86], t$95$0, If[LessEqual[y, 5.1e+110], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \sqrt{x}\\
\mathbf{if}\;y \leq -3.8 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{+110}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.79999999999999978e86 or 5.1000000000000002e110 < y Initial program 99.8%
Taylor expanded in y around inf
lower-*.f64N/A
lower-sqrt.f6498.4
Applied rewrites98.4%
if -3.79999999999999978e86 < y < 5.1000000000000002e110Initial program 99.9%
Taylor expanded in y around 0
lower--.f6495.2
Applied rewrites95.2%
Final simplification96.2%
(FPCore (x y) :precision binary64 (if (<= x 1.0) (fma (sqrt x) y 1.0) (- (* y (sqrt x)) x)))
double code(double x, double y) {
double tmp;
if (x <= 1.0) {
tmp = fma(sqrt(x), y, 1.0);
} else {
tmp = (y * sqrt(x)) - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 1.0) tmp = fma(sqrt(x), y, 1.0); else tmp = Float64(Float64(y * sqrt(x)) - x); end return tmp end
code[x_, y_] := If[LessEqual[x, 1.0], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision], N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \sqrt{x} - x\\
\end{array}
\end{array}
if x < 1Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6498.9
Applied rewrites98.9%
if 1 < x Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
associate-+r-N/A
lower--.f64N/A
lift-*.f64N/A
lower-fma.f6499.9
Applied rewrites99.9%
Taylor expanded in y around inf
lower-*.f64N/A
lower-sqrt.f6499.3
Applied rewrites99.3%
Final simplification99.1%
(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
lower--.f6468.4
Applied rewrites68.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 y around 0
lower--.f6468.4
Applied rewrites68.4%
Taylor expanded in x around 0
Applied rewrites31.1%
herbie shell --seed 2024219
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))