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.
- 124,525
- 11
- 401
- 574
- 1,678
- 8
- 13
3 Answers
@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]]
- 9
- 2
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)
- 124,525
- 11
- 401
- 574
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.
- 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
E^(3 x) /. E^z_ -> Exp[z]would returnExp[3 x], but it does not, because, Mathematica always expressesExp[3 x]asE^(3 x)in lines of output. Now,E^(3 x) /. E^z_ -> HoldForm[Exp[z]]will returnExp[z]as output, but this may not be particularly useful, becauseExp[z]remains enclosed byHoldForm, even though it is not visible in the output. I suggest you just live withE^(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:59DeferforHoldFormin your replacement may be more useful. Good summary otherwise. (see related (7741)) – Mr.Wizard Sep 19 '17 at 05:44Power[]. – J. M.'s missing motivation Sep 19 '17 at 07:57g = 4 Exp[3 (x + 2)] + 1returns1 + 4 E^(3 (2 + x)), butg /. 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 inApplyToArgument, if I understand this user function correctly. However, some minor change toApplyToArgumentitself may be more effective, and I suggest that this user function be added to the question. – bbgodfrey Sep 19 '17 at 13:32