
(FPCore (x y) :precision binary64 (+ (+ (* x x) y) y))
double code(double x, double y) {
return ((x * x) + y) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + y) + y
end function
public static double code(double x, double y) {
return ((x * x) + y) + y;
}
def code(x, y): return ((x * x) + y) + y
function code(x, y) return Float64(Float64(Float64(x * x) + y) + y) end
function tmp = code(x, y) tmp = ((x * x) + y) + y; end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + y\right) + y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x x) y) y))
double code(double x, double y) {
return ((x * x) + y) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + y) + y
end function
public static double code(double x, double y) {
return ((x * x) + y) + y;
}
def code(x, y): return ((x * x) + y) + y
function code(x, y) return Float64(Float64(Float64(x * x) + y) + y) end
function tmp = code(x, y) tmp = ((x * x) + y) + y; end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + y\right) + y
\end{array}
(FPCore (x y) :precision binary64 (fma x x (+ y y)))
double code(double x, double y) {
return fma(x, x, (y + y));
}
function code(x, y) return fma(x, x, Float64(y + y)) end
code[x_, y_] := N[(x * x + N[(y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, y + y\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 3.7e-31)
(and (not (<= (* x x) 7e+84)) (<= (* x x) 1.9e+130)))
(+ y y)
(* x x)))
double code(double x, double y) {
double tmp;
if (((x * x) <= 3.7e-31) || (!((x * x) <= 7e+84) && ((x * x) <= 1.9e+130))) {
tmp = y + y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((x * x) <= 3.7d-31) .or. (.not. ((x * x) <= 7d+84)) .and. ((x * x) <= 1.9d+130)) then
tmp = y + y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x * x) <= 3.7e-31) || (!((x * x) <= 7e+84) && ((x * x) <= 1.9e+130))) {
tmp = y + y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 3.7e-31) or (not ((x * x) <= 7e+84) and ((x * x) <= 1.9e+130)): tmp = y + y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 3.7e-31) || (!(Float64(x * x) <= 7e+84) && (Float64(x * x) <= 1.9e+130))) tmp = Float64(y + y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * x) <= 3.7e-31) || (~(((x * x) <= 7e+84)) && ((x * x) <= 1.9e+130))) tmp = y + y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 3.7e-31], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 7e+84]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 1.9e+130]]], N[(y + y), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3.7 \cdot 10^{-31} \lor \neg \left(x \cdot x \leq 7 \cdot 10^{+84}\right) \land x \cdot x \leq 1.9 \cdot 10^{+130}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.6999999999999998e-31 or 6.9999999999999998e84 < (*.f64 x x) < 1.9000000000000001e130Initial program 100.0%
Taylor expanded in x around 0 90.5%
if 3.6999999999999998e-31 < (*.f64 x x) < 6.9999999999999998e84 or 1.9000000000000001e130 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf 91.0%
unpow291.0%
Simplified91.0%
Taylor expanded in x around inf 89.4%
unpow291.0%
Simplified89.4%
Final simplification90.0%
(FPCore (x y) :precision binary64 (if (<= (* x x) 2.45e-36) (+ y y) (+ y (* x x))))
double code(double x, double y) {
double tmp;
if ((x * x) <= 2.45e-36) {
tmp = y + y;
} else {
tmp = y + (x * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 2.45d-36) then
tmp = y + y
else
tmp = y + (x * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 2.45e-36) {
tmp = y + y;
} else {
tmp = y + (x * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 2.45e-36: tmp = y + y else: tmp = y + (x * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 2.45e-36) tmp = Float64(y + y); else tmp = Float64(y + Float64(x * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 2.45e-36) tmp = y + y; else tmp = y + (x * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.45e-36], N[(y + y), $MachinePrecision], N[(y + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.45 \cdot 10^{-36}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.4499999999999998e-36Initial program 100.0%
Taylor expanded in x around 0 90.9%
if 2.4499999999999998e-36 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf 87.6%
unpow287.6%
Simplified87.6%
Final simplification89.3%
(FPCore (x y) :precision binary64 (if (<= (* x x) 6.8e-178) y (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 6.8e-178) {
tmp = y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 6.8d-178) then
tmp = y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 6.8e-178) {
tmp = y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 6.8e-178: tmp = y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 6.8e-178) tmp = y; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 6.8e-178) tmp = y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 6.8e-178], y, N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 6.8 \cdot 10^{-178}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 6.79999999999999945e-178Initial program 100.0%
Taylor expanded in x around inf 20.1%
unpow220.1%
Simplified20.1%
Taylor expanded in x around 0 18.5%
if 6.79999999999999945e-178 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf 77.4%
unpow277.4%
Simplified77.4%
Taylor expanded in x around inf 73.3%
unpow277.4%
Simplified73.3%
Final simplification52.5%
(FPCore (x y) :precision binary64 (+ y (+ y (* x x))))
double code(double x, double y) {
return y + (y + (x * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (y + (x * x))
end function
public static double code(double x, double y) {
return y + (y + (x * x));
}
def code(x, y): return y + (y + (x * x))
function code(x, y) return Float64(y + Float64(y + Float64(x * x))) end
function tmp = code(x, y) tmp = y + (y + (x * x)); end
code[x_, y_] := N[(y + N[(y + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(y + x \cdot x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 55.7%
unpow255.7%
Simplified55.7%
Taylor expanded in x around 0 11.4%
Final simplification11.4%
(FPCore (x y) :precision binary64 (+ (+ y y) (* x x)))
double code(double x, double y) {
return (y + y) + (x * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + y) + (x * x)
end function
public static double code(double x, double y) {
return (y + y) + (x * x);
}
def code(x, y): return (y + y) + (x * x)
function code(x, y) return Float64(Float64(y + y) + Float64(x * x)) end
function tmp = code(x, y) tmp = (y + y) + (x * x); end
code[x_, y_] := N[(N[(y + y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + y\right) + x \cdot x
\end{array}
herbie shell --seed 2023185
(FPCore (x y)
:name "Data.Random.Distribution.Normal:normalTail from random-fu-0.2.6.2"
:precision binary64
:herbie-target
(+ (+ y y) (* x x))
(+ (+ (* x x) y) y))