
(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 (+ 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 -0.026) t_1 (if (<= z 2.1e+14) (+ 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 <= -0.026) {
tmp = t_1;
} else if (z <= 2.1e+14) {
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 <= (-0.026d0)) then
tmp = t_1
else if (z <= 2.1d+14) 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 <= -0.026) {
tmp = t_1;
} else if (z <= 2.1e+14) {
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 <= -0.026: tmp = t_1 elif z <= 2.1e+14: 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 <= -0.026) tmp = t_1; elseif (z <= 2.1e+14) 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 <= -0.026) tmp = t_1; elseif (z <= 2.1e+14) 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, -0.026], t$95$1, If[LessEqual[z, 2.1e+14], 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 -0.026:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{+14}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -0.0259999999999999988 or 2.1e14 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified85.2%
if -0.0259999999999999988 < z < 2.1e14Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6495.1%
Simplified95.1%
Final simplification90.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y))))) (if (<= y -1.15e-18) t_1 (if (<= y 0.0033) (+ 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 <= -1.15e-18) {
tmp = t_1;
} else if (y <= 0.0033) {
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 <= (-1.15d-18)) then
tmp = t_1
else if (y <= 0.0033d0) 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 <= -1.15e-18) {
tmp = t_1;
} else if (y <= 0.0033) {
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 <= -1.15e-18: tmp = t_1 elif y <= 0.0033: 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 <= -1.15e-18) tmp = t_1; elseif (y <= 0.0033) 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 <= -1.15e-18) tmp = t_1; elseif (y <= 0.0033) 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, -1.15e-18], t$95$1, If[LessEqual[y, 0.0033], 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 -1.15 \cdot 10^{-18}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.0033:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.15e-18 or 0.0033 < 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-*.f6490.2%
Simplified90.2%
if -1.15e-18 < y < 0.0033Initial program 99.9%
Taylor expanded in x around 0
Simplified89.6%
Final simplification89.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= x -2.45e+65) t_1 (if (<= x 8.2e+68) (+ t (* y z)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (x <= -2.45e+65) {
tmp = t_1;
} else if (x <= 8.2e+68) {
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 (x <= (-2.45d+65)) then
tmp = t_1
else if (x <= 8.2d+68) 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 (x <= -2.45e+65) {
tmp = t_1;
} else if (x <= 8.2e+68) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if x <= -2.45e+65: tmp = t_1 elif x <= 8.2e+68: 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 (x <= -2.45e+65) tmp = t_1; elseif (x <= 8.2e+68) 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 (x <= -2.45e+65) tmp = t_1; elseif (x <= 8.2e+68) 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[x, -2.45e+65], t$95$1, If[LessEqual[x, 8.2e+68], 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}\;x \leq -2.45 \cdot 10^{+65}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{+68}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -2.44999999999999978e65 or 8.1999999999999998e68 < x Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6470.0%
Simplified70.0%
if -2.44999999999999978e65 < x < 8.1999999999999998e68Initial program 99.9%
Taylor expanded in x around 0
Simplified84.1%
Final simplification78.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -1.4e-16) t_1 (if (<= y 0.000202) t t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -1.4e-16) {
tmp = t_1;
} else if (y <= 0.000202) {
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 <= (-1.4d-16)) then
tmp = t_1
else if (y <= 0.000202d0) 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 <= -1.4e-16) {
tmp = t_1;
} else if (y <= 0.000202) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -1.4e-16: tmp = t_1 elif y <= 0.000202: 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 <= -1.4e-16) tmp = t_1; elseif (y <= 0.000202) 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 <= -1.4e-16) tmp = t_1; elseif (y <= 0.000202) 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, -1.4e-16], t$95$1, If[LessEqual[y, 0.000202], t, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -1.4 \cdot 10^{-16}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.000202:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.4000000000000001e-16 or 2.02000000000000004e-4 < 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-*.f6466.3%
Simplified66.3%
if -1.4000000000000001e-16 < y < 2.02000000000000004e-4Initial program 99.9%
Taylor expanded in y around 0
Simplified63.0%
Final simplification64.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* x (* y y)))) (if (<= y -1.1e-15) t_1 (if (<= y 0.00118) t t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -1.1e-15) {
tmp = t_1;
} else if (y <= 0.00118) {
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 <= (-1.1d-15)) then
tmp = t_1
else if (y <= 0.00118d0) 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 <= -1.1e-15) {
tmp = t_1;
} else if (y <= 0.00118) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -1.1e-15: tmp = t_1 elif y <= 0.00118: 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 <= -1.1e-15) tmp = t_1; elseif (y <= 0.00118) 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 <= -1.1e-15) tmp = t_1; elseif (y <= 0.00118) 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, -1.1e-15], t$95$1, If[LessEqual[y, 0.00118], t, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -1.1 \cdot 10^{-15}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.00118:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.09999999999999993e-15 or 0.0011800000000000001 < y Initial program 99.9%
*-commutativeN/A
flip3-+N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
flip3-+N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f6499.8%
Applied egg-rr99.8%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6465.1%
Simplified65.1%
if -1.09999999999999993e-15 < y < 0.0011800000000000001Initial program 99.9%
Taylor expanded in y around 0
Simplified63.0%
(FPCore (x y z t) :precision binary64 (if (<= z -1.65e+22) (* y z) (if (<= z 1.85e+15) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.65e+22) {
tmp = y * z;
} else if (z <= 1.85e+15) {
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.65d+22)) then
tmp = y * z
else if (z <= 1.85d+15) 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.65e+22) {
tmp = y * z;
} else if (z <= 1.85e+15) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.65e+22: tmp = y * z elif z <= 1.85e+15: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.65e+22) tmp = Float64(y * z); elseif (z <= 1.85e+15) 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.65e+22) tmp = y * z; elseif (z <= 1.85e+15) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.65e+22], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.85e+15], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{+22}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.85 \cdot 10^{+15}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.6499999999999999e22 or 1.85e15 < z Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6461.7%
Simplified61.7%
if -1.6499999999999999e22 < z < 1.85e15Initial program 99.9%
Taylor expanded in y around 0
Simplified45.3%
(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
Simplified35.7%
herbie shell --seed 2024152
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))