3
$\begingroup$

I've been trying to figure it out, to no avail. In reading someone else's code, I come across a function definition, where it says something like this

UserDefinedFunction[a_Integer, b_Integer, c_Integer, d_, k_:Automatic]/;Abs[a]>b:=0;

I understand that it means the function should return 0 if Abs[a] > b, but what does the tag Automatic in k_:Automatic mean? What is it broader usage? How does it relate to when I plot something and tell Mathematica to assign PlotRange -> Automatic?

$\endgroup$
  • $\begingroup$ It is not a tag, it is a default value for pattern k_. e.g. if you call UserDefinedFunction[1,2,3,4], then k will be considered as Automatic. As for what Automatic really means depends on the definition of the function, it could be used like Plot[...,PlotRange->k] which means that by default the resulting plot will have automatic plot range, or you might use it just as a symbol, e.g. k+1, which returns Automatic+1 if nothing is assigned to k. $\endgroup$ – Wjx Feb 20 at 7:42
5
$\begingroup$
FullForm[k_: Automatic]
(* Optional[Pattern[k,Blank[]],Automatic] *)
?Optional

p : v is a pattern object that represents an expression of the form p, which, if omitted, should be replaced by v

So, if you omit the argument, Automatic is what will be used.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Does it mean that if I omit k as the function argument, and only call UserDefinedFunction[a, b, c, d], then the function would be evaluated as if k is not defined at all? $\endgroup$ – Morgan Feb 15 at 16:38
  • $\begingroup$ No, it means that the function would be evaluated as if k is given as Automatic. $\endgroup$ – John Doty Feb 15 at 16:41
  • $\begingroup$ Okay, so is Automatic a type in this case? $\endgroup$ – Morgan Feb 15 at 16:53
  • 3
    $\begingroup$ @Morgan It's just a symbol. It could be anything else. The specific values used here (i.e. Automatic) is irrelevant to your question. Check the Optional doc page to understand what the code does. $\endgroup$ – Szabolcs Feb 15 at 17:38

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