
(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 -4.5e+40) (not (<= y 7.8e+40))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -4.5e+40) || !(y <= 7.8e+40)) {
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 <= (-4.5d+40)) .or. (.not. (y <= 7.8d+40))) 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 <= -4.5e+40) || !(y <= 7.8e+40)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.5e+40) or not (y <= 7.8e+40): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.5e+40) || !(y <= 7.8e+40)) 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 <= -4.5e+40) || ~((y <= 7.8e+40))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.5e+40], N[Not[LessEqual[y, 7.8e+40]], $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 -4.5 \cdot 10^{+40} \lor \neg \left(y \leq 7.8 \cdot 10^{+40}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -4.50000000000000032e40 or 7.8000000000000002e40 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
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.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in x around 0 91.4%
if -4.50000000000000032e40 < y < 7.8000000000000002e40Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification95.9%
(FPCore (x y) :precision binary64 (if (or (<= y -6.5e+49) (not (<= y 8e+80))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -6.5e+49) || !(y <= 8e+80)) {
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 <= (-6.5d+49)) .or. (.not. (y <= 8d+80))) 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 <= -6.5e+49) || !(y <= 8e+80)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.5e+49) or not (y <= 8e+80): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.5e+49) || !(y <= 8e+80)) 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 <= -6.5e+49) || ~((y <= 8e+80))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.5e+49], N[Not[LessEqual[y, 8e+80]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+49} \lor \neg \left(y \leq 8 \cdot 10^{+80}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -6.5000000000000005e49 or 8e80 < y Initial program 99.7%
Taylor expanded in y around inf 86.6%
if -6.5000000000000005e49 < y < 8e80Initial program 100.0%
Taylor expanded in y around 0 95.5%
Final simplification91.7%
(FPCore (x y) :precision binary64 (if (<= y -9.5e+128) (* (- y) (* x y)) (if (<= y 4.7e+142) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -9.5e+128) {
tmp = -y * (x * y);
} else if (y <= 4.7e+142) {
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 <= (-9.5d+128)) then
tmp = -y * (x * y)
else if (y <= 4.7d+142) 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 <= -9.5e+128) {
tmp = -y * (x * y);
} else if (y <= 4.7e+142) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9.5e+128: tmp = -y * (x * y) elif y <= 4.7e+142: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -9.5e+128) tmp = Float64(Float64(-y) * Float64(x * y)); elseif (y <= 4.7e+142) 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 <= -9.5e+128) tmp = -y * (x * y); elseif (y <= 4.7e+142) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9.5e+128], N[((-y) * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.7e+142], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+128}:\\
\;\;\;\;\left(-y\right) \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+142}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -9.50000000000000014e128Initial program 99.9%
flip-+23.7%
div-sub23.7%
pow223.7%
associate--l-23.7%
*-commutative23.7%
*-commutative23.7%
swap-sqr10.0%
add-sqr-sqrt10.0%
associate--l-10.0%
Applied egg-rr10.0%
div-sub10.0%
associate--r+10.0%
Simplified10.0%
Taylor expanded in y around inf 11.0%
unpow211.0%
associate-*r*11.0%
neg-mul-111.0%
Simplified11.0%
Taylor expanded in x around 0 33.1%
mul-1-neg33.1%
unpow233.1%
associate-*r*33.3%
distribute-lft-neg-in33.3%
Simplified33.3%
if -9.50000000000000014e128 < y < 4.7e142Initial program 99.9%
Taylor expanded in y around 0 80.7%
if 4.7e142 < y Initial program 99.6%
flip-+26.7%
div-sub26.7%
pow226.7%
associate--l-26.7%
*-commutative26.7%
*-commutative26.7%
swap-sqr7.1%
add-sqr-sqrt7.1%
associate--l-7.1%
Applied egg-rr7.1%
div-sub7.1%
associate--r+7.1%
Simplified7.1%
Taylor expanded in y around inf 7.7%
unpow27.7%
associate-*r*7.7%
neg-mul-17.7%
Simplified7.7%
Taylor expanded in x around inf 21.5%
unpow221.5%
Simplified21.5%
Final simplification65.3%
(FPCore (x y) :precision binary64 (if (<= y -1.4e+129) (* y (- y)) (if (<= y 9.8e+141) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -1.4e+129) {
tmp = y * -y;
} else if (y <= 9.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 <= (-1.4d+129)) then
tmp = y * -y
else if (y <= 9.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 <= -1.4e+129) {
tmp = y * -y;
} else if (y <= 9.8e+141) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.4e+129: tmp = y * -y elif y <= 9.8e+141: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.4e+129) tmp = Float64(y * Float64(-y)); elseif (y <= 9.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 <= -1.4e+129) tmp = y * -y; elseif (y <= 9.8e+141) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.4e+129], N[(y * (-y)), $MachinePrecision], If[LessEqual[y, 9.8e+141], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+129}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{+141}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -1.39999999999999987e129Initial program 99.9%
flip-+23.7%
div-sub23.7%
pow223.7%
associate--l-23.7%
*-commutative23.7%
*-commutative23.7%
swap-sqr10.0%
add-sqr-sqrt10.0%
associate--l-10.0%
Applied egg-rr10.0%
div-sub10.0%
associate--r+10.0%
Simplified10.0%
Taylor expanded in y around inf 11.0%
unpow211.0%
associate-*r*11.0%
neg-mul-111.0%
Simplified11.0%
Taylor expanded in x around inf 0.2%
neg-mul-10.2%
Simplified0.2%
associate-/l*0.2%
neg-sub00.2%
div-sub0.2%
add-sqr-sqrt0.0%
sqrt-unprod0.1%
sqr-neg0.1%
sqrt-unprod0.2%
add-sqr-sqrt0.2%
add-sqr-sqrt0.2%
sqrt-unprod0.2%
sqr-neg0.2%
sqrt-unprod0.0%
add-sqr-sqrt32.9%
div-inv32.9%
frac-2neg32.9%
remove-double-neg32.9%
clear-num32.9%
Applied egg-rr32.9%
*-inverses32.9%
metadata-eval32.9%
neg-sub032.9%
*-inverses32.9%
*-rgt-identity32.9%
distribute-rgt-neg-in32.9%
Simplified32.9%
if -1.39999999999999987e129 < y < 9.8000000000000002e141Initial program 99.9%
Taylor expanded in y around 0 80.7%
if 9.8000000000000002e141 < y Initial program 99.6%
flip-+26.7%
div-sub26.7%
pow226.7%
associate--l-26.7%
*-commutative26.7%
*-commutative26.7%
swap-sqr7.1%
add-sqr-sqrt7.1%
associate--l-7.1%
Applied egg-rr7.1%
div-sub7.1%
associate--r+7.1%
Simplified7.1%
Taylor expanded in y around inf 7.7%
unpow27.7%
associate-*r*7.7%
neg-mul-17.7%
Simplified7.7%
Taylor expanded in x around inf 21.5%
unpow221.5%
Simplified21.5%
Final simplification65.3%
(FPCore (x y) :precision binary64 (if (<= y 1.5e+142) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 1.5e+142) {
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.5d+142) 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.5e+142) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.5e+142: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.5e+142) 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.5e+142) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.5e+142], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.5 \cdot 10^{+142}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 1.49999999999999987e142Initial program 99.9%
Taylor expanded in y around 0 70.5%
if 1.49999999999999987e142 < y Initial program 99.6%
flip-+26.7%
div-sub26.7%
pow226.7%
associate--l-26.7%
*-commutative26.7%
*-commutative26.7%
swap-sqr7.1%
add-sqr-sqrt7.1%
associate--l-7.1%
Applied egg-rr7.1%
div-sub7.1%
associate--r+7.1%
Simplified7.1%
Taylor expanded in y around inf 7.7%
unpow27.7%
associate-*r*7.7%
neg-mul-17.7%
Simplified7.7%
Taylor expanded in x around inf 21.5%
unpow221.5%
Simplified21.5%
Final simplification62.1%
(FPCore (x y) :precision binary64 (if (<= x 1.65e-12) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 1.65e-12) {
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.65d-12) 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.65e-12) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.65e-12: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.65e-12) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.65e-12) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.65e-12], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.65 \cdot 10^{-12}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 1.65e-12Initial program 99.9%
Taylor expanded in x around 0 59.4%
if 1.65e-12 < x Initial program 99.9%
Taylor expanded in x around inf 57.9%
mul-1-neg57.9%
Simplified57.9%
Final simplification58.6%
(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 29.6%
Final simplification29.6%
herbie shell --seed 2023238
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))