
(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 (+ 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 (let* ((t_1 (+ t (* y z)))) (if (<= z -5.2e+26) t_1 (if (<= z 2.8e+83) (+ t (* y (* x y))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = t + (y * z);
double tmp;
if (z <= -5.2e+26) {
tmp = t_1;
} else if (z <= 2.8e+83) {
tmp = t + (y * (x * y));
} 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 <= (-5.2d+26)) then
tmp = t_1
else if (z <= 2.8d+83) then
tmp = t + (y * (x * y))
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 <= -5.2e+26) {
tmp = t_1;
} else if (z <= 2.8e+83) {
tmp = t + (y * (x * y));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = t + (y * z) tmp = 0 if z <= -5.2e+26: tmp = t_1 elif z <= 2.8e+83: tmp = t + (y * (x * y)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(t + Float64(y * z)) tmp = 0.0 if (z <= -5.2e+26) tmp = t_1; elseif (z <= 2.8e+83) tmp = Float64(t + Float64(y * Float64(x * y))); 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 <= -5.2e+26) tmp = t_1; elseif (z <= 2.8e+83) tmp = t + (y * (x * y)); 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, -5.2e+26], t$95$1, If[LessEqual[z, 2.8e+83], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t + y \cdot z\\
\mathbf{if}\;z \leq -5.2 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{+83}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -5.20000000000000004e26 or 2.8e83 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified87.3%
if -5.20000000000000004e26 < z < 2.8e83Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6495.4%
Simplified95.4%
Final simplification92.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y))))) (if (<= y -1800.0) t_1 (if (<= y 1.95e+48) (+ t (* y z)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -1800.0) {
tmp = t_1;
} else if (y <= 1.95e+48) {
tmp = t + (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 * (z + (x * y))
if (y <= (-1800.0d0)) then
tmp = t_1
else if (y <= 1.95d+48) then
tmp = t + (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 * (z + (x * y));
double tmp;
if (y <= -1800.0) {
tmp = t_1;
} else if (y <= 1.95e+48) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (x * y)) tmp = 0 if y <= -1800.0: tmp = t_1 elif y <= 1.95e+48: tmp = t + (y * z) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -1800.0) tmp = t_1; elseif (y <= 1.95e+48) tmp = Float64(t + Float64(y * z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (x * y)); tmp = 0.0; if (y <= -1800.0) tmp = t_1; elseif (y <= 1.95e+48) tmp = t + (y * z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1800.0], t$95$1, If[LessEqual[y, 1.95e+48], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -1800:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+48}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1800 or 1.95e48 < y Initial program 99.9%
Taylor expanded in y around inf
distribute-rgt-inN/A
+-commutativeN/A
unpow2N/A
associate-*r*N/A
fma-defineN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
fma-defineN/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6491.8%
Simplified91.8%
if -1800 < y < 1.95e48Initial program 100.0%
Taylor expanded in x around 0
Simplified87.9%
Final simplification90.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -8.5e+38) t_1 (if (<= y 6.6e+63) (+ t (* y z)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -8.5e+38) {
tmp = t_1;
} else if (y <= 6.6e+63) {
tmp = t + (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 <= (-8.5d+38)) then
tmp = t_1
else if (y <= 6.6d+63) then
tmp = t + (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 <= -8.5e+38) {
tmp = t_1;
} else if (y <= 6.6e+63) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -8.5e+38: tmp = t_1 elif y <= 6.6e+63: tmp = t + (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 <= -8.5e+38) tmp = t_1; elseif (y <= 6.6e+63) tmp = Float64(t + 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 <= -8.5e+38) tmp = t_1; elseif (y <= 6.6e+63) tmp = t + (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, -8.5e+38], t$95$1, If[LessEqual[y, 6.6e+63], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+38}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{+63}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.4999999999999997e38 or 6.6000000000000003e63 < y Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6480.3%
Simplified80.3%
if -8.4999999999999997e38 < y < 6.6000000000000003e63Initial program 100.0%
Taylor expanded in x around 0
Simplified85.3%
Final simplification82.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -4.6e+32) t_1 (if (<= y 1.95e+48) t t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -4.6e+32) {
tmp = t_1;
} else if (y <= 1.95e+48) {
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 = y * (x * y)
if (y <= (-4.6d+32)) then
tmp = t_1
else if (y <= 1.95d+48) 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 = y * (x * y);
double tmp;
if (y <= -4.6e+32) {
tmp = t_1;
} else if (y <= 1.95e+48) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -4.6e+32: tmp = t_1 elif y <= 1.95e+48: tmp = t 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.6e+32) tmp = t_1; elseif (y <= 1.95e+48) tmp = t; 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.6e+32) tmp = t_1; elseif (y <= 1.95e+48) tmp = t; 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.6e+32], t$95$1, If[LessEqual[y, 1.95e+48], t, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -4.6 \cdot 10^{+32}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+48}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.5999999999999999e32 or 1.95e48 < y Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6478.9%
Simplified78.9%
if -4.5999999999999999e32 < y < 1.95e48Initial program 100.0%
Taylor expanded in y around 0
Simplified59.8%
Final simplification69.6%
(FPCore (x y z t) :precision binary64 (if (<= z -1.3e+74) (* y z) (if (<= z 4.5e-24) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.3e+74) {
tmp = y * z;
} else if (z <= 4.5e-24) {
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 <= (-1.3d+74)) then
tmp = y * z
else if (z <= 4.5d-24) 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 <= -1.3e+74) {
tmp = y * z;
} else if (z <= 4.5e-24) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.3e+74: tmp = y * z elif z <= 4.5e-24: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.3e+74) tmp = Float64(y * z); elseif (z <= 4.5e-24) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.3e+74) tmp = y * z; elseif (z <= 4.5e-24) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.3e+74], N[(y * z), $MachinePrecision], If[LessEqual[z, 4.5e-24], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{+74}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-24}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.3e74 or 4.4999999999999997e-24 < z Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6458.9%
Simplified58.9%
if -1.3e74 < z < 4.4999999999999997e-24Initial program 99.9%
Taylor expanded in y around 0
Simplified43.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
Simplified33.1%
herbie shell --seed 2024158
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))