
(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 (+ (* y (fma y x z)) t))
double code(double x, double y, double z, double t) {
return (y * fma(y, x, z)) + t;
}
function code(x, y, z, t) return Float64(Float64(y * fma(y, x, z)) + t) end
code[x_, y_, z_, t_] := N[(N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \mathsf{fma}\left(y, x, z\right) + t
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
*-commutative99.9%
fma-undefine99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ t (* y z))))
(if (<= z -6.2e+42)
t_1
(if (<= z 2.7e-8)
(+ t (* y (* y x)))
(if (<= z 9.5e+121) (* y (+ z (* y x))) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = t + (y * z);
double tmp;
if (z <= -6.2e+42) {
tmp = t_1;
} else if (z <= 2.7e-8) {
tmp = t + (y * (y * x));
} else if (z <= 9.5e+121) {
tmp = y * (z + (y * x));
} 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 = t + (y * z)
if (z <= (-6.2d+42)) then
tmp = t_1
else if (z <= 2.7d-8) then
tmp = t + (y * (y * x))
else if (z <= 9.5d+121) then
tmp = y * (z + (y * x))
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 = t + (y * z);
double tmp;
if (z <= -6.2e+42) {
tmp = t_1;
} else if (z <= 2.7e-8) {
tmp = t + (y * (y * x));
} else if (z <= 9.5e+121) {
tmp = y * (z + (y * x));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = t + (y * z) tmp = 0 if z <= -6.2e+42: tmp = t_1 elif z <= 2.7e-8: tmp = t + (y * (y * x)) elif z <= 9.5e+121: tmp = y * (z + (y * x)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(t + Float64(y * z)) tmp = 0.0 if (z <= -6.2e+42) tmp = t_1; elseif (z <= 2.7e-8) tmp = Float64(t + Float64(y * Float64(y * x))); elseif (z <= 9.5e+121) tmp = Float64(y * Float64(z + Float64(y * x))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = t + (y * z); tmp = 0.0; if (z <= -6.2e+42) tmp = t_1; elseif (z <= 2.7e-8) tmp = t + (y * (y * x)); elseif (z <= 9.5e+121) tmp = y * (z + (y * x)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.2e+42], t$95$1, If[LessEqual[z, 2.7e-8], N[(t + N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9.5e+121], N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t + y \cdot z\\
\mathbf{if}\;z \leq -6.2 \cdot 10^{+42}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-8}:\\
\;\;\;\;t + y \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{+121}:\\
\;\;\;\;y \cdot \left(z + y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -6.2000000000000003e42 or 9.49999999999999949e121 < z Initial program 100.0%
Taylor expanded in x around 0 92.6%
if -6.2000000000000003e42 < z < 2.70000000000000002e-8Initial program 99.9%
Taylor expanded in x around inf 97.7%
*-commutative97.7%
Simplified97.7%
if 2.70000000000000002e-8 < z < 9.49999999999999949e121Initial program 99.9%
Taylor expanded in t around 0 90.5%
Final simplification94.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6.8e+24) (not (<= y 4.6e+59))) (* y (+ z (* y x))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.8e+24) || !(y <= 4.6e+59)) {
tmp = y * (z + (y * x));
} 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.8d+24)) .or. (.not. (y <= 4.6d+59))) then
tmp = y * (z + (y * x))
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.8e+24) || !(y <= 4.6e+59)) {
tmp = y * (z + (y * x));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6.8e+24) or not (y <= 4.6e+59): tmp = y * (z + (y * x)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.8e+24) || !(y <= 4.6e+59)) tmp = Float64(y * Float64(z + Float64(y * x))); 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.8e+24) || ~((y <= 4.6e+59))) tmp = y * (z + (y * x)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.8e+24], N[Not[LessEqual[y, 4.6e+59]], $MachinePrecision]], N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+24} \lor \neg \left(y \leq 4.6 \cdot 10^{+59}\right):\\
\;\;\;\;y \cdot \left(z + y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -6.8000000000000001e24 or 4.60000000000000016e59 < y Initial program 99.9%
Taylor expanded in t around 0 93.8%
if -6.8000000000000001e24 < y < 4.60000000000000016e59Initial program 99.9%
Taylor expanded in x around 0 87.0%
Final simplification90.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6.8e+24) (not (<= y 1.05e+65))) (* y (* y x)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.8e+24) || !(y <= 1.05e+65)) {
tmp = y * (y * x);
} 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 <= (-6.8d+24)) .or. (.not. (y <= 1.05d+65))) then
tmp = y * (y * x)
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 <= -6.8e+24) || !(y <= 1.05e+65)) {
tmp = y * (y * x);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6.8e+24) or not (y <= 1.05e+65): tmp = y * (y * x) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.8e+24) || !(y <= 1.05e+65)) tmp = Float64(y * Float64(y * x)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -6.8e+24) || ~((y <= 1.05e+65))) tmp = y * (y * x); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.8e+24], N[Not[LessEqual[y, 1.05e+65]], $MachinePrecision]], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+24} \lor \neg \left(y \leq 1.05 \cdot 10^{+65}\right):\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -6.8000000000000001e24 or 1.04999999999999996e65 < y Initial program 99.9%
Taylor expanded in t around 0 93.8%
Taylor expanded in z around 0 68.0%
*-commutative68.0%
Simplified68.0%
if -6.8000000000000001e24 < y < 1.04999999999999996e65Initial program 99.9%
Taylor expanded in y around 0 63.3%
Final simplification65.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.7e+105) (not (<= y 1.25e+98))) (* y (* y x)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.7e+105) || !(y <= 1.25e+98)) {
tmp = y * (y * x);
} 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.7d+105)) .or. (.not. (y <= 1.25d+98))) then
tmp = y * (y * x)
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.7e+105) || !(y <= 1.25e+98)) {
tmp = y * (y * x);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.7e+105) or not (y <= 1.25e+98): tmp = y * (y * x) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.7e+105) || !(y <= 1.25e+98)) tmp = Float64(y * Float64(y * x)); 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.7e+105) || ~((y <= 1.25e+98))) tmp = y * (y * x); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.7e+105], N[Not[LessEqual[y, 1.25e+98]], $MachinePrecision]], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+105} \lor \neg \left(y \leq 1.25 \cdot 10^{+98}\right):\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.70000000000000016e105 or 1.25e98 < y Initial program 99.9%
Taylor expanded in t around 0 97.6%
Taylor expanded in z around 0 75.9%
*-commutative75.9%
Simplified75.9%
if -2.70000000000000016e105 < y < 1.25e98Initial program 99.9%
Taylor expanded in x around 0 81.8%
Final simplification79.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.8e+52) (not (<= z 4.6e+16))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.8e+52) || !(z <= 4.6e+16)) {
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 <= (-2.8d+52)) .or. (.not. (z <= 4.6d+16))) 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 <= -2.8e+52) || !(z <= 4.6e+16)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.8e+52) or not (z <= 4.6e+16): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.8e+52) || !(z <= 4.6e+16)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.8e+52) || ~((z <= 4.6e+16))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.8e+52], N[Not[LessEqual[z, 4.6e+16]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{+52} \lor \neg \left(z \leq 4.6 \cdot 10^{+16}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.8e52 or 4.6e16 < z Initial program 100.0%
Taylor expanded in t around 0 79.8%
Taylor expanded in z around inf 64.1%
if -2.8e52 < z < 4.6e16Initial program 99.9%
Taylor expanded in y around 0 49.4%
Final simplification56.5%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* y x)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
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 + (y * x)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
def code(x, y, z, t): return t + (y * (z + (y * x)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(y * x)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (y * x))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + y \cdot x\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 36.4%
Final simplification36.4%
herbie shell --seed 2024046
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))