I am looking to define a new operator that would work similarly to the + or - operator. My end goal is to make a dice operator for calculating random distributions in the normal d20 fashion (e.g. 5d6 meaning 5 six sided die). I have been trying to find how to overwrite an operator or create a new one in the documentation, but I am not really finding much. I know how to do it in C++, but that hardly translates.

As an extension I would like to include the ability to calculate with some dice a friend of mine has that are bimodal or trimodal.

  • $\begingroup$ Any particular reason to go through such machinations as opposed to using Mathematica's probability functions? $\endgroup$ – ciao Mar 12 '14 at 0:33
  • $\begingroup$ @rasher practice creating my own operators. It is very much so a learning exercise for when I go to do more complicated projects. Also, I am using Mathematica to work out some math for a new d20 system that I am building with a friend and being able to use the same dice rolling system as is in the tabletop game would be very beneficial for making sure balance is maintained and such. $\endgroup$ – Adam Mar 12 '14 at 4:59
  • $\begingroup$ In that case, read the documentation re: upvalues, Notation Package, and Operators without built-in meanings to get an idea how to do such a thing "safely". You can also modify the behavior of the actual Mathematica operators, generally not a good idea. Search this site for keywords Operator, Overload, Infix and you'll get some hits with good information. Otherwise, a much too broad question without specific, well-defined examples of what you're trying to accomplish if it's beyond playing with capabilities of Mathematica. $\endgroup$ – ciao Mar 12 '14 at 5:59
  • $\begingroup$ Specific examples are easy enough, and I can tell that you have never played a d20 game or they would be readily apparent. specifically I want to make a binary operator that will work like this (d for now): 2d6 meaning that 2 dice with 6 sides are rolled, or 3d8 meaning 3 8 sided dice are rolled. by extension, 2d6+7 would roll 2 six sided die, then add 7 to the final value, and then 4*(2d6+7)+4d6+2d8 would complete the 2d6+7 opperation 4 times, then add the value of a 4d6 and 2d8 operation. This is a nearly exact example from my current character. $\endgroup$ – Adam Mar 12 '14 at 17:09
  • $\begingroup$ @Adam You cannot create a new binary operator in Mathematica, but there are existing operators with no built-in meaning. You can attach a definition to these. Check here: reference.wolfram.com/language/tutorial/… Does this answer your question? $\endgroup$ – Szabolcs Mar 15 '14 at 15:33

Browse other questions tagged or ask your own question.