0
$\begingroup$

For a given expression, such as:

exp=p[x]+p'[x]+p''[x]...Derivative[n][p][x]

I want to replace all the derivatives of p[x] to a constant 1. But the following rule:

rule=Derivative[_][p][x]:>1

works for the derivatives when n>=1, except `p[x]. That is:

p'[x]/.rule
(* output: 1 *)

p''[x]/.rule
(* output: 1 *)

p[x]/.rule
(* output: p[x] *)

I wonder what is the correct rule to replace all the Derivative[n][p][x] to 1, including p[x].

Thank you.

$\endgroup$
  • $\begingroup$ It's not elegant, but works: rule={Derivative[_][p][x] :> 1, p[x] :> 1} $\endgroup$ – Oscillon Apr 26 at 15:56
  • $\begingroup$ @Oscillon there are almost 15 rules... so this solution will double the input work. Oh... we do need some solution to reduce our labour. $\endgroup$ – PureLine Apr 26 at 15:59
  • 1
    $\begingroup$ Try rule = p[x] | Derivative[_][p][x] :> 1. $\endgroup$ – Somos Apr 26 at 16:55
  • 1
    $\begingroup$ If you need it to be more general (i.e. you need to set every derivative to 1), then you can use a variation of @Somos's suggestion: rule = _[x] | Derivative[_][_][x] :> 1 or something there-abouts. $\endgroup$ – march Apr 26 at 17:01
  • $\begingroup$ Duplicate of mathematica.stackexchange.com/q/194099 ? $\endgroup$ – Roman Apr 26 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.