MathGroup Archive 2006

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

Search the Archive

Re: Defining N for a new entity

  • To: mathgroup at
  • Subject: [mg66822] Re: Defining N for a new entity
  • From: Giuseppe Bilotta <bilotta78 at>
  • Date: Wed, 31 May 2006 06:31:39 -0400 (EDT)
  • References: <> <e5bsuq$afo$> <e5ei6d$800$> <e5h5p7$ero$>
  • Sender: owner-wri-mathgroup at

On Tue, 30 May 2006 10:11:51 +0000 (UTC), Peter Pein wrote:

>   just guessing...
> N[AffineExpression[c_,dev_]]:=... might evaluate the left hand side before applying SetDelayed. This is an explanation, why Mathematica doesn't complain about N being protected.
> But N[AffineExpression[c_,dev_]] evaluates to AffineExpression[c_,dev_], leaving you with a hidden recursion:
> N[f[x_]]:=f[N[x]]
> N[f[13]] (* choose your favourite unlucky number here *)
> reproduces the crash.
> If you don't want the NHoldRest-solution, you might try:
> In[1]:=
> a1=AffineExpression[1,{{1,1},{2,Pi}}];
> AffineExpression /: HoldPattern[N][AffineExpression[c_, dev_]] :=
>      AffineExpression[N[c], MapAt[N, #, 2]& /@ dev]
> N[a1]
> --> AffineExpression[1.,{{1,1.},{2,3.14159}}]

Hello Peter, thank you very much, this seems to be the case indeed.
Interestingly, even with this definition the Numericization done by
LinearSolve *still* seems to apply to the whole AffineExpression, so I
guess I will have to use both the HoldPattern[N] *and* the NHoldRest

Thanks all for your help.

Giuseppe "Oblomov" Bilotta

"I'm never quite so stupid
 as when I'm being smart" --Linus van Pelt

  • Prev by Date: Problem with Limit
  • Next by Date: Re: Re: Exporting Graphics to .eps
  • Previous by thread: Re: Defining N for a new entity
  • Next by thread: Re: Defining N for a new entity