
(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 11 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%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y 5e+41) (/ (* y (- 1.0 x)) y) (* x (+ (/ y (sqrt x)) -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 5e+41) {
tmp = (y * (1.0 - x)) / y;
} 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 (y <= 5d+41) then
tmp = (y * (1.0d0 - x)) / y
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 (y <= 5e+41) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = x * ((y / Math.sqrt(x)) + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5e+41: tmp = (y * (1.0 - x)) / y else: tmp = x * ((y / math.sqrt(x)) + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 5e+41) tmp = Float64(Float64(y * Float64(1.0 - x)) / y); 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 (y <= 5e+41) tmp = (y * (1.0 - x)) / y; else tmp = x * ((y / sqrt(x)) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5e+41], N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(x * N[(N[(y / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{+41}:\\
\;\;\;\;\frac{y \cdot \left(1 - x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\frac{y}{\sqrt{x}} + -1\right)\\
\end{array}
\end{array}
if y < 5.00000000000000022e41Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 85.3%
Taylor expanded in y around 0 63.8%
associate-*r/82.0%
Applied egg-rr82.0%
if 5.00000000000000022e41 < y Initial program 99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 74.5%
*-commutative74.5%
sqrt-div74.4%
metadata-eval74.4%
un-div-inv74.6%
Applied egg-rr74.6%
Final simplification80.2%
(FPCore (x y) :precision binary64 (if (<= y 2.1e+37) (/ (* y (- 1.0 x)) y) (* y (+ (sqrt x) (/ 1.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= 2.1e+37) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = y * (sqrt(x) + (1.0 / 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.1d+37) then
tmp = (y * (1.0d0 - x)) / y
else
tmp = y * (sqrt(x) + (1.0d0 / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.1e+37) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = y * (Math.sqrt(x) + (1.0 / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.1e+37: tmp = (y * (1.0 - x)) / y else: tmp = y * (math.sqrt(x) + (1.0 / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.1e+37) tmp = Float64(Float64(y * Float64(1.0 - x)) / y); else tmp = Float64(y * Float64(sqrt(x) + Float64(1.0 / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.1e+37) tmp = (y * (1.0 - x)) / y; else tmp = y * (sqrt(x) + (1.0 / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.1e+37], N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(y * N[(N[Sqrt[x], $MachinePrecision] + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{+37}:\\
\;\;\;\;\frac{y \cdot \left(1 - x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\sqrt{x} + \frac{1}{y}\right)\\
\end{array}
\end{array}
if y < 2.1000000000000001e37Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 85.3%
Taylor expanded in y around 0 63.6%
associate-*r/81.9%
Applied egg-rr81.9%
if 2.1000000000000001e37 < y Initial program 99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around inf 99.7%
Taylor expanded in x around 0 94.4%
Final simplification85.1%
(FPCore (x y) :precision binary64 (if (<= y 1.75e+39) (/ (* y (- 1.0 x)) y) (+ 1.0 (* y (sqrt x)))))
double code(double x, double y) {
double tmp;
if (y <= 1.75e+39) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = 1.0 + (y * sqrt(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.75d+39) then
tmp = (y * (1.0d0 - x)) / y
else
tmp = 1.0d0 + (y * sqrt(x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.75e+39) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = 1.0 + (y * Math.sqrt(x));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.75e+39: tmp = (y * (1.0 - x)) / y else: tmp = 1.0 + (y * math.sqrt(x)) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.75e+39) tmp = Float64(Float64(y * Float64(1.0 - x)) / y); else tmp = Float64(1.0 + Float64(y * sqrt(x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.75e+39) tmp = (y * (1.0 - x)) / y; else tmp = 1.0 + (y * sqrt(x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.75e+39], N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(1.0 + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.75 \cdot 10^{+39}:\\
\;\;\;\;\frac{y \cdot \left(1 - x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\end{array}
\end{array}
if y < 1.7500000000000001e39Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 85.3%
Taylor expanded in y around 0 63.6%
associate-*r/81.9%
Applied egg-rr81.9%
if 1.7500000000000001e39 < y Initial program 99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around 0 94.5%
Final simplification85.1%
(FPCore (x y) :precision binary64 (if (<= y 5e+41) (/ (* y (- 1.0 x)) y) (- (* y (sqrt x)) x)))
double code(double x, double y) {
double tmp;
if (y <= 5e+41) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = (y * sqrt(x)) - 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+41) then
tmp = (y * (1.0d0 - x)) / y
else
tmp = (y * sqrt(x)) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 5e+41) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = (y * Math.sqrt(x)) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5e+41: tmp = (y * (1.0 - x)) / y else: tmp = (y * math.sqrt(x)) - x return tmp
function code(x, y) tmp = 0.0 if (y <= 5e+41) tmp = Float64(Float64(y * Float64(1.0 - x)) / y); else tmp = Float64(Float64(y * sqrt(x)) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5e+41) tmp = (y * (1.0 - x)) / y; else tmp = (y * sqrt(x)) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5e+41], N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{+41}:\\
\;\;\;\;\frac{y \cdot \left(1 - x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \sqrt{x} - x\\
\end{array}
\end{array}
if y < 5.00000000000000022e41Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 85.3%
Taylor expanded in y around 0 63.8%
associate-*r/82.0%
Applied egg-rr82.0%
if 5.00000000000000022e41 < y Initial program 99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 74.5%
*-commutative74.5%
sqrt-div74.4%
metadata-eval74.4%
un-div-inv74.6%
Applied egg-rr74.6%
Taylor expanded in x around 0 90.8%
neg-mul-190.8%
+-commutative90.8%
unsub-neg90.8%
*-commutative90.8%
Simplified90.8%
Final simplification84.2%
(FPCore (x y) :precision binary64 (if (<= y 5.8e+69) (/ (* y (- 1.0 x)) y) (* y (sqrt x))))
double code(double x, double y) {
double tmp;
if (y <= 5.8e+69) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = y * sqrt(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.8d+69) then
tmp = (y * (1.0d0 - x)) / y
else
tmp = y * sqrt(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 5.8e+69) {
tmp = (y * (1.0 - x)) / y;
} else {
tmp = y * Math.sqrt(x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.8e+69: tmp = (y * (1.0 - x)) / y else: tmp = y * math.sqrt(x) return tmp
function code(x, y) tmp = 0.0 if (y <= 5.8e+69) tmp = Float64(Float64(y * Float64(1.0 - x)) / y); else tmp = Float64(y * sqrt(x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5.8e+69) tmp = (y * (1.0 - x)) / y; else tmp = y * sqrt(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.8e+69], N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.8 \cdot 10^{+69}:\\
\;\;\;\;\frac{y \cdot \left(1 - x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \sqrt{x}\\
\end{array}
\end{array}
if y < 5.7999999999999997e69Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 85.9%
Taylor expanded in y around 0 63.7%
associate-*r/80.8%
Applied egg-rr80.8%
if 5.7999999999999997e69 < y Initial program 99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around inf 99.6%
Taylor expanded in y around inf 92.8%
Final simplification83.4%
(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%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= x 0.062) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 0.062) {
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.062d0) 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.062) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.062: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 0.062) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.062) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.062], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.062:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 0.062Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around inf 99.7%
Taylor expanded in x around 0 98.1%
Taylor expanded in y around 0 61.0%
if 0.062 < x Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 97.3%
Taylor expanded in y around 0 61.1%
neg-mul-161.1%
Simplified61.1%
Final simplification61.0%
(FPCore (x y) :precision binary64 (/ (* y (- 1.0 x)) y))
double code(double x, double y) {
return (y * (1.0 - x)) / y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (1.0d0 - x)) / y
end function
public static double code(double x, double y) {
return (y * (1.0 - x)) / y;
}
def code(x, y): return (y * (1.0 - x)) / y
function code(x, y) return Float64(Float64(y * Float64(1.0 - x)) / y) end
function tmp = code(x, y) tmp = (y * (1.0 - x)) / y; end
code[x_, y_] := N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{y \cdot \left(1 - x\right)}{y}
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around inf 88.9%
Taylor expanded in y around 0 52.1%
associate-*r/65.3%
Applied egg-rr65.3%
Final simplification65.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%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 63.1%
Final simplification63.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%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around inf 88.9%
Taylor expanded in x around 0 67.6%
Taylor expanded in y around 0 31.5%
Final simplification31.5%
herbie shell --seed 2024066
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))