Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The second line below produces the errors shown:

p = LogLogPlot[Abs[10^2/((I ω)^2 + 100)], {ω, 10^0, 10^5}];
p /. x_ /; And @@ NumericQ /@ x :> x[[0]];
Part::pspec: Part specification True is neither a machine-sized integer nor a list of machine-sized integers. >>
Part::pspec: Part specification True is neither a machine-sized integer nor a list of machine-sized integers. >>

I have run out of ideas for pinpointing the specific reason for the error (let alone fixing the rule to avoid it).

Is there some command or tool or systematic way to debugging such errors?

share|improve this question
InputForm[p] gives the expression and Short[InputForm[p], 10] gives the short form of p. Please look at it and say, what do you need to find/extract/replace. – Vahagn Poghosyan Sep 21 '13 at 0:02
@VahagnPoghosyan: The code in the second line comes from – kjo Sep 21 '13 at 0:06
In any case, if you need to extract the data points, I would suggest you to use p /. Line[x_List] :> (data = x); – Vahagn Poghosyan Sep 21 '13 at 0:13
up vote 6 down vote accepted

The debugger in the notebook interface can give more information about errors of this kind. Granted, that information is sometimes cryptic -- but it is better than no information at all.

Let's try it with the expressions from the question.

We'll start by going to the Evaluation menu to enable the Debugger option:

menu selection

In the Debug palette that appears, click on Show Stack and tick the Break at Messages checkbox:

debug window

Now, evaluate the expressions. The first message will appear, the evaluation will be suspended, and the Stack window will show where the error occurred:

stack frames

The bottom expression in the Stack window is Message, which generated the message that we see. Above that is the offending expression, False[[True]]. This was the result of evaluating the rather strange expression NumericQ[#1][[NumericQ[2]]]. We can see that the head of this expression was generated from NumericQ /@ x where x is #1.

The strange expression is unexpected and is a strong clue about what has gone wrong. Apparently, x is being bound to all kinds of expressions, not just lists. Our pattern is not restrictive enough. We certainly want to restrict it to lists (e.g. x_List), but I suspect that the condition needs to be stronger as well (depending on the goal).

Having concluded our analysis, we can either choose the Abort or Finish option from the Debug palette, as suits our fancy.

It is not entirely clear to me what the purpose of these expressions are. If you are trying to extract the data from the plot then Cases might be more appropriate than /., perhaps something like:

First @ Cases[p, Line[pts_] :> pts, Infinity, 1]

If the intent is to make minor tweaks to the Graphics expression, then the pattern and condition will need to be restrictive enough to match only the desired list or lists of numbers.

share|improve this answer

The error occures, since the replacement operator scans not only lists, but also other expressions. The following expression doesn't give errors:

p = LogLogPlot[Abs[10^2/((I \[Omega])^2 + 100)], {\[Omega], 10^0, 10^5}];
p /. x_List /; And @@ NumericQ /@ x :> x[[0]];
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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