The Mathematica Journal
Departments
Feature Articles
Columns
New Products
New Publications
Classifieds
Calendar
News Bulletins
Mailbox
Letters
Write Us
About the Journal
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues
Home
Download this Issue

Building Your Own Domain

Q: How can I define my own domain so that it behaves similarly to the  built-in domains (Section 3.3.10 of The Mathematica Book) such as the integers ([Graphics:../Images/index_gr_42.gif])? Specifically, I want to have a domain of natural numbers ([Graphics:../Images/index_gr_43.gif]) which would allow me to do things like [Graphics:../Images/index_gr_44.gif] and have Element ([Graphics:../Images/index_gr_45.gif]) understand this new domain.
A: Paul Wellin (wellin@wolfram.com) and Adam Strzebonski (adams@wolfram.com) suggest the following definition.
[Graphics:../Images/index_gr_46.gif]
At first sight, this definition might appear more complicated than  necessary. However, one cannot use the simpler construct [Graphics:../Images/index_gr_47.gif] because, for an arbitrary symbol, the definition should return the unevaluated expression.
After we define a Format,
[Graphics:../Images/index_gr_48.gif]
our domain now has a symbolic representation.
[Graphics:../Images/index_gr_49.gif]
[Graphics:../Images/index_gr_50.gif]
Finally, we need to add interpretation rules for expressions involving [Graphics:../Images/index_gr_51.gif].
[Graphics:../Images/index_gr_52.gif]
Here is a test of our domain.
[Graphics:../Images/index_gr_53.gif]
[Graphics:../Images/index_gr_54.gif]


Converted by Mathematica      May 8, 2000

[In and Out Index] [Prev Page][Next Page]