Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new in Mathematica so this is maybe super easy to do, but I can't figure out how.

I've got a function plus[a,b] that sums two numbers and I need to implement a function derivation[a] that will derive the input like this:

derivation[e_Integer] (* returns 0 *)
derivation[x] (* returns 1 *)

I've got a problem with this rule:

derivation[plus[a, b]] := plus[derivation[a], derivation[b]];

When I implement it this way, it doesn't work because plus is evaluated before derivation. I.E. derivation[plus[x, 3]] should return 1. Is there some other way how to implement it?

share|improve this question
Is there a reason you're not using the built-in D or Derivative? You might want to look at giving your derivation a HoldAll attribute. – R. M. Oct 2 '13 at 15:13
Awesome, that's the attribute I was looking for! Thanks a lot. Yes I know about built-in Derivative, but I need to implement it on my own for learning purposes. – Micer Oct 2 '13 at 15:40
up vote 1 down vote accepted

Just to not leave this unanswered, as rm -rf suggested in comment, setting the attribute HoldAll to derivation function solved my problem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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