
(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 (+ (* x y) z))))
double code(double x, double y, double z, double t) {
return t + (y * ((x * y) + z));
}
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 * ((x * y) + z))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * ((x * y) + z));
}
def code(x, y, z, t): return t + (y * ((x * y) + z))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(Float64(x * y) + z))) end
function tmp = code(x, y, z, t) tmp = t + (y * ((x * y) + z)); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(x \cdot y + z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4200000000.0) (not (<= y 3.7e-53))) (* y (+ (* x y) z)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4200000000.0) || !(y <= 3.7e-53)) {
tmp = y * ((x * y) + z);
} 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 <= (-4200000000.0d0)) .or. (.not. (y <= 3.7d-53))) then
tmp = y * ((x * y) + z)
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 <= -4200000000.0) || !(y <= 3.7e-53)) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4200000000.0) or not (y <= 3.7e-53): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4200000000.0) || !(y <= 3.7e-53)) tmp = Float64(y * Float64(Float64(x * y) + z)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4200000000.0) || ~((y <= 3.7e-53))) tmp = y * ((x * y) + z); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4200000000.0], N[Not[LessEqual[y, 3.7e-53]], $MachinePrecision]], N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4200000000 \lor \neg \left(y \leq 3.7 \cdot 10^{-53}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4.2e9 or 3.69999999999999982e-53 < y Initial program 99.9%
Taylor expanded in t around inf 93.3%
associate-/l*91.9%
+-commutative91.9%
*-commutative91.9%
fma-undefine91.9%
Simplified91.9%
Taylor expanded in t around 0 92.0%
if -4.2e9 < y < 3.69999999999999982e-53Initial program 100.0%
Taylor expanded in x around 0 93.9%
Final simplification92.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.8e-5) (not (<= y 1.02e-42))) (* x (* y y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.8e-5) || !(y <= 1.02e-42)) {
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 <= (-2.8d-5)) .or. (.not. (y <= 1.02d-42))) 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 <= -2.8e-5) || !(y <= 1.02e-42)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.8e-5) or not (y <= 1.02e-42): tmp = x * (y * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.8e-5) || !(y <= 1.02e-42)) 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 <= -2.8e-5) || ~((y <= 1.02e-42))) tmp = x * (y * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.8e-5], N[Not[LessEqual[y, 1.02e-42]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-5} \lor \neg \left(y \leq 1.02 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -2.79999999999999996e-5 or 1.0199999999999999e-42 < y Initial program 99.9%
Taylor expanded in x around inf 81.3%
+-commutative81.3%
unpow281.3%
associate-/l*85.6%
distribute-lft-out89.9%
Simplified89.9%
Taylor expanded in t around 0 84.9%
Taylor expanded in y around inf 70.9%
if -2.79999999999999996e-5 < y < 1.0199999999999999e-42Initial program 100.0%
Taylor expanded in y around 0 70.6%
Final simplification70.8%
(FPCore (x y z t) :precision binary64 (if (<= y -1.9e+85) (* x (* y y)) (if (<= y 1.2e+43) (+ t (* y z)) (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.9e+85) {
tmp = x * (y * y);
} else if (y <= 1.2e+43) {
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.9d+85)) then
tmp = x * (y * y)
else if (y <= 1.2d+43) 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.9e+85) {
tmp = x * (y * y);
} else if (y <= 1.2e+43) {
tmp = t + (y * z);
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.9e+85: tmp = x * (y * y) elif y <= 1.2e+43: tmp = t + (y * z) else: tmp = y * (x * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.9e+85) tmp = Float64(x * Float64(y * y)); elseif (y <= 1.2e+43) 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.9e+85) tmp = x * (y * y); elseif (y <= 1.2e+43) tmp = t + (y * z); else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.9e+85], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.2e+43], 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.9 \cdot 10^{+85}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{+43}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -1.89999999999999996e85Initial program 100.0%
Taylor expanded in x around inf 82.6%
+-commutative82.6%
unpow282.6%
associate-/l*90.4%
distribute-lft-out92.4%
Simplified92.4%
Taylor expanded in t around 0 86.6%
Taylor expanded in y around inf 82.8%
if -1.89999999999999996e85 < y < 1.20000000000000012e43Initial program 99.9%
Taylor expanded in x around 0 85.6%
if 1.20000000000000012e43 < y Initial program 99.9%
Taylor expanded in t around inf 90.5%
associate-/l*90.4%
+-commutative90.4%
*-commutative90.4%
fma-undefine90.5%
Simplified90.5%
Taylor expanded in t around 0 97.5%
Taylor expanded in z around 0 81.1%
Final simplification84.0%
(FPCore (x y z t) :precision binary64 (if (<= y -0.00055) (* x (* y y)) (if (<= y 2.1e-42) t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -0.00055) {
tmp = x * (y * y);
} else if (y <= 2.1e-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 <= (-0.00055d0)) then
tmp = x * (y * y)
else if (y <= 2.1d-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 <= -0.00055) {
tmp = x * (y * y);
} else if (y <= 2.1e-42) {
tmp = t;
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -0.00055: tmp = x * (y * y) elif y <= 2.1e-42: tmp = t else: tmp = y * (x * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -0.00055) tmp = Float64(x * Float64(y * y)); elseif (y <= 2.1e-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 <= -0.00055) tmp = x * (y * y); elseif (y <= 2.1e-42) tmp = t; else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -0.00055], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.1e-42], t, N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00055:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-42}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -5.50000000000000033e-4Initial program 100.0%
Taylor expanded in x around inf 83.5%
+-commutative83.5%
unpow283.5%
associate-/l*89.1%
distribute-lft-out90.5%
Simplified90.5%
Taylor expanded in t around 0 81.9%
Taylor expanded in y around inf 70.8%
if -5.50000000000000033e-4 < y < 2.10000000000000006e-42Initial program 100.0%
Taylor expanded in y around 0 70.6%
if 2.10000000000000006e-42 < y Initial program 99.8%
Taylor expanded in t around inf 92.0%
associate-/l*90.5%
+-commutative90.5%
*-commutative90.5%
fma-undefine90.5%
Simplified90.5%
Taylor expanded in t around 0 97.8%
Taylor expanded in z around 0 75.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.6e+139) (not (<= z 3.4e+95))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.6e+139) || !(z <= 3.4e+95)) {
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.6d+139)) .or. (.not. (z <= 3.4d+95))) 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.6e+139) || !(z <= 3.4e+95)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.6e+139) or not (z <= 3.4e+95): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.6e+139) || !(z <= 3.4e+95)) 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.6e+139) || ~((z <= 3.4e+95))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.6e+139], N[Not[LessEqual[z, 3.4e+95]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+139} \lor \neg \left(z \leq 3.4 \cdot 10^{+95}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.60000000000000022e139 or 3.40000000000000022e95 < z Initial program 100.0%
Taylor expanded in t around inf 98.7%
associate-/l*85.6%
+-commutative85.6%
*-commutative85.6%
fma-undefine85.6%
Simplified85.6%
Taylor expanded in z around inf 67.3%
if -2.60000000000000022e139 < z < 3.40000000000000022e95Initial program 99.9%
Taylor expanded in y around 0 42.8%
Final simplification49.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.7%
herbie shell --seed 2024185
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))