
(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 10 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 y (sqrt x) (- 1.0 x)))
double code(double x, double y) {
return fma(y, sqrt(x), (1.0 - x));
}
function code(x, y) return fma(y, sqrt(x), Float64(1.0 - x)) end
code[x_, y_] := N[(y * N[Sqrt[x], $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \sqrt{x}, 1 - x\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -2.55e+20) (not (<= y 5e+47))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -2.55e+20) || !(y <= 5e+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 <= (-2.55d+20)) .or. (.not. (y <= 5d+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 <= -2.55e+20) || !(y <= 5e+47)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.55e+20) or not (y <= 5e+47): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.55e+20) || !(y <= 5e+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 <= -2.55e+20) || ~((y <= 5e+47))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.55e+20], N[Not[LessEqual[y, 5e+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 -2.55 \cdot 10^{+20} \lor \neg \left(y \leq 5 \cdot 10^{+47}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -2.55e20 or 5.00000000000000022e47 < y Initial program 99.7%
Taylor expanded in x around 0 93.0%
if -2.55e20 < y < 5.00000000000000022e47Initial program 100.0%
add-sqr-sqrt56.3%
sqrt-unprod98.6%
*-commutative98.6%
*-commutative98.6%
swap-sqr98.6%
add-sqr-sqrt98.6%
pow298.6%
Applied egg-rr98.6%
Taylor expanded in y around 0 98.3%
Final simplification95.9%
(FPCore (x y) :precision binary64 (if (or (<= y -2.9e+81) (not (<= y 1.1e+91))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -2.9e+81) || !(y <= 1.1e+91)) {
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 <= (-2.9d+81)) .or. (.not. (y <= 1.1d+91))) 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 <= -2.9e+81) || !(y <= 1.1e+91)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.9e+81) or not (y <= 1.1e+91): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.9e+81) || !(y <= 1.1e+91)) 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 <= -2.9e+81) || ~((y <= 1.1e+91))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.9e+81], N[Not[LessEqual[y, 1.1e+91]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+81} \lor \neg \left(y \leq 1.1 \cdot 10^{+91}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -2.9e81 or 1.1e91 < y Initial program 99.7%
Taylor expanded in x around inf 76.3%
associate--l+76.3%
distribute-rgt-in76.3%
Simplified99.5%
sqrt-div99.4%
metadata-eval99.4%
un-div-inv99.5%
Applied egg-rr99.5%
clear-num99.4%
clear-num99.4%
pow199.4%
pow1/299.4%
pow-div99.5%
metadata-eval99.5%
pow1/299.5%
associate-*l/99.5%
*-un-lft-identity99.5%
pow1/299.5%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in y around inf 96.8%
if -2.9e81 < y < 1.1e91Initial program 100.0%
add-sqr-sqrt54.6%
sqrt-unprod92.7%
*-commutative92.7%
*-commutative92.7%
swap-sqr92.7%
add-sqr-sqrt92.7%
pow292.7%
Applied egg-rr92.7%
Taylor expanded in y around 0 93.1%
Final simplification94.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= x 0.26) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
double tmp;
if (x <= 0.26) {
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.26d0) 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.26) {
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.26: 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.26) 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.26) 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.26], 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.26:\\
\;\;\;\;1 + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if x < 0.26000000000000001Initial program 99.8%
Taylor expanded in x around 0 99.3%
if 0.26000000000000001 < x Initial program 99.9%
Taylor expanded in x around inf 99.0%
neg-mul-199.0%
Simplified99.0%
Taylor expanded in y around 0 99.0%
Final simplification99.2%
(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 (<= y -1.85e+115) (/ (* y (- x)) y) (if (<= y 2.65e+227) (- 1.0 x) (/ (* y x) y))))
double code(double x, double y) {
double tmp;
if (y <= -1.85e+115) {
tmp = (y * -x) / y;
} else if (y <= 2.65e+227) {
tmp = 1.0 - x;
} else {
tmp = (y * x) / 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.85d+115)) then
tmp = (y * -x) / y
else if (y <= 2.65d+227) then
tmp = 1.0d0 - x
else
tmp = (y * x) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.85e+115) {
tmp = (y * -x) / y;
} else if (y <= 2.65e+227) {
tmp = 1.0 - x;
} else {
tmp = (y * x) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.85e+115: tmp = (y * -x) / y elif y <= 2.65e+227: tmp = 1.0 - x else: tmp = (y * x) / y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.85e+115) tmp = Float64(Float64(y * Float64(-x)) / y); elseif (y <= 2.65e+227) tmp = Float64(1.0 - x); else tmp = Float64(Float64(y * x) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.85e+115) tmp = (y * -x) / y; elseif (y <= 2.65e+227) tmp = 1.0 - x; else tmp = (y * x) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.85e+115], N[(N[(y * (-x)), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 2.65e+227], N[(1.0 - x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{+115}:\\
\;\;\;\;\frac{y \cdot \left(-x\right)}{y}\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{+227}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{y}\\
\end{array}
\end{array}
if y < -1.85000000000000003e115Initial program 99.7%
Taylor expanded in y around inf 99.7%
associate--l+99.7%
div-sub99.7%
Simplified99.7%
Taylor expanded in y around 0 3.7%
associate-*r/25.7%
Applied egg-rr25.7%
Taylor expanded in x around inf 26.8%
associate-*r*26.8%
mul-1-neg26.8%
Simplified26.8%
if -1.85000000000000003e115 < y < 2.65000000000000004e227Initial program 99.9%
add-sqr-sqrt56.3%
sqrt-unprod87.4%
*-commutative87.4%
*-commutative87.4%
swap-sqr83.8%
add-sqr-sqrt83.9%
pow283.9%
Applied egg-rr83.9%
Taylor expanded in y around 0 82.0%
if 2.65000000000000004e227 < y Initial program 99.7%
Taylor expanded in y around inf 99.7%
associate--l+99.7%
div-sub99.7%
Simplified99.7%
Taylor expanded in y around 0 2.5%
Taylor expanded in x around inf 1.2%
neg-mul-199.7%
Simplified1.2%
associate-*r/0.9%
add-sqr-sqrt0.0%
sqrt-unprod31.9%
sqr-neg31.9%
sqrt-unprod32.0%
add-sqr-sqrt32.0%
Applied egg-rr32.0%
Final simplification67.8%
(FPCore (x y) :precision binary64 (if (<= y 2.65e+227) (- 1.0 x) (/ (* y x) y)))
double code(double x, double y) {
double tmp;
if (y <= 2.65e+227) {
tmp = 1.0 - x;
} else {
tmp = (y * x) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.65d+227) then
tmp = 1.0d0 - x
else
tmp = (y * x) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.65e+227) {
tmp = 1.0 - x;
} else {
tmp = (y * x) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.65e+227: tmp = 1.0 - x else: tmp = (y * x) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.65e+227) tmp = Float64(1.0 - x); else tmp = Float64(Float64(y * x) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.65e+227) tmp = 1.0 - x; else tmp = (y * x) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.65e+227], N[(1.0 - x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.65 \cdot 10^{+227}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{y}\\
\end{array}
\end{array}
if y < 2.65000000000000004e227Initial program 99.9%
add-sqr-sqrt45.0%
sqrt-unprod70.0%
*-commutative70.0%
*-commutative70.0%
swap-sqr67.1%
add-sqr-sqrt67.1%
pow267.1%
Applied egg-rr67.1%
Taylor expanded in y around 0 66.4%
if 2.65000000000000004e227 < y Initial program 99.7%
Taylor expanded in y around inf 99.7%
associate--l+99.7%
div-sub99.7%
Simplified99.7%
Taylor expanded in y around 0 2.5%
Taylor expanded in x around inf 1.2%
neg-mul-199.7%
Simplified1.2%
associate-*r/0.9%
add-sqr-sqrt0.0%
sqrt-unprod31.9%
sqr-neg31.9%
sqrt-unprod32.0%
add-sqr-sqrt32.0%
Applied egg-rr32.0%
(FPCore (x y) :precision binary64 (if (<= x 1.0) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 1.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 <= 1.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 <= 1.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.0], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 1Initial program 99.8%
Taylor expanded in x around 0 99.3%
Taylor expanded in y around 0 56.5%
if 1 < x Initial program 99.9%
Taylor expanded in y around inf 76.2%
associate--l+76.2%
div-sub76.2%
Simplified76.2%
Taylor expanded in y around 0 41.6%
Taylor expanded in x around inf 64.8%
neg-mul-164.8%
Simplified64.8%
(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-unprod67.7%
*-commutative67.7%
*-commutative67.7%
swap-sqr64.4%
add-sqr-sqrt64.4%
pow264.4%
Applied egg-rr64.4%
Taylor expanded in y around 0 61.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.9%
Taylor expanded in x around 0 67.3%
Taylor expanded in y around 0 29.2%
herbie shell --seed 2024144
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))