Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.6K Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:
GROUPS:

Calculate John Conway's Subprime Fibs with a RecurrenceTable?

Posted 10 years ago
POSTED BY: stephen Morris

The problem is in PrimeQ[] PrimeQ[a] when a is symbol (or anything that is not a prime) immediately returns False, although if its argument is a[n+1]+a[n] which is a symbolic expression. Therefore your SD function return for the first iteration the value 5 (Divisors[5] returns {1,5} so Divisors[5][[2]] is 5) and the result of the first element is 1 What you need to do is to replace SD with another function that will not return immediately a value when a symbolic expression is given as its input option 1

SD[x_] :=(*smallest divisor not equal to x*) 
  If[Length[Divisors[x]] <= 2, 1, Divisors[x][[2]]];
SS[x_] :=(*x if prime,otherwise x/smallest prime factor of x*)
  x/SD[x];
S[x_, y_] := 
 SS[x + y] (*x+y devided by it's smallest factor,or itself if prime*)
\
RecurrenceTable[{a[n + 2] == S[a[n + 1], a[n]], a[1] == 2, 
  a[2] == 3}, a, {n, 10}]

and option 2

SD[x_Integer] :=(*smallest divisor not equal to x*) 
  If[x == 1 || PrimeQ[x], 1, Divisors[x][[2]]];
SS[x_] :=(*x if prime,otherwise x/smallest prime factor of x*)
  x/SD[x];
S[x_, y_] := 
 SS[x + y] (*x+y devided by it's smallest factor,or itself if prime*)
\
RecurrenceTable[{a[n + 2] == S[a[n + 1], a[n]], a[1] == 2, 
  a[2] == 3}, a, {n, 10}]

Notice that in both cases only SD is changed (since the problem is with PrimeQ In person, I prefer the second solution best yehuda

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard