
(FPCore (x y) :precision binary64 (* (* 3.0 (sqrt x)) (- (+ y (/ 1.0 (* x 9.0))) 1.0)))
double code(double x, double y) {
return (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (3.0d0 * sqrt(x)) * ((y + (1.0d0 / (x * 9.0d0))) - 1.0d0)
end function
public static double code(double x, double y) {
return (3.0 * Math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
def code(x, y): return (3.0 * math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0)
function code(x, y) return Float64(Float64(3.0 * sqrt(x)) * Float64(Float64(y + Float64(1.0 / Float64(x * 9.0))) - 1.0)) end
function tmp = code(x, y) tmp = (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0); end
code[x_, y_] := N[(N[(3.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[(N[(y + N[(1.0 / N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot \sqrt{x}\right) \cdot \left(\left(y + \frac{1}{x \cdot 9}\right) - 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (* 3.0 (sqrt x)) (- (+ y (/ 1.0 (* x 9.0))) 1.0)))
double code(double x, double y) {
return (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (3.0d0 * sqrt(x)) * ((y + (1.0d0 / (x * 9.0d0))) - 1.0d0)
end function
public static double code(double x, double y) {
return (3.0 * Math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
def code(x, y): return (3.0 * math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0)
function code(x, y) return Float64(Float64(3.0 * sqrt(x)) * Float64(Float64(y + Float64(1.0 / Float64(x * 9.0))) - 1.0)) end
function tmp = code(x, y) tmp = (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0); end
code[x_, y_] := N[(N[(3.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[(N[(y + N[(1.0 / N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot \sqrt{x}\right) \cdot \left(\left(y + \frac{1}{x \cdot 9}\right) - 1\right)
\end{array}
(FPCore (x y) :precision binary64 (* (* 3.0 (sqrt x)) (+ (+ y (/ 1.0 (* x 9.0))) -1.0)))
double code(double x, double y) {
return (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) + -1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (3.0d0 * sqrt(x)) * ((y + (1.0d0 / (x * 9.0d0))) + (-1.0d0))
end function
public static double code(double x, double y) {
return (3.0 * Math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) + -1.0);
}
def code(x, y): return (3.0 * math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) + -1.0)
function code(x, y) return Float64(Float64(3.0 * sqrt(x)) * Float64(Float64(y + Float64(1.0 / Float64(x * 9.0))) + -1.0)) end
function tmp = code(x, y) tmp = (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) + -1.0); end
code[x_, y_] := N[(N[(3.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[(N[(y + N[(1.0 / N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot \sqrt{x}\right) \cdot \left(\left(y + \frac{1}{x \cdot 9}\right) + -1\right)
\end{array}
Initial program 99.4%
Final simplification99.4%
(FPCore (x y)
:precision binary64
(if (<= x 66.0)
(sqrt (/ 0.1111111111111111 x))
(if (or (<= x 8.6e+58) (not (<= x 2.1e+255)))
(* (sqrt x) -3.0)
(* 3.0 (* (sqrt x) y)))))
double code(double x, double y) {
double tmp;
if (x <= 66.0) {
tmp = sqrt((0.1111111111111111 / x));
} else if ((x <= 8.6e+58) || !(x <= 2.1e+255)) {
tmp = sqrt(x) * -3.0;
} else {
tmp = 3.0 * (sqrt(x) * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 66.0d0) then
tmp = sqrt((0.1111111111111111d0 / x))
else if ((x <= 8.6d+58) .or. (.not. (x <= 2.1d+255))) then
tmp = sqrt(x) * (-3.0d0)
else
tmp = 3.0d0 * (sqrt(x) * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 66.0) {
tmp = Math.sqrt((0.1111111111111111 / x));
} else if ((x <= 8.6e+58) || !(x <= 2.1e+255)) {
tmp = Math.sqrt(x) * -3.0;
} else {
tmp = 3.0 * (Math.sqrt(x) * y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 66.0: tmp = math.sqrt((0.1111111111111111 / x)) elif (x <= 8.6e+58) or not (x <= 2.1e+255): tmp = math.sqrt(x) * -3.0 else: tmp = 3.0 * (math.sqrt(x) * y) return tmp
function code(x, y) tmp = 0.0 if (x <= 66.0) tmp = sqrt(Float64(0.1111111111111111 / x)); elseif ((x <= 8.6e+58) || !(x <= 2.1e+255)) tmp = Float64(sqrt(x) * -3.0); else tmp = Float64(3.0 * Float64(sqrt(x) * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 66.0) tmp = sqrt((0.1111111111111111 / x)); elseif ((x <= 8.6e+58) || ~((x <= 2.1e+255))) tmp = sqrt(x) * -3.0; else tmp = 3.0 * (sqrt(x) * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 66.0], N[Sqrt[N[(0.1111111111111111 / x), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, 8.6e+58], N[Not[LessEqual[x, 2.1e+255]], $MachinePrecision]], N[(N[Sqrt[x], $MachinePrecision] * -3.0), $MachinePrecision], N[(3.0 * N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 66:\\
\;\;\;\;\sqrt{\frac{0.1111111111111111}{x}}\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{+58} \lor \neg \left(x \leq 2.1 \cdot 10^{+255}\right):\\
\;\;\;\;\sqrt{x} \cdot -3\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(\sqrt{x} \cdot y\right)\\
\end{array}
\end{array}
if x < 66Initial program 99.3%
*-commutative99.3%
associate-*l*99.2%
associate--l+99.2%
distribute-lft-in99.2%
fma-define99.2%
sub-neg99.2%
+-commutative99.2%
distribute-lft-in99.2%
metadata-eval99.2%
metadata-eval99.2%
*-commutative99.2%
associate-/r*99.2%
associate-*r/99.3%
metadata-eval99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around 0 74.1%
metadata-eval74.1%
sqrt-prod74.1%
div-inv74.2%
pow1/274.2%
Applied egg-rr74.2%
unpow1/274.2%
Simplified74.2%
if 66 < x < 8.59999999999999982e58 or 2.1e255 < x Initial program 99.6%
*-commutative99.6%
associate-*l*99.4%
associate--l+99.4%
distribute-lft-in99.5%
fma-define99.4%
sub-neg99.4%
+-commutative99.4%
distribute-lft-in99.4%
metadata-eval99.4%
metadata-eval99.4%
*-commutative99.4%
associate-/r*99.4%
associate-*r/99.4%
metadata-eval99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around inf 96.2%
Taylor expanded in y around 0 64.3%
*-commutative64.3%
Simplified64.3%
if 8.59999999999999982e58 < x < 2.1e255Initial program 99.6%
*-commutative99.6%
associate-*l*99.5%
associate--l+99.5%
distribute-lft-in99.5%
fma-define99.5%
sub-neg99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
metadata-eval99.5%
*-commutative99.5%
associate-/r*99.5%
associate-*r/99.5%
metadata-eval99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in y around inf 67.1%
Final simplification70.4%
(FPCore (x y) :precision binary64 (if (or (<= y -1.65e+37) (not (<= y 1.72e+47))) (* 3.0 (* (sqrt x) y)) (* (sqrt x) (- -3.0 (/ -0.3333333333333333 x)))))
double code(double x, double y) {
double tmp;
if ((y <= -1.65e+37) || !(y <= 1.72e+47)) {
tmp = 3.0 * (sqrt(x) * y);
} else {
tmp = sqrt(x) * (-3.0 - (-0.3333333333333333 / 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.65d+37)) .or. (.not. (y <= 1.72d+47))) then
tmp = 3.0d0 * (sqrt(x) * y)
else
tmp = sqrt(x) * ((-3.0d0) - ((-0.3333333333333333d0) / x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.65e+37) || !(y <= 1.72e+47)) {
tmp = 3.0 * (Math.sqrt(x) * y);
} else {
tmp = Math.sqrt(x) * (-3.0 - (-0.3333333333333333 / x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.65e+37) or not (y <= 1.72e+47): tmp = 3.0 * (math.sqrt(x) * y) else: tmp = math.sqrt(x) * (-3.0 - (-0.3333333333333333 / x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.65e+37) || !(y <= 1.72e+47)) tmp = Float64(3.0 * Float64(sqrt(x) * y)); else tmp = Float64(sqrt(x) * Float64(-3.0 - Float64(-0.3333333333333333 / x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.65e+37) || ~((y <= 1.72e+47))) tmp = 3.0 * (sqrt(x) * y); else tmp = sqrt(x) * (-3.0 - (-0.3333333333333333 / x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.65e+37], N[Not[LessEqual[y, 1.72e+47]], $MachinePrecision]], N[(3.0 * N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * N[(-3.0 - N[(-0.3333333333333333 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+37} \lor \neg \left(y \leq 1.72 \cdot 10^{+47}\right):\\
\;\;\;\;3 \cdot \left(\sqrt{x} \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot \left(-3 - \frac{-0.3333333333333333}{x}\right)\\
\end{array}
\end{array}
if y < -1.65e37 or 1.72000000000000002e47 < y Initial program 99.5%
*-commutative99.5%
associate-*l*99.4%
associate--l+99.4%
distribute-lft-in99.4%
fma-define99.4%
sub-neg99.4%
+-commutative99.4%
distribute-lft-in99.4%
metadata-eval99.4%
metadata-eval99.4%
*-commutative99.4%
associate-/r*99.4%
associate-*r/99.4%
metadata-eval99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in y around inf 83.0%
if -1.65e37 < y < 1.72000000000000002e47Initial program 99.4%
*-commutative99.4%
associate-*l*99.3%
associate--l+99.3%
distribute-lft-in99.3%
fma-define99.3%
sub-neg99.3%
+-commutative99.3%
distribute-lft-in99.3%
metadata-eval99.3%
metadata-eval99.3%
*-commutative99.3%
associate-/r*99.3%
associate-*r/99.4%
metadata-eval99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in y around 0 94.5%
sub-neg94.5%
metadata-eval94.5%
associate-*r/94.6%
metadata-eval94.6%
+-commutative94.6%
metadata-eval94.6%
distribute-neg-frac94.6%
unsub-neg94.6%
Simplified94.6%
Final simplification89.9%
(FPCore (x y) :precision binary64 (* (sqrt x) (+ (+ (* 3.0 y) (/ 0.3333333333333333 x)) -3.0)))
double code(double x, double y) {
return sqrt(x) * (((3.0 * y) + (0.3333333333333333 / x)) + -3.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(x) * (((3.0d0 * y) + (0.3333333333333333d0 / x)) + (-3.0d0))
end function
public static double code(double x, double y) {
return Math.sqrt(x) * (((3.0 * y) + (0.3333333333333333 / x)) + -3.0);
}
def code(x, y): return math.sqrt(x) * (((3.0 * y) + (0.3333333333333333 / x)) + -3.0)
function code(x, y) return Float64(sqrt(x) * Float64(Float64(Float64(3.0 * y) + Float64(0.3333333333333333 / x)) + -3.0)) end
function tmp = code(x, y) tmp = sqrt(x) * (((3.0 * y) + (0.3333333333333333 / x)) + -3.0); end
code[x_, y_] := N[(N[Sqrt[x], $MachinePrecision] * N[(N[(N[(3.0 * y), $MachinePrecision] + N[(0.3333333333333333 / x), $MachinePrecision]), $MachinePrecision] + -3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x} \cdot \left(\left(3 \cdot y + \frac{0.3333333333333333}{x}\right) + -3\right)
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-*l*99.3%
associate--l+99.3%
distribute-lft-in99.4%
fma-define99.3%
sub-neg99.3%
+-commutative99.3%
distribute-lft-in99.3%
metadata-eval99.3%
metadata-eval99.3%
*-commutative99.3%
associate-/r*99.3%
associate-*r/99.4%
metadata-eval99.4%
metadata-eval99.4%
Simplified99.4%
fma-undefine99.4%
+-commutative99.4%
associate-+r+99.4%
Applied egg-rr99.4%
(FPCore (x y) :precision binary64 (if (<= x 66.0) (sqrt (/ 0.1111111111111111 x)) (* (sqrt x) -3.0)))
double code(double x, double y) {
double tmp;
if (x <= 66.0) {
tmp = sqrt((0.1111111111111111 / x));
} else {
tmp = sqrt(x) * -3.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 66.0d0) then
tmp = sqrt((0.1111111111111111d0 / x))
else
tmp = sqrt(x) * (-3.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 66.0) {
tmp = Math.sqrt((0.1111111111111111 / x));
} else {
tmp = Math.sqrt(x) * -3.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 66.0: tmp = math.sqrt((0.1111111111111111 / x)) else: tmp = math.sqrt(x) * -3.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 66.0) tmp = sqrt(Float64(0.1111111111111111 / x)); else tmp = Float64(sqrt(x) * -3.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 66.0) tmp = sqrt((0.1111111111111111 / x)); else tmp = sqrt(x) * -3.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 66.0], N[Sqrt[N[(0.1111111111111111 / x), $MachinePrecision]], $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * -3.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 66:\\
\;\;\;\;\sqrt{\frac{0.1111111111111111}{x}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot -3\\
\end{array}
\end{array}
if x < 66Initial program 99.3%
*-commutative99.3%
associate-*l*99.2%
associate--l+99.2%
distribute-lft-in99.2%
fma-define99.2%
sub-neg99.2%
+-commutative99.2%
distribute-lft-in99.2%
metadata-eval99.2%
metadata-eval99.2%
*-commutative99.2%
associate-/r*99.2%
associate-*r/99.3%
metadata-eval99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around 0 74.1%
metadata-eval74.1%
sqrt-prod74.1%
div-inv74.2%
pow1/274.2%
Applied egg-rr74.2%
unpow1/274.2%
Simplified74.2%
if 66 < x Initial program 99.6%
*-commutative99.6%
associate-*l*99.5%
associate--l+99.5%
distribute-lft-in99.5%
fma-define99.5%
sub-neg99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
metadata-eval99.5%
*-commutative99.5%
associate-/r*99.5%
associate-*r/99.5%
metadata-eval99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around inf 97.9%
Taylor expanded in y around 0 47.5%
*-commutative47.5%
Simplified47.5%
(FPCore (x y) :precision binary64 (sqrt (/ 0.1111111111111111 x)))
double code(double x, double y) {
return sqrt((0.1111111111111111 / x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt((0.1111111111111111d0 / x))
end function
public static double code(double x, double y) {
return Math.sqrt((0.1111111111111111 / x));
}
def code(x, y): return math.sqrt((0.1111111111111111 / x))
function code(x, y) return sqrt(Float64(0.1111111111111111 / x)) end
function tmp = code(x, y) tmp = sqrt((0.1111111111111111 / x)); end
code[x_, y_] := N[Sqrt[N[(0.1111111111111111 / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{0.1111111111111111}{x}}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-*l*99.3%
associate--l+99.3%
distribute-lft-in99.4%
fma-define99.3%
sub-neg99.3%
+-commutative99.3%
distribute-lft-in99.3%
metadata-eval99.3%
metadata-eval99.3%
*-commutative99.3%
associate-/r*99.3%
associate-*r/99.4%
metadata-eval99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around 0 41.7%
metadata-eval41.7%
sqrt-prod41.8%
div-inv41.8%
pow1/241.8%
Applied egg-rr41.8%
unpow1/241.8%
Simplified41.8%
(FPCore (x y) :precision binary64 (* 3.0 (+ (* y (sqrt x)) (* (- (/ 1.0 (* x 9.0)) 1.0) (sqrt x)))))
double code(double x, double y) {
return 3.0 * ((y * sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * sqrt(x)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 3.0d0 * ((y * sqrt(x)) + (((1.0d0 / (x * 9.0d0)) - 1.0d0) * sqrt(x)))
end function
public static double code(double x, double y) {
return 3.0 * ((y * Math.sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * Math.sqrt(x)));
}
def code(x, y): return 3.0 * ((y * math.sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * math.sqrt(x)))
function code(x, y) return Float64(3.0 * Float64(Float64(y * sqrt(x)) + Float64(Float64(Float64(1.0 / Float64(x * 9.0)) - 1.0) * sqrt(x)))) end
function tmp = code(x, y) tmp = 3.0 * ((y * sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * sqrt(x))); end
code[x_, y_] := N[(3.0 * N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 / N[(x * 9.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(y \cdot \sqrt{x} + \left(\frac{1}{x \cdot 9} - 1\right) \cdot \sqrt{x}\right)
\end{array}
herbie shell --seed 2024139
(FPCore (x y)
:name "Numeric.SpecFunctions:incompleteGamma from math-functions-0.1.5.2, B"
:precision binary64
:alt
(! :herbie-platform default (* 3 (+ (* y (sqrt x)) (* (- (/ 1 (* x 9)) 1) (sqrt x)))))
(* (* 3.0 (sqrt x)) (- (+ y (/ 1.0 (* x 9.0))) 1.0)))