
(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.9%
+-commutative99.9%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-9) (not (<= x 1.15e-51))) (* x (+ z y)) (+ (* z x) (* z 5.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-9) || !(x <= 1.15e-51)) {
tmp = x * (z + y);
} else {
tmp = (z * x) + (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 <= (-2.7d-9)) .or. (.not. (x <= 1.15d-51))) then
tmp = x * (z + y)
else
tmp = (z * x) + (z * 5.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-9) || !(x <= 1.15e-51)) {
tmp = x * (z + y);
} else {
tmp = (z * x) + (z * 5.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.7e-9) or not (x <= 1.15e-51): tmp = x * (z + y) else: tmp = (z * x) + (z * 5.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-9) || !(x <= 1.15e-51)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(z * x) + Float64(z * 5.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.7e-9) || ~((x <= 1.15e-51))) tmp = x * (z + y); else tmp = (z * x) + (z * 5.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-9], N[Not[LessEqual[x, 1.15e-51]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(z * x), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-9} \lor \neg \left(x \leq 1.15 \cdot 10^{-51}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot x + z \cdot 5\\
\end{array}
\end{array}
if x < -2.7000000000000002e-9 or 1.15000000000000001e-51 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -2.7000000000000002e-9 < x < 1.15000000000000001e-51Initial program 99.8%
Taylor expanded in y around 0 71.1%
*-commutative71.1%
Simplified71.1%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.4e-10) (not (<= x 5.4e-54))) (* x (+ z y)) (* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.4e-10) || !(x <= 5.4e-54)) {
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 <= (-6.4d-10)) .or. (.not. (x <= 5.4d-54))) 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 <= -6.4e-10) || !(x <= 5.4e-54)) {
tmp = x * (z + y);
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.4e-10) or not (x <= 5.4e-54): tmp = x * (z + y) else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.4e-10) || !(x <= 5.4e-54)) 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 <= -6.4e-10) || ~((x <= 5.4e-54))) tmp = x * (z + y); else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.4e-10], N[Not[LessEqual[x, 5.4e-54]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-10} \lor \neg \left(x \leq 5.4 \cdot 10^{-54}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -6.39999999999999961e-10 or 5.40000000000000051e-54 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -6.39999999999999961e-10 < x < 5.40000000000000051e-54Initial program 99.8%
Taylor expanded in x around 0 70.6%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.4e-8) (not (<= x 1.62e-53))) (* x (+ z y)) (* z (+ 5.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-8) || !(x <= 1.62e-53)) {
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 <= (-3.4d-8)) .or. (.not. (x <= 1.62d-53))) 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 <= -3.4e-8) || !(x <= 1.62e-53)) {
tmp = x * (z + y);
} else {
tmp = z * (5.0 + x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e-8) or not (x <= 1.62e-53): tmp = x * (z + y) else: tmp = z * (5.0 + x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e-8) || !(x <= 1.62e-53)) 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 <= -3.4e-8) || ~((x <= 1.62e-53))) tmp = x * (z + y); else tmp = z * (5.0 + x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e-8], N[Not[LessEqual[x, 1.62e-53]], $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 -3.4 \cdot 10^{-8} \lor \neg \left(x \leq 1.62 \cdot 10^{-53}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\end{array}
\end{array}
if x < -3.4e-8 or 1.62e-53 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -3.4e-8 < x < 1.62e-53Initial program 99.8%
Taylor expanded in y around 0 71.1%
distribute-rgt-in71.1%
Simplified71.1%
Final simplification86.8%
(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 (<= z -1.5e+49) (not (<= z 4.8e+89))) (* z 5.0) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e+49) || !(z <= 4.8e+89)) {
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 ((z <= (-1.5d+49)) .or. (.not. (z <= 4.8d+89))) 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 ((z <= -1.5e+49) || !(z <= 4.8e+89)) {
tmp = z * 5.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.5e+49) or not (z <= 4.8e+89): tmp = z * 5.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.5e+49) || !(z <= 4.8e+89)) 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 ((z <= -1.5e+49) || ~((z <= 4.8e+89))) tmp = z * 5.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.5e+49], N[Not[LessEqual[z, 4.8e+89]], $MachinePrecision]], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+49} \lor \neg \left(z \leq 4.8 \cdot 10^{+89}\right):\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -1.5000000000000001e49 or 4.80000000000000009e89 < z Initial program 99.9%
Taylor expanded in x around 0 48.9%
if -1.5000000000000001e49 < z < 4.80000000000000009e89Initial program 99.9%
Taylor expanded in y around inf 65.6%
Final simplification59.3%
(FPCore (x y z) :precision binary64 (if (<= z -9.5e-38) (* z x) (if (<= z 6e+85) (* x y) (* z 5.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-38) {
tmp = z * x;
} else if (z <= 6e+85) {
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 (z <= (-9.5d-38)) then
tmp = z * x
else if (z <= 6d+85) 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 (z <= -9.5e-38) {
tmp = z * x;
} else if (z <= 6e+85) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.5e-38: tmp = z * x elif z <= 6e+85: tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.5e-38) tmp = Float64(z * x); elseif (z <= 6e+85) 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 (z <= -9.5e-38) tmp = z * x; elseif (z <= 6e+85) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.5e-38], N[(z * x), $MachinePrecision], If[LessEqual[z, 6e+85], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-38}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 6 \cdot 10^{+85}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if z < -9.5000000000000009e-38Initial program 99.9%
Taylor expanded in x around inf 59.6%
+-commutative59.6%
Simplified59.6%
Taylor expanded in z around inf 45.8%
if -9.5000000000000009e-38 < z < 6.0000000000000001e85Initial program 99.9%
Taylor expanded in y around inf 68.6%
if 6.0000000000000001e85 < z Initial program 99.9%
Taylor expanded in x around 0 53.0%
Final simplification59.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 32.0%
Final simplification32.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 2023318
(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)))