
(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.8%
(FPCore (x y) :precision binary64 (if (or (<= y -9e+15) (not (<= y 3.6e+47))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -9e+15) || !(y <= 3.6e+47)) {
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 <= (-9d+15)) .or. (.not. (y <= 3.6d+47))) 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 <= -9e+15) || !(y <= 3.6e+47)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9e+15) or not (y <= 3.6e+47): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -9e+15) || !(y <= 3.6e+47)) 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 <= -9e+15) || ~((y <= 3.6e+47))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9e+15], N[Not[LessEqual[y, 3.6e+47]], $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 -9 \cdot 10^{+15} \lor \neg \left(y \leq 3.6 \cdot 10^{+47}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -9e15 or 3.60000000000000008e47 < y Initial program 99.6%
*-commutative99.6%
add-sqr-sqrt56.0%
sqrt-unprod42.7%
sqrt-prod35.4%
pow235.4%
Applied egg-rr35.4%
Taylor expanded in x around 0 96.0%
if -9e15 < y < 3.60000000000000008e47Initial program 100.0%
*-commutative100.0%
add-sqr-sqrt54.0%
sqrt-unprod100.0%
sqrt-prod100.0%
pow2100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 98.6%
Final simplification97.4%
(FPCore (x y) :precision binary64 (if (or (<= y -5e+36) (not (<= y 2.8e+89))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -5e+36) || !(y <= 2.8e+89)) {
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 <= (-5d+36)) .or. (.not. (y <= 2.8d+89))) 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 <= -5e+36) || !(y <= 2.8e+89)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+36) or not (y <= 2.8e+89): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+36) || !(y <= 2.8e+89)) 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 <= -5e+36) || ~((y <= 2.8e+89))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+36], N[Not[LessEqual[y, 2.8e+89]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+36} \lor \neg \left(y \leq 2.8 \cdot 10^{+89}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -4.99999999999999977e36 or 2.7999999999999998e89 < y Initial program 99.5%
*-commutative99.5%
add-sqr-sqrt53.9%
sqrt-unprod29.7%
sqrt-prod21.7%
pow221.7%
Applied egg-rr21.7%
unpow221.7%
Applied egg-rr21.7%
flip-+9.8%
unpow29.8%
add-sqr-sqrt9.8%
pow29.8%
clear-num9.8%
sqrt-prod10.0%
sqrt-prod9.3%
add-sqr-sqrt22.3%
associate--r+22.3%
clear-num22.3%
Applied egg-rr99.5%
Taylor expanded in y around inf 93.1%
if -4.99999999999999977e36 < y < 2.7999999999999998e89Initial program 100.0%
*-commutative100.0%
add-sqr-sqrt55.5%
sqrt-unprod99.4%
sqrt-prod98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in y around 0 94.2%
Final simplification93.8%
(FPCore (x y) :precision binary64 (if (<= x 27.5) (+ 1.0 (* y (sqrt x))) (* x (+ (/ y (sqrt x)) -1.0))))
double code(double x, double y) {
double tmp;
if (x <= 27.5) {
tmp = 1.0 + (y * sqrt(x));
} else {
tmp = x * ((y / sqrt(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 (x <= 27.5d0) then
tmp = 1.0d0 + (y * sqrt(x))
else
tmp = x * ((y / sqrt(x)) + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 27.5) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = x * ((y / Math.sqrt(x)) + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 27.5: tmp = 1.0 + (y * math.sqrt(x)) else: tmp = x * ((y / math.sqrt(x)) + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= 27.5) tmp = Float64(1.0 + Float64(y * sqrt(x))); else tmp = Float64(x * Float64(Float64(y / sqrt(x)) + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 27.5) tmp = 1.0 + (y * sqrt(x)); else tmp = x * ((y / sqrt(x)) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 27.5], N[(1.0 + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 27.5:\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\frac{y}{\sqrt{x}} + -1\right)\\
\end{array}
\end{array}
if x < 27.5Initial program 99.8%
*-commutative99.8%
add-sqr-sqrt52.7%
sqrt-unprod72.8%
sqrt-prod72.8%
pow272.8%
Applied egg-rr72.8%
Taylor expanded in x around 0 99.4%
if 27.5 < x Initial program 99.8%
*-commutative99.8%
add-sqr-sqrt57.4%
sqrt-unprod74.9%
sqrt-prod67.8%
pow267.8%
Applied egg-rr67.8%
Taylor expanded in x around inf 98.5%
*-commutative98.5%
sqrt-div98.5%
metadata-eval98.5%
un-div-inv98.6%
Applied egg-rr98.6%
Final simplification99.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= x 340.0) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
double tmp;
if (x <= 340.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 <= 340.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 <= 340.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 <= 340.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 <= 340.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 <= 340.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, 340.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 340:\\
\;\;\;\;1 + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if x < 340Initial program 99.8%
*-commutative99.8%
add-sqr-sqrt52.3%
sqrt-unprod72.3%
sqrt-prod72.3%
pow272.3%
Applied egg-rr72.3%
Taylor expanded in x around 0 99.4%
if 340 < x Initial program 99.8%
*-commutative99.8%
add-sqr-sqrt57.8%
sqrt-unprod75.5%
sqrt-prod68.4%
pow268.4%
Applied egg-rr68.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around 0 98.5%
neg-mul-198.5%
+-commutative98.5%
fma-define98.5%
fma-neg98.5%
Simplified98.5%
Final simplification99.0%
(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%
*-commutative99.8%
add-sqr-sqrt54.9%
sqrt-unprod73.8%
sqrt-prod70.5%
pow270.5%
Applied egg-rr70.5%
Taylor expanded in y around 0 62.4%
(FPCore (x y) :precision binary64 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 99.8%
*-commutative99.8%
add-sqr-sqrt54.9%
sqrt-unprod73.8%
sqrt-prod70.5%
pow270.5%
Applied egg-rr70.5%
Taylor expanded in x around inf 59.0%
Taylor expanded in y around 0 28.0%
neg-mul-128.0%
Simplified28.0%
herbie shell --seed 2024103
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))