
(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 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.9%
+-commutative99.9%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -6.2e+168)
(* x y)
(if (<= x -2.2e+142)
(* z x)
(if (<= x -4.8e+34)
(* x y)
(if (<= x -2050000.0)
(* z x)
(if (<= x -8.5e-25)
(* x y)
(if (<= x 3.9e-61)
(* z 5.0)
(if (or (<= x 4.3e+58) (and (not (<= x 2.8e+90)) (<= x 9.5e+250)))
(* x y)
(* z x)))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+168) {
tmp = x * y;
} else if (x <= -2.2e+142) {
tmp = z * x;
} else if (x <= -4.8e+34) {
tmp = x * y;
} else if (x <= -2050000.0) {
tmp = z * x;
} else if (x <= -8.5e-25) {
tmp = x * y;
} else if (x <= 3.9e-61) {
tmp = z * 5.0;
} else if ((x <= 4.3e+58) || (!(x <= 2.8e+90) && (x <= 9.5e+250))) {
tmp = x * y;
} else {
tmp = z * 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 <= (-6.2d+168)) then
tmp = x * y
else if (x <= (-2.2d+142)) then
tmp = z * x
else if (x <= (-4.8d+34)) then
tmp = x * y
else if (x <= (-2050000.0d0)) then
tmp = z * x
else if (x <= (-8.5d-25)) then
tmp = x * y
else if (x <= 3.9d-61) then
tmp = z * 5.0d0
else if ((x <= 4.3d+58) .or. (.not. (x <= 2.8d+90)) .and. (x <= 9.5d+250)) then
tmp = x * y
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+168) {
tmp = x * y;
} else if (x <= -2.2e+142) {
tmp = z * x;
} else if (x <= -4.8e+34) {
tmp = x * y;
} else if (x <= -2050000.0) {
tmp = z * x;
} else if (x <= -8.5e-25) {
tmp = x * y;
} else if (x <= 3.9e-61) {
tmp = z * 5.0;
} else if ((x <= 4.3e+58) || (!(x <= 2.8e+90) && (x <= 9.5e+250))) {
tmp = x * y;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.2e+168: tmp = x * y elif x <= -2.2e+142: tmp = z * x elif x <= -4.8e+34: tmp = x * y elif x <= -2050000.0: tmp = z * x elif x <= -8.5e-25: tmp = x * y elif x <= 3.9e-61: tmp = z * 5.0 elif (x <= 4.3e+58) or (not (x <= 2.8e+90) and (x <= 9.5e+250)): tmp = x * y else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.2e+168) tmp = Float64(x * y); elseif (x <= -2.2e+142) tmp = Float64(z * x); elseif (x <= -4.8e+34) tmp = Float64(x * y); elseif (x <= -2050000.0) tmp = Float64(z * x); elseif (x <= -8.5e-25) tmp = Float64(x * y); elseif (x <= 3.9e-61) tmp = Float64(z * 5.0); elseif ((x <= 4.3e+58) || (!(x <= 2.8e+90) && (x <= 9.5e+250))) tmp = Float64(x * y); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.2e+168) tmp = x * y; elseif (x <= -2.2e+142) tmp = z * x; elseif (x <= -4.8e+34) tmp = x * y; elseif (x <= -2050000.0) tmp = z * x; elseif (x <= -8.5e-25) tmp = x * y; elseif (x <= 3.9e-61) tmp = z * 5.0; elseif ((x <= 4.3e+58) || (~((x <= 2.8e+90)) && (x <= 9.5e+250))) tmp = x * y; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.2e+168], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.2e+142], N[(z * x), $MachinePrecision], If[LessEqual[x, -4.8e+34], N[(x * y), $MachinePrecision], If[LessEqual[x, -2050000.0], N[(z * x), $MachinePrecision], If[LessEqual[x, -8.5e-25], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.9e-61], N[(z * 5.0), $MachinePrecision], If[Or[LessEqual[x, 4.3e+58], And[N[Not[LessEqual[x, 2.8e+90]], $MachinePrecision], LessEqual[x, 9.5e+250]]], N[(x * y), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+168}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{+142}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -4.8 \cdot 10^{+34}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2050000:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{-61}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 4.3 \cdot 10^{+58} \lor \neg \left(x \leq 2.8 \cdot 10^{+90}\right) \land x \leq 9.5 \cdot 10^{+250}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -6.19999999999999993e168 or -2.19999999999999987e142 < x < -4.79999999999999974e34 or -2.05e6 < x < -8.49999999999999981e-25 or 3.90000000000000033e-61 < x < 4.29999999999999991e58 or 2.8e90 < x < 9.49999999999999957e250Initial program 100.0%
Taylor expanded in y around inf 68.3%
if -6.19999999999999993e168 < x < -2.19999999999999987e142 or -4.79999999999999974e34 < x < -2.05e6 or 4.29999999999999991e58 < x < 2.8e90 or 9.49999999999999957e250 < x Initial program 100.0%
Taylor expanded in x around inf 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in z around inf 77.4%
if -8.49999999999999981e-25 < x < 3.90000000000000033e-61Initial program 99.9%
Taylor expanded in x around 0 74.4%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-24) (not (<= x 4.6e-61))) (* x (+ z y)) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-24) || !(x <= 4.6e-61)) {
tmp = x * (z + 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 <= (-2d-24)) .or. (.not. (x <= 4.6d-61))) then
tmp = x * (z + 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 <= -2e-24) || !(x <= 4.6e-61)) {
tmp = x * (z + y);
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-24) or not (x <= 4.6e-61): tmp = x * (z + y) else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-24) || !(x <= 4.6e-61)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * 5.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e-24) || ~((x <= 4.6e-61))) tmp = x * (z + y); else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-24], N[Not[LessEqual[x, 4.6e-61]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-24} \lor \neg \left(x \leq 4.6 \cdot 10^{-61}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -1.99999999999999985e-24 or 4.59999999999999984e-61 < x Initial program 100.0%
Taylor expanded in x around inf 96.1%
+-commutative96.1%
Simplified96.1%
if -1.99999999999999985e-24 < x < 4.59999999999999984e-61Initial program 99.9%
Taylor expanded in x around 0 74.4%
Final simplification87.1%
(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.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e-24) (not (<= x 7.6e-66))) (* x y) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-24) || !(x <= 7.6e-66)) {
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 <= (-3d-24)) .or. (.not. (x <= 7.6d-66))) 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 <= -3e-24) || !(x <= 7.6e-66)) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e-24) or not (x <= 7.6e-66): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e-24) || !(x <= 7.6e-66)) 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 <= -3e-24) || ~((x <= 7.6e-66))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-24], N[Not[LessEqual[x, 7.6e-66]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-24} \lor \neg \left(x \leq 7.6 \cdot 10^{-66}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -2.99999999999999995e-24 or 7.5999999999999995e-66 < x Initial program 100.0%
Taylor expanded in y around inf 57.2%
if -2.99999999999999995e-24 < x < 7.5999999999999995e-66Initial program 99.9%
Taylor expanded in x around 0 74.4%
Final simplification64.4%
(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 33.8%
Final simplification33.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 2023311
(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)))