
(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 9 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.8%
+-commutative99.8%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.85e+25) (not (<= y 7.5e+52))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.85e+25) || !(y <= 7.5e+52)) {
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.85d+25)) .or. (.not. (y <= 7.5d+52))) 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.85e+25) || !(y <= 7.5e+52)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.85e+25) or not (y <= 7.5e+52): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.85e+25) || !(y <= 7.5e+52)) 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.85e+25) || ~((y <= 7.5e+52))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.85e+25], N[Not[LessEqual[y, 7.5e+52]], $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.85 \cdot 10^{+25} \lor \neg \left(y \leq 7.5 \cdot 10^{+52}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.8499999999999999e25 or 7.49999999999999995e52 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.4%
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 93.5%
if -1.8499999999999999e25 < y < 7.49999999999999995e52Initial program 100.0%
Taylor expanded in y around 0 98.3%
Final simplification96.4%
(FPCore (x y) :precision binary64 (if (or (<= y -3.9e+59) (not (<= y 2.5e+85))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -3.9e+59) || !(y <= 2.5e+85)) {
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 <= (-3.9d+59)) .or. (.not. (y <= 2.5d+85))) 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 <= -3.9e+59) || !(y <= 2.5e+85)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.9e+59) or not (y <= 2.5e+85): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.9e+59) || !(y <= 2.5e+85)) 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 <= -3.9e+59) || ~((y <= 2.5e+85))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.9e+59], N[Not[LessEqual[y, 2.5e+85]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{+59} \lor \neg \left(y \leq 2.5 \cdot 10^{+85}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -3.90000000000000021e59 or 2.5e85 < y Initial program 99.6%
Taylor expanded in y around inf 92.6%
if -3.90000000000000021e59 < y < 2.5e85Initial program 100.0%
Taylor expanded in y around 0 96.4%
Final simplification95.1%
(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.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (<= y -7.1e+112) (* x (* y (- y))) (if (<= y 7.5e+120) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -7.1e+112) {
tmp = x * (y * -y);
} else if (y <= 7.5e+120) {
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 <= (-7.1d+112)) then
tmp = x * (y * -y)
else if (y <= 7.5d+120) 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 <= -7.1e+112) {
tmp = x * (y * -y);
} else if (y <= 7.5e+120) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.1e+112: tmp = x * (y * -y) elif y <= 7.5e+120: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.1e+112) tmp = Float64(x * Float64(y * Float64(-y))); elseif (y <= 7.5e+120) 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 <= -7.1e+112) tmp = x * (y * -y); elseif (y <= 7.5e+120) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.1e+112], N[(x * N[(y * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.5e+120], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.1 \cdot 10^{+112}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-y\right)\right)\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+120}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -7.1e112Initial program 99.6%
flip-+42.7%
div-sub42.6%
pow242.6%
*-commutative42.6%
*-commutative42.6%
swap-sqr20.2%
add-sqr-sqrt20.3%
Applied egg-rr20.3%
div-sub20.2%
Simplified20.2%
Taylor expanded in y around inf 19.6%
unpow219.6%
associate-*r*19.6%
neg-mul-119.6%
Simplified19.6%
Taylor expanded in y around 0 3.3%
associate-*r/3.3%
mul-1-neg3.3%
unpow23.3%
*-commutative3.3%
associate-*l*3.7%
distribute-rgt-neg-in3.7%
*-commutative3.7%
Simplified3.7%
Taylor expanded in x around 0 17.9%
mul-1-neg17.9%
unpow217.9%
*-commutative17.9%
distribute-rgt-neg-in17.9%
distribute-rgt-neg-in17.9%
Simplified17.9%
if -7.1e112 < y < 7.5000000000000006e120Initial program 99.9%
Taylor expanded in y around 0 91.2%
if 7.5000000000000006e120 < y Initial program 99.6%
flip-+27.8%
div-sub27.8%
pow227.8%
*-commutative27.8%
*-commutative27.8%
swap-sqr7.4%
add-sqr-sqrt7.4%
Applied egg-rr7.4%
div-sub7.4%
Simplified7.4%
Taylor expanded in y around inf 5.0%
unpow25.0%
associate-*r*5.0%
neg-mul-15.0%
Simplified5.0%
Taylor expanded in x around inf 23.1%
unpow223.1%
Simplified23.1%
Final simplification70.3%
(FPCore (x y) :precision binary64 (if (<= y -1.45e+113) (* y (* y (- x))) (if (<= y 2.3e+121) (- 1.0 x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= -1.45e+113) {
tmp = y * (y * -x);
} else if (y <= 2.3e+121) {
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.45d+113)) then
tmp = y * (y * -x)
else if (y <= 2.3d+121) 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.45e+113) {
tmp = y * (y * -x);
} else if (y <= 2.3e+121) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.45e+113: tmp = y * (y * -x) elif y <= 2.3e+121: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.45e+113) tmp = Float64(y * Float64(y * Float64(-x))); elseif (y <= 2.3e+121) 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.45e+113) tmp = y * (y * -x); elseif (y <= 2.3e+121) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.45e+113], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.3e+121], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+113}:\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+121}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < -1.44999999999999992e113Initial program 99.6%
flip-+42.7%
div-sub42.6%
pow242.6%
*-commutative42.6%
*-commutative42.6%
swap-sqr20.2%
add-sqr-sqrt20.3%
Applied egg-rr20.3%
div-sub20.2%
Simplified20.2%
Taylor expanded in y around inf 19.6%
unpow219.6%
associate-*r*19.6%
neg-mul-119.6%
Simplified19.6%
Taylor expanded in x around 0 17.9%
mul-1-neg17.9%
unpow217.9%
*-commutative17.9%
associate-*l*18.3%
distribute-rgt-neg-in18.3%
*-commutative18.3%
Simplified18.3%
if -1.44999999999999992e113 < y < 2.2999999999999999e121Initial program 99.9%
Taylor expanded in y around 0 91.2%
if 2.2999999999999999e121 < y Initial program 99.6%
flip-+27.8%
div-sub27.8%
pow227.8%
*-commutative27.8%
*-commutative27.8%
swap-sqr7.4%
add-sqr-sqrt7.4%
Applied egg-rr7.4%
div-sub7.4%
Simplified7.4%
Taylor expanded in y around inf 5.0%
unpow25.0%
associate-*r*5.0%
neg-mul-15.0%
Simplified5.0%
Taylor expanded in x around inf 23.1%
unpow223.1%
Simplified23.1%
Final simplification70.3%
(FPCore (x y) :precision binary64 (if (<= y 2.3e+121) (- 1.0 x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 2.3e+121) {
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+121) 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+121) {
tmp = 1.0 - x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.3e+121: tmp = 1.0 - x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.3e+121) 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+121) tmp = 1.0 - x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.3e+121], N[(1.0 - x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.3 \cdot 10^{+121}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 2.2999999999999999e121Initial program 99.9%
Taylor expanded in y around 0 73.0%
if 2.2999999999999999e121 < y Initial program 99.6%
flip-+27.8%
div-sub27.8%
pow227.8%
*-commutative27.8%
*-commutative27.8%
swap-sqr7.4%
add-sqr-sqrt7.4%
Applied egg-rr7.4%
div-sub7.4%
Simplified7.4%
Taylor expanded in y around inf 5.0%
unpow25.0%
associate-*r*5.0%
neg-mul-15.0%
Simplified5.0%
Taylor expanded in x around inf 23.1%
unpow223.1%
Simplified23.1%
Final simplification67.5%
(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 60.4%
if 1 < x Initial program 99.9%
Taylor expanded in x around inf 67.3%
neg-mul-167.3%
Simplified67.3%
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 30.2%
Final simplification30.2%
herbie shell --seed 2023196
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))