Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

RE: Clear or remove definitions including Subscripts

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23154] RE: [mg23116] Clear or remove definitions including Subscripts
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 20 Apr 2000 03:21:22 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> From: SANCHEZ DE LEON, Guillermo [mailto:gsl at fab.enusa.es]
To: mathgroup at smc.vnet.net
> Dear friends,
>
> If I write:
>
> In[1]:= Subscript[a, 11];
> In[2]:= Subscript[a, 12];
>
> Q1: How I can Clear or Remove the previous definitions?.
> Q2: Is it posible to clear at the same time all definitions with pattern:
> Subscript[a, i] (* i=1,2,..*)
>
> I wish to avoid using Notation Package
>
> I have tested:
>
> In[3]: Clear[Subscript[a, 11]]
> Message: Clear:: "ssym": a_11 is not a symbol or a string
>
> In[4]: Clear["\!\(a\_11\)"]
>
> But they don`t work
>

Here is a Mathematica notebook, which if you open and save, will produce a
package called WollSubscripts. I wrote the package as a slight modification
and extension of a suggestion first put forward by Carl Woll in MathGroup.
It allows you to use subscripted symbols, even if the subscript has been
given a value elsewhere. It also has routines for clearing the subscript
variables and obtaining information on them. The package should be put in
the AddOns/ExtraPackages/Algebra directory.

Copy the text and paste it into an empty notebook.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



(***********************************************************************

                    Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. The data for the notebook
starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do one of
the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the
word CacheID, otherwise Mathematica-compatible applications may try to
use invalid cache data.

For more information on notebooks and Mathematica-compatible
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info at wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      5011,        143]*)
(*NotebookOutlinePosition[      6306,        184]*)
(*  CellTagsIndexPosition[      6262,        180]*)
(*WindowFrame->Normal*)



Notebook[{

Cell[CellGroupData[{
Cell["Algebra`WollSubscripts` Package", "Title"],

Cell[CellGroupData[{

Cell["Implementation", "Section",
  InitializationCell->True],

Cell[BoxData[{
    \(ClearAll[Subscript]\), "\[IndentingNewLine]",
    \(\(Subscript::usage = "\<Subscript has been given the Attribute \
HoldFirst so that it can be used like a symbol and be given \
definitions.\>";\)\), "\[IndentingNewLine]",
    \(SetAttributes[Subscript, {HoldFirst}]\)}], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(BeginPackage["\<Algebra`WollSubscripts`\>"]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(Algebra`WollSubscripts::usage = "\<WollSubscripts sets the attributes
\
of Subscript to HoldFirst so that it can be used like a symbol. Subscript \
definitions can be defined. The additional routines ClearSubscripts and \
SubscriptInformation are also provided.\>"\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(\(ClearSubscripts::usage = "\<ClearSubscripts[sym1, sym2,...] will \
clear all Subscript definitions based on the symbols.\>";\)\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(\(SubscriptInformation::usage = "\<SubscriptInformation[sym1,
sym2,...] \
will print the Subscript definitions based on the symbols.\>";\)\)],
"Input",
  InitializationCell->True],

Cell[BoxData[
    \(Begin["\<`Private`\>"]\)], "Input",
  InitializationCell->True],

Cell[BoxData[{
    \(\(SetAttributes[
        ClearSubscripts, {HoldAll}];\)\), "\[IndentingNewLine]",
    \(ClearSubscripts[a__]\  := \[IndentingNewLine]\
      Module[{b}, \[IndentingNewLine]DownValues[Subscript]\  =
          Cases[DownValues[Subscript], \((b_\  :> \ _)\)\  /; \
              FreeQ[b,
                HoldPattern[
                  Subscript[
                    Alternatives[a], \ __]]]]; \[IndentingNewLine]SubValues[
            Subscript]\  =
          Cases[SubValues[Subscript], \((b_\  :> \ _)\)\  /; \
              FreeQ[b,
                HoldPattern[
                  Subscript[
                    Alternatives[
                      a], \ __]]]];\[IndentingNewLine]]\)}], "Input",
  InitializationCell->True],

Cell[BoxData[{
    StyleBox[\(SetAttributes[SubscriptInformation, \ {HoldAll}];\),
      FormatType->StandardForm], "\n",
    StyleBox[\(SubscriptInformation[syms__]\  := \[IndentingNewLine]\
        Module[{PrintDownValue},
\[IndentingNewLine]PrintDownValue[\(Verbatim[
                    HoldPattern]\)[a_]\  :> \ b_]\  := \
            Print[HoldForm[
                a\  = \
                  b]]; \[IndentingNewLine]PrintDownValue\  /@
\((DeleteCases[
                Join[DownValues[Subscript],
                  SubValues[Subscript]], \ \((b_\  :> \ _)\)\  /; \
                  FreeQ[b,
                    HoldPattern[
                      Subscript[
                        Alternatives[
                          syms], \ __]]]])\);\[IndentingNewLine]]\),
      FormatType->StandardForm]}], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(End[]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(Protect[ClearSubscripts, SubscriptInformation]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(EndPackage[]\)], "Input",
  InitializationCell->True]
}, Open  ]]
}, Open  ]]
},
FrontEndVersion->"4.0 for Microsoft Windows",
ScreenRectangle->{{0, 1280}, {0, 943}},
AutoGeneratedPackage->Automatic,
ScreenStyleEnvironment->"Working",
InitializationCellEvaluation->False,
WindowSize->{591, 571},
WindowMargins->{{Automatic, 94}, {Automatic, 21}},
PrintingCopies->1,
PrintingPageRange->{Automatic, Automatic},
PageHeaders->{{Cell[ 
        TextData[ {
          CounterBox[ "Page"]}], "PageNumber"], Inherited, Cell[ 
        TextData[ {
          ValueBox[ "FileName"]}], "Header"]}, {Cell[ 
        TextData[ {
          ValueBox[ "FileName"]}], "Header"], Cell[ 
        TextData[ {
          ValueBox[ "Day"], " ", 
          ValueBox[ "MonthName"], " ", 
          ValueBox[ "Year"]}], "PageNumber"], Cell[ 
        TextData[ {
          CounterBox[ "Page"]}], "PageNumber"]}}
]


(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of 
the file.  The cache data will then be recreated when you save this file 
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{

Cell[CellGroupData[{
Cell[1739, 51, 48, 0, 170, "Title"],

Cell[CellGroupData[{
Cell[1812, 55, 61, 1, 59, "Section",
  InitializationCell->True],
Cell[1876, 58, 332, 6, 110, "Input",
  InitializationCell->True],
Cell[2211, 66, 104, 2, 30, "Input",
  InitializationCell->True],
Cell[2318, 70, 325, 5, 110, "Input",
  InitializationCell->True],
Cell[2646, 77, 189, 3, 70, "Input",
  InitializationCell->True],
Cell[2838, 82, 199, 3, 70, "Input",
  InitializationCell->True],
Cell[304
0, 87, 83, 2, 22, "Input",
  InitializationCell->True],
Cell[3126, 91, 751, 17, 112, "Input",
  InitializationCell->True],
Cell[3880, 110, 848, 17, 100, "Input",
  InitializationCell->True],
Cell[4731, 129, 66, 2, 22, "Input",
  InitializationCell->True],
Cell[4800, 133, 107, 2, 22, "Input",
  InitializationCell->True],
Cell[4910, 137, 73, 2, 22, "Input",
  InitializationCell->True]
}, Open  ]]
}, Open  ]]
}
]
*)




(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)



  • Prev by Date: Re: PrintPrecision
  • Next by Date: Re: breaking up lists into intervals
  • Previous by thread: Re: Clear or remove definitions including Subscripts
  • Next by thread: Mathematica and 3D surface.