
(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 (<= z -1.26e+138) (not (<= z 220000.0))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.26e+138) || !(z <= 220000.0)) {
tmp = t + (y * z);
} else {
tmp = t + (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 ((z <= (-1.26d+138)) .or. (.not. (z <= 220000.0d0))) then
tmp = t + (y * z)
else
tmp = t + (y * (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.26e+138) || !(z <= 220000.0)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.26e+138) or not (z <= 220000.0): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.26e+138) || !(z <= 220000.0)) tmp = Float64(t + Float64(y * z)); else tmp = Float64(t + Float64(y * Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.26e+138) || ~((z <= 220000.0))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.26e+138], N[Not[LessEqual[z, 220000.0]], $MachinePrecision]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.26 \cdot 10^{+138} \lor \neg \left(z \leq 220000\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.25999999999999994e138 or 2.2e5 < z Initial program 100.0%
Taylor expanded in x around 0 90.4%
if -1.25999999999999994e138 < z < 2.2e5Initial program 99.9%
Taylor expanded in x around inf 91.5%
*-commutative91.5%
Simplified91.5%
Final simplification91.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.6e-26) (not (<= y 9.5e+52))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.6e-26) || !(y <= 9.5e+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 <= (-2.6d-26)) .or. (.not. (y <= 9.5d+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 <= -2.6e-26) || !(y <= 9.5e+52)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.6e-26) or not (y <= 9.5e+52): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.6e-26) || !(y <= 9.5e+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 <= -2.6e-26) || ~((y <= 9.5e+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, -2.6e-26], N[Not[LessEqual[y, 9.5e+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 -2.6 \cdot 10^{-26} \lor \neg \left(y \leq 9.5 \cdot 10^{+52}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.6000000000000001e-26 or 9.49999999999999994e52 < y Initial program 99.9%
Taylor expanded in z around -inf 95.3%
mul-1-neg95.3%
distribute-rgt-neg-in95.3%
fmm-def95.3%
*-commutative95.3%
associate-/l*95.3%
metadata-eval95.3%
Simplified95.3%
Taylor expanded in t around 0 83.8%
*-commutative83.8%
associate-*r/83.7%
associate-*r*83.7%
neg-mul-183.7%
Simplified83.7%
Taylor expanded in y around 0 88.4%
if -2.6000000000000001e-26 < y < 9.49999999999999994e52Initial program 99.9%
Taylor expanded in x around 0 90.6%
Final simplification89.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.46e+109) (not (<= y 3e+53))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.46e+109) || !(y <= 3e+53)) {
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 <= (-1.46d+109)) .or. (.not. (y <= 3d+53))) 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 <= -1.46e+109) || !(y <= 3e+53)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.46e+109) or not (y <= 3e+53): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.46e+109) || !(y <= 3e+53)) 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 <= -1.46e+109) || ~((y <= 3e+53))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.46e+109], N[Not[LessEqual[y, 3e+53]], $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 -1.46 \cdot 10^{+109} \lor \neg \left(y \leq 3 \cdot 10^{+53}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.46e109 or 2.99999999999999998e53 < y Initial program 99.9%
Taylor expanded in z around -inf 96.5%
mul-1-neg96.5%
distribute-rgt-neg-in96.5%
fmm-def96.5%
*-commutative96.5%
associate-/l*96.5%
metadata-eval96.5%
Simplified96.5%
Taylor expanded in t around 0 90.5%
*-commutative90.5%
associate-*r/90.4%
associate-*r*90.4%
neg-mul-190.4%
Simplified90.4%
Taylor expanded in z around 0 79.6%
if -1.46e109 < y < 2.99999999999999998e53Initial program 99.9%
Taylor expanded in x around 0 87.1%
Final simplification84.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.9e-25) (not (<= y 2.7e+53))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.9e-25) || !(y <= 2.7e+53)) {
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 <= (-3.9d-25)) .or. (.not. (y <= 2.7d+53))) 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 <= -3.9e-25) || !(y <= 2.7e+53)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.9e-25) or not (y <= 2.7e+53): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.9e-25) || !(y <= 2.7e+53)) 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 <= -3.9e-25) || ~((y <= 2.7e+53))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.9e-25], N[Not[LessEqual[y, 2.7e+53]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{-25} \lor \neg \left(y \leq 2.7 \cdot 10^{+53}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -3.9e-25 or 2.70000000000000019e53 < y Initial program 99.9%
Taylor expanded in z around -inf 95.3%
mul-1-neg95.3%
distribute-rgt-neg-in95.3%
fmm-def95.3%
*-commutative95.3%
associate-/l*95.3%
metadata-eval95.3%
Simplified95.3%
Taylor expanded in t around 0 83.8%
*-commutative83.8%
associate-*r/83.7%
associate-*r*83.7%
neg-mul-183.7%
Simplified83.7%
Taylor expanded in z around 0 72.0%
if -3.9e-25 < y < 2.70000000000000019e53Initial program 99.9%
Taylor expanded in y around 0 65.0%
Final simplification67.7%
(FPCore (x y z t) :precision binary64 (if (<= t -1.05e-141) t (if (<= t 1.5e-83) (* y z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.05e-141) {
tmp = t;
} else if (t <= 1.5e-83) {
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 (t <= (-1.05d-141)) then
tmp = t
else if (t <= 1.5d-83) 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 (t <= -1.05e-141) {
tmp = t;
} else if (t <= 1.5e-83) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -1.05e-141: tmp = t elif t <= 1.5e-83: tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -1.05e-141) tmp = t; elseif (t <= 1.5e-83) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -1.05e-141) tmp = t; elseif (t <= 1.5e-83) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -1.05e-141], t, If[LessEqual[t, 1.5e-83], N[(y * z), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.05 \cdot 10^{-141}:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq 1.5 \cdot 10^{-83}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if t < -1.05e-141 or 1.50000000000000005e-83 < t Initial program 99.9%
Taylor expanded in y around 0 60.0%
if -1.05e-141 < t < 1.50000000000000005e-83Initial program 99.9%
Taylor expanded in x around 0 66.6%
Taylor expanded in y around inf 66.6%
Taylor expanded in z around inf 55.0%
(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 44.8%
herbie shell --seed 2024186
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))