SeqKind

it.grypho.scala.leonardo.scalar.SeqKind
enum SeqKind(val fnName: String, val a: Int, val b: Int, val p: Int, val q: Int)

Which linear recurrence a _Sequence denotes.

Every case is x(k) = p*x(k-1) + q*x(k-2) with its own seeds and coefficients, so there is one definition of the recurrence and the named variants are spellings of it:

kind seeds (a, b) (p, q) first terms
Fibonacci (0, 1) (1, 1) 0, 1, 1, 2, 3, 5, ...
Lucas (2, 1) (1, 1) 2, 1, 3, 4, 7, 11, ...
Pell (0, 1) (2, 1) 0, 1, 2, 5, 12, 29, ...
Jacobsthal (0, 1) (1, 2) 0, 1, 1, 3, 5, 11, ...

An enum-tagged node rather than parse-time aliases, which is the _Statistic/StatKind and _Comparison/CompareOp pattern. Desugaring lucas(n) into fib(n, 2, 1) — the dfact -> mfact route — would have been cheaper, but the sugar is lost on the way back: the user types lucas(10) and the REPL, and :save, answer fib(10, 2, 1). Acceptable for dfact; self-defeating for a family whose point is that the names are related. This way each name survives the round trip and the equivalence (lucas(n) = fib(n, 2, 1)) is a documented fact rather than a second implementation.

Attributes

Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Enum entries

case Fibonacci extends SeqKind
case Jacobsthal extends SeqKind
case Lucas extends SeqKind
case Pell extends SeqKind