0
$\begingroup$

Let us consider the derivative

D[Floor[x]*Sin[Pi*x]^2, x] // Simplify

Piecewise[{{Pi*Floor[x]*Sin[2*Pi*x], x > Floor[x]}}, Indeterminate]

The result is not correct as the plot

Plot[Floor[x]*Sin[Pi*x]^2, {x, -3, 3}]

enter image description here

and

Limit[(Floor[2 + h]*Sin[Pi*(2 + h)]^2 - Floor[2]*Sin[Pi*2]^2)/h, h -> 0]

0

show. It should be noticed that Wolfram|Alpha produces the same expression (see that screen ). The command Limit[D[Floor[x]*Sin[Pi*x]^2, x], x -> 2] which results in 0 is not any workaround because the continuity of the derivative is not established. This is exercise 978 г) from the wellknown problem book on analysis by B. Demidovich and the answer there $\pi \lfloor x\rfloor \sin (2 \pi x)$ is correct. The same issue with the derivatives of RealAbs[Sin[Pi*x]^2] and RealAbs[Sin[Pi*x]^3].

Are there workarounds for all the integer values of x?

$\endgroup$
15
  • $\begingroup$ I'd like to notice that ResourceFunction["IsContinuousFunction"][D[Floor[x]*Sin[Pi*x]^2, x], x] produces an incorrect answer False as well as ResourceFunction["FunctionDiscontinuities"][ D[Floor[x]*Sin[Pi*x]^2, x], x] which results in {{C[1] \[Element] Integers && x == 2 C[1]}, {C[1] \[Element] Integers && x == 1 + 2 C[1]}}. $\endgroup$
    – user64494
    Commented Mar 11, 2021 at 12:42
  • $\begingroup$ Limit[D[Floor[x]*Sin[Pi*x]^2, x], x -> 2] How should the correct answer be? $\endgroup$ Commented Mar 11, 2021 at 15:03
  • 3
    $\begingroup$ What specifically is the issue being raised? That D gives Indeterminate at integer values? It does the same for e.g. D[Floor[x]*Sin[Pi/3*x]^2, x]. This is probably a good thing since for some purposes one wants to regard the derivative of a step function as zero and for others as a Dirac comb. $\endgroup$ Commented Mar 11, 2021 at 15:19
  • 1
    $\begingroup$ It's not a wrong answer. It is in effect "I don't know that this happens to be zero on this measure zero subset". This is how the program works, and in this case there is good reason: the set of multipliers in that Sin for which Indeterminate is incomplete is also measure zero (which was sort of the point of my example) . One should get used to such things, if one wishes to use it productively. $\endgroup$ Commented Mar 11, 2021 at 18:52
  • 1
    $\begingroup$ @DanielLichtblau: In your first comment to my question you probably confuse the derivarive of the usual function D[UnitStep[x], x] which results in Piecewise[{{Indeterminate, x == 0}}, 0] with the derivative of the generalized function D[HeavisideTheta[x], x] which results in the generalized function DiracDelta[x]. Concerning your second comment, a bug is a bug. Unfortunately, the limitations of the D command are not documented. $\endgroup$
    – user64494
    Commented Mar 12, 2021 at 7:46

2 Answers 2

2
$\begingroup$

Try Derivative

Derivative[1][Function[x, Floor[x] Sin[Pi*x]^2]][x]

enter image description here

Plot[{Floor[x] Sin[Pi*x]^2 , 
Derivative[1][Function[x, Floor[x] Sin[Pi*x]^2]][x]}, {x, -5, 5}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Unfortunately, Derivative[1][Function[x, Floor[x] Sin[Pi*x]^2]][x] produces 2*Pi*Cos[Pi*x]*Floor[x]*Sin[Pi*x] + Piecewise[{{0, x > Floor[x]}}, Indeterminate]*Sin[Pi*x]^2 .This is essentially the same as D does. The Plot command does not show removable singularities. Don't hesitate to ask for further explanation in need. Deep regard. $\endgroup$
    – user64494
    Commented Mar 11, 2021 at 10:50
  • $\begingroup$ The output of Derivative[1][Function[x, Floor[x] Sin[Pi*x]^2]][x] was added to the answer after my comment, not having indicated the change in the edit. $\endgroup$
    – user64494
    Commented Mar 11, 2021 at 11:04
  • $\begingroup$ Derivative[...]and D[...] both give the same result in accordance with "B. Demidovich". Perhaps it's time to change the title of your question... $\endgroup$ Commented Mar 11, 2021 at 11:53
  • $\begingroup$ UlrichNeumann(@ does not work.): Your words do not correspond to reality in view of FunctionDomain[ Piecewise[{{Pi*Floor[x]*Sin[2*Pi*x], x > Floor[x]}}, Indeterminate], x, Reals], resulting in x - Floor[x] > 0, and FunctionDomain[Pi*Floor[x]*Sin[2*Pi*x], x, Reals], resulting in True. $\endgroup$
    – user64494
    Commented Mar 11, 2021 at 12:04
1
$\begingroup$

I found a workaround on my own:

der[x_?NumericQ] := Piecewise[{{D[Floor[x]*Sin[Pi*x]^2, x], 
x \[NotElement] 
 Integers}, {Limit[(Floor[x + h]*Sin[Pi*(x + h)]^2 - 
    Floor[x]*Sin[Pi*x]^2)/h, h -> 0, 
 Assumptions -> x \[Element] Integers], x \[Element] Integers}}]
der[2]

0

Edit. The definition of der should be adjusted as follows.

der[x_?NumericQ] := Piecewise[{{Evaluate[D[Floor[t]*Sin[Pi*t]^2, t] /. t -> x], 
x \[NotElement] 
 Integers}, {Limit[(Floor[x + h]*Sin[Pi*(x + h)]^2 - 
    Floor[x]*Sin[Pi*x]^2)/h, h -> 0, 
 Assumptions -> x \[Element] Integers], x \[Element] Integers}}]

Now

der[2.1]

3.69316

which is confirmed by

Pi*Floor[2.1]*Sin[2*Pi*2.1]

3.69316

$\endgroup$
3
  • $\begingroup$ FunctionDomain[] evaluates to x \[Element] Integers || (x \[NotElement] Integers && x - Floor[x] > 0) $\endgroup$ Commented Mar 11, 2021 at 21:27
  • $\begingroup$ UlrichNeumann (@ does not work): FunctionDomain[der[x], x, Reals] produces "FunctionDomain::nmet: Unable to find the domain with the available methods." and returns the input. This domain over the reals found by hand is x \[NotElement] Integers || x\[Element] Integers. It's clear this is True. $\endgroup$
    – user64494
    Commented Mar 12, 2021 at 6:37
  • $\begingroup$ There is some deficiency in the definition of der[x] because der[6.1] produces \!\( \*SubscriptBox[\(\[PartialD]\), \(6.1\)]0.5729490168751488\) not simply 0.5729490168751488. $\endgroup$
    – user64494
    Commented Mar 12, 2021 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.