
(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%
(FPCore (x y) :precision binary64 (if (or (<= y -1.25e+67) (not (<= y 1.9e+71))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.25e+67) || !(y <= 1.9e+71)) {
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 <= (-1.25d+67)) .or. (.not. (y <= 1.9d+71))) 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 <= -1.25e+67) || !(y <= 1.9e+71)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.25e+67) or not (y <= 1.9e+71): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.25e+67) || !(y <= 1.9e+71)) 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 <= -1.25e+67) || ~((y <= 1.9e+71))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.25e+67], N[Not[LessEqual[y, 1.9e+71]], $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 -1.25 \cdot 10^{+67} \lor \neg \left(y \leq 1.9 \cdot 10^{+71}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.24999999999999994e67 or 1.9e71 < y Initial program 99.7%
Taylor expanded in x around 0 96.0%
if -1.24999999999999994e67 < y < 1.9e71Initial program 100.0%
add-sqr-sqrt47.2%
sqrt-unprod92.3%
*-commutative92.3%
*-commutative92.3%
swap-sqr92.3%
add-sqr-sqrt92.3%
pow292.3%
Applied egg-rr92.3%
Taylor expanded in y around 0 94.2%
Final simplification94.9%
(FPCore (x y) :precision binary64 (if (or (<= y -6.8e+73) (not (<= y 1.52e+74))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -6.8e+73) || !(y <= 1.52e+74)) {
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 <= (-6.8d+73)) .or. (.not. (y <= 1.52d+74))) 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 <= -6.8e+73) || !(y <= 1.52e+74)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.8e+73) or not (y <= 1.52e+74): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.8e+73) || !(y <= 1.52e+74)) 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 <= -6.8e+73) || ~((y <= 1.52e+74))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.8e+73], N[Not[LessEqual[y, 1.52e+74]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+73} \lor \neg \left(y \leq 1.52 \cdot 10^{+74}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -6.8000000000000003e73 or 1.52000000000000009e74 < y Initial program 99.7%
Taylor expanded in x around 0 96.0%
Taylor expanded in y around inf 96.1%
Taylor expanded in x around inf 92.9%
if -6.8000000000000003e73 < y < 1.52000000000000009e74Initial program 100.0%
add-sqr-sqrt47.2%
sqrt-unprod92.3%
*-commutative92.3%
*-commutative92.3%
swap-sqr92.3%
add-sqr-sqrt92.3%
pow292.3%
Applied egg-rr92.3%
Taylor expanded in y around 0 94.2%
Final simplification93.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= x 0.0042) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
double tmp;
if (x <= 0.0042) {
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 = y * sqrt(x)
if (x <= 0.0042d0) 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 = y * Math.sqrt(x);
double tmp;
if (x <= 0.0042) {
tmp = 1.0 + t_0;
} else {
tmp = t_0 - x;
}
return tmp;
}
def code(x, y): t_0 = y * math.sqrt(x) tmp = 0 if x <= 0.0042: tmp = 1.0 + t_0 else: tmp = t_0 - x return tmp
function code(x, y) t_0 = Float64(y * sqrt(x)) tmp = 0.0 if (x <= 0.0042) tmp = Float64(1.0 + t_0); else tmp = Float64(t_0 - x); end return tmp end
function tmp_2 = code(x, y) t_0 = y * sqrt(x); tmp = 0.0; if (x <= 0.0042) tmp = 1.0 + t_0; else tmp = t_0 - x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 0.0042], N[(1.0 + t$95$0), $MachinePrecision], N[(t$95$0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \sqrt{x}\\
\mathbf{if}\;x \leq 0.0042:\\
\;\;\;\;1 + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if x < 0.00419999999999999974Initial program 99.8%
Taylor expanded in x around 0 98.2%
if 0.00419999999999999974 < x Initial program 99.9%
Taylor expanded in x around inf 99.4%
Taylor expanded in x around 0 99.5%
neg-mul-199.5%
+-commutative99.5%
fma-define99.5%
fma-neg99.5%
Simplified99.5%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (<= x 0.0042) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 0.0042) {
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.0042d0) 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.0042) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.0042: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 0.0042) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.0042) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.0042], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0042:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 0.00419999999999999974Initial program 99.8%
Taylor expanded in x around 0 98.2%
Taylor expanded in y around 0 54.9%
if 0.00419999999999999974 < x Initial program 99.9%
Taylor expanded in x around inf 99.4%
Taylor expanded in y around 0 68.3%
neg-mul-168.3%
Simplified68.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.9%
add-sqr-sqrt49.5%
sqrt-unprod72.0%
*-commutative72.0%
*-commutative72.0%
swap-sqr68.2%
add-sqr-sqrt68.3%
pow268.3%
Applied egg-rr68.3%
Taylor expanded in y around 0 62.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 63.9%
Taylor expanded in y around 0 27.4%
herbie shell --seed 2024141
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))