Re: "Esoteric of the week"

*To*: mathgroup at smc.vnet.net*Subject*: [mg122012] Re: "Esoteric of the week"*From*: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>*Date*: Sun, 9 Oct 2011 03:51:19 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <j6q5mt$ov1$1@smc.vnet.net> <op.v21rrnmwqcgwdu@core2.lan>

On Sat, 08 Oct 2011 20:15:13 +0100, Oleksandr Rasputinov <oleksandr_rasputinov at hmamail.com> wrote: > On Sat, 08 Oct 2011 19:44:45 +0100, Bill Rowe <readnews at sbcglobal.net> > wrote: > >> On 10/6/11 at 4:23 AM, weh at snafu.de (Dr. Wolfgang Hintze) wrote: >> >>> What about setting up a regular column "esoteric of the week" naming >>> functions that are rarely used ? >> >> The difficulty is a determination of rarely used. Who decides? >> And how? ... For me at least, the operational definition of rarely >> used would be those functions I have to look up syntax to use correctly. >> > > Along these lines, I would suggest a family of undocumented Internal` > functions that can be quite useful: > > Internal`InheritedBlock: > works just like Block, except that the definitions of the localized > symbols are copied from the global environment (including Attributes, > Options, etc.). Useful for temporarily overriding the properties of > System` functions without going through the Unprotect/modify/Protect > dance, for example. > > {Internal`Bag, Internal`StuffBag, Internal`BagPart}: > described by Daniel Lichtblau here: > <http://stackoverflow.com/questions/6691491/implementing-a-quadtree-in-mathematica>. > Apart from being useful for building your own data structures, Bags are > considered to be scalars by the Mathematica compiler and can be used to > build up lists inside compiled code without AppendTo (and its associated > CopyTensor). (Sow/Reap use Bags but at present don't work in compiled > code because their ability to associate a tag with each expression > relies on pattern matching.) > > Internal`Deflatten: > Somewhat similar to Partition, but only works with 1-d Lists and > operates based on a structural specification as given by Dimensions. > Similar to the RESHAPE function from Fortran 90. Say we have a list > (which must be a full-rank tensor) with some nested structure: > > lst = Partition[{{11, 12, 13}, {21, 22, 23}, {31, 32, 33}}, {2, 1}, 1]; > dims = Dimensions[lst] > > {2, 3, 2, 1} > > lst == Internal`Deflatten[Flatten[lst], dims] > > True > > an important point to note about Internal`Deflatten is that a > dimensional specification must not be given that would require more > elements in the source array than actually exist in order to produce a > full-rank tensor result. That is, for Internal`Deflatten[lst, dims], > Times @@ dims <= Length@Flatten[lst] must be fulfilled, otherwise the > kernel will crash. While I remember, I will add: {Internal`$EqualTolerance, Internal`$SameQTolerance}: As discussed recently in the thread archived here, <http://www.mathkb.com/Uwe/Forum.aspx/mathematica/21194/Numerical-accuracy-precision-this-is-a-bug-or-a-feature>, Equal and SameQ apply a certain tolerance when comparing real numbers. From their respective documentation pages: "Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits)." (Internal`$EqualTolerance = 2.10721) and "SameQ ... considers Real numbers equal if they differ in their last binary digit." (Internal`$SameQTolerance = 0.30103) One may or may not agree with the principle behind the application of such a tolerance, but it turns out that this can be controlled by adjusting the values given above. However, Alexey Popkov has correctly noted here <http://stackoverflow.com/questions/4983885/is-there-a-normal-equalq-function-in-mathematica> that setting these to zero does not necessarily guarantee that two different numbers will not compare Equal. In fact it appears that the units of these values are not exactly Log[2]/Log[10] ulps, but Log[2]/Log[10] ulps _relative to those of a machine precision number_: in other words, for arbitrary precision numbers, negative values may be required in order to make the tolerance small enough. Fortunately, it is possible to make it arbitrarily small because a value of -Infinity is allowed, in which case Alexey's example from the link above works as anticipated: Block[{Internal`$EqualTolerance = -Infinity}, Cases[ Table[ a = SetPrecision[1., n]; b = a + 10^-n; {n, a == b, RealDigits[a, 2] === RealDigits[b, 2], Order[a, b] == 0}, {n, 15, 300} ], {_, True, False, _} ] ] // Length 0 While a tolerance of +Infinity is also allowable, since this means that any two real numbers will compare Equal, I struggle to imagine any realistic situation in which this would be useful.

**Re: Sort on vector component**

**Re: Sort on vector component**

**Re: general formula for differentiating a spherical bessel function of**

**Re: "Esoteric of the week"**