
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* x y)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t + (y * (z + (x * y)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
def code(x, y, z, t): return t + (y * (z + (x * y)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(x * y)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (x * y))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + x \cdot y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -5.8)
(not
(or (<= y -1.4e-42) (and (not (<= y -1.18e-54)) (<= y 2.6e-12)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.8) || !((y <= -1.4e-42) || (!(y <= -1.18e-54) && (y <= 2.6e-12)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-5.8d0)) .or. (.not. (y <= (-1.4d-42)) .or. (.not. (y <= (-1.18d-54))) .and. (y <= 2.6d-12))) then
tmp = y * (x * y)
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.8) || !((y <= -1.4e-42) || (!(y <= -1.18e-54) && (y <= 2.6e-12)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5.8) or not ((y <= -1.4e-42) or (not (y <= -1.18e-54) and (y <= 2.6e-12))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.8) || !((y <= -1.4e-42) || (!(y <= -1.18e-54) && (y <= 2.6e-12)))) tmp = Float64(y * Float64(x * y)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -5.8) || ~(((y <= -1.4e-42) || (~((y <= -1.18e-54)) && (y <= 2.6e-12))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.8], N[Not[Or[LessEqual[y, -1.4e-42], And[N[Not[LessEqual[y, -1.18e-54]], $MachinePrecision], LessEqual[y, 2.6e-12]]]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \lor \neg \left(y \leq -1.4 \cdot 10^{-42} \lor \neg \left(y \leq -1.18 \cdot 10^{-54}\right) \land y \leq 2.6 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -5.79999999999999982 or -1.39999999999999999e-42 < y < -1.17999999999999996e-54 or 2.59999999999999983e-12 < y Initial program 99.9%
Taylor expanded in t around 0 94.7%
Taylor expanded in y around inf 69.2%
if -5.79999999999999982 < y < -1.39999999999999999e-42 or -1.17999999999999996e-54 < y < 2.59999999999999983e-12Initial program 100.0%
Taylor expanded in x around 0 89.9%
Final simplification79.5%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ z (* x y)))))
(if (<= y -1.95e+54)
t_1
(if (<= y -1.35e-85)
(+ t (* x (* y y)))
(if (<= y 1.45e-7) (+ t (* y z)) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -1.95e+54) {
tmp = t_1;
} else if (y <= -1.35e-85) {
tmp = t + (x * (y * y));
} else if (y <= 1.45e-7) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * (z + (x * y))
if (y <= (-1.95d+54)) then
tmp = t_1
else if (y <= (-1.35d-85)) then
tmp = t + (x * (y * y))
else if (y <= 1.45d-7) then
tmp = t + (y * z)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -1.95e+54) {
tmp = t_1;
} else if (y <= -1.35e-85) {
tmp = t + (x * (y * y));
} else if (y <= 1.45e-7) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (x * y)) tmp = 0 if y <= -1.95e+54: tmp = t_1 elif y <= -1.35e-85: tmp = t + (x * (y * y)) elif y <= 1.45e-7: tmp = t + (y * z) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -1.95e+54) tmp = t_1; elseif (y <= -1.35e-85) tmp = Float64(t + Float64(x * Float64(y * y))); elseif (y <= 1.45e-7) tmp = Float64(t + Float64(y * z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (x * y)); tmp = 0.0; if (y <= -1.95e+54) tmp = t_1; elseif (y <= -1.35e-85) tmp = t + (x * (y * y)); elseif (y <= 1.45e-7) tmp = t + (y * z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.95e+54], t$95$1, If[LessEqual[y, -1.35e-85], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.45e-7], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -1.95 \cdot 10^{+54}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{-85}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-7}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.9500000000000001e54 or 1.4499999999999999e-7 < y Initial program 100.0%
Taylor expanded in t around 0 96.7%
if -1.9500000000000001e54 < y < -1.3500000000000001e-85Initial program 99.8%
*-commutative99.8%
distribute-rgt-in99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 84.3%
unpow284.3%
*-commutative84.3%
Simplified84.3%
if -1.3500000000000001e-85 < y < 1.4499999999999999e-7Initial program 100.0%
Taylor expanded in x around 0 92.1%
Final simplification93.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.35e-85) (not (<= y 1.05e-9))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.35e-85) || !(y <= 1.05e-9)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-1.35d-85)) .or. (.not. (y <= 1.05d-9))) then
tmp = y * (z + (x * y))
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.35e-85) || !(y <= 1.05e-9)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.35e-85) or not (y <= 1.05e-9): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.35e-85) || !(y <= 1.05e-9)) tmp = Float64(y * Float64(z + Float64(x * y))); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.35e-85) || ~((y <= 1.05e-9))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.35e-85], N[Not[LessEqual[y, 1.05e-9]], $MachinePrecision]], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-85} \lor \neg \left(y \leq 1.05 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.3500000000000001e-85 or 1.0500000000000001e-9 < y Initial program 99.9%
Taylor expanded in t around 0 91.2%
if -1.3500000000000001e-85 < y < 1.0500000000000001e-9Initial program 100.0%
Taylor expanded in x around 0 92.1%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -7.5e-55) (not (<= y 1.05e-8))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.5e-55) || !(y <= 1.05e-8)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-7.5d-55)) .or. (.not. (y <= 1.05d-8))) then
tmp = y * (x * y)
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.5e-55) || !(y <= 1.05e-8)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7.5e-55) or not (y <= 1.05e-8): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.5e-55) || !(y <= 1.05e-8)) tmp = Float64(y * Float64(x * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -7.5e-55) || ~((y <= 1.05e-8))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.5e-55], N[Not[LessEqual[y, 1.05e-8]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-55} \lor \neg \left(y \leq 1.05 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -7.50000000000000023e-55 or 1.04999999999999997e-8 < y Initial program 99.9%
Taylor expanded in t around 0 92.2%
Taylor expanded in y around inf 66.7%
if -7.50000000000000023e-55 < y < 1.04999999999999997e-8Initial program 100.0%
Taylor expanded in y around 0 64.2%
Final simplification65.6%
(FPCore (x y z t) :precision binary64 (if (<= z -1.75e+97) (* y z) (if (<= z 6.4e-6) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.75e+97) {
tmp = y * z;
} else if (z <= 6.4e-6) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-1.75d+97)) then
tmp = y * z
else if (z <= 6.4d-6) then
tmp = t
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.75e+97) {
tmp = y * z;
} else if (z <= 6.4e-6) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.75e+97: tmp = y * z elif z <= 6.4e-6: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.75e+97) tmp = Float64(y * z); elseif (z <= 6.4e-6) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.75e+97) tmp = y * z; elseif (z <= 6.4e-6) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.75e+97], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.4e-6], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{+97}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{-6}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.75e97 or 6.3999999999999997e-6 < z Initial program 100.0%
Taylor expanded in t around 0 80.9%
Taylor expanded in y around 0 57.3%
if -1.75e97 < z < 6.3999999999999997e-6Initial program 99.9%
Taylor expanded in y around 0 48.0%
Final simplification52.4%
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
return t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t
end function
public static double code(double x, double y, double z, double t) {
return t;
}
def code(x, y, z, t): return t
function code(x, y, z, t) return t end
function tmp = code(x, y, z, t) tmp = t; end
code[x_, y_, z_, t_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 35.3%
Final simplification35.3%
herbie shell --seed 2023238
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))