Hi everyone! It's been a remarkably long time since I posted on MaplePrimes -- I should probably briefly reintroduce myself to the community here. My name is Erik Postma. I manage the mathematical software group at Maplesoft: the team that writes most of the Maple-language code in the Maple product, also known as the math library. You can find a longer introduction at this link.
One of my tasks at Maplesoft is the following. When a request for tech support comes in, our tech support team can usually answer the request by themselves. But no single person can know everything, and when specialized knowledge of Maple's mathematical library is needed, they ask my team for help. I screen such requests, answer what I can by myself, and send the even more specialized requests to the experts responsible for the appropriate part of the library.
Yesterday I received a request from a user asking how to unwrap angles occurring in an expression. This is the general idea of taking the fact that , and similarly for the other trig functions; and using it to modify an expression of the form to make it look "nicer" by adding or subtracting a multiple of to the angle. For a constant, real value of you would simply make the result be as close to 0 as possible; this is discussed in e.g. this MaplePrimes question, but the expressions that this user was interested in had arguments for the trig functions that involved variables, too.
In such cases, the easiest solution is usually to write a small piece of custom code that the user can use. You might think that we should just add all these bits and pieces to the Maple product, so that everyone can use them -- but there are several reasons why that's not usually a good idea:
That said, I thought this case was interesting enough to post on MaplePrimes, so that the community can take a look - maybe there is something here that can help you with your own code.
So here is the concrete question from the user. They have expressions coming from an inverse Laplace transform, such as:
F := -0.3000*(-1 + exp(-s))*s/(0.0500*s^2 + 0.1*s + 125);
f := invlaplace(F, s, t)*u(t);
# result: (.1680672269e-1*exp(1.-1.*t)*Heaviside(t-1.)*(7.141428429*sin(49.98999900*t-
I interpreted their request for unwrapping these angles as replacing the expressions of the form with versions where the constant term was unwrapped. Thinking a bit about how to be safe if unexpected expressions show up, I came up with the following solution:
unwrap_trig_functions := module()
local ModuleApply := proc(expr :: algebraic, $)
return evalindets(expr, ':-trig', process_trig);
local process_trig := proc(expr :: trig, $)
local terms := convert(op(expr), ':-list', ':-`+`');
local const, nonconst;
const, nonconst := selectremove(type, terms, ':-complexcons');
const := add(const);
local result := add(nonconst) + (
if is(const = 0) then
const := evalf(const);
if type(const, ':-float') then
frem(Re(const), 2.*Pi) + I*Im(const);
return op(0, expr)(result);
# To use this, with f defined as above:
f2 := unwrap_trig_functions(f);
# result: (.1680672269e-1*exp(1.-1.*t)*Heaviside(t-1.)*(7.141428429*sin(49.98999900*t+
Exercise for the reader, in case you expect to encounter very large constant terms: replace the calls to frem above with the code that Alec Mihailovs wrote in the question linked above!
We had the exciting opportunity to interview Dr Trefor Bazett, a math professor at the University of Victoria who also regularly posts videos to his YouTube channel explaining a wide variety of math concepts, from cool math facts to full university courses. You may also recognize him from the recent webinar he did on effective interactive learning! If you’re a teacher, and particularly if you’re trying to find ways to keep your students engaged when teaching math online, read on for some great advice and perspective from someone who’s already built a significant online following. If you’re not a teacher, read on anyways! We may not all be teachers, but we’ve all been (or are!) students. And as students, we probably all have some opinions on how things should be taught! Read on for a new perspective, and maybe even some new ways to approach your learning in the future.