
(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 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 100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.3e+182)
(* x y)
(if (<= x -5.6e+90)
(* x z)
(if (<= x -3.8e+53)
(* x y)
(if (<= x -4500.0)
(* x z)
(if (<= x 2.1e-78)
(* z 5.0)
(if (or (<= x 5.2e+82) (not (<= x 6.5e+225))) (* x y) (* x z))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+182) {
tmp = x * y;
} else if (x <= -5.6e+90) {
tmp = x * z;
} else if (x <= -3.8e+53) {
tmp = x * y;
} else if (x <= -4500.0) {
tmp = x * z;
} else if (x <= 2.1e-78) {
tmp = z * 5.0;
} else if ((x <= 5.2e+82) || !(x <= 6.5e+225)) {
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.3d+182)) then
tmp = x * y
else if (x <= (-5.6d+90)) then
tmp = x * z
else if (x <= (-3.8d+53)) then
tmp = x * y
else if (x <= (-4500.0d0)) then
tmp = x * z
else if (x <= 2.1d-78) then
tmp = z * 5.0d0
else if ((x <= 5.2d+82) .or. (.not. (x <= 6.5d+225))) 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.3e+182) {
tmp = x * y;
} else if (x <= -5.6e+90) {
tmp = x * z;
} else if (x <= -3.8e+53) {
tmp = x * y;
} else if (x <= -4500.0) {
tmp = x * z;
} else if (x <= 2.1e-78) {
tmp = z * 5.0;
} else if ((x <= 5.2e+82) || !(x <= 6.5e+225)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+182: tmp = x * y elif x <= -5.6e+90: tmp = x * z elif x <= -3.8e+53: tmp = x * y elif x <= -4500.0: tmp = x * z elif x <= 2.1e-78: tmp = z * 5.0 elif (x <= 5.2e+82) or not (x <= 6.5e+225): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+182) tmp = Float64(x * y); elseif (x <= -5.6e+90) tmp = Float64(x * z); elseif (x <= -3.8e+53) tmp = Float64(x * y); elseif (x <= -4500.0) tmp = Float64(x * z); elseif (x <= 2.1e-78) tmp = Float64(z * 5.0); elseif ((x <= 5.2e+82) || !(x <= 6.5e+225)) 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.3e+182) tmp = x * y; elseif (x <= -5.6e+90) tmp = x * z; elseif (x <= -3.8e+53) tmp = x * y; elseif (x <= -4500.0) tmp = x * z; elseif (x <= 2.1e-78) tmp = z * 5.0; elseif ((x <= 5.2e+82) || ~((x <= 6.5e+225))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+182], N[(x * y), $MachinePrecision], If[LessEqual[x, -5.6e+90], N[(x * z), $MachinePrecision], If[LessEqual[x, -3.8e+53], N[(x * y), $MachinePrecision], If[LessEqual[x, -4500.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.1e-78], N[(z * 5.0), $MachinePrecision], If[Or[LessEqual[x, 5.2e+82], N[Not[LessEqual[x, 6.5e+225]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+182}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -5.6 \cdot 10^{+90}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -3.8 \cdot 10^{+53}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -4500:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-78}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+82} \lor \neg \left(x \leq 6.5 \cdot 10^{+225}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.3e182 or -5.6000000000000001e90 < x < -3.79999999999999997e53 or 2.1000000000000001e-78 < x < 5.1999999999999997e82 or 6.5000000000000006e225 < x Initial program 99.9%
Taylor expanded in y around inf 68.2%
if -1.3e182 < x < -5.6000000000000001e90 or -3.79999999999999997e53 < x < -4500 or 5.1999999999999997e82 < x < 6.5000000000000006e225Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 71.9%
if -4500 < x < 2.1000000000000001e-78Initial program 100.0%
Taylor expanded in x around 0 70.9%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1e-15) (not (<= x 1.8e-90))) (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-15) || !(x <= 1.8e-90)) {
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 <= (-1d-15)) .or. (.not. (x <= 1.8d-90))) 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 <= -1e-15) || !(x <= 1.8e-90)) {
tmp = x * (y + z);
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e-15) or not (x <= 1.8e-90): tmp = x * (y + z) else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e-15) || !(x <= 1.8e-90)) 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 <= -1e-15) || ~((x <= 1.8e-90))) tmp = x * (y + z); else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e-15], N[Not[LessEqual[x, 1.8e-90]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-15} \lor \neg \left(x \leq 1.8 \cdot 10^{-90}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -1.0000000000000001e-15 or 1.7999999999999999e-90 < x Initial program 100.0%
Taylor expanded in x around inf 91.7%
+-commutative91.7%
Simplified91.7%
if -1.0000000000000001e-15 < x < 1.7999999999999999e-90Initial program 100.0%
Taylor expanded in x around 0 73.1%
Final simplification83.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e-13) (not (<= x 1.8e-90))) (* x (+ y z)) (* z (+ x 5.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-13) || !(x <= 1.8e-90)) {
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 <= (-6.2d-13)) .or. (.not. (x <= 1.8d-90))) 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 <= -6.2e-13) || !(x <= 1.8e-90)) {
tmp = x * (y + z);
} else {
tmp = z * (x + 5.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e-13) or not (x <= 1.8e-90): tmp = x * (y + z) else: tmp = z * (x + 5.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-13) || !(x <= 1.8e-90)) 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 <= -6.2e-13) || ~((x <= 1.8e-90))) tmp = x * (y + z); else tmp = z * (x + 5.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-13], N[Not[LessEqual[x, 1.8e-90]], $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 -6.2 \cdot 10^{-13} \lor \neg \left(x \leq 1.8 \cdot 10^{-90}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + 5\right)\\
\end{array}
\end{array}
if x < -6.1999999999999998e-13 or 1.7999999999999999e-90 < x Initial program 100.0%
Taylor expanded in x around inf 91.7%
+-commutative91.7%
Simplified91.7%
if -6.1999999999999998e-13 < x < 1.7999999999999999e-90Initial program 100.0%
Taylor expanded in y around 0 73.1%
distribute-rgt-in73.1%
Simplified73.1%
Final simplification83.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e-14) (not (<= x 2.6e-77))) (* x y) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-14) || !(x <= 2.6e-77)) {
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 <= (-5.5d-14)) .or. (.not. (x <= 2.6d-77))) 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 <= -5.5e-14) || !(x <= 2.6e-77)) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e-14) or not (x <= 2.6e-77): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e-14) || !(x <= 2.6e-77)) 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 <= -5.5e-14) || ~((x <= 2.6e-77))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e-14], N[Not[LessEqual[x, 2.6e-77]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-14} \lor \neg \left(x \leq 2.6 \cdot 10^{-77}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -5.49999999999999991e-14 or 2.6000000000000001e-77 < x Initial program 100.0%
Taylor expanded in y around inf 53.6%
if -5.49999999999999991e-14 < x < 2.6000000000000001e-77Initial program 100.0%
Taylor expanded in x around 0 72.3%
Final simplification62.1%
(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 36.8%
Final simplification36.8%
(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 2024031
(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)))