
(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 (+ x 5.0) z (* x y)))
double code(double x, double y, double z) {
return fma((x + 5.0), z, (x * y));
}
function code(x, y, z) return fma(Float64(x + 5.0), z, Float64(x * y)) end
code[x_, y_, z_] := N[(N[(x + 5.0), $MachinePrecision] * z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + 5, z, x \cdot y\right)
\end{array}
Initial program 99.5%
distribute-lft-in99.2%
associate-+r+99.2%
*-commutative99.2%
distribute-rgt-in99.2%
+-commutative99.2%
*-commutative99.2%
fma-define99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (fma x y (* (+ x 5.0) z)))
double code(double x, double y, double z) {
return fma(x, y, ((x + 5.0) * z));
}
function code(x, y, z) return fma(x, y, Float64(Float64(x + 5.0) * z)) end
code[x_, y_, z_] := N[(x * y + N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \left(x + 5\right) \cdot z\right)
\end{array}
Initial program 99.5%
distribute-rgt-in99.2%
associate-+l+99.2%
*-commutative99.2%
fma-define99.2%
distribute-lft-out99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z)
:precision binary64
(if (<= x -3.5e+39)
(* x z)
(if (<= x -1.42e-109)
(* x y)
(if (<= x 2e-37)
(* 5.0 z)
(if (or (<= x 1.7e+42)
(and (not (<= x 3.6e+100))
(or (<= x 5.7e+140)
(and (not (<= x 2.6e+216)) (<= x 2.5e+278)))))
(* x y)
(* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.5e+39) {
tmp = x * z;
} else if (x <= -1.42e-109) {
tmp = x * y;
} else if (x <= 2e-37) {
tmp = 5.0 * z;
} else if ((x <= 1.7e+42) || (!(x <= 3.6e+100) && ((x <= 5.7e+140) || (!(x <= 2.6e+216) && (x <= 2.5e+278))))) {
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 <= (-3.5d+39)) then
tmp = x * z
else if (x <= (-1.42d-109)) then
tmp = x * y
else if (x <= 2d-37) then
tmp = 5.0d0 * z
else if ((x <= 1.7d+42) .or. (.not. (x <= 3.6d+100)) .and. (x <= 5.7d+140) .or. (.not. (x <= 2.6d+216)) .and. (x <= 2.5d+278)) 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 <= -3.5e+39) {
tmp = x * z;
} else if (x <= -1.42e-109) {
tmp = x * y;
} else if (x <= 2e-37) {
tmp = 5.0 * z;
} else if ((x <= 1.7e+42) || (!(x <= 3.6e+100) && ((x <= 5.7e+140) || (!(x <= 2.6e+216) && (x <= 2.5e+278))))) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.5e+39: tmp = x * z elif x <= -1.42e-109: tmp = x * y elif x <= 2e-37: tmp = 5.0 * z elif (x <= 1.7e+42) or (not (x <= 3.6e+100) and ((x <= 5.7e+140) or (not (x <= 2.6e+216) and (x <= 2.5e+278)))): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.5e+39) tmp = Float64(x * z); elseif (x <= -1.42e-109) tmp = Float64(x * y); elseif (x <= 2e-37) tmp = Float64(5.0 * z); elseif ((x <= 1.7e+42) || (!(x <= 3.6e+100) && ((x <= 5.7e+140) || (!(x <= 2.6e+216) && (x <= 2.5e+278))))) 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 <= -3.5e+39) tmp = x * z; elseif (x <= -1.42e-109) tmp = x * y; elseif (x <= 2e-37) tmp = 5.0 * z; elseif ((x <= 1.7e+42) || (~((x <= 3.6e+100)) && ((x <= 5.7e+140) || (~((x <= 2.6e+216)) && (x <= 2.5e+278))))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.5e+39], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.42e-109], N[(x * y), $MachinePrecision], If[LessEqual[x, 2e-37], N[(5.0 * z), $MachinePrecision], If[Or[LessEqual[x, 1.7e+42], And[N[Not[LessEqual[x, 3.6e+100]], $MachinePrecision], Or[LessEqual[x, 5.7e+140], And[N[Not[LessEqual[x, 2.6e+216]], $MachinePrecision], LessEqual[x, 2.5e+278]]]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{+39}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.42 \cdot 10^{-109}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-37}:\\
\;\;\;\;5 \cdot z\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+42} \lor \neg \left(x \leq 3.6 \cdot 10^{+100}\right) \land \left(x \leq 5.7 \cdot 10^{+140} \lor \neg \left(x \leq 2.6 \cdot 10^{+216}\right) \land x \leq 2.5 \cdot 10^{+278}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -3.5000000000000002e39 or 1.69999999999999988e42 < x < 3.6e100 or 5.70000000000000015e140 < x < 2.5999999999999999e216 or 2.50000000000000014e278 < x Initial program 99.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 65.3%
*-commutative65.3%
Simplified65.3%
if -3.5000000000000002e39 < x < -1.41999999999999994e-109 or 2.00000000000000013e-37 < x < 1.69999999999999988e42 or 3.6e100 < x < 5.70000000000000015e140 or 2.5999999999999999e216 < x < 2.50000000000000014e278Initial program 99.9%
Taylor expanded in y around inf 69.5%
if -1.41999999999999994e-109 < x < 2.00000000000000013e-37Initial program 99.9%
Taylor expanded in x around 0 78.1%
Final simplification70.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.5e-99) (* x (+ z y)) (if (<= x 360.0) (* (+ x 5.0) z) (+ (* x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e-99) {
tmp = x * (z + y);
} else if (x <= 360.0) {
tmp = (x + 5.0) * z;
} else {
tmp = (x * y) + (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 <= (-1.5d-99)) then
tmp = x * (z + y)
else if (x <= 360.0d0) then
tmp = (x + 5.0d0) * z
else
tmp = (x * y) + (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e-99) {
tmp = x * (z + y);
} else if (x <= 360.0) {
tmp = (x + 5.0) * z;
} else {
tmp = (x * y) + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.5e-99: tmp = x * (z + y) elif x <= 360.0: tmp = (x + 5.0) * z else: tmp = (x * y) + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.5e-99) tmp = Float64(x * Float64(z + y)); elseif (x <= 360.0) tmp = Float64(Float64(x + 5.0) * z); else tmp = Float64(Float64(x * y) + Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.5e-99) tmp = x * (z + y); elseif (x <= 360.0) tmp = (x + 5.0) * z; else tmp = (x * y) + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.5e-99], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 360.0], N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-99}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{elif}\;x \leq 360:\\
\;\;\;\;\left(x + 5\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + x \cdot z\\
\end{array}
\end{array}
if x < -1.50000000000000003e-99Initial program 98.8%
Taylor expanded in x around inf 92.5%
+-commutative92.5%
Simplified92.5%
if -1.50000000000000003e-99 < x < 360Initial program 99.9%
Taylor expanded in y around 0 73.6%
distribute-rgt-in73.6%
Simplified73.6%
if 360 < x Initial program 100.0%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
Simplified99.8%
distribute-lft-in99.8%
Applied egg-rr99.8%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e-100) (not (<= x 4.2e-36))) (* x (+ z y)) (* 5.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-100) || !(x <= 4.2e-36)) {
tmp = x * (z + y);
} else {
tmp = 5.0 * 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.2d-100)) .or. (.not. (x <= 4.2d-36))) then
tmp = x * (z + y)
else
tmp = 5.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-100) || !(x <= 4.2e-36)) {
tmp = x * (z + y);
} else {
tmp = 5.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e-100) or not (x <= 4.2e-36): tmp = x * (z + y) else: tmp = 5.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e-100) || !(x <= 4.2e-36)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(5.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e-100) || ~((x <= 4.2e-36))) tmp = x * (z + y); else tmp = 5.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e-100], N[Not[LessEqual[x, 4.2e-36]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-100} \lor \neg \left(x \leq 4.2 \cdot 10^{-36}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;5 \cdot z\\
\end{array}
\end{array}
if x < -8.1999999999999998e-100 or 4.19999999999999982e-36 < x Initial program 99.4%
Taylor expanded in x around inf 92.0%
+-commutative92.0%
Simplified92.0%
if -8.1999999999999998e-100 < x < 4.19999999999999982e-36Initial program 99.9%
Taylor expanded in x around 0 76.8%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e-99) (not (<= x 16000.0))) (* x (+ z y)) (* (+ x 5.0) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-99) || !(x <= 16000.0)) {
tmp = x * (z + y);
} else {
tmp = (x + 5.0) * 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 <= (-1.5d-99)) .or. (.not. (x <= 16000.0d0))) then
tmp = x * (z + y)
else
tmp = (x + 5.0d0) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-99) || !(x <= 16000.0)) {
tmp = x * (z + y);
} else {
tmp = (x + 5.0) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e-99) or not (x <= 16000.0): tmp = x * (z + y) else: tmp = (x + 5.0) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e-99) || !(x <= 16000.0)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x + 5.0) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.5e-99) || ~((x <= 16000.0))) tmp = x * (z + y); else tmp = (x + 5.0) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e-99], N[Not[LessEqual[x, 16000.0]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-99} \lor \neg \left(x \leq 16000\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + 5\right) \cdot z\\
\end{array}
\end{array}
if x < -1.50000000000000003e-99 or 16000 < x Initial program 99.3%
Taylor expanded in x around inf 95.7%
+-commutative95.7%
Simplified95.7%
if -1.50000000000000003e-99 < x < 16000Initial program 99.9%
Taylor expanded in y around 0 73.6%
distribute-rgt-in73.6%
Simplified73.6%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-109) (not (<= x 3.2e-39))) (* x y) (* 5.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-109) || !(x <= 3.2e-39)) {
tmp = x * y;
} else {
tmp = 5.0 * 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.7d-109)) .or. (.not. (x <= 3.2d-39))) then
tmp = x * y
else
tmp = 5.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-109) || !(x <= 3.2e-39)) {
tmp = x * y;
} else {
tmp = 5.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.7e-109) or not (x <= 3.2e-39): tmp = x * y else: tmp = 5.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-109) || !(x <= 3.2e-39)) tmp = Float64(x * y); else tmp = Float64(5.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.7e-109) || ~((x <= 3.2e-39))) tmp = x * y; else tmp = 5.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-109], N[Not[LessEqual[x, 3.2e-39]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-109} \lor \neg \left(x \leq 3.2 \cdot 10^{-39}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;5 \cdot z\\
\end{array}
\end{array}
if x < -2.7e-109 or 3.1999999999999998e-39 < x Initial program 99.4%
Taylor expanded in y around inf 50.9%
if -2.7e-109 < x < 3.1999999999999998e-39Initial program 99.9%
Taylor expanded in x around 0 78.1%
Final simplification59.6%
(FPCore (x y z) :precision binary64 (+ (* x (+ z y)) (* 5.0 z)))
double code(double x, double y, double z) {
return (x * (z + y)) + (5.0 * 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 + y)) + (5.0d0 * z)
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) + (5.0 * z);
}
def code(x, y, z): return (x * (z + y)) + (5.0 * z)
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) + Float64(5.0 * z)) end
function tmp = code(x, y, z) tmp = (x * (z + y)) + (5.0 * z); end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] + N[(5.0 * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) + 5 \cdot z
\end{array}
Initial program 99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (* 5.0 z))
double code(double x, double y, double z) {
return 5.0 * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 5.0d0 * z
end function
public static double code(double x, double y, double z) {
return 5.0 * z;
}
def code(x, y, z): return 5.0 * z
function code(x, y, z) return Float64(5.0 * z) end
function tmp = code(x, y, z) tmp = 5.0 * z; end
code[x_, y_, z_] := N[(5.0 * z), $MachinePrecision]
\begin{array}{l}
\\
5 \cdot z
\end{array}
Initial program 99.5%
Taylor expanded in x around 0 31.1%
Final simplification31.1%
(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 2024059
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:alt
(+ (* (+ x 5.0) z) (* x y))
(+ (* x (+ y z)) (* z 5.0)))