
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z): return (x * (y + z)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (y + z)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z): return (x * (y + z)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (y + z)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}
(FPCore (x y z) :precision binary64 (fma z 5.0 (* x (+ z y))))
double code(double x, double y, double z) {
return fma(z, 5.0, (x * (z + y)));
}
function code(x, y, z) return fma(z, 5.0, Float64(x * Float64(z + y))) end
code[x_, y_, z_] := N[(z * 5.0 + N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, 5, x \cdot \left(z + y\right)\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -3.9e+58)
(* z x)
(if (<= x -4.4e-25)
(* x y)
(if (<= x 1.1e-65)
(* z 5.0)
(if (<= x 2.3e-35)
(* x y)
(if (<= x 1.7e-9)
(* z 5.0)
(if (<= x 3e+71)
(* x y)
(if (or (<= x 3.5e+182)
(and (not (<= x 2.3e+206)) (<= x 2.25e+291)))
(* z x)
(* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.9e+58) {
tmp = z * x;
} else if (x <= -4.4e-25) {
tmp = x * y;
} else if (x <= 1.1e-65) {
tmp = z * 5.0;
} else if (x <= 2.3e-35) {
tmp = x * y;
} else if (x <= 1.7e-9) {
tmp = z * 5.0;
} else if (x <= 3e+71) {
tmp = x * y;
} else if ((x <= 3.5e+182) || (!(x <= 2.3e+206) && (x <= 2.25e+291))) {
tmp = z * x;
} 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 <= (-3.9d+58)) then
tmp = z * x
else if (x <= (-4.4d-25)) then
tmp = x * y
else if (x <= 1.1d-65) then
tmp = z * 5.0d0
else if (x <= 2.3d-35) then
tmp = x * y
else if (x <= 1.7d-9) then
tmp = z * 5.0d0
else if (x <= 3d+71) then
tmp = x * y
else if ((x <= 3.5d+182) .or. (.not. (x <= 2.3d+206)) .and. (x <= 2.25d+291)) then
tmp = z * x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.9e+58) {
tmp = z * x;
} else if (x <= -4.4e-25) {
tmp = x * y;
} else if (x <= 1.1e-65) {
tmp = z * 5.0;
} else if (x <= 2.3e-35) {
tmp = x * y;
} else if (x <= 1.7e-9) {
tmp = z * 5.0;
} else if (x <= 3e+71) {
tmp = x * y;
} else if ((x <= 3.5e+182) || (!(x <= 2.3e+206) && (x <= 2.25e+291))) {
tmp = z * x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.9e+58: tmp = z * x elif x <= -4.4e-25: tmp = x * y elif x <= 1.1e-65: tmp = z * 5.0 elif x <= 2.3e-35: tmp = x * y elif x <= 1.7e-9: tmp = z * 5.0 elif x <= 3e+71: tmp = x * y elif (x <= 3.5e+182) or (not (x <= 2.3e+206) and (x <= 2.25e+291)): tmp = z * x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.9e+58) tmp = Float64(z * x); elseif (x <= -4.4e-25) tmp = Float64(x * y); elseif (x <= 1.1e-65) tmp = Float64(z * 5.0); elseif (x <= 2.3e-35) tmp = Float64(x * y); elseif (x <= 1.7e-9) tmp = Float64(z * 5.0); elseif (x <= 3e+71) tmp = Float64(x * y); elseif ((x <= 3.5e+182) || (!(x <= 2.3e+206) && (x <= 2.25e+291))) tmp = Float64(z * x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.9e+58) tmp = z * x; elseif (x <= -4.4e-25) tmp = x * y; elseif (x <= 1.1e-65) tmp = z * 5.0; elseif (x <= 2.3e-35) tmp = x * y; elseif (x <= 1.7e-9) tmp = z * 5.0; elseif (x <= 3e+71) tmp = x * y; elseif ((x <= 3.5e+182) || (~((x <= 2.3e+206)) && (x <= 2.25e+291))) tmp = z * x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.9e+58], N[(z * x), $MachinePrecision], If[LessEqual[x, -4.4e-25], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.1e-65], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 2.3e-35], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.7e-9], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 3e+71], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 3.5e+182], And[N[Not[LessEqual[x, 2.3e+206]], $MachinePrecision], LessEqual[x, 2.25e+291]]], N[(z * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+58}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -4.4 \cdot 10^{-25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{-65}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-35}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-9}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+71}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+182} \lor \neg \left(x \leq 2.3 \cdot 10^{+206}\right) \land x \leq 2.25 \cdot 10^{+291}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.9000000000000001e58 or 3.00000000000000013e71 < x < 3.50000000000000023e182 or 2.30000000000000016e206 < x < 2.24999999999999997e291Initial program 100.0%
Taylor expanded in y around 0 69.6%
+-commutative69.6%
*-commutative69.6%
distribute-rgt-in69.6%
Simplified69.6%
Taylor expanded in x around inf 69.6%
if -3.9000000000000001e58 < x < -4.4000000000000004e-25 or 1.10000000000000011e-65 < x < 2.2999999999999999e-35 or 1.6999999999999999e-9 < x < 3.00000000000000013e71 or 3.50000000000000023e182 < x < 2.30000000000000016e206 or 2.24999999999999997e291 < x Initial program 100.0%
Taylor expanded in y around inf 76.5%
if -4.4000000000000004e-25 < x < 1.10000000000000011e-65 or 2.2999999999999999e-35 < x < 1.6999999999999999e-9Initial program 99.8%
Taylor expanded in x around 0 78.2%
Final simplification75.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))))
(if (<= x -1.25e-24)
t_0
(if (<= x 3.4e-61)
(* z 5.0)
(if (<= x 1.8e-36) (* x y) (if (<= x 1.45e-10) (* z 5.0) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -1.25e-24) {
tmp = t_0;
} else if (x <= 3.4e-61) {
tmp = z * 5.0;
} else if (x <= 1.8e-36) {
tmp = x * y;
} else if (x <= 1.45e-10) {
tmp = z * 5.0;
} 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 * (z + y)
if (x <= (-1.25d-24)) then
tmp = t_0
else if (x <= 3.4d-61) then
tmp = z * 5.0d0
else if (x <= 1.8d-36) then
tmp = x * y
else if (x <= 1.45d-10) then
tmp = z * 5.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -1.25e-24) {
tmp = t_0;
} else if (x <= 3.4e-61) {
tmp = z * 5.0;
} else if (x <= 1.8e-36) {
tmp = x * y;
} else if (x <= 1.45e-10) {
tmp = z * 5.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) tmp = 0 if x <= -1.25e-24: tmp = t_0 elif x <= 3.4e-61: tmp = z * 5.0 elif x <= 1.8e-36: tmp = x * y elif x <= 1.45e-10: tmp = z * 5.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + y)) tmp = 0.0 if (x <= -1.25e-24) tmp = t_0; elseif (x <= 3.4e-61) tmp = Float64(z * 5.0); elseif (x <= 1.8e-36) tmp = Float64(x * y); elseif (x <= 1.45e-10) tmp = Float64(z * 5.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + y); tmp = 0.0; if (x <= -1.25e-24) tmp = t_0; elseif (x <= 3.4e-61) tmp = z * 5.0; elseif (x <= 1.8e-36) tmp = x * y; elseif (x <= 1.45e-10) tmp = z * 5.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.25e-24], t$95$0, If[LessEqual[x, 3.4e-61], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 1.8e-36], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.45e-10], N[(z * 5.0), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -1.25 \cdot 10^{-24}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{-61}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-36}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-10}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.24999999999999995e-24 or 1.4499999999999999e-10 < x Initial program 100.0%
Taylor expanded in x around inf 98.9%
+-commutative98.9%
Simplified98.9%
if -1.24999999999999995e-24 < x < 3.3999999999999998e-61 or 1.80000000000000016e-36 < x < 1.4499999999999999e-10Initial program 99.8%
Taylor expanded in x around 0 78.2%
if 3.3999999999999998e-61 < x < 1.80000000000000016e-36Initial program 99.7%
Taylor expanded in y around inf 85.4%
Final simplification88.8%
(FPCore (x y z)
:precision binary64
(if (<= x -3.1e-25)
(* x y)
(if (or (<= x 6e-61) (and (not (<= x 1.8e-36)) (<= x 8e-7)))
(* z 5.0)
(* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.1e-25) {
tmp = x * y;
} else if ((x <= 6e-61) || (!(x <= 1.8e-36) && (x <= 8e-7))) {
tmp = z * 5.0;
} 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 <= (-3.1d-25)) then
tmp = x * y
else if ((x <= 6d-61) .or. (.not. (x <= 1.8d-36)) .and. (x <= 8d-7)) then
tmp = z * 5.0d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.1e-25) {
tmp = x * y;
} else if ((x <= 6e-61) || (!(x <= 1.8e-36) && (x <= 8e-7))) {
tmp = z * 5.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.1e-25: tmp = x * y elif (x <= 6e-61) or (not (x <= 1.8e-36) and (x <= 8e-7)): tmp = z * 5.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.1e-25) tmp = Float64(x * y); elseif ((x <= 6e-61) || (!(x <= 1.8e-36) && (x <= 8e-7))) tmp = Float64(z * 5.0); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.1e-25) tmp = x * y; elseif ((x <= 6e-61) || (~((x <= 1.8e-36)) && (x <= 8e-7))) tmp = z * 5.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.1e-25], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 6e-61], And[N[Not[LessEqual[x, 1.8e-36]], $MachinePrecision], LessEqual[x, 8e-7]]], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-61} \lor \neg \left(x \leq 1.8 \cdot 10^{-36}\right) \land x \leq 8 \cdot 10^{-7}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.09999999999999995e-25 or 6.00000000000000024e-61 < x < 1.80000000000000016e-36 or 7.9999999999999996e-7 < x Initial program 100.0%
Taylor expanded in y around inf 51.3%
if -3.09999999999999995e-25 < x < 6.00000000000000024e-61 or 1.80000000000000016e-36 < x < 7.9999999999999996e-7Initial program 99.8%
Taylor expanded in x around 0 78.2%
Final simplification64.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e-183) (not (<= z 4.7e+54))) (* z (+ 5.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-183) || !(z <= 4.7e+54)) {
tmp = z * (5.0 + x);
} 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 ((z <= (-3.1d-183)) .or. (.not. (z <= 4.7d+54))) then
tmp = z * (5.0d0 + x)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-183) || !(z <= 4.7e+54)) {
tmp = z * (5.0 + x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e-183) or not (z <= 4.7e+54): tmp = z * (5.0 + x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e-183) || !(z <= 4.7e+54)) tmp = Float64(z * Float64(5.0 + x)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e-183) || ~((z <= 4.7e+54))) tmp = z * (5.0 + x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e-183], N[Not[LessEqual[z, 4.7e+54]], $MachinePrecision]], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-183} \lor \neg \left(z \leq 4.7 \cdot 10^{+54}\right):\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -3.1e-183 or 4.69999999999999993e54 < z Initial program 99.8%
Taylor expanded in y around 0 85.8%
+-commutative85.8%
*-commutative85.8%
distribute-rgt-in85.8%
Simplified85.8%
if -3.1e-183 < z < 4.69999999999999993e54Initial program 99.9%
Taylor expanded in y around inf 71.2%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (+ (* x (+ z y)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (z + y)) + (z * 5.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (z + y)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) + (z * 5.0);
}
def code(x, y, z): return (x * (z + y)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (z + y)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) + z \cdot 5
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (* z 5.0))
double code(double x, double y, double z) {
return z * 5.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * 5.0d0
end function
public static double code(double x, double y, double z) {
return z * 5.0;
}
def code(x, y, z): return z * 5.0
function code(x, y, z) return Float64(z * 5.0) end
function tmp = code(x, y, z) tmp = z * 5.0; end
code[x_, y_, z_] := N[(z * 5.0), $MachinePrecision]
\begin{array}{l}
\\
z \cdot 5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 38.9%
Final simplification38.9%
(FPCore (x y z) :precision binary64 (+ (* (+ x 5.0) z) (* x y)))
double code(double x, double y, double z) {
return ((x + 5.0) * z) + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x + 5.0d0) * z) + (x * y)
end function
public static double code(double x, double y, double z) {
return ((x + 5.0) * z) + (x * y);
}
def code(x, y, z): return ((x + 5.0) * z) + (x * y)
function code(x, y, z) return Float64(Float64(Float64(x + 5.0) * z) + Float64(x * y)) end
function tmp = code(x, y, z) tmp = ((x + 5.0) * z) + (x * y); end
code[x_, y_, z_] := N[(N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 5\right) \cdot z + x \cdot y
\end{array}
herbie shell --seed 2023199
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:herbie-target
(+ (* (+ x 5.0) z) (* x y))
(+ (* x (+ y z)) (* z 5.0)))