File: FactorRationals-oeis.t

package info (click to toggle)
libmath-planepath-perl 117-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,988 kB
  • ctags: 5,587
  • sloc: perl: 99,131; ansic: 299; sh: 233; lisp: 73; makefile: 4
file content (261 lines) | stat: -rw-r--r-- 6,890 bytes parent folder | download | duplicates (2)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/perl -w

# Copyright 2011, 2012, 2013, 2014 Kevin Ryde

# This file is part of Math-PlanePath.
#
# Math-PlanePath is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later
# version.
#
# Math-PlanePath is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.

use 5.004;
use strict;
use Test;
plan tests => 14;

use lib 't','xt';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings(); }
use MyOEIS;

use Math::PlanePath::FactorRationals;

# uncomment this to run the ### lines
#use Smart::Comments '###';


my $path = Math::PlanePath::FactorRationals->new;


#------------------------------------------------------------------------------
# A053985 - negabinary pos->pn
MyOEIS::compare_values
  (anum => 'A053985',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::FactorRationals;
     for (my $i = 0; @got < $count; $i++) {
       push @got, Math::PlanePath::FactorRationals::_pos_to_pn__negabinary($i);
     }
     return \@got;
   });

# A005351  pn(+ve) -> pos
MyOEIS::compare_values
  (anum => 'A005351',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::FactorRationals;
     for (my $i = 0; @got < $count; $i++) {
       push @got, Math::PlanePath::FactorRationals::_pn_to_pos__negabinary($i);
     }
     return \@got;
   });
# A039724  pn(+ve) -> pos, in binary
MyOEIS::compare_values
  (anum => 'A039724',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::FactorRationals;
     for (my $i = 0; @got < $count; $i++) {
       push @got, sprintf('%b', Math::PlanePath::FactorRationals::_pn_to_pos__negabinary($i));
     }
     return \@got;
   });

# A005352  pn(-ve) -> pos
MyOEIS::compare_values
  (anum => 'A005352',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::FactorRationals;
     for (my $i = -1; @got < $count; $i--) {
       push @got, Math::PlanePath::FactorRationals::_pn_to_pos__negabinary($i);
     }
     return \@got;
   });


#------------------------------------------------------------------------------
# A065620 - revbinary pos->pn
MyOEIS::compare_values
  (anum => 'A065620',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::FactorRationals;
     for (my $i = 1; @got < $count; $i++) {
       push @got, Math::PlanePath::FactorRationals::_pos_to_pn__revbinary($i);
     }
     return \@got;
   });

# A065621  pn(+ve) -> pos
MyOEIS::compare_values
  (anum => 'A065621',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::FactorRationals;
     for (my $i = 1; @got < $count; $i++) {
       push @got, Math::PlanePath::FactorRationals::_pn_to_pos__revbinary($i);
     }
     return \@got;
   });

# A048724  pn(-ve) -> pos        n XOR 2n
MyOEIS::compare_values
  (anum => 'A048724',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::FactorRationals;
     for (my $i = 0; @got < $count; $i--) {
       push @got, Math::PlanePath::FactorRationals::_pn_to_pos__revbinary($i);
     }
     return \@got;
   });


#------------------------------------------------------------------------------
# A072345 -- X or Y at N=2^k, being alternately 1 and 2^k

MyOEIS::compare_values
  (anum => 'A072345',
   func => sub {
     my ($count) = @_;
     my @got;
     for (my $n = 2; @got < $count; $n *= 2) {
       my ($x, $y) = $path->n_to_xy ($n);
       push @got, $x;
       # last unless @got < $count;
       # push @got, $y;
     }
     return\@got;
   });

MyOEIS::compare_values
  (anum => q{A072345},
   func => sub {
     my ($count) = @_;
     my @got;
     for (my $n = 1; @got < $count; $n *= 2) {
       my ($x, $y) = $path->n_to_xy ($n);
       push @got, $y;
     }
     return\@got;
   });

#------------------------------------------------------------------------------
# A011262 -- N at transpose Y/X, incr odd powers, decr even powers
# cf A011264 prime factorization decr odd powers, incr even powers

MyOEIS::compare_values
  (anum => 'A011262',
   func => sub {
     my ($count) = @_;
     my @got;
     for (my $n = $path->n_start; @got < $count; $n++) {
       my ($x, $y) = $path->n_to_xy ($n);
       ($x, $y) = ($y, $x);
       my $n = $path->xy_to_n ($x, $y);
       push @got, $n;
     }
     return\@got;
   });

sub calc_A011262 {
  my ($n) = @_;
  my $ret = 1;
  for (my $p = 2; $p <= $n; $p++) {
    if (($n % $p) == 0) {
      my $count = 0;
      while (($n % $p) == 0) {
        $n /= $p;
        $count++;
      }
      $count = ($count & 1 ? $count+1 : $count-1);
      # $count++;
      # $count ^= 1;
      # $count--;
      $ret *= $p ** $count;
    }
  }
  return $ret;
}
MyOEIS::compare_values
  (anum => 'A011262',
   func => sub {
     my ($count) = @_;
     my @got;
     for (my $n = $path->n_start; @got < $count; $n++) {
       push @got, calc_A011262($n);
     }
     return \@got;
   });

#------------------------------------------------------------------------------
# A102631 - n^2/squarefreekernel(n), is column at X=1

MyOEIS::compare_values
  (anum => 'A102631',
   func => sub {
     my ($count) = @_;
     my @got;
     for (my $y = 1; @got < $count; $y++) {
       push @got, $path->xy_to_n (1, $y);
     }
     return \@got;
   });

#------------------------------------------------------------------------------
# A060837 - permutation DiagonalRationals N -> FactorRationals N

MyOEIS::compare_values
  (anum => 'A060837',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::DiagonalRationals;
     my $columns = Math::PlanePath::DiagonalRationals->new;
     for (my $n = $path->n_start; @got < $count; $n++) {
       my ($x,$y) = $columns->n_to_xy ($n);
       push @got, $path->xy_to_n($x,$y);
     }
     return \@got;
   });


#------------------------------------------------------------------------------
# A071970 - permutation Stern a[i]/[ai+1] which is Calkin-Wilf N -> power N

MyOEIS::compare_values
  (anum => 'A071970',
   func => sub {
     my ($count) = @_;
     my @got;
     require Math::PlanePath::RationalsTree;
     my $sb = Math::PlanePath::RationalsTree->new (tree_type => 'CW');
     for (my $n = $path->n_start; @got < $count; $n++) {
       my ($x,$y) = $sb->n_to_xy ($n);
       push @got, $path->xy_to_n($x,$y);
     }
     return \@got;
   });


#------------------------------------------------------------------------------
exit 0;