[Date Index]
[Thread Index]
[Author Index]
Re: Re: Infinity vs DirectedInfinity[1]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg70591] Re: [mg70539] Re: Infinity vs DirectedInfinity[1]
*From*: "Chris Chiasson" <chris at chiasson.name>
*Date*: Fri, 20 Oct 2006 05:22:07 -0400 (EDT)
*References*: <acbec1a40610162329m404af5d6h5d54098ec764d0ad@mail.gmail.com> <acbec1a40610180602r3edca17ic9c4004c3b2ba97d@mail.gmail.com> <200610190721.DAA13863@smc.vnet.net>
This talk about Infinity being a symbol defined as DirectedInfinity[1]
but DirectedInfinity[1] displaying as Infinity gave me an idea about
defining and formatting units inthe same way. It doesn't totally work
yet; it is just a concept, but here it is:
In[1]:=
Off[General::"spell1"]
definePrefixedUnit[prefix:{_Symbol,_String},unit:{_Symbol,_String},
desiredContext_String]:=
Module[{pSymb=prefix[[1]],pUStr=prefix[[2]]<>unit[[2]],uSymb=unit[[1]]},
MakeBoxes[HoldPattern[Times[args___]],format_]/;
MemberQ[{args},pSymb]&&MemberQ[{args},uSymb]:=
ReleaseHold[
Hold[MakeBoxes][
Fold[DeleteCases[##,1,1]&,
Append[Times[args],pUStr],{pSymb,uSymb}],format]];
Block[{Set},ToExpression[desiredContext<>pUStr]=pSymb*uSymb];pUStr];
definePrefixedUnit[prefix_List,unit_List]:=
definePrefixedUnit[prefix,unit,Context[]];
In[4]:=
Unprotect[Times]
Outer[definePrefixedUnit,{{Milli,"m"},{Centi,"c"},{Kilo,"k"},{Giga,"G"},{Mega,
"M"}},{{Meter,"m"},{Gram,"g"},{Newton,"N"},{Second,"s"}},1]
Protect[Times]
Out[4]=
{Times}
Out[5]=
{{mm,mg,mN,ms},{cm,cg,cN,cs},{km,kg,kN,ks},{Gm,Gg,GN,Gs},{Mm,Mg,MN,Ms}}
Out[6]=
{Times}
In[7]:=
kg//FullForm
kg
Kilo Gram//FullForm
Kilo Gram
Out[7]//FullForm=
Times[Gram,Kilo]
Out[8]=
kg
Out[9]//FullForm=
Times[Gram,Kilo]
Out[10]=
kg
In[11]:=
km*mm(*doesn't work*)
Out[11]=
\!\(Kilo\ Meter\^2\ Milli\)
On 10/19/06, Andrzej Kozlowski <akoz at mimuw.edu.pl> wrote:
> I definitely do not. I have been trying, it seems without effect, to
> persuade Chris that this has nothing to do with MakeBoxes or anything
> "like" MakeBoxes, since MakeBoxes involves and interplay between the
> Kernel and the FrontEnd and this phenomenon ivolves the Kernel alone
> and has nothing at all to do with the FrontEnd. In fact can be
> demonstrated using the command line and without making any use of the
> FrontEnd. The phenomenon involves two of the basic function of the
> Kernel, known as "parsing" and "evaluation". Evaluation involves only
> the FullForm of expressions. The process of evaluation involved is
> thus demonstrated below:
>
> In[1]:=
> FullForm[Hold[Infinity]]
>
> Out[1]//FullForm=
> Hold[Infinity]
>
> In[2]:=
> FullForm[Infinity]
>
> Out[2]//FullForm=
> DirectedInfinity[1]
>
> In the first example Evaluation is prevented by Hold, which shows
> that Infinity evaluates to DirectedInfinity[1]. Note that Hold
> prevents evaluation but it does not prevent "parsing", e.g:
>
>
> Hold[Plus[a,b]]
>
> Hold[a+b]
>
> Here no evaluation took place, but Plus[a,b] was parsed into the
> input form a+b. (This has nothing to do with the FrontEnd or
> MakeBoxes!).
>
> Now observe this:
>
> In[7]:=
> Hold[DirectedInfinity[1]]//InputForm
>
> Out[7]//InputForm=
> Hold[Infinity]
>
>
> This is pure parsing in action - again no FrontEnd involved. No
> evaluation took place because Hold prevents evaluation. Moreover, the
> FullForm actually remains unchanged:
>
> In[8]:=
> FullForm[%]
>
> Out[8]//FullForm=
> Hold[DirectedInfinity[1]]
>
> In fact, we can now demonstrate here that two expressions can be
> parsed to look exactly the same *in InputForm* (this is important,
> because the fact that two different expressions may look the same in
> StandardForm or TraditionalForm is well known and easy to
> demonstrate) although they are actually different objects as far as
> evaluation is concerned:
>
> a = Hold[DirectedInfinity[1]];
> b = Hold[Infinity];
>
> In[13]:=
> InputForm[a]
>
> Out[13]//InputForm=
> Hold[Infinity]
>
> In[14]:=
> InputForm[b]
>
> Out[14]//InputForm=
> Hold[Infinity]
>
> In[15]:=
> a===b
>
> Out[15]=
> False
>
> In[16]:=
> FullForm[a]
>
> Out[16]//FullForm=
> Hold[DirectedInfinity[1]]
>
> In[17]:=
> FullForm[b]
>
> Out[17]//FullForm=
> Hold[Infinity]
>
> To me this seems pretty clear and it certainly has no relation to
> MakeBoxes.
>
> Andrzej Kozlowski
>
>
>
>
> On 18 Oct 2006, at 22:02, Chris Chiasson wrote:
>
> > So, after talking further with Andrzej Kozlowski, I now think that
> >
> > Infinity is defined to be DirectedInfinity[1] (perhaps via Set, i.e.
> > Infinity=DirectedInfinity[1] )
> >
> > and that it is DirectedInfinity[1] that has a MakeBoxes (or
> > equivalent) rule to display as Infinity in StandardForm and
> > TraditionalForm (or actually, \[Infinity], if you are in the FrontEnd
> > looking at an Output cell).
> >
> > Although, I am not sure Andrzej actually agrees with me :-]
> >
> > On 10/17/06, Chris Chiasson <chris at chiasson.name> wrote:
> >> Infinity is a symbol, as far as I know. However, in FullForm it is
> >> shown as the equivalent DirectedInfinity[1].
> >>
> >> Is there some kind of MakeBoxes rule for FullForm that makes Infinity
> >> show up that way?
> >>
> >> --
> >> http://chris.chiasson.name/
> >>
> >
> >
> > --
> > http://chris.chiasson.name/
>
>
--
http://chris.chiasson.name/
Prev by Date:
**Re: sum of binomials .. bug ?**
Next by Date:
**Re: "short circuiting" And and Or**
Previous by thread:
**Re: Infinity vs DirectedInfinity[1]**
Next by thread:
**Coefficient with dot products**
| |