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: [mg64023] Re: how to define a constant like Pi in Mathematica
  • From: Urijah Kaplan <uak at sas.upenn.edu>
  • Date: Fri, 27 Jan 2006 05:13:54 -0500 (EST)
  • Organization: University of Pennsylvania
  • References: <dra36k$m2t$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In Mtm 5.2,  Im[Log[Sqrt[E+Omega]]==0, but NumericQ[Omega]=True is not 
retained when you DumpSave[] Omega, Quit, and then Get. Strange.

           --Urijah Kaplan

In[1]:=

$Version
Out[1]=
5.2 for Microsoft Windows (June 20, 2005)
In[2]:=
ClearAll[Omega];
SetAttributes[Omega,Constant];
N[Omega]=N[ProductLog[1]];
N[Omega,prec_]:=N[ProductLog[1],prec];
NumericQ[Omega]=True;
Omega/:Re[Omega]=Omega;
Omega/:Im[Omega]=0;
Omega/:Arg[Omega]=0;
Omega/:Abs[Omega]=Omega;
Omega/:Conjugate[Omega]=Omega;
In[12]:=
{Negative[Log[Omega]],0<Sqrt[Omega]<1,Sign[Sqrt[E+Omega]],Ceiling[E+Omega]}

Out[12]=
{True,True,1,4}
In[13]:=
Im[Log[Sqrt[E+Omega]]]

Out[13]=
0
In[14]:=
??Omega

Global`Omega
\!\(\*
   InterpretationBox[GridBox[{
         {\(Attributes[Omega] = {Constant}\)},
         {" "},
         {GridBox[{
               {\(Abs[Omega] ^= Omega\)},
               {" "},
               {\(Arg[Omega] ^= 0\)},
               {" "},
               {\(Conjugate[Omega] ^= Omega\)},
               {" "},
               {\(Im[Omega] ^= 0\)},
               {" "},
               {\(Re[Omega] ^= Omega\)}
               },
             GridBaseline->{Baseline, {1, 1}},
             ColumnWidths->0.999,
             ColumnAlignments->{Left}]},
         {" "},
         {GridBox[{
               {\(Omega /: N[Omega, {MachinePrecision, \[Infinity]}] =
                   0.5671432904097838`\)},
               {" "},
               {\(N[Omega, prec_] := N[ProductLog[1], prec]\)}
               },
             GridBaseline->{Baseline, {1, 1}},
             ColumnWidths->0.999,
             ColumnAlignments->{Left}]}
         },
       GridBaseline->{Baseline, {1, 1}},
       ColumnAlignments->{Left}],
     Definition[ "Omega"],
     Editable->False]\)
In[15]:=

DefaultValues[NumericQ]
OwnValues[NumericQ]
DownValues[NumericQ]
NValues[NumericQ]
UpValues[Symbol]
DownValues[Omega]
UpValues[Omega]
Out[15]=
{}
Out[16]=
{}
Out[17]=
{}
Out[18]=
{}
Out[19]=
{}
Out[20]=
{}
Out[21]=
{HoldPattern[Abs[Omega]]\[RuleDelayed]Omega,
   HoldPattern[Arg[Omega]]\[RuleDelayed]0,
   HoldPattern[Conjugate[Omega]]\[RuleDelayed]Omega,
   HoldPattern[Im[Omega]]\[RuleDelayed]0,
   HoldPattern[Re[Omega]]\[RuleDelayed]Omega}
In[22]:=

NumericQ[Omega]
Out[22]=
True
In[23]:=

DumpSave["OM.mx",Omega]
Out[23]=
{Omega}
In[24]:=

Quit[]
In[1]:=

<<OM.mx
In[2]:=

??Omega
Global`Omega
\!\(\*
   InterpretationBox[GridBox[{
         {\(Attributes[Omega] = {Constant}\)},
         {" "},
         {GridBox[{
               {\(Abs[Omega] ^= Omega\)},
               {" "},
               {\(Arg[Omega] ^= 0\)},
               {" "},
               {\(Conjugate[Omega] ^= Omega\)},
               {" "},
               {\(Im[Omega] ^= 0\)},
               {" "},
               {\(Re[Omega] ^= Omega\)}
               },
             GridBaseline->{Baseline, {1, 1}},
             ColumnWidths->0.999,
             ColumnAlignments->{Left}]},
         {" "},
         {GridBox[{
               {\(Omega /: N[Omega, {MachinePrecision, \[Infinity]}] =
                   0.5671432904097838`\)},
               {" "},
               {\(N[Omega, prec_] := N[ProductLog[1], prec]\)}
               },
             GridBaseline->{Baseline, {1, 1}},
             ColumnWidths->0.999,
             ColumnAlignments->{Left}]}
         },
       GridBaseline->{Baseline, {1, 1}},
       ColumnAlignments->{Left}],
     Definition[ "Omega"],
     Editable->False]\)
In[3]:=

DefaultValues[NumericQ]
OwnValues[NumericQ]
DownValues[NumericQ]
NValues[NumericQ]
UpValues[Symbol]
DownValues[Omega]
UpValues[Omega]
Out[3]=
{}
Out[4]=
{}
Out[5]=
{}
Out[6]=
{}
Out[7]=
{}
Out[8]=
{}
Out[9]=
{HoldPattern[Abs[Omega]]\[RuleDelayed]Omega,
   HoldPattern[Arg[Omega]]\[RuleDelayed]0,
   HoldPattern[Conjugate[Omega]]\[RuleDelayed]Omega,
   HoldPattern[Im[Omega]]\[RuleDelayed]0,
   HoldPattern[Re[Omega]]\[RuleDelayed]Omega}
In[10]:=

NumericQ[Omega]
Out[10]=
False

ted.ersek at tqci.net wrote:
> 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: Repeated sequence
  • Next by Date: Weighted GraphPlot Display
  • Previous by thread: Re: how to define a constant like Pi in Mathematica
  • Next by thread: Assuming to be a real number is useless even in simple cases?