
(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 (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.6%
+-commutative99.6%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -7.6e+159)
(* z x)
(if (<= z -1.15e+135)
(* z 5.0)
(if (<= z -5.2e+118)
(* z x)
(if (or (<= z 1.7e-76) (and (not (<= z 1.26e+17)) (<= z 8.2e+82)))
(* x y)
(* z 5.0))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e+159) {
tmp = z * x;
} else if (z <= -1.15e+135) {
tmp = z * 5.0;
} else if (z <= -5.2e+118) {
tmp = z * x;
} else if ((z <= 1.7e-76) || (!(z <= 1.26e+17) && (z <= 8.2e+82))) {
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 <= (-7.6d+159)) then
tmp = z * x
else if (z <= (-1.15d+135)) then
tmp = z * 5.0d0
else if (z <= (-5.2d+118)) then
tmp = z * x
else if ((z <= 1.7d-76) .or. (.not. (z <= 1.26d+17)) .and. (z <= 8.2d+82)) 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 <= -7.6e+159) {
tmp = z * x;
} else if (z <= -1.15e+135) {
tmp = z * 5.0;
} else if (z <= -5.2e+118) {
tmp = z * x;
} else if ((z <= 1.7e-76) || (!(z <= 1.26e+17) && (z <= 8.2e+82))) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.6e+159: tmp = z * x elif z <= -1.15e+135: tmp = z * 5.0 elif z <= -5.2e+118: tmp = z * x elif (z <= 1.7e-76) or (not (z <= 1.26e+17) and (z <= 8.2e+82)): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.6e+159) tmp = Float64(z * x); elseif (z <= -1.15e+135) tmp = Float64(z * 5.0); elseif (z <= -5.2e+118) tmp = Float64(z * x); elseif ((z <= 1.7e-76) || (!(z <= 1.26e+17) && (z <= 8.2e+82))) 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 <= -7.6e+159) tmp = z * x; elseif (z <= -1.15e+135) tmp = z * 5.0; elseif (z <= -5.2e+118) tmp = z * x; elseif ((z <= 1.7e-76) || (~((z <= 1.26e+17)) && (z <= 8.2e+82))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.6e+159], N[(z * x), $MachinePrecision], If[LessEqual[z, -1.15e+135], N[(z * 5.0), $MachinePrecision], If[LessEqual[z, -5.2e+118], N[(z * x), $MachinePrecision], If[Or[LessEqual[z, 1.7e-76], And[N[Not[LessEqual[z, 1.26e+17]], $MachinePrecision], LessEqual[z, 8.2e+82]]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{+159}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq -1.15 \cdot 10^{+135}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;z \leq -5.2 \cdot 10^{+118}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{-76} \lor \neg \left(z \leq 1.26 \cdot 10^{+17}\right) \land z \leq 8.2 \cdot 10^{+82}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if z < -7.5999999999999993e159 or -1.1500000000000001e135 < z < -5.20000000000000032e118Initial program 96.4%
Taylor expanded in y around 0 93.2%
+-commutative93.2%
*-commutative93.2%
distribute-rgt-in96.7%
Simplified96.7%
Taylor expanded in x around inf 69.9%
if -7.5999999999999993e159 < z < -1.1500000000000001e135 or 1.7e-76 < z < 1.26e17 or 8.1999999999999999e82 < z Initial program 99.9%
Taylor expanded in x around 0 62.0%
if -5.20000000000000032e118 < z < 1.7e-76 or 1.26e17 < z < 8.1999999999999999e82Initial program 100.0%
Taylor expanded in y around inf 71.9%
Final simplification68.7%
(FPCore (x y z)
:precision binary64
(if (<= z -5.2e+129)
(* z 5.0)
(if (or (<= z 2e-76) (and (not (<= z 80000000.0)) (<= z 9.5e+82)))
(* x y)
(* z 5.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e+129) {
tmp = z * 5.0;
} else if ((z <= 2e-76) || (!(z <= 80000000.0) && (z <= 9.5e+82))) {
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 <= (-5.2d+129)) then
tmp = z * 5.0d0
else if ((z <= 2d-76) .or. (.not. (z <= 80000000.0d0)) .and. (z <= 9.5d+82)) 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 <= -5.2e+129) {
tmp = z * 5.0;
} else if ((z <= 2e-76) || (!(z <= 80000000.0) && (z <= 9.5e+82))) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.2e+129: tmp = z * 5.0 elif (z <= 2e-76) or (not (z <= 80000000.0) and (z <= 9.5e+82)): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.2e+129) tmp = Float64(z * 5.0); elseif ((z <= 2e-76) || (!(z <= 80000000.0) && (z <= 9.5e+82))) 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 <= -5.2e+129) tmp = z * 5.0; elseif ((z <= 2e-76) || (~((z <= 80000000.0)) && (z <= 9.5e+82))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.2e+129], N[(z * 5.0), $MachinePrecision], If[Or[LessEqual[z, 2e-76], And[N[Not[LessEqual[z, 80000000.0]], $MachinePrecision], LessEqual[z, 9.5e+82]]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+129}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-76} \lor \neg \left(z \leq 80000000\right) \land z \leq 9.5 \cdot 10^{+82}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if z < -5.20000000000000024e129 or 1.99999999999999985e-76 < z < 8e7 or 9.50000000000000049e82 < z Initial program 98.9%
Taylor expanded in x around 0 54.2%
if -5.20000000000000024e129 < z < 1.99999999999999985e-76 or 8e7 < z < 9.50000000000000049e82Initial program 100.0%
Taylor expanded in y around inf 71.2%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.7e-41) (not (<= z 1.5e-76))) (* z (+ 5.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e-41) || !(z <= 1.5e-76)) {
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 ((z <= (-1.7d-41)) .or. (.not. (z <= 1.5d-76))) 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 ((z <= -1.7e-41) || !(z <= 1.5e-76)) {
tmp = z * (5.0 + x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e-41) or not (z <= 1.5e-76): tmp = z * (5.0 + x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e-41) || !(z <= 1.5e-76)) 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 ((z <= -1.7e-41) || ~((z <= 1.5e-76))) tmp = z * (5.0 + x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e-41], N[Not[LessEqual[z, 1.5e-76]], $MachinePrecision]], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-41} \lor \neg \left(z \leq 1.5 \cdot 10^{-76}\right):\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -1.6999999999999999e-41 or 1.50000000000000012e-76 < z Initial program 99.2%
Taylor expanded in y around 0 83.5%
+-commutative83.5%
*-commutative83.5%
distribute-rgt-in84.2%
Simplified84.2%
if -1.6999999999999999e-41 < z < 1.50000000000000012e-76Initial program 100.0%
Taylor expanded in y around inf 79.0%
Final simplification81.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.2e+129) (not (<= z 1.8e-76))) (* z (+ 5.0 x)) (* x (+ z y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+129) || !(z <= 1.8e-76)) {
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 ((z <= (-4.2d+129)) .or. (.not. (z <= 1.8d-76))) 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 ((z <= -4.2e+129) || !(z <= 1.8e-76)) {
tmp = z * (5.0 + x);
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.2e+129) or not (z <= 1.8e-76): tmp = z * (5.0 + x) else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.2e+129) || !(z <= 1.8e-76)) 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 ((z <= -4.2e+129) || ~((z <= 1.8e-76))) tmp = z * (5.0 + x); else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.2e+129], N[Not[LessEqual[z, 1.8e-76]], $MachinePrecision]], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+129} \lor \neg \left(z \leq 1.8 \cdot 10^{-76}\right):\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if z < -4.19999999999999993e129 or 1.8e-76 < z Initial program 99.1%
Taylor expanded in y around 0 89.6%
+-commutative89.6%
*-commutative89.6%
distribute-rgt-in90.5%
Simplified90.5%
if -4.19999999999999993e129 < z < 1.8e-76Initial program 100.0%
Taylor expanded in x around inf 82.2%
+-commutative82.2%
Simplified82.2%
Final simplification85.9%
(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.6%
Final simplification99.6%
(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.6%
Taylor expanded in x around 0 33.3%
Final simplification33.3%
(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 2023230
(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)))