Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.3K Views
|
18 Replies
|
8 Total Likes
View groups...
Share
Share this post:

How to clear a variable with subscript?

Posted 1 year ago

Hello,

The subscript symbol can be assigned but can't be cleared.

Subscript[a, 0] = 2
Clear[Subscript[a, 0]]

cause error.

enter image description here

POSTED BY: Zhenyu Zeng
18 Replies

Isn’t this where Remove is supposed to be used? That seems to get rid of a subscripted variable that’s been made into a symbol via the palette from the Notations package.

https://stackoverflow.com/questions/8512120/difference-between-clear-and-remove-in-mathematica#:~:text=Remove%5Bsymbol1%2C%20...,string%20input%20that%20ClearAll%20supports.

Posted 1 year ago

Thanks for your advice. The Remove doesn't work for Subscript.

Subscript[a, 0] = 7; Remove[Subscript[a, 0]]
(*Remove::ssym: Subscript[a, 0] is not a symbol or a valid string pattern.*)
POSTED BY: Updating Name
Posted 1 year ago

That's now how you'd use Remove. Remove can't remove an expression. It can only remove a symbol.

POSTED BY: Eric Rimbey
Posted 1 year ago

Thanks.

POSTED BY: Zhenyu Zeng
Posted 1 year ago

What is the difference between a normal expression and a symbol?

Regards.

POSTED BY: Zhenyu Zeng

In the WL everything is an expression. An expression is either an Atom or a normal expression. A normal expression is of the form

h[e1, e2, ...]

where h is the Head. h, e1, e2, ... are expressions - atoms or normal expressions. I don't think there are any exceptions to this structure.

POSTED BY: Rohit Namjoshi
Posted 1 year ago

Thanks. So a symbol is a atom?

POSTED BY: Zhenyu Zeng
POSTED BY: Michael Rogers
Posted 1 year ago

Thanks. Learned a lot.

POSTED BY: Updating Name
Posted 1 year ago
POSTED BY: Eric Rimbey
Posted 1 year ago

Okay. So, Subscript[a,0] definite Subscript.

Subscript[a, 0] = 2
Information[Subscript]
Superscript*5

Why isn't the last result of the codes 10 but 5 Superscript? enter image description here

POSTED BY: Zhenyu Zeng
Posted 1 year ago
POSTED BY: Eric Rimbey
Posted 1 year ago

Thanks. I am still a little confused. When there is a value in DownValues, multiplication should work normally.

POSTED BY: Zhenyu Zeng
Posted 1 year ago

Multiplication is working normally (as in, the way Mathematica intends for it to work).

Try

5  List
(* 5 List *)

List is a built in function, and it definitely has defined behavior when applied to arguments (aka DownValues), but when encountered in isolation, it's just a symbol. In the expression Subscript*5, Subscript appears as an isolated symbol--it's not the head of any expression. So, Mathematica looks at OwnValues, finds nothing, and leaves Subscript alone.

Try 5 Table or 5 Integrate or any other symbol that has no OwnValues. The multiplication cannot be resolved further so you just end up with 5 symbol.

When Mathematica encounters an isolated symbol, it consults OwnValues not DownValues to figure out what to do. Mathematica looks for DownValues when the symbol is the head of an expression.

POSTED BY: Eric Rimbey
Posted 1 year ago

Thanks. Benefit a lot

POSTED BY: Zhenyu Zeng

You can use

Subscript[a, 0] =.(*where the decimal point follows the equal sign.*)
Posted 1 year ago

Thanks. That is a good way. But why can variable be assigned but can't be cleared by Clear?

POSTED BY: Zhenyu Zeng

An error occurs because the argument is a normal expression rather than a symbol: As shown in the error message, ef/message/ClearAll/ssym :enter image description here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard