
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * cos(y)) + (x * sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x * Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x * math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x * sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x * sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + x \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -2.9e-44)
t_0
(if (<= z -8.8e-86)
(+ z (* x y))
(if (or (<= z -5.8e-133) (not (<= z 1.45e-44))) t_0 (* x (sin y)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.9e-44) {
tmp = t_0;
} else if (z <= -8.8e-86) {
tmp = z + (x * y);
} else if ((z <= -5.8e-133) || !(z <= 1.45e-44)) {
tmp = t_0;
} else {
tmp = x * sin(y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (z <= (-2.9d-44)) then
tmp = t_0
else if (z <= (-8.8d-86)) then
tmp = z + (x * y)
else if ((z <= (-5.8d-133)) .or. (.not. (z <= 1.45d-44))) then
tmp = t_0
else
tmp = x * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -2.9e-44) {
tmp = t_0;
} else if (z <= -8.8e-86) {
tmp = z + (x * y);
} else if ((z <= -5.8e-133) || !(z <= 1.45e-44)) {
tmp = t_0;
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -2.9e-44: tmp = t_0 elif z <= -8.8e-86: tmp = z + (x * y) elif (z <= -5.8e-133) or not (z <= 1.45e-44): tmp = t_0 else: tmp = x * math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.9e-44) tmp = t_0; elseif (z <= -8.8e-86) tmp = Float64(z + Float64(x * y)); elseif ((z <= -5.8e-133) || !(z <= 1.45e-44)) tmp = t_0; else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -2.9e-44) tmp = t_0; elseif (z <= -8.8e-86) tmp = z + (x * y); elseif ((z <= -5.8e-133) || ~((z <= 1.45e-44))) tmp = t_0; else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.9e-44], t$95$0, If[LessEqual[z, -8.8e-86], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -5.8e-133], N[Not[LessEqual[z, 1.45e-44]], $MachinePrecision]], t$95$0, N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{-44}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -8.8 \cdot 10^{-86}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{elif}\;z \leq -5.8 \cdot 10^{-133} \lor \neg \left(z \leq 1.45 \cdot 10^{-44}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -2.9000000000000001e-44 or -8.8000000000000006e-86 < z < -5.7999999999999997e-133 or 1.4500000000000001e-44 < z Initial program 99.8%
Taylor expanded in x around 0 85.3%
if -2.9000000000000001e-44 < z < -8.8000000000000006e-86Initial program 99.7%
Taylor expanded in y around 0 85.1%
+-commutative85.1%
Simplified85.1%
if -5.7999999999999997e-133 < z < 1.4500000000000001e-44Initial program 99.8%
Taylor expanded in x around inf 75.9%
Final simplification82.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -2.9e-44)
t_0
(if (<= z -1.4e-83)
(fma x y z)
(if (or (<= z -3.8e-129) (not (<= z 9.6e-39))) t_0 (* x (sin y)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.9e-44) {
tmp = t_0;
} else if (z <= -1.4e-83) {
tmp = fma(x, y, z);
} else if ((z <= -3.8e-129) || !(z <= 9.6e-39)) {
tmp = t_0;
} else {
tmp = x * sin(y);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.9e-44) tmp = t_0; elseif (z <= -1.4e-83) tmp = fma(x, y, z); elseif ((z <= -3.8e-129) || !(z <= 9.6e-39)) tmp = t_0; else tmp = Float64(x * sin(y)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.9e-44], t$95$0, If[LessEqual[z, -1.4e-83], N[(x * y + z), $MachinePrecision], If[Or[LessEqual[z, -3.8e-129], N[Not[LessEqual[z, 9.6e-39]], $MachinePrecision]], t$95$0, N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{-44}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{-83}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\mathbf{elif}\;z \leq -3.8 \cdot 10^{-129} \lor \neg \left(z \leq 9.6 \cdot 10^{-39}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -2.9000000000000001e-44 or -1.4e-83 < z < -3.79999999999999985e-129 or 9.60000000000000063e-39 < z Initial program 99.8%
Taylor expanded in x around 0 85.3%
if -2.9000000000000001e-44 < z < -1.4e-83Initial program 99.7%
Taylor expanded in y around 0 85.1%
+-commutative85.1%
fma-def85.2%
Simplified85.2%
if -3.79999999999999985e-129 < z < 9.60000000000000063e-39Initial program 99.8%
Taylor expanded in x around inf 75.9%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.3e-59) (not (<= x 1.6e-98))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.3e-59) || !(x <= 1.6e-98)) {
tmp = z + (x * sin(y));
} else {
tmp = z * cos(y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-7.3d-59)) .or. (.not. (x <= 1.6d-98))) then
tmp = z + (x * sin(y))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.3e-59) || !(x <= 1.6e-98)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.3e-59) or not (x <= 1.6e-98): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.3e-59) || !(x <= 1.6e-98)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.3e-59) || ~((x <= 1.6e-98))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.3e-59], N[Not[LessEqual[x, 1.6e-98]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.3 \cdot 10^{-59} \lor \neg \left(x \leq 1.6 \cdot 10^{-98}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -7.3000000000000004e-59 or 1.6e-98 < x Initial program 99.8%
Taylor expanded in y around 0 85.3%
if -7.3000000000000004e-59 < x < 1.6e-98Initial program 99.9%
Taylor expanded in x around 0 92.9%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00146) (not (<= y 0.053))) (* x (sin y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00146) || !(y <= 0.053)) {
tmp = x * sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-0.00146d0)) .or. (.not. (y <= 0.053d0))) then
tmp = x * sin(y)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00146) || !(y <= 0.053)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00146) or not (y <= 0.053): tmp = x * math.sin(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00146) || !(y <= 0.053)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00146) || ~((y <= 0.053))) tmp = x * sin(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00146], N[Not[LessEqual[y, 0.053]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00146 \lor \neg \left(y \leq 0.053\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -0.0014599999999999999 or 0.0529999999999999985 < y Initial program 99.7%
Taylor expanded in x around inf 44.8%
if -0.0014599999999999999 < y < 0.0529999999999999985Initial program 100.0%
Taylor expanded in y around 0 98.2%
+-commutative98.2%
Simplified98.2%
Final simplification71.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.6e+51) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+51) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-1.6d+51)) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+51) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.6e+51: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.6e+51) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.6e+51) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.6e+51], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+51}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.6000000000000001e51Initial program 99.8%
Taylor expanded in x around inf 70.3%
Taylor expanded in y around 0 36.9%
if -1.6000000000000001e51 < x Initial program 99.8%
*-commutative99.8%
add-sqr-sqrt62.4%
associate-*r*62.4%
fma-def62.4%
Applied egg-rr62.4%
Taylor expanded in y around 0 46.6%
Taylor expanded in y around 0 42.9%
Final simplification41.8%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 51.4%
+-commutative51.4%
Simplified51.4%
Final simplification51.4%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
*-commutative99.8%
add-sqr-sqrt51.0%
associate-*r*51.0%
fma-def51.0%
Applied egg-rr51.0%
Taylor expanded in y around 0 38.0%
Taylor expanded in y around 0 38.2%
Final simplification38.2%
herbie shell --seed 2023290
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))