1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/// Generate Lucas sequence up to n terms
///
/// The Lucas sequence is the companion to Fibonacci, using the same recurrence relation
/// L(n) = L(n-1) + L(n-2) but with different starting values: 2, 1 instead of 1, 1.
///
/// The sequence goes: 2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199...
///
/// Named after François Édouard Anatole Lucas (1842-1891), this sequence shares many
/// properties with Fibonacci but creates different intervallic relationships. Like Fibonacci,
/// the ratio between consecutive Lucas numbers converges to the golden ratio φ ≈ 1.618.
///
/// # Mathematical Properties
/// - L(n) = F(n-1) + F(n+1) where F is Fibonacci
/// - L(n)² = 5·F(n)² + 4·(-1)ⁿ (Lucas-Fibonacci identity)
/// - Used in primality testing (Lucas-Lehmer test)
/// - Appears in combinatorics and number theory
///
/// # Musical Character
/// Unlike Fibonacci's gradual 1→1→2→3 start, Lucas begins with 2→1→3→4, creating
/// larger initial jumps. This makes it excellent for:
/// - More dramatic melodic leaps early in the sequence
/// - Different harmonic series than Fibonacci
/// - Creating tension through larger intervals
///
/// # Arguments
/// * `n` - Number of Lucas terms to generate
///
/// # Returns
/// Vector of the first n Lucas numbers: [2, 1, 3, 4, 7, 11, 18, ...]
///
/// # Examples
/// ```
/// use tunes::sequences;
///
/// let lucas = sequences::lucas::generate(8);
/// assert_eq!(lucas, vec![2, 1, 3, 4, 7, 11, 18, 29]);
///
/// // Use for melodic intervals (semitones)
/// # use tunes::prelude::*;
/// # let mut comp = Composition::new(Tempo::new(120.0));
/// let base = 440.0; // A4
/// for (i, &interval) in lucas.iter().take(6).enumerate() {
/// let freq = base * 2.0_f32.powf(interval as f32 / 12.0);
/// comp.track("lucas_melody")
/// .at(i as f32 * 0.5)
/// .note(&[freq], 0.4);
/// }
///
/// // Use for phrase lengths (different from Fibonacci)
/// let phrase_lengths = sequences::lucas::generate(5); // [2, 1, 3, 4, 7] beats
/// ```
///
/// # Musical Applications
/// - **Melodic intervals**: Creates larger jumps than Fibonacci, more dramatic
/// - **Harmonic series**: Different overtone relationships
/// - **Phrase structure**: Alternative to Fibonacci for organic phrasing
/// - **Countermelody**: Use Lucas against Fibonacci for natural counterpoint
/// - **Rhythmic variation**: Note durations or rest lengths
/// - **Dynamic curves**: Volume envelopes with different shape than Fibonacci
///
/// # Comparison with Fibonacci
/// ```text
/// Fibonacci: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
/// Lucas: 2, 1, 3, 4, 7, 11, 18, 29, 47, 76
/// ↑ ↓ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
/// (Lucas starts higher, dips, then diverges upward)
/// ```
// ========== PRESETS ==========
/// Short Lucas sequence (6 terms)
/// Classic Lucas sequence (12 terms) - balanced length
/// Extended Lucas sequence (16 terms)