
(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 8 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 (fma (fma x y z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(x, y, z), y, t);
}
function code(x, y, z, t) return fma(fma(x, y, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(x * y + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)
\end{array}
Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -380.0) (not (<= y 1.9e-52))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -380.0) || !(y <= 1.9e-52)) {
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 <= (-380.0d0)) .or. (.not. (y <= 1.9d-52))) 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 <= -380.0) || !(y <= 1.9e-52)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -380.0) or not (y <= 1.9e-52): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -380.0) || !(y <= 1.9e-52)) 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 <= -380.0) || ~((y <= 1.9e-52))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -380.0], N[Not[LessEqual[y, 1.9e-52]], $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 -380 \lor \neg \left(y \leq 1.9 \cdot 10^{-52}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -380 or 1.9000000000000002e-52 < y Initial program 99.9%
Taylor expanded in t around inf 91.5%
associate-/l*90.8%
+-commutative90.8%
*-commutative90.8%
fma-undefine90.8%
Simplified90.8%
Taylor expanded in t around 0 91.4%
if -380 < y < 1.9000000000000002e-52Initial program 99.9%
Taylor expanded in x around 0 91.0%
Final simplification91.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1300.0) (not (<= y 0.28))) (* x (* y y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1300.0) || !(y <= 0.28)) {
tmp = x * (y * 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 <= (-1300.0d0)) .or. (.not. (y <= 0.28d0))) then
tmp = x * (y * 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 <= -1300.0) || !(y <= 0.28)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1300.0) or not (y <= 0.28): tmp = x * (y * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1300.0) || !(y <= 0.28)) tmp = Float64(x * Float64(y * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1300.0) || ~((y <= 0.28))) tmp = x * (y * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1300.0], N[Not[LessEqual[y, 0.28]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1300 \lor \neg \left(y \leq 0.28\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1300 or 0.28000000000000003 < y Initial program 99.9%
Taylor expanded in x around inf 75.1%
+-commutative75.1%
unpow275.1%
associate-/l*78.0%
distribute-lft-out90.1%
Simplified90.1%
Taylor expanded in t around 0 86.3%
Taylor expanded in y around inf 67.4%
if -1300 < y < 0.28000000000000003Initial program 99.9%
Taylor expanded in y around 0 69.1%
Final simplification68.2%
(FPCore (x y z t) :precision binary64 (if (<= y -1.5e+49) (* x (* y y)) (if (<= y 2.6e+129) (+ t (* y z)) (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.5e+49) {
tmp = x * (y * y);
} else if (y <= 2.6e+129) {
tmp = t + (y * z);
} else {
tmp = y * (x * y);
}
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.5d+49)) then
tmp = x * (y * y)
else if (y <= 2.6d+129) then
tmp = t + (y * z)
else
tmp = y * (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.5e+49) {
tmp = x * (y * y);
} else if (y <= 2.6e+129) {
tmp = t + (y * z);
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.5e+49: tmp = x * (y * y) elif y <= 2.6e+129: tmp = t + (y * z) else: tmp = y * (x * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.5e+49) tmp = Float64(x * Float64(y * y)); elseif (y <= 2.6e+129) tmp = Float64(t + Float64(y * z)); else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -1.5e+49) tmp = x * (y * y); elseif (y <= 2.6e+129) tmp = t + (y * z); else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.5e+49], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.6e+129], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+49}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+129}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -1.5000000000000001e49Initial program 100.0%
Taylor expanded in x around inf 79.5%
+-commutative79.5%
unpow279.5%
associate-/l*82.6%
distribute-lft-out95.6%
Simplified95.6%
Taylor expanded in t around 0 95.3%
Taylor expanded in y around inf 79.6%
if -1.5000000000000001e49 < y < 2.60000000000000012e129Initial program 99.9%
Taylor expanded in x around 0 80.7%
if 2.60000000000000012e129 < y Initial program 99.9%
Taylor expanded in t around inf 90.9%
associate-/l*91.0%
+-commutative91.0%
*-commutative91.0%
fma-undefine91.0%
Simplified91.0%
Taylor expanded in t around 0 97.1%
Taylor expanded in z around 0 77.8%
Final simplification80.1%
(FPCore (x y z t) :precision binary64 (if (<= y -40.0) (* x (* y y)) (if (<= y 0.095) t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -40.0) {
tmp = x * (y * y);
} else if (y <= 0.095) {
tmp = t;
} else {
tmp = y * (x * y);
}
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 <= (-40.0d0)) then
tmp = x * (y * y)
else if (y <= 0.095d0) then
tmp = t
else
tmp = y * (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -40.0) {
tmp = x * (y * y);
} else if (y <= 0.095) {
tmp = t;
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -40.0: tmp = x * (y * y) elif y <= 0.095: tmp = t else: tmp = y * (x * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -40.0) tmp = Float64(x * Float64(y * y)); elseif (y <= 0.095) tmp = t; else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -40.0) tmp = x * (y * y); elseif (y <= 0.095) tmp = t; else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -40.0], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.095], t, N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -40:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 0.095:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -40Initial program 99.9%
Taylor expanded in x around inf 80.4%
+-commutative80.4%
unpow280.4%
associate-/l*83.0%
distribute-lft-out93.8%
Simplified93.8%
Taylor expanded in t around 0 90.9%
Taylor expanded in y around inf 72.8%
if -40 < y < 0.095000000000000001Initial program 99.9%
Taylor expanded in y around 0 69.1%
if 0.095000000000000001 < y Initial program 99.9%
Taylor expanded in t around inf 93.5%
associate-/l*93.5%
+-commutative93.5%
*-commutative93.5%
fma-undefine93.5%
Simplified93.5%
Taylor expanded in t around 0 91.6%
Taylor expanded in z around 0 63.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.8e+151) (not (<= z 3.5e+127))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.8e+151) || !(z <= 3.5e+127)) {
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 ((z <= (-3.8d+151)) .or. (.not. (z <= 3.5d+127))) 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 ((z <= -3.8e+151) || !(z <= 3.5e+127)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.8e+151) or not (z <= 3.5e+127): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.8e+151) || !(z <= 3.5e+127)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.8e+151) || ~((z <= 3.5e+127))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.8e+151], N[Not[LessEqual[z, 3.5e+127]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+151} \lor \neg \left(z \leq 3.5 \cdot 10^{+127}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -3.8e151 or 3.49999999999999978e127 < z Initial program 99.9%
Taylor expanded in x around 0 75.4%
Taylor expanded in z around inf 75.4%
Taylor expanded in y around inf 62.8%
if -3.8e151 < z < 3.49999999999999978e127Initial program 99.9%
Taylor expanded in y around 0 46.9%
Final simplification51.5%
(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 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 37.3%
herbie shell --seed 2024172
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))