Analysis of Mathematica 8 Symbols and Functions

By Nasser M. Abbasi
Updated March 9,2011

Introduction

The following is quantitative analysis of Mathematica 8.0 in terms of what functions and symbols it contains. This includes all the AddOns package which come with Mathematica 8.0 outside of the kernel and have to be loaded to be used. These packages are standard packages that come with Mathematica, but are not inside the kernel itself. These are the packages listed in “Wolfram/Mathematica/8.0/AddOns/Packages”

Finding a list of just the functions (i.e. not just Symbols) was a bit tricky.  This is how this was done
1) Run the notebook called getUsageMessages.nb, located in this folder.
2) Select all the output cells, COPY AS TEXT, then put the result in plain text file called “packagesFunctions.txt” in the same folder as this notebook
3) Open this notebook (called process.nb) and run it. It will read the text file and process it.

Thanks for John R. Fultz for suggesting in the Math group to use SyntaxInformation[] and the Usage message to help determine which Symbols are functions and which are not.

Table showing number of Symbols in System and all other AddOns Packages

Get["Utilities`CleanSlate`"]
SetOptions[CleanSlate,Verbose->False];

(* removed the following as they gave errors: "BarCharts", "Combinatorica", "Compatibility", "ComputationalGeometry","Geodesy","GUIKit", "Histograms", "HypothesisTesting", "LinearRegression", "NonlinearRegression", "PieCharts","Units","VectorAnalysis","VectorFieldPlots", "Benchmarking","Developer","Experimental","MultivariateStatistics", *)
addOnPackages={"ANOVA","Audio", "BlackBodyRadiation", "Calendar",   "ComputerArithmetic",  "EquationTrekker", "ErrorBarPlots",  "FiniteFields", "FourierSeries", "FunctionApproximations",  "GraphUtilities",  "HierarchicalClustering","Music",  "Notation", "NumericalCalculus", "NumericalDifferentialEquationAnalysis", "PhysicalConstants", "PlotLegends", "PolyhedronOperations", "Polytopes", "PrimalityProving", "Quaternions", "RegressionCommon", "ResonanceAbsorptionLines", "Splines", "StandardAtmosphere", "StatisticalPlots",  "VariationalMethods",   "WorldPlot", "XML"};
addOnPackages=Sort[addOnPackages];

numberOfSymbolsInPackage[nameOfPackage_]:=Module[{n},
(*Print["processing package ",nameOfPackage];*)
Get[nameOfPackage<>"`"];
n=Length[Names[nameOfPackage<>"`*"]];
CleanSlate[Evaluate[nameOfPackage<>"`"]];
n
];

data=Table[{i,addOnPackages[[i]],numberOfSymbolsInPackage[addOnPackages[[i]]]},{i,1,Length[addOnPackages]}];

data=Prepend[data,{0,"System",Length[Names["System`*"]]}];

TableForm[data,TableHeadings->{None,{"#","Context","Number of symbols"}}]
Print["Total number of symbols = ",Total[data[[All,3]]]]

Finding the functions in System and all other AddOns packages

isFunction[name_String]:=Module[{m},
m=SyntaxInformation[Symbol[name]];
If[Length[m]>0,True,False]
]

getFunctionsInSystem[]:=Module[{data,result,i,funs},
funs=Names["System`*"];
data=Table[If[isFunction[funs[[i]]],funs[[i]],""],
{i,1,Length[funs]}];
result=Flatten[Select[data,StringLength[#]>0&]];
result=Table[{"System",result[[i]]},{i,1,Length[result]}]
]

getFunctionsInPackage[pkgName_,data_]:=Module[{result,i},
(*Print["getFunctionsInPackage, pkgName=",pkgName];*)
result=StringCases[data,RegularExpression["^\\w*\\["]];
result=Union[result];
result=Flatten[Select[result,Length[#]>0&]];
result=StringReplace[result,x__~~"["->x];
result=Table[{StringTake[pkgName,{2,-1}],result[[i]]},{i,1,Length[result]}]
]

We be in the same folder as the data file, this command below changes directories so that the current directory becomes the same as where this notebook is saved. Which should be also the same folder where this text file is.

SetDirectory[ToFileName[Extract["FileName"/.NotebookInformation[EvaluationNotebook[]],{1},FrontEnd`FileName]]]

FileNames[]

data=ReadList["packagesFunctions.txt",String];

r=StringCases[data,RegularExpression["^<"]];
r=Position[r,"<"][[All,1]];
r=Append[r,Length[data]+1];

result=Table[
Table[{ data[[ r[[j]] ]] , data[[k]]},{k,r[[j]]+1,r[[j+1]]-1}],
{j,1,Length[r]-1}
];

result=Table[getFunctionsInPackage[result[[i,1,1]],result[[i,All,2]]],{i,1,Length[result]}];
result=Flatten[result,1];

resultForSystem=getFunctionsInSystem[];
result=Union[resultForSystem,result];
result=Table[{i,result[[i,1]],result[[i,2]]},{i,1,Length[result]}];
TableForm[result,TableHeadings->{None,{"#","Context", "Function Name"}}]