
(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.2e-127)
(and (not (<= (* x x) 1.5e-91))
(or (<= (* x x) 1e-62)
(and (not (<= (* x x) 63000000.0)) (<= (* x x) 2.6e+83)))))
(+ y y)
(* x x)))
double code(double x, double y) {
double tmp;
if (((x * x) <= 3.2e-127) || (!((x * x) <= 1.5e-91) && (((x * x) <= 1e-62) || (!((x * x) <= 63000000.0) && ((x * x) <= 2.6e+83))))) {
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.2d-127) .or. (.not. ((x * x) <= 1.5d-91)) .and. ((x * x) <= 1d-62) .or. (.not. ((x * x) <= 63000000.0d0)) .and. ((x * x) <= 2.6d+83)) 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.2e-127) || (!((x * x) <= 1.5e-91) && (((x * x) <= 1e-62) || (!((x * x) <= 63000000.0) && ((x * x) <= 2.6e+83))))) {
tmp = y + y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 3.2e-127) or (not ((x * x) <= 1.5e-91) and (((x * x) <= 1e-62) or (not ((x * x) <= 63000000.0) and ((x * x) <= 2.6e+83)))): tmp = y + y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 3.2e-127) || (!(Float64(x * x) <= 1.5e-91) && ((Float64(x * x) <= 1e-62) || (!(Float64(x * x) <= 63000000.0) && (Float64(x * x) <= 2.6e+83))))) 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.2e-127) || (~(((x * x) <= 1.5e-91)) && (((x * x) <= 1e-62) || (~(((x * x) <= 63000000.0)) && ((x * x) <= 2.6e+83))))) tmp = y + y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 3.2e-127], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 1.5e-91]], $MachinePrecision], Or[LessEqual[N[(x * x), $MachinePrecision], 1e-62], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 63000000.0]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 2.6e+83]]]]], N[(y + y), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3.2 \cdot 10^{-127} \lor \neg \left(x \cdot x \leq 1.5 \cdot 10^{-91}\right) \land \left(x \cdot x \leq 10^{-62} \lor \neg \left(x \cdot x \leq 63000000\right) \land x \cdot x \leq 2.6 \cdot 10^{+83}\right):\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.20000000000000017e-127 or 1.5000000000000001e-91 < (*.f64 x x) < 1e-62 or 6.3e7 < (*.f64 x x) < 2.6000000000000001e83Initial program 100.0%
Taylor expanded in x around 0 92.1%
if 3.20000000000000017e-127 < (*.f64 x x) < 1.5000000000000001e-91 or 1e-62 < (*.f64 x x) < 6.3e7 or 2.6000000000000001e83 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf 92.6%
unpow292.6%
Simplified92.6%
Taylor expanded in x around inf 91.3%
unpow292.6%
Simplified91.3%
Final simplification91.7%
(FPCore (x y)
:precision binary64
(if (<= (* x x) 2.65e-135)
(+ y y)
(if (<= (* x x) 1.06e-91)
(* x x)
(if (<= (* x x) 4.8e-62) (+ y y) (+ y (* x x))))))
double code(double x, double y) {
double tmp;
if ((x * x) <= 2.65e-135) {
tmp = y + y;
} else if ((x * x) <= 1.06e-91) {
tmp = x * x;
} else if ((x * x) <= 4.8e-62) {
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.65d-135) then
tmp = y + y
else if ((x * x) <= 1.06d-91) then
tmp = x * x
else if ((x * x) <= 4.8d-62) 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.65e-135) {
tmp = y + y;
} else if ((x * x) <= 1.06e-91) {
tmp = x * x;
} else if ((x * x) <= 4.8e-62) {
tmp = y + y;
} else {
tmp = y + (x * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 2.65e-135: tmp = y + y elif (x * x) <= 1.06e-91: tmp = x * x elif (x * x) <= 4.8e-62: tmp = y + y else: tmp = y + (x * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 2.65e-135) tmp = Float64(y + y); elseif (Float64(x * x) <= 1.06e-91) tmp = Float64(x * x); elseif (Float64(x * x) <= 4.8e-62) 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.65e-135) tmp = y + y; elseif ((x * x) <= 1.06e-91) tmp = x * x; elseif ((x * x) <= 4.8e-62) tmp = y + y; else tmp = y + (x * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.65e-135], N[(y + y), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1.06e-91], N[(x * x), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4.8e-62], N[(y + y), $MachinePrecision], N[(y + N[(x * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.65 \cdot 10^{-135}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;x \cdot x \leq 1.06 \cdot 10^{-91}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \cdot x \leq 4.8 \cdot 10^{-62}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.65e-135 or 1.06000000000000006e-91 < (*.f64 x x) < 4.79999999999999967e-62Initial program 100.0%
Taylor expanded in x around 0 94.2%
if 2.65e-135 < (*.f64 x x) < 1.06000000000000006e-91Initial program 100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
if 4.79999999999999967e-62 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf 87.7%
unpow287.7%
Simplified87.7%
Final simplification90.8%
(FPCore (x y) :precision binary64 (if (<= (* x x) 3e-244) y (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 3e-244) {
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) <= 3d-244) 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) <= 3e-244) {
tmp = y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 3e-244: tmp = y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 3e-244) tmp = y; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 3e-244) tmp = y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 3e-244], y, N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3 \cdot 10^{-244}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.0000000000000001e-244Initial program 100.0%
Taylor expanded in x around inf 18.8%
unpow218.8%
Simplified18.8%
Taylor expanded in x around 0 18.8%
if 3.0000000000000001e-244 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf 78.8%
unpow278.8%
Simplified78.8%
Taylor expanded in x around inf 75.1%
unpow278.8%
Simplified75.1%
Final simplification57.9%
(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 60.5%
unpow260.5%
Simplified60.5%
Taylor expanded in x around 0 10.6%
Final simplification10.6%
(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 2023271
(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))