3
$\begingroup$

Example

I came across the following simple example from A Beginner's Guide to Mathematica, by McMahon and Topa, which I believe was written circa version 5.2. (FWIW, I'm using v9.)

(* simple differential equation *)
eqn = (D[y[ x], x] == A);

(* solve the differential equation *)
result = DSolve[eqn, y[x], x];

Note to question readers: For the input below, fill in the ... with result then hit (Ctrl + minus) to get a subscript, then type in [[1,1,2]] and evaluate the function. Sorry if this is a wonkish way to present the question, but I wasn't sure of the best way to handle the front-end representation of the original input. *)

(* extract a functional dependence *)
f[x_] := ... 

Evaluating:

f[x]
(* -> A*x + C[1] *)

Question

Can someone point me to documentation on this behavior or explain it? Looking at expression form (Ctrl + e) makes it clear that the front-end is interpreting the subscripted input to make this happen, but I've never seen it before.

Encountering this makes me wish developers would refactor the behavior so that one could easily apply functions other than Part in this manner.

$\endgroup$
2
  • $\begingroup$ I doubt if you will find this peculiar behavior documented. It strikes me as a bug. When I enter Subscript[result, [[1, 1, 2,]]], which ought to be equivalent, I get a syntax error from the code editor (in 8.0.4). $\endgroup$
    – m_goldberg
    Commented Dec 15, 2012 at 13:55
  • $\begingroup$ @m_goldberg Exactly why I asked the question. I wouldn't call it a bug, but the way it apparently works---purely through input (box) interpretation---struck me as odd. $\endgroup$ Commented Dec 15, 2012 at 16:18

2 Answers 2

7
$\begingroup$

This is documented in Part >> More Information (Part >> Details in V9):

enter image description here

$\endgroup$
3
  • $\begingroup$ thanks @Mike, edited with v8 info. $\endgroup$
    – kglr
    Commented Dec 15, 2012 at 21:41
  • $\begingroup$ @MikeHoneychurch and @kguler Thanks for pointing out that this info was semi-hidden at the bottom of the 'Details' section in documentation for Part (was it 'More Information' in v8?). Was kinda driving me nuts that I hadn't come across this before... I've spent TONS of time in the docs... and BTW, does anyone else with the history feature was enabled for the doc center? (performance issues, etc., notwithstanding) $\endgroup$ Commented Dec 15, 2012 at 21:41
  • $\begingroup$ @telefunkenvf14 I had seen this code style before so figured there must be something about it in the Part docs. There is also an example in the Scope section of the docs. $\endgroup$ Commented Dec 15, 2012 at 21:47
4
$\begingroup$

Not an answer since I could not find where it is documented (but I did not spend much time searching)

But just to show that they are really same thing, which I did not know this myself as I do not really use subscripts as they do not work nicely across function calls.

But this shows that $x_{[[1]]}$ is really the same as $x[[1]]$ , it is just different syntax that is all

enter image description here

Actually, just looking at InputForm shows that the frontend changes it to Part

enter image description here

So, my conclusion from this quick analysis:

When [[ ]] appears in Subscript, it is converted to Part directly by the frontend, otherwise, it is left as Subscript as you can see below

enter image description here

I am sure this is documented somewhere, may be more time googling or in the documenation center might find it?

$\endgroup$
1
  • $\begingroup$ +1 for the screenshots. Your answer probably demonstrates the issue better than my original question. $\endgroup$ Commented Dec 15, 2012 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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