I want to create a function that derives (Derivada) the function Log[x] for any base.

My code:

Derivada[x_^n_, x_Symbol] /; FreeQ[n, x] := n*x^(n - 1)
Derivada[n_*x_, x_Symbol] /; FreeQ[n, x] := n
Derivada[Log[a_: E, x_], x_Symbol] := 1/(x*Log[a])
Derivada[f_, x_Symbol] /; FreeQ[f, x] := 0
Derivada[(a_?NumericQ) f_, x_Symbol] := a*Derivada[f, x]
Derivada[Exp[x_], x_Symbol] := Exp[x]
Derivada[a_^x_, x_Symbol] := a^x Log[a]
Derivada[u_Plus, x_Symbol] := Derivada[#, x] & /@ u
Derivada[u_*v_, x_Symbol] := u Derivada[v, x] + v Derivada[u, x]
Derivada[u_/v_, x_Symbol] := (Derivada[u, x]*v - u*Derivada[v, x])/v^2

My problem is to derive Log[x]. The functions works for any base Log[2,x], Log[3,x] except when I use just Log[x].

Doesn't work:

In[64]:= Derivada[Log[x], x]

Out[64]= Derivada[Log[x], x]


In[65]:= Derivada[Log[2, x], x]

Out[65]= 1/(x Log[2])
  • $\begingroup$ Is there a reason for not using D? $\endgroup$ Aug 30, 2018 at 22:12
  • $\begingroup$ Yes.. I want to create my own function "D". Is just for exercise. $\endgroup$
    – Mateus
    Aug 30, 2018 at 22:13

1 Answer 1


Just add the rule

Derivada[Log[x_], x_Symbol] := 1/x

Since Log[x] has only one argument, it cannot match with the pattern Derivada[Log[a_: E, x_] - even if the first argument is optional:

MatchQ[Log[a_: E, x_], Log[x]]



Your Answer

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

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