# How to symbolically manipulate the closed form series output from the easyFourier package?

EasyFourier by @xzczd is a nice package to obtain a Fourier series in closed form, e.g.

f = x^2
easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]] However, the output cannot be manipulated symbolically, at least I don't know how to. For instance, differentiating the Fourier series is not possible like this:

D[easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]],x] What I would like to do is something comparable to the following, where I have copied the summand manually into a regular Mathematica Sum: BTW: How do I downscale the size of pictures in stack exchange? Is there no easier way to insert Mathematica output? How can I insert complicated Mathematica input code in 2d-mode? (Thanks for hints to these "meta" questions, too.)

• Perhaps ReleaseHold? D[ReleaseHold@easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]], x] gives 2 (I Log[1 + E^(-I x)] - I Log[1 + E^(I x)]). Aug 28, 2021 at 15:22
• @Domen, that's the evaluated form. What I need is the Out. Aug 28, 2021 at 16:27
• I have provided an answer. As for the images: you can change the size of the image on StackExchange by using pure html tag as described in the Advanced Markdown help. Furthermore, SE-Tools is a really nice tool to quickly upload images from Mathematica to SE. Aug 28, 2021 at 16:50

Inactivate has attribute HoldFirst, that is why Inactivate[ft, Sum] by itself doesn't inactivate your sum. You have to first bypass this HoldFirst with Evaluate.

ft = easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]]
D[Inactivate[Evaluate[ft], Sum] // ReleaseHold, x]

(* Inactive[Sum][-((
4 (-1)^\[FormalK] Sin[\[FormalK] x])/\[FormalK]), {\[FormalK],
1, \[Infinity]}] *)


Let's take a look at some of the examples to better understand how Inactivate works:

5 + 3
(* 8 *)

Inactivate[5 + 3, Plus]
(* Inactive[Plus][5, 3] *)

Activate[Inactivate[5 + 3, Plus], Plus]
(* 8 *)

x = Hold[5 + 3]
(* Hold[5 + 3] *)

Inactivate[x, Plus]
(* Hold[5 + 3] *)

Inactivate[Hold[5 + 3], Plus]
(* Hold[Inactive[Plus][5, 3]] *)

Inactivate[Evaluate[Hold[5 + 3]], Plus]
(* Hold[Inactive[Plus][5, 3]] *)


As you can see in the fifth example, Inactivate cannot penetrate inside x and "see" that there is a Plus (because it has attribute HoldFirst), so it doesn't inactivate it.

If you look at the documentation of Evaluate, it says: You can use Evaluate to override HoldFirst etc. attributes of built-in functions. And this is exactly what we need in this case: we use evaluate, but this doesn't mean that 5 + 3 will instantly be replaced with 8. Instead, Inactivate will be able to creep inside x and inactivate Plus.

• Great, that is exactly what I was looking for! Thanks also for your hints on the meta issues. Aug 28, 2021 at 17:17
• I'm not very familiar with Mathematica yet, and I have problems understanding why your solution works. Why does the Holdfirst attribute prevent Inactivate to work properly in this case (normally it does not)? And why do we therefore need Evaluate? This seems highly contradictory, since what we want is ft not to be evaluated, but to be inactivated. Can you possibly explain that in a few more words? Aug 28, 2021 at 21:21
• Thank you very much, I see the point now! Aug 29, 2021 at 8:06