2

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]]

enter image description here

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]

enter image description here

What I would like to do is something comparable to the following, where I have copied the summand manually into a regular Mathematica Sum:

enter image description here

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.)

Roland Salz
  • 381
  • 1
  • 6
  • 1
    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)]). – Domen Aug 28 '21 at 15:22
  • @Domen, that's the evaluated form. What I need is the Out[94]. – Roland Salz Aug 28 '21 at 16:27
  • 1
    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. – Domen Aug 28 '21 at 16:50

1 Answers1

4

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.

Domen
  • 23,608
  • 1
  • 27
  • 45
  • Great, that is exactly what I was looking for! Thanks also for your hints on the meta issues. – Roland Salz Aug 28 '21 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? – Roland Salz Aug 28 '21 at 21:21
  • Thank you very much, I see the point now! – Roland Salz Aug 29 '21 at 08:06