
(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 6 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 (if (or (<= y -360000000000.0) (not (<= y 0.5))) (+ z (* x y)) (+ z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -360000000000.0) || !(y <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z + (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 ((y <= (-360000000000.0d0)) .or. (.not. (y <= 0.5d0))) then
tmp = z + (x * y)
else
tmp = z + (x * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -360000000000.0) || !(y <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z + (x * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -360000000000.0) or not (y <= 0.5): tmp = z + (x * y) else: tmp = z + (x * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -360000000000.0) || !(y <= 0.5)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -360000000000.0) || ~((y <= 0.5))) tmp = z + (x * y); else tmp = z + (x * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -360000000000.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -360000000000 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 0.5\\
\end{array}
\end{array}
if y < -3.6e11 or 0.5 < y Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 99.4%
if -3.6e11 < y < 0.5Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 98.3%
*-commutative98.3%
Simplified98.3%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= y -2.4e+83) (* x y) (if (<= y 2.9e+37) (+ z (* x 0.5)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e+83) {
tmp = x * y;
} else if (y <= 2.9e+37) {
tmp = z + (x * 0.5);
} 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 (y <= (-2.4d+83)) then
tmp = x * y
else if (y <= 2.9d+37) then
tmp = z + (x * 0.5d0)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e+83) {
tmp = x * y;
} else if (y <= 2.9e+37) {
tmp = z + (x * 0.5);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.4e+83: tmp = x * y elif y <= 2.9e+37: tmp = z + (x * 0.5) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.4e+83) tmp = Float64(x * y); elseif (y <= 2.9e+37) tmp = Float64(z + Float64(x * 0.5)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.4e+83) tmp = x * y; elseif (y <= 2.9e+37) tmp = z + (x * 0.5); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.4e+83], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.9e+37], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+83}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+37}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.39999999999999991e83 or 2.89999999999999978e37 < y Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
distribute-lft-in100.0%
flip-+49.1%
pow249.1%
Applied egg-rr49.1%
unpow249.1%
difference-of-squares49.4%
+-commutative49.4%
distribute-lft-in49.4%
distribute-lft-out--49.4%
sub-neg49.4%
metadata-eval49.4%
distribute-lft-out--49.4%
sub-neg49.4%
metadata-eval49.4%
Simplified49.4%
Taylor expanded in y around inf 26.4%
unpow226.4%
unpow226.4%
swap-sqr49.4%
Simplified49.4%
frac-2neg49.4%
div-inv49.3%
fma-def49.3%
pow249.3%
distribute-rgt-neg-in49.3%
Applied egg-rr49.3%
fma-udef49.3%
+-commutative49.3%
distribute-lft-neg-out49.3%
associate-*r/49.4%
*-rgt-identity49.4%
unsub-neg49.4%
associate-/r*69.4%
unpow269.4%
swap-sqr49.5%
associate-*l/51.6%
associate-/l*56.8%
*-inverses56.8%
/-rgt-identity56.8%
neg-sub056.8%
+-commutative56.8%
associate--r+56.8%
metadata-eval56.8%
Simplified56.8%
Taylor expanded in y around inf 72.4%
if -2.39999999999999991e83 < y < 2.89999999999999978e37Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 92.9%
*-commutative92.9%
Simplified92.9%
Final simplification85.3%
(FPCore (x y z) :precision binary64 (if (<= y -3.3e+83) (* x y) (if (<= y 6.2e+36) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.3e+83) {
tmp = x * y;
} else if (y <= 6.2e+36) {
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 (y <= (-3.3d+83)) then
tmp = x * y
else if (y <= 6.2d+36) 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 (y <= -3.3e+83) {
tmp = x * y;
} else if (y <= 6.2e+36) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.3e+83: tmp = x * y elif y <= 6.2e+36: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.3e+83) tmp = Float64(x * y); elseif (y <= 6.2e+36) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.3e+83) tmp = x * y; elseif (y <= 6.2e+36) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.3e+83], N[(x * y), $MachinePrecision], If[LessEqual[y, 6.2e+36], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+83}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+36}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3.29999999999999985e83 or 6.1999999999999999e36 < y Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
distribute-lft-in100.0%
flip-+49.1%
pow249.1%
Applied egg-rr49.1%
unpow249.1%
difference-of-squares49.4%
+-commutative49.4%
distribute-lft-in49.4%
distribute-lft-out--49.4%
sub-neg49.4%
metadata-eval49.4%
distribute-lft-out--49.4%
sub-neg49.4%
metadata-eval49.4%
Simplified49.4%
Taylor expanded in y around inf 26.4%
unpow226.4%
unpow226.4%
swap-sqr49.4%
Simplified49.4%
frac-2neg49.4%
div-inv49.3%
fma-def49.3%
pow249.3%
distribute-rgt-neg-in49.3%
Applied egg-rr49.3%
fma-udef49.3%
+-commutative49.3%
distribute-lft-neg-out49.3%
associate-*r/49.4%
*-rgt-identity49.4%
unsub-neg49.4%
associate-/r*69.4%
unpow269.4%
swap-sqr49.5%
associate-*l/51.6%
associate-/l*56.8%
*-inverses56.8%
/-rgt-identity56.8%
neg-sub056.8%
+-commutative56.8%
associate--r+56.8%
metadata-eval56.8%
Simplified56.8%
Taylor expanded in y around inf 72.4%
if -3.29999999999999985e83 < y < 6.1999999999999999e36Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 57.3%
Final simplification62.9%
(FPCore (x y z) :precision binary64 (+ z (* x (+ y 0.5))))
double code(double x, double y, double z) {
return z + (x * (y + 0.5));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * (y + 0.5d0))
end function
public static double code(double x, double y, double z) {
return z + (x * (y + 0.5));
}
def code(x, y, z): return z + (x * (y + 0.5))
function code(x, y, z) return Float64(z + Float64(x * Float64(y + 0.5))) end
function tmp = code(x, y, z) tmp = z + (x * (y + 0.5)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y + 0.5\right)
\end{array}
Initial program 100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(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%
remove-double-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-lft-neg-in100.0%
distribute-rgt-out100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 47.0%
Final simplification47.0%
herbie shell --seed 2023287
(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))