
(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 9 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 (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.9%
distribute-lft-in99.9%
associate-+l+99.9%
*-commutative99.9%
fma-def99.9%
distribute-lft-out99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= x -2.75e-33)
(* x y)
(if (<= x 6.4e-34)
(* z 5.0)
(if (<= x 1.45e+40) (* x y) (if (<= x 5.5e+258) (* z x) (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.75e-33) {
tmp = x * y;
} else if (x <= 6.4e-34) {
tmp = z * 5.0;
} else if (x <= 1.45e+40) {
tmp = x * y;
} else if (x <= 5.5e+258) {
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 <= (-2.75d-33)) then
tmp = x * y
else if (x <= 6.4d-34) then
tmp = z * 5.0d0
else if (x <= 1.45d+40) then
tmp = x * y
else if (x <= 5.5d+258) 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 <= -2.75e-33) {
tmp = x * y;
} else if (x <= 6.4e-34) {
tmp = z * 5.0;
} else if (x <= 1.45e+40) {
tmp = x * y;
} else if (x <= 5.5e+258) {
tmp = z * x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.75e-33: tmp = x * y elif x <= 6.4e-34: tmp = z * 5.0 elif x <= 1.45e+40: tmp = x * y elif x <= 5.5e+258: tmp = z * x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.75e-33) tmp = Float64(x * y); elseif (x <= 6.4e-34) tmp = Float64(z * 5.0); elseif (x <= 1.45e+40) tmp = Float64(x * y); elseif (x <= 5.5e+258) 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 <= -2.75e-33) tmp = x * y; elseif (x <= 6.4e-34) tmp = z * 5.0; elseif (x <= 1.45e+40) tmp = x * y; elseif (x <= 5.5e+258) tmp = z * x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.75e-33], N[(x * y), $MachinePrecision], If[LessEqual[x, 6.4e-34], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 1.45e+40], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.5e+258], N[(z * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{-33}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6.4 \cdot 10^{-34}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+40}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{+258}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.75e-33 or 6.40000000000000005e-34 < x < 1.45000000000000009e40 or 5.49999999999999978e258 < x Initial program 100.0%
Taylor expanded in y around inf 74.3%
if -2.75e-33 < x < 6.40000000000000005e-34Initial program 99.8%
Taylor expanded in x around 0 77.7%
if 1.45000000000000009e40 < x < 5.49999999999999978e258Initial program 100.0%
Taylor expanded in y around 0 66.2%
+-commutative66.2%
*-commutative66.2%
distribute-rgt-in66.2%
Simplified66.2%
Taylor expanded in x around inf 66.2%
Final simplification74.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e-10) (not (<= x 2.9e-8))) (* x (+ z y)) (* z (+ 5.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-10) || !(x <= 2.9e-8)) {
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 <= (-9.5d-10)) .or. (.not. (x <= 2.9d-8))) 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 <= -9.5e-10) || !(x <= 2.9e-8)) {
tmp = x * (z + y);
} else {
tmp = z * (5.0 + x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e-10) or not (x <= 2.9e-8): tmp = x * (z + y) else: tmp = z * (5.0 + x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e-10) || !(x <= 2.9e-8)) 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 <= -9.5e-10) || ~((x <= 2.9e-8))) tmp = x * (z + y); else tmp = z * (5.0 + x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e-10], N[Not[LessEqual[x, 2.9e-8]], $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 -9.5 \cdot 10^{-10} \lor \neg \left(x \leq 2.9 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\end{array}
\end{array}
if x < -9.50000000000000028e-10 or 2.9000000000000002e-8 < x Initial program 100.0%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
Simplified99.2%
if -9.50000000000000028e-10 < x < 2.9000000000000002e-8Initial program 99.8%
Taylor expanded in y around 0 76.0%
+-commutative76.0%
*-commutative76.0%
distribute-rgt-in76.1%
Simplified76.1%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= y -2e-6) (* x y) (if (<= y 3.8e-15) (* z (+ 5.0 x)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-6) {
tmp = x * y;
} else if (y <= 3.8e-15) {
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 <= (-2d-6)) then
tmp = x * y
else if (y <= 3.8d-15) 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 <= -2e-6) {
tmp = x * y;
} else if (y <= 3.8e-15) {
tmp = z * (5.0 + x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e-6: tmp = x * y elif y <= 3.8e-15: tmp = z * (5.0 + x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e-6) tmp = Float64(x * y); elseif (y <= 3.8e-15) 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 <= -2e-6) tmp = x * y; elseif (y <= 3.8e-15) tmp = z * (5.0 + x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e-6], N[(x * y), $MachinePrecision], If[LessEqual[y, 3.8e-15], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-6}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-15}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.99999999999999991e-6 or 3.8000000000000002e-15 < y Initial program 99.9%
Taylor expanded in y around inf 76.8%
if -1.99999999999999991e-6 < y < 3.8000000000000002e-15Initial program 99.8%
Taylor expanded in y around 0 83.0%
+-commutative83.0%
*-commutative83.0%
distribute-rgt-in83.0%
Simplified83.0%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (if (<= x -5.6e-10) (+ (* z x) (* x y)) (if (<= x 1.12e-9) (* z (+ 5.0 x)) (* x (+ z y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.6e-10) {
tmp = (z * x) + (x * y);
} else if (x <= 1.12e-9) {
tmp = z * (5.0 + x);
} else {
tmp = x * (z + 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.6d-10)) then
tmp = (z * x) + (x * y)
else if (x <= 1.12d-9) then
tmp = z * (5.0d0 + x)
else
tmp = x * (z + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.6e-10) {
tmp = (z * x) + (x * y);
} else if (x <= 1.12e-9) {
tmp = z * (5.0 + x);
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.6e-10: tmp = (z * x) + (x * y) elif x <= 1.12e-9: tmp = z * (5.0 + x) else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.6e-10) tmp = Float64(Float64(z * x) + Float64(x * y)); elseif (x <= 1.12e-9) tmp = Float64(z * Float64(5.0 + x)); else tmp = Float64(x * Float64(z + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.6e-10) tmp = (z * x) + (x * y); elseif (x <= 1.12e-9) tmp = z * (5.0 + x); else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.6e-10], N[(N[(z * x), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.12e-9], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-10}:\\
\;\;\;\;z \cdot x + x \cdot y\\
\mathbf{elif}\;x \leq 1.12 \cdot 10^{-9}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if x < -5.60000000000000031e-10Initial program 100.0%
Taylor expanded in x around inf 99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in z around 0 99.8%
if -5.60000000000000031e-10 < x < 1.12000000000000006e-9Initial program 99.8%
Taylor expanded in y around 0 76.0%
+-commutative76.0%
*-commutative76.0%
distribute-rgt-in76.1%
Simplified76.1%
if 1.12000000000000006e-9 < x Initial program 100.0%
Taylor expanded in x around inf 98.8%
+-commutative98.8%
Simplified98.8%
Final simplification88.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 (<= x -2.75e-33) (* x y) (if (<= x 1.7e-34) (* z 5.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.75e-33) {
tmp = x * y;
} else if (x <= 1.7e-34) {
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 <= (-2.75d-33)) then
tmp = x * y
else if (x <= 1.7d-34) 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 <= -2.75e-33) {
tmp = x * y;
} else if (x <= 1.7e-34) {
tmp = z * 5.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.75e-33: tmp = x * y elif x <= 1.7e-34: tmp = z * 5.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.75e-33) tmp = Float64(x * y); elseif (x <= 1.7e-34) 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 <= -2.75e-33) tmp = x * y; elseif (x <= 1.7e-34) tmp = z * 5.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.75e-33], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.7e-34], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{-33}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-34}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.75e-33 or 1.7e-34 < x Initial program 100.0%
Taylor expanded in y around inf 63.4%
if -2.75e-33 < x < 1.7e-34Initial program 99.8%
Taylor expanded in x around 0 77.7%
Final simplification69.8%
(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 38.0%
Final simplification38.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 2023238
(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)))