
(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 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 (or (<= y -1.6e+39) (not (<= y 4.8e+31))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.6e+39) || !(y <= 4.8e+31)) {
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 <= (-1.6d+39)) .or. (.not. (y <= 4.8d+31))) 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 <= -1.6e+39) || !(y <= 4.8e+31)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.6e+39) or not (y <= 4.8e+31): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.6e+39) || !(y <= 4.8e+31)) 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 <= -1.6e+39) || ~((y <= 4.8e+31))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.6e+39], N[Not[LessEqual[y, 4.8e+31]], $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 -1.6 \cdot 10^{+39} \lor \neg \left(y \leq 4.8 \cdot 10^{+31}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.59999999999999996e39 or 4.79999999999999965e31 < y Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-sqr-sqrt99.3%
associate-*l*99.4%
fma-def99.4%
pow1/299.4%
sqrt-pow199.5%
metadata-eval99.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 92.2%
if -1.59999999999999996e39 < y < 4.79999999999999965e31Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification96.4%
(FPCore (x y) :precision binary64 (if (or (<= y -1.6e+82) (not (<= y 5.2e+31))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.6e+82) || !(y <= 5.2e+31)) {
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.6d+82)) .or. (.not. (y <= 5.2d+31))) 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.6e+82) || !(y <= 5.2e+31)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.6e+82) or not (y <= 5.2e+31): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.6e+82) || !(y <= 5.2e+31)) 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.6e+82) || ~((y <= 5.2e+31))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.6e+82], N[Not[LessEqual[y, 5.2e+31]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+82} \lor \neg \left(y \leq 5.2 \cdot 10^{+31}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.59999999999999987e82 or 5.2e31 < y Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-sqr-sqrt99.2%
associate-*l*99.3%
fma-def99.4%
pow1/299.4%
sqrt-pow199.5%
metadata-eval99.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in y around inf 87.5%
if -1.59999999999999987e82 < y < 5.2e31Initial program 100.0%
Taylor expanded in y around 0 97.8%
Final simplification93.5%
(FPCore (x y) :precision binary64 (if (<= y -1.1e+136) (* x (* y (- y))) (if (<= y 1.7e+131) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -1.1e+136) {
tmp = x * (y * -y);
} else if (y <= 1.7e+131) {
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.1d+136)) then
tmp = x * (y * -y)
else if (y <= 1.7d+131) 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.1e+136) {
tmp = x * (y * -y);
} else if (y <= 1.7e+131) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.1e+136: tmp = x * (y * -y) elif y <= 1.7e+131: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.1e+136) tmp = Float64(x * Float64(y * Float64(-y))); elseif (y <= 1.7e+131) 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.1e+136) tmp = x * (y * -y); elseif (y <= 1.7e+131) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.1e+136], N[(x * N[(y * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.7e+131], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+136}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+131}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -1.1e136Initial program 99.9%
flip-+22.9%
div-sub22.9%
pow222.9%
associate--l-22.9%
*-commutative22.9%
*-commutative22.9%
swap-sqr14.6%
add-sqr-sqrt14.6%
associate--l-14.6%
Applied egg-rr14.6%
div-sub14.6%
associate--r+14.6%
*-commutative14.6%
Simplified14.6%
Taylor expanded in y around inf 14.9%
unpow214.9%
associate-*r*14.9%
neg-mul-114.9%
Simplified14.9%
Taylor expanded in x around 0 35.7%
mul-1-neg35.7%
unpow235.7%
distribute-rgt-neg-in35.7%
distribute-rgt-neg-in35.7%
Simplified35.7%
if -1.1e136 < y < 1.69999999999999993e131Initial program 100.0%
Taylor expanded in y around 0 87.6%
if 1.69999999999999993e131 < y Initial program 99.7%
flip-+27.3%
div-sub27.3%
pow227.3%
associate--l-27.3%
*-commutative27.3%
*-commutative27.3%
swap-sqr10.3%
add-sqr-sqrt10.2%
associate--l-10.2%
Applied egg-rr10.2%
div-sub10.2%
associate--r+10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in y around inf 10.6%
unpow210.6%
associate-*r*10.6%
neg-mul-110.6%
Simplified10.6%
Taylor expanded in x around inf 31.0%
unpow231.0%
Simplified31.0%
Final simplification70.6%
(FPCore (x y) :precision binary64 (if (<= y -6e+134) (* y (* y (- x))) (if (<= y 1.7e+131) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -6e+134) {
tmp = y * (y * -x);
} else if (y <= 1.7e+131) {
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 <= (-6d+134)) then
tmp = y * (y * -x)
else if (y <= 1.7d+131) 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 <= -6e+134) {
tmp = y * (y * -x);
} else if (y <= 1.7e+131) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e+134: tmp = y * (y * -x) elif y <= 1.7e+131: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -6e+134) tmp = Float64(y * Float64(y * Float64(-x))); elseif (y <= 1.7e+131) 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 <= -6e+134) tmp = y * (y * -x); elseif (y <= 1.7e+131) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e+134], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.7e+131], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+134}:\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+131}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -5.99999999999999993e134Initial program 99.9%
flip-+22.9%
div-sub22.9%
pow222.9%
associate--l-22.9%
*-commutative22.9%
*-commutative22.9%
swap-sqr14.6%
add-sqr-sqrt14.6%
associate--l-14.6%
Applied egg-rr14.6%
div-sub14.6%
associate--r+14.6%
*-commutative14.6%
Simplified14.6%
Taylor expanded in y around inf 14.9%
unpow214.9%
associate-*r*14.9%
neg-mul-114.9%
Simplified14.9%
Taylor expanded in x around 0 35.7%
mul-1-neg35.7%
unpow235.7%
distribute-rgt-neg-in35.7%
distribute-rgt-neg-in35.7%
Simplified35.7%
Taylor expanded in x around 0 35.7%
mul-1-neg35.7%
unpow235.7%
associate-*r*35.8%
distribute-rgt-neg-in35.8%
Simplified35.8%
if -5.99999999999999993e134 < y < 1.69999999999999993e131Initial program 100.0%
Taylor expanded in y around 0 87.6%
if 1.69999999999999993e131 < y Initial program 99.7%
flip-+27.3%
div-sub27.3%
pow227.3%
associate--l-27.3%
*-commutative27.3%
*-commutative27.3%
swap-sqr10.3%
add-sqr-sqrt10.2%
associate--l-10.2%
Applied egg-rr10.2%
div-sub10.2%
associate--r+10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in y around inf 10.6%
unpow210.6%
associate-*r*10.6%
neg-mul-110.6%
Simplified10.6%
Taylor expanded in x around inf 31.0%
unpow231.0%
Simplified31.0%
Final simplification70.6%
(FPCore (x y) :precision binary64 (if (<= y 1.7e+131) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 1.7e+131) {
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.7d+131) 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.7e+131) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.7e+131: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.7e+131) 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.7e+131) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.7e+131], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.7 \cdot 10^{+131}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 1.69999999999999993e131Initial program 100.0%
Taylor expanded in y around 0 73.7%
if 1.69999999999999993e131 < y Initial program 99.7%
flip-+27.3%
div-sub27.3%
pow227.3%
associate--l-27.3%
*-commutative27.3%
*-commutative27.3%
swap-sqr10.3%
add-sqr-sqrt10.2%
associate--l-10.2%
Applied egg-rr10.2%
div-sub10.2%
associate--r+10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in y around inf 10.6%
unpow210.6%
associate-*r*10.6%
neg-mul-110.6%
Simplified10.6%
Taylor expanded in x around inf 31.0%
unpow231.0%
Simplified31.0%
Final simplification66.2%
(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.9%
Taylor expanded in x around 0 67.2%
if 1 < x Initial program 99.9%
Taylor expanded in x around inf 54.0%
mul-1-neg54.0%
Simplified54.0%
Final simplification60.3%
(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 33.2%
Final simplification33.2%
herbie shell --seed 2023293
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))