MathGroup Archive 2008

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

Search the Archive

Re: Using a logical Or in the function definition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86691] Re: Using a logical Or in the function definition
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Wed, 19 Mar 2008 05:20:30 -0500 (EST)
  • Organization: University of Bergen
  • References: <fro39q$i8a$1@smc.vnet.net>

ahallam at iastate.edu wrote:
> I would like to use Or in the function definition as in
> 
> ab[ Or[r_Integer,r_Rational], Or[s_Integer,s_Rational] ]:=r/s;
> 
> In other words, I want the function to take integers or ratios of
> integers as arguments, but not real numbers which are not rational.
> 
>  But if I give the function integer arguments, it does not evaluate.
> 
> If I try
> 
> ar[ r_Integer , Or[s_Integer , s_Rational]] := r/s;
> 
> and give an integer first argument it works and so on.
> 

Have you checked the documentation on how to construct patterns?

http://reference.wolfram.com/mathematica/guide/Patterns.html

You need Alternatives, not Or.

ab[ r:(_Integer|_Rational), s:(_Integer|_Rational) ]:=r/s

But perhaps you were looking for

ab[r_?ExactNumberQ, s_?ExactNumberQ] := r/s

?


  • Prev by Date: Re: Unwanted lined in PDF-exported Graphics3D
  • Next by Date: Re: Bug: symbol recreates itself suddenly
  • Previous by thread: Re: Using a logical Or in the function definition
  • Next by thread: Re: Using a logical Or in the function definition