
(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 8 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 (* (+ y z) x)))
double code(double x, double y, double z) {
return fma(z, 5.0, ((y + z) * x));
}
function code(x, y, z) return fma(z, 5.0, Float64(Float64(y + z) * x)) end
code[x_, y_, z_] := N[(z * 5.0 + N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, 5, \left(y + z\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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.1e+186)
(* x y)
(if (<= x -1.4e+24)
(* x z)
(if (<= x -1.1e-48)
(* x y)
(if (<= x 1.18e-36) (* 5.0 z) (if (<= x 1.65e+180) (* x y) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+186) {
tmp = x * y;
} else if (x <= -1.4e+24) {
tmp = x * z;
} else if (x <= -1.1e-48) {
tmp = x * y;
} else if (x <= 1.18e-36) {
tmp = 5.0 * z;
} else if (x <= 1.65e+180) {
tmp = x * y;
} 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 <= (-2.1d+186)) then
tmp = x * y
else if (x <= (-1.4d+24)) then
tmp = x * z
else if (x <= (-1.1d-48)) then
tmp = x * y
else if (x <= 1.18d-36) then
tmp = 5.0d0 * z
else if (x <= 1.65d+180) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+186) {
tmp = x * y;
} else if (x <= -1.4e+24) {
tmp = x * z;
} else if (x <= -1.1e-48) {
tmp = x * y;
} else if (x <= 1.18e-36) {
tmp = 5.0 * z;
} else if (x <= 1.65e+180) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.1e+186: tmp = x * y elif x <= -1.4e+24: tmp = x * z elif x <= -1.1e-48: tmp = x * y elif x <= 1.18e-36: tmp = 5.0 * z elif x <= 1.65e+180: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.1e+186) tmp = Float64(x * y); elseif (x <= -1.4e+24) tmp = Float64(x * z); elseif (x <= -1.1e-48) tmp = Float64(x * y); elseif (x <= 1.18e-36) tmp = Float64(5.0 * z); elseif (x <= 1.65e+180) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.1e+186) tmp = x * y; elseif (x <= -1.4e+24) tmp = x * z; elseif (x <= -1.1e-48) tmp = x * y; elseif (x <= 1.18e-36) tmp = 5.0 * z; elseif (x <= 1.65e+180) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.1e+186], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.4e+24], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.1e-48], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.18e-36], N[(5.0 * z), $MachinePrecision], If[LessEqual[x, 1.65e+180], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+186}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.4 \cdot 10^{+24}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.1 \cdot 10^{-48}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{-36}:\\
\;\;\;\;5 \cdot z\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{+180}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.1e186 or -1.4000000000000001e24 < x < -1.10000000000000006e-48 or 1.1799999999999999e-36 < x < 1.64999999999999995e180Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6464.8
Applied rewrites64.8%
if -2.1e186 < x < -1.4000000000000001e24 or 1.64999999999999995e180 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6466.1
Applied rewrites66.1%
Taylor expanded in x around inf
Applied rewrites66.1%
if -1.10000000000000006e-48 < x < 1.1799999999999999e-36Initial program 99.8%
Taylor expanded in x around 0
lower-*.f6474.9
Applied rewrites74.9%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y z) x))) (if (<= x -1.18e-48) t_0 (if (<= x 1.18e-36) (fma z 5.0 (* x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + z) * x;
double tmp;
if (x <= -1.18e-48) {
tmp = t_0;
} else if (x <= 1.18e-36) {
tmp = fma(z, 5.0, (x * z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y + z) * x) tmp = 0.0 if (x <= -1.18e-48) tmp = t_0; elseif (x <= 1.18e-36) tmp = fma(z, 5.0, Float64(x * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.18e-48], t$95$0, If[LessEqual[x, 1.18e-36], N[(z * 5.0 + N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + z\right) \cdot x\\
\mathbf{if}\;x \leq -1.18 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{-36}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.18000000000000007e-48 or 1.1799999999999999e-36 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate--l+N/A
lower-fma.f64N/A
cancel-sign-sub-invN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f6495.8
Applied rewrites95.8%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6496.2
Applied rewrites96.2%
if -1.18000000000000007e-48 < x < 1.1799999999999999e-36Initial program 99.8%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6474.9
Applied rewrites74.9%
Applied rewrites75.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y z) x))) (if (<= x -1.18e-48) t_0 (if (<= x 1.18e-36) (* 5.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + z) * x;
double tmp;
if (x <= -1.18e-48) {
tmp = t_0;
} else if (x <= 1.18e-36) {
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 = (y + z) * x
if (x <= (-1.18d-48)) then
tmp = t_0
else if (x <= 1.18d-36) 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 = (y + z) * x;
double tmp;
if (x <= -1.18e-48) {
tmp = t_0;
} else if (x <= 1.18e-36) {
tmp = 5.0 * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y + z) * x tmp = 0 if x <= -1.18e-48: tmp = t_0 elif x <= 1.18e-36: tmp = 5.0 * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y + z) * x) tmp = 0.0 if (x <= -1.18e-48) tmp = t_0; elseif (x <= 1.18e-36) tmp = Float64(5.0 * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y + z) * x; tmp = 0.0; if (x <= -1.18e-48) tmp = t_0; elseif (x <= 1.18e-36) tmp = 5.0 * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.18e-48], t$95$0, If[LessEqual[x, 1.18e-36], N[(5.0 * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + z\right) \cdot x\\
\mathbf{if}\;x \leq -1.18 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{-36}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.18000000000000007e-48 or 1.1799999999999999e-36 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate--l+N/A
lower-fma.f64N/A
cancel-sign-sub-invN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f6495.8
Applied rewrites95.8%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6496.2
Applied rewrites96.2%
if -1.18000000000000007e-48 < x < 1.1799999999999999e-36Initial program 99.8%
Taylor expanded in x around 0
lower-*.f6474.9
Applied rewrites74.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- x -5.0) z))) (if (<= z -4e-80) t_0 (if (<= z 2.8e-76) (* x y) t_0))))
double code(double x, double y, double z) {
double t_0 = (x - -5.0) * z;
double tmp;
if (z <= -4e-80) {
tmp = t_0;
} else if (z <= 2.8e-76) {
tmp = x * y;
} 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 - (-5.0d0)) * z
if (z <= (-4d-80)) then
tmp = t_0
else if (z <= 2.8d-76) then
tmp = x * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x - -5.0) * z;
double tmp;
if (z <= -4e-80) {
tmp = t_0;
} else if (z <= 2.8e-76) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x - -5.0) * z tmp = 0 if z <= -4e-80: tmp = t_0 elif z <= 2.8e-76: tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x - -5.0) * z) tmp = 0.0 if (z <= -4e-80) tmp = t_0; elseif (z <= 2.8e-76) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - -5.0) * z; tmp = 0.0; if (z <= -4e-80) tmp = t_0; elseif (z <= 2.8e-76) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - -5.0), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -4e-80], t$95$0, If[LessEqual[z, 2.8e-76], N[(x * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - -5\right) \cdot z\\
\mathbf{if}\;z \leq -4 \cdot 10^{-80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{-76}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.99999999999999985e-80 or 2.8000000000000001e-76 < z Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6482.3
Applied rewrites82.3%
if -3.99999999999999985e-80 < z < 2.8000000000000001e-76Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6471.4
Applied rewrites71.4%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (<= x -4e+185) (* (+ y z) x) (fma y x (* (+ x 5.0) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4e+185) {
tmp = (y + z) * x;
} else {
tmp = fma(y, x, ((x + 5.0) * z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4e+185) tmp = Float64(Float64(y + z) * x); else tmp = fma(y, x, Float64(Float64(x + 5.0) * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4e+185], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(y * x + N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+185}:\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, \left(x + 5\right) \cdot z\right)\\
\end{array}
\end{array}
if x < -3.9999999999999999e185Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate--l+N/A
lower-fma.f64N/A
cancel-sign-sub-invN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f6476.2
Applied rewrites76.2%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
if -3.9999999999999999e185 < x Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate--l+N/A
lower-fma.f64N/A
cancel-sign-sub-invN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f6499.5
Applied rewrites99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= x -5.0) (* x z) (if (<= x 5.0) (* 5.0 z) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.0) {
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 <= (-5.0d0)) 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 <= -5.0) {
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 <= -5.0: 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 <= -5.0) 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 <= -5.0) 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, -5.0], 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 -5:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 5:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -5 or 5 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6454.4
Applied rewrites54.4%
Taylor expanded in x around inf
Applied rewrites53.6%
if -5 < x < 5Initial program 99.8%
Taylor expanded in x around 0
lower-*.f6468.5
Applied rewrites68.5%
(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 y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6461.5
Applied rewrites61.5%
Taylor expanded in x around inf
Applied rewrites28.6%
(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 2024298
(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)))