-1

How do I convert the E^[...] notation back to Exp[...] notation? Is there a simple command for this? It appears that E^[...] notation cannot be used as a name of an built-in function, but Exp is a valid name of a function.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Quasar Supernova
  • 1,678
  • 8
  • 13
  • 1
    You can use [esc]ee[esc] for the exponential E. For the problem at hand see ReplaceAll. – b3m2a1 Sep 19 '17 at 04:25
  • A code using ReplaceAll that does what I want will be appreciated. I am currently making do with the clumsy hack viz. ExpToTrig and referring to Sin and Cos as bonafide function names for further manipulation.. – Quasar Supernova Sep 19 '17 at 04:31
  • I just tried replacing e^{..} with Exp[..] using ReplaceAll or /. which is the same thing. It does not seem to work if "..." is a lengthy symbolic expression. – Quasar Supernova Sep 19 '17 at 04:41
  • 2
    One might expect that E^(3 x) /. E^z_ -> Exp[z] would return Exp[3 x], but it does not, because, Mathematica always expresses Exp[3 x] as E^(3 x) in lines of output. Now, E^(3 x) /. E^z_ -> HoldForm[Exp[z]] will return Exp[z] as output, but this may not be particularly useful, because Exp[z] remains enclosed by HoldForm, even though it is not visible in the output. I suggest you just live with E^(3 x). If you cannot for some reason, explain that reason in your question to obtain a better answer. – bbgodfrey Sep 19 '17 at 04:59
  • 1
    @bbgodfrey Substituting Defer for HoldForm in your replacement may be more useful. Good summary otherwise. (see related (7741)) – Mr.Wizard Sep 19 '17 at 05:44
  • 1
    @bbgodfrey Thanks. I need this because: Some clever user has written a subroutine called ApplyToArgument which applies a command such as Simplify, Expand etc. to the argument of a function. Both these pieces of information are to be supplied eg. ApplyToArgument[expr, Exp, Expand]. There seems to be a bug in this subroutine I suspect has something to do with the question I asked to begin with. This works wonderfully if the function in question is Sin,Cos, Log but does not seem to work for Exp. I can of course use ExpToTrig and then use this routine but this is clumsy. – Quasar Supernova Sep 19 '17 at 06:13
  • @Quasar, if the situation is like that, then this is an XY problem. The better solution would have been to add a rule for handling Power[]. – J. M.'s missing motivation Sep 19 '17 at 07:57
  • @J.M surely it's not impossible to override the default built in replacements? – LLlAMnYP Sep 19 '17 at 09:32
  • Certainly not impossible, @LLlAMnYP; I was just making the point that the OP seems to be solving a more complicated problem than what s/he actually has. – J. M.'s missing motivation Sep 19 '17 at 09:50
  • 1
    Thanks to @Mr.Wizard, the following appears to answer the question: For instance, g = 4 Exp[3 (x + 2)] + 1 returns 1 + 4 E^(3 (2 + x)), but g /. Power[E, z_] -> Defer[Exp[z]] returns it to its input form, 1 + 4 Exp[3 (2 + x)], and this result can be used directly in ApplyToArgument, if I understand this user function correctly. However, some minor change to ApplyToArgument itself may be more effective, and I suggest that this user function be added to the question. – bbgodfrey Sep 19 '17 at 13:32
  • 2
    I got it from this link: https://stackoverflow.com/questions/8064438/how-to-simplify-expand-apply-a-pattern-to-a-functions-argument – Quasar Supernova Sep 20 '17 at 11:35

3 Answers3

1

@quasar The subroutine "ApplyToArgument" that is being discussed here only applies to those mathematica commands that do not change form on simple execution for a variable argument, for example Sin[x] remains as Sin[x], Log[x] remains as Log[x] and so on. But Exp[x] becomes e^x, Simplify[x] becomes x and for such cases it won't work.

Specifically for the case of "Exp" the following subroutine will work instead.

ApplyToArgument[expr_, ToWhat_, WhatFunction_] := 
 Module[{list}, list = Extract[expr, Position[expr, ToWhat[_]]];
  list = Map[Rule[#, ToWhat[WhatFunction[#[[2]]]]] &, list];
  Return[expr /. list]]
Joy
  • 9
  • 2
1

Since this is apparently an XY problem, let me provide a solution for problem X instead of the Y being asked here:

ata[expr_, ToWhat_, WhatFunction_] := 
    expr /. HoldPattern[ToWhat[x__]] :> ToWhat[Apply[Sequence, WhatFunction /@ {x}]]

Now, for example:

ata[Sin[a b + a c] + (u + v)/(f p + f q), Sin, Simplify]
   (u + v)/(f p + f q) + Sin[a (b + c)]

ata[Sin[a b + a c] + (u + v)/(f p + f q), Power, Simplify]
   (u + v)/(f (p + q)) + Sin[a b + a c]    

ata[4 Exp[3 (x + 2)] + 1, Power, Expand]
   1 + 4 E^(6 + 3 x)
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
0

You question is not defined well. What is e^{...}? Do you mean E^2 for instance? Or you actually mean `e^{2}? I'm going with the latter.

First, we need to define e to be the Euler number by setting it equal to E. Since anything in {...} is a list and many Mathematica functions such as Exp are distributive (i.e. F[{a, b, c}] = {F[a], F[b], F[c]}) we can write

e = E;
First[e^{2}]
FullForm[First[e^{2}]]

This gives you Power[E, 2]. This is the same as Exp[2]. If you want the expression Exp[2] verbatim, you have to use Hold or Unevaluated.

Miladiouss
  • 1,883
  • 11
  • 26
  • Sir, I know all this but please tell me the answer to my question. – Quasar Supernova Sep 19 '17 at 04:53
  • Oooh, I see what you are asking. I'll update my answer soon. So you want "e^{2}" to give you Exp[2]? Is the input an string? If so I can help you. Otherwise, we can't change Mathematica syntax. – Miladiouss Sep 19 '17 at 05:16