
(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.9%
+-commutative99.9%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -5.0)
(* z x)
(if (<= x 4e-100)
(* z 5.0)
(if (<= x 1.76e+19)
(* x y)
(if (or (<= x 1.55e+62) (and (not (<= x 6.2e+111)) (<= x 8e+214)))
(* z x)
(* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.0) {
tmp = z * x;
} else if (x <= 4e-100) {
tmp = z * 5.0;
} else if (x <= 1.76e+19) {
tmp = x * y;
} else if ((x <= 1.55e+62) || (!(x <= 6.2e+111) && (x <= 8e+214))) {
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 <= (-5.0d0)) then
tmp = z * x
else if (x <= 4d-100) then
tmp = z * 5.0d0
else if (x <= 1.76d+19) then
tmp = x * y
else if ((x <= 1.55d+62) .or. (.not. (x <= 6.2d+111)) .and. (x <= 8d+214)) 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 <= -5.0) {
tmp = z * x;
} else if (x <= 4e-100) {
tmp = z * 5.0;
} else if (x <= 1.76e+19) {
tmp = x * y;
} else if ((x <= 1.55e+62) || (!(x <= 6.2e+111) && (x <= 8e+214))) {
tmp = z * x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.0: tmp = z * x elif x <= 4e-100: tmp = z * 5.0 elif x <= 1.76e+19: tmp = x * y elif (x <= 1.55e+62) or (not (x <= 6.2e+111) and (x <= 8e+214)): tmp = z * x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.0) tmp = Float64(z * x); elseif (x <= 4e-100) tmp = Float64(z * 5.0); elseif (x <= 1.76e+19) tmp = Float64(x * y); elseif ((x <= 1.55e+62) || (!(x <= 6.2e+111) && (x <= 8e+214))) 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 <= -5.0) tmp = z * x; elseif (x <= 4e-100) tmp = z * 5.0; elseif (x <= 1.76e+19) tmp = x * y; elseif ((x <= 1.55e+62) || (~((x <= 6.2e+111)) && (x <= 8e+214))) tmp = z * x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 4e-100], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 1.76e+19], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 1.55e+62], And[N[Not[LessEqual[x, 6.2e+111]], $MachinePrecision], LessEqual[x, 8e+214]]], N[(z * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 4 \cdot 10^{-100}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq 1.76 \cdot 10^{+19}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{+62} \lor \neg \left(x \leq 6.2 \cdot 10^{+111}\right) \land x \leq 8 \cdot 10^{+214}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5 or 1.76e19 < x < 1.55000000000000007e62 or 6.2000000000000001e111 < x < 7.9999999999999996e214Initial program 100.0%
Taylor expanded in y around 0 64.5%
+-commutative64.5%
*-commutative64.5%
distribute-rgt-in64.5%
Simplified64.5%
Taylor expanded in x around inf 64.5%
if -5 < x < 4.0000000000000001e-100Initial program 99.9%
Taylor expanded in x around 0 71.9%
if 4.0000000000000001e-100 < x < 1.76e19 or 1.55000000000000007e62 < x < 6.2000000000000001e111 or 7.9999999999999996e214 < x Initial program 100.0%
Taylor expanded in y around inf 67.8%
Final simplification68.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4e-119) (not (<= z 1.05e-62))) (* z (+ 5.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4e-119) || !(z <= 1.05e-62)) {
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 <= (-4d-119)) .or. (.not. (z <= 1.05d-62))) 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 <= -4e-119) || !(z <= 1.05e-62)) {
tmp = z * (5.0 + x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4e-119) or not (z <= 1.05e-62): tmp = z * (5.0 + x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4e-119) || !(z <= 1.05e-62)) 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 <= -4e-119) || ~((z <= 1.05e-62))) tmp = z * (5.0 + x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4e-119], N[Not[LessEqual[z, 1.05e-62]], $MachinePrecision]], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{-119} \lor \neg \left(z \leq 1.05 \cdot 10^{-62}\right):\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -4.00000000000000005e-119 or 1.05e-62 < z Initial program 99.9%
Taylor expanded in y around 0 83.1%
+-commutative83.1%
*-commutative83.1%
distribute-rgt-in83.2%
Simplified83.2%
if -4.00000000000000005e-119 < z < 1.05e-62Initial program 100.0%
Taylor expanded in y around inf 75.5%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.8e-118) (not (<= z 2.15e-61))) (* z (+ 5.0 x)) (* x (+ z y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e-118) || !(z <= 2.15e-61)) {
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 <= (-5.8d-118)) .or. (.not. (z <= 2.15d-61))) 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 <= -5.8e-118) || !(z <= 2.15e-61)) {
tmp = z * (5.0 + x);
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.8e-118) or not (z <= 2.15e-61): tmp = z * (5.0 + x) else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.8e-118) || !(z <= 2.15e-61)) 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 <= -5.8e-118) || ~((z <= 2.15e-61))) tmp = z * (5.0 + x); else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.8e-118], N[Not[LessEqual[z, 2.15e-61]], $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 -5.8 \cdot 10^{-118} \lor \neg \left(z \leq 2.15 \cdot 10^{-61}\right):\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if z < -5.79999999999999961e-118 or 2.1500000000000002e-61 < z Initial program 99.9%
Taylor expanded in y around 0 83.1%
+-commutative83.1%
*-commutative83.1%
distribute-rgt-in83.2%
Simplified83.2%
if -5.79999999999999961e-118 < z < 2.1500000000000002e-61Initial program 100.0%
Taylor expanded in x around inf 83.9%
+-commutative83.9%
Simplified83.9%
Final simplification83.5%
(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 -1.4e-11) (* x y) (if (<= x 7.5e-101) (* z 5.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e-11) {
tmp = x * y;
} else if (x <= 7.5e-101) {
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 <= (-1.4d-11)) then
tmp = x * y
else if (x <= 7.5d-101) 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 <= -1.4e-11) {
tmp = x * y;
} else if (x <= 7.5e-101) {
tmp = z * 5.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.4e-11: tmp = x * y elif x <= 7.5e-101: tmp = z * 5.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.4e-11) tmp = Float64(x * y); elseif (x <= 7.5e-101) 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 <= -1.4e-11) tmp = x * y; elseif (x <= 7.5e-101) tmp = z * 5.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.4e-11], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.5e-101], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-101}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.4e-11 or 7.5000000000000001e-101 < x Initial program 100.0%
Taylor expanded in y around inf 51.4%
if -1.4e-11 < x < 7.5000000000000001e-101Initial program 99.9%
Taylor expanded in x around 0 72.4%
Final simplification60.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.9%
Taylor expanded in x around 0 37.2%
Final simplification37.2%
(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 2023192
(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)))