
(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 6 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 x y (* z (+ x 5.0))))
double code(double x, double y, double z) {
return fma(x, y, (z * (x + 5.0)));
}
function code(x, y, z) return fma(x, y, Float64(z * Float64(x + 5.0))) end
code[x_, y_, z_] := N[(x * y + N[(z * N[(x + 5.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z \cdot \left(x + 5\right)\right)
\end{array}
Initial program 100.0%
distribute-rgt-in98.4%
associate-+l+98.4%
*-commutative98.4%
fma-define100.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.6e+107)
(* x z)
(if (<= x -4.6e-97)
(* x y)
(if (<= x 3.7e-28) (* z 5.0) (if (<= x 8.1e+251) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+107) {
tmp = x * z;
} else if (x <= -4.6e-97) {
tmp = x * y;
} else if (x <= 3.7e-28) {
tmp = z * 5.0;
} else if (x <= 8.1e+251) {
tmp = x * y;
} else {
tmp = x * z;
}
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 <= (-1.6d+107)) then
tmp = x * z
else if (x <= (-4.6d-97)) then
tmp = x * y
else if (x <= 3.7d-28) then
tmp = z * 5.0d0
else if (x <= 8.1d+251) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+107) {
tmp = x * z;
} else if (x <= -4.6e-97) {
tmp = x * y;
} else if (x <= 3.7e-28) {
tmp = z * 5.0;
} else if (x <= 8.1e+251) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.6e+107: tmp = x * z elif x <= -4.6e-97: tmp = x * y elif x <= 3.7e-28: tmp = z * 5.0 elif x <= 8.1e+251: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.6e+107) tmp = Float64(x * z); elseif (x <= -4.6e-97) tmp = Float64(x * y); elseif (x <= 3.7e-28) tmp = Float64(z * 5.0); elseif (x <= 8.1e+251) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.6e+107) tmp = x * z; elseif (x <= -4.6e-97) tmp = x * y; elseif (x <= 3.7e-28) tmp = z * 5.0; elseif (x <= 8.1e+251) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.6e+107], N[(x * z), $MachinePrecision], If[LessEqual[x, -4.6e-97], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.7e-28], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 8.1e+251], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+107}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -4.6 \cdot 10^{-97}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-28}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 8.1 \cdot 10^{+251}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.60000000000000015e107 or 8.1000000000000003e251 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 69.4%
if -1.60000000000000015e107 < x < -4.59999999999999988e-97 or 3.7000000000000002e-28 < x < 8.1000000000000003e251Initial program 100.0%
Taylor expanded in y around inf 71.5%
if -4.59999999999999988e-97 < x < 3.7000000000000002e-28Initial program 100.0%
Taylor expanded in x around 0 73.2%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.8e-97) (not (<= x 6e-29))) (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.8e-97) || !(x <= 6e-29)) {
tmp = x * (y + z);
} else {
tmp = z * 5.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) :: tmp
if ((x <= (-8.8d-97)) .or. (.not. (x <= 6d-29))) then
tmp = x * (y + z)
else
tmp = z * 5.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.8e-97) || !(x <= 6e-29)) {
tmp = x * (y + z);
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.8e-97) or not (x <= 6e-29): tmp = x * (y + z) else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.8e-97) || !(x <= 6e-29)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * 5.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.8e-97) || ~((x <= 6e-29))) tmp = x * (y + z); else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.8e-97], N[Not[LessEqual[x, 6e-29]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{-97} \lor \neg \left(x \leq 6 \cdot 10^{-29}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -8.7999999999999996e-97 or 6.0000000000000005e-29 < x Initial program 100.0%
Taylor expanded in x around inf 94.9%
+-commutative94.9%
Simplified94.9%
if -8.7999999999999996e-97 < x < 6.0000000000000005e-29Initial program 100.0%
Taylor expanded in x around 0 73.2%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.4e-99) (not (<= x 2.35e-29))) (* x y) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-99) || !(x <= 2.35e-29)) {
tmp = x * y;
} else {
tmp = z * 5.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) :: tmp
if ((x <= (-3.4d-99)) .or. (.not. (x <= 2.35d-29))) then
tmp = x * y
else
tmp = z * 5.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-99) || !(x <= 2.35e-29)) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e-99) or not (x <= 2.35e-29): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e-99) || !(x <= 2.35e-29)) tmp = Float64(x * y); else tmp = Float64(z * 5.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.4e-99) || ~((x <= 2.35e-29))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e-99], N[Not[LessEqual[x, 2.35e-29]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-99} \lor \neg \left(x \leq 2.35 \cdot 10^{-29}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -3.40000000000000007e-99 or 2.3499999999999999e-29 < x Initial program 100.0%
Taylor expanded in y around inf 62.0%
if -3.40000000000000007e-99 < x < 2.3499999999999999e-29Initial program 100.0%
Taylor expanded in x around 0 73.2%
Final simplification66.7%
(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}
Initial program 100.0%
Final simplification100.0%
(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 100.0%
Taylor expanded in x around 0 34.0%
Final simplification34.0%
(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 2024052
(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)))