MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to define a constant like Pi in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63981] Re: how to define a constant like Pi in Mathematica
  • From: ted.ersek at tqci.net
  • Date: Thu, 26 Jan 2006 03:43:04 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

John Smith wanted to define a constant such as (c=1.2345)
that would behave exactly like Pi or E.

Below I give a good, but incomplete definition for the
Omega constant described at
  http://mathworld.wolfram.com/OmegaConstant.html

--------------------------------

In[1]:=
  ClearAll[Omega];
  SetAttributes[Omega,Constant];
  NumericQ[Omega]=True;
  N[Omega]=N[ProductLog[1]];
  N[Omega,prec_]:=N[ProductLog[1],prec];
  Omega/:Re[Omega]=Omega;
  Omega/:Im[Omega]=0;
  Omega/:Arg[Omega]=0;
  Omega/:Abs[Omega]=Omega;
  Omega/:Conjugate[Omega]=Omega;


After making the above definitions we can do lots of things with
Omega that aren't directly defined above. Here are some examples.


In[11]:=
  {
     Negative[Log[Omega]],
     0<Sqrt[Omega]<1,
     Sign[Sqrt[E+Omega]],
     Ceiling[E+Omega]
  }

Out[11]=
  {True, True, 1, 4}


I thought with the above definitions, Mathematica could determine that
the following is zero, but it can't.

In[12]:=
  Im[Log[Sqrt[E+Omega]]]

Out[12]=
  Im[Log[Sqrt[E + Omega]]]

However, if we change Omega to Pi above Mathematica knows the result is zero.
We could fix this specific example with a rule in DownValues[Im] or
UpValues[Log],
but that would only cover limited examples. No doubt there are many other
examples
that my definitions don't cover, but are covered for built-in constants
such as
E and Pi.

In[13]:=
  Im[Log[Sqrt[E+Pi]]]

Out[13]=
  0

----------------------------------
QUESTIONS:

(1)  How can we define a constant the does a better job of acting
     like a built-in constant.

(2)  After making the definitions above NumericQ[Omega] returns True.
     Where is this definition stored?


I evaluated:

In[14]:=
    ??NumericQ


In[15]:=
    ??Symbol


In[16]:=
    ??Omega


In[17]:=
    DefaultValues[NumericQ]
    OwnValues[NumericQ]
    DownValues[NumericQ]
    NValues[NumericQ]
    UpValues[Symbol]
    DownValues[Omega]
    UpValues[Omega]


After checking all those places I found no trace of the definition
   NumericQ[Omega]=True


Note: I am using Mathematica 4.0 and this may be a bug that is fixed in
later versions.

----------
    Thanks,

        Ted Ersek



  • Prev by Date: Re: Factorising polynomials
  • Next by Date: Re: Repeated sequence
  • Previous by thread: Re: Re: how to define a constant like Pi in Mathematica
  • Next by thread: Re: how to define a constant like Pi in Mathematica