Skip to content

Operator Name "Gotchas" (Function Application Operators, Others) #75

@rljacobson

Description

@rljacobson

This issue is to discuss and track the following work I propose to do. For the sake of limiting scope, this issue is restricted to working on "incorrectly" named operators (explained below).

  • Identify and list operators in Mathics with problematic names (as described below).
  • Evaluate the impact of renaming operators on the codebase and dependencies.
  • Implement name changes and update all references.
  • Test to ensure functionality is preserved.
  • Document any operators left unchanged and reasons for exclusion.

The purpose of this work is to make Mathics' operator database more complete, correct, and compatible.

Background

In a small handful of cases, Mathematica gives the wrong name to an operator. The primary reason, as far as I can tell, is that Mathematica gives preference to the typographical representation of operators rather than to their computational/semantic meaning. Thus, the naming convention used in Mathematica maps the name of the operator to the function that formats an expression typographically like the operator rather than the underlying function implementing the operator's computational function. There are 13 cases.

Suggested Name Mathematica's Name Parse FullForm Usage String Comments
OverscriptBox Overscript {"OverscriptBox", "[", "expr1", ",", "expr2", "]"}   expr1&expr2  
UnderscriptBox Underscript {"UnderscriptBox", "[", "expr1", ",", "expr2", "]"}   expr1+expr2  
OverunderscriptBox Underoverscript {"UnderoverscriptBox", "[", "expr1", ",", "expr3", ",", "expr2", "]"}   expr1&expr2\%expr3  
UnderoverscriptBox Underoverscript {"UnderoverscriptBox", "[", "expr1", ",", "expr2", ",", "expr3", "]"}   expr1+expr2\%expr3  
InterpretBoxes None     *expr  
SubscriptBox Subscript {"SubscriptBox", "[", "expr1", ",", "expr2", "]"}   expr1_expr2  
SubsuperscriptBox Subsuperscript {"SubsuperscriptBox", "[", "expr1", ",", "expr2", ",", "expr3", "]"}   expr1_expr2\%expr3  
FunctionApplyPrefix Prefix {"expr1", "[", "expr2", "]"} expr1[expr2] expr1@expr2 Operator Notations includes usages with invisible unicode characters.
FunctionApplyInfix Infix {"expr2", "[", "expr1", ",", "expr3", "]"} expr2[expr1, expr3] expr1~expr2~expr3 Infix[f[x,y]] will display as x~f~y. Precedence identifies Infix with this operator, and Precedence[Infix]==30 which is almost correct.
SupersubscriptBox SubsuperscriptBox {"SubsuperscriptBox", "[", "expr1", ",", "expr3", ",", "expr2", "]"}   expr1\^expr2\%expr3  
SqrtBox Sqrt {"SqrtBox", "[", "expr", "]"}   \@expr  
Integrate Integral {"Integrate", "[", "expr1", ",", "expr2", "]"} Integrate[expr1, expr2] ∫expr1expr2  
FunctionApplyPostfix Postfix {"expr2", "[", "expr1", "]"} expr2[expr1] expr1//expr2 Postfix[f[x]] will display as x//f. Precedence identifies Postfix with this operator.

For some of these, it is obvious that they are misnamed based on how they are parsed. OverscriptBox, for example, is called Overscript by Mathematica but is parsed as OverscriptBox. The case of what I call FunctionApplyInfix, for example, is fundamentally the same, but is easy to misunderstand because the underlying semantic meaning is function application which has no corresponding named function. The Mathematica function Infix, despite being the name Mathematica gives this operator, is not the corresponding functional meaning of this operator! The Infix function is concerned with how a function is displayed.

An interesting case is FunctionApplyPrefix, which Mathematica calls Prefix. Again, the Mathematica function Prefix is a directive for displaying a function. The @ operator is actually an alias (sort of) for the square brackets operator [ ], which does not have a name in Mathematica—at least it didn't have a name until the Construct function was introduced!

Challenges

I am assuming in this discussion that operators should be given the name of their underlying (functional) semantic meaning, that is, they should have the same name as the function they are parsed into. There are a few realities that challenge this assumption:

  • Some operators don't have a single function they correspond to.
  • We wish distinct operators to have distinct names, but there are cases where multiple operators correspond to the same underlying function.
  • Some distinct operators share a common lexical representation AND underlying function but have different properties, like arity and precedence. (These operators are necessarily context sensitive.) An example is UnaryPlus vs. Plus, both of which Mathematica just calls Plus.

I haven't made a thorough survey of what Mathics is doing with the 13 operators I identify in the table above, but I think just choosing reasonable alternative names will not present any problems. Mathics already does this for postfix &, for example. But again, part of the work is to figure out what might break.

@rocky should check that this all makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions