
(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 7 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 (+ (+ (/ x 2.0) (* x y)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (x * y)) + 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) + (x * y)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (x * y)) + z;
}
def code(x, y, z): return ((x / 2.0) + (x * y)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(x * y)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (x * y)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + x \cdot y\right) + z
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* x y)))) (if (<= y -0.5) t_0 (if (<= y 0.5) (+ z (* x 0.5)) t_0))))
double code(double x, double y, double z) {
double t_0 = z + (x * y);
double tmp;
if (y <= -0.5) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = z + (x * y)
if (y <= (-0.5d0)) then
tmp = t_0
else if (y <= 0.5d0) then
tmp = z + (x * 0.5d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z + (x * y);
double tmp;
if (y <= -0.5) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z + (x * y) tmp = 0 if y <= -0.5: tmp = t_0 elif y <= 0.5: tmp = z + (x * 0.5) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z + Float64(x * y)) tmp = 0.0 if (y <= -0.5) tmp = t_0; elseif (y <= 0.5) tmp = Float64(z + Float64(x * 0.5)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z + (x * y); tmp = 0.0; if (y <= -0.5) tmp = t_0; elseif (y <= 0.5) tmp = z + (x * 0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.5], t$95$0, If[LessEqual[y, 0.5], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z + x \cdot y\\
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.5 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64100.0%
Simplified100.0%
if -0.5 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6498.8%
Simplified98.8%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y 0.5)))) (if (<= x -8.5e+20) t_0 (if (<= x 1.3e-68) (+ z (* x 0.5)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + 0.5);
double tmp;
if (x <= -8.5e+20) {
tmp = t_0;
} else if (x <= 1.3e-68) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = x * (y + 0.5d0)
if (x <= (-8.5d+20)) then
tmp = t_0
else if (x <= 1.3d-68) then
tmp = z + (x * 0.5d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + 0.5);
double tmp;
if (x <= -8.5e+20) {
tmp = t_0;
} else if (x <= 1.3e-68) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + 0.5) tmp = 0 if x <= -8.5e+20: tmp = t_0 elif x <= 1.3e-68: tmp = z + (x * 0.5) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + 0.5)) tmp = 0.0 if (x <= -8.5e+20) tmp = t_0; elseif (x <= 1.3e-68) tmp = Float64(z + Float64(x * 0.5)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + 0.5); tmp = 0.0; if (x <= -8.5e+20) tmp = t_0; elseif (x <= 1.3e-68) tmp = z + (x * 0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.5e+20], t$95$0, If[LessEqual[x, 1.3e-68], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + 0.5\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-68}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.5e20 or 1.2999999999999999e-68 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6488.3%
Simplified88.3%
if -8.5e20 < x < 1.2999999999999999e-68Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6482.1%
Simplified82.1%
Final simplification85.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y 0.5)))) (if (<= x -3.8e-87) t_0 (if (<= x 4.6e-69) z t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + 0.5);
double tmp;
if (x <= -3.8e-87) {
tmp = t_0;
} else if (x <= 4.6e-69) {
tmp = z;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = x * (y + 0.5d0)
if (x <= (-3.8d-87)) then
tmp = t_0
else if (x <= 4.6d-69) then
tmp = z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + 0.5);
double tmp;
if (x <= -3.8e-87) {
tmp = t_0;
} else if (x <= 4.6e-69) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + 0.5) tmp = 0 if x <= -3.8e-87: tmp = t_0 elif x <= 4.6e-69: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + 0.5)) tmp = 0.0 if (x <= -3.8e-87) tmp = t_0; elseif (x <= 4.6e-69) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + 0.5); tmp = 0.0; if (x <= -3.8e-87) tmp = t_0; elseif (x <= 4.6e-69) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.8e-87], t$95$0, If[LessEqual[x, 4.6e-69], z, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + 0.5\right)\\
\mathbf{if}\;x \leq -3.8 \cdot 10^{-87}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{-69}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.8e-87 or 4.6000000000000001e-69 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6484.3%
Simplified84.3%
if -3.8e-87 < x < 4.6000000000000001e-69Initial program 100.0%
Taylor expanded in x around 0
Simplified78.2%
Final simplification81.9%
(FPCore (x y z) :precision binary64 (if (<= x -65000000000000.0) (* x y) (if (<= x 7.6e-60) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -65000000000000.0) {
tmp = x * y;
} else if (x <= 7.6e-60) {
tmp = z;
} else {
tmp = x * y;
}
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 (x <= (-65000000000000.0d0)) then
tmp = x * y
else if (x <= 7.6d-60) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -65000000000000.0) {
tmp = x * y;
} else if (x <= 7.6e-60) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -65000000000000.0: tmp = x * y elif x <= 7.6e-60: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -65000000000000.0) tmp = Float64(x * y); elseif (x <= 7.6e-60) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -65000000000000.0) tmp = x * y; elseif (x <= 7.6e-60) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -65000000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.6e-60], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -65000000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-60}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -6.5e13 or 7.59999999999999989e-60 < x Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6456.7%
Simplified56.7%
if -6.5e13 < x < 7.59999999999999989e-60Initial program 100.0%
Taylor expanded in x around 0
Simplified71.8%
(FPCore (x y z) :precision binary64 (if (<= x -4.75e+24) (* x 0.5) (if (<= x 6e+42) z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.75e+24) {
tmp = x * 0.5;
} else if (x <= 6e+42) {
tmp = z;
} else {
tmp = x * 0.5;
}
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 (x <= (-4.75d+24)) then
tmp = x * 0.5d0
else if (x <= 6d+42) then
tmp = z
else
tmp = x * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.75e+24) {
tmp = x * 0.5;
} else if (x <= 6e+42) {
tmp = z;
} else {
tmp = x * 0.5;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.75e+24: tmp = x * 0.5 elif x <= 6e+42: tmp = z else: tmp = x * 0.5 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.75e+24) tmp = Float64(x * 0.5); elseif (x <= 6e+42) tmp = z; else tmp = Float64(x * 0.5); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.75e+24) tmp = x * 0.5; elseif (x <= 6e+42) tmp = z; else tmp = x * 0.5; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.75e+24], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 6e+42], z, N[(x * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.75 \cdot 10^{+24}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 6 \cdot 10^{+42}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5\\
\end{array}
\end{array}
if x < -4.7500000000000001e24 or 6.00000000000000058e42 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6489.3%
Simplified89.3%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6437.6%
Simplified37.6%
if -4.7500000000000001e24 < x < 6.00000000000000058e42Initial program 100.0%
Taylor expanded in x around 0
Simplified67.4%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Simplified41.7%
herbie shell --seed 2024191
(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))