
(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 -3700000000000.0)
(* x z)
(if (<= x -1.32e-23)
(* x y)
(if (<= x 5.6e-92) (* 5.0 z) (if (<= x 2.1e+251) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3700000000000.0) {
tmp = x * z;
} else if (x <= -1.32e-23) {
tmp = x * y;
} else if (x <= 5.6e-92) {
tmp = 5.0 * z;
} else if (x <= 2.1e+251) {
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 <= (-3700000000000.0d0)) then
tmp = x * z
else if (x <= (-1.32d-23)) then
tmp = x * y
else if (x <= 5.6d-92) then
tmp = 5.0d0 * z
else if (x <= 2.1d+251) 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 <= -3700000000000.0) {
tmp = x * z;
} else if (x <= -1.32e-23) {
tmp = x * y;
} else if (x <= 5.6e-92) {
tmp = 5.0 * z;
} else if (x <= 2.1e+251) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3700000000000.0: tmp = x * z elif x <= -1.32e-23: tmp = x * y elif x <= 5.6e-92: tmp = 5.0 * z elif x <= 2.1e+251: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3700000000000.0) tmp = Float64(x * z); elseif (x <= -1.32e-23) tmp = Float64(x * y); elseif (x <= 5.6e-92) tmp = Float64(5.0 * z); elseif (x <= 2.1e+251) 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 <= -3700000000000.0) tmp = x * z; elseif (x <= -1.32e-23) tmp = x * y; elseif (x <= 5.6e-92) tmp = 5.0 * z; elseif (x <= 2.1e+251) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3700000000000.0], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.32e-23], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.6e-92], N[(5.0 * z), $MachinePrecision], If[LessEqual[x, 2.1e+251], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3700000000000:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.32 \cdot 10^{-23}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-92}:\\
\;\;\;\;5 \cdot z\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+251}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -3.7e12 or 2.1e251 < 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--.f6461.3
Applied rewrites61.3%
Taylor expanded in x around inf
Applied rewrites61.3%
if -3.7e12 < x < -1.31999999999999994e-23 or 5.6e-92 < x < 2.1e251Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6459.5
Applied rewrites59.5%
if -1.31999999999999994e-23 < x < 5.6e-92Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6477.1
Applied rewrites77.1%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (if (<= x -1e-16) (* (+ y z) x) (if (<= x 1.45e-92) (fma z 5.0 (* x z)) (fma z x (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e-16) {
tmp = (y + z) * x;
} else if (x <= 1.45e-92) {
tmp = fma(z, 5.0, (x * z));
} else {
tmp = fma(z, x, (x * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1e-16) tmp = Float64(Float64(y + z) * x); elseif (x <= 1.45e-92) tmp = fma(z, 5.0, Float64(x * z)); else tmp = fma(z, x, Float64(x * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1e-16], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.45e-92], N[(z * 5.0 + N[(x * z), $MachinePrecision]), $MachinePrecision], N[(z * x + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-16}:\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-92}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x \cdot y\right)\\
\end{array}
\end{array}
if x < -9.9999999999999998e-17Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f6498.7
Applied rewrites98.7%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-+.f6497.7
Applied rewrites97.7%
if -9.9999999999999998e-17 < x < 1.44999999999999992e-92Initial 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--.f6476.2
Applied rewrites76.2%
Applied rewrites76.2%
if 1.44999999999999992e-92 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-+.f6494.8
Applied rewrites94.8%
Applied rewrites94.8%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y z) x))) (if (<= x -1e-16) t_0 (if (<= x 1.45e-92) (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 <= -1e-16) {
tmp = t_0;
} else if (x <= 1.45e-92) {
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 <= -1e-16) tmp = t_0; elseif (x <= 1.45e-92) 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, -1e-16], t$95$0, If[LessEqual[x, 1.45e-92], 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 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-92}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.9999999999999998e-17 or 1.44999999999999992e-92 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f6499.3
Applied rewrites99.3%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-+.f6496.3
Applied rewrites96.3%
if -9.9999999999999998e-17 < x < 1.44999999999999992e-92Initial 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--.f6476.2
Applied rewrites76.2%
Applied rewrites76.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y z) x))) (if (<= x -1e-16) t_0 (if (<= x 1.45e-92) (* 5.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + z) * x;
double tmp;
if (x <= -1e-16) {
tmp = t_0;
} else if (x <= 1.45e-92) {
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 <= (-1d-16)) then
tmp = t_0
else if (x <= 1.45d-92) 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 <= -1e-16) {
tmp = t_0;
} else if (x <= 1.45e-92) {
tmp = 5.0 * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y + z) * x tmp = 0 if x <= -1e-16: tmp = t_0 elif x <= 1.45e-92: 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 <= -1e-16) tmp = t_0; elseif (x <= 1.45e-92) 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 <= -1e-16) tmp = t_0; elseif (x <= 1.45e-92) 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, -1e-16], t$95$0, If[LessEqual[x, 1.45e-92], 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 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-92}:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.9999999999999998e-17 or 1.44999999999999992e-92 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f6499.3
Applied rewrites99.3%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-+.f6496.3
Applied rewrites96.3%
if -9.9999999999999998e-17 < x < 1.44999999999999992e-92Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6476.2
Applied rewrites76.2%
(FPCore (x y z) :precision binary64 (if (<= y -8e+170) (* x y) (if (<= y 4.8e+48) (* (- x -5.0) z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e+170) {
tmp = x * y;
} else if (y <= 4.8e+48) {
tmp = (x - -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 <= (-8d+170)) then
tmp = x * y
else if (y <= 4.8d+48) then
tmp = (x - (-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 <= -8e+170) {
tmp = x * y;
} else if (y <= 4.8e+48) {
tmp = (x - -5.0) * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e+170: tmp = x * y elif y <= 4.8e+48: tmp = (x - -5.0) * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e+170) tmp = Float64(x * y); elseif (y <= 4.8e+48) tmp = Float64(Float64(x - -5.0) * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8e+170) tmp = x * y; elseif (y <= 4.8e+48) tmp = (x - -5.0) * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e+170], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.8e+48], N[(N[(x - -5.0), $MachinePrecision] * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+170}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+48}:\\
\;\;\;\;\left(x - -5\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -8.00000000000000028e170 or 4.8000000000000002e48 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6482.9
Applied rewrites82.9%
if -8.00000000000000028e170 < y < 4.8000000000000002e48Initial 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--.f6479.8
Applied rewrites79.8%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (<= x -8.5) (* x z) (if (<= x 5.0) (* 5.0 z) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.5) {
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 <= (-8.5d0)) 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 <= -8.5) {
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 <= -8.5: 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 <= -8.5) 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 <= -8.5) 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, -8.5], 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 -8.5:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 5:\\
\;\;\;\;5 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -8.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.9
Applied rewrites54.9%
Taylor expanded in x around inf
Applied rewrites54.3%
if -8.5 < x < 5Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6470.1
Applied rewrites70.1%
(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--.f6462.7
Applied rewrites62.7%
Taylor expanded in x around inf
Applied rewrites29.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 2024332
(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)))