
(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 99.9%
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 (or (<= x -1.45e-6) (not (<= x 1.25e-81))) (* (+ z y) x) (fma z 5.0 (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e-6) || !(x <= 1.25e-81)) {
tmp = (z + y) * x;
} else {
tmp = fma(z, 5.0, (x * z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.45e-6) || !(x <= 1.25e-81)) tmp = Float64(Float64(z + y) * x); else tmp = fma(z, 5.0, Float64(x * z)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.45e-6], N[Not[LessEqual[x, 1.25e-81]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(z * 5.0 + N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-6} \lor \neg \left(x \leq 1.25 \cdot 10^{-81}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
\end{array}
\end{array}
if x < -1.4500000000000001e-6 or 1.24999999999999995e-81 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6451.8
Applied rewrites51.8%
Applied rewrites45.2%
Taylor expanded in x around 0
Applied rewrites5.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6496.0
Applied rewrites96.0%
if -1.4500000000000001e-6 < x < 1.24999999999999995e-81Initial program 99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6482.2
Applied rewrites82.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6482.3
Applied rewrites82.3%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (<= x -4.7e+215) (* y x) (if (<= x -14000000.0) (* z x) (if (<= x 1.25e-81) (* 5.0 z) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.7e+215) {
tmp = y * x;
} else if (x <= -14000000.0) {
tmp = z * x;
} else if (x <= 1.25e-81) {
tmp = 5.0 * 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 (x <= (-4.7d+215)) then
tmp = y * x
else if (x <= (-14000000.0d0)) then
tmp = z * x
else if (x <= 1.25d-81) then
tmp = 5.0d0 * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.7e+215) {
tmp = y * x;
} else if (x <= -14000000.0) {
tmp = z * x;
} else if (x <= 1.25e-81) {
tmp = 5.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.7e+215: tmp = y * x elif x <= -14000000.0: tmp = z * x elif x <= 1.25e-81: tmp = 5.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.7e+215) tmp = Float64(y * x); elseif (x <= -14000000.0) tmp = Float64(z * x); elseif (x <= 1.25e-81) tmp = Float64(5.0 * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.7e+215) tmp = y * x; elseif (x <= -14000000.0) tmp = z * x; elseif (x <= 1.25e-81) tmp = 5.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.7e+215], N[(y * x), $MachinePrecision], If[LessEqual[x, -14000000.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 1.25e-81], N[(5.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{+215}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -14000000:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-81}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -4.7000000000000002e215 or 1.24999999999999995e-81 < x Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6459.2
Applied rewrites59.2%
if -4.7000000000000002e215 < x < -1.4e7Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6467.4
Applied rewrites67.4%
Applied rewrites55.8%
Taylor expanded in x around 0
Applied rewrites1.6%
Taylor expanded in x around inf
Applied rewrites67.4%
if -1.4e7 < x < 1.24999999999999995e-81Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6479.7
Applied rewrites79.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.45e-6) (not (<= x 1.25e-81))) (* (+ z y) x) (* (+ 5.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e-6) || !(x <= 1.25e-81)) {
tmp = (z + y) * x;
} else {
tmp = (5.0 + 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 <= (-1.45d-6)) .or. (.not. (x <= 1.25d-81))) then
tmp = (z + y) * x
else
tmp = (5.0d0 + x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e-6) || !(x <= 1.25e-81)) {
tmp = (z + y) * x;
} else {
tmp = (5.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.45e-6) or not (x <= 1.25e-81): tmp = (z + y) * x else: tmp = (5.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.45e-6) || !(x <= 1.25e-81)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(5.0 + x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.45e-6) || ~((x <= 1.25e-81))) tmp = (z + y) * x; else tmp = (5.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.45e-6], N[Not[LessEqual[x, 1.25e-81]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-6} \lor \neg \left(x \leq 1.25 \cdot 10^{-81}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -1.4500000000000001e-6 or 1.24999999999999995e-81 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6451.8
Applied rewrites51.8%
Applied rewrites45.2%
Taylor expanded in x around 0
Applied rewrites5.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6496.0
Applied rewrites96.0%
if -1.4500000000000001e-6 < x < 1.24999999999999995e-81Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6482.2
Applied rewrites82.2%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.1e-132) (not (<= z 8.8e-113))) (* (+ 5.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-132) || !(z <= 8.8e-113)) {
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 <= (-1.1d-132)) .or. (.not. (z <= 8.8d-113))) 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 <= -1.1e-132) || !(z <= 8.8e-113)) {
tmp = (5.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.1e-132) or not (z <= 8.8e-113): tmp = (5.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.1e-132) || !(z <= 8.8e-113)) 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 <= -1.1e-132) || ~((z <= 8.8e-113))) tmp = (5.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.1e-132], N[Not[LessEqual[z, 8.8e-113]], $MachinePrecision]], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{-132} \lor \neg \left(z \leq 8.8 \cdot 10^{-113}\right):\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -1.09999999999999995e-132 or 8.80000000000000016e-113 < z Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6485.1
Applied rewrites85.1%
if -1.09999999999999995e-132 < z < 8.80000000000000016e-113Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6473.2
Applied rewrites73.2%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -14000000.0) (not (<= x 5.0))) (* z x) (* 5.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -14000000.0) || !(x <= 5.0)) {
tmp = z * x;
} 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 <= (-14000000.0d0)) .or. (.not. (x <= 5.0d0))) then
tmp = z * x
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 <= -14000000.0) || !(x <= 5.0)) {
tmp = z * x;
} else {
tmp = 5.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -14000000.0) or not (x <= 5.0): tmp = z * x else: tmp = 5.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -14000000.0) || !(x <= 5.0)) tmp = Float64(z * x); else tmp = Float64(5.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -14000000.0) || ~((x <= 5.0))) tmp = z * x; else tmp = 5.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -14000000.0], N[Not[LessEqual[x, 5.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -14000000 \lor \neg \left(x \leq 5\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;5 \cdot z\\
\end{array}
\end{array}
if x < -1.4e7 or 5 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6453.5
Applied rewrites53.5%
Applied rewrites46.2%
Taylor expanded in x around 0
Applied rewrites1.6%
Taylor expanded in x around inf
Applied rewrites52.8%
if -1.4e7 < x < 5Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6477.0
Applied rewrites77.0%
Final simplification65.5%
(FPCore (x y z) :precision binary64 (* z x))
double code(double x, double y, double z) {
return z * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * x
end function
public static double code(double x, double y, double z) {
return z * x;
}
def code(x, y, z): return z * x
function code(x, y, z) return Float64(z * x) end
function tmp = code(x, y, z) tmp = z * x; end
code[x_, y_, z_] := N[(z * x), $MachinePrecision]
\begin{array}{l}
\\
z \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6466.1
Applied rewrites66.1%
Applied rewrites62.1%
Taylor expanded in x around 0
Applied rewrites40.8%
Taylor expanded in x around inf
Applied rewrites26.9%
(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 2024339
(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)))