
(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 4 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 (+ (* 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}
Initial program 99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -8.5e-96) t_0 (if (<= x 5.1e-49) (* z 5.0) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -8.5e-96) {
tmp = t_0;
} else if (x <= 5.1e-49) {
tmp = z * 5.0;
} 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 <= (-8.5d-96)) then
tmp = t_0
else if (x <= 5.1d-49) then
tmp = z * 5.0d0
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 <= -8.5e-96) {
tmp = t_0;
} else if (x <= 5.1e-49) {
tmp = z * 5.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -8.5e-96: tmp = t_0 elif x <= 5.1e-49: tmp = z * 5.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -8.5e-96) tmp = t_0; elseif (x <= 5.1e-49) tmp = Float64(z * 5.0); 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 <= -8.5e-96) tmp = t_0; elseif (x <= 5.1e-49) tmp = z * 5.0; 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, -8.5e-96], t$95$0, If[LessEqual[x, 5.1e-49], N[(z * 5.0), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{-96}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.1 \cdot 10^{-49}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.49999999999999983e-96 or 5.10000000000000026e-49 < x Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites91.9%
if -8.49999999999999983e-96 < x < 5.10000000000000026e-49Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites83.3%
(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 inf
Applied rewrites35.6%
(FPCore (x y z) :precision binary64 (+ y z))
double code(double x, double y, double z) {
return y + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + z
end function
public static double code(double x, double y, double z) {
return y + z;
}
def code(x, y, z): return y + z
function code(x, y, z) return Float64(y + z) end
function tmp = code(x, y, z) tmp = y + z; end
code[x_, y_, z_] := N[(y + z), $MachinePrecision]
\begin{array}{l}
\\
y + z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites65.7%
Taylor expanded in x around 0
Applied rewrites6.7%
(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 2024321
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (+ (* (+ x 5) z) (* x y)))
(+ (* x (+ y z)) (* z 5.0)))