4
$\begingroup$

What is the difference between ? Definition and ?? Information?

If I define two functions for the same symbol

f[x_] := Cos[x]
f[b_, c_] := Sin[b c]

I get the same result for ?f and ??f

enter image description here

I've read the documentation, but it's not giving me a real sense of the difference. Are there different use cases? Can I always use one of these (? or ??) and ignore the other?

ps. Which tags are appropriate for this question?

$\endgroup$
  • $\begingroup$ try this $\endgroup$ – chris Apr 9 '15 at 9:22
  • 1
    $\begingroup$ ?... is the same as Information[..., LongForm -> False] and different from Definition. $\endgroup$ – Szabolcs Apr 9 '15 at 16:42
7
$\begingroup$

Actually, while the input escape ?? is shorthand for Information, ? is not a shorthand for Definition (though ? might use Definition). Basically, if there is a usage message defined, ? returns that, if not, it returns definitions. Information and ?? always return everything accessible. Compare:

In[25]:= f[x_] := Cos[x]
f[b_, c_] := Sin[b c]
f::usage = "blahblah";

Definition@f
 f[x_] := Cos[x]

 f[b_, c_] := Sin[b c]
?f (* prints usage message if exists, Definitions[f] otherwise *)
  blahblah
Information@f (* same as ??f *)
blahblah

f[x_]:=Cos[x]

f[b_,c_]:=Sin[b c]

According to the documentation under Document Constructs:

Mathematica graphics

Of course, any definition is only printed if the symbol is not ReadProtected. Information itself is ReadProtected, hence only attributes and options are listed:

Definition@Information
Attributes[Information] = {HoldAll, Protected, ReadProtected}

Options[Information] = {LongForm -> True}

Compare the above to the extensive output produced by PrintDefinitions, that delves deep into the symbol's definition (large output is omitted):

Needs["GeneralUtilities`"];
PrintDefinitions@Information

Furthermore, you can abuse the ? operator to ask about multiple functions:

?*Chart

Mathematica graphics

| improve this answer | |
$\endgroup$

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.