MitPY 13: Trigonometry and Wolfram Alpha

This MitPY comes from frequent commenter, John Friend:

Dear Colleagues,

I gave a CAS-FREE question to my Specialist students whose first part was to solve (exactly) the equation \boldsymbol{\cot 2x = \sec x}. I solved it two different ways and got two different answers that are equivalent. I’ve attached my calculations.

I checked my answers using Mathematica, which lead to my question: Mathematica gives a third different but equivalent answer (scroll down to real solutions). How has Mathematica got this answer?

It may be that Mathematica ‘used’ my Method 2, got my tan answer and then for some arcane reason ‘manipulated’ this answer into the one it finally gives. If so, I can ascribe the answer to a Mathematica quirk. But it may be that Mathematica is using a method unclear to me that leads to its answer. If so, I’m curious.

Any thoughts are appreciated.

Click to access Calculations.pdf

11 Replies to “MitPY 13: Trigonometry and Wolfram Alpha”

  1. Hmmm. When I click the Alpha link, Mathematica is giving me only two (real) answers, not three.

    The method it appears to be using is the half-angle substitution, which a human would never do, because it results in a fifth order polynomial (fourth order after simplifying). To solve the polynomial, the

        \[z = t + \frac1t\]

    substitution is used. This turns it into a quadratic, which mathematica completes as a square. Taking square roots gives the pair of solutions, and then undoing the definitions the final answer.

    1. Cheers, Glen. Much obliged.

      I figured it must have involved first finding x/2 somehow but what you’ve said would not have occurred to me. I wonder if Mathematica just ‘brute forces’ a rigid algorithm onto everything (being a machine, brute force is its forte).

      (By third I meant I found two forms of answers and Mathematica gave a third form of answer).

      1. Oh! Now I understand the “third” comment.

        The coolest thing about Mathematica’s solution IMO is that substitution to turn the polynomial you get out of it into a quadratic. That can’t be generic, I wonder if it is expected in problems like these though?

        Mathematica likely just tries this half angle strategy on everything, and then tries a laundry list of subs when solving polynomials. So it is easy to explain away.

        Nevertheless I still found it rather nifty.

        1. lol! Nifty is one word for it. If a student made that substitution I’d call him/her a bonehead! For this question I think the substitution \displaystyle t = \tan (x) is \displaystyle niftier, although I concede that \displaystyle t = \tan\left( \frac{t}{2}\right) leads to a polynomial more directly albeit you then have to make another non-trivial substitution to get the roots.

        2. If you’re really interested in how Mathematica does certain tasks, there’s a page on how various methods are roughly implemented here: https://reference.wolfram.com/language/tutorial/SomeNotesOnInternalImplementation.html

          Some of the solving stuff takes over 500 pages… Really tells you how many people have been working on this programming language.

          And while we’re at it, I remember my teacher calling me out for using a nuclear solution for a trigonometric problem on a test. Funny times, because that sort of complex trick I pulled out of nowhere could also be used for solving certain integrals with trigonometric terms.

          Edit: I just checked the question and remembered exactly what I did, and its even more amazing that I managed to use two silly identities and still somehow get the question right. Stupidity finds a way I suppose… If anyone is interested, I managed to use the identity

              \[\cos(2x) = 2\cos^2(x)-1\]

          followed by

              \[\alpha \cos(2x)+\beta \sin(2x) = r \sin(2x+\gamma)\]

          instead of simply factorising.

          1. Smart teacher. I’d do exactly the same …

            You don’t bring a nuclear bomb to a knife-fight – while you’re fumbling around with the bomb the other guy’s already won the fight.

  2. So this has been more rewarding than I expected. I’ve only thought of and used the Weierstrass substitution in the context of integration (we’re all victims of our experience), but obviously it’s a very useful technique for solving trigonometric equations since it always transforms a trigonometric equation into a polynomial equation. For example, I’ve always solved equations of the form

    \displaystyle a \sin (x) + b \cos (x) = c

    by first converting \displaystyle a \sin (x) + b \cos (x) into one of the forms \displaystyle r \sin (x \pm \theta) or \displaystyle r \cos (x \pm \theta) using the compound angle formulae (we’re all victims of our experience). But clearly the Weierstrass substitution can be used to transform the above equation into a quadratic equation and is a ‘nifty’ alternative method. For example:

    \displaystyle \sin (x) + 2 \cos (x) = 1

    \displaystyle \Rightarrow \frac{2t}{1+t^2} + \frac{2(1 - t^2)}{1 + t^2} = 1

    where \displaystyle t = \tan \left( \frac{x}{2} \right)

    \displaystyle \Rightarrow 2t + 2(1 - t^2) = t^2 + 1

    \displaystyle \Rightarrow 3t^2 - 2t - 1 = 0

    \displaystyle \Rightarrow (3t + 1)(t-1) = 0.

    Case 1:
    \displaystyle t = -\frac{1}{3} \Rightarrow \tan \left( \frac{x}{2} \right) = -\frac{1}{3} \Rightarrow \frac{x}{2} = \tan^{-1} \left( -\frac{1}{3}\right) + n \pi, (\displaystyle n \in Z)

    \displaystyle \Rightarrow x = -2 \tan^{-1} \left( \frac{1}{3}\right) + 2n \pi.

    Case 2:
    \displaystyle t = 1 etc.

    Indeed, Wolfram Alpha gives the same solutions rather than the ‘obvious’ solution involving arcsin or arccos:
    https://www.wolframalpha.com/input/?i=solve+Sin%5Bx%5D+%2B+2+Cos%5Bx%5D+%3D+1

    It looks like Mathematica solves all trig equations in this way (although I haven’t found any documentation to support this) which makes good sense because the problem is then reduced to the well-known problem of solving a polynomial equation.

    With this insight, the Mathematica solution to \displaystyle \text{cot} (2x) = \text{sec} (x) is obvious and inevitable.

    1. It is interesting. I guess if the trig problem leads to a sufficiently awful polynomial, then Mathematica may become unstuck. I find the possibility of a trig problem like this that has a nice “by hand” solution that doesn’t involve the half-angle sub quite interesting; I wonder what Mathematica would do with it.

      1. I’ve checked what Mathematica does when the polynomial is ‘awful’ and, unsurprisingly, Mathematica gives decimal approximations rather than surds.

        I say unsurprising because the roots of cubic and quartic polynomials can be calculated exactly using the cubic and quartic formulae and this is what Mathematica does. However, when the degree of the polynomial is greater than 4 there is no general formula and so a numerical approximation of the roots is all that can be done. (I find that such impossibilities surprise many students (and even some teachers), particularly when it comes to integration).

        As for “a trig problem … that has a nice “by hand” solution”, it’s hard to tell because the answers come out ‘nicely’. I suspect that Mathematica would still use the Weiertstrass substitution (why change its computational spots?)

        For example, to solve \displaystyle \sin (2x) = \cos (x):

        \displaystyle \frac{4t(1-t^2)}{(1+t^2)(1-t^2)}=\frac{1-t^2}{1+t^2} \Rightarrow t^4 - 4t^3 +4t - 1 = 0

        \displaystyle \Rightarrow (t-1)(t+1)(t^2-4t+1) = 0.

        So \displaystyle \tan \left( \frac{x}{2}\right) = \pm 1 or \displaystyle \tan \left( \frac{x}{2}\right) = 2 \pm \sqrt{3}

        and Mathematica has no trouble solving \displaystyle \tan \left( \frac{x}{2}\right) = 2 \pm \sqrt{3} to get the exact value of x.

        For very simple trig equations like \displaystyle \sin \left(\frac{x}{2}\right) = \frac{1}{4} Mathematica does give an answer involving the expected arcsin rather than the ‘unexpected’ \displaystyle \text{tan}^{-1}\left(\frac{1}{\sqrt{15}}\right).

        Maybe Sai could shed some light on how Mathematica solves trigonometric equations if he’s not too busy reminiscing about the good old days of being a knucklehead.

  3. This may be of interest.

    Adrian, Y.E.O. (2007). “Trig or treat: An encyclopedia of trigonometric identity proofs.” World Scientific.

Leave a Reply

Your email address will not be published.

The maximum upload file size: 128 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded.

This site uses Akismet to reduce spam. Learn how your comment data is processed.