
(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 (* (+ z y) x)))
double code(double x, double y, double z) {
return fma(z, 5.0, ((z + y) * x));
}
function code(x, y, z) return fma(z, 5.0, Float64(Float64(z + y) * x)) end
code[x_, y_, z_] := N[(z * 5.0 + N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, 5, \left(z + y\right) \cdot x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= x -5.0) (* x z) (if (<= x 7.5e-57) (* 5.0 z) (if (<= x 1.45e+139) (* y x) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.0) {
tmp = x * z;
} else if (x <= 7.5e-57) {
tmp = 5.0 * z;
} else if (x <= 1.45e+139) {
tmp = y * x;
} else {
tmp = x * z;
}
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 = x * z
else if (x <= 7.5d-57) then
tmp = 5.0d0 * z
else if (x <= 1.45d+139) then
tmp = y * x
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.0) {
tmp = x * z;
} else if (x <= 7.5e-57) {
tmp = 5.0 * z;
} else if (x <= 1.45e+139) {
tmp = y * x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.0: tmp = x * z elif x <= 7.5e-57: tmp = 5.0 * z elif x <= 1.45e+139: tmp = y * x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.0) tmp = Float64(x * z); elseif (x <= 7.5e-57) tmp = Float64(5.0 * z); elseif (x <= 1.45e+139) tmp = Float64(y * x); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.0) tmp = x * z; elseif (x <= 7.5e-57) tmp = 5.0 * z; elseif (x <= 1.45e+139) tmp = y * x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 7.5e-57], N[(5.0 * z), $MachinePrecision], If[LessEqual[x, 1.45e+139], N[(y * x), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-57}:\\
\;\;\;\;5 \cdot z\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+139}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -5 or 1.4499999999999999e139 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6464.4
Applied rewrites64.4%
Taylor expanded in x around inf
Applied rewrites63.8%
if -5 < x < 7.49999999999999973e-57Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6469.4
Applied rewrites69.4%
if 7.49999999999999973e-57 < x < 1.4499999999999999e139Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6454.8
Applied rewrites54.8%
(FPCore (x y z) :precision binary64 (if (<= z -3e-45) (* (+ 5.0 x) z) (if (<= z 2.25e-68) (* (+ z y) x) (fma z 5.0 (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3e-45) {
tmp = (5.0 + x) * z;
} else if (z <= 2.25e-68) {
tmp = (z + y) * x;
} else {
tmp = fma(z, 5.0, (x * z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3e-45) tmp = Float64(Float64(5.0 + x) * z); elseif (z <= 2.25e-68) tmp = Float64(Float64(z + y) * x); else tmp = fma(z, 5.0, Float64(x * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3e-45], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 2.25e-68], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(z * 5.0 + N[(x * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-45}:\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\mathbf{elif}\;z \leq 2.25 \cdot 10^{-68}:\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
\end{array}
\end{array}
if z < -3.00000000000000011e-45Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6486.4
Applied rewrites86.4%
if -3.00000000000000011e-45 < z < 2.25e-68Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6424.2
Applied rewrites24.2%
Taylor expanded in x around inf
Applied rewrites11.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6486.9
Applied rewrites86.9%
if 2.25e-68 < z Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6486.7
Applied rewrites86.7%
Applied rewrites86.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-45) (not (<= z 2.25e-68))) (* (+ 5.0 x) z) (* (+ z y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-45) || !(z <= 2.25e-68)) {
tmp = (5.0 + x) * z;
} else {
tmp = (z + y) * 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 ((z <= (-3d-45)) .or. (.not. (z <= 2.25d-68))) then
tmp = (5.0d0 + x) * z
else
tmp = (z + y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-45) || !(z <= 2.25e-68)) {
tmp = (5.0 + x) * z;
} else {
tmp = (z + y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e-45) or not (z <= 2.25e-68): tmp = (5.0 + x) * z else: tmp = (z + y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e-45) || !(z <= 2.25e-68)) tmp = Float64(Float64(5.0 + x) * z); else tmp = Float64(Float64(z + y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e-45) || ~((z <= 2.25e-68))) tmp = (5.0 + x) * z; else tmp = (z + y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-45], N[Not[LessEqual[z, 2.25e-68]], $MachinePrecision]], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-45} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\right):\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) \cdot x\\
\end{array}
\end{array}
if z < -3.00000000000000011e-45 or 2.25e-68 < z Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6486.6
Applied rewrites86.6%
if -3.00000000000000011e-45 < z < 2.25e-68Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6424.2
Applied rewrites24.2%
Taylor expanded in x around inf
Applied rewrites11.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6486.9
Applied rewrites86.9%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e-55) (not (<= z 2.25e-68))) (* (+ 5.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-55) || !(z <= 2.25e-68)) {
tmp = (5.0 + x) * z;
} else {
tmp = y * 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 ((z <= (-3.5d-55)) .or. (.not. (z <= 2.25d-68))) then
tmp = (5.0d0 + x) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-55) || !(z <= 2.25e-68)) {
tmp = (5.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e-55) or not (z <= 2.25e-68): tmp = (5.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e-55) || !(z <= 2.25e-68)) tmp = Float64(Float64(5.0 + x) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.5e-55) || ~((z <= 2.25e-68))) tmp = (5.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.5e-55], N[Not[LessEqual[z, 2.25e-68]], $MachinePrecision]], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-55} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\right):\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -3.50000000000000025e-55 or 2.25e-68 < z Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6486.2
Applied rewrites86.2%
if -3.50000000000000025e-55 < z < 2.25e-68Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6478.6
Applied rewrites78.6%
Final simplification83.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.0) (not (<= x 0.00034))) (* x z) (* 5.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.0) || !(x <= 0.00034)) {
tmp = x * z;
} else {
tmp = 5.0 * z;
}
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)) .or. (.not. (x <= 0.00034d0))) then
tmp = x * z
else
tmp = 5.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.0) || !(x <= 0.00034)) {
tmp = x * z;
} else {
tmp = 5.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.0) or not (x <= 0.00034): tmp = x * z else: tmp = 5.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.0) || !(x <= 0.00034)) tmp = Float64(x * z); else tmp = Float64(5.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.0) || ~((x <= 0.00034))) tmp = x * z; else tmp = 5.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.0], N[Not[LessEqual[x, 0.00034]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \lor \neg \left(x \leq 0.00034\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;5 \cdot z\\
\end{array}
\end{array}
if x < -5 or 3.4e-4 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6460.4
Applied rewrites60.4%
Taylor expanded in x around inf
Applied rewrites59.3%
if -5 < x < 3.4e-4Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6467.6
Applied rewrites67.6%
Final simplification63.2%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return x * z;
}
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
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6463.9
Applied rewrites63.9%
Taylor expanded in x around inf
Applied rewrites33.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 2024320
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:alt
(! :herbie-platform default (+ (* (+ x 5) z) (* x y)))
(+ (* x (+ y z)) (* z 5.0)))