Re: Defining N for a new entity
- To: mathgroup at smc.vnet.net
- Subject: [mg66822] Re: Defining N for a new entity
- From: Giuseppe Bilotta <bilotta78 at hotpop.com>
- Date: Wed, 31 May 2006 06:31:39 -0400 (EDT)
- References: <200605280103.VAA23345@smc.vnet.net> <e5bsuq$afo$1@smc.vnet.net> <e5ei6d$800$1@smc.vnet.net> <e5h5p7$ero$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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
strategy.
Thanks all for your help.
--
Giuseppe "Oblomov" Bilotta
"I'm never quite so stupid
as when I'm being smart" --Linus van Pelt
- References:
- Defining N for a new entity
- From: Giuseppe Bilotta <bilotta78@hotpop.com>
- Defining N for a new entity