
(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-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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.7%
associate-+l+98.7%
*-commutative98.7%
fma-def99.1%
distribute-lft-out99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x y z)
:precision binary64
(if (<= x -3.1e+148)
(* x y)
(if (<= x -8.2e+99)
(* z x)
(if (<= x -4.6e-8)
(* x y)
(if (<= x 3e-67)
(* z 5.0)
(if (<= x 1600000000000.0)
(* x y)
(if (<= x 6.6e+169) (* z x) (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.1e+148) {
tmp = x * y;
} else if (x <= -8.2e+99) {
tmp = z * x;
} else if (x <= -4.6e-8) {
tmp = x * y;
} else if (x <= 3e-67) {
tmp = z * 5.0;
} else if (x <= 1600000000000.0) {
tmp = x * y;
} else if (x <= 6.6e+169) {
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+148)) then
tmp = x * y
else if (x <= (-8.2d+99)) then
tmp = z * x
else if (x <= (-4.6d-8)) then
tmp = x * y
else if (x <= 3d-67) then
tmp = z * 5.0d0
else if (x <= 1600000000000.0d0) then
tmp = x * y
else if (x <= 6.6d+169) 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+148) {
tmp = x * y;
} else if (x <= -8.2e+99) {
tmp = z * x;
} else if (x <= -4.6e-8) {
tmp = x * y;
} else if (x <= 3e-67) {
tmp = z * 5.0;
} else if (x <= 1600000000000.0) {
tmp = x * y;
} else if (x <= 6.6e+169) {
tmp = z * x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.1e+148: tmp = x * y elif x <= -8.2e+99: tmp = z * x elif x <= -4.6e-8: tmp = x * y elif x <= 3e-67: tmp = z * 5.0 elif x <= 1600000000000.0: tmp = x * y elif x <= 6.6e+169: tmp = z * x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.1e+148) tmp = Float64(x * y); elseif (x <= -8.2e+99) tmp = Float64(z * x); elseif (x <= -4.6e-8) tmp = Float64(x * y); elseif (x <= 3e-67) tmp = Float64(z * 5.0); elseif (x <= 1600000000000.0) tmp = Float64(x * y); elseif (x <= 6.6e+169) 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+148) tmp = x * y; elseif (x <= -8.2e+99) tmp = z * x; elseif (x <= -4.6e-8) tmp = x * y; elseif (x <= 3e-67) tmp = z * 5.0; elseif (x <= 1600000000000.0) tmp = x * y; elseif (x <= 6.6e+169) tmp = z * x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.1e+148], N[(x * y), $MachinePrecision], If[LessEqual[x, -8.2e+99], N[(z * x), $MachinePrecision], If[LessEqual[x, -4.6e-8], N[(x * y), $MachinePrecision], If[LessEqual[x, 3e-67], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 1600000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 6.6e+169], N[(z * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+148}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -8.2 \cdot 10^{+99}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -4.6 \cdot 10^{-8}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-67}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 1600000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6.6 \cdot 10^{+169}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.09999999999999975e148 or -8.19999999999999959e99 < x < -4.6000000000000002e-8 or 3.00000000000000032e-67 < x < 1.6e12 or 6.5999999999999994e169 < x Initial program 98.8%
Taylor expanded in y around inf 64.5%
if -3.09999999999999975e148 < x < -8.19999999999999959e99 or 1.6e12 < x < 6.5999999999999994e169Initial program 99.9%
Taylor expanded in y around 0 68.5%
+-commutative68.5%
*-commutative68.5%
distribute-rgt-in68.6%
Simplified68.6%
Taylor expanded in x around inf 67.7%
if -4.6000000000000002e-8 < x < 3.00000000000000032e-67Initial program 99.9%
Taylor expanded in x around 0 75.9%
Final simplification70.5%
(FPCore (x y z)
:precision binary64
(if (<= y -1100000.0)
(* x y)
(if (or (<= y 3.9e+115) (and (not (<= y 5e+189)) (<= y 5.7e+226)))
(* z (+ 5.0 x))
(* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1100000.0) {
tmp = x * y;
} else if ((y <= 3.9e+115) || (!(y <= 5e+189) && (y <= 5.7e+226))) {
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 (y <= (-1100000.0d0)) then
tmp = x * y
else if ((y <= 3.9d+115) .or. (.not. (y <= 5d+189)) .and. (y <= 5.7d+226)) 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 (y <= -1100000.0) {
tmp = x * y;
} else if ((y <= 3.9e+115) || (!(y <= 5e+189) && (y <= 5.7e+226))) {
tmp = z * (5.0 + x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1100000.0: tmp = x * y elif (y <= 3.9e+115) or (not (y <= 5e+189) and (y <= 5.7e+226)): tmp = z * (5.0 + x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1100000.0) tmp = Float64(x * y); elseif ((y <= 3.9e+115) || (!(y <= 5e+189) && (y <= 5.7e+226))) 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 (y <= -1100000.0) tmp = x * y; elseif ((y <= 3.9e+115) || (~((y <= 5e+189)) && (y <= 5.7e+226))) tmp = z * (5.0 + x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1100000.0], N[(x * y), $MachinePrecision], If[Or[LessEqual[y, 3.9e+115], And[N[Not[LessEqual[y, 5e+189]], $MachinePrecision], LessEqual[y, 5.7e+226]]], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1100000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{+115} \lor \neg \left(y \leq 5 \cdot 10^{+189}\right) \land y \leq 5.7 \cdot 10^{+226}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.1e6 or 3.90000000000000006e115 < y < 5.0000000000000004e189 or 5.69999999999999948e226 < y Initial program 100.0%
Taylor expanded in y around inf 73.3%
if -1.1e6 < y < 3.90000000000000006e115 or 5.0000000000000004e189 < y < 5.69999999999999948e226Initial program 99.2%
Taylor expanded in y around 0 82.0%
+-commutative82.0%
*-commutative82.0%
distribute-rgt-in82.7%
Simplified82.7%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -28.0) (not (<= x 1.75e-65))) (* x (+ z y)) (* z (+ 5.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -28.0) || !(x <= 1.75e-65)) {
tmp = x * (z + y);
} else {
tmp = z * (5.0 + x);
}
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 <= (-28.0d0)) .or. (.not. (x <= 1.75d-65))) then
tmp = x * (z + y)
else
tmp = z * (5.0d0 + x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -28.0) || !(x <= 1.75e-65)) {
tmp = x * (z + y);
} else {
tmp = z * (5.0 + x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -28.0) or not (x <= 1.75e-65): tmp = x * (z + y) else: tmp = z * (5.0 + x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -28.0) || !(x <= 1.75e-65)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(5.0 + x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -28.0) || ~((x <= 1.75e-65))) tmp = x * (z + y); else tmp = z * (5.0 + x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -28.0], N[Not[LessEqual[x, 1.75e-65]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -28 \lor \neg \left(x \leq 1.75 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\end{array}
\end{array}
if x < -28 or 1.75000000000000002e-65 < x Initial program 99.2%
Taylor expanded in x around inf 96.1%
+-commutative96.1%
Simplified96.1%
if -28 < x < 1.75000000000000002e-65Initial program 99.9%
Taylor expanded in y around 0 76.4%
+-commutative76.4%
*-commutative76.4%
distribute-rgt-in76.4%
Simplified76.4%
Final simplification86.4%
(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 -4.6e-8) (* x y) (if (<= x 7.2e-66) (* z 5.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.6e-8) {
tmp = x * y;
} else if (x <= 7.2e-66) {
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 <= (-4.6d-8)) then
tmp = x * y
else if (x <= 7.2d-66) 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 <= -4.6e-8) {
tmp = x * y;
} else if (x <= 7.2e-66) {
tmp = z * 5.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.6e-8: tmp = x * y elif x <= 7.2e-66: tmp = z * 5.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.6e-8) tmp = Float64(x * y); elseif (x <= 7.2e-66) 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 <= -4.6e-8) tmp = x * y; elseif (x <= 7.2e-66) tmp = z * 5.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.6e-8], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.2e-66], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-8}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-66}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.6000000000000002e-8 or 7.20000000000000025e-66 < x Initial program 99.2%
Taylor expanded in y around inf 53.8%
if -4.6000000000000002e-8 < x < 7.20000000000000025e-66Initial program 99.9%
Taylor expanded in x around 0 75.9%
Final simplification64.5%
(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 39.0%
Final simplification39.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 2023229
(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)))