
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) - (z * 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 = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) - (z * 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 = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma z (- (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-define99.8%
sin-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) - (z * 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 = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - z \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.45e-46) (not (<= x 2.6e-19))) (* x (cos y)) (* z (* x (- (/ 1.0 z) (/ (sin y) x))))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e-46) || !(x <= 2.6e-19)) {
tmp = x * cos(y);
} else {
tmp = z * (x * ((1.0 / z) - (sin(y) / 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 <= (-1.45d-46)) .or. (.not. (x <= 2.6d-19))) then
tmp = x * cos(y)
else
tmp = z * (x * ((1.0d0 / z) - (sin(y) / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e-46) || !(x <= 2.6e-19)) {
tmp = x * Math.cos(y);
} else {
tmp = z * (x * ((1.0 / z) - (Math.sin(y) / x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.45e-46) or not (x <= 2.6e-19): tmp = x * math.cos(y) else: tmp = z * (x * ((1.0 / z) - (math.sin(y) / x))) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.45e-46) || !(x <= 2.6e-19)) tmp = Float64(x * cos(y)); else tmp = Float64(z * Float64(x * Float64(Float64(1.0 / z) - Float64(sin(y) / x)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.45e-46) || ~((x <= 2.6e-19))) tmp = x * cos(y); else tmp = z * (x * ((1.0 / z) - (sin(y) / x))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.45e-46], N[Not[LessEqual[x, 2.6e-19]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * N[(x * N[(N[(1.0 / z), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-46} \lor \neg \left(x \leq 2.6 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(\frac{1}{z} - \frac{\sin y}{x}\right)\right)\\
\end{array}
\end{array}
if x < -1.45000000000000002e-46 or 2.60000000000000013e-19 < x Initial program 99.8%
Taylor expanded in x around inf 88.6%
if -1.45000000000000002e-46 < x < 2.60000000000000013e-19Initial program 99.7%
Taylor expanded in z around inf 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around inf 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
Taylor expanded in y around 0 87.7%
Final simplification88.2%
(FPCore (x y z)
:precision binary64
(if (<= y -5.4e+187)
(* z (- (sin y)))
(if (or (<= y -0.215) (not (<= y 1.85e-6)))
(* x (cos y))
(+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* z y)))) z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e+187) {
tmp = z * -sin(y);
} else if ((y <= -0.215) || !(y <= 1.85e-6)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - 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 (y <= (-5.4d+187)) then
tmp = z * -sin(y)
else if ((y <= (-0.215d0)) .or. (.not. (y <= 1.85d-6))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (z * y)))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e+187) {
tmp = z * -Math.sin(y);
} else if ((y <= -0.215) || !(y <= 1.85e-6)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.4e+187: tmp = z * -math.sin(y) elif (y <= -0.215) or not (y <= 1.85e-6): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.4e+187) tmp = Float64(z * Float64(-sin(y))); elseif ((y <= -0.215) || !(y <= 1.85e-6)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(z * y)))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.4e+187) tmp = z * -sin(y); elseif ((y <= -0.215) || ~((y <= 1.85e-6))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.4e+187], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], If[Or[LessEqual[y, -0.215], N[Not[LessEqual[y, 1.85e-6]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{+187}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{elif}\;y \leq -0.215 \lor \neg \left(y \leq 1.85 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(z \cdot y\right)\right) - z\right)\\
\end{array}
\end{array}
if y < -5.40000000000000016e187Initial program 99.6%
Taylor expanded in x around 0 66.4%
neg-mul-166.4%
distribute-rgt-neg-in66.4%
Simplified66.4%
if -5.40000000000000016e187 < y < -0.214999999999999997 or 1.8500000000000001e-6 < y Initial program 99.6%
Taylor expanded in x around inf 72.8%
if -0.214999999999999997 < y < 1.8500000000000001e-6Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.23) (not (<= y 1.85e-6))) (* x (cos y)) (+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* z y)))) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.23) || !(y <= 1.85e-6)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - 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 ((y <= (-0.23d0)) .or. (.not. (y <= 1.85d-6))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (z * y)))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.23) || !(y <= 1.85e-6)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.23) or not (y <= 1.85e-6): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.23) || !(y <= 1.85e-6)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(z * y)))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.23) || ~((y <= 1.85e-6))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.23], N[Not[LessEqual[y, 1.85e-6]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.23 \lor \neg \left(y \leq 1.85 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(z \cdot y\right)\right) - z\right)\\
\end{array}
\end{array}
if y < -0.23000000000000001 or 1.8500000000000001e-6 < y Initial program 99.6%
Taylor expanded in x around inf 65.3%
if -0.23000000000000001 < y < 1.8500000000000001e-6Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification82.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.35e+214) (not (<= z 6.6e+113))) (* z (- y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e+214) || !(z <= 6.6e+113)) {
tmp = z * -y;
} else {
tmp = 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 ((z <= (-1.35d+214)) .or. (.not. (z <= 6.6d+113))) then
tmp = z * -y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e+214) || !(z <= 6.6e+113)) {
tmp = z * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.35e+214) or not (z <= 6.6e+113): tmp = z * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.35e+214) || !(z <= 6.6e+113)) tmp = Float64(z * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.35e+214) || ~((z <= 6.6e+113))) tmp = z * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.35e+214], N[Not[LessEqual[z, 6.6e+113]], $MachinePrecision]], N[(z * (-y)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+214} \lor \neg \left(z \leq 6.6 \cdot 10^{+113}\right):\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.35000000000000005e214 or 6.6000000000000006e113 < z Initial program 99.8%
Taylor expanded in y around 0 63.2%
mul-1-neg63.2%
unsub-neg63.2%
Simplified63.2%
Taylor expanded in x around 0 52.0%
mul-1-neg52.0%
distribute-rgt-neg-out52.0%
Simplified52.0%
if -1.35000000000000005e214 < z < 6.6000000000000006e113Initial program 99.8%
flip--59.3%
div-inv59.2%
Applied egg-rr43.4%
Taylor expanded in y around 0 43.1%
Taylor expanded in y around 0 46.4%
Final simplification47.4%
(FPCore (x y z) :precision binary64 (- x (* z y)))
double code(double x, double y, double z) {
return x - (z * 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 - (z * y)
end function
public static double code(double x, double y, double z) {
return x - (z * y);
}
def code(x, y, z): return x - (z * y)
function code(x, y, z) return Float64(x - Float64(z * y)) end
function tmp = code(x, y, z) tmp = x - (z * y); end
code[x_, y_, z_] := N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 54.1%
mul-1-neg54.1%
unsub-neg54.1%
Simplified54.1%
Final simplification54.1%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
flip--58.2%
div-inv58.0%
Applied egg-rr37.6%
Taylor expanded in y around 0 37.9%
Taylor expanded in y around 0 40.7%
Final simplification40.7%
herbie shell --seed 2024060
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))