[seqfan] Re: Using "Quiet" in Mathematica

Olivier Gerard olivier.gerard at gmail.com
Sat Feb 18 21:38:50 CET 2012


On Sat, Feb 18, 2012 at 19:26, Harvey P. Dale <hpd1 at nyu.edu> wrote:

>        I would like guidance, and perhaps a consensus or rule, about
> whether and when to use "Quiet" in Mathematica programs in the OEIS.
>        Here's an example: A031795 lists numbers such that there are
> exactly 27 occurrences of the digit 1 in the period of the continued
> fraction of the square root of the number.  In Mathematica, it is easy
> to generate the terms of the period of the continued fraction --
> ContinuedFraction[Sqrt[n]][[2]] does that.  It is also easy to count the
> number of ones in that period, using Count.  The problem is that every
> number that is a perfect square causes an error message to be generated
> since there is no period of the continued fraction for the square root
> of a perfect square.
>        There are two ways to deal with this.  One is simply to wrap the
> Mathematica program inside "Quiet."  The second is to write a program
> that avoids the error messages, in this case by separately testing for
> perfect-square status.  I chose the latter for the program I submitted
> for A031795.


Good.


>  But there are two problems with this choice:
> (1) it makes the program more opaque to the readers of the OEIS and (2)
> it takes additional time to write such an error-code-avoiding program.
> (Indeed, in some instances I am not readily able to figure out how to
> avoid the error messages and so cannot easily write a program that
> avoids their generation.)
>

See my remarks below.


>        Using Quiet to eliminate the error messages, however, might be
> dangerous because some of the messages generated might be material,
> e.g., they might deal with precision errors or erroneous terms being
> generated.
>

For this, I would suggest, in cases where defensive programming is too
cumbersome, not to use Quiet[] but Off[]/On[] with the precise error
message generated so that other error messages would not be ignored.
But in your case, the error message you wanted to ignore is a structural
error, trying to extract an information that is not present. I think this
case require explicit precautions.


>        I would assume that no one would want to use Quiet when its
> effect might be to pollute the accuracy of the OEIS.  The question
> really is: if it appears clear that the error messages being generated
> are not of the dangerous variety, should Quiet be permitted in lieu of
> having to figure out and submit what will always be a more complex
> Mathematica program?
>

something like

Table[If[IntegerQ[Sqrt[n]], {}, ContinuedFraction[Sqrt[n]][[2]]], {n, 10}]

is certainly readable as readable as with Quiet. The trouble a casual
reader would have has more to do with the particular output of
ContinuedFraction
and the Part notation of Mathematica than with this initial test.

Another way is to write something this way:

Table[If[Length[#] > 1, #[[2]], {}] &@ContinuedFraction[Sqrt[n]], {n, 10}]


Olivier



More information about the SeqFan mailing list