
(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 (+ (* 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%
(FPCore (x y z)
:precision binary64
(if (<= x -2.6e+39)
(* x z)
(if (<= x -8e-36)
(* x y)
(if (<= x 3.5e-38) (* z 5.0) (if (<= x 3.6e+195) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e+39) {
tmp = x * z;
} else if (x <= -8e-36) {
tmp = x * y;
} else if (x <= 3.5e-38) {
tmp = z * 5.0;
} else if (x <= 3.6e+195) {
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.6d+39)) then
tmp = x * z
else if (x <= (-8d-36)) then
tmp = x * y
else if (x <= 3.5d-38) then
tmp = z * 5.0d0
else if (x <= 3.6d+195) 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.6e+39) {
tmp = x * z;
} else if (x <= -8e-36) {
tmp = x * y;
} else if (x <= 3.5e-38) {
tmp = z * 5.0;
} else if (x <= 3.6e+195) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.6e+39: tmp = x * z elif x <= -8e-36: tmp = x * y elif x <= 3.5e-38: tmp = z * 5.0 elif x <= 3.6e+195: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.6e+39) tmp = Float64(x * z); elseif (x <= -8e-36) tmp = Float64(x * y); elseif (x <= 3.5e-38) tmp = Float64(z * 5.0); elseif (x <= 3.6e+195) 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.6e+39) tmp = x * z; elseif (x <= -8e-36) tmp = x * y; elseif (x <= 3.5e-38) tmp = z * 5.0; elseif (x <= 3.6e+195) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.6e+39], N[(x * z), $MachinePrecision], If[LessEqual[x, -8e-36], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.5e-38], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 3.6e+195], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+39}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -8 \cdot 10^{-36}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-38}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{+195}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.6e39 or 3.5999999999999999e195 < x Initial program 100.0%
Taylor expanded in y around 0 67.5%
+-commutative67.5%
distribute-rgt-in67.5%
Simplified67.5%
Taylor expanded in x around inf 67.5%
if -2.6e39 < x < -7.9999999999999995e-36 or 3.5000000000000001e-38 < x < 3.5999999999999999e195Initial program 99.9%
add-cube-cbrt99.8%
pow399.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 60.6%
if -7.9999999999999995e-36 < x < 3.5000000000000001e-38Initial program 99.9%
Taylor expanded in y around 0 75.6%
+-commutative75.6%
distribute-rgt-in75.6%
Simplified75.6%
Taylor expanded in x around 0 75.6%
Final simplification68.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -30.5) (not (<= x 5.1))) (* x (+ y z)) (+ (* z 5.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -30.5) || !(x <= 5.1)) {
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 <= (-30.5d0)) .or. (.not. (x <= 5.1d0))) 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 <= -30.5) || !(x <= 5.1)) {
tmp = x * (y + z);
} else {
tmp = (z * 5.0) + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -30.5) or not (x <= 5.1): tmp = x * (y + z) else: tmp = (z * 5.0) + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -30.5) || !(x <= 5.1)) 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 <= -30.5) || ~((x <= 5.1))) tmp = x * (y + z); else tmp = (z * 5.0) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -30.5], N[Not[LessEqual[x, 5.1]], $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 -30.5 \lor \neg \left(x \leq 5.1\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5 + x \cdot y\\
\end{array}
\end{array}
if x < -30.5 or 5.0999999999999996 < x Initial program 100.0%
Taylor expanded in x around inf 99.1%
if -30.5 < x < 5.0999999999999996Initial program 99.9%
Taylor expanded in y around inf 98.2%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-37) (not (<= x 7.8e-39))) (* x (+ y z)) (* z (+ x 5.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-37) || !(x <= 7.8e-39)) {
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 <= (-9d-37)) .or. (.not. (x <= 7.8d-39))) 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 <= -9e-37) || !(x <= 7.8e-39)) {
tmp = x * (y + z);
} else {
tmp = z * (x + 5.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-37) or not (x <= 7.8e-39): tmp = x * (y + z) else: tmp = z * (x + 5.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-37) || !(x <= 7.8e-39)) 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 <= -9e-37) || ~((x <= 7.8e-39))) tmp = x * (y + z); else tmp = z * (x + 5.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-37], N[Not[LessEqual[x, 7.8e-39]], $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 -9 \cdot 10^{-37} \lor \neg \left(x \leq 7.8 \cdot 10^{-39}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + 5\right)\\
\end{array}
\end{array}
if x < -9.00000000000000081e-37 or 7.80000000000000059e-39 < x Initial program 100.0%
Taylor expanded in x around inf 92.7%
if -9.00000000000000081e-37 < x < 7.80000000000000059e-39Initial program 99.9%
Taylor expanded in y around 0 75.6%
+-commutative75.6%
distribute-rgt-in75.6%
Simplified75.6%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e-36) (not (<= x 5e-39))) (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e-36) || !(x <= 5e-39)) {
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 <= (-7.2d-36)) .or. (.not. (x <= 5d-39))) 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 <= -7.2e-36) || !(x <= 5e-39)) {
tmp = x * (y + z);
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e-36) or not (x <= 5e-39): tmp = x * (y + z) else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e-36) || !(x <= 5e-39)) 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 <= -7.2e-36) || ~((x <= 5e-39))) tmp = x * (y + z); else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e-36], N[Not[LessEqual[x, 5e-39]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-36} \lor \neg \left(x \leq 5 \cdot 10^{-39}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -7.20000000000000064e-36 or 4.9999999999999998e-39 < x Initial program 100.0%
Taylor expanded in x around inf 92.7%
if -7.20000000000000064e-36 < x < 4.9999999999999998e-39Initial program 99.9%
Taylor expanded in y around 0 75.6%
+-commutative75.6%
distribute-rgt-in75.6%
Simplified75.6%
Taylor expanded in x around 0 75.6%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e-36) (not (<= x 1.85e-38))) (* x y) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-36) || !(x <= 1.85e-38)) {
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.6d-36)) .or. (.not. (x <= 1.85d-38))) 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.6e-36) || !(x <= 1.85e-38)) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e-36) or not (x <= 1.85e-38): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e-36) || !(x <= 1.85e-38)) 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.6e-36) || ~((x <= 1.85e-38))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e-36], N[Not[LessEqual[x, 1.85e-38]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-36} \lor \neg \left(x \leq 1.85 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -3.60000000000000032e-36 or 1.85e-38 < x Initial program 100.0%
add-cube-cbrt99.9%
pow399.9%
Applied egg-rr99.9%
Taylor expanded in y around inf 48.9%
if -3.60000000000000032e-36 < x < 1.85e-38Initial program 99.9%
Taylor expanded in y around 0 75.6%
+-commutative75.6%
distribute-rgt-in75.6%
Simplified75.6%
Taylor expanded in x around 0 75.6%
Final simplification59.2%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return 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 * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.9%
add-cube-cbrt99.3%
pow399.3%
Applied egg-rr99.3%
Taylor expanded in y around inf 40.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 2024186
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:alt
(! :herbie-platform default (+ (* (+ x 5) z) (* x y)))
(+ (* x (+ y z)) (* z 5.0)))