Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

An apostrophe ' is often used when we want to distinguish two variables. For example, if we already have a variable t and we may want define another variable t'. What I found weird is that, in *Mathematica` it is legitimate to define a variable with apostrophe but it just can't clear a variable which has an apostrophe in the usual way.

For example, if we write the following

t'=8

and 3t' will correctly give 24

but Clear[t'] will prompt an error says

Clear::ssym: t' is not a symbol or a string

Can anyone help?

share|improve this question
4  
Apostrophe means Derivative in Mathematica. You don't define a new variable, you add a rule for Derivative function. It is not Protected, which is why you can do it. Don't use apostrophe for this purpose, this is a wrong thing to do. –  Leonid Shifrin Dec 3 '12 at 13:59
1  
@NasserM.Abbasi It is really often used in mathmatics that way and I have seen people using this notation in Mathematica very often. I'm sure if someone uses this notation, he just tries it without looking it up in the documentation and since it seems to work, they think it's fine. –  halirutan Dec 3 '12 at 14:50
1  
Duplicate of: mathematica.stackexchange.com/q/373/5 –  rm -rf Dec 3 '12 at 16:21
    
I have a question! why mathematica design Derivative to be not protected?? –  matheorem Dec 4 '12 at 13:05

3 Answers 3

up vote 6 down vote accepted

You already read from @Leonid and @halirutan that it's impossible to use the simple notation a' as a primed variable because it represents a derivative.

Of course you may now wonder if this means that primed variables are completely impossible. The answer is that you can define primed variables. To do so, you just have to introduce a different glyph for the apostrophe in your variable names. Looking at the unicode characters understood by Mathematica, I have the following suggestion.

First define an input alias, i.e., a shortcut for entering the new "prime". This alias definition is only done for the currently active notebook (edit catch the case where there are no existing InputAnliases):

SetOptions[EvaluationNotebook[], 
 InputAliases -> 
  Join[Quiet@OptionValue[Options[EvaluationNotebook[]], 
    InputAliases]/. InputAliases -> {}, {"prime" -> FromCharacterCode[700]}]]

The last line says that you're now allowed to enter the keyboard sequence escprimeesc when typing variable names. For example, type

eescprimeesc = 1

to get an input line that looks like this:

eʼ = 1

1

Now you have a variable where the apostrophe is part of the name, as shown below:

Definition[eʼ]

eʼ = 1

Note that I chose a glyph for the primed symbol that is slightly slanted so that you can distinguish it visually from the derivative prime.

And of course, you can now clear the primed variable (coming back to your question) as usual:

Clear[eʼ]

Definition[eʼ]

Null

share|improve this answer
    
Ah, clever. +1. –  rcollyer Dec 3 '12 at 17:20

As Leonid already pointed out in comments, it only seems that you set a variable t' here, but your assumption is wrong.

Never use ' appended to a variable to define another distinguishable variable!

The ' has the built-in meaning: It expresses the derivative of t. You can see this by using FullForm which gives you the full Mathematica expression used

FullForm[a'[x]]

(* Derivative[1][a][x] *)

Note, that your a only occurs as part of Derivative. Because of this you are able to use y'[x] as derivative of y when e.g. using DSolve. You can now almost guess, how t', which you assumed to be a valid variable name, is stored

FullForm[t']

(* Derivative[1][t] *)

The important detail is that such derivatives are not stored with the variable name. They are stored as SubValues of Derivative. Example:

a'[x] = x;
SubValues[Derivative]

(* {HoldPattern[Derivative[1][a][x]] :> x} *)

to clear now thes SubValues you can use

SubValues[Derivative] = {}

or, which I find more unclear, ClearAll[Derivative].

and now a'[x] will no longer evaluate to x.

share|improve this answer
2  
Maybe it'd be good to include FullForm[t'] in the answer, as illustration. –  Szabolcs Dec 3 '12 at 15:03

Thank you for all your help! Jens's alias definition is quite general. But I just found that we can write a variable with an apostrophe much more easily.

mathematica has bulit-in symbol \[Prime]

or to use keyboard, just

esc ' esc

this will give a symbol very similar to the derivative meaning apostrophe while a little lower in position.

so in conclusion, if we want to define a variable t', we just knock the keyboard in order

t esc ' esc

I think we'd better call it primed variable instead of variable with an apostrophe. You can clear this primed variable normally with "Clear".

share|improve this answer
    
Yes, that's true - as long as you're OK with the fact that your \[Prime] doesn't appear raised above the text baseline. I.e., \[Prime] doesn't actually look like the character you'd usually call an apostrophe (and it doesn't look like the one displayed in this answer). The unicode character that I found has this raised appearance. –  Jens Dec 4 '12 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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