
(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-define100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -5e+167)
(and (not (<= y -5.2e+138))
(or (<= y -3.4e+93) (not (<= y 2.4e+20)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5e+167) || (!(y <= -5.2e+138) && ((y <= -3.4e+93) || !(y <= 2.4e+20)))) {
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 <= (-5d+167)) .or. (.not. (y <= (-5.2d+138))) .and. (y <= (-3.4d+93)) .or. (.not. (y <= 2.4d+20))) 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 <= -5e+167) || (!(y <= -5.2e+138) && ((y <= -3.4e+93) || !(y <= 2.4e+20)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5e+167) or (not (y <= -5.2e+138) and ((y <= -3.4e+93) or not (y <= 2.4e+20))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5e+167) || (!(y <= -5.2e+138) && ((y <= -3.4e+93) || !(y <= 2.4e+20)))) 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 <= -5e+167) || (~((y <= -5.2e+138)) && ((y <= -3.4e+93) || ~((y <= 2.4e+20))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5e+167], And[N[Not[LessEqual[y, -5.2e+138]], $MachinePrecision], Or[LessEqual[y, -3.4e+93], N[Not[LessEqual[y, 2.4e+20]], $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 -5 \cdot 10^{+167} \lor \neg \left(y \leq -5.2 \cdot 10^{+138}\right) \land \left(y \leq -3.4 \cdot 10^{+93} \lor \neg \left(y \leq 2.4 \cdot 10^{+20}\right)\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4.9999999999999997e167 or -5.2000000000000002e138 < y < -3.4e93 or 2.4e20 < y Initial program 99.9%
Taylor expanded in t around -inf 90.5%
mul-1-neg90.5%
distribute-rgt-neg-in90.5%
fma-neg90.5%
+-commutative90.5%
fma-undefine90.5%
*-commutative90.5%
associate-/l*90.5%
fma-undefine90.5%
*-commutative90.5%
fma-undefine90.5%
metadata-eval90.5%
Simplified90.5%
Taylor expanded in t around 0 96.0%
Taylor expanded in z around 0 76.5%
*-commutative76.5%
Simplified76.5%
if -4.9999999999999997e167 < y < -5.2000000000000002e138 or -3.4e93 < y < 2.4e20Initial program 99.9%
Taylor expanded in x around 0 86.1%
Final simplification82.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.9e+38) (not (<= y 1.8e-19))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.9e+38) || !(y <= 1.8e-19)) {
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 <= (-1.9d+38)) .or. (.not. (y <= 1.8d-19))) 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 <= -1.9e+38) || !(y <= 1.8e-19)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.9e+38) or not (y <= 1.8e-19): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.9e+38) || !(y <= 1.8e-19)) 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 <= -1.9e+38) || ~((y <= 1.8e-19))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.9e+38], N[Not[LessEqual[y, 1.8e-19]], $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 -1.9 \cdot 10^{+38} \lor \neg \left(y \leq 1.8 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.8999999999999999e38 or 1.8000000000000001e-19 < y Initial program 99.9%
Taylor expanded in t around -inf 90.3%
mul-1-neg90.3%
distribute-rgt-neg-in90.3%
fma-neg90.3%
+-commutative90.3%
fma-undefine90.3%
*-commutative90.3%
associate-/l*88.8%
fma-undefine88.8%
*-commutative88.8%
fma-undefine88.8%
metadata-eval88.8%
Simplified88.8%
Taylor expanded in t around 0 92.0%
if -1.8999999999999999e38 < y < 1.8000000000000001e-19Initial program 100.0%
Taylor expanded in x around 0 89.2%
Final simplification90.6%
(FPCore (x y z t) :precision binary64 (if (<= z -1.75e+63) (* y (+ z (* x y))) (if (<= z 6e+23) (+ t (* y (* x y))) (+ t (* y z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.75e+63) {
tmp = y * (z + (x * y));
} else if (z <= 6e+23) {
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 <= (-1.75d+63)) then
tmp = y * (z + (x * y))
else if (z <= 6d+23) 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 <= -1.75e+63) {
tmp = y * (z + (x * y));
} else if (z <= 6e+23) {
tmp = t + (y * (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.75e+63: tmp = y * (z + (x * y)) elif z <= 6e+23: tmp = t + (y * (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.75e+63) tmp = Float64(y * Float64(z + Float64(x * y))); elseif (z <= 6e+23) 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 <= -1.75e+63) tmp = y * (z + (x * y)); elseif (z <= 6e+23) tmp = t + (y * (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.75e+63], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6e+23], 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 -1.75 \cdot 10^{+63}:\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{elif}\;z \leq 6 \cdot 10^{+23}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if z < -1.75000000000000015e63Initial program 100.0%
Taylor expanded in t around -inf 91.3%
mul-1-neg91.3%
distribute-rgt-neg-in91.3%
fma-neg91.3%
+-commutative91.3%
fma-undefine91.3%
*-commutative91.3%
associate-/l*91.1%
fma-undefine91.1%
*-commutative91.1%
fma-undefine91.1%
metadata-eval91.1%
Simplified91.1%
Taylor expanded in t around 0 86.7%
if -1.75000000000000015e63 < z < 6.0000000000000002e23Initial program 99.9%
Taylor expanded in x around inf 93.9%
*-commutative93.9%
Simplified93.9%
if 6.0000000000000002e23 < z Initial program 100.0%
Taylor expanded in x around 0 84.7%
Final simplification90.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.7e+39) (not (<= y 1.8e-19))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.7e+39) || !(y <= 1.8e-19)) {
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 <= (-2.7d+39)) .or. (.not. (y <= 1.8d-19))) 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 <= -2.7e+39) || !(y <= 1.8e-19)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.7e+39) or not (y <= 1.8e-19): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.7e+39) || !(y <= 1.8e-19)) 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 <= -2.7e+39) || ~((y <= 1.8e-19))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.7e+39], N[Not[LessEqual[y, 1.8e-19]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+39} \lor \neg \left(y \leq 1.8 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -2.70000000000000003e39 or 1.8000000000000001e-19 < y Initial program 99.9%
Taylor expanded in t around -inf 90.3%
mul-1-neg90.3%
distribute-rgt-neg-in90.3%
fma-neg90.3%
+-commutative90.3%
fma-undefine90.3%
*-commutative90.3%
associate-/l*88.8%
fma-undefine88.8%
*-commutative88.8%
fma-undefine88.8%
metadata-eval88.8%
Simplified88.8%
Taylor expanded in t around 0 92.0%
Taylor expanded in z around 0 66.4%
*-commutative66.4%
Simplified66.4%
if -2.70000000000000003e39 < y < 1.8000000000000001e-19Initial program 100.0%
Taylor expanded in y around 0 65.0%
Final simplification65.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -15000000.0) (not (<= z 4e+18))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -15000000.0) || !(z <= 4e+18)) {
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 <= (-15000000.0d0)) .or. (.not. (z <= 4d+18))) 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 <= -15000000.0) || !(z <= 4e+18)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -15000000.0) or not (z <= 4e+18): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -15000000.0) || !(z <= 4e+18)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -15000000.0) || ~((z <= 4e+18))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -15000000.0], N[Not[LessEqual[z, 4e+18]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -15000000 \lor \neg \left(z \leq 4 \cdot 10^{+18}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -1.5e7 or 4e18 < z Initial program 100.0%
Taylor expanded in t around -inf 94.0%
mul-1-neg94.0%
distribute-rgt-neg-in94.0%
fma-neg94.0%
+-commutative94.0%
fma-undefine94.0%
*-commutative94.0%
associate-/l*93.8%
fma-undefine93.8%
*-commutative93.8%
fma-undefine93.8%
metadata-eval93.8%
Simplified93.8%
Taylor expanded in z around inf 62.5%
if -1.5e7 < z < 4e18Initial program 99.9%
Taylor expanded in y around 0 52.1%
Final simplification56.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 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 37.9%
herbie shell --seed 2024086
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))