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


Groups > comp.soft-sys.math.mathematica > #8022 > unrolled thread

Re: Tips for writing correct, non trivial Mathematica Libraries

Started byAndrzej Kozlowski <akoz@mimuw.edu.pl>
First post2012-01-20 06:46 +0000
Last post2012-01-20 06:46 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Tips for writing correct, non trivial Mathematica Libraries Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2012-01-20 06:46 +0000

#8022 — Re: Tips for writing correct, non trivial Mathematica Libraries

FromAndrzej Kozlowski <akoz@mimuw.edu.pl>
Date2012-01-20 06:46 +0000
SubjectRe: Tips for writing correct, non trivial Mathematica Libraries
Message-ID<jfb2ku$hig$1@smc.vnet.net>
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:

geom[list_List] := Apply[Times, list]^(1/Length[list])

and now

geom[list_List] := Apply[Times, list]^(1/Length[list])

geom[x + y]

geom[x + y]

and if you really wish you can restrict it only to vectors you can do

geom[list_?VectorQ] := Apply[Times, list]^(1/Length[list])

and so on.

This is much more powerful and flexible than the "other" approach.

Andrzej Kozlowski

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web