
(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 9 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-def99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (* y y))))
(if (<= y -0.0138)
t_1
(if (<= y 1.22e-64)
t
(if (<= y 5.2e-18) (* y z) (if (<= y 1.95e+42) t t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -0.0138) {
tmp = t_1;
} else if (y <= 1.22e-64) {
tmp = t;
} else if (y <= 5.2e-18) {
tmp = y * z;
} else if (y <= 1.95e+42) {
tmp = t;
} 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 = x * (y * y)
if (y <= (-0.0138d0)) then
tmp = t_1
else if (y <= 1.22d-64) then
tmp = t
else if (y <= 5.2d-18) then
tmp = y * z
else if (y <= 1.95d+42) then
tmp = t
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 = x * (y * y);
double tmp;
if (y <= -0.0138) {
tmp = t_1;
} else if (y <= 1.22e-64) {
tmp = t;
} else if (y <= 5.2e-18) {
tmp = y * z;
} else if (y <= 1.95e+42) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -0.0138: tmp = t_1 elif y <= 1.22e-64: tmp = t elif y <= 5.2e-18: tmp = y * z elif y <= 1.95e+42: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -0.0138) tmp = t_1; elseif (y <= 1.22e-64) tmp = t; elseif (y <= 5.2e-18) tmp = Float64(y * z); elseif (y <= 1.95e+42) tmp = t; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y * y); tmp = 0.0; if (y <= -0.0138) tmp = t_1; elseif (y <= 1.22e-64) tmp = t; elseif (y <= 5.2e-18) tmp = y * z; elseif (y <= 1.95e+42) tmp = t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0138], t$95$1, If[LessEqual[y, 1.22e-64], t, If[LessEqual[y, 5.2e-18], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.95e+42], t, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -0.0138:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-64}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+42}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -0.0138 or 1.94999999999999985e42 < y Initial program 99.9%
Taylor expanded in t around 0 87.6%
Taylor expanded in z around 0 65.4%
Taylor expanded in y around 0 66.3%
unpow266.3%
Simplified66.3%
if -0.0138 < y < 1.22000000000000003e-64 or 5.2000000000000001e-18 < y < 1.94999999999999985e42Initial program 100.0%
Taylor expanded in y around 0 64.7%
if 1.22000000000000003e-64 < y < 5.2000000000000001e-18Initial program 100.0%
Taylor expanded in t around 0 87.6%
Taylor expanded in z around inf 77.0%
Final simplification65.9%
(FPCore (x y z t)
:precision binary64
(if (<= y -2.1)
(* x (* y y))
(if (<= y 3.8e-64)
t
(if (<= y 2e-16) (* y z) (if (<= y 7.5e+42) t (* y (* x y)))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.1) {
tmp = x * (y * y);
} else if (y <= 3.8e-64) {
tmp = t;
} else if (y <= 2e-16) {
tmp = y * z;
} else if (y <= 7.5e+42) {
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 <= (-2.1d0)) then
tmp = x * (y * y)
else if (y <= 3.8d-64) then
tmp = t
else if (y <= 2d-16) then
tmp = y * z
else if (y <= 7.5d+42) 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 <= -2.1) {
tmp = x * (y * y);
} else if (y <= 3.8e-64) {
tmp = t;
} else if (y <= 2e-16) {
tmp = y * z;
} else if (y <= 7.5e+42) {
tmp = t;
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -2.1: tmp = x * (y * y) elif y <= 3.8e-64: tmp = t elif y <= 2e-16: tmp = y * z elif y <= 7.5e+42: tmp = t else: tmp = y * (x * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -2.1) tmp = Float64(x * Float64(y * y)); elseif (y <= 3.8e-64) tmp = t; elseif (y <= 2e-16) tmp = Float64(y * z); elseif (y <= 7.5e+42) 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 <= -2.1) tmp = x * (y * y); elseif (y <= 3.8e-64) tmp = t; elseif (y <= 2e-16) tmp = y * z; elseif (y <= 7.5e+42) tmp = t; else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.1], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.8e-64], t, If[LessEqual[y, 2e-16], N[(y * z), $MachinePrecision], If[LessEqual[y, 7.5e+42], t, N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-64}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-16}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+42}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -2.10000000000000009Initial program 99.9%
Taylor expanded in t around 0 91.2%
Taylor expanded in z around 0 72.4%
Taylor expanded in y around 0 74.1%
unpow274.1%
Simplified74.1%
if -2.10000000000000009 < y < 3.8000000000000002e-64 or 2e-16 < y < 7.50000000000000041e42Initial program 100.0%
Taylor expanded in y around 0 64.7%
if 3.8000000000000002e-64 < y < 2e-16Initial program 100.0%
Taylor expanded in t around 0 87.6%
Taylor expanded in z around inf 77.0%
if 7.50000000000000041e42 < y Initial program 99.9%
Taylor expanded in t around 0 83.3%
Taylor expanded in z around 0 57.1%
Final simplification65.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -550.0) (not (<= y 3e+43))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -550.0) || !(y <= 3e+43)) {
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 <= (-550.0d0)) .or. (.not. (y <= 3d+43))) 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 <= -550.0) || !(y <= 3e+43)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -550.0) or not (y <= 3e+43): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -550.0) || !(y <= 3e+43)) 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 <= -550.0) || ~((y <= 3e+43))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -550.0], N[Not[LessEqual[y, 3e+43]], $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 -550 \lor \neg \left(y \leq 3 \cdot 10^{+43}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -550 or 3.00000000000000017e43 < y Initial program 99.9%
Taylor expanded in t around 0 87.5%
if -550 < y < 3.00000000000000017e43Initial program 100.0%
Taylor expanded in x around 0 93.0%
Final simplification90.6%
(FPCore (x y z t) :precision binary64 (if (<= z -9.2e+29) (* y (+ z (* x y))) (if (<= z 3.7e+60) (+ t (* y (* x y))) (+ t (* y z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.2e+29) {
tmp = y * (z + (x * y));
} else if (z <= 3.7e+60) {
tmp = t + (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 (z <= (-9.2d+29)) then
tmp = y * (z + (x * y))
else if (z <= 3.7d+60) then
tmp = t + (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 (z <= -9.2e+29) {
tmp = y * (z + (x * y));
} else if (z <= 3.7e+60) {
tmp = t + (y * (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -9.2e+29: tmp = y * (z + (x * y)) elif z <= 3.7e+60: tmp = t + (y * (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -9.2e+29) tmp = Float64(y * Float64(z + Float64(x * y))); elseif (z <= 3.7e+60) tmp = Float64(t + 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 (z <= -9.2e+29) tmp = y * (z + (x * y)); elseif (z <= 3.7e+60) tmp = t + (y * (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -9.2e+29], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.7e+60], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+29}:\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{elif}\;z \leq 3.7 \cdot 10^{+60}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if z < -9.2000000000000004e29Initial program 100.0%
Taylor expanded in t around 0 84.8%
if -9.2000000000000004e29 < z < 3.69999999999999988e60Initial program 99.9%
Taylor expanded in x around inf 96.3%
*-commutative96.3%
Simplified96.3%
if 3.69999999999999988e60 < z Initial program 99.9%
Taylor expanded in x around 0 90.2%
Final simplification92.3%
(FPCore (x y z t) :precision binary64 (if (<= y -3.8e+52) (* x (* y y)) (if (<= y 1.5e+197) (+ t (* y z)) (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3.8e+52) {
tmp = x * (y * y);
} else if (y <= 1.5e+197) {
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 <= (-3.8d+52)) then
tmp = x * (y * y)
else if (y <= 1.5d+197) 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 <= -3.8e+52) {
tmp = x * (y * y);
} else if (y <= 1.5e+197) {
tmp = t + (y * z);
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -3.8e+52: tmp = x * (y * y) elif y <= 1.5e+197: tmp = t + (y * z) else: tmp = y * (x * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -3.8e+52) tmp = Float64(x * Float64(y * y)); elseif (y <= 1.5e+197) 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 <= -3.8e+52) tmp = x * (y * y); elseif (y <= 1.5e+197) tmp = t + (y * z); else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -3.8e+52], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.5e+197], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+52}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+197}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -3.8e52Initial program 99.9%
Taylor expanded in t around 0 94.2%
Taylor expanded in z around 0 79.0%
Taylor expanded in y around 0 80.9%
unpow280.9%
Simplified80.9%
if -3.8e52 < y < 1.5000000000000001e197Initial program 99.9%
Taylor expanded in x around 0 84.3%
if 1.5000000000000001e197 < y Initial program 100.0%
Taylor expanded in t around 0 94.6%
Taylor expanded in z around 0 83.5%
Final simplification83.6%
(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 (<= z -9.2e+29) (* y z) (if (<= z 1.15e+65) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.2e+29) {
tmp = y * z;
} else if (z <= 1.15e+65) {
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 <= (-9.2d+29)) then
tmp = y * z
else if (z <= 1.15d+65) 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 <= -9.2e+29) {
tmp = y * z;
} else if (z <= 1.15e+65) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -9.2e+29: tmp = y * z elif z <= 1.15e+65: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -9.2e+29) tmp = Float64(y * z); elseif (z <= 1.15e+65) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -9.2e+29) tmp = y * z; elseif (z <= 1.15e+65) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -9.2e+29], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.15e+65], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+29}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+65}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -9.2000000000000004e29 or 1.15e65 < z Initial program 100.0%
Taylor expanded in t around 0 79.7%
Taylor expanded in z around inf 66.3%
if -9.2000000000000004e29 < z < 1.15e65Initial program 99.9%
Taylor expanded in y around 0 57.3%
Final simplification61.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 40.1%
Final simplification40.1%
herbie shell --seed 2023297
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))