
(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 8 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 (- (* y (sqrt x)) x)))
double code(double x, double y) {
return 1.0 + ((y * sqrt(x)) - x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((y * sqrt(x)) - x)
end function
public static double code(double x, double y) {
return 1.0 + ((y * Math.sqrt(x)) - x);
}
def code(x, y): return 1.0 + ((y * math.sqrt(x)) - x)
function code(x, y) return Float64(1.0 + Float64(Float64(y * sqrt(x)) - x)) end
function tmp = code(x, y) tmp = 1.0 + ((y * sqrt(x)) - x); end
code[x_, y_] := N[(1.0 + N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(y \cdot \sqrt{x} - x\right)
\end{array}
Initial program 99.8%
associate-+l-99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -2.05e+42) (not (<= y 9.5e+59))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -2.05e+42) || !(y <= 9.5e+59)) {
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.05d+42)) .or. (.not. (y <= 9.5d+59))) 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.05e+42) || !(y <= 9.5e+59)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.05e+42) or not (y <= 9.5e+59): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.05e+42) || !(y <= 9.5e+59)) 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.05e+42) || ~((y <= 9.5e+59))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.05e+42], N[Not[LessEqual[y, 9.5e+59]], $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.05 \cdot 10^{+42} \lor \neg \left(y \leq 9.5 \cdot 10^{+59}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -2.05e42 or 9.50000000000000023e59 < y Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
add-sqr-sqrt99.2%
associate-*l*99.3%
fma-def99.3%
pow1/299.3%
sqrt-pow199.4%
metadata-eval99.4%
pow1/299.4%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 97.0%
if -2.05e42 < y < 9.50000000000000023e59Initial program 100.0%
Taylor expanded in y around 0 97.1%
Final simplification97.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.35e+110) (not (<= y 3.2e+67))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.35e+110) || !(y <= 3.2e+67)) {
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 <= (-1.35d+110)) .or. (.not. (y <= 3.2d+67))) 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 <= -1.35e+110) || !(y <= 3.2e+67)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.35e+110) or not (y <= 3.2e+67): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.35e+110) || !(y <= 3.2e+67)) 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 <= -1.35e+110) || ~((y <= 3.2e+67))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.35e+110], N[Not[LessEqual[y, 3.2e+67]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{+110} \lor \neg \left(y \leq 3.2 \cdot 10^{+67}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.35000000000000005e110 or 3.19999999999999983e67 < y Initial program 99.6%
Taylor expanded in y around inf 95.6%
if -1.35000000000000005e110 < y < 3.19999999999999983e67Initial program 99.9%
Taylor expanded in y around 0 94.0%
Final simplification94.5%
(FPCore (x y) :precision binary64 (+ (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
return (y * sqrt(x)) + (1.0 - x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * sqrt(x)) + (1.0d0 - x)
end function
public static double code(double x, double y) {
return (y * Math.sqrt(x)) + (1.0 - x);
}
def code(x, y): return (y * math.sqrt(x)) + (1.0 - x)
function code(x, y) return Float64(Float64(y * sqrt(x)) + Float64(1.0 - x)) end
function tmp = code(x, y) tmp = (y * sqrt(x)) + (1.0 - x); end
code[x_, y_] := N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \sqrt{x} + \left(1 - x\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (<= y 1.85e+109) (- 1.0 x) (* y (/ x (/ (+ 1.0 x) y)))))
double code(double x, double y) {
double tmp;
if (y <= 1.85e+109) {
tmp = 1.0 - x;
} else {
tmp = y * (x / ((1.0 + 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+109) then
tmp = 1.0d0 - x
else
tmp = y * (x / ((1.0d0 + x) / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.85e+109) {
tmp = 1.0 - x;
} else {
tmp = y * (x / ((1.0 + x) / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.85e+109: tmp = 1.0 - x else: tmp = y * (x / ((1.0 + x) / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.85e+109) tmp = Float64(1.0 - x); else tmp = Float64(y * Float64(x / Float64(Float64(1.0 + x) / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.85e+109) tmp = 1.0 - x; else tmp = y * (x / ((1.0 + x) / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.85e+109], N[(1.0 - x), $MachinePrecision], N[(y * N[(x / N[(N[(1.0 + x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{+109}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{\frac{1 + x}{y}}\\
\end{array}
\end{array}
if y < 1.8500000000000001e109Initial program 99.9%
Taylor expanded in y around 0 80.7%
if 1.8500000000000001e109 < y Initial program 99.7%
flip-+36.5%
div-sub36.5%
pow236.5%
associate--l-36.5%
*-commutative36.5%
*-commutative36.5%
swap-sqr17.8%
add-sqr-sqrt17.7%
associate--l-17.7%
Applied egg-rr17.7%
div-sub17.7%
associate--r+17.7%
Simplified17.7%
Taylor expanded in y around inf 18.4%
unpow218.4%
associate-*r*18.4%
neg-mul-118.4%
Simplified18.4%
Taylor expanded in y around 0 28.5%
associate-*r/28.5%
mul-1-neg28.5%
unpow228.5%
*-commutative28.5%
distribute-lft-neg-in28.5%
associate-/l*28.7%
Simplified28.7%
associate-/r*28.7%
associate-/r/28.7%
add-sqr-sqrt0.0%
sqrt-unprod1.7%
sqr-neg1.7%
sqrt-unprod2.4%
add-sqr-sqrt2.4%
sub-neg2.4%
add-sqr-sqrt0.0%
sqrt-unprod13.0%
sqr-neg13.0%
sqrt-unprod30.8%
add-sqr-sqrt30.8%
Applied egg-rr30.8%
Final simplification71.7%
(FPCore (x y) :precision binary64 (if (<= y 1.85e+109) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 1.85e+109) {
tmp = 1.0 - x;
} else {
tmp = 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.85d+109) then
tmp = 1.0d0 - x
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.85e+109) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.85e+109: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.85e+109) tmp = Float64(1.0 - x); else tmp = Float64(y * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.85e+109) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.85e+109], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{+109}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 1.8500000000000001e109Initial program 99.9%
Taylor expanded in y around 0 80.7%
if 1.8500000000000001e109 < y Initial program 99.7%
flip-+36.5%
div-sub36.5%
pow236.5%
associate--l-36.5%
*-commutative36.5%
*-commutative36.5%
swap-sqr17.8%
add-sqr-sqrt17.7%
associate--l-17.7%
Applied egg-rr17.7%
div-sub17.7%
associate--r+17.7%
Simplified17.7%
Taylor expanded in y around inf 18.4%
unpow218.4%
associate-*r*18.4%
neg-mul-118.4%
Simplified18.4%
Taylor expanded in x around inf 30.4%
unpow230.4%
Simplified30.4%
Final simplification71.6%
(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 68.0%
if 1 < x Initial program 99.9%
Taylor expanded in x around inf 59.2%
mul-1-neg59.2%
Simplified59.2%
Final simplification63.9%
(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.8%
Taylor expanded in x around 0 37.2%
Final simplification37.2%
herbie shell --seed 2023221
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))