OFFSET
1,5
LINKS
G. C. Greubel, Table of n, a(n) for n = 1..19
FORMULA
a(n) = a(n-1) - 2*a(n-1) + a(n-3) + (a(n-1) - a(n-2))^2 + (a(n-2) - a(n-3))^2, with a(1) = a(2) = a(3) = 1.
MATHEMATICA
(* First program *)
a[n_]:= a[n]= If[n<4, 1, -a[n-1] +a[n-3] +(a[n-1] -a[n-2])^2 +(a[n-2] -a[n-3])^2];
Table[a[n], {n, 20}]
(* Second program *)
RecurrenceTable[{a[1]==a[2]==a[3]==1, a[n]==-a[n-1]+a[n-3]+(a[n-2]-a[n-1])^2+(a[n-2]-a[n-3])^2}, a, {n, 20}] (* Harvey P. Dale, Dec 18 2012 *)
PROG
(Magma)
function a(n) // a = A122592
if n lt 4 then return 1;
else return -a(n-1) +a(n-3) +(a(n-1) -a(n-2))^2 +(a(n-2) -a(n-3))^2;
end if; return a; end function;
[a(n): n in [1..18]]; // G. C. Greubel, Nov 29 2021
(Sage)
@CachedFunction
def a(n): return 1 if (n<4) else -a(n-1) +a(n-3) +(a(n-1) -a(n-2))^2 +(a(n-2) -a(n-3))^2 # a = A122592
[a(n) for n in (1..18)] # G. C. Greubel, Nov 29 2021
CROSSREFS
KEYWORD
nonn
AUTHOR
Roger L. Bagula, Sep 19 2006
EXTENSIONS
Edited by N. J. A. Sloane, Sep 21 2006
Definition corrected by Harvey P. Dale, Dec 18 2012
STATUS
approved