Saturday, 31 July 2010

ADDING HELP TO OEIS SEQUENCES

As I´m working on more than one small projects of programming sequences from The On-Line Encyclopedia of Integer Sequences, and as I always try to document my code the best I can: I like to add comments and help information to it, but after many hours of “copy and paste”, and being aware that when you are trying to do something with a computer: if you feel that everything is repetitive and boring, then it is for sure, that you are using the wrong procedure, so then, I decided to create a very simple tools to make my life easier.

The PHP code of these two on-line applications is almost the same than the one of OEIS2BibTeX, but this time changed to provide the help code for PARI/GP or Mathematica OEIS sequences functions.

Both applications can be used in two different ways:

* Entering the Sequence Id number with a HTML form: in a POST METHOD, or
* With the Id Number supplied to the PHP code within the link, using ?sequence=valid_ID



1) PARI/GP

1.1) HTML POST Method:
http://oeis2bibtex.netai.net/helpPARI_GP/

1.2) PHP Parameter:
http://oeis2bibtex.netai.net/helpPARI_GP/OEIS-PARI_GP-Help.php?sequence=A000200
Here you can change A000200 for the desired Sequence Id Number:


2) WOLFRAM MATHEMATICA

2.1) HTML POST Method:
http://oeis2bibtex.netai.net/helpMathematica/

2.2) PHP Parameter:
http://oeis2bibtex.netai.net/helpMathematica/OEIS-Mathematica-Help.php?sequence=A000200

2.3) Mathematica Code using Import:

As Mathematica can access on-line data, these functions can do the job too inside any Mathematica Notebook or Package:
OEISSequenceDescription[seq_String]:=Module[{dataloaded = StringJoin[Import["http://oeis.org/classic/?q=id%3a" <> seq <> "&fmt=3","Data"]], first, last},
first = Flatten[StringPosition[dataloaded, "%N"], 1][[2]];
last = Select[StringPosition[dataloaded, "%"][[All, 1]], # > first&][[1]];
StringReplace[StringTake[dataloaded, {first + 10, last - 1}], " " ~~ _ -> ""]]


OEISAddHelp[seq_String]:=ToExpression[StringJoin[seq, "::usage=\"",seq, ": ", OEISSequenceDescription[seq], "\""]]


Archives:
[a]-073110-Adding Help to OEIS Sequences.nb


References:

[1]-PARI/GP Development Headquarters - Programming in GP: other specific functions-addhelp
[2]-http://formatmysourcecode.blogspot.com/
[3]-Wolfram Mathematica Documentation Center: Import
[4]-E.PĂ©rez Herrero-OEIS Utilities Page@ OEIS Wiki

Sunday, 11 July 2010

TOTIENT CARNIVAL


Euler's totient function: $latex \phi(n)$ is defined as the number of positive integers less than or equal to $latex n$, that are coprime to $latex n$, and using Iverson bracket, $latex \phi$ can be written as: (See reference [1])


$latex \phi(n) =\sum_{i=1}^{n}{[gcd(i,n)=1]} $


MULTIPLICATIVE BUT NOT COMPLETELY MULTIPLICATIVE FUNCTIONS:

The above summatory can be expressed with the aid of non completely multiplicative arithmetical funcions, using the fact that, some functions hold for inequalities similar to this one:

$latex f(n \cdot m) < f(n) \cdot f(m);$ if $latex gcd(n,m)\neq 1$ And that also hold for the properties that any multiplicative function has: $latex f(n)>0$

$latex f(n \cdot m) = f(n) \cdot f(m);$ if $latex gcd(n,m)= 1$


Then:

$latex \phi(n)=\sum_{i=1}^{n}{\bigg\lfloor \frac{f(i \cdot n)}{f(i)\cdot \f(n)}\bigg\rfloor}$

And applying this idea to arithmetical functions of common use, we can give, for the divisor sigma functions, the Piltz divisor functions and the squarefree kernel [4], respectively:

$latex \phi(n)=\sum_{i=1}^{n}{\bigg\lfloor \frac{\sigma_{k}(i \cdot n)}{\sigma_{k}(i)\cdot \sigma_{k}(n)}\bigg\rfloor}$

$latex \phi(n)=\sum_{i=1}^{n}{\bigg\lfloor \frac{\tau_{k}(i \cdot n)}{\tau_{k}(i)\cdot \tau_{k}(n)}\bigg\rfloor}$

$latex \phi(n)=\sum_{i=1}^{n}{\bigg\lfloor \frac{rad(i \cdot n)}{rad(i)\cdot rad(n)}\bigg\rfloor}$

Or we can construct an implicit formula for the Totient function:

$latex \phi(n)=\sum_{i=1}^{n}{\bigg\lfloor \frac {\phi(i)\cdot \phi(n)}{\phi(i \cdot n)}\bigg\rfloor}$

But we must take care that now:

$latex f(n \cdot m) > f(n) \cdot f(m);$ if $latex gcd(n,m)\neq 1$

so we must invert the fraction inside the floor function.


ADDITIVE BUT NOT COMPLETELY ADDITIVE FUNCTIONS:

The same thing can be done with additive but not completely additive functions:

$latex \phi(n)=\sum_{i=1}^{n}{\bigg\lfloor \frac{\omega(i \cdot n)}{\omega(i) + \omega(n)}\bigg\rfloor} \; (n>1)$


OTHER FORMULAS:

This way of constructing new formulas, seems to be trivial and useless, but this is only an excuse to show how works the characteristic or indicator functions, that are underneath the behaviour of the arithmetical functions, and thus the basic Set Theory inside Number Theory.

And of course we can extend this collection of formulas to other functions distinct than $latex \phi$, like for example $latex \pi$ the Prime Counting Function:

$latex \pi(n)=\sum_{i=2}^{n}{\bigg\lfloor \frac{i+1}{\sigma_{1}(i)}\bigg\rfloor} \; (n>1)$

$latex \pi(n)=\sum_{i=2}^{n}{\bigg\lfloor \frac{\phi(i)}{i-1}\bigg\rfloor} \; (n>1)$

$latex \pi(n)=\sum_{i=2}^{n}{\bigg\lfloor \frac{2}{\tau(i)}\bigg\rfloor}=\sum_{i=2}^{n}{\bigg\lfloor \frac{k}{\tau_{k}(i)}\bigg\rfloor} \; (n>1)$



Archives:
[a]-071210-Totient Carnival.nb


References:

[1]-Peter Luschny - OEIS-Wiki: Sequences related to Euler's totient function.
[2]- N. J. A. Sloane, The On-Line Encyclopedia of Integer Sequences.
A000720: pi(n), the number of primes <= n. Sometimes called PrimePi(n) to distinguish it from the number 3.14159... [3]- N. J. A. Sloane, The On-Line Encyclopedia of Integer Sequences.
A000010: Euler totient function phi(n): count numbers <= n and prime to n. [4]- R. Muller, The On-Line Encyclopedia of Integer Sequences.
A007947: Largest squarefree number dividing n (the squarefree kernel of n)

Thursday, 13 May 2010

A SMALL FIBONACCI SUM

If $latex F_{n}$ is the nth Fibonacci Number then:


$latex \displaystyle \sum_{i=0}^{n}{i \cdot F_{2i}} = n \cdot F_{2n+1} - F_{2n}$


This identity can be easily proved using the method of induction with the basic recurrence relation of Fibonacci Numbers.

How can we find methods for constructing new identities like this one?


References:

[1]-Wikipedia - Fibonacci number
[2]-Chandra, Pravin and Weisstein, Eric W. "Fibonacci Number." From MathWorld--A Wolfram Web Resource - http://mathworld.wolfram.com/FibonacciNumber.html

Sunday, 14 February 2010

BibTeX AUTOMATIC OEIS CITATIONS



I've programmed a small web application in PHP to get automatically the BibTeX citation of any sequence in the The On-Line Encyclopedia of Integer Sequences.

If you follow this link: OEIS2BibTeX or just click on the above image, then you must enter the desired sequence ID to get the BibTeX citation data, that you can easily copy to your .bib file.

As I begun to learn PHP yesterday´s evening, and this is my first PHP programming, you can guess that this code must have more than one bug.

The citation is done using the @MISC BibTeX entry, that uses as Required fields: none, and as Optional fields: AUTHOR, TITLE, HOWPUBLISHED, MONTH, YEAR, NOTE.


The AUTHOR field contains the OEIS Sequence Author.

HOWPUBLISHED contains the url to the sequence in the OEIS Wiki, and it is assumed to be used with the $latex \LaTeX$ hyperref packages

MONTH and YEAR are not yet used, and the field NOTE includes the Description of the sequence.

If this small application is used in combination with the BibTeX2HTML it is very fast to reuse the same bibliography data in your web, or in your $latex \LaTeX$ document.

All the PHP archives can be downloaded and changed if desired.

The reference [1] is an example of how does the Plain format works.



References and Archives:
[1] Clark Kimberling. The On-Line Encyclopedia of Integer Sequences. A045051. Numbers n with property that in base 4 representation the numbers of 0's and 2's are 2 and 4, respectively.
[2] Andrew Roberts. Bibtex entry and field types. www.andy-roberts.net/misc/latex/sessions/bibtex/bibentries.pdf.
[3] Psychedelic Geometry.PHP file. OEIS2BibTeX.php.
[4] Psychedelic Geometry.PHP file. default.php, feb 2010.
[5] Psychedelic Geometry. OEIS2BibTeX web site. http://www.oeis2bibtex.netai.net/, feb 2010.


Sunday, 17 January 2010

READER'S CORNER (I)


A BINOMIAL PLAY:

Our contributor Raymond Rogers has sent an alternate proof for:

$latex \displaystyle det{\bigg[ \binom{i+j+k}{i} \bigg]}_{0\leq i,j \leq n} =\binom{n+k+1}{k+1}$

This expression is identical to the one found in the post Binomial Matrix (III), but here the matrices are indexed from zero instead of one.

The proof is entitled A BINOMIAL DETERMINATE,A VERY SHORT PLAY IN THREE ACTS, and it is based on Vandermonde's identity.

Thank you Raymond.



Archives:
[a]-120510-Binomial-Play-R.Rogers.pdf


Links:
[1]-Raymond Rogers, Lamm´s Equation, Confluent Hypergeometric Equations- Lamm´s Equation Blogspot

Saturday, 9 January 2010

BINARY BISECTION


INTRO:

The Bisection Method is a very well-known root-finding algorithm that always comes at the very beginning of every book on Numerical Analysis.

The algorithm searches for a root in the interval, $latex [a_{0},b_{0}]$ in whose endpoints the continuous problem function, $latex f(x)$, takes opposite signs:

$latex f(a_{0})f(b_{0})<0$ The Bisection Method is based on Bolzano's Intermediate Value Theorem, and it can give, also, an alternate proof for it. (Reference [1])

Here, it does not matter function values: The algorithm does not use any other information from $latex f(x)$, other than its sign changes.

There are excelent pages on the internet that deal with this topic, (references [1], [2] and [3] for example), and it would be useless to add more redundant and, for sure, worse presented summary about this numerical method.

I just want to take out something hidden inside the computer software, a small piece of math inside the programming area.

THE LOST FUNCTION

The core of the Bisection Method is the conditional IF... THEN... sentence, where the algorithm chooses in which half of the interval is the desired root.

This conditional evaluation can be converted into a decision function, Let's say $latex \delta_i$, gives $latex 0$ if the root is on the left half interval and $latex 1$, otherwise.

Now the iterative sequence can be rewritten using this function, $latex \delta_i$, where:

$latex m_{i}$ is the midpoint of the search interval:

$latex \displaystyle m_{i}=\frac{a_{i}+b_{i}}{2}$

$latex \delta_{i}$ is the decision function, and the $latex \delta(i,j)$, in the second member, is the Kronecker's delta:

$latex \delta_i=\delta(sgn(f(m_{i})),sgn(f(a_{i})))$

Then:

$latex \delta_{i} = \left\{ \begin{array}{ll} 1 & \mbox{if } (sgn(f(m_{i})=sgn(f(a_{i})) \\\\ 0 & \mbox{if } (sgn(f(m_{i})\neq sgn(f(a_{i})) \end{array}$


The endpoints of the search interval must be:

$latex {[a_{i+1}, b_{i+1}]} = \left\{ \begin{array}{ll} {[m_{i},b_{i}]} & \mbox{if }(\delta_{i}=0) \\\\ {[a_{i},m_{i}]} & \mbox{if } (\delta_{i}=1) \end{array}$

Then, they can be expressed with the aid of $latex \delta_{i}$, as:

$latex a_{i+1}=a_{i}+\delta_{i}\cdot (m_{i}-a_{i})$

$latex b_{i+1}=b_{i}+(1-\delta_{i})\cdot (m_{i}-b_{i})$

Note:
If $latex f(x)$, has only a single root in the interval $latex [a_{0},b_{0}]$, then it is possible to use an alternate version of the decision function:

$latex \delta_i=\delta(sgn(f(m_{i})),sgn(f(a_{0})))$

with the advantage that then it is not necessary to evaluate $latex f(a_{i})$ in the main loop of the algorithm: this implies an improvement in performance.



LENGTHS RATIO:

We can name lengths ratio between intervals $latex [a_{0},a_{i}]$, and $latex [a_{0},b_{0}]$, as the parameter:

$latex \theta_{i}=\frac{a_{i}-a_{0}}{b_{0}-a_{0}}$

If $latex \theta_{i}$ is expressed as a function of $latex \delta_{i}$:

$latex \displaystyle \theta_{i}=\sum_{k=0}^{i-1} \frac{\delta_{k}}{2^{k+1}}$

The sequence formed by the distinct values of the decision function, $latex \delta_{i}$, matches up with the binary expansion (or the binary digits) of $latex \theta_{i}$

Then the midpoint and the endpoints of the interval in function of $latex \theta_{i}$, are:

$latex a_{i}=a_{0}+(b_{0}-a_{0})\cdot \theta_{i}$

$latex \displaystyle m_{i}=a_{0}+(b_{0}-a_{0})\cdot \left(\theta_{i}+\frac{1}{2^{i+1}}\right)$

$latex \displaystyle b_{i}=a_{0}+(b_{0}-a_{0})\cdot \left(\theta_{i}+\frac{1}{2^{i}}\right)$


HACKING BISECTION METHOD:

The connection between $latex \delta_{i}$ and $latex \theta_{i}$ can be used to turn Bisection Method into a method to find the binary expansion of a root of any function that holds with theorem hypothesis.

For example if we take:

$latex f(x)=x^2-x_{0}$, where $latex x_{0}>0$

with $latex a_{0}=0$ and $latex b_{0}=2^{k}$, where $latex 2^{k-1} < \sqrt{x_{0}} < 2^{k}$, then: $latex \sqrt{x_{0}}=\lim_{i \to +\infty}{\theta_{i}}$ and the sequence of $latex \delta_{i}$ gives the binary digits of $latex \sqrt{x_{0}}$
Archives:
[a]-010910-Binary Bisection.nb


References:

[1]-Mohamed A. Khamsi, Helmut Knaust - SOSMATH - The Bisection Method
[2]-John H. Mathews - California State Univ. Fullerton - Module for The Bisection Method
[3]-Holistic Numerical Methods Institute- - Bisection Method: Nonlinear Equations