|
[Date Index]
[Thread Index]
[Author Index]
Re: LeafCount Question
- To: mathgroup at smc.vnet.net
- Subject: [mg25802] Re: LeafCount Question
- From: "Hans Staugaard" <hans.staugaard at get2net.dk>
- Date: Sat, 28 Oct 2000 01:40:57 -0400 (EDT)
- References: <8t63s9$eg2@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hello
Here's a quick fix.
First a check to see that the ordering is 'wrong':
In[1]:=
2c - 2a - b + d
Out[1]=
-2 a - b + 2 c + d
Then my fix
In[2]:=
Unprotect[Plus];
In[3]:=
Format[Plus[negs : (Times[_?Negative, _] ..), poss__]] :=
SequenceForm[Plus[poss], negs]
In[4]:=
Protect[Plus];
Now check that the ordering is 'right'
In[5]:=
2*c - 2a - b + d
Out[5]=
2 c + d-2 a-b
Note that there are problems with the operator spacing.
Hans
"Dana" <dana_news at hotmail.com> wrote in message
news:8t63s9$eg2 at smc.vnet.net...
> Hello. Using Mathematica 4.0 When one solves equations, I get a little
frustrated
> when the answers come out as
> -A +B, when the answer looks much better as...
> B - A
>
> I was hoping that the "LeafCount" would be smaller with my "preferred"
way,
> but for some reason, it does not look like there is a difference.
>
> In[19]:=
> {LeafCount[-B + D], LeafCount[D - B]}
>
> Out[19]=
> {5, 5}
>
>
> Here is a simple Solve, and it is a little embarrassing to say the answer
is
> (-B + D)..Etc when everyone else will have to change this manually to
(D -
> B)...ect.
>
> Is there a way around this? Again, I was hoping LeafCount would do the
> trick, but it apparently does not.
> Thank you in advance. Dana.
>
> FullSimplify[Solve[{Y == A*X + B, Y == C*X + D}, {X, Y}],
> ComplexityFunction -> LeafCount]
>
> {{X -> (-B + D)/(A - C), Y -> (-(B*C) + A*D)/(A - C)}}
>
>
>
> Since I am new to Mathematica, I noticed the following...
> Internally, it looks like no difference. It is just frustrating.
>
> In[25]:=
> {FullForm[(-B + D)], FullForm[(D - B)]}
>
> Out[25]=
> {Plus[Times[-1, B], D], Plus[Times[-1, B], D]}
>
>
>
>
Prev by Date:
Re: LeafCount Question
Next by Date:
RE: A simple problem
Previous by thread:
Re: LeafCount Question
Next by thread:
Re: LeafCount Question
|