Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
2  
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. –  rm -rf 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
add comment

1 Answer

up vote 0 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
add comment

Your Answer

 
discard

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.