Short and Shallow Output

When you generate a very large output expression in the Wolfram Language, you often do not want to see the whole expression at once. Rather, you would first like to get an idea of the general structure of the expression, and then, perhaps, go in and look at particular parts in more detail.

The functions (RefLink[Short, paclet:ref/Short]) and (RefLink[Shallow, paclet:ref/Shallow]) allow you to see "outlines" of large Wolfram Language expressions.

Showing outlines of expressions.

This generates a long expression. If the whole expression were printed out here, it would go on for 23 lines:

t=Expand[(1+x+y)^12];

This gives a one-line "outline" of t. The <<>> indicates the number of terms omitted:

Short[t]

When the Wolfram Language generates output in a textual format such as (RefLink[OutputForm, paclet:ref/OutputForm]), it first effectively writes the output in one long row. Then it looks at the width of text you have asked for, and it chops the row of output into a sequence of separate "lines". Each of the "lines" may of course contain superscripts and built-up fractions, and so may take up more than one actual line on your output device. When you specify a particular number of lines in (RefLink[Short, paclet:ref/Short]), the Wolfram Language takes this to be the number of "logical lines" that you want, not the number of actual physical lines on your particular output device.

Here is a four-line version of t. More terms are shown in this case:

Short[t,4]

(RefLink[Short, paclet:ref/Short]) works in other formats too, such as (RefLink[StandardForm, paclet:ref/StandardForm]) and (RefLink[TraditionalForm, paclet:ref/TraditionalForm]). When using these formats, linewrapping is determined by the notebook interface when displaying the output rather than by the kernel when creating the output. As a result, setting the number of lines generated by (RefLink[Short, paclet:ref/Short]) can only approximate the actual number of lines displayed onscreen.

You can use (RefLink[Short, paclet:ref/Short]) with other output forms, such as (RefLink[InputForm, paclet:ref/InputForm]):

Short[InputForm[t]]

(RefLink[Short, paclet:ref/Short]) works by removing a sequence of parts from an expression until the output form of the result fits on the number of lines you specify. Sometimes, however, you may find it better to specify not how many final output lines you want, but which parts of the expression to drop. (RefLink[Shallow, paclet:ref/Shallow])[expr,{depth,length}] includes only length arguments to any function, and drops all subexpressions that are below the specified depth.

(RefLink[Shallow, paclet:ref/Shallow]) shows a different outline of t:

Shallow[t]

This includes only 10 arguments to each function, but allows any depth:

Shallow[t,{Infinity,10}]

(RefLink[Shallow, paclet:ref/Shallow]) is particularly useful when you want to drop parts in a uniform way throughout a highly nested expression, such as a large list structure returned by (RefLink[Trace, paclet:ref/Trace]).

Here is the recursive definition of the Fibonacci function:

fib[n_]:=fib[n-1]+fib[n-2];fib[0]=fib[1]=1

This generates a large list structure:

tr=Trace[fib[8]];

You can use (RefLink[Shallow, paclet:ref/Shallow]) to see an outline of the structure:

Shallow[tr]

(RefLink[Short, paclet:ref/Short]) gives you a less uniform outline, which can be more difficult to understand:

Short[tr,4]

When generated outputs in the notebook interface are exceedingly large, the Wolfram Language automatically applies (RefLink[Short, paclet:ref/Short]) to the output. This user interface enhancement prevents the Wolfram Language from spending a lot of time generating and formatting the printed output for an evaluation which probably generated output you did not expect.

Typically, an assignment like this would have a semicolon at the end:

lst = Range[(10^6)]

The buttons in the user interface allow you to control how much of the output you see. The size threshold at which this behavior takes effect is determined by the byte count of the output expression. That byte count can be set in the Preferences dialog of the notebook interface, which is opened by the Set Size Limit button.