I use Maple primarily in a Unix text window (TTY or "command-line" Maple), so I am used to seeing common subexpression labeling in the output of my computations. However, in Maple 11, GUI users don't see subexpression labeling by default.  I'll begin by talking about subexpression labeling as it appears in TTY Maple, then I'll talk about it in the GUI.

For starters lets look at an example in which a single subexpression is labeled:

f:=-62*x^3+97*x^2-73*x-4;
sol:=[solve](f,x,Explicit); #Explicit tells solve not to return RootOfs
--output--
            1/3
          %1        4169      97
sol := [- ----- + --------- + ---,
           186          1/3   186
                  186 %1

      1/3                                /    1/3            \
    %1        4169      97           1/2 |  %1        4169   |
    ----- - --------- + --- + 1/2 I 3    |- ----- - ---------|,
     372          1/3   186              |   186          1/3|
            372 %1                       \          186 %1   /

      1/3                                /    1/3            \
    %1        4169      97           1/2 |  %1        4169   |
    ----- - --------- + --- - 1/2 I 3    |- ----- - ---------|]
     372          1/3   186              |   186          1/3|
            372 %1                       \          186 %1   /

                            1/2
%1 := 1270502 + 279 21667693

In the output here, the expression labeled as %1 is pulled out to make the display compact.  This is relatively easy for the Maple kernel to do since in the internal representation of the list sol, every occurrence of %1 is just a pointer to the same expression. 

Recently, I noticed something very cool (and obvious?) about these labels: Maple really means that "%1 :=".  That is, when sol was printed %1 was assigned and can be used like the ditto operators (%, %%, and %%%). 

Here is an examplet that generates two labels:

In fact, the subexpression %1 occurs inside the subexpression %2:

          1/3
        %2        4169 %1    97
sol := [------ - --------- + ---,
        186 %1         1/3   186
                 186 %2

        1/3                                 /  1/3             \
      %2        4169 %1    97           1/2 |%2        4169 %1 |
    - ------ + --------- + --- + 1/2 I 3    |------ + ---------|,
      372 %1         1/3   186              |186 %1         1/3|
               372 %2                       \         186 %2   /

        1/3                                 /  1/3             \
      %2        4169 %1    97           1/2 |%2        4169 %1 |
    - ------ + --------- + --- - 1/2 I 3    |------ + ---------|]
      372 %1         1/3   186              |186 %1         1/3|
               372 %2                       \         186 %2   /

           2
%1 := 961 y  - 3286 y + 2809

                    2                                   1/2                  4
%2 := (-1220952422 y  + 4174869572 y - 3568892012 + 93 3    (60031708521159 y

                        3                     2
     - 410539426015668 y  + 1052839863430514 y  - 1200022160121380 y

                       1/2    2
     + 512919835255259)   ) %1

Other interesting things about labels:

  1. You can control labeling with the interface options labeling (default=true) and labelwidth (default = 20).  If you don't like labels, you can turn then off with interface(labeling=false): or increase the threshold so small expressions no longer get labeled with interface(labelwidth=200): -- Corollary: there is lots of good stuff in ?interface
     
  2. The labels only get assigned if the output is printed.  If the call to solve above ended with a colon (:) instead of a semi-colon (;), %1 would not have been assigned.  This is not always obvious because of (3):
     
  3. Labels do not get unassigned, they can only be overwritten.  In fact, unlike the ditto operators, even "restart" does not unassign them.  
     
  4. Trying to access an undefined label gives a syntax error in the interface - not something that can be trapped in a try-catch.  This, together with (3), means that labels cannot really be used programmatically.
     
  5. You can use labels to manipulate subexpressions.  For instance, in the second example above, the expression labeled %1 can factor.  If you want to just factor that subexpression, labels make it possible:

     
  6. If you want to completely hide complicated subexpression you can also do that with labels and freeze:

    Recover the original expression with
    You might do something like this if you wanted to call expand or normal on the expression without expanding the subexpression %2.

So, how do you use subexpression labeling in the GUI?  If you are using the classic worksheet interface, the answer is that you just have to change your renderer with   (the default is =3: editable math -- I am not sure what functionality this has over 2 in the classic interface).  Labeling should work as it does in TTY Maple after doing this.

If you are using the Standard interface, you can also use (again, I am not sure what the difference is between this and =3, but I would guess there is some functionality being lost by setting it to 2) to turn labeling on, but, unfortunately, the labels do not get assigned.  You can still do some of the cool things mentioned above, but you have to cut and paste your subexpressions (of course, this will only sometimes work). I also noticed that labeling is more "aggressive" in the standard interface (a lot more labels are generated for the two examples above). I am guessing that the standard interface is calling a different internal routine to do the labeling.

 


Please Wait...