
(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 x (+ y z) (* z 5.0)))
double code(double x, double y, double z) {
return fma(x, (y + z), (z * 5.0));
}
function code(x, y, z) return fma(x, Float64(y + z), Float64(z * 5.0)) end
code[x_, y_, z_] := N[(x * N[(y + z), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + z, z \cdot 5\right)
\end{array}
Initial program 99.9%
fma-define99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= x -2.45e+57)
(* x z)
(if (<= x -6.7e-12)
(* x y)
(if (<= x 1.66e-65) (* z 5.0) (if (<= x 1.2e+132) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.45e+57) {
tmp = x * z;
} else if (x <= -6.7e-12) {
tmp = x * y;
} else if (x <= 1.66e-65) {
tmp = z * 5.0;
} else if (x <= 1.2e+132) {
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 <= (-2.45d+57)) then
tmp = x * z
else if (x <= (-6.7d-12)) then
tmp = x * y
else if (x <= 1.66d-65) then
tmp = z * 5.0d0
else if (x <= 1.2d+132) 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 <= -2.45e+57) {
tmp = x * z;
} else if (x <= -6.7e-12) {
tmp = x * y;
} else if (x <= 1.66e-65) {
tmp = z * 5.0;
} else if (x <= 1.2e+132) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.45e+57: tmp = x * z elif x <= -6.7e-12: tmp = x * y elif x <= 1.66e-65: tmp = z * 5.0 elif x <= 1.2e+132: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.45e+57) tmp = Float64(x * z); elseif (x <= -6.7e-12) tmp = Float64(x * y); elseif (x <= 1.66e-65) tmp = Float64(z * 5.0); elseif (x <= 1.2e+132) 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 <= -2.45e+57) tmp = x * z; elseif (x <= -6.7e-12) tmp = x * y; elseif (x <= 1.66e-65) tmp = z * 5.0; elseif (x <= 1.2e+132) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.45e+57], N[(x * z), $MachinePrecision], If[LessEqual[x, -6.7e-12], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.66e-65], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 1.2e+132], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{+57}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -6.7 \cdot 10^{-12}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.66 \cdot 10^{-65}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{+132}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.45e57 or 1.2000000000000001e132 < x Initial program 100.0%
Taylor expanded in x around 0 100.0%
distribute-lft-in95.3%
*-commutative95.3%
+-commutative95.3%
associate-+r+95.3%
*-commutative95.3%
distribute-lft-in95.3%
fma-define97.6%
Simplified97.6%
Taylor expanded in z around inf 65.5%
+-commutative65.5%
Simplified65.5%
Taylor expanded in x around inf 65.5%
if -2.45e57 < x < -6.7000000000000001e-12 or 1.6599999999999999e-65 < x < 1.2000000000000001e132Initial program 100.0%
Taylor expanded in y around inf 66.9%
if -6.7000000000000001e-12 < x < 1.6599999999999999e-65Initial program 99.9%
Taylor expanded in x around 0 74.0%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.0) (not (<= x 2e-14))) (* x (+ y z)) (+ (* z 5.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.0) || !(x <= 2e-14)) {
tmp = x * (y + z);
} else {
tmp = (z * 5.0) + (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 <= (-5.0d0)) .or. (.not. (x <= 2d-14))) then
tmp = x * (y + z)
else
tmp = (z * 5.0d0) + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.0) || !(x <= 2e-14)) {
tmp = x * (y + z);
} else {
tmp = (z * 5.0) + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.0) or not (x <= 2e-14): tmp = x * (y + z) else: tmp = (z * 5.0) + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.0) || !(x <= 2e-14)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(z * 5.0) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.0) || ~((x <= 2e-14))) tmp = x * (y + z); else tmp = (z * 5.0) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.0], N[Not[LessEqual[x, 2e-14]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(z * 5.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \lor \neg \left(x \leq 2 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5 + x \cdot y\\
\end{array}
\end{array}
if x < -5 or 2e-14 < x Initial program 100.0%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -5 < x < 2e-14Initial program 99.9%
Taylor expanded in x around inf 75.7%
Taylor expanded in x around 0 75.7%
Taylor expanded in x around 0 99.9%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.9e-11) (not (<= x 5.8e-61))) (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e-11) || !(x <= 5.8e-61)) {
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 <= (-2.9d-11)) .or. (.not. (x <= 5.8d-61))) 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 <= -2.9e-11) || !(x <= 5.8e-61)) {
tmp = x * (y + z);
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.9e-11) or not (x <= 5.8e-61): tmp = x * (y + z) else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.9e-11) || !(x <= 5.8e-61)) 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 <= -2.9e-11) || ~((x <= 5.8e-61))) tmp = x * (y + z); else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.9e-11], N[Not[LessEqual[x, 5.8e-61]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{-11} \lor \neg \left(x \leq 5.8 \cdot 10^{-61}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -2.9e-11 or 5.7999999999999999e-61 < x Initial program 100.0%
Taylor expanded in x around inf 95.2%
+-commutative95.2%
Simplified95.2%
if -2.9e-11 < x < 5.7999999999999999e-61Initial program 99.9%
Taylor expanded in x around 0 74.0%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -420000000.0) (not (<= x 7e-64))) (* x (+ y z)) (* z (+ x 5.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -420000000.0) || !(x <= 7e-64)) {
tmp = x * (y + z);
} else {
tmp = z * (x + 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 <= (-420000000.0d0)) .or. (.not. (x <= 7d-64))) then
tmp = x * (y + z)
else
tmp = z * (x + 5.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -420000000.0) || !(x <= 7e-64)) {
tmp = x * (y + z);
} else {
tmp = z * (x + 5.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -420000000.0) or not (x <= 7e-64): tmp = x * (y + z) else: tmp = z * (x + 5.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -420000000.0) || !(x <= 7e-64)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + 5.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -420000000.0) || ~((x <= 7e-64))) tmp = x * (y + z); else tmp = z * (x + 5.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -420000000.0], N[Not[LessEqual[x, 7e-64]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + 5.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -420000000 \lor \neg \left(x \leq 7 \cdot 10^{-64}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + 5\right)\\
\end{array}
\end{array}
if x < -4.2e8 or 7.0000000000000006e-64 < x Initial program 100.0%
Taylor expanded in x around inf 96.0%
+-commutative96.0%
Simplified96.0%
if -4.2e8 < x < 7.0000000000000006e-64Initial program 99.9%
Taylor expanded in y around 0 73.8%
distribute-rgt-in73.8%
Simplified73.8%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e-16) (not (<= x 4.4e-61))) (* x y) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-16) || !(x <= 4.4e-61)) {
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 <= (-1.5d-16)) .or. (.not. (x <= 4.4d-61))) 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 <= -1.5e-16) || !(x <= 4.4e-61)) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e-16) or not (x <= 4.4e-61): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e-16) || !(x <= 4.4e-61)) 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 <= -1.5e-16) || ~((x <= 4.4e-61))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e-16], N[Not[LessEqual[x, 4.4e-61]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-16} \lor \neg \left(x \leq 4.4 \cdot 10^{-61}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -1.49999999999999997e-16 or 4.40000000000000017e-61 < x Initial program 100.0%
Taylor expanded in y around inf 50.4%
if -1.49999999999999997e-16 < x < 4.40000000000000017e-61Initial program 99.9%
Taylor expanded in x around 0 74.0%
Final simplification61.0%
(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 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 37.1%
Final simplification37.1%
(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 2024066
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:alt
(+ (* (+ x 5.0) z) (* x y))
(+ (* x (+ y z)) (* z 5.0)))