
(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 (sqrt x) y (- 1.0 x)))
double code(double x, double y) {
return fma(sqrt(x), y, (1.0 - x));
}
function code(x, y) return fma(sqrt(x), y, Float64(1.0 - x)) end
code[x_, y_] := N[(N[Sqrt[x], $MachinePrecision] * y + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt{x}, y, 1 - x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (- 1.0 x) (* y (sqrt x)))))
(if (<= t_0 -2e+16)
(fma (sqrt x) y (- x))
(if (<= t_0 0.9999999999999808) (- 1.0 x) (fma (sqrt x) y 1.0)))))
double code(double x, double y) {
double t_0 = (1.0 - x) + (y * sqrt(x));
double tmp;
if (t_0 <= -2e+16) {
tmp = fma(sqrt(x), y, -x);
} else if (t_0 <= 0.9999999999999808) {
tmp = 1.0 - x;
} else {
tmp = fma(sqrt(x), y, 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) tmp = 0.0 if (t_0 <= -2e+16) tmp = fma(sqrt(x), y, Float64(-x)); elseif (t_0 <= 0.9999999999999808) tmp = Float64(1.0 - x); else tmp = fma(sqrt(x), y, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+16], N[(N[Sqrt[x], $MachinePrecision] * y + (-x)), $MachinePrecision], If[LessEqual[t$95$0, 0.9999999999999808], N[(1.0 - x), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) + y \cdot \sqrt{x}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+16}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, -x\right)\\
\mathbf{elif}\;t\_0 \leq 0.9999999999999808:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -2e16Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6499.8
Applied rewrites99.8%
if -2e16 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < 0.999999999999980793Initial program 100.0%
Taylor expanded in y around 0
lower--.f6495.5
Applied rewrites95.5%
if 0.999999999999980793 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6499.9
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (if (<= (+ (- 1.0 x) (* y (sqrt x))) -50.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (((1.0 - x) + (y * sqrt(x))) <= -50.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 (((1.0d0 - x) + (y * sqrt(x))) <= (-50.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 (((1.0 - x) + (y * Math.sqrt(x))) <= -50.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) + (y * math.sqrt(x))) <= -50.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) <= -50.0) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - x) + (y * sqrt(x))) <= -50.0) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -50.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) + y \cdot \sqrt{x} \leq -50:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -50Initial program 99.8%
Taylor expanded in y around 0
lower--.f6454.3
Applied rewrites54.3%
Taylor expanded in x around inf
Applied rewrites52.7%
if -50 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.9%
Taylor expanded in y around 0
lower--.f6460.6
Applied rewrites60.6%
Taylor expanded in x around 0
Applied rewrites59.0%
(FPCore (x y) :precision binary64 (if (or (<= y -2.4e+37) (not (<= y 1.2e+14))) (fma (sqrt x) y 1.0) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -2.4e+37) || !(y <= 1.2e+14)) {
tmp = fma(sqrt(x), y, 1.0);
} else {
tmp = 1.0 - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -2.4e+37) || !(y <= 1.2e+14)) tmp = fma(sqrt(x), y, 1.0); else tmp = Float64(1.0 - x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -2.4e+37], N[Not[LessEqual[y, 1.2e+14]], $MachinePrecision]], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+37} \lor \neg \left(y \leq 1.2 \cdot 10^{+14}\right):\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -2.4e37 or 1.2e14 < y Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6493.9
Applied rewrites93.9%
if -2.4e37 < y < 1.2e14Initial program 100.0%
Taylor expanded in y around 0
lower--.f6499.4
Applied rewrites99.4%
Final simplification96.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.6e+64) (not (<= y 1.4e+41))) (* (sqrt x) y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.6e+64) || !(y <= 1.4e+41)) {
tmp = sqrt(x) * y;
} 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.6d+64)) .or. (.not. (y <= 1.4d+41))) then
tmp = sqrt(x) * y
else
tmp = 1.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.6e+64) || !(y <= 1.4e+41)) {
tmp = Math.sqrt(x) * y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.6e+64) or not (y <= 1.4e+41): tmp = math.sqrt(x) * y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.6e+64) || !(y <= 1.4e+41)) tmp = Float64(sqrt(x) * y); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.6e+64) || ~((y <= 1.4e+41))) tmp = sqrt(x) * y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.6e+64], N[Not[LessEqual[y, 1.4e+41]], $MachinePrecision]], N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+64} \lor \neg \left(y \leq 1.4 \cdot 10^{+41}\right):\\
\;\;\;\;\sqrt{x} \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.60000000000000009e64 or 1.4e41 < y Initial program 99.7%
Taylor expanded in x around inf
remove-double-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
rem-square-sqrtN/A
unpow2N/A
*-commutativeN/A
distribute-lft-out--N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
fp-cancel-sub-signN/A
mul-1-negN/A
Applied rewrites79.1%
Taylor expanded in x around 0
Applied rewrites91.1%
if -1.60000000000000009e64 < y < 1.4e41Initial program 100.0%
Taylor expanded in y around 0
lower--.f6499.0
Applied rewrites99.0%
Final simplification95.3%
(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.8%
Taylor expanded in y around 0
lower--.f6457.1
Applied rewrites57.1%
(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.8%
Taylor expanded in y around 0
lower--.f6457.1
Applied rewrites57.1%
Taylor expanded in x around 0
Applied rewrites26.9%
herbie shell --seed 2024339
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))