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: [mg86724] Re: [mg86687] Using a logical Or in the function definition
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 19 Mar 2008 05:26:46 -0500 (EST)
  • Reply-to: hanlonr at cox.net

ior[x_] := (Head[x] == Integer) || (Head[x] == Rational);

ab[r_?(ior[#] &), s_?(ior[#] &)] := r/s


Bob Hanlon

---- "ahallam at iastate.edu" <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.
> 



  • Prev by Date: Re: Unwanted lined in PDF-exported Graphics3D
  • Next by Date: Re: best fitting
  • Previous by thread: Re: Using a logical Or in the function definition
  • Next by thread: Re: Using a logical Or in the function definition