|
From: Camm M. <ca...@ma...> - 2024-02-29 21:04:12
|
Greetings! Henry Baker <hb...@pi...> writes: > Re symbols/NaNs: > > > > A long time ago, I was attempting to derive Lisp-style > > bounds declarations at compile time using 'forward' and > > 'backward' type inferencing. > Indeed, GCL at the moment is making some pretty heavy use of bounds inferencing/propagation. It seems the most efficient way to do this to me is to define the common bounds as bits in a predefined type vector, and indeed to use floats to avoid the worst in ratios for corner cases. One thing I would like to improve is 'backward' type inferencing, so I am intrigued by your comment. Once one establishes a binding and later figures out it must have a more restricted type than originally thought, the straightforward compiler algorithm is to iterate or throw back to the binding establishment and proceed again with the updated information. We do this in a few places such as when processing tags in tagbodies, but the general idea seems horribly inefficient in terms of compiler speed. What is the best way to collect 'backward' type inferencing while processing code as few times as possible? Take care, > > > For the heck of it, I tried my type inferencer out on a > > Newton sqrt iteration, and it dutifully tried to do the > > computation at compile time, except using Lisp-style 'bounds' > > as a data type. Since the Lisp standard requires *rationals* > > for declaring numeric bounds, I quickly got bounds with enormous > > denominators. > > > > I never tried using range arithmetic with floating point bounds > > as approximations to the rational bounds, but perhaps that might > > be the *best* use for FP range arithmetic in Lisp ! So long as > > the FP bounds are *always* looser than the rational bounds, then > > the FP bounds should still be useful, and the FP type inference > > calculations will be far more efficient than the rational type > > inference calculations were. > > > > BTW, I also worked out a system using Henrici *circular arithmetic* > > for implementing continued fractions for sqrt's; perhaps not the > > fastest way to compute sqrt approximations, but maybe the most > > elegant? > > > > -----Original Message----- > From: Stavros Macrakis <mac...@gm...> > Sent: Feb 29, 2024 11:30 AM > To: Richard Fateman <fa...@gm...> > Cc: <max...@li...> <max...@li...> > Subject: Re: [Maxima-discuss] putting a symbol into a numeric formula, a use for a NaN? > > > > Won't the Newton iteration typically be wrapped in a while clause? How will the termination condition be evaluated? > > On Thu, Feb 29, 2024 at 12:32 AM Richard Fateman <fa...@gm...> wrote: > > In the context of taking a numerical program and reusing it > with partial symbolic input, here's another example.. > > Here is one step of a newton iteration: x[n+1] = x[n] - f(x[n])/df(x[n])... > > newtstep(f,x,val):= block([d:diff(f,x)], val- subst(val, x,f/d)); > > how does this work? val is a guess... here, a guess the root of x^2-9... > > newtstep(x^2-9,x, 5.0); --> returns 3.4 > newtstep(x^2-9,x, 3.4); --> returns 3.023529411764706 > newtstep(x^2-9,x, 3.023529411764706); --> returns 3.00009155413138 > you get the idea. > > Now try putting an expression in there for the guess.. [ could use a NaN perhaps] > newtstep(x^2-9,x,3-eps)$ /* could put 5-eps or anything else... > newtstep(x^2-9,x,%)$ > newtstep(x^2-9,x,%)$ --> > -((eps^8-24*eps^7+504*eps^6-6048*eps^5+45360*eps^4-217728*eps^3+653184*eps^2-1119744*eps+839808)/(8*eps^7-168*eps^6+2016*eps^5-15120*eps^4+72576*eps^3-217728*eps^2+373248*eps-279936)) > > whew! try to understand this by using Taylor expansion.. > > taylor(%,eps,0, 9) --> 3+eps^8/279936+eps^9/209952 > > The newtstep program could instead be some large mysterious > iterative numerical program in a language that normally does not > allow symbols. But we might fool it by using NaNs as substitutes for symbolic > expressions. > If you had this all hooked up via trap handling > you might get some insight as to how a program works.. > > RJF > > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > -- Camm Maguire ca...@ma... ========================================================================== "The earth is but one country, and mankind its citizens." -- Baha'u'llah |