
(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 -3.7e+53) (not (<= y 2.6e+22))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -3.7e+53) || !(y <= 2.6e+22)) {
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 <= (-3.7d+53)) .or. (.not. (y <= 2.6d+22))) 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 <= -3.7e+53) || !(y <= 2.6e+22)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.7e+53) or not (y <= 2.6e+22): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.7e+53) || !(y <= 2.6e+22)) 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 <= -3.7e+53) || ~((y <= 2.6e+22))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.7e+53], N[Not[LessEqual[y, 2.6e+22]], $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 -3.7 \cdot 10^{+53} \lor \neg \left(y \leq 2.6 \cdot 10^{+22}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -3.7e53 or 2.6e22 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.4%
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 92.0%
if -3.7e53 < y < 2.6e22Initial program 100.0%
Taylor expanded in y around 0 99.4%
Final simplification96.5%
(FPCore (x y) :precision binary64 (if (or (<= y -4.2e+57) (not (<= y 1.52e+66))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -4.2e+57) || !(y <= 1.52e+66)) {
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 <= (-4.2d+57)) .or. (.not. (y <= 1.52d+66))) 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 <= -4.2e+57) || !(y <= 1.52e+66)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.2e+57) or not (y <= 1.52e+66): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.2e+57) || !(y <= 1.52e+66)) 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 <= -4.2e+57) || ~((y <= 1.52e+66))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.2e+57], N[Not[LessEqual[y, 1.52e+66]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+57} \lor \neg \left(y \leq 1.52 \cdot 10^{+66}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -4.19999999999999982e57 or 1.52000000000000004e66 < y Initial program 99.7%
Taylor expanded in y around inf 88.4%
if -4.19999999999999982e57 < y < 1.52000000000000004e66Initial program 100.0%
Taylor expanded in y around 0 97.5%
Final simplification94.2%
(FPCore (x y) :precision binary64 (if (<= y -1.65e+127) (* x (* y (- y))) (if (<= y 1.22e+132) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -1.65e+127) {
tmp = x * (y * -y);
} else if (y <= 1.22e+132) {
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.65d+127)) then
tmp = x * (y * -y)
else if (y <= 1.22d+132) 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.65e+127) {
tmp = x * (y * -y);
} else if (y <= 1.22e+132) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.65e+127: tmp = x * (y * -y) elif y <= 1.22e+132: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.65e+127) tmp = Float64(x * Float64(y * Float64(-y))); elseif (y <= 1.22e+132) 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.65e+127) tmp = x * (y * -y); elseif (y <= 1.22e+132) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.65e+127], N[(x * N[(y * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.22e+132], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+127}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{+132}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -1.64999999999999988e127Initial program 99.8%
flip-+33.4%
div-sub33.4%
pow233.4%
associate--l-33.4%
*-commutative33.4%
*-commutative33.4%
swap-sqr12.5%
add-sqr-sqrt12.6%
associate--l-12.6%
Applied egg-rr12.6%
div-sub12.6%
associate--r+12.6%
Simplified12.6%
Taylor expanded in y around inf 13.1%
unpow213.1%
associate-*r*13.1%
neg-mul-113.1%
Simplified13.1%
Taylor expanded in x around 0 26.1%
mul-1-neg26.1%
unpow226.1%
*-commutative26.1%
distribute-rgt-neg-in26.1%
distribute-rgt-neg-in26.1%
Simplified26.1%
if -1.64999999999999988e127 < y < 1.22e132Initial program 99.9%
Taylor expanded in y around 0 88.7%
if 1.22e132 < y Initial program 99.7%
flip-+28.7%
div-sub28.7%
pow228.7%
associate--l-28.7%
*-commutative28.7%
*-commutative28.7%
swap-sqr8.9%
add-sqr-sqrt8.9%
associate--l-8.9%
Applied egg-rr8.9%
div-sub8.9%
associate--r+8.9%
Simplified8.9%
Taylor expanded in y around inf 10.1%
unpow210.1%
associate-*r*10.1%
neg-mul-110.1%
Simplified10.1%
Taylor expanded in x around inf 28.0%
unpow228.0%
Simplified28.0%
Final simplification72.8%
(FPCore (x y) :precision binary64 (if (<= y -9e+127) (* y (* x (- y))) (if (<= y 8e+141) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -9e+127) {
tmp = y * (x * -y);
} else if (y <= 8e+141) {
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 <= (-9d+127)) then
tmp = y * (x * -y)
else if (y <= 8d+141) 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 <= -9e+127) {
tmp = y * (x * -y);
} else if (y <= 8e+141) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9e+127: tmp = y * (x * -y) elif y <= 8e+141: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -9e+127) tmp = Float64(y * Float64(x * Float64(-y))); elseif (y <= 8e+141) 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 <= -9e+127) tmp = y * (x * -y); elseif (y <= 8e+141) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9e+127], N[(y * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8e+141], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+127}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+141}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -9.00000000000000068e127Initial program 99.8%
flip-+33.4%
div-sub33.4%
pow233.4%
associate--l-33.4%
*-commutative33.4%
*-commutative33.4%
swap-sqr12.5%
add-sqr-sqrt12.6%
associate--l-12.6%
Applied egg-rr12.6%
div-sub12.6%
associate--r+12.6%
Simplified12.6%
Taylor expanded in y around inf 13.1%
unpow213.1%
associate-*r*13.1%
neg-mul-113.1%
Simplified13.1%
Taylor expanded in x around 0 26.1%
mul-1-neg26.1%
unpow226.1%
*-commutative26.1%
distribute-rgt-neg-in26.1%
distribute-rgt-neg-in26.1%
Simplified26.1%
Taylor expanded in x around 0 26.1%
mul-1-neg26.1%
unpow226.1%
associate-*l*26.6%
*-commutative26.6%
distribute-rgt-neg-in26.6%
distribute-rgt-neg-in26.6%
Simplified26.6%
if -9.00000000000000068e127 < y < 8.00000000000000014e141Initial program 99.9%
Taylor expanded in y around 0 88.7%
if 8.00000000000000014e141 < y Initial program 99.7%
flip-+28.7%
div-sub28.7%
pow228.7%
associate--l-28.7%
*-commutative28.7%
*-commutative28.7%
swap-sqr8.9%
add-sqr-sqrt8.9%
associate--l-8.9%
Applied egg-rr8.9%
div-sub8.9%
associate--r+8.9%
Simplified8.9%
Taylor expanded in y around inf 10.1%
unpow210.1%
associate-*r*10.1%
neg-mul-110.1%
Simplified10.1%
Taylor expanded in x around inf 28.0%
unpow228.0%
Simplified28.0%
Final simplification72.9%
(FPCore (x y) :precision binary64 (if (<= y 2.3e+137) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 2.3e+137) {
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 <= 2.3d+137) 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 <= 2.3e+137) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.3e+137: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.3e+137) 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 <= 2.3e+137) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.3e+137], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.3 \cdot 10^{+137}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 2.29999999999999999e137Initial program 99.9%
Taylor expanded in y around 0 76.4%
if 2.29999999999999999e137 < y Initial program 99.7%
flip-+28.7%
div-sub28.7%
pow228.7%
associate--l-28.7%
*-commutative28.7%
*-commutative28.7%
swap-sqr8.9%
add-sqr-sqrt8.9%
associate--l-8.9%
Applied egg-rr8.9%
div-sub8.9%
associate--r+8.9%
Simplified8.9%
Taylor expanded in y around inf 10.1%
unpow210.1%
associate-*r*10.1%
neg-mul-110.1%
Simplified10.1%
Taylor expanded in x around inf 28.0%
unpow228.0%
Simplified28.0%
Final simplification70.0%
(FPCore (x y) :precision binary64 (if (<= x 0.0005) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 0.0005) {
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.0005d0) 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.0005) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.0005: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 0.0005) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.0005) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.0005], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0005:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 5.0000000000000001e-4Initial program 99.9%
Taylor expanded in x around 0 63.7%
if 5.0000000000000001e-4 < x Initial program 99.9%
Taylor expanded in x around inf 66.8%
mul-1-neg66.8%
Simplified66.8%
Final simplification65.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 32.1%
Final simplification32.1%
herbie shell --seed 2023200
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))