
(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 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%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -290000.0) t_0 (if (<= x 5.0) (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 <= -290000.0) {
tmp = t_0;
} else if (x <= 5.0) {
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 <= -290000.0) tmp = t_0; elseif (x <= 5.0) 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, -290000.0], t$95$0, If[LessEqual[x, 5.0], 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 -290000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.9e5 or 5 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
if -2.9e5 < x < 5Initial 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-*.f6498.9
Applied rewrites98.9%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= y -1.1e+82) t_0 (if (<= y 2.1e+59) (* (- x -5.0) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (y <= -1.1e+82) {
tmp = t_0;
} else if (y <= 2.1e+59) {
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 (y <= (-1.1d+82)) then
tmp = t_0
else if (y <= 2.1d+59) 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 (y <= -1.1e+82) {
tmp = t_0;
} else if (y <= 2.1e+59) {
tmp = (x - -5.0) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if y <= -1.1e+82: tmp = t_0 elif y <= 2.1e+59: 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 (y <= -1.1e+82) tmp = t_0; elseif (y <= 2.1e+59) 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 (y <= -1.1e+82) tmp = t_0; elseif (y <= 2.1e+59) 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[y, -1.1e+82], t$95$0, If[LessEqual[y, 2.1e+59], 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}\;y \leq -1.1 \cdot 10^{+82}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+59}:\\
\;\;\;\;\left(x - -5\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.1000000000000001e82 or 2.09999999999999984e59 < y Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6484.6
Applied rewrites84.6%
if -1.1000000000000001e82 < y < 2.09999999999999984e59Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6482.7
Applied rewrites82.7%
Final simplification83.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -1.3e-51) t_0 (if (<= x 4.45e-13) (* 5.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -1.3e-51) {
tmp = t_0;
} else if (x <= 4.45e-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 <= (-1.3d-51)) then
tmp = t_0
else if (x <= 4.45d-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 <= -1.3e-51) {
tmp = t_0;
} else if (x <= 4.45e-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 <= -1.3e-51: tmp = t_0 elif x <= 4.45e-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 <= -1.3e-51) tmp = t_0; elseif (x <= 4.45e-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 <= -1.3e-51) tmp = t_0; elseif (x <= 4.45e-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, -1.3e-51], t$95$0, If[LessEqual[x, 4.45e-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 -1.3 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.45 \cdot 10^{-13}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.3e-51 or 4.4500000000000002e-13 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.1
Applied rewrites98.1%
if -1.3e-51 < x < 4.4500000000000002e-13Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6470.6
Applied rewrites70.6%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.1e+82) (* x y) (if (<= y 2.1e+59) (* 5.0 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+82) {
tmp = x * y;
} else if (y <= 2.1e+59) {
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 (y <= (-1.1d+82)) then
tmp = x * y
else if (y <= 2.1d+59) 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 (y <= -1.1e+82) {
tmp = x * y;
} else if (y <= 2.1e+59) {
tmp = 5.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.1e+82: tmp = x * y elif y <= 2.1e+59: tmp = 5.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.1e+82) tmp = Float64(x * y); elseif (y <= 2.1e+59) 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 (y <= -1.1e+82) tmp = x * y; elseif (y <= 2.1e+59) tmp = 5.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.1e+82], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.1e+59], N[(5.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+82}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+59}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.1000000000000001e82 or 2.09999999999999984e59 < y Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6479.2
Applied rewrites79.2%
if -1.1000000000000001e82 < y < 2.09999999999999984e59Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6455.8
Applied rewrites55.8%
Final simplification65.6%
(FPCore (x y z) :precision binary64 (if (<= x -290000.0) (* x z) (if (<= x 2.4e+16) (* 5.0 z) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -290000.0) {
tmp = x * z;
} else if (x <= 2.4e+16) {
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 <= (-290000.0d0)) then
tmp = x * z
else if (x <= 2.4d+16) 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 <= -290000.0) {
tmp = x * z;
} else if (x <= 2.4e+16) {
tmp = 5.0 * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -290000.0: tmp = x * z elif x <= 2.4e+16: tmp = 5.0 * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -290000.0) tmp = Float64(x * z); elseif (x <= 2.4e+16) 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 <= -290000.0) tmp = x * z; elseif (x <= 2.4e+16) tmp = 5.0 * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -290000.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.4e+16], N[(5.0 * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -290000:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{+16}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.9e5 or 2.4e16 < 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--.f6445.2
Applied rewrites45.2%
Taylor expanded in x around inf
Applied rewrites44.7%
if -2.9e5 < x < 2.4e16Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6466.8
Applied rewrites66.8%
Final simplification57.4%
(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 z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6458.2
Applied rewrites58.2%
Taylor expanded in x around inf
Applied rewrites21.3%
Final simplification21.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 2024270
(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)))