MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: graphing traces of complicated evaluations (improved)

  • To: mathgroup at
  • Subject: [mg80625] Re: graphing traces of complicated evaluations (improved)
  • From: Chris Chiasson <chris.chiasson at>
  • Date: Sun, 26 Aug 2007 23:24:01 -0400 (EDT)
  • References: <f7si68$28u$><f8n22c$kj0$>

On Jul 31, 5:14 am, Chris  Chiasson <chris.chias... at> wrote:
> On Jul 21, 4:04 am, chuck009 <dmili... at> wrote:
> > Suppose I'm tenacious.  Really I'm just not satisfied with Integrate returning Pi^2/6 for this integral.  I know it's a bug but aren't they just curious why it's giving this answer?
> > In[15]:=
> > Integrate[Log[1 + Exp[-z]/Sqrt[z]], {z, 0, Infinity}]
> > Out[15]=
> > Pi^2/6
> > I tried using your code to trace it but to no avail.  Any suggestions?
> > > Previously, I released code that could help with the
> > > tracing of
> > > evaluations,
> Hey, google groups wasn't showing this thread a few days ago (or I am
> mentally blind, which I would not put past myself). Otherwise, I would
> have responded sooner.
> If you really want to get to the bottom of this, there are several
> tools at your disposal.
> 1. Contexts[]
> Evaluate this command when you start mathematica. Then evaluate it
> after your integral. The contexts that have been added (use
> Complement) are ones that were loaded especially for your evaluation.
> I got:
> {Integrate`EllipticTrig`,Integrate`QuickLookUpDump`,Integrate`TableDump`,Integrate`TableDumpExp`,Integrate`TableDumpSpec`,Integrate`TableDumpTrig`,Internal`HypergeometricPFQ`,Internal`Integrate`,System`EllipticDump`,System`FibonacciDump`,System`GroebnerBasisDump`,System`HypergeometricDump`,System`InverseFunctionDump`,System`MeijerGDump`,System`NielsenDump`,System`TrigExpIntegralDump`}
> 2. Trace and TraceDialog
> The contexts used above can be use to select the symbols you might
> like to monitor. This is important, because the trace output for the
> full evaluation is likely to be more than a typical computer could
> handle (and certainly more than could be graphed easily).
> 3. Stack (with no argument or with a pattern) and StackComplete (wrap
> the Trace or TraceDialog with this)
> Stack with no arguments gives the tags (symbols associated with
> DownValues, UpValues, and OwnValues) that are currently executing.
> This is useful in the right hand side of a transformation rule in the
> second argument of Trace or as a command issued inside a Dialog
> initiated by Trace dialog. If you feed in a pattern instead, it will
> match against the expressions that are evaluating and return only
> those. StackComplete has the effect of making Stack work on the
> sequence of expressions used to arrive at the current expression, not
> just the sequence of expressions that are currently evaluating (if
> this doesn't make sense, look at the corresponding help browser
> entry).
> Let's use #s 1 and 2 to get an idea of what is happening in the newly
> loaded contexts:
> integralTrace=Trace[Integrate[Log[1+Exp[-z]/Sqrt[z]],z],xpr_/;!
> FreeQ[Unevaluated@xpr,symb_Symbol/;AtomQ@Unevaluated@symb&&MemberQ[{"Integrate`EllipticTrig`","Integrate`QuickLookUpDump`","Integrate`TableDump`","Integrate`TableDumpExp`","Integrate`TableDumpSpec`","Integrate`TableDumpTrig`","Internal`HypergeometricPFQ`","Internal`Integrate`","System`EllipticDump`","System`FibonacciDump`","System`GroebnerBasisDump`","System`HypergeometricDump`","System`InverseFunctionDump`","System`MeijerGDump`","System`NielsenDump`","System`TrigExpIntegralDump`"},Context@Unevaluated@symb]],TraceInternal-
> >True];
> With[{gr=traceToTree[DeleteCases[integralTrace,
> {HoldForm[_Message],___},Infinity]]},TreePlot[gr,Left,gr[[1,1]],VertexRenderingFunction-
> >Function@Tooltip[{Blue,Point@#},#2[[-1]]]]]
> Mousing over the nodes in the graph should give you an idea of which
> functions you may want to trace and explore further.
> Of course, I don't know what is wrong with the answer Integrate is
> giving, so I don't know what to look for, but perhaps you do?
> Here is a version of the tracing code that changes HoldFormComplete so
> that it is stored in a TagBox and that changes the toVertex function
> to show more lines of Short output (5 instead of whatever the default
> is):
> (Attributes@#={HoldAllComplete})&/
> @{traceToTreeAux,toVertex,HoldFormComplete}
> MakeBoxes[HoldFormComplete[arg_],form_]:=TagBox[MakeBoxes[arg,form],HoldFormComplete]
> MakeBoxes[HoldFormComplete[args___],form_]:=TagBox[MakeBoxes[Sequence@args,form],HoldFormComplete]
> edge[{head1_,pos1_,xpr1_},
> {head2_,pos2_,xpr2_}]:=Quiet[Rule[{head1,vertexNumberFunction@pos1,xpr1},
> {head2,vertexNumberFunction@pos2,xpr2}],{Rule::"rhs"}]
> toVertex[traceToTreeAux[HoldForm[heldXpr_],pos_]]:=toVertex[heldXpr]
> toVertex[traceToTreeAux[HoldForm[heldXprs___],pos_]]:=toVertex@traceToTreeAux[Sequence[],pos]
> (*this code is strong enough to not need the ToString commands,but
> some of the resulting graph vertices give trouble to thegraphing
> routines*)
> toVertex[traceToTreeAux[xpr_,pos_]]:={ToString[Short[Extract[Unevaluated@xpr,
> 0,HoldFormComplete],
> 5],StandardForm],pos,ToString[Short[First@originalTraceExtract@{pos},
> 5],StandardForm]}
> traceToTreeAux[xpr_/;AtomQ@Unevaluated@xpr,___]:=Sequence[]
> traceToTreeAux[_HoldForm,___]:=Sequence[]
> traceToTreeAux[xpr_,pos_]:=With[{lhs=toVertex@traceToTreeAux[xpr,pos],args=HoldComplete@@Unevaluated@xpr},Identity[Sequence]
> [ReleaseHold[Function[Null,edge[lhs,toVertex@#],HoldAllComplete]/
> @args],ReleaseHold@args]]
> traceToTree[xpr_]:=Block[{vertexNumber=-1,vertexNumberFunction,originalTraceExtract},vertexNumberFunction[arg_]:=vertexNumberFunction[arg]=
> +
> +vertexNumber;originalTraceExtract[pos_]:=Extract[Unevaluated@xpr,pos,HoldFormComplete];
> {MapIndexed[traceToTreeAux,Unevaluated@xpr,{0,Infinity}]}]
> TraceTreeFormPlot[trace_,opts___]:=Block[{$traceExpressionToTree=True},Through@{Unprotect,Update}@SparseArray`ExpressionToTree;SparseArray`ExpressionToTree[trace,Infinity]=traceToTree@trace;With[{result=ToExpression@ToBoxes@TreeForm[trace,opts]},Through@{Unprotect,Update}@SparseArray`ExpressionToTree;SparseArray`ExpressionToTree[trace,Infinity]=.;Through@{Update,Protect,Update}@SparseArray`ExpressionToTree;result]]

I just noticed that the combination of transmission over the newsgroup
and pasting back into mathematica screws up this code:

I dunno what to say...

  • Prev by Date: Re: Fw: BarChart inside a Frame. How to remove Labels from the top of the frame? How to put x-axis label below and not on the side?
  • Next by Date: Questions on AstronomicalData
  • Previous by thread: Re: BarChart inside a Frame. How to remove Labels from
  • Next by thread: Questions on AstronomicalData