Re: How to declare Integers?
- To: mathgroup at smc.vnet.net
- Subject: [mg13331] Re: How to declare Integers?
- From: Tobias Oed <tobias at physics.odu.edu>
- Date: Mon, 20 Jul 1998 02:49:52 -0400
- Organization: Old Dominion University
- References: <email@example.com> <firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
Sean Ross wrote: > > Le Van Tri wrote: > > > > Dear Joe Oswald and Sean Ross, > > > > About your idea of having variable typing instead of pattern matching in > > Mathematica > > I think that idea is nice but some what "obsolete" - by which I mean > > variable typing > > is obsolete by the coming out of pattern matching. Why ? In traditional > > languages > > like Fortran, C++, Lisp, Scheme, ML, ... variable typing was done statically > > at compile > > time. By using pattern matching, that could be done dynamically at run time. > > Which > > way is better ? > > Perhaps the term variable "typing" is ill-advised since it sounds the > same as what is done in C++ or Fortran. No, what we are after is > something like this: > > Declare[symbol,Integer]; > > Sin[symbol Pi x] > > and have it return zero for all x even with no explicit value assigned > to symbol. > > I want to be able to tell mathematica that a certain symbol is Real, > Complex, Imaginary, greater than 2, Integer etc. and have every single > function in the language react appropriately taking that declaration as > an assumption. I want Integrals to be appropriate to Real only or > Integer only arguments etc. In essence I want global assumptions or > conditions on symbols with every built-in function looking at those > restrictions or assumptions and responding appropriately. > > You can't do that yet with pattern matching. I have a similar problem, but it is less involved with the built in mathematica function since it deals with functions I defined in a Package. I need to be able to declare proberties of four vectors, (more or less the same as usual vectors except relativistic). I still haven't decided on how to declare a given symbol to represent a four vector. I see two alternatives: i) I tag all my symbols, so if k is supposed to be fourvector, I use Fv[k] everywhere, and can use definitions like Energy[a_?(FreeQ[#,Fv] b_]:=a Energy[b] b) I put all my four vectors in the context Fv` and I would write Energy[a_ b_?(Context[#]==="Fv`")]:= a Energy[b] (This is just an example which in fact does not work since b could be the sum of two four vectors) Which alternative do you think is better ? Tobias