
(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 8 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.5%
+-commutative99.5%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (fma x y (* z (+ 5.0 x))))
double code(double x, double y, double z) {
return fma(x, y, (z * (5.0 + x)));
}
function code(x, y, z) return fma(x, y, Float64(z * Float64(5.0 + x))) end
code[x_, y_, z_] := N[(x * y + N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z \cdot \left(5 + x\right)\right)
\end{array}
Initial program 99.5%
distribute-lft-in98.3%
associate-+l+98.3%
*-commutative98.3%
fma-def99.1%
distribute-lft-out99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x y z)
:precision binary64
(if (<= x -3.1e+203)
(* z x)
(if (<= x -1.4e+96)
(* x y)
(if (<= x -6e+70)
(* z x)
(if (<= x -4.7e-95)
(* x y)
(if (<= x 5.6e-6)
(* z 5.0)
(if (<= x 1.06e+58)
(* x y)
(if (<= x 9.8e+209) (* z x) (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.1e+203) {
tmp = z * x;
} else if (x <= -1.4e+96) {
tmp = x * y;
} else if (x <= -6e+70) {
tmp = z * x;
} else if (x <= -4.7e-95) {
tmp = x * y;
} else if (x <= 5.6e-6) {
tmp = z * 5.0;
} else if (x <= 1.06e+58) {
tmp = x * y;
} else if (x <= 9.8e+209) {
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.1d+203)) then
tmp = z * x
else if (x <= (-1.4d+96)) then
tmp = x * y
else if (x <= (-6d+70)) then
tmp = z * x
else if (x <= (-4.7d-95)) then
tmp = x * y
else if (x <= 5.6d-6) then
tmp = z * 5.0d0
else if (x <= 1.06d+58) then
tmp = x * y
else if (x <= 9.8d+209) 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.1e+203) {
tmp = z * x;
} else if (x <= -1.4e+96) {
tmp = x * y;
} else if (x <= -6e+70) {
tmp = z * x;
} else if (x <= -4.7e-95) {
tmp = x * y;
} else if (x <= 5.6e-6) {
tmp = z * 5.0;
} else if (x <= 1.06e+58) {
tmp = x * y;
} else if (x <= 9.8e+209) {
tmp = z * x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.1e+203: tmp = z * x elif x <= -1.4e+96: tmp = x * y elif x <= -6e+70: tmp = z * x elif x <= -4.7e-95: tmp = x * y elif x <= 5.6e-6: tmp = z * 5.0 elif x <= 1.06e+58: tmp = x * y elif x <= 9.8e+209: tmp = z * x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.1e+203) tmp = Float64(z * x); elseif (x <= -1.4e+96) tmp = Float64(x * y); elseif (x <= -6e+70) tmp = Float64(z * x); elseif (x <= -4.7e-95) tmp = Float64(x * y); elseif (x <= 5.6e-6) tmp = Float64(z * 5.0); elseif (x <= 1.06e+58) tmp = Float64(x * y); elseif (x <= 9.8e+209) 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.1e+203) tmp = z * x; elseif (x <= -1.4e+96) tmp = x * y; elseif (x <= -6e+70) tmp = z * x; elseif (x <= -4.7e-95) tmp = x * y; elseif (x <= 5.6e-6) tmp = z * 5.0; elseif (x <= 1.06e+58) tmp = x * y; elseif (x <= 9.8e+209) tmp = z * x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.1e+203], N[(z * x), $MachinePrecision], If[LessEqual[x, -1.4e+96], N[(x * y), $MachinePrecision], If[LessEqual[x, -6e+70], N[(z * x), $MachinePrecision], If[LessEqual[x, -4.7e-95], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.6e-6], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 1.06e+58], N[(x * y), $MachinePrecision], If[LessEqual[x, 9.8e+209], N[(z * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+203}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -1.4 \cdot 10^{+96}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -6 \cdot 10^{+70}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -4.7 \cdot 10^{-95}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-6}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 1.06 \cdot 10^{+58}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 9.8 \cdot 10^{+209}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.1e203 or -1.4e96 < x < -5.99999999999999952e70 or 1.05999999999999997e58 < x < 9.7999999999999995e209Initial program 98.5%
Taylor expanded in y around 0 67.5%
+-commutative67.5%
*-commutative67.5%
distribute-rgt-in68.9%
Simplified68.9%
Taylor expanded in x around inf 68.9%
if -3.1e203 < x < -1.4e96 or -5.99999999999999952e70 < x < -4.6999999999999998e-95 or 5.59999999999999975e-6 < x < 1.05999999999999997e58 or 9.7999999999999995e209 < x Initial program 99.9%
Taylor expanded in y around inf 64.4%
if -4.6999999999999998e-95 < x < 5.59999999999999975e-6Initial program 99.8%
Taylor expanded in x around 0 78.1%
Final simplification70.6%
(FPCore (x y z)
:precision binary64
(if (or (<= z -23000.0)
(not
(or (<= z -2.2e-48) (and (not (<= z -3.1e-86)) (<= z 5.4e-117)))))
(* z (+ 5.0 x))
(* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -23000.0) || !((z <= -2.2e-48) || (!(z <= -3.1e-86) && (z <= 5.4e-117)))) {
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 <= (-23000.0d0)) .or. (.not. (z <= (-2.2d-48)) .or. (.not. (z <= (-3.1d-86))) .and. (z <= 5.4d-117))) 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 <= -23000.0) || !((z <= -2.2e-48) || (!(z <= -3.1e-86) && (z <= 5.4e-117)))) {
tmp = z * (5.0 + x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -23000.0) or not ((z <= -2.2e-48) or (not (z <= -3.1e-86) and (z <= 5.4e-117))): tmp = z * (5.0 + x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -23000.0) || !((z <= -2.2e-48) || (!(z <= -3.1e-86) && (z <= 5.4e-117)))) 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 <= -23000.0) || ~(((z <= -2.2e-48) || (~((z <= -3.1e-86)) && (z <= 5.4e-117))))) tmp = z * (5.0 + x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -23000.0], N[Not[Or[LessEqual[z, -2.2e-48], And[N[Not[LessEqual[z, -3.1e-86]], $MachinePrecision], LessEqual[z, 5.4e-117]]]], $MachinePrecision]], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -23000 \lor \neg \left(z \leq -2.2 \cdot 10^{-48} \lor \neg \left(z \leq -3.1 \cdot 10^{-86}\right) \land z \leq 5.4 \cdot 10^{-117}\right):\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -23000 or -2.20000000000000013e-48 < z < -3.09999999999999989e-86 or 5.40000000000000005e-117 < z Initial program 99.2%
Taylor expanded in y around 0 78.9%
+-commutative78.9%
*-commutative78.9%
distribute-rgt-in79.5%
Simplified79.5%
if -23000 < z < -2.20000000000000013e-48 or -3.09999999999999989e-86 < z < 5.40000000000000005e-117Initial program 99.9%
Taylor expanded in y around inf 70.9%
Final simplification76.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))))
(if (<= x -2.6e-18)
t_0
(if (<= x -1.55e-60)
(/ z 0.2)
(if (<= x -4.9e-95) (* x y) (if (<= x 6.4e-6) (* z (+ 5.0 x)) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -2.6e-18) {
tmp = t_0;
} else if (x <= -1.55e-60) {
tmp = z / 0.2;
} else if (x <= -4.9e-95) {
tmp = x * y;
} else if (x <= 6.4e-6) {
tmp = z * (5.0 + x);
} 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 <= (-2.6d-18)) then
tmp = t_0
else if (x <= (-1.55d-60)) then
tmp = z / 0.2d0
else if (x <= (-4.9d-95)) then
tmp = x * y
else if (x <= 6.4d-6) then
tmp = z * (5.0d0 + x)
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 <= -2.6e-18) {
tmp = t_0;
} else if (x <= -1.55e-60) {
tmp = z / 0.2;
} else if (x <= -4.9e-95) {
tmp = x * y;
} else if (x <= 6.4e-6) {
tmp = z * (5.0 + x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) tmp = 0 if x <= -2.6e-18: tmp = t_0 elif x <= -1.55e-60: tmp = z / 0.2 elif x <= -4.9e-95: tmp = x * y elif x <= 6.4e-6: tmp = z * (5.0 + x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + y)) tmp = 0.0 if (x <= -2.6e-18) tmp = t_0; elseif (x <= -1.55e-60) tmp = Float64(z / 0.2); elseif (x <= -4.9e-95) tmp = Float64(x * y); elseif (x <= 6.4e-6) tmp = Float64(z * Float64(5.0 + x)); 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 <= -2.6e-18) tmp = t_0; elseif (x <= -1.55e-60) tmp = z / 0.2; elseif (x <= -4.9e-95) tmp = x * y; elseif (x <= 6.4e-6) tmp = z * (5.0 + x); 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, -2.6e-18], t$95$0, If[LessEqual[x, -1.55e-60], N[(z / 0.2), $MachinePrecision], If[LessEqual[x, -4.9e-95], N[(x * y), $MachinePrecision], If[LessEqual[x, 6.4e-6], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -2.6 \cdot 10^{-18}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{-60}:\\
\;\;\;\;\frac{z}{0.2}\\
\mathbf{elif}\;x \leq -4.9 \cdot 10^{-95}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6.4 \cdot 10^{-6}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -2.6e-18 or 6.3999999999999997e-6 < x Initial program 99.3%
Taylor expanded in x around inf 98.8%
+-commutative98.8%
Simplified98.8%
if -2.6e-18 < x < -1.54999999999999994e-60Initial program 99.5%
Taylor expanded in y around 0 70.7%
+-commutative70.7%
*-commutative70.7%
distribute-rgt-in70.7%
Simplified70.7%
flip-+70.7%
associate-*r/70.7%
metadata-eval70.7%
Applied egg-rr70.7%
associate-/l*71.0%
Simplified71.0%
Taylor expanded in x around 0 71.0%
if -1.54999999999999994e-60 < x < -4.9e-95Initial program 99.8%
Taylor expanded in y around inf 79.2%
if -4.9e-95 < x < 6.3999999999999997e-6Initial program 99.8%
Taylor expanded in y around 0 78.9%
+-commutative78.9%
*-commutative78.9%
distribute-rgt-in78.9%
Simplified78.9%
Final simplification89.8%
(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.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= x -3.3e-95) (* x y) (if (<= x 1.56e-7) (* z 5.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.3e-95) {
tmp = x * y;
} else if (x <= 1.56e-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.3d-95)) then
tmp = x * y
else if (x <= 1.56d-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.3e-95) {
tmp = x * y;
} else if (x <= 1.56e-7) {
tmp = z * 5.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.3e-95: tmp = x * y elif x <= 1.56e-7: tmp = z * 5.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.3e-95) tmp = Float64(x * y); elseif (x <= 1.56e-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.3e-95) tmp = x * y; elseif (x <= 1.56e-7) tmp = z * 5.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.3e-95], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.56e-7], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-95}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.56 \cdot 10^{-7}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.3e-95 or 1.55999999999999994e-7 < x Initial program 99.3%
Taylor expanded in y around inf 53.0%
if -3.3e-95 < x < 1.55999999999999994e-7Initial program 99.8%
Taylor expanded in x around 0 78.1%
Final simplification62.1%
(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.5%
Taylor expanded in x around 0 33.6%
Final simplification33.6%
(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 2023224
(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)))