# Obtaining a Previously Constructed Function as Desired Output

I was playing around with some Generalized Trigonometric Functions defined as follows;

 w[n_] := E^((2*\[Pi]*I)/n)

Ncos[n_, x_] := Expand[(1/n)*Sum[E^(x*w[2 n]^(2 k + 1)), {k, 0, n - 1}]]

Nsin[n_, j_, x_] := Expand[(1/(n*w[2 n]^j))*Sum[w[n]^(-j*k) E^(x*w[2 n]^(2 k + 1)), {k, 0, n - 1}]]


These functions act like the familiar trigonometric functions and have the property that

$$\frac{d^{2n}}{dx^{2n}}f(x)=f(x)$$ or $$f^{(n)}(x)+f(x)=0$$

As I was testing with paper and pencil I wrote up the above functions when I got home to my computer and observed that these relations hold. However, when I employ the derivative function $D$ in Mathematica, it will give the derivative in terms of the expanded function. For example, if I type in

 D[Ncos[3,x],x]


It returns $$-\frac{e^{-x}}{3}+\frac{1}{3}e^{{\frac{-i\pi}{3}-e^{\frac{-i\pi}{3}}}x}+\frac{1}{3}e^{{\frac{i\pi}{3}-e^{\frac{i\pi}{3}}}x}$$

The derivative should equal -Nsin[3,2,x], and when you input

 -Nsin[3,2,x]


it returns

$$-\frac{e^{-x}}{3}-\frac{1}{3}e^{{\frac{-4i\pi}{3}-e^{\frac{-i\pi}{3}}}x}-\frac{1}{3}e^{{\frac{-2i\pi}{3}-e^{\frac{i\pi}{3}}}x}$$

While Mathematica doesn't output the same form, subtracting the two yields 0, proving their equality...

My question is this. Is there a way to get mathematica, when I input

 D[Ncos[3,x],x]


to output

 -Nsin[3,2,x]


Or for other derivative, for example, if I input

 D[D[D[Ncos[3,x],x],x],x]


I would like to see

 -Ncos[3,x]


Is this possible?

• Could you check your results? I copied your definitions and ran them, and I don't get the results you posted for -Nsin[3, 2, x] (your result seems to be missing a few $x$ here and there) or for D[Ncos[3, x]] (your result seems to contain a $(-1)^{1/3}$ factor in two terms that I cannot reproduce. Not only that, but if I run D[Ncos[3, x]] - (-Nsin[3, 2, x]) // FullSimplify I do NOT obtain zero, no matter what I try for simplification. Feb 25, 2016 at 23:05
• Did you include the root of unity definition? Mine definitely works, and I verified with with >D[Nsin[3,2,x],x]-Nsin[3,1,x] // FullSimplify Feb 25, 2016 at 23:15
• I could email you my notebook.... Feb 25, 2016 at 23:18
• I edited the formulas (removed the simplify command) and reposted. I am definitely getting the correct results... Feb 25, 2016 at 23:21
• @MarcoB have you retried with the new formulas i edited in the question? Feb 26, 2016 at 2:09