Message Boards Message Boards

1
|
4463 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Simplify[] on string expressions

Posted 12 years ago
I'm trying to find a good way to simplify an arithmetic expression that
used strings (instead of symbols), along the lines of:
In[1]:= exp = ("a"^3)^(1/3)*"b"^2;
It seems that Simplify[] doesn't operate on the strings in the same way
as it does symbols:
In[2]:= Simplify[exp, "a" > 0 && "b" > 0]
Out[2]= (("a")^3)^(1/3) ("b")^2

In[4]:= Simplify[exp /. {"a" -> a, "b" -> b}, a > 0 && b > 0]
Out[4]= a b^2
I'm wondering if there is any way to have Simplify operate on exp
without having to replace the strings with symbols first (this is how I
do things now, but it adds a number of steps that impact the speed of
the operation):
In[11]:= With[{ele = Cases[exp, x_String, Infinity]},
Module[{rlist = Table[Unique[tmp$], {Length[ele]}], rules, expr,
res}, rules = Thread[ele -> rlist];
expr = Simplify[exp /. rules, Thread[rlist > 0]];
expr /. Map[Reverse, rules]]]
Out[11]= "a" ("b")^2
POSTED BY: Nick Lariviere
Could you try PowerExpand instead?
POSTED BY: Carl Woll
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract