
(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 9 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 (+ (* (sqrt x) y) (- 1.0 x)))
double code(double x, double y) {
return (sqrt(x) * y) + (1.0 - x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sqrt(x) * y) + (1.0d0 - x)
end function
public static double code(double x, double y) {
return (Math.sqrt(x) * y) + (1.0 - x);
}
def code(x, y): return (math.sqrt(x) * y) + (1.0 - x)
function code(x, y) return Float64(Float64(sqrt(x) * y) + Float64(1.0 - x)) end
function tmp = code(x, y) tmp = (sqrt(x) * y) + (1.0 - x); end
code[x_, y_] := N[(N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x} \cdot y + \left(1 - x\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y -850000000000.0) (fma y (sqrt x) 1.0) (if (<= y 4.9e+55) (- 1.0 x) (+ 1.0 (* (sqrt x) y)))))
double code(double x, double y) {
double tmp;
if (y <= -850000000000.0) {
tmp = fma(y, sqrt(x), 1.0);
} else if (y <= 4.9e+55) {
tmp = 1.0 - x;
} else {
tmp = 1.0 + (sqrt(x) * y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -850000000000.0) tmp = fma(y, sqrt(x), 1.0); elseif (y <= 4.9e+55) tmp = Float64(1.0 - x); else tmp = Float64(1.0 + Float64(sqrt(x) * y)); end return tmp end
code[x_, y_] := If[LessEqual[y, -850000000000.0], N[(y * N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[y, 4.9e+55], N[(1.0 - x), $MachinePrecision], N[(1.0 + N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -850000000000:\\
\;\;\;\;\mathsf{fma}\left(y, \sqrt{x}, 1\right)\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{+55}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;1 + \sqrt{x} \cdot y\\
\end{array}
\end{array}
if y < -8.5e11Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6487.3
Applied rewrites87.3%
if -8.5e11 < y < 4.90000000000000015e55Initial program 100.0%
Taylor expanded in y around 0
lower--.f6499.5
Applied rewrites99.5%
if 4.90000000000000015e55 < y Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites93.4%
Final simplification95.3%
(FPCore (x y) :precision binary64 (if (<= (+ (* (sqrt x) y) (- 1.0 x)) -5000.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (((sqrt(x) * y) + (1.0 - x)) <= -5000.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 (((sqrt(x) * y) + (1.0d0 - x)) <= (-5000.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 (((Math.sqrt(x) * y) + (1.0 - x)) <= -5000.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((math.sqrt(x) * y) + (1.0 - x)) <= -5000.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(sqrt(x) * y) + Float64(1.0 - x)) <= -5000.0) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((sqrt(x) * y) + (1.0 - x)) <= -5000.0) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision], -5000.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{x} \cdot y + \left(1 - x\right) \leq -5000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -5e3Initial program 99.8%
Taylor expanded in y around 0
lower--.f6462.7
Applied rewrites62.7%
Taylor expanded in x around inf
Applied rewrites63.1%
if -5e3 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.9%
Taylor expanded in y around 0
lower--.f6464.4
Applied rewrites64.4%
Taylor expanded in x around 0
Applied rewrites62.2%
Final simplification62.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma y (sqrt x) 1.0))) (if (<= y -850000000000.0) t_0 (if (<= y 4.9e+55) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = fma(y, sqrt(x), 1.0);
double tmp;
if (y <= -850000000000.0) {
tmp = t_0;
} else if (y <= 4.9e+55) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(y, sqrt(x), 1.0) tmp = 0.0 if (y <= -850000000000.0) tmp = t_0; elseif (y <= 4.9e+55) tmp = Float64(1.0 - x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[y, -850000000000.0], t$95$0, If[LessEqual[y, 4.9e+55], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, \sqrt{x}, 1\right)\\
\mathbf{if}\;y \leq -850000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{+55}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.5e11 or 4.90000000000000015e55 < y Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6490.0
Applied rewrites90.0%
if -8.5e11 < y < 4.90000000000000015e55Initial program 100.0%
Taylor expanded in y around 0
lower--.f6499.5
Applied rewrites99.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (sqrt x) y))) (if (<= y -9e+92) t_0 (if (<= y 1.65e+57) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = sqrt(x) * y;
double tmp;
if (y <= -9e+92) {
tmp = t_0;
} else if (y <= 1.65e+57) {
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 = sqrt(x) * y
if (y <= (-9d+92)) then
tmp = t_0
else if (y <= 1.65d+57) 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 = Math.sqrt(x) * y;
double tmp;
if (y <= -9e+92) {
tmp = t_0;
} else if (y <= 1.65e+57) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sqrt(x) * y tmp = 0 if y <= -9e+92: tmp = t_0 elif y <= 1.65e+57: tmp = 1.0 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(sqrt(x) * y) tmp = 0.0 if (y <= -9e+92) tmp = t_0; elseif (y <= 1.65e+57) tmp = Float64(1.0 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = sqrt(x) * y; tmp = 0.0; if (y <= -9e+92) tmp = t_0; elseif (y <= 1.65e+57) tmp = 1.0 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -9e+92], t$95$0, If[LessEqual[y, 1.65e+57], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x} \cdot y\\
\mathbf{if}\;y \leq -9 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{+57}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.9999999999999998e92 or 1.6500000000000001e57 < y Initial program 99.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f6490.3
Applied rewrites90.3%
if -8.9999999999999998e92 < y < 1.6500000000000001e57Initial program 100.0%
Taylor expanded in y around 0
lower--.f6496.9
Applied rewrites96.9%
Final simplification94.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (sqrt x) y))) (if (<= x 1.0) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = sqrt(x) * y;
double tmp;
if (x <= 1.0) {
tmp = 1.0 + t_0;
} else {
tmp = t_0 - x;
}
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 = sqrt(x) * y
if (x <= 1.0d0) then
tmp = 1.0d0 + t_0
else
tmp = t_0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.sqrt(x) * y;
double tmp;
if (x <= 1.0) {
tmp = 1.0 + t_0;
} else {
tmp = t_0 - x;
}
return tmp;
}
def code(x, y): t_0 = math.sqrt(x) * y tmp = 0 if x <= 1.0: tmp = 1.0 + t_0 else: tmp = t_0 - x return tmp
function code(x, y) t_0 = Float64(sqrt(x) * y) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 + t_0); else tmp = Float64(t_0 - x); end return tmp end
function tmp_2 = code(x, y) t_0 = sqrt(x) * y; tmp = 0.0; if (x <= 1.0) tmp = 1.0 + t_0; else tmp = t_0 - x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[x, 1.0], N[(1.0 + t$95$0), $MachinePrecision], N[(t$95$0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x} \cdot y\\
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if x < 1Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites96.8%
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
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f6499.8
Applied rewrites99.8%
Final simplification98.3%
(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 Float64(fma(sqrt(x), y, 1.0) - x) end
code[x_, y_] := N[(N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt{x}, y, 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
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
(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--.f6463.6
Applied rewrites63.6%
(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--.f6463.6
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites31.1%
herbie shell --seed 2024244
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))