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: [mg86703] Re: [mg86687] Using a logical Or in the function definition
  • From: Arne Hallam <ahallam at iastate.edu>
  • Date: Wed, 19 Mar 2008 05:22:48 -0500 (EST)
  • Organization: Iowa State University
  • References: <200803180951.EAA18708@smc.vnet.net> <8AF07FCB-2A0E-4C24-8A56-814D817C2C20@dimi.uniud.it>
  • Reply-to: ahallam at iastate.edu

Thanks to everyone who replied.

These are all great ``alternatives'' as opposed to logical solutions.

Using alternative instead of logical was what I needed.




Adriano Pascoletti wrote:
> Use Alternatives (|):
> In[1]:= ab[(r_Integer) | (r_Rational), (s_Integer) | (s_Rational)] := r/s;
> In[2]:= ab[3, 7]
> Out[2]= 3/7
> In[3]:= ab[3/2, 21/4]
> Out[3]= 2/7
> In[4]:= ab[3/2, 7]
> Out[4]= 3/14
> In[5]:= ab[3.2, 4]
> Out[5]= ab[3.2, 4]
> 
> Adriano Pascoletti
> 
> On 18 mar 2008, at 10:51, 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.
>>
> 

-- 
with all thy getting get understanding---Proverbs 4:7.

The gentle art of being gentle---of kindness and forgiveness, 
sensitivity and thoughtfulness and generosity and humility and good 
old-fashioned love---have gone out of fashion.  Ironically, everyone is 
demanding their rights, and this demand is so shrill that it destroys 
one of the most basic rights, if we can put it like that: the right, or 
at least the longing and hope, to have a peaceful, stable, secure, and 
caring place to live, to be, to learn, and to flourish---N.T. Wright.

In the wildness of speculation it has been suggested (of course more in 
jest than in earnest),that Europe ought to grow its corn in America, and 
devote itself solely to manufactures and commerce, as the best sort of 
division of the labour of the globe---Thomas Malthus, An Essay on the 
Principle of Population Book III, Chapter XII.

Arne Hallam
Department of Economics
266 Heady Hall
Iowa State University
Ames, IA 50011
ahallam at iastate.edu

Contact Information:
ahallam at iastate.edu
Work:	515-294-5861
FAX: 	515-294-0221
Home:	515-292-8739


  • Prev by Date: Re: V.6.0.2 gripes...
  • Next by Date: Re: Compiled function slowdown
  • Previous by thread: Re: Using a logical Or in the function definition
  • Next by thread: Re: Using a logical Or in the function definition