Re: Re: Simple Solve Question
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg385] Re: [mg362] Re: [mg350] Simple Solve Question
- From: danl (Daniel Lichtblau)
- Date: Tue, 3 Jan 1995 10:49:19 -0600
Automatic flattenning is not/will not be done because it is the
wrong thing to do. The output of Solve is a list of solns, each of
which is a list of rules. Flattenning would destroy this structure.
Among other drawbacks, it would kill any code that automatically
extracts info from Solve output, because such code would assume the
output of Solve was as described above.
Daniel Lichtblau, WRI
Begin forwarded message:
Date: Tue, 27 Dec 94 13:36:02 EST
From: wmm at chem.wayne.edu (Martin McClain)
Subject: [mg362] Re: [mg350] Simple Solve Question
To: mathgroup at christensen.cybernetics.net
Content-Length: 1144
>Dear MathGroupers-
>
> I have a very simple question.
>Why when you issue
>
>Solve[5 x==10, x]
>
>Does MMA return:
>{{x->2}}
>
>I'm wondering why it's List[List[...]].
>
>I hate using Flatten to get rid of this nested List.
>
>Thanks in advance,
>Daryl
It's because in general, Solve[] produces multiple sets of multiple
replacements, like
{{x->1,y->2},{x->3,y->4}}. When there is only a single solution for
a
single unknown, the double brackets survive because to get rid of
them they
would have to test for them explicitly, and I suppose this would make
Solve[] a tiny bit slower.
But I agree completely with you. I use Mma a lot for simple
problems, and
automatic removal of the outer bracket (when there is only one
solution,
but with multiple unknowns), or removal of both brackets (when there
is
single solution for a single unknown) would be a great convenience.
Failure to Flatten here always causes trouble down the page. This is
one
of the most frequent errors I and my undergraduate students make.
WRI, please note: If you automate the flattening, existing programs
with
explicit flattening will still work perfectly.