
(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 (+ (* x y) z))))
double code(double x, double y, double z, double t) {
return t + (y * ((x * y) + z));
}
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 * ((x * y) + z))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * ((x * y) + z));
}
def code(x, y, z, t): return t + (y * ((x * y) + z))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(Float64(x * y) + z))) end
function tmp = code(x, y, z, t) tmp = t + (y * ((x * y) + z)); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(x \cdot y + z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ t (* y z))) (t_2 (* y (+ (* x y) z))))
(if (<= y -2.6e-22)
t_2
(if (<= y 2.55e-36)
t_1
(if (<= y 1.28e+44)
(+ t (* y (* x y)))
(if (<= y 1.65e+49) t_1 t_2))))))
double code(double x, double y, double z, double t) {
double t_1 = t + (y * z);
double t_2 = y * ((x * y) + z);
double tmp;
if (y <= -2.6e-22) {
tmp = t_2;
} else if (y <= 2.55e-36) {
tmp = t_1;
} else if (y <= 1.28e+44) {
tmp = t + (y * (x * y));
} else if (y <= 1.65e+49) {
tmp = t_1;
} else {
tmp = t_2;
}
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) :: t_2
real(8) :: tmp
t_1 = t + (y * z)
t_2 = y * ((x * y) + z)
if (y <= (-2.6d-22)) then
tmp = t_2
else if (y <= 2.55d-36) then
tmp = t_1
else if (y <= 1.28d+44) then
tmp = t + (y * (x * y))
else if (y <= 1.65d+49) then
tmp = t_1
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = t + (y * z);
double t_2 = y * ((x * y) + z);
double tmp;
if (y <= -2.6e-22) {
tmp = t_2;
} else if (y <= 2.55e-36) {
tmp = t_1;
} else if (y <= 1.28e+44) {
tmp = t + (y * (x * y));
} else if (y <= 1.65e+49) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t): t_1 = t + (y * z) t_2 = y * ((x * y) + z) tmp = 0 if y <= -2.6e-22: tmp = t_2 elif y <= 2.55e-36: tmp = t_1 elif y <= 1.28e+44: tmp = t + (y * (x * y)) elif y <= 1.65e+49: tmp = t_1 else: tmp = t_2 return tmp
function code(x, y, z, t) t_1 = Float64(t + Float64(y * z)) t_2 = Float64(y * Float64(Float64(x * y) + z)) tmp = 0.0 if (y <= -2.6e-22) tmp = t_2; elseif (y <= 2.55e-36) tmp = t_1; elseif (y <= 1.28e+44) tmp = Float64(t + Float64(y * Float64(x * y))); elseif (y <= 1.65e+49) tmp = t_1; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = t + (y * z); t_2 = y * ((x * y) + z); tmp = 0.0; if (y <= -2.6e-22) tmp = t_2; elseif (y <= 2.55e-36) tmp = t_1; elseif (y <= 1.28e+44) tmp = t + (y * (x * y)); elseif (y <= 1.65e+49) tmp = t_1; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.6e-22], t$95$2, If[LessEqual[y, 2.55e-36], t$95$1, If[LessEqual[y, 1.28e+44], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.65e+49], t$95$1, t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t + y \cdot z\\
t_2 := y \cdot \left(x \cdot y + z\right)\\
\mathbf{if}\;y \leq -2.6 \cdot 10^{-22}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-36}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.28 \cdot 10^{+44}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{+49}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if y < -2.6e-22 or 1.6499999999999999e49 < y Initial program 99.9%
Taylor expanded in t around 0 93.4%
if -2.6e-22 < y < 2.54999999999999987e-36 or 1.28000000000000006e44 < y < 1.6499999999999999e49Initial program 100.0%
Taylor expanded in x around 0 96.8%
if 2.54999999999999987e-36 < y < 1.28000000000000006e44Initial program 99.8%
Taylor expanded in x around inf 78.6%
*-commutative78.6%
Simplified78.6%
Final simplification93.5%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -4.4e-15)
t_1
(if (<= y 1.9e+45) t (if (<= y 1.45e+199) (* y z) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -4.4e-15) {
tmp = t_1;
} else if (y <= 1.9e+45) {
tmp = t;
} else if (y <= 1.45e+199) {
tmp = 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 * (x * y)
if (y <= (-4.4d-15)) then
tmp = t_1
else if (y <= 1.9d+45) then
tmp = t
else if (y <= 1.45d+199) then
tmp = 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 * (x * y);
double tmp;
if (y <= -4.4e-15) {
tmp = t_1;
} else if (y <= 1.9e+45) {
tmp = t;
} else if (y <= 1.45e+199) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -4.4e-15: tmp = t_1 elif y <= 1.9e+45: tmp = t elif y <= 1.45e+199: tmp = y * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -4.4e-15) tmp = t_1; elseif (y <= 1.9e+45) tmp = t; elseif (y <= 1.45e+199) tmp = Float64(y * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (x * y); tmp = 0.0; if (y <= -4.4e-15) tmp = t_1; elseif (y <= 1.9e+45) tmp = t; elseif (y <= 1.45e+199) tmp = y * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.4e-15], t$95$1, If[LessEqual[y, 1.9e+45], t, If[LessEqual[y, 1.45e+199], N[(y * z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -4.4 \cdot 10^{-15}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+45}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+199}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -4.39999999999999971e-15 or 1.4499999999999999e199 < y Initial program 99.9%
Taylor expanded in t around 0 93.9%
Taylor expanded in z around 0 72.0%
if -4.39999999999999971e-15 < y < 1.9000000000000001e45Initial program 100.0%
Taylor expanded in y around 0 67.2%
if 1.9000000000000001e45 < y < 1.4499999999999999e199Initial program 99.9%
Taylor expanded in t around 0 92.0%
Taylor expanded in z around inf 59.5%
Final simplification68.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6.2e-23) (not (<= y 1.8e+49))) (* y (+ (* x y) z)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.2e-23) || !(y <= 1.8e+49)) {
tmp = y * ((x * y) + z);
} 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 <= (-6.2d-23)) .or. (.not. (y <= 1.8d+49))) then
tmp = y * ((x * y) + z)
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 <= -6.2e-23) || !(y <= 1.8e+49)) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6.2e-23) or not (y <= 1.8e+49): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.2e-23) || !(y <= 1.8e+49)) tmp = Float64(y * Float64(Float64(x * y) + z)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -6.2e-23) || ~((y <= 1.8e+49))) tmp = y * ((x * y) + z); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.2e-23], N[Not[LessEqual[y, 1.8e+49]], $MachinePrecision]], N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-23} \lor \neg \left(y \leq 1.8 \cdot 10^{+49}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -6.1999999999999998e-23 or 1.79999999999999998e49 < y Initial program 99.9%
Taylor expanded in t around 0 93.4%
if -6.1999999999999998e-23 < y < 1.79999999999999998e49Initial program 100.0%
Taylor expanded in x around 0 90.0%
Final simplification91.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.4e+51) (not (<= y 1.52e+199))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.4e+51) || !(y <= 1.52e+199)) {
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 <= (-2.4d+51)) .or. (.not. (y <= 1.52d+199))) 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 <= -2.4e+51) || !(y <= 1.52e+199)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.4e+51) or not (y <= 1.52e+199): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.4e+51) || !(y <= 1.52e+199)) 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 <= -2.4e+51) || ~((y <= 1.52e+199))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.4e+51], N[Not[LessEqual[y, 1.52e+199]], $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 -2.4 \cdot 10^{+51} \lor \neg \left(y \leq 1.52 \cdot 10^{+199}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.3999999999999999e51 or 1.51999999999999995e199 < y Initial program 99.9%
Taylor expanded in t around 0 97.6%
Taylor expanded in z around 0 77.5%
if -2.3999999999999999e51 < y < 1.51999999999999995e199Initial program 99.9%
Taylor expanded in x around 0 83.1%
Final simplification81.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.8e-53) (not (<= y 1.35e+46))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.8e-53) || !(y <= 1.35e+46)) {
tmp = y * z;
} 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 <= (-1.8d-53)) .or. (.not. (y <= 1.35d+46))) then
tmp = y * z
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 <= -1.8e-53) || !(y <= 1.35e+46)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.8e-53) or not (y <= 1.35e+46): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.8e-53) || !(y <= 1.35e+46)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.8e-53) || ~((y <= 1.35e+46))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.8e-53], N[Not[LessEqual[y, 1.35e+46]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-53} \lor \neg \left(y \leq 1.35 \cdot 10^{+46}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1.7999999999999999e-53 or 1.3500000000000001e46 < y Initial program 99.9%
Taylor expanded in t around 0 92.4%
Taylor expanded in z around inf 41.5%
if -1.7999999999999999e-53 < y < 1.3500000000000001e46Initial program 100.0%
Taylor expanded in y around 0 69.7%
Final simplification55.1%
(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 38.6%
Final simplification38.6%
herbie shell --seed 2023310
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))