# to reduce the unknowns of a set of equations with several symbolic coefficients, e.g. using the GroebnerBasis

I have a set of $4$ equations with $4$ unknowns $\theta_1$ to $\theta_4$, and would like to eliminate the number of unknowns, to get a smaller set of equations, e.g. $n$ equations with $n$ unknowns, where $n=3,2$, or even better $1$. The four equations look like this

$\small-\cos \left(\theta _1\right) \left(a_2 \cos \left(\theta _2\right)+b_4 \sin \left(\theta _3\right)\right)+b_5 \left(\sin \left(\theta _1\right) \cos \left(\theta _4\right)-\sin \left(\theta _4\right) \cos \left(\theta _1\right) \cos \left(\theta _3\right)\right)+o_1=0\\ \small-\sin \left(\theta _1\right) \left(a_2 \cos \left(\theta _2\right)+b_4 \sin \left(\theta _3\right)\right)-b_5 \left(\cos \left(\theta _1\right) \cos \left(\theta _4\right)+\sin \left(\theta _1\right) \sin \left(\theta _4\right) \cos \left(\theta _3\right)\right)+o_2=0\\ \small a_2 \left(-\sin \left(\theta _2\right)\right)-b_5 \sin \left(\theta _3\right) \sin \left(\theta _4\right)+b_4 \cos \left(\theta _3\right)+o_3=0\\ \small \cos \left(\theta _4\right) \left(e_2 \sin \left(\theta _1\right)+e_1 \cos \left(\theta _1\right)\right)+\sin \left(\theta _4\right) \left(\frac{1}{2} e_3 \sin \left(\theta _3\right)-e_2 \cos \left(\theta _1\right) \cos \left(\theta _3\right)+e_1 \sin \left(\theta _1\right) \cos \left(\theta _3\right)\right)=0$

which can also be written as an equivalent form

$\small b_5 \cos \left(\theta _4\right)+o_1 \sin \left(\theta _1\right)-o_2 \cos \left(\theta _1\right)=0\\ \small-\sin \left(\theta _1\right) \left(a_2 \cos \left(\theta _2\right)+b_4 \sin \left(\theta _3\right)\right)-b_5 \left(\cos \left(\theta _1\right) \cos \left(\theta _4\right)+\sin \left(\theta _1\right) \sin \left(\theta _4\right) \cos \left(\theta _3\right)\right)+o_2=0\\ \small a_2 \left(-\sin \left(\theta _2\right)\right)-b_5 \sin \left(\theta _3\right) \sin \left(\theta _4\right)+b_4 \cos \left(\theta _3\right)+o_3=0\\\small \cos \left(\theta _4\right) \left(e_2 \sin \left(\theta _1\right)+e_1 \cos \left(\theta _1\right)\right)+\sin \left(\theta _4\right) \left(\frac{1}{2} e_3 \sin \left(\theta _3\right)-e_2 \cos \left(\theta _1\right) \cos \left(\theta _3\right)+e_1 \sin \left(\theta _1\right) \cos \left(\theta _3\right)\right)=0$

I'm thinking of using the Groebner basis to solve the problem, but the problem has some feature making it challenging: 1. it involves sine and cosine 2. it involves some symbolic coefficients $a_2,b_4,b_5$ and $o_1,o_2,o_3,e_1,e_2,e_3$, the former three are constant so I can give them some numbers, but the latter six are variable, so I can't give them numbers.

I tried using the command

  basisSinCos =   GroebnerBasis[   eqs, {Subscript[\[Theta], 1], Subscript[\[Theta], 2],
Subscript[\[Theta], 3]}, {Subscript[\[Theta], 4]}];


but somehow it return some lengthy results with more than four equations; moreover, $\theta_4$ is not eliminated at all. I wonder what does this mean?

I guess this may be because that the GrobenerBasis is not quite suitable for the case involving sine and cosine. So I change $\sin\theta_i$ and $\cos\theta_i$ into $x_i$ and $y_i$, and add the four conditions of $\sin^2\theta_i+\cos^2\theta_i=1$, then end up with $8$ polynomials, i.e.

$\left\{-y_1 \left(a_2 y_2+b_4 x_3\right)+b_5 \left(x_1 y_4-x_4 y_1 y_3\right)+o_1,-x_1 \left(a_2 y_2+b_4 x_3\right)-b_5 \left(x_1 x_4 y_3+y_1 y_4\right)+o_2,-a_2 x_2-b_5 x_3 x_4+b_4 y_3+o_3,x_4 \left(e_1 x_1 y_3+\frac{e_3 x_3}{2}-e_2 y_1 y_3\right)+y_4 \left(e_2 x_1+e_1 y_1\right),x_1^2+y_1^2-1,x_2^2+y_2^2-1,x_3^2+y_3^2-1,x_4^2+y_4^2-1\right\}$

This time, mathematica can provide the correct GrobenerBasis or eliminate the variables as I wish, only when I specify numerical values to all the coefficients, via the function

GroebnerBasis[ eqspoly, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 4],   Subscript[x, 3]}, {Subscript[y, 1], Subscript[y, 2], Subscript[y,    4],Subscript[y, 3]}];


however, if I keep the symbolic coefficients as symbols, it will keep running without returning a result if the coefficients are left as symbols even I only leave only the three symbols $o_1,o_2,o_3$.

So I wonder whether the Groebner basis is the correct tool I should use? and how should I continue? Could someone give me a hand? I have uploaded the code to "https://www.dropbox.com/sh/5e46dntkyrllu4y/AAD4dCrTRQcZO3GT3qhC9JCTa?dl=0"

Thanks a lot!

According to the comments, it seems that changing the equations into polynomials is preferable. Below are the code for these eight equations

eqspoly={Subscript[o, 1]-Subscript[y, 1] (Subscript[b, 4] Subscript[x, 3]+Subscript[a, 2] Subscript[y, 2])+Subscript[b, 5] (-Subscript[x, 4] Subscript[y, 1] Subscript[y, 3]+Subscript[x, 1] Subscript[y, 4]),Subscript[o, 2]-Subscript[x, 1] (Subscript[b, 4] Subscript[x, 3]+Subscript[a, 2] Subscript[y, 2])-Subscript[b, 5] (Subscript[x, 1] Subscript[x, 4] Subscript[y, 3]+Subscript[y, 1] Subscript[y, 4]),Subscript[o, 3]-Subscript[a, 2] Subscript[x, 2]-Subscript[b, 5] Subscript[x, 3] Subscript[x, 4]+Subscript[b, 4] Subscript[y, 3],Subscript[x, 4] ((Subscript[e, 3] Subscript[x, 3])/2+Subscript[e, 1] Subscript[x, 1] Subscript[y, 3]-Subscript[e, 2] Subscript[y, 1] Subscript[y, 3])+(Subscript[e, 2] Subscript[x, 1]+Subscript[e, 1] Subscript[y, 1]) Subscript[y, 4],-1+Subsuperscript[x, 1, 2]+Subsuperscript[y, 1, 2],-1+Subsuperscript[x, 2, 2]+Subsuperscript[y, 2, 2],-1+Subsuperscript[x, 3, 2]+Subsuperscript[y, 3, 2],-1+Subsuperscript[x, 4, 2]+Subsuperscript[y, 4, 2]}


then I tried the following code:

basis= GroebnerBasis[ eqspoly, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 4],  Subscript[x, 3]}, {Subscript[y, 1], Subscript[y, 2], Subscript[y, 4], Subscript[y, 3]}, CoefficientDomain -> RationalFunctions,  MonomialOrder -> EliminationOrder]


This also runs without returning a result. I could change the order of the variables in the parameters, but in my several test, they are always slow, since there are around 600 different ways of sorting these variables, I don't know how to choose from. I wonder if there is any guideline of how to choose the order? And I wonder if I have used the correct options for the the command I'm using in the GroebnerBasis? Thanks!

• A lot of the efficiency hinges on choosing the right MonomialOrder and Sort settings; see the docs for GroebnerBasis for details. – J. M. is away Aug 16 '17 at 1:31
• (1) It would be much better to have the equations in the post itself rater than requiring a download to access them. (2) This prior response might be along the lines of what you want. Involves making explicit polynomials from the trigs e.g. replace Cos[x] with c[x], adding the usual trig identity relations e.g. c[x]^2+s[x]^2-1, and creating a term order to eliminate some variables (e.g. MonomialOrder->EliminationOrder with variable lists set up for eliminating those in the third argument to GB). – Daniel Lichtblau Aug 17 '17 at 16:24
• @J.M., thanks for your comments, I know this effect, but I'm not quite familiar with the GrebnerBasis. From the docs of GroebnerBasis, I didn't find the answer to: 1. does it work well on functions involving sine and cosine? If so, why does it return a basis whose dimension is higher than the previous set, and why the parameter I specified in the second bracket is not eliminated? 2. If it is mainly for polynomials, and I have some symbolic coefficients, the basis returned is also of higher dimension than the previous basis. What does this mean? Could you please help me answer these question? – larry Aug 17 '17 at 16:42
• @DanielLichtblau, hi, please see the update in the statement. Thanks. – larry Aug 17 '17 at 17:49