Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * SeaDragon 0.59 (2012 Sept 18th)
- * By R.J. Cano, <aallggoorriitthhmmuuss@gmail.com>
- *
- * Program released under the terms of the GNU General public license 3.0 (GNU-GPL 3.0)
- *
- *
- *
- * << If people do not believe that mathematics is simple, it is only because
- * they do not realize how complicated life is. >>
- * --John von Neumann
- *
- *
- *
- *
- * Hint for authors and contributors about C programs:
- *
- * It is suggested when compiling C programs verify if it's written in an
- * acceptable way using a command like: "gcc -O2 -W -Wall my_oeis_program.c"
- *
- * (Thanks to: Joerg Arndt)
- *
- *
- *
- *
- * Important:
- *
- * Leak-bug feature still keept for research purposes, but it was partially fixed
- * reducing the leaks...
- *
- * by a factor of:
- * [leaks_prime/leaks](n)= ( n/4 + 1 + 1/(n-1) )
- * from:
- * leaks_prime(n)= ( (n+4)*(n-1) + 4 )/2
- * to:
- * leaks(n)= 2*(n-1);
- *
- * In other words, leaks were reduced from quadratic to linear according the work case.
- *
- * ( At purpose,the 8 bytes block size mentioned for the leaks, depends on machine specifications )
- *
- * Now assuming for certain machine a blocksize of 2 raised to "z", if you were ask to estimate for
- * which upper size "N" the program leaks when run an amount of 2 raised to "lambda" bytes, then you
- * should answer this: N= ( 2 raised to (lambda-z-1) ) plus 1;
- *
- * As straightforward as it sounds... (Of course it have sense only for "lambda" greater than "z")
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- /*---------> non-standard datatype definitions <-----------------------------------------------------------*/
- typedef struct matrix_linear_stack {
- long integer_value;
- struct matrix_linear_stack *arrow;
- } matrix_linear_stack;
- /*---------> non-standard constant values definition <------------------------------------------------------*/
- const long __mode_ZERO = 0;
- const long __mode_EQUAL = 1;
- const long __mode_DETERMINANT = 2;
- const long __TOKEN_TEMPLATE = 0;
- const long __UNIT = 1;
- long generator_settings = 0;
- long __config_generator[3][2];
- /*---------> Suitable globals <-----------------------------------------------------------------------------*/
- matrix_linear_stack *__the_ring_stckPointerReference_HEAD, *__the_ring_stckPointerReference_TAIL;
- // About the ring:
- // Warning: After calling close__the_ring() a first time, don't call it again before a call to open_the_ring() of course
- // for the same parameter list (Else it would have possible harmful and unpredictible consequences).
- /*---------> non-standards called by main(); <-----------------------------------------------------*/
- void configure_modes(void);
- void runSequencer(int, long);
- /*---------> non-standards called by others; <-----------------------------------------------------*/
- void finalizer_matrix(matrix_linear_stack **, matrix_linear_stack**);
- void print_matrix(matrix_linear_stack **);
- void myTryfor_SteinhausJohnsonTrotterAlgorithm(matrix_linear_stack**, matrix_linear_stack**, long);
- void mode_matrix_waterfall(void);
- matrix_linear_stack* generate_square_matrix(matrix_linear_stack**, matrix_linear_stack**, matrix_linear_stack**, matrix_linear_stack**, long);
- void initializer_matrix(matrix_linear_stack **, matrix_linear_stack**);
- matrix_linear_stack* extract_first_nodes(matrix_linear_stack**, matrix_linear_stack**, long);
- void concat_matrices_node_by_node(matrix_linear_stack**, matrix_linear_stack**, matrix_linear_stack**);
- /*---------> additional non-standards (some of them called by more than one function); <-----------------------------------------------------*/
- long only_initialized(matrix_linear_stack**);
- long absolute_value(long);
- matrix_linear_stack* insert_new_node(long, matrix_linear_stack**);
- void close__the_ring(matrix_linear_stack**, matrix_linear_stack**);
- void open_the_ring(matrix_linear_stack**, matrix_linear_stack**);
- long LeibnitzLaplaceSignature(long);
- /*------------------------------------------------------------------------------------------------------------------------------*/
- int main(void) {
- int j, _OScurrentExecutionFeedbackCode = EXIT_SUCCESS;
- long N;
- configure_modes(); // Don't change this, it is for initialization.
- printf("%s%s","\n\nDemonstration program: ", "\n\n\tShould be run the sequencer only for a particular SJT-array? (1=yes, 0=No) ");
- scanf("%i", &j);
- getchar();
- printf("%s","\n\n\tWhich is the upper size? (try first 1-11 on 32-bit machines): ");
- scanf("%li", &N);
- getchar();
- runSequencer(j, N);
- return _OScurrentExecutionFeedbackCode;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void configure_modes(void) {
- __config_generator[__mode_ZERO][__TOKEN_TEMPLATE] = 0;
- __config_generator[__mode_ZERO][__UNIT] = 0;
- __config_generator[__mode_EQUAL][__TOKEN_TEMPLATE] = 0;
- __config_generator[__mode_EQUAL][__UNIT] = 1;
- __config_generator[__mode_DETERMINANT][__TOKEN_TEMPLATE] = 1;
- __config_generator[__mode_DETERMINANT][__UNIT] = 0;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void runSequencer(int just_for_the_Nth_array, long N) {
- long k;
- matrix_linear_stack *J0_head, *J0_tail;
- for (k=(just_for_the_Nth_array ? N : 1);k<=N;k++) {
- myTryfor_SteinhausJohnsonTrotterAlgorithm(&J0_head, &J0_tail, k);
- print_matrix(&J0_head);
- finalizer_matrix(&J0_head, &J0_tail);
- }
- printf("\n\n\tSequencer execution completed successfully.\n");
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void finalizer_matrix(matrix_linear_stack **stckPointerReference_HEAD, matrix_linear_stack **stckPointerReference_TAIL) {
- while (*stckPointerReference_HEAD != NULL) {
- (*stckPointerReference_TAIL) = (*stckPointerReference_HEAD);
- (*stckPointerReference_HEAD) = (*stckPointerReference_HEAD)->arrow;
- free( *stckPointerReference_TAIL );
- }
- (*stckPointerReference_TAIL) = NULL;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void print_matrix(matrix_linear_stack **stckPointerReference_HEAD) {
- matrix_linear_stack* focus= *stckPointerReference_HEAD;
- if ( NULL == focus ) {
- printf(" Not initialized! ");
- } else {
- if ( -1 == (focus->integer_value) ) {
- focus = focus->arrow;
- if ( NULL == focus ) {
- printf(" initialized but empty. ");
- } else {;}
- } else {
- }
- while ( NULL != focus ) {
- printf("\n%li", (focus->integer_value) );
- focus = focus->arrow;
- }
- }
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void myTryfor_SteinhausJohnsonTrotterAlgorithm(matrix_linear_stack **J_head, matrix_linear_stack **J_tail, long _SIZE) {
- matrix_linear_stack *JJ_head;
- matrix_linear_stack *JJ_tail;
- matrix_linear_stack *P_head;
- matrix_linear_stack *P_tail;
- matrix_linear_stack *Q_head;
- matrix_linear_stack *Q_tail;
- long diagonal;
- long _CASE = 1;
- mode_matrix_waterfall();
- generate_square_matrix(NULL, NULL, J_head, J_tail, 1);
- while (_CASE < _SIZE) {
- _CASE++;
- diagonal = -1;
- initializer_matrix(&JJ_head, &JJ_tail);
- while ( !only_initialized(J_head) ) {
- P_head = extract_first_nodes(J_head, &P_tail, (_CASE-1)) ;
- generate_square_matrix(&P_head, &P_tail, &Q_head, &Q_tail, _CASE*diagonal);
- concat_matrices_node_by_node(&JJ_tail, &Q_head, &Q_tail);
- finalizer_matrix(&P_head, &P_tail);
- diagonal *= -1;
- }
- /*
- * This lines fixes partially the leakage.
- */
- finalizer_matrix(J_head, J_tail);
- /**/
- *J_head = JJ_head;
- *J_tail = JJ_tail;
- JJ_head = NULL;
- JJ_tail = NULL;
- }
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void mode_matrix_waterfall(void) {
- generator_settings = __mode_DETERMINANT;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- matrix_linear_stack* generate_square_matrix(matrix_linear_stack **baseRef_head, matrix_linear_stack **baseRef_tail, matrix_linear_stack **ref_answer_head, matrix_linear_stack **ref_answer_tail, long TOKEN_TEMPLATE) {
- long counting_L = 1;
- long counting_X = 1;
- long counting_Y = 1;
- long matrix_size = absolute_value(TOKEN_TEMPLATE);
- long newValuetobeIncluded;
- matrix_linear_stack *BASE_head, *BASE_tail;
- if ( ( (baseRef_head) == (baseRef_tail) ) && ( NULL == (baseRef_head) ) ) {
- initializer_matrix(&BASE_head, &BASE_tail);
- insert_new_node(0, &BASE_tail);
- } else if ( (baseRef_head != NULL) && (baseRef_tail != NULL) ) {
- BASE_head = *baseRef_head;
- BASE_tail = *baseRef_tail;
- } else {
- return NULL;
- }
- close__the_ring(&BASE_head, &BASE_tail);
- initializer_matrix(ref_answer_head, ref_answer_tail);
- matrix_size = absolute_value(TOKEN_TEMPLATE);
- while (counting_L <= (matrix_size*matrix_size)) {
- if (BASE_head->integer_value == -1) { BASE_head = BASE_head->arrow; }
- newValuetobeIncluded = (TOKEN_TEMPLATE < 0) ? ( ( counting_X + counting_Y == (matrix_size+1) ) ? (matrix_size*__config_generator[generator_settings][__TOKEN_TEMPLATE] + __config_generator[generator_settings][__UNIT]) : (0) ) : ( (counting_X - counting_Y == 0) ? (matrix_size*__config_generator[generator_settings][__TOKEN_TEMPLATE] + __config_generator[generator_settings][__UNIT]) : (0) );
- if ( ( 0 == newValuetobeIncluded ) && ( __mode_ZERO != generator_settings) ) {
- newValuetobeIncluded+= (BASE_head->integer_value);
- BASE_head = BASE_head->arrow;
- }
- insert_new_node(newValuetobeIncluded, ref_answer_tail);
- counting_L++;
- counting_X++;
- if (counting_X > matrix_size) {
- counting_X = 1;
- counting_Y++;
- }
- }
- open_the_ring(&BASE_head, &BASE_tail);
- return (*ref_answer_head);
- }
- /*----------------------------------------------------------------------------------------------------------------------(OJO)---*/
- void initializer_matrix(matrix_linear_stack **stckPointerReference_HEAD, matrix_linear_stack **stckPointerReference_TAIL) {
- (*stckPointerReference_HEAD) = NULL;
- (*stckPointerReference_TAIL) = insert_new_node( -1, stckPointerReference_HEAD );
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- matrix_linear_stack* extract_first_nodes(matrix_linear_stack** ref_from_source, matrix_linear_stack** stckPointerReference_TAIL, long arg_howmanymustbe) {
- long counting = 1;
- long howmanymustbe = ( 0 == arg_howmanymustbe ) ? 1 : arg_howmanymustbe;
- matrix_linear_stack *focus = (*ref_from_source)->arrow;
- matrix_linear_stack *answer;
- initializer_matrix(&answer, stckPointerReference_TAIL);
- while ( counting < howmanymustbe ) {
- focus = focus->arrow;
- counting++;
- }
- (*stckPointerReference_TAIL)->arrow = (*ref_from_source)->arrow;
- (*ref_from_source)->arrow = focus->arrow;
- focus->arrow = NULL;
- (*stckPointerReference_TAIL) = focus;
- return answer;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void concat_matrices_node_by_node(matrix_linear_stack **operand_left_tail, matrix_linear_stack **operand_right_head, matrix_linear_stack **operand_right_tail) {
- matrix_linear_stack *slayer = *operand_right_head;
- *operand_right_head = NULL;
- (*operand_left_tail)->arrow = slayer->arrow;
- slayer->arrow = NULL;
- free(slayer);
- *operand_left_tail = *operand_right_tail;
- *operand_right_tail = NULL;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- long only_initialized(matrix_linear_stack** stckPointerReference_HEAD) {
- if ( 0 != ( NULL != stckPointerReference_HEAD ) ) {
- if ( 0 != ( NULL != *stckPointerReference_HEAD ) ) {
- if ( 0 != ( NULL == (*stckPointerReference_HEAD)->arrow ) ) {
- if ( -1 == (*stckPointerReference_HEAD)->integer_value ) {
- return 1;
- }
- }
- }
- }
- return 0;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- long absolute_value(long argument) {
- return ( argument * LeibnitzLaplaceSignature(argument) );
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- matrix_linear_stack* insert_new_node(long value_assigned, matrix_linear_stack **stckPointerReference_TAIL) {
- matrix_linear_stack *focus;
- matrix_linear_stack *inserto = (matrix_linear_stack *)( malloc( sizeof( matrix_linear_stack ) ) );
- matrix_linear_stack *answer_ref = inserto;
- inserto->integer_value = value_assigned;
- inserto->arrow = NULL;
- if (( NULL == (*stckPointerReference_TAIL) ) && (-1 == value_assigned)) {
- (*stckPointerReference_TAIL) = inserto;
- } else if ( NULL != (*stckPointerReference_TAIL) ) {
- focus = (*stckPointerReference_TAIL);
- while ( NULL != focus->arrow ) { focus = focus->arrow; }
- focus->arrow = inserto;
- if ( focus == (*stckPointerReference_TAIL) ) { (*stckPointerReference_TAIL) = inserto; }
- }
- return answer_ref;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void close__the_ring(matrix_linear_stack** stckPointerReference_HEAD, matrix_linear_stack** stckPointerReference_TAIL) {
- __the_ring_stckPointerReference_HEAD = *stckPointerReference_HEAD;
- __the_ring_stckPointerReference_TAIL = *stckPointerReference_TAIL;
- (*stckPointerReference_TAIL)->arrow = *stckPointerReference_HEAD;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- void open_the_ring(matrix_linear_stack** stckPointerReference_HEAD, matrix_linear_stack** stckPointerReference_TAIL) {
- (*stckPointerReference_HEAD) = __the_ring_stckPointerReference_HEAD;
- (*stckPointerReference_TAIL) = __the_ring_stckPointerReference_TAIL;
- (*stckPointerReference_TAIL)->arrow = NULL;
- }
- /*------------------------------------------------------------------------------------------------------------------------------*/
- long LeibnitzLaplaceSignature(long argument) {
- long answer;
- answer = (argument < 0) ? (-1) : (1) ;
- return answer;
- }
- /*===============================================> "The End" <===================================================================
- *
- * Below is a sample output, run from the author's machine:
- *
- *-------------------------------------------------------------------------------------------------------------------------------
- rjcano@seadragon:~/oeis-experiments$ g++ -x c -O2 -Wall ./seadragon_v049.c && ./a.out
- Demonstration program:
- Should be run the sequencer only for a particular SJT-array? (1=yes, 0=No) 0
- Which is the upper size? (try first 1-11 on 32-bit machines): 10
- .
- .
- .
- 2
- 1
- 3
- 4
- 5
- 6
- 7
- 8
- 10
- 9
- 2
- 1
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Sequencer execution completed successfully.
- Memory usage summary: heap total: 359036024, heap peak: 290304264, stack peak: 728
- total calls total memory failed calls
- malloc| 44879439 359035512 0
- realloc| 2 512 0 (nomove:0, dec:0, free:0)
- calloc| 0 0 0
- free| 44879421 359035864
- Histogram for block sizes:
- 0-15 44879439 4% ==================================================
- 256-271 2 <1%
- rjcano@seadragon:~/oeis-experiments$ uname -a
- Linux seadragon 3.2.28-smp #2 SMP Thu Aug 23 12:58:19 CDT 2012 i686 Genuine Intel(R) CPU N270 @ 1.60GHz GenuineIntel GNU/Linux
- rjcano@seadragon:~/oeis-experiments$ g++ -v
- Reading specs from /usr/lib/gcc/i486-slackware-linux/4.7.1/specs
- COLLECT_GCC=g++
- COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-slackware-linux/4.7.1/lto-wrapper
- Target: i486-slackware-linux
- Configured with: ../gcc-4.7.1/configure --prefix=/usr --libdir=/usr/lib --mandir=/usr/man --infodir=/usr/info --enable-shared --enable-bootstrap --enable-languages=ada,c,c++,fortran,go,java,lto,objc --enable-threads=posix --enable-checking=release --enable-objc-gc --with-system-zlib --with-python-dir=/lib/python2.7/site-packages --disable-libunwind-exceptions --enable-__cxa_atexit --enable-libssp --enable-lto --with-gnu-ld --verbose --enable-java-home --with-java-home=/usr/lib/jvm/jre --with-jvm-root-dir=/usr/lib/jvm --with-jvm-jar-dir=/usr/lib/jvm/jvm-exports --with-arch-directory=i386 --with-antlr-jar=/root/slackware-current/source/d/gcc/antlr-runtime-3.4.jar --enable-java-awt=gtk --disable-gtktest --with-arch=i486 --target=i486-slackware-linux --build=i486-slackware-linux --host=i486-slackware-linux
- Thread model: posix
- gcc version 4.7.1 (GCC)
- rjcano@seadragon:~/oeis-experiments$ memusage -V
- memusage (GNU libc) 2.15
- Copyright (C) 2012 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Written by Ulrich Drepper.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement