MathGroup Archive 2011

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

Search the Archive

Re: "Esoteric of the week"

  • To: mathgroup at
  • Subject: [mg122012] Re: "Esoteric of the week"
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at>
  • Date: Sun, 9 Oct 2011 03:51:19 -0400 (EDT)
  • Delivered-to:
  • References: <j6q5mt$ov1$> <op.v21rrnmwqcgwdu@core2.lan>

On Sat, 08 Oct 2011 20:15:13 +0100, Oleksandr Rasputinov  
<oleksandr_rasputinov at> wrote:

> On Sat, 08 Oct 2011 19:44:45 +0100, Bill Rowe <readnews at>  
> wrote:
>> On 10/6/11 at 4:23 AM, weh at (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:  
> <>.  
> 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,  
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)


"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  
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  

Block[{Internal`$EqualTolerance = -Infinity},
    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


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.

  • Prev by Date: Re: Sort on vector component
  • Next by Date: Re: Sort on vector component
  • Previous by thread: Re: general formula for differentiating a spherical bessel function of
  • Next by thread: Re: "Esoteric of the week"