
(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 (+ (- 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 -3.5e+63) (not (<= y 6e+41))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -3.5e+63) || !(y <= 6e+41)) {
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 <= (-3.5d+63)) .or. (.not. (y <= 6d+41))) 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 <= -3.5e+63) || !(y <= 6e+41)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.5e+63) or not (y <= 6e+41): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.5e+63) || !(y <= 6e+41)) 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 <= -3.5e+63) || ~((y <= 6e+41))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.5e+63], N[Not[LessEqual[y, 6e+41]], $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 -3.5 \cdot 10^{+63} \lor \neg \left(y \leq 6 \cdot 10^{+41}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -3.50000000000000029e63 or 5.9999999999999997e41 < y Initial program 99.6%
Taylor expanded in x around 0 91.5%
if -3.50000000000000029e63 < y < 5.9999999999999997e41Initial program 100.0%
add-sqr-sqrt100.0%
pow2100.0%
pow1/2100.0%
sqrt-pow1100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 97.3%
Final simplification95.3%
(FPCore (x y) :precision binary64 (if (or (<= y -5.2e+84) (not (<= y 6e+58))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -5.2e+84) || !(y <= 6e+58)) {
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 <= (-5.2d+84)) .or. (.not. (y <= 6d+58))) 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 <= -5.2e+84) || !(y <= 6e+58)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5.2e+84) or not (y <= 6e+58): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5.2e+84) || !(y <= 6e+58)) 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 <= -5.2e+84) || ~((y <= 6e+58))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5.2e+84], N[Not[LessEqual[y, 6e+58]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+84} \lor \neg \left(y \leq 6 \cdot 10^{+58}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -5.2000000000000002e84 or 6.0000000000000005e58 < y Initial program 99.6%
Taylor expanded in x around inf 83.2%
Taylor expanded in y around inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Taylor expanded in x around 0 88.3%
if -5.2000000000000002e84 < y < 6.0000000000000005e58Initial program 100.0%
add-sqr-sqrt99.9%
pow299.9%
pow1/299.9%
sqrt-pow1100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 96.3%
Final simplification93.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= x 1.0) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
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 = y * sqrt(x)
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 = y * Math.sqrt(x);
double tmp;
if (x <= 1.0) {
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 <= 1.0: 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 <= 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 = y * sqrt(x); 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[(y * N[Sqrt[x], $MachinePrecision]), $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 := y \cdot \sqrt{x}\\
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if x < 1Initial program 99.8%
Taylor expanded in x around 0 97.4%
if 1 < x Initial program 99.9%
Taylor expanded in x around inf 99.4%
neg-mul-199.4%
Simplified99.4%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= y -9.5e+147) (/ (* x y) (- y)) (if (<= y 4.4e+158) (- 1.0 x) (/ (* x y) y))))
double code(double x, double y) {
double tmp;
if (y <= -9.5e+147) {
tmp = (x * y) / -y;
} else if (y <= 4.4e+158) {
tmp = 1.0 - x;
} else {
tmp = (x * y) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-9.5d+147)) then
tmp = (x * y) / -y
else if (y <= 4.4d+158) then
tmp = 1.0d0 - x
else
tmp = (x * y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -9.5e+147) {
tmp = (x * y) / -y;
} else if (y <= 4.4e+158) {
tmp = 1.0 - x;
} else {
tmp = (x * y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9.5e+147: tmp = (x * y) / -y elif y <= 4.4e+158: tmp = 1.0 - x else: tmp = (x * y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= -9.5e+147) tmp = Float64(Float64(x * y) / Float64(-y)); elseif (y <= 4.4e+158) tmp = Float64(1.0 - x); else tmp = Float64(Float64(x * y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9.5e+147) tmp = (x * y) / -y; elseif (y <= 4.4e+158) tmp = 1.0 - x; else tmp = (x * y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9.5e+147], N[(N[(x * y), $MachinePrecision] / (-y)), $MachinePrecision], If[LessEqual[y, 4.4e+158], N[(1.0 - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+147}:\\
\;\;\;\;\frac{x \cdot y}{-y}\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{+158}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{y}\\
\end{array}
\end{array}
if y < -9.4999999999999996e147Initial program 99.6%
Taylor expanded in x around inf 83.8%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
Taylor expanded in y around 0 4.3%
mul-1-neg4.3%
distribute-frac-neg24.3%
Simplified4.3%
associate-*r/20.9%
frac-2neg20.9%
remove-double-neg20.9%
Applied egg-rr20.9%
if -9.4999999999999996e147 < y < 4.4000000000000002e158Initial program 99.9%
add-sqr-sqrt99.8%
pow299.8%
pow1/299.8%
sqrt-pow199.8%
metadata-eval99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 86.0%
if 4.4000000000000002e158 < y Initial program 99.7%
Taylor expanded in x around inf 76.1%
Taylor expanded in y around inf 99.7%
mul-1-neg99.7%
unsub-neg99.7%
Simplified99.7%
Taylor expanded in y around 0 0.9%
mul-1-neg0.9%
distribute-frac-neg20.9%
Simplified0.9%
associate-*r/0.6%
add-sqr-sqrt0.0%
sqrt-unprod0.9%
sqr-neg0.9%
sqrt-unprod48.8%
add-sqr-sqrt48.8%
Applied egg-rr48.8%
Final simplification75.8%
(FPCore (x y) :precision binary64 (if (<= y 1.25e+163) (- 1.0 x) (/ (* x y) y)))
double code(double x, double y) {
double tmp;
if (y <= 1.25e+163) {
tmp = 1.0 - x;
} else {
tmp = (x * y) / 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.25d+163) then
tmp = 1.0d0 - x
else
tmp = (x * y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.25e+163) {
tmp = 1.0 - x;
} else {
tmp = (x * y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.25e+163: tmp = 1.0 - x else: tmp = (x * y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.25e+163) tmp = Float64(1.0 - x); else tmp = Float64(Float64(x * y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.25e+163) tmp = 1.0 - x; else tmp = (x * y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.25e+163], N[(1.0 - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.25 \cdot 10^{+163}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{y}\\
\end{array}
\end{array}
if y < 1.25e163Initial program 99.9%
add-sqr-sqrt99.8%
pow299.8%
pow1/299.8%
sqrt-pow199.8%
metadata-eval99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 77.3%
if 1.25e163 < y Initial program 99.7%
Taylor expanded in x around inf 76.1%
Taylor expanded in y around inf 99.7%
mul-1-neg99.7%
unsub-neg99.7%
Simplified99.7%
Taylor expanded in y around 0 0.9%
mul-1-neg0.9%
distribute-frac-neg20.9%
Simplified0.9%
associate-*r/0.6%
add-sqr-sqrt0.0%
sqrt-unprod0.9%
sqr-neg0.9%
sqrt-unprod48.8%
add-sqr-sqrt48.8%
Applied egg-rr48.8%
Final simplification74.1%
(FPCore (x y) :precision binary64 (if (<= x 300000.0) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 300000.0) {
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 <= 300000.0d0) 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 <= 300000.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 300000.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 300000.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 300000.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 300000.0], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 300000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 3e5Initial program 99.8%
Taylor expanded in x around 0 96.9%
Taylor expanded in y around 0 64.4%
if 3e5 < x Initial program 99.9%
Taylor expanded in x around inf 99.8%
Taylor expanded in y around 0 71.5%
neg-mul-171.5%
Simplified71.5%
(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-sqrt99.7%
pow299.7%
pow1/299.7%
sqrt-pow199.8%
metadata-eval99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 69.0%
(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 62.2%
Taylor expanded in y around 0 32.2%
herbie shell --seed 2024146
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))