Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8030

Re: Tips for writing correct, non trivial Mathematica Libraries

From Nehal Patel <nehal.alum@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Tips for writing correct, non trivial Mathematica Libraries
Date 2012-01-20 06:53 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jfb30f$ho3$1@smc.vnet.net> (permalink)
References <201201191012.FAA03722@smc.vnet.net> <3609A129-8BFE-453D-B414-9C1D4366BA43@mimuw.edu.pl>

Show all headers | View raw


On Jan 19, 2012, at 6:39 AM, Andrzej Kozlowski wrote:

>
> On 19 Jan 2012, at 11:12, Bill Rowe wrote:
>
>>>
>>> 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
>
> Clearly he sees what actually is a powerful feature of Mathematica as 
a "bad thing". The feature is that a function whose arguments are not 
restricted by pattern maching can be put to a more general use. I think 
it's great and not "bad". If you want to restrict the function to work 
on lists you can do this:
>

Hi -- thanks for your comment.  Actually I think the pattern matching is 
the coolest thing.  my point is that when combined with how Mathematica 
treats + (and in general, Flat and Orderless operators) it becomes a lot 
harder to reason about whether  a function handles all edge cases 
correctly.  So for instance nobody would expect the geometric mean of x 
+ y to be  Sqrt[x y], it should be (x + y)^1 = x+ y

Separately, GeometricMean does do something reasonable for 
GeometricMean[x + y] (give it a try), and I wish it were easier to see 
what syntax it uses.  


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Tips for writing correct, non trivial Mathematica Libraries Nehal Patel <nehal.alum@gmail.com> - 2012-01-20 06:53 +0000

csiph-web