For example, a network diagram of pattern matching might have _ at the root and the _List and _?NumberQ, etc. connected to it and then more
complicated patterns connected to those, etc. I think I diagram of that sort could be quite useful.
If I wanted this, I would approach this like the following.
-
get all of the names in the system…use something like words=Names[“System`”];
-
strip out all of the ones that begin with ‘$’
-
use this graph code in the man page here: Graph—Wolfram Documentation
(* Generate a network of “nearby” words in a dictionary *)
Flatten[Map[(Thread[# \[DirectedEdge] DeleteCases[Nearest[words, #, 3], #]]) &, words]];
Flatten[Map[(Thread[# \[DirectedEdge] DeleteCases[Nearest[words, #, 3], #]]) &, words]];
Graph[%, VertexLabels -> "Name", ImageSize -> 450]
To me what would tell more is a different Nearest[] that (somehow) shows near in functionality.
HTH.
Turns out there are a lot of pattern tests:
In[3]:= Names["*Q"]
Out[3]= {"AcyclicGraphQ", "AlgebraicIntegerQ", "AlgebraicUnitQ", \
"AntihermitianMatrixQ", "AntisymmetricMatrixQ", "ArgumentCountQ", \
"ArrayQ", "AssociationQ", "AtomQ", "BinaryImageQ", "BipartiteGraphQ", \
"BooleanQ", "BoundaryMeshRegionQ", "BoundedRegionQ", "BusinessDayQ", \
"ByteArrayQ", "ColorQ", "CompatibleUnitQ", "CompleteGraphQ", \
"CompositeQ", "ConnectedGraphQ", "ConstantRegionQ", \
"ContinuousTimeModelQ", "ControllableModelQ", "CoprimeQ", \
"DateObjectQ", "DaylightQ", "DayMatchQ", "DeviceOpenQ", \
"DiagonalizableMatrixQ", "DigitQ", "DirectedGraphQ", "DirectoryQ", \
"DiscreteTimeModelQ", "DisjointQ", "DispatchQ", \
"DistributionParameterQ", "DuplicateFreeQ", "EdgeCoverQ", "EdgeQ", \
"EllipticNomeQ", "EmptyGraphQ", "EulerianGraphQ", "EvenQ", \
"ExactNumberQ", "FileExistsQ", "FreeQ", "FrontEndSharedQ", \
"GeoWithinQ", "GraphQ", "GroupElementQ", "HamiltonianGraphQ", \
"HermitianMatrixQ", "HypergeometricPFQ", "ImageInstanceQ", "ImageQ", \
"IndefiniteMatrixQ", "IndependentEdgeSetQ", "IndependentVertexSetQ", \
"InexactNumberQ", "IntegerQ", "IntersectingQ", "IntervalMemberQ", \
"InverseEllipticNomeQ", "IrreduciblePolynomialQ", "IsomorphicGraphQ", \
"JavaObjectQ", "KEdgeConnectedGraphQ", "KernelSharedQ", "KeyExistsQ", \
"KeyFreeQ", "KeyMemberQ", "KnownUnitQ", "KVertexConnectedGraphQ", \
"LeapYearQ", "LegendreQ", "LetterQ", "LinkConnectedQ", "LinkReadyQ", \
"ListQ", "LoopFreeGraphQ", "LowerCaseQ", "MachineNumberQ", \
"ManagedLibraryExpressionQ", "MandelbrotSetMemberQ", "MarcumQ", \
"MatchLocalNameQ", "MatchQ", "MatrixQ", "MemberQ", "MeshRegionQ", \
"MixedGraphQ", "MultigraphQ", "NameQ", "NegativeDefiniteMatrixQ", \
"NegativeSemidefiniteMatrixQ", "NormalMatrixQ", "NumberQ", \
"NumericQ", "ObservableModelQ", "OddQ", "OptionQ", "OrderedQ", \
"OrthogonalMatrixQ", "OutputControllableModelQ", "PacletNewerQ", \
"PartitionsQ", "PathGraphQ", "PermutationCyclesQ", \
"PermutationListQ", "PlanarGraphQ", "PolynomialQ", \
"PositiveDefiniteMatrixQ", "PositiveSemidefiniteMatrixQ", \
"PossibleZeroQ", "PrimePowerQ", "PrimeQ", "PrintableASCIIQ", \
"ProcessParameterQ", "QHypergeometricPFQ", "QuadraticIrrationalQ", \
"QuantityQ", "RegionQ", "RegularlySampledQ", "RootOfUnityQ", \
"SameObjectQ", "SameQ", "SatisfiableQ", "SimpleGraphQ", \
"SquareFreeQ", "SquareMatrixQ", "StringContainsQ", "StringEndsQ", \
"StringFreeQ", "StringMatchQ", "StringQ", "StringStartsQ", "SubsetQ", \
"SymmetricMatrixQ", "SyntaxQ", "TautologyQ", "TensorQ", \
"TimeObjectQ", "TreeGraphQ", "TrueQ", "UnateQ", "UndirectedGraphQ", \
"UnitaryMatrixQ", "UnsameQ", "UpperCaseQ", "URLExistsQ", "ValueQ", \
"VectorQ", "VertexCoverQ", "VertexQ", "WeaklyConnectedGraphQ", \
"WeightedGraphQ"}
In[4]:= Length[%]
Out[4]= 157
I haven’t figured out how get their definitions all at once. The following doesn’t work:
(? #)& /@ Names["*Q"]
I am not sure what you want to do with this info…
Information /@ Take[Names["*Q"], 5]
Yes, the definitions don’t provide much more information than the name.
I thought the original goal of the question was to find some meta-data or annotation for each function that would allow a graph of semantically clustered functions to be constructed. Using that meta-data and Nearest[] could facilitate a classification and/or network of those functions..further down that path would be tool-tips with data from Information[] and links into the documentation.
So far I cannot see any such meta-data.
The semantic clustering you seek does not exist, and seeking it will simply mislead you about the nature of Mathematica. “Everything is an expression.” Start there.
I hear what you are saying, the replies stating that Mathematica looks for patterns in EXPRESSIONS doesn’t mean it can’t get from T initai to T final by way of another mesh all points in the complex are connected.
OK Frank and John:
It seems obvious that Mma cannot possibly attach any semantic meaning to the 3 leters “Map”. It only looks up the 3-character symbol in the current Context and begins replacements.
But with all languages, syntax (which Mma is very concerned with) and semantics are in different domains. Certainly as we all work to learn more and more of Mma, the semantic meaning of various functions can be grouped in our minds as “closer” or “farther”.
I got stuck on the idea of a visualization of this.
It is interesting to me that Wolfram wants everything to be “computable” but the help system of Mma itself is not computable. Maybe they can make WolframLanguageData[]. But the web is (computable) and Mma’s help system is out on the web.
So I posit that a first approximation to this visualization is the “See Also” list of the Mma “man pages” on the web.
Inspired by the example I cited above, I have “sketched some code” in an attached notebook that:
Import[] the man page from the web (e.g. Import[“Map: Apply a function to elements in a list—Wolfram Documentation”] )
strips out the “See Also” list of functions
creates Graph[] rules
generates a network for that function
Since “See Also” is human-curated, it probably also has limitations.
To run against all the functions, that code needs more error checking.
I could not figure out how to use FindClusters[], since I am not sure how to graph the functions in 2D.
HTH.
OK Frank and John:
It seems obvious that Mma cannot possibly attach any semantic meaning to the 3 leters “Map”. It only looks up the 3-character symbol in the current Context and begins replacements.
But with all languages, syntax (which Mma is very concerned with) and semantics are in different domains. Certainly as we all work to learn more and more of Mma, the semantic meaning of various functions can be grouped in our minds as “closer” or “farther”.
I got stuck on the idea of a visualization of this.
It is interesting to me that Wolfram wants everything to be “computable” but the help system of Mma itself is not computable. Maybe they can make WolframLanguageData[]. But the web is (computable) and Mma’s help system is out on the web.
So I posit that a first approximation to this visualization is the “See Also” list of the Mma “man pages” on the web.
Inspired by the example I cited above, I have “sketched some code” in an attached notebook that:
Import[] the man page from the web (e.g. Import[“Map: Apply a function to elements in a list—Wolfram Documentation”] )
strips out the “See Also” list of functions
creates Graph[] rules
generates a network for that function
Notes:
Since “See Also” is human-curated, it probably also has limitations.
To run against all the functions, that code needs more error checking.
I could not figure out how to use FindClusters[], since I am not sure how to graph the functions names in 2D.
HTH.
Consider:
Sin[IntegerQ[MatrixForm]]
Now, these symbols have no intended connection. Nevertheless, Mathematica accepts and even partially rewrites the expression:
Sin[False]
And, of course, there are several ways you could coax Mathematica to rewrite that if you choose.
Most expressions that fit the form head[sequence] are legitimate in Mathematica. Even many that throw errors are OK when wrapped in Quiet. So a “network diagram” for the “language” would be uninformative, since it’s very nearly a fully connected graph. I suppose you could make a weighted diagram for somebody’s specific programming style, but I expect that would mostly illuminate bad programming. Using Mathematica’s power involves forging connections.
Interesting. This is definitely along the lines I was thinking.
This should come out using WolframLanguageData[Map, SeeAlsoList]
Actually this is (still) not correct…it needs a custom NearestFunction[]…
It seems obvious that Mma cannot possibly attach any semantic meaning to the 3 leters “Map”. It only looks up the 3-character symbol in the current Context and begins replacements.
Map is a perfect illustration of the difficulty. It’s a pure expression rewriter. It certainly has semantics, but in:
Map[head, tails]
as far as I know, there are no restrictions on head and tails: any expression works. Therefore, Map is connected to the entire language.
Moderation Team note: sorry for the chronological offset of this post.
The functions whose names end in “Q” are not linguistically associated with PatternTest: they are simply functions that yield True or False (predicates). PatternTest may use any such function. It doesn’t even need a name:
abs[x_?(# < 0 &)] := -x
abs[x_?(# >= 0 &)] := x
You may use predicates for classifying expressions, regardless of whether there’s a PatternTest involved:
IntegerQ /@ {1, 1.5, x}
{True, False, False}
I think this question poorly conceived. Mathematica is not a language in the sense you want. The first rule of Mathematica is “Everything is an expression.” Mathematica works by rewriting expressions it recognizes. Sometimes those transformations have side effects. The fundamental expression grammar is trivial, head[sequence]. There are several expression “forms” with more complex grammars, but those grammars are different and not fundamental. You can make meaningless juxtapositions of symbols meaningful by providing a replacement rule or suitably tagged definition. The symbols you think of as human input can also be the output of expression rewriting, and that’s often the most effective way to solve problems.
Given the volume of the documentation, it should be possible to construct a map of the functionality.
In[1]:= Length[Names["*"]]
Out[1]= 5605
5605 is not that many things to deal with for modern machine learning techniques.
My guess is that WRI has the documentation in some custom format that could easily be converted to some “computable” format. Maybe this is not prioritized.
I would expect that all the documentation was developed in Mathematica.
Hello John:
Actually I completely agree with you.
But in my mind, the list of Mma functions I know are categorized with some custom meta-data, so that Map[] is closer to Apply[] than it is to NComputeChebyshevDoubleIntegral[]. For sure, you can do Map[] using this non-existent function.
Using this “See Also” metric over the space of functions is far from optimal. But a (correct) visualization using this metric would (I guess) be illuminative.