MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Patterns with conditions

  • To: mathgroup at
  • Subject: [mg116883] Patterns with conditions
  • From: ÅerÃch Jakub <Serych at>
  • Date: Thu, 3 Mar 2011 05:58:30 -0500 (EST)

Dear Mathematica group,
I'm playing with function definitions and patterns based multiple definition of the function. I have defined this function:
sinc[x_ /; x == 0] := 1;
sinc[x_] := Sin[\[Pi] x]/(\[Pi] x);

(I know, that Mathematica has Sinc function defined, it's just the test.)

It works fine for let's say sinc[\[Pi]], even for sinc[0]. But if I define the table:

tab = {0, \[Pi]/3, \[Pi]/2, \[Pi] 2/3, \[Pi], \[Pi] 4/3, \[Pi] 5/3, 
   2 \[Pi]};

and I let my function evaluate the results sinc[tab], it returns error messages: 
Power::infy: Infinite expression 1/0 encountered. >> and
Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>

I can understand, that "tab" doesn't fit to pattern condition /; x==0, also I know, that it is possible to Map my function to table
Map[sinc, tab] and it works fine.

I can imagine solution with IF[x==0,1, Sin[\[Pi] x]/(\[Pi] x), but my question is: Is it possible to make my function fully Listable using just pattern conditions?

Thanks for responses


P.S. Code in one block for easy copying:

sinc[x_ /; x == 0] := 1;
sinc[x_] := Sin[\[Pi] x]/(\[Pi] x);
tab = {0, \[Pi]/3, \[Pi] 2/3, \[Pi], \[Pi] 4/3, \[Pi] 5/3, 2 \[Pi]};
Map[sinc, tab] 

  • Prev by Date: Re: Select from Tuplet using logical expression
  • Next by Date: Re: problem with"Re" syntax
  • Previous by thread: Re: Alternative to DumpSave
  • Next by thread: Re: Patterns with conditions