
(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 (+ y z))))
double code(double x, double y, double z) {
return fma(z, 5.0, (x * (y + z)));
}
function code(x, y, z) return fma(z, 5.0, Float64(x * Float64(y + z))) end
code[x_, y_, z_] := N[(z * 5.0 + N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, 5, x \cdot \left(y + z\right)\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%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -90.0) t_0 (if (<= x 1.65) (fma z 5.0 (* x y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -90.0) {
tmp = t_0;
} else if (x <= 1.65) {
tmp = fma(z, 5.0, (x * y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -90.0) tmp = t_0; elseif (x <= 1.65) tmp = fma(z, 5.0, Float64(x * y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -90.0], t$95$0, If[LessEqual[x, 1.65], N[(z * 5.0 + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -90:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.65:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -90 or 1.6499999999999999 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
if -90 < x < 1.6499999999999999Initial 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%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -3.5e-10) t_0 (if (<= x 3.5e-11) (* (- x -5.0) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -3.5e-10) {
tmp = t_0;
} else if (x <= 3.5e-11) {
tmp = (x - -5.0) * z;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = x * (y + z)
if (x <= (-3.5d-10)) then
tmp = t_0
else if (x <= 3.5d-11) then
tmp = (x - (-5.0d0)) * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -3.5e-10) {
tmp = t_0;
} else if (x <= 3.5e-11) {
tmp = (x - -5.0) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -3.5e-10: tmp = t_0 elif x <= 3.5e-11: tmp = (x - -5.0) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -3.5e-10) tmp = t_0; elseif (x <= 3.5e-11) tmp = Float64(Float64(x - -5.0) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + z); tmp = 0.0; if (x <= -3.5e-10) tmp = t_0; elseif (x <= 3.5e-11) tmp = (x - -5.0) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.5e-10], t$95$0, If[LessEqual[x, 3.5e-11], N[(N[(x - -5.0), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -3.5 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-11}:\\
\;\;\;\;\left(x - -5\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.4999999999999998e-10 or 3.50000000000000019e-11 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
if -3.4999999999999998e-10 < x < 3.50000000000000019e-11Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6470.7
Applied rewrites70.7%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -2.45e-11) t_0 (if (<= x 3.2e-13) (* 5.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -2.45e-11) {
tmp = t_0;
} else if (x <= 3.2e-13) {
tmp = 5.0 * z;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = x * (y + z)
if (x <= (-2.45d-11)) then
tmp = t_0
else if (x <= 3.2d-13) then
tmp = 5.0d0 * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -2.45e-11) {
tmp = t_0;
} else if (x <= 3.2e-13) {
tmp = 5.0 * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -2.45e-11: tmp = t_0 elif x <= 3.2e-13: tmp = 5.0 * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -2.45e-11) tmp = t_0; elseif (x <= 3.2e-13) tmp = Float64(5.0 * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + z); tmp = 0.0; if (x <= -2.45e-11) tmp = t_0; elseif (x <= 3.2e-13) tmp = 5.0 * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.45e-11], t$95$0, If[LessEqual[x, 3.2e-13], N[(5.0 * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -2.45 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-13}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.4499999999999999e-11 or 3.2e-13 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
if -2.4499999999999999e-11 < x < 3.2e-13Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6470.4
Applied rewrites70.4%
Final simplification85.1%
(FPCore (x y z) :precision binary64 (if (<= x -2.3e-11) (* x y) (if (<= x 2.4e-11) (* 5.0 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e-11) {
tmp = x * y;
} else if (x <= 2.4e-11) {
tmp = 5.0 * z;
} 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 <= (-2.3d-11)) then
tmp = x * y
else if (x <= 2.4d-11) then
tmp = 5.0d0 * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e-11) {
tmp = x * y;
} else if (x <= 2.4e-11) {
tmp = 5.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.3e-11: tmp = x * y elif x <= 2.4e-11: tmp = 5.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.3e-11) tmp = Float64(x * y); elseif (x <= 2.4e-11) tmp = Float64(5.0 * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.3e-11) tmp = x * y; elseif (x <= 2.4e-11) tmp = 5.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.3e-11], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.4e-11], N[(5.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-11}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.30000000000000014e-11 or 2.4000000000000001e-11 < x Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6460.0
Applied rewrites60.0%
if -2.30000000000000014e-11 < x < 2.4000000000000001e-11Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6470.4
Applied rewrites70.4%
Final simplification65.1%
(FPCore (x y z) :precision binary64 (if (<= x -7.6e-9) (* x z) (if (<= x 5.0) (* 5.0 z) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.6e-9) {
tmp = x * z;
} else if (x <= 5.0) {
tmp = 5.0 * z;
} 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 <= (-7.6d-9)) then
tmp = x * z
else if (x <= 5.0d0) then
tmp = 5.0d0 * z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.6e-9) {
tmp = x * z;
} else if (x <= 5.0) {
tmp = 5.0 * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.6e-9: tmp = x * z elif x <= 5.0: tmp = 5.0 * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.6e-9) tmp = Float64(x * z); elseif (x <= 5.0) tmp = Float64(5.0 * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.6e-9) tmp = x * z; elseif (x <= 5.0) tmp = 5.0 * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.6e-9], N[(x * z), $MachinePrecision], If[LessEqual[x, 5.0], N[(5.0 * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{-9}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 5:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -7.60000000000000023e-9 or 5 < x Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6446.3
Applied rewrites46.3%
Taylor expanded in x around inf
Applied rewrites45.6%
if -7.60000000000000023e-9 < x < 5Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6469.8
Applied rewrites69.8%
Final simplification57.6%
(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 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6458.1
Applied rewrites58.1%
Taylor expanded in x around inf
Applied rewrites24.9%
Final simplification24.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 2024278
(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)))