1
$\begingroup$

The documentation says: "The Wolfram Language by default interprets any sequence of letters or letter‐like forms as the name of a symbol."

But when I test for example the object x (with a hat above) "=OverHat[x]" I get the error message: "The string "Overscript[x, ^]" cannot be used for a symbol name. A symbol name must start with a letter followed by letters and numbers."

Letters with (user-defined) diacritics are also not accepted as symbol names. https://reference.wolfram.com/language/tutorial/MathematicalAndOtherNotation.html#41 <- just above this html-anchor

  1. I have no idea what a letter-like form really is.
  2. Does it make sense to use objects as variables or should I use only symbols?
  3. If I understand correctly, objects with annotated names are in fact unary operators. But I suppose that they are used in a different way.
$\endgroup$
8
  • $\begingroup$ Can you clarify what you did to get that message? Were you trying to use the literal built-in function SymbolName? $\endgroup$
    – lericr
    Jan 27, 2023 at 17:23
  • $\begingroup$ And is your question about symbols per se, or is it about assigning a value to things like OverHat[x]? $\endgroup$
    – lericr
    Jan 27, 2023 at 17:25
  • $\begingroup$ Yes, I use this function to get that message. $\endgroup$
    – zbjoko
    Jan 27, 2023 at 17:27
  • $\begingroup$ Okay, well if you did something like SymbolName["Overscript[x,^]"], then that message makes sense. Any expression of the form SomeSymbol[<...stuff...>] is a headed expression and so not a symbol by definition (by the basic syntax of Mathematica), so SymbolName cannot give you the name, because you didn't give it a symbol. $\endgroup$
    – lericr
    Jan 27, 2023 at 17:30
  • 3
    $\begingroup$ I’m voting to close this question because I believe that it has the potential to be confusing, because it's anchored to what seems to be a mistaken understanding of the evaluation process and the notion of "expression". $\endgroup$
    – lericr
    Jan 28, 2023 at 0:10

2 Answers 2

2
$\begingroup$

I'm not really sure if an answer is appropriate here, and I'm on the verge of voting to close this question. But for now, here are some thought about your three questions/issues:

  1. I have no idea what a letter-like form really is.

The documentation that you linked to has large lists of letter-like forms. I suggest that you just read through that section. Basically, letter-like forms are free from any special parsing rules, and so get treated as symbols (as does any catenation of them).

  1. Does it make sense to use objects as variables or should I use only symbols?

This is where things get tricky. This might be a bit much if you're new to Mathematica, but there aren't really variables in the traditional programming sense. What I'm calling the "traditional sense" here is where variables are really just aliases to memory locations. In Mathematica everything is just an expression. Some expressions have rules for how to "compute" or "transform" or "rewrite" them. If I evaluate x = 7 what I am NOT doing is allocating memory for an integer and using x to reference what's stored there. What I AM doing is saving a rule in the "environment" that says that whenever the evaluator encounters x it should replace it with 7. It's abstract and complicated and not really appropriate here, so I'll leave it at that.

So, your question doesn't really make sense. You should use raw symbols or more complicated expressions as needed. There is no rule about that (other than the basic rules of syntax and evaluation that are built in). So, if it makes your situation semantically clear to say x = 7, then do that. If it would be clearer to say x[1] = 7, then do that. But either way, you're just creating rewrite rules.

  1. If I understand correctly, objects with annotated names are in fact unary operators. But I suppose that they are used in a different way.

I'm really not sure how to interpret this one. I think maybe what you mean by "objects with annotated names" is headed expressions. An expression like Sqrt[7] has Sqrt as its head. Now, Sqrt has built-in rules associated to it, and you can think of it as a unary operator, but that's just a model to carry around in your head. To Mathematica, Sqrt[7] is just an expression.

So, OverHat[x] is just another expression. Out of the box, it has no built-in rewrite rules associated to it. But you can make your own: OverHat[x] = 7. As it turns out, this probably isn't a very good thing to do, as there's nothing preventing x itself from being assigned its own rewrite rules, e.g. x = 17, in which case the rule OverHat[x] = 7 will be masked so that if you evaluate OverHat[x] now, you'll get OverHat[17].

$\endgroup$
4
  • $\begingroup$ Okay, I see that in the little comment under the chart, but I don't really consider that a term of art in the Mathematica world. I think what that term might be trying to convey is that these forms have distinctive formatting in the front end. But that has no impact on the computation. $\endgroup$
    – lericr
    Jan 27, 2023 at 23:45
  • $\begingroup$ The wording "objects with annotated names" comes from the documentation. WolframDocumentation - Please scroll down a little bit and you'll find the corresponding table. $\endgroup$
    – zbjoko
    Jan 27, 2023 at 23:49
  • $\begingroup$ Yes, I said that I saw it. $\endgroup$
    – lericr
    Jan 28, 2023 at 0:05
  • $\begingroup$ I'm just telling you that you are clinging to that too tightly. That's not a term of art. It's just someone's description of those items in that chart. $\endgroup$
    – lericr
    Jan 28, 2023 at 0:05
2
$\begingroup$
$Version

"13.2.0 for Mac OS X x86 (64-bit) (November 18, 2022)"

Clear["Global`*"]

Assigning a value to OverHat[x]

OverHat[x] = 3

(* 3 *)

OverHat[x]^2 + 3 OverHat[x] + 1

(* 19 *)

Clear the value

OverHat[x] =.

Solve[OverHat[x]^2 + 3 OverHat[x] + 1 == 19, OverHat[x]]

enter image description here

EDIT: To use both x and OverHat[x]

x = 4;

OverHat[x] = 5;

x*OverHat[x]

(* 20 *)

With a pattern definition

OverHat[x_] := StringForm[
  "OverHat's argument is ``", x]

OverHat[y]

enter image description here

OverHat[x] is not affected

OverHat[x]

(* 5 *)

?? OverHat

enter image description here

$\endgroup$
4
  • $\begingroup$ Yes, that's correct and it doesn't bother you if you previously assigned a value to the variable x. But on the other hand, you can also use it as a function. Are both types of application really intended? $\endgroup$
    – zbjoko
    Jan 27, 2023 at 17:20
  • $\begingroup$ Define OverHat[x_]:=.... $\endgroup$
    – zbjoko
    Jan 27, 2023 at 17:23
  • $\begingroup$ @zbjoko - since OverHat is not Protected you are absolutely free to do that! Is there any situation where that would cause a problem for your application? $\endgroup$
    – Jason B.
    Jan 27, 2023 at 23:36
  • $\begingroup$ No, it's just understanding. $\endgroup$
    – zbjoko
    Jan 30, 2023 at 11:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.