
(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 9 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 (+ y z) x (* z 5.0)))
double code(double x, double y, double z) {
return fma((y + z), x, (z * 5.0));
}
function code(x, y, z) return fma(Float64(y + z), x, Float64(z * 5.0)) end
code[x_, y_, z_] := N[(N[(y + z), $MachinePrecision] * x + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + z, x, z \cdot 5\right)
\end{array}
Initial program 100.0%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= y -8.8e-20) (* y x) (if (<= y -6.5e-83) (* z 5.0) (if (<= y 1.15e-70) (* z x) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.8e-20) {
tmp = y * x;
} else if (y <= -6.5e-83) {
tmp = z * 5.0;
} else if (y <= 1.15e-70) {
tmp = z * x;
} 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 (y <= (-8.8d-20)) then
tmp = y * x
else if (y <= (-6.5d-83)) then
tmp = z * 5.0d0
else if (y <= 1.15d-70) then
tmp = z * x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.8e-20) {
tmp = y * x;
} else if (y <= -6.5e-83) {
tmp = z * 5.0;
} else if (y <= 1.15e-70) {
tmp = z * x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.8e-20: tmp = y * x elif y <= -6.5e-83: tmp = z * 5.0 elif y <= 1.15e-70: tmp = z * x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.8e-20) tmp = Float64(y * x); elseif (y <= -6.5e-83) tmp = Float64(z * 5.0); elseif (y <= 1.15e-70) tmp = Float64(z * x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.8e-20) tmp = y * x; elseif (y <= -6.5e-83) tmp = z * 5.0; elseif (y <= 1.15e-70) tmp = z * x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.8e-20], N[(y * x), $MachinePrecision], If[LessEqual[y, -6.5e-83], N[(z * 5.0), $MachinePrecision], If[LessEqual[y, 1.15e-70], N[(z * x), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-20}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -6.5 \cdot 10^{-83}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-70}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.79999999999999964e-20 or 1.15e-70 < y Initial program 99.9%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6471.1
Simplified71.1%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6471.1
Applied egg-rr71.1%
if -8.79999999999999964e-20 < y < -6.5e-83Initial program 99.9%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6475.4
Simplified75.4%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6475.4
Applied egg-rr75.4%
if -6.5e-83 < y < 1.15e-70Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6469.3
Simplified69.3%
Taylor expanded in z around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6455.4
Simplified55.4%
+-rgt-identityN/A
*-lowering-*.f6455.4
Applied egg-rr55.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y z) x))) (if (<= x -5.0) t_0 (if (<= x 7.6e-20) (fma z 5.0 (* y x)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + z) * x;
double tmp;
if (x <= -5.0) {
tmp = t_0;
} else if (x <= 7.6e-20) {
tmp = fma(z, 5.0, (y * x));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y + z) * x) tmp = 0.0 if (x <= -5.0) tmp = t_0; elseif (x <= 7.6e-20) tmp = fma(z, 5.0, Float64(y * x)); 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, -5.0], t$95$0, If[LessEqual[x, 7.6e-20], N[(z * 5.0 + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + z\right) \cdot x\\
\mathbf{if}\;x \leq -5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5 or 7.5999999999999995e-20 < x Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6498.9
Simplified98.9%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6498.9
Applied egg-rr98.9%
if -5 < x < 7.5999999999999995e-20Initial program 99.9%
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified99.7%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y z) x))) (if (<= x -5.0) t_0 (if (<= x 7.6e-20) (fma y x (* z 5.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + z) * x;
double tmp;
if (x <= -5.0) {
tmp = t_0;
} else if (x <= 7.6e-20) {
tmp = fma(y, x, (z * 5.0));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y + z) * x) tmp = 0.0 if (x <= -5.0) tmp = t_0; elseif (x <= 7.6e-20) tmp = fma(y, x, Float64(z * 5.0)); 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, -5.0], t$95$0, If[LessEqual[x, 7.6e-20], N[(y * x + N[(z * 5.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + z\right) \cdot x\\
\mathbf{if}\;x \leq -5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot 5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5 or 7.5999999999999995e-20 < x Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6498.9
Simplified98.9%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6498.9
Applied egg-rr98.9%
if -5 < x < 7.5999999999999995e-20Initial program 99.9%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
Taylor expanded in y around inf
Simplified99.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y z) x))) (if (<= x -3.2e-8) t_0 (if (<= x 2.2e-91) (* z (+ x 5.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + z) * x;
double tmp;
if (x <= -3.2e-8) {
tmp = t_0;
} else if (x <= 2.2e-91) {
tmp = z * (x + 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 = (y + z) * x
if (x <= (-3.2d-8)) then
tmp = t_0
else if (x <= 2.2d-91) then
tmp = z * (x + 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 = (y + z) * x;
double tmp;
if (x <= -3.2e-8) {
tmp = t_0;
} else if (x <= 2.2e-91) {
tmp = z * (x + 5.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y + z) * x tmp = 0 if x <= -3.2e-8: tmp = t_0 elif x <= 2.2e-91: tmp = z * (x + 5.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y + z) * x) tmp = 0.0 if (x <= -3.2e-8) tmp = t_0; elseif (x <= 2.2e-91) tmp = Float64(z * Float64(x + 5.0)); 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 <= -3.2e-8) tmp = t_0; elseif (x <= 2.2e-91) tmp = z * (x + 5.0); 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, -3.2e-8], t$95$0, If[LessEqual[x, 2.2e-91], N[(z * N[(x + 5.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + z\right) \cdot x\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-91}:\\
\;\;\;\;z \cdot \left(x + 5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.2000000000000002e-8 or 2.2000000000000001e-91 < x Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6497.3
Simplified97.3%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6497.3
Applied egg-rr97.3%
if -3.2000000000000002e-8 < x < 2.2000000000000001e-91Initial program 99.9%
Taylor expanded in y around 0
+-rgt-identityN/A
associate-+l+N/A
distribute-rgt-inN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6469.8
Simplified69.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6469.8
Applied egg-rr69.8%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.06e-19) (* y x) (if (<= y 3e+83) (* z (+ x 5.0)) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e-19) {
tmp = y * x;
} else if (y <= 3e+83) {
tmp = z * (x + 5.0);
} 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 (y <= (-1.06d-19)) then
tmp = y * x
else if (y <= 3d+83) then
tmp = z * (x + 5.0d0)
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e-19) {
tmp = y * x;
} else if (y <= 3e+83) {
tmp = z * (x + 5.0);
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.06e-19: tmp = y * x elif y <= 3e+83: tmp = z * (x + 5.0) else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.06e-19) tmp = Float64(y * x); elseif (y <= 3e+83) tmp = Float64(z * Float64(x + 5.0)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.06e-19) tmp = y * x; elseif (y <= 3e+83) tmp = z * (x + 5.0); else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.06e-19], N[(y * x), $MachinePrecision], If[LessEqual[y, 3e+83], N[(z * N[(x + 5.0), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{-19}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+83}:\\
\;\;\;\;z \cdot \left(x + 5\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.06e-19 or 3e83 < y Initial program 100.0%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6475.9
Simplified75.9%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6475.9
Applied egg-rr75.9%
if -1.06e-19 < y < 3e83Initial program 99.9%
Taylor expanded in y around 0
+-rgt-identityN/A
associate-+l+N/A
distribute-rgt-inN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6480.3
Simplified80.3%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6480.3
Applied egg-rr80.3%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e-9) (* y x) (if (<= x 2.15e-85) (* z 5.0) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e-9) {
tmp = y * x;
} else if (x <= 2.15e-85) {
tmp = z * 5.0;
} 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 <= (-1.9d-9)) then
tmp = y * x
else if (x <= 2.15d-85) then
tmp = z * 5.0d0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e-9) {
tmp = y * x;
} else if (x <= 2.15e-85) {
tmp = z * 5.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e-9: tmp = y * x elif x <= 2.15e-85: tmp = z * 5.0 else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e-9) tmp = Float64(y * x); elseif (x <= 2.15e-85) tmp = Float64(z * 5.0); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e-9) tmp = y * x; elseif (x <= 2.15e-85) tmp = z * 5.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e-9], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.15e-85], N[(z * 5.0), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-9}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.15 \cdot 10^{-85}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.90000000000000006e-9 or 2.14999999999999999e-85 < x Initial program 100.0%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6455.4
Simplified55.4%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6455.4
Applied egg-rr55.4%
if -1.90000000000000006e-9 < x < 2.14999999999999999e-85Initial program 99.9%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6469.8
Simplified69.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6469.8
Applied egg-rr69.8%
(FPCore (x y z) :precision binary64 (fma z (+ x 5.0) (* y x)))
double code(double x, double y, double z) {
return fma(z, (x + 5.0), (y * x));
}
function code(x, y, z) return fma(z, Float64(x + 5.0), Float64(y * x)) end
code[x_, y_, z_] := N[(z * N[(x + 5.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, x + 5, y \cdot x\right)
\end{array}
Initial program 100.0%
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.6
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6446.8
Simplified46.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6446.8
Applied egg-rr46.8%
(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 2024195
(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)))