Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9488
| From | Murray Eisenberg <murray@math.umass.edu> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Pattern Syntax for Alternate Heads with Default Value |
| Date | 2012-04-06 10:01 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jlmet7$mft$1@smc.vnet.net> (permalink) |
While mathematically each integer is a real number, a Mathematica object with head Integer does _not_ have head Real. Thus: g[x_Real] := x^2 g[3] g[3] On 4/5/12 5:51 AM, Murta wrote: > On Apr 4, 5:28 am, Ben<ben...@gmail.com> wrote: >> I'm trying to build a unary function which accepts only arguments with >> two possible heads and has a default value. That is, something like >> the following, except that this doesn't work. Anyone know how to do >> this correctly? >> >> f[(x_Real | x_Integer) : 2.5] := x^2; >> where f[3] = 9 >> and f[1.5] = 2.25 >> and f[] = 6.25 > > Hi Ben > Maybe something like that? > > f[x_ (Real | Integer)] := x^2; f[] = 6.25; > > (But all Integer are Real, I don't understand the application. > It could be f[x_Real: 2.5] := x^2) > best regards > Murta > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Pattern Syntax for Alternate Heads with Default Value Murray Eisenberg <murray@math.umass.edu> - 2012-04-06 10:01 +0000
csiph-web