
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ 0.5 y) x z))
double code(double x, double y, double z) {
return fma((0.5 + y), x, z);
}
function code(x, y, z) return fma(Float64(0.5 + y), x, z) end
code[x_, y_, z_] := N[(N[(0.5 + y), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + y, x, z\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (/ x 2.0) (* y x))))
(if (or (<= t_0 -1e+25) (not (<= t_0 5e+159)))
(* (- y -0.5) x)
(fma 0.5 x z))))
double code(double x, double y, double z) {
double t_0 = (x / 2.0) + (y * x);
double tmp;
if ((t_0 <= -1e+25) || !(t_0 <= 5e+159)) {
tmp = (y - -0.5) * x;
} else {
tmp = fma(0.5, x, z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x / 2.0) + Float64(y * x)) tmp = 0.0 if ((t_0 <= -1e+25) || !(t_0 <= 5e+159)) tmp = Float64(Float64(y - -0.5) * x); else tmp = fma(0.5, x, z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e+25], N[Not[LessEqual[t$95$0, 5e+159]], $MachinePrecision]], N[(N[(y - -0.5), $MachinePrecision] * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+25} \lor \neg \left(t\_0 \leq 5 \cdot 10^{+159}\right):\\
\;\;\;\;\left(y - -0.5\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1.00000000000000009e25 or 5.00000000000000003e159 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6443.4
Applied rewrites43.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
rgt-mult-inverseN/A
associate-*r*N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6488.5
Applied rewrites88.5%
if -1.00000000000000009e25 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 5.00000000000000003e159Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6488.4
Applied rewrites88.4%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e+79) (not (<= y 2.25e+47))) (* y x) (fma 0.5 x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+79) || !(y <= 2.25e+47)) {
tmp = y * x;
} else {
tmp = fma(0.5, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e+79) || !(y <= 2.25e+47)) tmp = Float64(y * x); else tmp = fma(0.5, x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e+79], N[Not[LessEqual[y, 2.25e+47]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+79} \lor \neg \left(y \leq 2.25 \cdot 10^{+47}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\end{array}
\end{array}
if y < -3.8000000000000002e79 or 2.2499999999999999e47 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6427.6
Applied rewrites27.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6474.8
Applied rewrites74.8%
if -3.8000000000000002e79 < y < 2.2499999999999999e47Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6491.1
Applied rewrites91.1%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -28.0) (not (<= y 0.5))) (* y x) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -28.0) || !(y <= 0.5)) {
tmp = y * x;
} else {
tmp = 0.5 * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-28.0d0)) .or. (.not. (y <= 0.5d0))) then
tmp = y * x
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -28.0) || !(y <= 0.5)) {
tmp = y * x;
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -28.0) or not (y <= 0.5): tmp = y * x else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -28.0) || !(y <= 0.5)) tmp = Float64(y * x); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -28.0) || ~((y <= 0.5))) tmp = y * x; else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -28.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -28 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -28 or 0.5 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6435.2
Applied rewrites35.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6466.3
Applied rewrites66.3%
if -28 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around inf
Applied rewrites45.7%
Final simplification55.3%
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
return 0.5 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
return 0.5 * x;
}
def code(x, y, z): return 0.5 * x
function code(x, y, z) return Float64(0.5 * x) end
function tmp = code(x, y, z) tmp = 0.5 * x; end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6469.2
Applied rewrites69.2%
Taylor expanded in x around inf
Applied rewrites25.8%
herbie shell --seed 2024338
(FPCore (x y z)
:name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
:precision binary64
(+ (+ (/ x 2.0) (* y x)) z))