Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8005 > unrolled thread
| Started by | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| First post | 2012-01-19 10:17 +0000 |
| Last post | 2012-01-20 06:47 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Tips for writing correct, non trivial Mathematica Libraries Bill Rowe <readnews@sbcglobal.net> - 2012-01-19 10:17 +0000
Re: Tips for writing correct, non trivial Mathematica Libraries "l.i.b." <nehal.alum@gmail.com> - 2012-01-20 06:47 +0000
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Date | 2012-01-19 10:17 +0000 |
| Subject | Re: Tips for writing correct, non trivial Mathematica Libraries |
| Message-ID | <jf8qj3$3of$1@smc.vnet.net> |
On 1/18/12 at 6:00 AM, nehal.alum@gmail.com (l.i.b.) wrote:
>** Take for example the following: (Taken from the mathematica 8
>virtual book section "Applying Functions to Lists and Other
>Expressions")
>geom[list_] := Apply[Times, list]^(1/Length[list])
>So, this does a bad thing for geom[ x+ y] (returns (Sqrt[x y])
What were you expecting here? This looks correct to me
>The built-in function GeometricMean properly complains when given
>this input,
I don't see a problem with the built in function. That is:
In[6]:= GeometricMean[{x, y}]
Out[6]= Sqrt[x*y]
>** In general I get the feeling the nature of Mathematica
>programming (pattern matching, transformations, etc) make it hard to
>reason about the correctness of code. So while these aspects are
>seem super useful for manipulating data, or building up
>expressions/calculations, and interacting in general, it is hard to
>have solid trust when using mathematica code.
I think this comes with experience with Mathematica.
>For instance it feels likely that given mathematica source code
>written by a 'normal' person, a reasonably clever person could
>find a
>way to spoof it -- not just make it run really slow, but actually
>produce the wrong answer.
This is no more true of Mathematica code than code written in
any other language. Well written code provides correct results
and will not generate incorrect results. If what you are saying
is pattern matching and replacement rules can be used by someone
to rewrite code to produce an incorrect result then I agree this
is possible. But, I emphasize that is *re-writing* the code not
getting a bad result from well written code.
>** Another difficulty I see that it is not easy to understand how to
>best leverage the other parts of Mathematica when writing your own
>libraries. For instance suppose I have my matrix differential
>algebra library, MatDiffLib, and I'm happy with how it works on a
>stand alone basis. Now suppose I want my routines to play
>intelligently with // N (using specialized numerical algorithms) or
>work well with Interval arithmetic -- of course I could cross my
>fingers and just trust that things would work, but it's just not
>clear from the documentation how to get the inner details needed to
>solve problems would things not work.
>**Maybe another way to ask my question is , "Are there any good open
>source Mathematica libraries that could serve as a template for how
>to practically develop complicated Mathematica code"?
In terms of Mathematica, I interpret libraries as being
Mathematica packages. With that understanding there are a great
many packages available on the Internet. Start with Wolfram's site.
Now, as to whether these are good packages or not, like any
other open source code some will be good some will not be good.
If you want to look at examples of well written Mathematica
packages, a good place to start is to look at the packages that
ship with Mathematica.
[toc] | [next] | [standalone]
| From | "l.i.b." <nehal.alum@gmail.com> |
|---|---|
| Date | 2012-01-20 06:47 +0000 |
| Message-ID | <jfb2lt$hit$1@smc.vnet.net> |
| In reply to | #8005 |
Thanks for your comments. My followups are inlined below:
> >** Take for example the following: (Taken from the mathematica 8
> >virtual book section "Applying Functions to Lists and Other
> >Expressions")
> >geom[list_] := Apply[Times, list]^(1/Length[list])
> >So, this does a bad thing for geom[ x+ y] (returns (Sqrt[x y])
>
> What were you expecting here? This looks correct to me
the snippet for 'geom' is taken for the mathematica tutorial, and is
meant to show the user how to define a function that implements the
geometric mean. so for instance,
geom[{x,y,z}] = (x y z )^(1/3). But geom[x+y] treats the expression
as a list and returns Sqrt[x y], which is not what a new user would
expect ( a better answer would be x+y)
>
> >The built-in function GeometricMean properly complains when given
> >this input,
>
I'm saying GeometricMean does not get fooled by GeometricMean[x+y],
which means the author thought of how to protect it from doing the
wrong thing -- and it would be nice to see exactly what syntax they
used.
>
> If you want to look at examples of well written Mathematica
> packages, a good place to start is to look at the packages that
> ship with Mathematica.
Actually that's exactly what I've started to do, once I nailed down
the location of the bundled packages. Though I've yet to find the
definition for GeometricMean in the install directory -- presumable it
is a native command.
Thanks
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web