3

There was a question on mathgroup, and while I was looking at it, I noticed this thing, and I can't understand why, I thought some expert here would know.

When doing Dt [ x[1] ]

it gives zero, because during evaluation of x[1], the last value left is 1, as can be seen from the TracePrint below. And hence '1' is what is seen by Dt, and so Dt[1] is 0.

Hence Dt[ x[1] ] is zero

In[86]:= TracePrint[ Dt[x[1] ]]

During evaluation of In[86]:=  Dt[x[1]]
During evaluation of In[86]:=   Dt
During evaluation of In[86]:=   x[1]
During evaluation of In[86]:=    x
During evaluation of In[86]:=    1
During evaluation of In[86]:=  0

Out[86]= 0

That made sense to me, until I typed x[1], and got back x[1]

In[84]:= x[1] Out[84]= x[1]

But x[1] returning x[1] also made sense to me, since x[1] has no value, so it should return unevaluated.

So, my question, is why it seems that x[1] was evaluated all the way down to '1' during the call above, but at the top level notebook interface, it did not evaluate to 1?

In[87]:= Evaluate[ x[1] ]
Out[87]= x[1]

Thanks

Nasser
  • 12,849
  • 6
  • 52
  • 104

1 Answers1

5

The expression

x[1]

does not evaluate to 1 - it is an indexed variable with undefined value. The problem is that when you use the form of Dt with 1 argument, then x is considered a function, and 1 - its argument, and you get 0. This becomes clearer when you consider

In[1]:= Dt[x[y]]

Out[1]= Dt[y] Derivative[1][x][y]

If you now use

In[2]:= Dt[x[1],x[1]]

Out[2]= 1

you get 1, since now you differentiate over x[1] considered as a variable. Or,

In[3]:= Dt[x[1]^2, x[1]]

Out[3]= 2 x[1]

You were confused by evaluation printout since indeed, when evaluating an expression, all parts are normally evaluated - but (in the absense of any rules for x), x[1] evaluates back to itself also inside Dt, to be sure. What you observed is related to how Dt with one argument interprets that argument.

Leonid Shifrin
  • 22,449
  • 4
  • 68
  • 100
  • @Simon Sorry, that wasn't in my plans :). Thanks for the upvote. – Leonid Shifrin Jun 01 '11 at 10:30
  • Thanks Leonid, Yes, I looked at the trace and saw what seemed liked it evaluated to x[1] to 1. But I have a follow up. You say that Dt looked at x[1] as a function x with its argument 1, ok, but why then it returned zero? This function x[1] has no value, so it should return unevaluated. So why would Dt of unevaluated function return zero, while Dt of any other name return the name? i.e. Dt[foo[1]] returns zero, but Dt[foo] returns Dt[foo] ? isn't foo and foo[1] the same thing in terms of both being expressions with no value associated with them? thanks – Nasser Jun 01 '11 at 10:32
  • 1
    @Nasser I added an illustration to the top of my post (even before reading your comment) - `Dt[x[y]]` (which does not return zero for general `y`). Now, for `Dt[x[1]]`, it is computed as `x'[1] Dt[1]`, but `Dt[1]` is zero since `1` is a constant, thus the overall result. Once again: `x[1]` evaluated to itself all right, but then `D[x[1]]` evaluated and resulted in 0. – Leonid Shifrin Jun 01 '11 at 10:37
  • @Nasser When `Dt` sees `x[y]`, it assumes that `x` is a function of only one variable and returns `Dt[y] x'[y]` (See Leonid's In[1]). When it sees a plain symbol, then it assumes that it's a variable, so `Dt[x]` returns unevaluated. This should make what's going on clear. If not, read the docs on `Dt` so you can see what it's been designed to do. – Simon Jun 01 '11 at 10:38
  • 1
    btw, I just want to say how great Stackoverflow forum is, the person who asked this question on the mathgroup will not get the correct answer for 2-3 days, but here, the experts answered in few minutes ! I saw this question on Mathgroup and answered it, but I do not think I did a good job :) – Nasser Jun 01 '11 at 10:39
  • 1
    @Nasser While Mathgroup has its strengths and is an excellent forum, I agree that SO offers more advanced functionality in many ways, and has a much faster turnaround. But I think, what really makes it great is that, with all its tools taken together, it facilitates another level of collaboration, so each answer here is really a collaborative product, while on more traditional forums you have a collection of individual (often duplicate, sometimes conflicting) answers. – Leonid Shifrin Jun 01 '11 at 10:45
  • There should be a way to tell others about this Mathematica forum. I did not know about it, until some student at the Wolfram student forum mentioned it in a post. I think Mathgroup being so slow is hurting Mathematica, not helping it, in particular for students who want immediate help. But this discussion for another place I guess. But I am happy I found this, at least now when I get stuck, at least I know where to go for help – Nasser Jun 01 '11 at 10:58
  • @Nasser I posted a couple of answers in both the mathgroup and the student forum with an advertisement for Stackoverflow in my sig. I'd suggest you all consider doing something like this. – Sjoerd C. de Vries Jun 01 '11 at 11:09
  • 5
    @Nasser I think the current state of the SO Mathematica forum here is quite healthy. It is rapidly evolving, but not too rapidly, so that we have a biological growth rather than a chaotic expansion. A big inflow of students with very basic questions could bring more harm than good at the moment, since it may lower the level of question quality and distract people here. I'd just let it go as it goes, and once the community and the number of answered questions gets larger, more questions can be effectively handled. Those who really need us, will find us, like you did. My two cents. – Leonid Shifrin Jun 01 '11 at 11:09
  • @Leonid You have a point there. The fun part of SO is the questions that make you think, do research, try things. We shouldn't have too many basic questions. We might have to call RTFM more and close those topics, though that in itself is rather unfriendly. – Sjoerd C. de Vries Jun 01 '11 at 11:13
  • 2
    @Sjoerd I think it is great that you did it on Mathgroup, but are you sure our SO community here is ready to handle a rapid growth of a number of basic questions (I mean not Mathgroup posters, more basic)? Most new users here so far have been doing their homework and ask only after they tried something themselves, and part of that I think is due to us not being quite on the surface - people needed some motivation to find us. If a really large crowd of people with very basic questions comes within a very short period of time, that can be a hard burden to our community - or am I totally off? – Leonid Shifrin Jun 01 '11 at 11:15
  • @Sjoerd Sorry, I posted my last comment before having a chance to see yours. Fast turnaround has its flaws :) – Leonid Shifrin Jun 01 '11 at 11:16
  • @Leonid been there, done that. Anyway, perhaps we should advertise SO/Mathematica as intended for difficult/advanced level Mathematica questions? – Sjoerd C. de Vries Jun 01 '11 at 11:21
  • @Sjoerd Sounds good, but we should target professionals / acedmics/ researchers rather than students IMO (with a possible exception for grad.students).The question is - how to do this effectively. One very straightforward answer is that WRI could help with that. But I still have a feeling that we are not yet ready for a large-scale expansion, not even in terms of the number of active competent users, but in terms of the infrastructure (large number of linked questions, FAQ, etc).I'd give it some more time, and meanwhile I'd really love to see here more people from mathgroup. What do you think? – Leonid Shifrin Jun 01 '11 at 11:31
  • @Leonid While working on the SO API I was struck by the relative low number of resident experts here, so I tried to entice a couple of the mathgroup regulars to appear here as well (DrMajorBob being one; he has gone in, but haven't seen much of him since). I sent a suggestion to WRI to mention SO on the resources page, but didn't receive any feedback on that. Perhaps you, being one of the mathgroup heavy weights, could invite some of the mathgroup regulars directly? – Sjoerd C. de Vries Jun 01 '11 at 11:42
  • @Sjoerd Well, you are certainly much "heavier" than me on MathGroup:). But let me think about it. One reason why many people may be reluctant is that the turnaround here is, in a way, too fast - we compete to be the first to answer,and those who are not fast enough to spot a new question end up being late and disappointed, since someone else already answered :). I think that many mathgroup power users would probably prefer a quiter environment for question answering. But also, at some point this becomes counter-productive, we are missing some important mechanism in addition to votes and reps. – Leonid Shifrin Jun 01 '11 at 11:54
  • @leonid What kind of mechanisms are you looking for? I believe it is possible to post feature requests on SO. Don't know where precisely, probably meta, but belisarius will know. Are you looking for a categorization of the level of the question or so? We could do that by means of tags (Mathematica-basic). – Sjoerd C. de Vries Jun 01 '11 at 12:22
  • @Sjoerd Would be nice to have, for example, a bidding mechanism. For any given question, people who see it and want to answer, bid on it. Up to say 3 people can then work on it at the same time, while others see that the bidding is closed. They can still prepare their answers, but the priority in terms of overall consideration is given to those 3, who are given say an hour each. Then, those 3 answerers post their answers. All 3 answers are considered on equal grounds in terms of timing (As a variant, those people may enter a private chat room and collaborate). Continuing... – Leonid Shifrin Jun 01 '11 at 12:49
  • @Sjoerd The answers are then somehow merged, and the votes go to all participants. There can be options: either they agree to merge and share votes, or they don't (which could only make *some* sense if answers are substantially different and contain little or no duplication) but then those who read the posts are asked to treat these answers on equal ground in terms of timing. If any one (or more) of the answers is considered not good by the community, the top answer from those who did not bid can share the acceptance mark as well. This is a very rough idea, it should be formalized. – Leonid Shifrin Jun 01 '11 at 12:55
  • @Sjoerd At least, this seems like a logical way to share the community resources (expert's time). If some of those coming late but having a vast expertise in the area of the question asked, wants to be one of the answerers (bidders), he/she should be able to request that, and ths current bidders are notified - so should one of them wish to voluntarily transfer their bid to that new person, that should be possible to do. The mechanism of gaining reps should be somewhat more complex, and take into account not just the answers' quality, but the level of collaboration as well. – Leonid Shifrin Jun 01 '11 at 12:58
  • @Leonid. Good idea which will increase the levels of collaboration even more. A problem I see is that of time zones, where most of the questions seem to be posted during US working hours (or day time). That would exclude us from many questions. I'm also not sure whether this can be done within the SO framework as it requires a substantial change from current procedures. – Sjoerd C. de Vries Jun 01 '11 at 13:12
  • @Sjoerd @Leonid I am following your conversation. I think you could continue it in a chat room, and while doing that, I suggest browsing the _Meta_ site, where infinite discussions had been posted. In general, big modifications to the current model are not very well received. SO is a business, and it is doing great. – Dr. belisarius Jun 01 '11 at 13:31
  • @Leonid: What you're talking about is close to "Community Wiki" but with a rep gain involved (CW posts gain no rep). I do think that this rep hunting does hurt in some ways, but then again, I feel that I hunt for rep only because I'm curious to know "what lies yonder" i.e., what the 10k tools provide... Beyond that, 15k and 20k are mere milestones with a small additional privilege and nothing after that. So I guess what I'm trying to say is that once the resident experts here get to a comfortable rep level, we'll probably all stop worrying about rep pettily – abcd Jun 01 '11 at 13:37
  • @Leonid: In other words, once people here have sufficient rep, I don't see it unreasonable that the first serious answerer marks their answer CW and every one adds to it. Of course basic questions are always up for grabs :) – abcd Jun 01 '11 at 13:39
  • @yoda Re: `I don't see it unreasonable that the first serious answerer marks their answer CW and every one adds to it.` Usually it doesn't work that way. Once a lot of inexperienced users are in, nobody wants the content to be modified by everyone. Also, Community Wiki is currently discouraged, and there are only a few backdoors to tag a Q or A as that. – Dr. belisarius Jun 01 '11 at 14:31
  • @belisarius: Agree with the "everyone can add to it" part. But `Community Wiki is currently discouraged, and there are only a few backdoors to tag a Q or A as that`. Was this discussed on meta? I thought answerers and question askers _always_ had the option to mark their question/answer as CW if they so chose, for what ever reason... – abcd Jun 01 '11 at 14:34
  • @yoda See http://meta.stackexchange.com/questions/67581/community-wiki-checkbox-missing-in-action – Dr. belisarius Jun 01 '11 at 20:34
  • @belisarius: That pertains only to questions. You can still mark your answer as CW when you compose it. I recently did mark one of my own as CW and wept at the +65 rep loss (atleast my answers aren't anywhere as good as Mr.W or Leonid's to net more than 8 votes, so my heart aches are minimal) – abcd Jun 01 '11 at 20:40
  • @yoda Don't cry. Look at this one http://stackoverflow.com/questions/3265986/an-algorithm-to-space-out-overlapping-rectangles/3279877#3279877 :) – Dr. belisarius Jun 01 '11 at 21:51