
(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 10 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.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -3e+36) (not (<= y 5.5e+19))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -3e+36) || !(y <= 5.5e+19)) {
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 <= (-3d+36)) .or. (.not. (y <= 5.5d+19))) 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 <= -3e+36) || !(y <= 5.5e+19)) {
tmp = 1.0 + (y * Math.sqrt(x));
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3e+36) or not (y <= 5.5e+19): tmp = 1.0 + (y * math.sqrt(x)) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3e+36) || !(y <= 5.5e+19)) 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 <= -3e+36) || ~((y <= 5.5e+19))) tmp = 1.0 + (y * sqrt(x)); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3e+36], N[Not[LessEqual[y, 5.5e+19]], $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 \cdot 10^{+36} \lor \neg \left(y \leq 5.5 \cdot 10^{+19}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -3e36 or 5.5e19 < y Initial program 99.7%
Taylor expanded in x around 0 90.6%
if -3e36 < y < 5.5e19Initial program 100.0%
Taylor expanded in y around 0 99.3%
Final simplification95.3%
(FPCore (x y) :precision binary64 (if (or (<= y -1.3e+59) (not (<= y 6.5e+60))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.3e+59) || !(y <= 6.5e+60)) {
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.3d+59)) .or. (.not. (y <= 6.5d+60))) 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.3e+59) || !(y <= 6.5e+60)) {
tmp = y * Math.sqrt(x);
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.3e+59) or not (y <= 6.5e+60): tmp = y * math.sqrt(x) else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.3e+59) || !(y <= 6.5e+60)) 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.3e+59) || ~((y <= 6.5e+60))) tmp = y * sqrt(x); else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.3e+59], N[Not[LessEqual[y, 6.5e+60]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{+59} \lor \neg \left(y \leq 6.5 \cdot 10^{+60}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -1.3e59 or 6.49999999999999931e60 < y Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
add-sqr-sqrt99.4%
associate-*l*99.4%
fma-define99.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 y around inf 87.8%
if -1.3e59 < y < 6.49999999999999931e60Initial program 100.0%
Taylor expanded in y around 0 95.4%
Final simplification92.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= x 1.0) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
double tmp;
if (x <= 1.0) {
tmp = 1.0 + t_0;
} else {
tmp = t_0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * sqrt(x)
if (x <= 1.0d0) then
tmp = 1.0d0 + t_0
else
tmp = t_0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * Math.sqrt(x);
double tmp;
if (x <= 1.0) {
tmp = 1.0 + t_0;
} else {
tmp = t_0 - x;
}
return tmp;
}
def code(x, y): t_0 = y * math.sqrt(x) tmp = 0 if x <= 1.0: tmp = 1.0 + t_0 else: tmp = t_0 - x return tmp
function code(x, y) t_0 = Float64(y * sqrt(x)) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 + t_0); else tmp = Float64(t_0 - x); end return tmp end
function tmp_2 = code(x, y) t_0 = y * sqrt(x); tmp = 0.0; if (x <= 1.0) tmp = 1.0 + t_0; else tmp = t_0 - x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.0], N[(1.0 + t$95$0), $MachinePrecision], N[(t$95$0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \sqrt{x}\\
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if x < 1Initial program 99.8%
Taylor expanded in x around 0 99.3%
if 1 < x Initial program 99.9%
Taylor expanded in y around inf 75.6%
Taylor expanded in x around inf 74.9%
Taylor expanded in y around 0 99.2%
neg-mul-199.2%
+-commutative99.2%
sub-neg99.2%
Simplified99.2%
Final simplification99.3%
(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 (<= y -6e+116) (/ (* y x) (- y)) (if (<= y 1.05e+130) (- 1.0 x) (/ (* y x) y))))
double code(double x, double y) {
double tmp;
if (y <= -6e+116) {
tmp = (y * x) / -y;
} else if (y <= 1.05e+130) {
tmp = 1.0 - x;
} else {
tmp = (y * 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 <= (-6d+116)) then
tmp = (y * x) / -y
else if (y <= 1.05d+130) then
tmp = 1.0d0 - x
else
tmp = (y * x) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6e+116) {
tmp = (y * x) / -y;
} else if (y <= 1.05e+130) {
tmp = 1.0 - x;
} else {
tmp = (y * x) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e+116: tmp = (y * x) / -y elif y <= 1.05e+130: tmp = 1.0 - x else: tmp = (y * x) / y return tmp
function code(x, y) tmp = 0.0 if (y <= -6e+116) tmp = Float64(Float64(y * x) / Float64(-y)); elseif (y <= 1.05e+130) tmp = Float64(1.0 - x); else tmp = Float64(Float64(y * x) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6e+116) tmp = (y * x) / -y; elseif (y <= 1.05e+130) tmp = 1.0 - x; else tmp = (y * x) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e+116], N[(N[(y * x), $MachinePrecision] / (-y)), $MachinePrecision], If[LessEqual[y, 1.05e+130], N[(1.0 - x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+116}:\\
\;\;\;\;\frac{y \cdot x}{-y}\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+130}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{y}\\
\end{array}
\end{array}
if y < -5.9999999999999997e116Initial program 99.7%
Taylor expanded in y around inf 99.7%
Taylor expanded in y around 0 3.9%
Taylor expanded in x around inf 4.9%
neg-mul-14.9%
distribute-neg-frac4.9%
Simplified4.9%
distribute-frac-neg4.9%
distribute-frac-neg24.9%
associate-*r/28.4%
Applied egg-rr28.4%
if -5.9999999999999997e116 < y < 1.04999999999999995e130Initial program 99.9%
Taylor expanded in y around 0 87.9%
if 1.04999999999999995e130 < y Initial program 99.8%
Taylor expanded in y around inf 99.8%
Taylor expanded in y around 0 1.9%
Taylor expanded in x around inf 0.9%
neg-mul-10.9%
distribute-neg-frac0.9%
Simplified0.9%
associate-*r/0.7%
*-un-lft-identity0.7%
*-commutative0.7%
rgt-mult-inverse0.7%
*-commutative0.7%
associate-*l*0.8%
div-inv0.8%
*-commutative0.8%
*-commutative0.8%
div-inv0.8%
associate-*l*0.7%
*-commutative0.7%
rgt-mult-inverse0.7%
*-commutative0.7%
*-un-lft-identity0.7%
add-sqr-sqrt0.0%
sqrt-unprod31.3%
sqr-neg31.3%
sqrt-unprod31.4%
add-sqr-sqrt31.4%
Applied egg-rr31.4%
Final simplification71.5%
(FPCore (x y) :precision binary64 (if (<= y 9.5e+129) (- 1.0 x) (/ (* y x) y)))
double code(double x, double y) {
double tmp;
if (y <= 9.5e+129) {
tmp = 1.0 - x;
} else {
tmp = (y * 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 <= 9.5d+129) then
tmp = 1.0d0 - x
else
tmp = (y * x) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 9.5e+129) {
tmp = 1.0 - x;
} else {
tmp = (y * x) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 9.5e+129: tmp = 1.0 - x else: tmp = (y * x) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 9.5e+129) tmp = Float64(1.0 - x); else tmp = Float64(Float64(y * x) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 9.5e+129) tmp = 1.0 - x; else tmp = (y * x) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 9.5e+129], N[(1.0 - x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{+129}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{y}\\
\end{array}
\end{array}
if y < 9.5000000000000004e129Initial program 99.9%
Taylor expanded in y around 0 72.9%
if 9.5000000000000004e129 < y Initial program 99.8%
Taylor expanded in y around inf 99.8%
Taylor expanded in y around 0 1.9%
Taylor expanded in x around inf 0.9%
neg-mul-10.9%
distribute-neg-frac0.9%
Simplified0.9%
associate-*r/0.7%
*-un-lft-identity0.7%
*-commutative0.7%
rgt-mult-inverse0.7%
*-commutative0.7%
associate-*l*0.8%
div-inv0.8%
*-commutative0.8%
*-commutative0.8%
div-inv0.8%
associate-*l*0.7%
*-commutative0.7%
rgt-mult-inverse0.7%
*-commutative0.7%
*-un-lft-identity0.7%
add-sqr-sqrt0.0%
sqrt-unprod31.3%
sqr-neg31.3%
sqrt-unprod31.4%
add-sqr-sqrt31.4%
Applied egg-rr31.4%
Final simplification67.7%
(FPCore (x y) :precision binary64 (if (<= x 235.0) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (x <= 235.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 <= 235.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 <= 235.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 235.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 235.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 235.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 235.0], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 235:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 235Initial program 99.8%
Taylor expanded in y around inf 99.7%
Taylor expanded in y around 0 64.6%
Taylor expanded in x around 0 64.3%
if 235 < x Initial program 99.9%
Taylor expanded in y around inf 75.4%
Taylor expanded in y around 0 38.7%
Taylor expanded in x around inf 62.5%
neg-mul-162.5%
Simplified62.5%
Final simplification63.4%
(FPCore (x y) :precision binary64 (- 1.0 x))
double code(double x, double y) {
return 1.0 - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - x
end function
public static double code(double x, double y) {
return 1.0 - x;
}
def code(x, y): return 1.0 - x
function code(x, y) return Float64(1.0 - x) end
function tmp = code(x, y) tmp = 1.0 - x; end
code[x_, y_] := N[(1.0 - x), $MachinePrecision]
\begin{array}{l}
\\
1 - x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 64.0%
Final simplification64.0%
(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 y around inf 87.8%
Taylor expanded in y around 0 52.0%
Taylor expanded in x around 0 33.7%
Final simplification33.7%
herbie shell --seed 2024071
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))