
(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 8 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-define99.8%
Simplified99.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 (if (or (<= x -1.38e-40) (not (<= x 2.8e-136))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.38e-40) || !(x <= 2.8e-136)) {
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 <= (-1.38d-40)) .or. (.not. (x <= 2.8d-136))) 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 <= -1.38e-40) || !(x <= 2.8e-136)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.38e-40) or not (x <= 2.8e-136): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.38e-40) || !(x <= 2.8e-136)) 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 <= -1.38e-40) || ~((x <= 2.8e-136))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.38e-40], N[Not[LessEqual[x, 2.8e-136]], $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 -1.38 \cdot 10^{-40} \lor \neg \left(x \leq 2.8 \cdot 10^{-136}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.37999999999999996e-40 or 2.8000000000000001e-136 < x Initial program 99.8%
Taylor expanded in y around 0 91.5%
if -1.37999999999999996e-40 < x < 2.8000000000000001e-136Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 85.2%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2e-6) (not (<= y 0.0055))) (* x (sin y)) (fma x y z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e-6) || !(y <= 0.0055)) {
tmp = x * sin(y);
} else {
tmp = fma(x, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -7.2e-6) || !(y <= 0.0055)) tmp = Float64(x * sin(y)); else tmp = fma(x, y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e-6], N[Not[LessEqual[y, 0.0055]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-6} \lor \neg \left(y \leq 0.0055\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\end{array}
\end{array}
if y < -7.19999999999999967e-6 or 0.0054999999999999997 < y Initial program 99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around inf 59.5%
if -7.19999999999999967e-6 < y < 0.0054999999999999997Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.033) (not (<= y 0.055))) (* x (sin y)) (+ z (* y (+ x (* y (+ (* z -0.5) (* -0.16666666666666666 (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.033) || !(y <= 0.055)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (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.033d0)) .or. (.not. (y <= 0.055d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * ((z * (-0.5d0)) + ((-0.16666666666666666d0) * (x * y))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.033) || !(y <= 0.055)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.033) or not (y <= 0.055): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.033) || !(y <= 0.055)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(Float64(z * -0.5) + Float64(-0.16666666666666666 * Float64(x * y))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.033) || ~((y <= 0.055))) tmp = x * sin(y); else tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.033], N[Not[LessEqual[y, 0.055]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(N[(z * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.033 \lor \neg \left(y \leq 0.055\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5 + -0.16666666666666666 \cdot \left(x \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.033000000000000002 or 0.0550000000000000003 < y Initial program 99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around inf 59.2%
if -0.033000000000000002 < y < 0.0550000000000000003Initial program 99.9%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.9e+165) (not (<= x 9.5e+207))) (* x y) (* x (/ z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+165) || !(x <= 9.5e+207)) {
tmp = x * y;
} else {
tmp = x * (z / x);
}
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 <= (-2.9d+165)) .or. (.not. (x <= 9.5d+207))) then
tmp = x * y
else
tmp = x * (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+165) || !(x <= 9.5e+207)) {
tmp = x * y;
} else {
tmp = x * (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.9e+165) or not (x <= 9.5e+207): tmp = x * y else: tmp = x * (z / x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.9e+165) || !(x <= 9.5e+207)) tmp = Float64(x * y); else tmp = Float64(x * Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.9e+165) || ~((x <= 9.5e+207))) tmp = x * y; else tmp = x * (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.9e+165], N[Not[LessEqual[x, 9.5e+207]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * N[(z / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+165} \lor \neg \left(x \leq 9.5 \cdot 10^{+207}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{z}{x}\\
\end{array}
\end{array}
if x < -2.90000000000000006e165 or 9.5000000000000005e207 < x Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in y around 0 35.9%
+-commutative35.9%
Simplified35.9%
Taylor expanded in x around inf 30.4%
*-commutative30.4%
Simplified30.4%
if -2.90000000000000006e165 < x < 9.5000000000000005e207Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 54.6%
+-commutative54.6%
Simplified54.6%
Taylor expanded in x around inf 48.4%
Taylor expanded in y around 0 39.7%
Final simplification37.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%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 50.9%
+-commutative50.9%
Simplified50.9%
Final simplification50.9%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return 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 = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 50.9%
+-commutative50.9%
Simplified50.9%
Taylor expanded in x around inf 15.5%
*-commutative15.5%
Simplified15.5%
Final simplification15.5%
herbie shell --seed 2024139
(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))))