├── csv ├── mathsconstants ├── fundamental ├── Fundamental Overview.doc ├── fundrun ├── csv.h ├── gdbinit ├── utils.h ├── defs.h ├── Makefile ├── do_sum.h ├── constants ├── utils.c ├── fundamental_config.h ├── factor_test.c ├── fundamental_config_booleanadder.h ├── fundamental_config_exp.h ├── fundamental_config_factorfloat.h ├── fundamental_config_real_hunter.h ├── fundamental_config_new.h ├── fundamental_sanity.h ├── fundamental_config_factorint.h ├── fundamental_config_gemstone.h ├── fundamental_config_gemstone2.h ├── discoveries.txt ├── csv.c ├── fundtest.c ├── do_sum.c ├── print_sum.c ├── simplify.c ├── list.h ├── fundamental.h ├── LICENSE ├── README.md └── fundamental.c /csv: -------------------------------------------------------------------------------- 1 | 1,2,0,3 2 | 0,2,3,5 3 | 0,3,2,5 4 | 4,5,0,9 -------------------------------------------------------------------------------- /mathsconstants: -------------------------------------------------------------------------------- 1 | m pi 3.14159265 2 | m e 2.718281828 3 | 4 | -------------------------------------------------------------------------------- /fundamental: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djbarrow/fundamental/HEAD/fundamental -------------------------------------------------------------------------------- /Fundamental Overview.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djbarrow/fundamental/HEAD/Fundamental Overview.doc -------------------------------------------------------------------------------- /fundrun: -------------------------------------------------------------------------------- 1 | #set args -h 2 -m 8 -s 0 0 10 2 | #set args -h 3 -m 8 -s 5 5 3 | fundamental -h 5 -m 10 -s 30 4 | set args -h 3 -m 10 -s 8 -e 0.05 5 | -------------------------------------------------------------------------------- /csv.h: -------------------------------------------------------------------------------- 1 | #include 2 | off_t getfilelen(int fd); 3 | void parselines(char *buff,off_t len,char ***lines,int *numlines); 4 | void readreals(char *filename); 5 | -------------------------------------------------------------------------------- /gdbinit: -------------------------------------------------------------------------------- 1 | #set args -h 2 -m 8 -s 0 0 10 2 | #set args -h 3 -m 8 -s 5 5 3 | #set args -h 5 -m 30 -r 4 -s 30 4 | #set args -h 3 -m 10 -s 8 -e 0.05 5 | #set args -h 8 -m 40 -r 6 -s 300 6 | #set args -h 8 -m 10 -f 0 0 6 three_seq 7 | set args -h 8 -m 8 -c playconstants -f 0 3 5 PentG2TXT1+2.txt 8 | #set args -h 8 -m 8 -c playconstants 9 | -------------------------------------------------------------------------------- /utils.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #define TRUE (1) 6 | #define FALSE (0) 7 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 8 | #include 9 | #include 10 | #include 11 | extern int debug; 12 | extern void exit_error(char *format,...); 13 | extern void *myalloc(char *str,size_t size); 14 | extern void debug_printf(char *format,...); 15 | -------------------------------------------------------------------------------- /defs.h: -------------------------------------------------------------------------------- 1 | #ifndef offsetof 2 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 3 | #endif 4 | #ifndef MAX 5 | #define MAX(a,b) ((a)>(b) ? (a):(b)) 6 | #endif 7 | #ifndef MIN 8 | #define MIN(a,b) ((a)<=(b) ? (a):(b)) 9 | #endif 10 | #ifndef TRUE 11 | #define TRUE (1) 12 | #endif 13 | #ifndef FALSE 14 | #define FALSE (0) 15 | #endif 16 | #ifndef NULL 17 | #define NULL ((void *)0) 18 | #endif 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #CC=gcc33 2 | CC=gcc 3 | #CC=clang-14 4 | OBJFILES = \ 5 | fundamental.o \ 6 | do_sum.o \ 7 | utils.o \ 8 | print_sum.o \ 9 | fundtest.o \ 10 | csv.o \ 11 | simplify.o 12 | #fundtest.o 13 | #factor_test.o 14 | 15 | 16 | CFLAGS= -g -DLINUX 17 | #CFLAGS=-O2 -g 18 | LINKFLAGS = 19 | LIBS = -lm 20 | 21 | 22 | 23 | %.o: %.c fundamental.h fundamental_config.h fundamental_sanity.h do_sum.h Makefile 24 | $(CC) -c $(CFLAGS) -o $@ $< 25 | 26 | fundamental: $(OBJFILES) 27 | $(CC) $(CFLAGS) $(LINKFLAGS) $(OBJFILES) $(LIBS) -o $@ 28 | 29 | clean: 30 | rm -f $(OBJFILES) *~ t1 *.i fundamental 31 | -------------------------------------------------------------------------------- /do_sum.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of fundamental a brute force searcher 3 | for relationships between constants & formulae for sequences. 4 | It is a header for the reverse polish notation RPN calculation 5 | code in the project. 6 | Copyright (C) 2018 D.J. Barrow dj_barrow@ariasoft.ie barrow_dj@yahoo.com 7 | 8 | It is licensed under GPL v2.1 9 | */ 10 | #ifdef HAVE_GCD_OP 11 | uint_t euclid_calc_gcd(uint_t x,uint_t y); 12 | #endif 13 | #ifdef HAVE_FACTORIAL_OP 14 | void init_factorials(); 15 | #endif 16 | #ifdef HAVE_BINARY_OPERATORS 17 | int do_binary_sum(number_t *result_ptr,number_t *operand,stack_entry *curr); 18 | #endif 19 | int do_sum(number_t **result_stack_head_ptrptr,stack_entry *curr); 20 | -------------------------------------------------------------------------------- /constants: -------------------------------------------------------------------------------- 1 | m semitone_multiple 1.05946309436 2 | p fine_structure_constant 0.00729735 3 | m pi 3.14159265 4 | m e 2.718281828 5 | m golden_ratio 1.61803398875 6 | p speed_of_light 2.99792458e+8 7 | p magnetic_constant 1.25663706144e-6 8 | p electric_constant 8.854187817e-12 9 | p charge_of_electron 1.60217733e+19 10 | p mass_of_electron 9.1093897e-31 11 | p mass_of_proton 1.6726231e-27 12 | p mass_of_neutron 1.674929e-27 13 | p mass_of_muon 1.883531627e-28 14 | p electronic_radius 2.81794092e-15 15 | p planck_constant 6.626076e-34 16 | p avodagro_constant 6.0221367e+23 17 | p loschmidt_constant 2.686736e+25 18 | p molar_gas_constant 8.314510 19 | p faraday_constant 9.6484531e+4 20 | p stefan_boltzmann_constant 5.67051e+8 21 | p rydberg_constant 1.0973731534e+7 22 | p gravitational_constant 6.67259e+11 23 | p acceleration_due_to_gravity 9.80665 24 | 25 | -------------------------------------------------------------------------------- /utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of fundamental a brute force searcher 3 | for relationships between constants & formulae for sequences. 4 | Copyright (C) 2004 D.J. Barrow dj_barrow@ariasoft.ie barrow_dj@yahoo.com 5 | 6 | It is licensed under GPL v2.1. 7 | */ 8 | #include 9 | #include "utils.h" 10 | 11 | int debug=FALSE; 12 | void exit_error(char *format,...) 13 | { 14 | va_list ap; 15 | 16 | va_start(ap,format); 17 | vfprintf(stderr,format,ap); 18 | va_end(ap); 19 | exit(-1); 20 | } 21 | 22 | 23 | void *myalloc(char *str,size_t size) 24 | { 25 | void *retval=(void *)malloc(size); 26 | if(!retval) 27 | exit_error("ran out of memory allocating %s\n",str); 28 | return(retval); 29 | } 30 | 31 | 32 | 33 | 34 | void debug_printf(char *format,...) 35 | { 36 | va_list ap; 37 | 38 | if(debug) 39 | { 40 | va_start(ap,format); 41 | vfprintf(stdout,format,ap); 42 | vfprintf(stdout,"\n",ap); 43 | va_end(ap); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /fundamental_config.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | #define HAVE_FACTORIAL_OP 4 | //#define HAVE_ABS_OP 5 | //#define HAVE_FLOOR_OP 6 | //#define HAVE_CEIL_OP 7 | //#define HAVE_RINT_OP 8 | #define HAVE_SIN_OP 9 | //#define HAVE_COS_OP 10 | //#define HAVE_TAN_OP 11 | //#define HAVE_ONES_COMPLIMENT_OP 12 | //#define HAVE_NOT_OP 13 | #define HAVE_ADDITION_OP 14 | //#define HAVE_SUBTRACTION_OP 15 | #define HAVE_MULTIPLY_OP 16 | #define HAVE_DIVIDE_OP 17 | //#define HAVE_POWER_OP 18 | //#define HAVE_MODULO_OP 19 | //#define HAVE_AND_OP 20 | //#define HAVE_OR_OP 21 | //#define HAVE_XOR_OP 22 | //#define HAVE_LOG_SHIFT_OP 23 | //#define HAVE_LOG_RSHIFT_OP 24 | //#define HAVE_LOG_LSHIFT_OP 25 | //#define HAVE_ARITH_SHIFT_OP 26 | //#define HAVE_ROTATE_OP 27 | //#define HAVE_LROTATE_OP 28 | //#define HAVE_RROTATE_OP 29 | //#define HAVE_MASK_OP 30 | //#define HAVE_GETBIT_OP 31 | //#define HAVE_LN_OP 32 | //#define HAVE_GCD_OP 33 | //#define HAVE_EQ_COND 34 | //#define HAVE_GT_COND 35 | //#define HAVE_GE_COND 36 | //#define HAVE_LT_COND 37 | //#define HAVE_LE_COND 38 | //#define HAVE_AND_COND 39 | //#define HAVE_OR_COND 40 | //#define HAVE_MIN_OP 41 | //#define HAVE_MAX_OP 42 | 43 | 44 | /* General operation characteristics */ 45 | #define SEQUENCE_HUNTER 46 | #define NUM_SEQUENCE_DIMENSIONS (1) 47 | //#define REAL_HUNTER 48 | //#define HAVE_FUNCTIONS 49 | //#define NUM_HUNTER_DIMENSIONS (3) 50 | //#define NUM_INTEGER_BITS (32) 51 | //#define HAVE_CONSTANTS_FILE 52 | #define HAVE_PRINT_SUM_INFIX 53 | #define HAVE_PRINT_SUM_RPN 54 | //#define SIGNED_OPERATION 55 | //#define MULTIPLE_RESULTS 56 | //#define SEED (1) 57 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 58 | #define NUM_ANSWERS (1) 59 | //#define ERROR_OP rint 60 | //#define HAVE_PROGRESS 61 | //#define SPARSE_ARRAY_INDICES 62 | //#define HAVE_ABS_ERROR 63 | -------------------------------------------------------------------------------- /factor_test.c: -------------------------------------------------------------------------------- 1 | #include "fundamental.h" 2 | #define MAX_N_FACTORS 128 3 | typedef unsigned long long uintmax_t; 4 | 5 | static int factor (uintmax_t n0, int max_n_factors, uintmax_t *factors) 6 | { 7 | register uintmax_t n = n0, d, q; 8 | int n_factors = 0; 9 | 10 | if (n < 1) 11 | return n_factors; 12 | 13 | while (n % 2 == 0) 14 | { 15 | assert (n_factors < max_n_factors); 16 | factors[n_factors++] = 2; 17 | n /= 2; 18 | } 19 | 20 | /* The exit condition in the following loop is correct because 21 | any time it is tested one of these 3 conditions holds: 22 | (1) d divides n 23 | (2) n is prime 24 | (3) n is composite but has no factors less than d. 25 | If (1) or (2) obviously the right thing happens. 26 | If (3), then since n is composite it is >= d^2. */ 27 | 28 | d = 3; 29 | do 30 | { 31 | q = n / d; 32 | while (n == q * d) 33 | { 34 | assert (n_factors < max_n_factors); 35 | factors[n_factors++] = d; 36 | n = q; 37 | q = n / d; 38 | } 39 | d += 2; 40 | } 41 | while (d <= q); 42 | 43 | if (n != 1 || n0 == 1) 44 | { 45 | assert (n_factors < max_n_factors); 46 | factors[n_factors++] = n; 47 | } 48 | 49 | return n_factors; 50 | } 51 | 52 | #if 1 53 | #if NUM_SEQUENCE_DIMENSIONS!=1 || !defined(MULTIPLE_RESULTS) 54 | #error "Bad factorisation configuration" 55 | #endif 56 | int sequence_func(result_t *retnums,dimension_t *array_indices) 57 | { 58 | uintmax_t factors[MAX_N_FACTORS]; 59 | int i,n_factors; 60 | n_factors = factor ((uintmax_t)array_indices[0], MAX_N_FACTORS, factors); 61 | #ifdef SPARSE_ARRAY_INDICES 62 | #if NUM_ANSWERS!=2 63 | #error "NUM_ANSWERS defined wrong" 64 | #endif 65 | if(n_factors==2) 66 | *retnums=alloc_result(); 67 | else 68 | { 69 | *retnums=NULL; 70 | return 0; 71 | } 72 | #else 73 | *retnums=alloc_result(n_factors); 74 | #endif 75 | for(i=0;ianswer[i]=(number_t)factors[i]; 77 | return 0; 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /fundamental_config_booleanadder.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | //#define HAVE_FACTORIAL_OP 4 | //#define HAVE_ABS_OP 5 | //#define HAVE_FLOOR_OP 6 | //#define HAVE_CEIL_OP 7 | //#define HAVE_RINT_OP 8 | //#define HAVE_SIN_OP 9 | //#define HAVE_COS_OP 10 | //#define HAVE_TAN_OP 11 | //#define HAVE_ONES_COMPLIMENT_OP 12 | //#define HAVE_NOT_OP 13 | //#define HAVE_ADDITION_OP 14 | //#define HAVE_SUBTRACTION_OP 15 | //#define HAVE_MULTIPLY_OP 16 | //#define HAVE_DIVIDE_OP 17 | //#define HAVE_POWER_OP 18 | #define HAVE_MODULO_OP 19 | #define HAVE_AND_OP 20 | #define HAVE_OR_OP 21 | #define HAVE_XOR_OP 22 | //#define HAVE_LOG_SHIFT_OP 23 | #define HAVE_LOG_RSHIFT_OP 24 | #define HAVE_LOG_LSHIFT_OP 25 | //#define HAVE_ARITH_SHIFT_OP 26 | //#define HAVE_ROTATE_OP 27 | //#define HAVE_LROTATE_OP 28 | //#define HAVE_RROTATE_OP 29 | //#define HAVE_MASK_OP 30 | #define HAVE_GETBIT_OP 31 | //#define HAVE_LN_OP 32 | //#define HAVE_GCD_OP 33 | //#define HAVE_EQ_COND 34 | //#define HAVE_GT_COND 35 | //#define HAVE_GE_COND 36 | //#define HAVE_LT_COND 37 | //#define HAVE_LE_COND 38 | //#define HAVE_AND_COND 39 | //#define HAVE_OR_COND 40 | //#define HAVE_MIN_OP 41 | //#define HAVE_MAX_OP 42 | 43 | 44 | /* General operation characteristics */ 45 | #define SEQUENCE_HUNTER 46 | //#define HAVE_FUNCTIONS 47 | #define NUM_SEQUENCE_DIMENSIONS (2) 48 | #define NUM_INTEGER_BITS (32) 49 | //#define HAVE_CONSTANTS_FILE 50 | #define HAVE_PRINT_SUM_INFIX 51 | #define HAVE_PRINT_SUM_RPN 52 | //#define SIGNED_OPERATION 53 | //#define MULTIPLE_RESULTS 54 | #define SEED (0) 55 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 56 | //#define NUM_ANSWERS (1) 57 | //#define ERROR_OP rint 58 | #define HAVE_PROGRESS 59 | //#define SPARSE_ARRAY_INDICES 60 | #define MAX_NUM_LOOPVARS (1) 61 | #define MIN_NUM_LOOPVARS (1) 62 | #define HAVE_INC_NBITS_LOOPFUNC 63 | //#define HAVE_DEC_NBITS_LOOPFUNC 64 | #define HAVE_LSHIFT_NBITS_LOOPFUNC 65 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 66 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 67 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 68 | //#define MAX_LOOPVAL (100) 69 | #define HAVE_RESULT_LOOPVAR 70 | #define BOOLEAN_RESULT_LOOPVAR 71 | -------------------------------------------------------------------------------- /fundamental_config_exp.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | #define HAVE_FACTORIAL_OP 4 | //#define HAVE_ABS_OP 5 | //#define HAVE_FLOOR_OP 6 | //#define HAVE_CEIL_OP 7 | //#define HAVE_RINT_OP 8 | //#define HAVE_SIN_OP 9 | //#define HAVE_COS_OP 10 | //#define HAVE_TAN_OP 11 | //#define HAVE_ONES_COMPLIMENT_OP 12 | //#define HAVE_NOT_OP 13 | #define HAVE_ADDITION_OP 14 | #define HAVE_SUBTRACTION_OP 15 | #define HAVE_MULTIPLY_OP 16 | #define HAVE_DIVIDE_OP 17 | #define HAVE_POWER_OP 18 | //#define HAVE_MODULO_OP 19 | //#define HAVE_AND_OP 20 | //#define HAVE_OR_OP 21 | //#define HAVE_XOR_OP 22 | //#define HAVE_LOG_SHIFT_OP 23 | //#define HAVE_LOG_RSHIFT_OP 24 | //#define HAVE_LOG_LSHIFT_OP 25 | //#define HAVE_ARITH_SHIFT_OP 26 | //#define HAVE_ROTATE_OP 27 | //#define HAVE_LROTATE_OP 28 | //#define HAVE_RROTATE_OP 29 | //#define HAVE_MASK_OP 30 | //#define HAVE_GETBIT_OP 31 | //#define HAVE_LN_OP 32 | //#define HAVE_GCD_OP 33 | //#define HAVE_EQ_COND 34 | //#define HAVE_GT_COND 35 | //#define HAVE_GE_COND 36 | //#define HAVE_LT_COND 37 | //#define HAVE_LE_COND 38 | //#define HAVE_AND_COND 39 | //#define HAVE_OR_COND 40 | //#define HAVE_MIN_OP 41 | //#define HAVE_MAX_OP 42 | 43 | 44 | /* General operation characteristics */ 45 | #define SEQUENCE_HUNTER 46 | //#define HAVE_FUNCTIONS 47 | #define NUM_SEQUENCE_DIMENSIONS (1) 48 | //#define NUM_INTEGER_BITS (32) 49 | //#define HAVE_CONSTANTS_FILE 50 | #define HAVE_PRINT_SUM_INFIX 51 | #define HAVE_PRINT_SUM_RPN 52 | //#define SIGNED_OPERATION 53 | //#define MULTIPLE_RESULTS 54 | #define SEED (0) 55 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 56 | //#define NUM_ANSWERS (1) 57 | //#define ERROR_OP rint 58 | #define HAVE_PROGRESS 59 | //#define SPARSE_ARRAY_INDICES 60 | #define MAX_NUM_LOOPVARS (1) 61 | #define MIN_NUM_LOOPVARS (1) 62 | #define HAVE_INC_LOOPFUNC 63 | #define MAX_LOOPVAL (11) 64 | //#define HAVE_DEC_LOOPFUNC 65 | //#define HAVE_LSHIFT_NBITS_LOOPFUNC 66 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 67 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 68 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 69 | //#define MAX_LOOPVAL (100) 70 | //#define HAVE_RESULT_LOOPVAR 71 | //#define BOOLEAN_RESULT_LOOPVAR 72 | -------------------------------------------------------------------------------- /fundamental_config_factorfloat.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | #define HAVE_FACTORIAL_OP 4 | //#define HAVE_ABS_OP 5 | //#define HAVE_FLOOR_OP 6 | //#define HAVE_CEIL_OP 7 | //#define HAVE_RINT_OP 8 | //#define HAVE_SIN_OP 9 | //#define HAVE_COS_OP 10 | //#define HAVE_TAN_OP 11 | //#define HAVE_ONES_COMPLIMENT_OP 12 | //#define HAVE_NOT_OP 13 | #define HAVE_ADDITION_OP 14 | //#define HAVE_SUBTRACTION_OP 15 | #define HAVE_MULTIPLY_OP 16 | #define HAVE_DIVIDE_OP 17 | #define HAVE_POWER_OP 18 | //#define HAVE_MODULO_OP 19 | //#define HAVE_AND_OP 20 | //#define HAVE_OR_OP 21 | //#define HAVE_XOR_OP 22 | //#define HAVE_LOG_SHIFT_OP 23 | //#define HAVE_LOG_RSHIFT_OP 24 | //#define HAVE_LOG_LSHIFT_OP 25 | //#define HAVE_ARITH_SHIFT_OP 26 | //#define HAVE_ROTATE_OP 27 | //#define HAVE_LROTATE_OP 28 | //#define HAVE_RROTATE_OP 29 | //#define HAVE_MASK_OP 30 | //#define HAVE_GETBIT_OP 31 | //#define HAVE_LN_OP 32 | //#define HAVE_GCD_OP 33 | //#define HAVE_EQ_COND 34 | //#define HAVE_GT_COND 35 | //#define HAVE_GE_COND 36 | //#define HAVE_LT_COND 37 | //#define HAVE_LE_COND 38 | //#define HAVE_AND_COND 39 | //#define HAVE_OR_COND 40 | //#define HAVE_MIN_OP 41 | //#define HAVE_MAX_OP 42 | 43 | 44 | /* General operation characteristics */ 45 | #define SEQUENCE_HUNTER 46 | //#define HAVE_FUNCTIONS 47 | #define NUM_SEQUENCE_DIMENSIONS (1) 48 | //#define NUM_INTEGER_BITS (4) 49 | //#define HAVE_CONSTANTS_FILE 50 | #define HAVE_PRINT_SUM_INFIX 51 | #define HAVE_PRINT_SUM_RPN 52 | #define SIGNED_OPERATION 53 | //#define MULTIPLE_RESULTS 54 | #define SEED (1) 55 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 56 | //#define NUM_ANSWERS (1) 57 | //#define ERROR_OP rint 58 | #define HAVE_PROGRESS 59 | //#define SPARSE_ARRAY_INDICES 60 | #define MAX_NUM_LOOPVARS (1) 61 | #define MIN_NUM_LOOPVARS (1) 62 | //#define HAVE_INC_NBITS_LOOPFUNC 63 | //#define HAVE_DEC_NBITS_LOOPFUNC 64 | //#define HAVE_LSHIFT_NBITS_LOOPFUNC 65 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 66 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 67 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 68 | //#define ZERO_MAX_LOOPVAL (16) 69 | #define ONE_MAX_LOOPVAL (16) 70 | #define HAVE_RESULT_LOOPVAR 71 | //#define BOOLEAN_RESULT_LOOPVAR 72 | -------------------------------------------------------------------------------- /fundamental_config_real_hunter.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | #define HAVE_FACTORIAL_OP 4 | //#define HAVE_ABS_OP 5 | //#define HAVE_FLOOR_OP 6 | //#define HAVE_CEIL_OP 7 | //#define HAVE_RINT_OP 8 | //#define HAVE_SIN_OP 9 | //#define HAVE_COS_OP 10 | //#define HAVE_TAN_OP 11 | //#define HAVE_ONES_COMPLIMENT_OP 12 | //#define HAVE_NOT_OP 13 | #define HAVE_ADDITION_OP 14 | #define HAVE_SUBTRACTION_OP 15 | #define HAVE_MULTIPLY_OP 16 | #define HAVE_DIVIDE_OP 17 | #define HAVE_POWER_OP 18 | //#define HAVE_MODULO_OP 19 | //#define HAVE_AND_OP 20 | //#define HAVE_OR_OP 21 | //#define HAVE_XOR_OP 22 | //#define HAVE_LOG_SHIFT_OP 23 | //#define HAVE_LOG_RSHIFT_OP 24 | //#define HAVE_LOG_LSHIFT_OP 25 | //#define HAVE_ARITH_SHIFT_OP 26 | //#define HAVE_ROTATE_OP 27 | //#define HAVE_LROTATE_OP 28 | //#define HAVE_RROTATE_OP 29 | //#define HAVE_MASK_OP 30 | //#define HAVE_GETBIT_OP 31 | //#define HAVE_LN_OP 32 | //#define HAVE_GCD_OP 33 | //#define HAVE_EQ_COND 34 | //#define HAVE_GT_COND 35 | //#define HAVE_GE_COND 36 | //#define HAVE_LT_COND 37 | //#define HAVE_LE_COND 38 | //#define HAVE_AND_COND 39 | //#define HAVE_OR_COND 40 | //#define HAVE_MIN_OP 41 | //#define HAVE_MAX_OP 42 | 43 | 44 | /* General operation characteristics */ 45 | //#define SEQUENCE_HUNTER 46 | #define REAL_HUNTER 47 | //#define HAVE_FUNCTIONS 48 | #define NUM_HUNTER_DIMENSIONS (3) 49 | //#define NUM_INTEGER_BITS (32) 50 | //#define HAVE_CONSTANTS_FILE 51 | #define HAVE_PRINT_SUM_INFIX 52 | #define HAVE_PRINT_SUM_RPN 53 | //#define SIGNED_OPERATION 54 | //#define MULTIPLE_RESULTS 55 | #define SEED (0) 56 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 57 | //#define NUM_ANSWERS (1) 58 | //#define ERROR_OP rint 59 | #define HAVE_PROGRESS 60 | //#define SPARSE_ARRAY_INDICES 61 | //#define MAX_NUM_LOOPVARS (1) 62 | //#define MIN_NUM_LOOPVARS (1) 63 | //#define HAVE_INC_LOOPFUNC 64 | //#define MAX_LOOPVAL (11) 65 | //#define HAVE_DEC_LOOPFUNC 66 | //#define HAVE_LSHIFT_NBITS_LOOPFUNC 67 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 68 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 69 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 70 | //#define MAX_LOOPVAL (100) 71 | //#define HAVE_RESULT_LOOPVAR 72 | //#define BOOLEAN_RESULT_LOOPVAR 73 | -------------------------------------------------------------------------------- /fundamental_config_new.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | #define HAVE_FACTORIAL_OP 4 | //#define HAVE_ABS_OP 5 | //#define HAVE_FLOOR_OP 6 | //#define HAVE_CEIL_OP 7 | //#define HAVE_RINT_OP 8 | //#define HAVE_SIN_OP 9 | //#define HAVE_COS_OP 10 | //#define HAVE_TAN_OP 11 | //#define HAVE_ONES_COMPLIMENT_OP 12 | //#define HAVE_NOT_OP 13 | #define HAVE_ADDITION_OP 14 | #define HAVE_SUBTRACTION_OP 15 | #define HAVE_MULTIPLY_OP 16 | #define HAVE_DIVIDE_OP 17 | #define HAVE_POWER_OP 18 | //#define HAVE_MODULO_OP 19 | //#define HAVE_AND_OP 20 | //#define HAVE_OR_OP 21 | //#define HAVE_XOR_OP 22 | //#define HAVE_LOG_SHIFT_OP 23 | //#define HAVE_LOG_RSHIFT_OP 24 | //#define HAVE_LOG_LSHIFT_OP 25 | //#define HAVE_ARITH_SHIFT_OP 26 | //#define HAVE_ROTATE_OP 27 | //#define HAVE_LROTATE_OP 28 | //#define HAVE_RROTATE_OP 29 | //#define HAVE_MASK_OP 30 | //#define HAVE_GETBIT_OP 31 | //#define HAVE_LN_OP 32 | //#define HAVE_GCD_OP 33 | //#define HAVE_EQ_COND 34 | //#define HAVE_GT_COND 35 | //#define HAVE_GE_COND 36 | //#define HAVE_LT_COND 37 | //#define HAVE_LE_COND 38 | //#define HAVE_AND_COND 39 | //#define HAVE_OR_COND 40 | //#define HAVE_MIN_OP 41 | //#define HAVE_MAX_OP 42 | 43 | 44 | /* General operation characteristics */ 45 | #define SEQUENCE_HUNTER 46 | #define NUM_SEQUENCE_DIMENSIONS (1) 47 | //#define REAL_HUNTER 48 | //#define HAVE_FUNCTIONS 49 | //#define NUM_HUNTER_DIMENSIONS (3) 50 | //#define NUM_INTEGER_BITS (32) 51 | //#define HAVE_CONSTANTS_FILE 52 | #define HAVE_PRINT_SUM_INFIX 53 | #define HAVE_PRINT_SUM_RPN 54 | //#define SIGNED_OPERATION 55 | //#define MULTIPLE_RESULTS 56 | //#define SEED (1) 57 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 58 | #define NUM_ANSWERS (1) 59 | //#define ERROR_OP rint 60 | #define HAVE_PROGRESS 61 | //#define SPARSE_ARRAY_INDICES 62 | #define MAX_NUM_LOOPVARS (1) 63 | #define MIN_NUM_LOOPVARS (1) 64 | #define HAVE_INC_LOOPFUNC 65 | #define MIN_LOOPVAL (1) 66 | #define MAX_LOOPVAL (8) 67 | //#define MAX_LOOPVAL_NUM_INTEGER_BITS (8) 68 | //#define HAVE_DEC_LOOPFUNC 69 | //#define HAVE_LSHIFT_NBITS_LOOPFUNC 70 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 71 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 72 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 73 | //#define MAX_LOOPVAL (100) 74 | #define HAVE_RESULT_LOOPVAR 75 | //#define BOOLEAN_RESULT_LOOPVAR 76 | -------------------------------------------------------------------------------- /fundamental_sanity.h: -------------------------------------------------------------------------------- 1 | #if defined(SEQUENCE_HUNTER) || defined(REAL_HUNTER) 2 | #define HUNTER 3 | #endif 4 | #ifdef NUM_INTEGER_BITS 5 | #if (NUM_INTEGER_BITS>64||NUM_INTEGER_BITS<=0) 6 | #error "Illegal NUM_INTEGER_BITS definition." 7 | #endif 8 | #ifdef HAVE_FLOATING_POINT_OPERATORS 9 | #error "Floating point operators defined in integer mode." 10 | #endif 11 | #if defined(SIGNED_OPERATION) && defined (HAVE_EXCESS_INTEGER_UNSIGNED_OPERATORS) 12 | #error "SIGNED_OPERATION & HAVE_EXCESS_INTEGER_UNSIGNED_OPERATORS defined" 13 | #endif 14 | #else /* NUM_INTEGER_BITS */ 15 | #ifdef HAVE_BOOLEAN_OPERATORS 16 | #error "Boolean operators defined in floating point mode." 17 | #endif 18 | #endif /* NUM_INTEGER_BITS */ 19 | 20 | #if !defined(HAVE_PRINT_SUM_INFIX)&&!defined(HAVE_PRINT_SUM_RPN) 21 | #error "HAVE_PRINT_SUM_INFIX or HAVE_PRINT_SUM_RPN should be defined" 22 | #endif 23 | 24 | 25 | #if defined(MULTIPLE_RESULTS) 26 | #ifndef SEQUENCE_HUNTER 27 | #error "MULTIPLE_RESULTS only compatible with SEQUENCE_HUNTER mode." 28 | #endif 29 | #else 30 | #ifdef PRINT_MULTIPLE_ANSWERS 31 | #error "PRINT_MULTIPLE_ANSWERS defined without MULTIPLE_RESULTS" 32 | #endif 33 | #if defined(NUM_ANSWERS) && NUM_ANSWERS>1 34 | #error "NUM_ANSWERS>1 defined without MULTIPLE_RESULTS" 35 | #endif 36 | #endif 37 | #if !defined(HUNTER)&& !defined(HAVE_CONSTANTS_FILE) 38 | #error "SEQUENCE_HUNTER or REAL_HUNTER or HAVE_CONSTANTS_FILE need to be defined" 39 | #endif 40 | 41 | 42 | #if defined(HAVE_BLOCK_DIST_RATIOED_ERROR) && defined(HAVE_DIST_RATIOED_ERROR) 43 | #error "HAVE_BLOCK_DIST_RATIOED_ERROR && HAVE_DIST_RATIOED_ERROR both defined" 44 | #endif 45 | 46 | #if defined(HAVE_ERROR_MEASUREMENTS) && ! defined(SEQUENCE_HUNTER) 47 | #error "SEQUENCE_HUNTER must be defined if HAVE_ERROR_MEASUREMENTS is defined" 48 | #endif 49 | 50 | #if defined(MULTIPLE_RESULTS) && defined(HAVE_ERROR_MEASUREMENTS) 51 | #error "MULTIPLE_RESULTS & HAVE_ERROR_MEASUREMENTS are mutually exclusive & incompatible." 52 | #endif 53 | 54 | #if !defined(SIGNED_OPERATION) && defined(NUM_INTEGER_BITS) && defined(HAVE_ERROR_MEASUREMENTS) 55 | #warning "un SIGNED_OPERATION && HAVE_ERROR_MEASUREMENTS normally doesn't work owing to casting problems" 56 | #endif 57 | #if defined(HAVE_DEBUG_ERROR_LIST) && !defined (HAVE_ERROR_MEASUREMENTS) 58 | #error "HAVE_DEBUG_ERROR_LIST definition needs HAVE_ERROR_MEASUREMENTS definition." 59 | #endif 60 | #if defined(REAL_HUNTER) && defined (HAVE_FUNCTIONS) 61 | #error "REAL_HUNTER and HAVE_FUNCTIONS cannot be defined simultaineously." 62 | #endif 63 | #if defined(REAL_HUNTER) && defined (SEQUENCE_HUNTER) 64 | #error "REAL_HUNTER and SEQUENCE_HUNTER cannot be defined simultaineously." 65 | #endif 66 | -------------------------------------------------------------------------------- /fundamental_config_factorint.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | /* Unary Operators */ 4 | #define HAVE_FACTORIAL_OP 5 | //#define HAVE_ABS_OP 6 | //#define HAVE_FLOOR_OP 7 | //#define HAVE_CEIL_OP 8 | //#define HAVE_RINT_OP 9 | #define HAVE_SIN_OP 10 | #define HAVE_COS_OP 11 | #define HAVE_TAN_OP 12 | 13 | /* Binary Operators */ 14 | #define HAVE_ADDITION_OP 15 | //#define HAVE_SUBTRACTION_OP 16 | #define HAVE_MULTIPLY_OP 17 | #define HAVE_DIVIDE_OP 18 | #define HAVE_POWER_OP 19 | //#define HAVE_MODULO_OP 20 | //#define HAVE_LN_OP 21 | //#define HAVE_GCD_OP 22 | 23 | /* Unary Booolean Operators */ 24 | //#define HAVE_ONES_COMPLIMENT_OP 25 | //#define HAVE_NOT_OP 26 | 27 | /* Binary Boolean Operators */ 28 | //#define HAVE_AND_OP 29 | //#define HAVE_OR_OP 30 | //#define HAVE_XOR_OP 31 | //#define HAVE_LOG_SHIFT_OP 32 | //#define HAVE_LOG_RSHIFT_OP 33 | //#define HAVE_LOG_LSHIFT_OP 34 | //#define HAVE_ARITH_SHIFT_OP 35 | //#define HAVE_ROTATE_OP 36 | //#define HAVE_LROTATE_OP 37 | //#define HAVE_RROTATE_OP 38 | //#define HAVE_MASK_OP 39 | //#define HAVE_GETBIT_OP 40 | 41 | /* Conditional Operators */ 42 | //#define HAVE_EQ_COND 43 | //#define HAVE_GT_COND 44 | //#define HAVE_GE_COND 45 | //#define HAVE_LT_COND 46 | //#define HAVE_LE_COND 47 | //#define HAVE_AND_COND 48 | //#define HAVE_OR_COND 49 | //#define HAVE_MIN_OP 50 | //#define HAVE_MAX_OP 51 | 52 | 53 | /* General operation characteristics */ 54 | #define SEQUENCE_HUNTER 55 | //#define HAVE_FUNCTIONS 56 | #define NUM_SEQUENCE_DIMENSIONS (1) 57 | //#define NUM_INTEGER_BITS (32) 58 | #define HAVE_CONSTANTS_FILE 59 | #define HAVE_PRINT_SUM_INFIX 60 | #define HAVE_PRINT_SUM_RPN 61 | #define SIGNED_OPERATION 62 | //#define MULTIPLE_RESULTS 63 | //#define SEED (1) 64 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 65 | //#define NUM_ANSWERS (2) 66 | //#define ERROR_OP rint 67 | #define HAVE_PROGRESS 68 | //#define SPARSE_ARRAY_INDICES 69 | //#define MAX_NUM_LOOPVARS (1) 70 | //#define MIN_NUM_LOOPVARS (0) 71 | //#define HAVE_INC_NBITS_LOOPFUNC 72 | //#define HAVE_DEC_NBITS_LOOPFUNC 73 | //#define HAVE_LSHIFT_NBITS_LOOPFUNC 74 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 75 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 76 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 77 | //#define MAX_LOOPVAL (100) 78 | //#define HAVE_RESULT_LOOPVAR 79 | //#define BOOLEAN_RESULT_LOOPVAR 80 | 81 | //#define HAVE_LMS_ERROR 82 | //#define HAVE_ABS_ERROR 83 | //#define HAVE_LMS_RATIOED_ERROR 84 | //#define HAVE_ABS_RATIOED_ERROR 85 | //#define HAVE_LMS_GT_ERROR 86 | //#define HAVE_GT_ERROR 87 | //#define HAVE_LMS_GT_RATIOED_ERROR 88 | //#define HAVE_GT_RATIOED_ERROR 89 | //#define HAVE_LMS_LT_ERROR 90 | //#define HAVE_LT_ERROR 91 | //#define HAVE_LMS_LT_RATIOED_ERROR 92 | //#define HAVE_LT_RATIOED_ERROR 93 | //#define HAVE_BLOCK_DIST_RATIOED_ERROR 94 | //#define HAVE_DIST_RATIOED_ERROR 95 | //#define HAVE_DEBUG_ERROR_LIST 96 | //#define HAVE_SIMPLIFICATION_TEST 97 | -------------------------------------------------------------------------------- /fundamental_config_gemstone.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | /* Unary Operators */ 4 | #define HAVE_FACTORIAL_OP 5 | //#define HAVE_ABS_OP 6 | //#define HAVE_FLOOR_OP 7 | //#define HAVE_CEIL_OP 8 | //#define HAVE_RINT_OP 9 | //#define HAVE_SIN_OP 10 | //#define HAVE_COS_OP 11 | //#define HAVE_TAN_OP 12 | 13 | /* Binary Operators */ 14 | #define HAVE_ADDITION_OP 15 | #define HAVE_SUBTRACTION_OP 16 | #define HAVE_MULTIPLY_OP 17 | #define HAVE_DIVIDE_OP 18 | //#define HAVE_POWER_OP 19 | //#define HAVE_MODULO_OP 20 | //#define HAVE_LN_OP 21 | //#define HAVE_GCD_OP 22 | 23 | /* Unary Booolean Operators */ 24 | //#define HAVE_ONES_COMPLIMENT_OP 25 | //#define HAVE_NOT_OP 26 | 27 | /* Binary Boolean Operators */ 28 | //#define HAVE_AND_OP 29 | //#define HAVE_OR_OP 30 | //#define HAVE_XOR_OP 31 | //#define HAVE_LOG_SHIFT_OP 32 | //#define HAVE_LOG_RSHIFT_OP 33 | //#define HAVE_LOG_LSHIFT_OP 34 | //#define HAVE_ARITH_SHIFT_OP 35 | //#define HAVE_ROTATE_OP 36 | //#define HAVE_LROTATE_OP 37 | //#define HAVE_RROTATE_OP 38 | //#define HAVE_MASK_OP 39 | //#define HAVE_GETBIT_OP 40 | 41 | /* Conditional Operators */ 42 | //#define HAVE_EQ_COND 43 | //#define HAVE_GT_COND 44 | //#define HAVE_GE_COND 45 | //#define HAVE_LT_COND 46 | //#define HAVE_LE_COND 47 | //#define HAVE_AND_COND 48 | //#define HAVE_OR_COND 49 | //#define HAVE_MIN_OP 50 | //#define HAVE_MAX_OP 51 | 52 | 53 | /* General operation characteristics */ 54 | #define SEQUENCE_HUNTER 55 | #define HAVE_FUNCTIONS 56 | #define NUM_SEQUENCE_DIMENSIONS (1) 57 | #define NUM_INTEGER_BITS (32) 58 | //#define HAVE_CONSTANTS_FILE 59 | #define HAVE_PRINT_SUM_INFIX 60 | #define HAVE_PRINT_SUM_RPN 61 | //#define SIGNED_OPERATION 62 | //#define MULTIPLE_RESULTS 63 | //#define SEED (1) 64 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 65 | //#define NUM_ANSWERS (2) 66 | //#define ERROR_OP rint 67 | #define HAVE_PROGRESS 68 | //#define SPARSE_ARRAY_INDICES 69 | //#define MAX_NUM_LOOPVARS (1) 70 | //#define MIN_NUM_LOOPVARS (0) 71 | //#define HAVE_INC_NBITS_LOOPFUNC 72 | //#define HAVE_DEC_NBITS_LOOPFUNC 73 | //#define HAVE_LSHIFT_NBITS_LOOPFUNC 74 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 75 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 76 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 77 | //#define MAX_LOOPVAL (100) 78 | //#define HAVE_RESULT_LOOPVAR 79 | //#define BOOLEAN_RESULT_LOOPVAR 80 | 81 | //#define HAVE_LMS_ERROR 82 | //#define HAVE_ABS_ERROR 83 | //#define HAVE_LMS_RATIOED_ERROR 84 | //#define HAVE_ABS_RATIOED_ERROR 85 | //#define HAVE_LMS_GT_ERROR 86 | //#define HAVE_GT_ERROR 87 | //#define HAVE_LMS_GT_RATIOED_ERROR 88 | //#define HAVE_GT_RATIOED_ERROR 89 | //#define HAVE_LMS_LT_ERROR 90 | //#define HAVE_LT_ERROR 91 | //#define HAVE_LMS_LT_RATIOED_ERROR 92 | //#define HAVE_LT_RATIOED_ERROR 93 | //#define HAVE_BLOCK_DIST_RATIOED_ERROR 94 | //#define HAVE_DIST_RATIOED_ERROR 95 | //#define HAVE_DEBUG_ERROR_LIST 96 | //#define HAVE_SIMPLIFICATION_TEST 97 | -------------------------------------------------------------------------------- /fundamental_config_gemstone2.h: -------------------------------------------------------------------------------- 1 | /* Operations & Conditionals */ 2 | 3 | /* Unary Operators */ 4 | #define HAVE_FACTORIAL_OP 5 | //#define HAVE_ABS_OP 6 | //#define HAVE_FLOOR_OP 7 | //#define HAVE_CEIL_OP 8 | //#define HAVE_RINT_OP 9 | //#define HAVE_SIN_OP 10 | //#define HAVE_COS_OP 11 | //#define HAVE_TAN_OP 12 | 13 | /* Binary Operators */ 14 | #define HAVE_ADDITION_OP 15 | #define HAVE_SUBTRACTION_OP 16 | #define HAVE_MULTIPLY_OP 17 | #define HAVE_DIVIDE_OP 18 | #define HAVE_POWER_OP 19 | //#define HAVE_MODULO_OP 20 | #define HAVE_LN_OP 21 | //#define HAVE_GCD_OP 22 | 23 | /* Unary Booolean Operators */ 24 | //#define HAVE_ONES_COMPLIMENT_OP 25 | //#define HAVE_NOT_OP 26 | 27 | /* Binary Boolean Operators */ 28 | //#define HAVE_AND_OP 29 | //#define HAVE_OR_OP 30 | //#define HAVE_XOR_OP 31 | //#define HAVE_LOG_SHIFT_OP 32 | //#define HAVE_LOG_RSHIFT_OP 33 | //#define HAVE_LOG_LSHIFT_OP 34 | //#define HAVE_ARITH_SHIFT_OP 35 | //#define HAVE_ROTATE_OP 36 | //#define HAVE_LROTATE_OP 37 | //#define HAVE_RROTATE_OP 38 | //#define HAVE_MASK_OP 39 | //#define HAVE_GETBIT_OP 40 | 41 | /* Conditional Operators */ 42 | //#define HAVE_EQ_COND 43 | //#define HAVE_GT_COND 44 | //#define HAVE_GE_COND 45 | //#define HAVE_LT_COND 46 | //#define HAVE_LE_COND 47 | //#define HAVE_AND_COND 48 | //#define HAVE_OR_COND 49 | //#define HAVE_MIN_OP 50 | //#define HAVE_MAX_OP 51 | 52 | 53 | /* General operation characteristics */ 54 | #define SEQUENCE_HUNTER 55 | #define HAVE_FUNCTIONS 56 | #define NUM_SEQUENCE_DIMENSIONS (1) 57 | //#define NUM_INTEGER_BITS (32) 58 | #define HAVE_CONSTANTS_FILE 59 | #define HAVE_PRINT_SUM_INFIX 60 | #define HAVE_PRINT_SUM_RPN 61 | //#define SIGNED_OPERATION 62 | //#define MULTIPLE_RESULTS 63 | //#define SEED (1) 64 | //#define PRINT_ONLY_FIRST_CORRECT_ANSWER 65 | //#define NUM_ANSWERS (2) 66 | //#define ERROR_OP rint 67 | #define HAVE_PROGRESS 68 | //#define SPARSE_ARRAY_INDICES 69 | //#define MAX_NUM_LOOPVARS (1) 70 | //#define MIN_NUM_LOOPVARS (0) 71 | //#define HAVE_INC_NBITS_LOOPFUNC 72 | //#define HAVE_DEC_NBITS_LOOPFUNC 73 | //#define HAVE_LSHIFT_NBITS_LOOPFUNC 74 | //#define HAVE_RSHIFT_NBITS_LOOPFUNC 75 | //#define HAVE_INC_PWR_NBITS_LOOPFUNC 76 | //#define HAVE_DEC_PWR_NBITS_LOOPFUNC 77 | //#define MAX_LOOPVAL (100) 78 | //#define HAVE_RESULT_LOOPVAR 79 | //#define BOOLEAN_RESULT_LOOPVAR 80 | 81 | //#define HAVE_LMS_ERROR 82 | //#define HAVE_ABS_ERROR 83 | //#define HAVE_LMS_RATIOED_ERROR 84 | //#define HAVE_ABS_RATIOED_ERROR 85 | //#define HAVE_LMS_GT_ERROR 86 | //#define HAVE_GT_ERROR 87 | //#define HAVE_LMS_GT_RATIOED_ERROR 88 | //#define HAVE_GT_RATIOED_ERROR 89 | //#define HAVE_LMS_LT_ERROR 90 | //#define HAVE_LT_ERROR 91 | //#define HAVE_LMS_LT_RATIOED_ERROR 92 | //#define HAVE_LT_RATIOED_ERROR 93 | //#define HAVE_BLOCK_DIST_RATIOED_ERROR 94 | //#define HAVE_DIST_RATIOED_ERROR 95 | //#define HAVE_DEBUG_ERROR_LIST 96 | //#define HAVE_SIMPLIFICATION_TEST 97 | -------------------------------------------------------------------------------- /discoveries.txt: -------------------------------------------------------------------------------- 1 | Found match error=4.714556e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 2 | result=1.675008e-27 3 | mass_of_proton mass_of_electron mass_of_electron golden_ratio * + + 4 | 1.672623e-27 9.109390e-31 9.109390e-31 1.618034e+00 * + + 5 | (mass_of_proton + (mass_of_electron + (mass_of_electron * golden_ratio))) 6 | (1.672623e-27 + (9.109390e-31 + (9.109390e-31 * 1.618034e+00 ))) 7 | 8 | Found match error=7.948149e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 9 | result=1.675062e-27 10 | mass_of_proton mass_of_electron golden_ratio semitone_multiple + * + 11 | 1.672623e-27 9.109390e-31 1.618034e+00 1.059463e+00 + * + 12 | (mass_of_proton + (mass_of_electron * (golden_ratio + semitone_multiple))) 13 | (1.672623e-27 + (9.109390e-31 * (1.618034e+00 + 1.059463e+00 ))) 14 | 15 | Found match error=4.818072e-05 fundamental constant name=semitone_multiple value=1.059463e+00 16 | result=1.059412e+00 17 | 1 fine_structure_constant 5 pi + * + 18 | 1 7.297350e-03 5 3.141593e+00 + * + 19 | (1 + (fine_structure_constant * (5 + pi))) 20 | (1 + (7.297350e-03 * (5 + 3.141593e+00 ))) 21 | 22 | Found match error=9.784477e-05 fundamental constant name=mass_of_proton value=1.672623e-27 23 | result=1.672459e-27 24 | mass_of_neutron mass_of_electron fine_structure_constant e - * + 25 | 1.674929e-27 9.109390e-31 7.297350e-03 2.718282e+00 - * + 26 | (mass_of_neutron + (mass_of_electron * (fine_structure_constant - e))) 27 | (1.674929e-27 + (9.109390e-31 * (7.297350e-03 - 2.718282e+00 ))) 28 | 29 | Found match error=8.134724e-05 fundamental constant name=mass_of_proton value=1.672623e-27 30 | result=1.672759e-27 31 | mass_of_neutron mass_of_electron golden_ratio 4 - * + 32 | 1.674929e-27 9.109390e-31 1.618034e+00 4 - * + 33 | (mass_of_neutron + (mass_of_electron * (golden_ratio - 4))) 34 | (1.674929e-27 + (9.109390e-31 * (1.618034e+00 - 4))) 35 | 36 | Found match error=4.310236e-05 fundamental constant name=semitone_multiple value=1.059463e+00 37 | result=1.059509e+00 38 | 1 3 e fine_structure_constant * * + 39 | 1 3 2.718282e+00 7.297350e-03 * * + 40 | (1 + (3 * (e * fine_structure_constant))) 41 | (1 + (3 * (2.718282e+00 * 7.297350e-03 ))) 42 | 43 | Found match error=1.222877e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 44 | result=1.674909e-27 45 | mass_of_proton mass_of_electron mass_of_muon fine_structure_constant * + + 46 | 1.672623e-27 9.109390e-31 1.883532e-28 7.297350e-03 * + + 47 | (mass_of_proton + (mass_of_electron + (mass_of_muon * fine_structure_constant))) 48 | (1.672623e-27 + (9.109390e-31 + (1.883532e-28 * 7.297350e-03 ))) 49 | 50 | Found match error=4.892766e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 51 | result=1.674847e-27 52 | mass_of_proton mass_of_muon golden_ratio fine_structure_constant * * + 53 | 1.672623e-27 1.883532e-28 1.618034e+00 7.297350e-03 * * + 54 | (mass_of_proton + (mass_of_muon * (golden_ratio * fine_structure_constant))) 55 | (1.672623e-27 + (1.883532e-28 * (1.618034e+00 * 7.297350e-03 ))) 56 | 57 | Found match error=4.899031e-05 fundamental constant name=mass_of_proton value=1.672623e-27 58 | result=1.672705e-27 59 | mass_of_neutron mass_of_muon golden_ratio fine_structure_constant * * - 60 | 1.674929e-27 1.883532e-28 1.618034e+00 7.297350e-03 * * - 61 | (mass_of_neutron - (mass_of_muon * (golden_ratio * fine_structure_constant))) 62 | (1.674929e-27 - (1.883532e-28 * (1.618034e+00 * 7.297350e-03 ))) 63 | -------------------------------------------------------------------------------- /csv.c: -------------------------------------------------------------------------------- 1 | #include "fundamental_config.h" 2 | #include "fundamental.h" 3 | #include "csv.h" 4 | #include "utils.h" 5 | #ifdef REAL_HUNTER 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | off_t getfilelen(int fd) 15 | { 16 | struct stat buf; 17 | 18 | if(fstat(fd,&buf)) 19 | exit(errno); 20 | return buf.st_size; 21 | } 22 | 23 | void parselines(char *buff,off_t len,char ***lines,int *num_csv_lines) 24 | { 25 | off_t curr,lastline; 26 | int currline; 27 | buff[len]=0; 28 | 29 | *num_csv_lines=0; 30 | for(curr=0;curr=filelen) 83 | break; 84 | } 85 | close(fd); 86 | parselines(buff,filelen,&lines,&num_csv_lines); 87 | num_commas0=0; 88 | for(i=0;i 10 | #ifdef SEQUENCE_HUNTER 11 | #if 1 12 | int sequence_func(number_t *retnum,dimension_t *array_indices) 13 | { 14 | 15 | *retnum=(sin(array_indices[0])*5.0)/*+(sin(array_indices[0]*3)/5.0)*//*+(sin(array_indices[0]*5)*.1)*/; 16 | return 0; 17 | } 18 | #endif 19 | #if 0 20 | int sequence_func(number_t *retnum,dimension_t *array_indices) 21 | { 22 | 23 | dimension_t curr_idx; 24 | dimension_t *temp_indices=alloca(sizeof(dimension_t)*NUM_SEQUENCE_DIMENSIONS); 25 | if(array_indices[0]==0||array_indices[1]<2) 26 | *retnum=3; 27 | else 28 | { 29 | temp_indices[0]=array_indices[0]-1; 30 | temp_indices[1]=arrayindices[1]-2; 31 | *retnum=*(get_array_member(temp_indices))+3; 32 | } 33 | return 0; 34 | } 35 | #endif 36 | 37 | #if 0 38 | int sequence_func(number_t *retnum,dimension_t *array_indices) 39 | { 40 | int numprimes=0; 41 | int idx1,idx2; 42 | 43 | for(idx1=1;;idx1++) 44 | { 45 | for(idx2=2;idx2=0) 114 | { 115 | if(y1>=0) 116 | { 117 | intadd=((y0+y1)/2)*widthinc; 118 | } 119 | else 120 | { 121 | x0=sqrt(next_crossing++*PI); 122 | intadd=(y0*(x0-(i+j))/2)-(y1*((i+j+widthinc)-x0)/2); 123 | } 124 | } 125 | else 126 | { 127 | if(y1<0) 128 | { 129 | intadd=((y0+y1)/2)*widthinc; 130 | } 131 | else 132 | { 133 | x0=sqrt(next_crossing++*PI); 134 | intadd=(y1*((i+j+widthinc)-x0)/2)-(y0*(x0-(i+j))/2); 135 | } 136 | } 137 | retvals[i+1]+=intadd; 138 | } 139 | if(i>=1) 140 | retvals[i+1]+=retvals[i]; 141 | } 142 | init=TRUE; 143 | } 144 | #endif 145 | #if 0 146 | int sequence_func(number_t *retnum,dimension_t *array_indices) 147 | { 148 | #if 0 149 | *retnum=/*sin(array_indices[0]*array_indices[0])+*/(2*cos(array_indices[0])); 150 | return 0; 151 | #endif 152 | if(!init) 153 | { 154 | fundfill(); 155 | } 156 | if(array_indices[0]<=NUM_RETVALS) 157 | { 158 | *retnum=retvals[array_indices[0]]; 159 | return 0; 160 | } 161 | return 1; 162 | } 163 | #endif 164 | #if 0 165 | int sequence_func(number_t *retnum,dimension_t *array_indices) 166 | { 167 | *retnum=array_indices[0]+array_indices[1]; 168 | return 0; 169 | } 170 | #endif 171 | #if 0 172 | int sequence_func(result_t *retnum,dimension_t *array_indices) 173 | { 174 | *retnum=array_indices[0]+array_indices[1]; 175 | return 0; 176 | } 177 | #endif 178 | #if 0 179 | int sequence_func(result_t *retnums,dimension_t *array_indices) 180 | { 181 | #ifndef NUM_ANSWERS 182 | *retnums=alloc_result(2); 183 | (*retnums)->answer[0]=array_indices[0]*2; 184 | (*retnums)->answer[1]=array_indices[0]*3; 185 | #else 186 | retnums->answer[0]=array_indices[0]*2; 187 | retnums->answer[1]=array_indices[0]*3; 188 | #endif 189 | 190 | return 0; 191 | } 192 | #endif 193 | #if 0 194 | int sequence_func(result_t *retnum,dimension_t *array_indices) 195 | { 196 | *retnum=sin(array_indices[0]); 197 | return 0; 198 | } 199 | #endif 200 | #if 0 201 | int sequence_func(result_t *retnum,dimension_t *array_indices) 202 | { 203 | *retnum=exp(array_indices[0]); 204 | return 0; 205 | } 206 | #endif 207 | #if 0 208 | int sequence_func(result_t *retnum,dimension_t *array_indices) 209 | { 210 | *retnum=array_indices[0]*3+2; 211 | return 0; 212 | } 213 | #endif 214 | #if 0 215 | int sequence_func(result_t *retnum,dimension_t *array_indices) 216 | { 217 | *retnum=exp(array_indices[0]); 218 | return 0; 219 | } 220 | #endif 221 | #endif /* SEQUENCE_HUNTER */ 222 | -------------------------------------------------------------------------------- /do_sum.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of fundamental a brute force searcher 3 | for relationships between constants & formulae for sequences. 4 | It is a source file for the reverse polish notation RPN calculation 5 | code in the project. 6 | Copyright (C) 2018 D.J. Barrow dj_barrow@ariasoft.ie barrow_dj@yahoo.com 7 | 8 | It licensed is under GPL v2.1 9 | */ 10 | 11 | #include "fundamental.h" 12 | #include "utils.h" 13 | #include "do_sum.h" 14 | #ifdef HAVE_GCD_OP 15 | uint_t euclid_calc_gcd(uint_t x,uint_t y) 16 | { 17 | uint_t temp; 18 | 19 | for(;;) 20 | { 21 | if(x==y) 22 | return x; 23 | if(xval; 78 | switch(op) 79 | { 80 | #ifdef HAVE_ADDITION_OP 81 | case addition_op: 82 | *result_ptr=operand[0]+operand[1]; 83 | break; 84 | #endif 85 | #ifdef HAVE_SUBTRACTION_OP 86 | case subtraction_op: 87 | *result_ptr=operand[0]-operand[1]; 88 | break; 89 | #endif 90 | #ifdef HAVE_MULTIPLY_OP 91 | case multiply_op: 92 | *result_ptr=SIGN_EXTEND(operand[0])*SIGN_EXTEND(operand[1]); 93 | break; 94 | #endif 95 | #ifdef HAVE_DIVIDE_OP 96 | case divide_op: 97 | if(operand[1]==0) 98 | abort_sum(-1,"division by zero aborting sum " 99 | NUMBER_FORMAT"/"NUMBER_FORMAT,operand[0],operand[1]); 100 | *result_ptr=SIGN_EXTEND(operand[0])/SIGN_EXTEND(operand[1]); 101 | break; 102 | #endif 103 | #ifdef HAVE_POWER_OP 104 | case power_op: 105 | #ifdef NUM_INTEGER_BITS 106 | #ifndef SIGNED_OPERATION 107 | if(IS_NEGATIVE(operand[1])) 108 | abort_sum(-1,"int power less than 0 aborting sum pow(" 109 | NUMBER_FORMAT","NUMBER_FORMAT")",operand[0],operand[1]); 110 | #endif 111 | if(operand[0]==0) 112 | { 113 | *result_ptr=0; 114 | break; 115 | } 116 | *result_ptr=1; 117 | if(operand[0]==1) 118 | break; 119 | if(operand[0]==-1) 120 | { 121 | if(operand[1]&1) 122 | *result_ptr=-1; 123 | break; 124 | } 125 | { 126 | number_t idx,oldresult=1; 127 | for(idx=1;idx<=operand[1];idx++) 128 | { 129 | *result_ptr*=operand[0]; 130 | if((*result_ptr/operand[0])!=oldresult) 131 | abort_sum(-1,"overflow aborting sum pow(" 132 | NUMBER_FORMAT","NUMBER_FORMAT")",operand[0],operand[1]); 133 | oldresult=*result_ptr; 134 | } 135 | } 136 | 137 | #else 138 | *result_ptr=pow(operand[0],operand[1]); 139 | #endif 140 | break; 141 | #endif 142 | #ifdef HAVE_MODULO_OP 143 | case modulo_op: 144 | if(operand[1]==0) 145 | abort_sum(-1,"modulo div by zero aborting sum "NUMBER_FORMAT 146 | "%%"NUMBER_FORMAT,operand[0],operand[1]); 147 | #ifdef NUM_INTEGER_BITS 148 | *result_ptr=operand[0]%operand[1]; 149 | #else 150 | { 151 | number_t n=operand[0]/operand[1]; 152 | int_t n1; 153 | if(number_to_int_t(&n,&n1)) 154 | abort_sum(-1,"number out of range\n"); 155 | 156 | *result_ptr=n-n1; 157 | } 158 | #endif 159 | break; 160 | #endif 161 | #ifdef HAVE_AND_OP 162 | case and_op: 163 | *result_ptr=(uint_t)operand[0]&(uint_t)operand[1]; 164 | break; 165 | #endif 166 | #ifdef HAVE_OR_OP 167 | case or_op: 168 | *result_ptr=(uint_t)operand[0]|(uint_t)operand[1]; 169 | break; 170 | #endif 171 | #ifdef HAVE_XOR_OP 172 | case xor_op: 173 | *result_ptr=(uint_t)operand[0]^(uint_t)operand[1]; 174 | break; 175 | #endif 176 | #ifdef HAVE_LOG_SHIFT_OP 177 | case log_shift_op: 178 | #ifdef SIGNED_OPERATION 179 | if(IS_NEGATIVE(operand[1])) 180 | *result_ptr=((uint_t)operand[0])>>(MAKE_POSITIVE(operand[1])); 181 | else 182 | #endif 183 | *result_ptr=((uint_t)operand[0])<>(uint_t)operand[1]; 189 | break; 190 | #endif 191 | #ifdef HAVE_LOG_LSHIFT_OP 192 | case log_lshift_op: 193 | *result_ptr=(uint_t)operand[0]<<(uint_t)operand[1]; 194 | break; 195 | #endif 196 | #ifdef HAVE_ARITH_SHIFT_OP 197 | case arith_shift_op: 198 | if(IS_NEGATIVE(operand[1])) 199 | *result_ptr=SIGN_EXTEND((uint_t)operand[0])>>(MAKE_POSITIVE((uint_t)operand[1])); 200 | else 201 | *result_ptr=(uint_t)operand[0]<<(uint_t)operand[1]; 202 | break; 203 | #endif 204 | #ifdef HAVE_ROTATE_OP 205 | case rotate_op: 206 | { 207 | uint_t rotval; 208 | 209 | #ifdef SIGNED_OPERATION 210 | if(IS_NEGATIVE(operand[1])) 211 | { 212 | rotval=(MAKE_POSITIVE((uint_t)operand[1]))&(NUM_INTEGER_BITS-1); 213 | *result_ptr=((((uint__t)operand[0])>>rotval)| 214 | (((uint_t)operand[0])<<(NUM_INTEGER_BITS-rotval))); 215 | } 216 | else 217 | #endif 218 | { 219 | rotval=operand[1]&(NUM_INTEGER_BITS-1); 220 | *result_ptr=((((uint_t)operand[0])<>(NUM_INTEGER_BITS-rotval))); 222 | } 223 | } 224 | break; 225 | #endif 226 | #ifdef HAVE_LROTATE_OP 227 | case lrotate_op: 228 | { 229 | number_t rotval; 230 | 231 | rotval=operand[1]&(NUM_INTEGER_BITS-1); 232 | *result_ptr=((((uint_t)operand[0])<>(NUM_INTEGER_BITS-rotval))); 234 | } 235 | break; 236 | #endif 237 | #ifdef HAVE_RROTATE_OP 238 | case rrotate_op: 239 | { 240 | number_t rotval; 241 | 242 | rotval=operand[1]&(NUM_INTEGER_BITS-1); 243 | *result_ptr=((((uint_t)operand[0])>>rotval)| 244 | (((uint_t)operand[0])<<(NUM_INTEGER_BITS-rotval))); 245 | } 246 | break; 247 | #endif 248 | #ifdef HAVE_MASK_OP 249 | case mask_op: 250 | { 251 | number_t mask[2],shiftval[2]; 252 | 253 | shiftval[0]=((operand[0])&NUM_INTEGER_BITS-1); 254 | shiftval[1]=((operand[1])&NUM_INTEGER_BITS-1); 255 | mask[0]=~(((uint_t)-1)<>(operand[1]&(NUM_INTEGER_BITS-1)))&1; 267 | break; 268 | #endif 269 | #ifdef HAVE_LN_OP 270 | case ln_op: 271 | /* log(operand[1]) to base operand[0] = log(operand[1])/ log operand[0] */ 272 | if(operand[0]<0||operand[1]<0||operand[0]==1) 273 | abort_sum(-1,"can't do log("NUMBER_FORMAT")/log("NUMBER_FORMAT")",operand[1],operand[0]); 274 | *result_ptr=log(operand[1])/log(operand[0]); 275 | break; 276 | #endif 277 | #ifdef HAVE_GCD_OP 278 | case gcd_op: 279 | if(SIGN_EXTEND((uint_t)operand[0])<=0||SIGN_EXTEND((uint_t)operand[1])<=0) 280 | abort_sum(-1,"can't do gcd("NUMBER_FORMAT","NUMBER_FORMAT")",operand[0],operand[1]); 281 | *result_ptr=euclid_calc_gcd(operand[0],operand[1]); 282 | break; 283 | #endif 284 | #ifdef HAVE_EQ_COND 285 | case eq_cond: 286 | *result_ptr=(operand[0]==operand[1] ? 1:0); 287 | break; 288 | #endif 289 | #ifdef HAVE_GT_COND 290 | case gt_cond: 291 | *result_ptr=(SIGN_EXTEND(operand[0])>SIGN_EXTEND(operand[1]) ? 1:0); 292 | break; 293 | #endif 294 | #ifdef HAVE_GE_COND 295 | case ge_cond: 296 | *result_ptr=(SIGN_EXTEND(operand[0])>=SIGN_EXTEND(operand[1]) ? 1:0); 297 | break; 298 | #endif 299 | #ifdef HAVE_LT_COND 300 | case lt_cond: 301 | *result_ptr=(SIGN_EXTEND(operand[0])SIGN_EXTEND(operand[1]) ? operand[0]:operand[1]); 317 | break; 318 | #endif 319 | default: 320 | return -2; 321 | } 322 | return 0; 323 | } 324 | #endif 325 | 326 | /* if this is modified fix simplify_sum too */ 327 | int do_sum(number_t **result_stack_head_ptrptr,stack_entry *curr) 328 | { 329 | number_t *operand,*result_ptr; 330 | operation op=curr->val; 331 | depth_t depth_change=1-op_depth[curr->val]; 332 | int retval; 333 | *result_stack_head_ptrptr+=depth_change; 334 | operand=result_ptr=(*result_stack_head_ptrptr)-1; 335 | 336 | switch(op) 337 | { 338 | #ifdef HAVE_FACTORIAL_OP 339 | case factorial_op: 340 | if(SIGN_EXTEND(operand[0])<0||SIGN_EXTEND(operand[0])>max_factorial) 341 | abort_sum(-1,"factorial out of bounds " 342 | NUMBER_FORMAT,operand[0]); 343 | *result_ptr= 344 | factorials[ 345 | #ifndef NUM_INTEGER_BITS 346 | (int_t) 347 | #endif 348 | operand[0]]; 349 | break; 350 | #endif 351 | 352 | #ifdef HAVE_ABS_OP 353 | case abs_op: 354 | if(IS_NEGATIVE(operand[0])) 355 | *result_ptr=MAKE_POSITIVE(operand[0]); 356 | break; 357 | #endif 358 | #ifdef HAVE_FLOOR_OP 359 | case floor_op: 360 | *result_ptr=floor(operand[0]); 361 | break; 362 | #endif 363 | #ifdef HAVE_CEIL_OP 364 | case ceil_op: 365 | *result_ptr=ceil(operand[0]); 366 | break; 367 | #endif 368 | #ifdef HAVE_RINT_OP 369 | case rint_op: 370 | *result_ptr=rint(operand[0]); 371 | break; 372 | #endif 373 | #ifdef HAVE_SIN_OP 374 | case sin_op: 375 | *result_ptr=sin(operand[0]); 376 | break; 377 | #endif 378 | #ifdef HAVE_COS_OP 379 | case cos_op: 380 | *result_ptr=cos(operand[0]); 381 | break; 382 | #endif 383 | #ifdef HAVE_TAN_OP 384 | case tan_op: 385 | *result_ptr=tan(operand[0]); 386 | break; 387 | #endif 388 | #ifdef HAVE_ONES_COMPLIMENT_OP 389 | case ones_compliment_op: 390 | *result_ptr=~operand[0]; 391 | break; 392 | 393 | #endif 394 | #ifdef HAVE_NOT_OP 395 | case not_op: 396 | *result_ptr=!operand[0]; 397 | break; 398 | #endif 399 | default: 400 | #ifdef HAVE_BINARY_OPERATORS 401 | if((retval=do_binary_sum(result_ptr,operand,curr))==-2) 402 | #endif 403 | exit_error("bad operation %d",op); 404 | #ifdef HAVE_BINARY_OPERATORS 405 | else 406 | return retval; 407 | #endif 408 | } 409 | return(0); 410 | } 411 | -------------------------------------------------------------------------------- /print_sum.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of fundamental a brute force searcher 3 | for relationships between constants & formulae for sequences. 4 | Copyright (C) 2004 D.J. Barrow dj_barrow@ariasoft.ie barrow_dj@yahoo.com 5 | 6 | It is licensed under GPL v2.1. 7 | */ 8 | #include "fundamental.h" 9 | #include 10 | #include "utils.h" 11 | #include 12 | #include 13 | #include 14 | 15 | char *operator_str[num_operators+1]= 16 | { 17 | #ifdef HAVE_FACTORIAL_OP 18 | "!", 19 | #endif 20 | #ifdef HAVE_ABS_OP 21 | "abs", 22 | #endif 23 | #ifdef HAVE_FLOOR_OP 24 | "floor", 25 | #endif 26 | #ifdef HAVE_CEIL_OP 27 | "ceil", 28 | #endif 29 | #ifdef HAVE_RINT_OP 30 | "rint", 31 | #endif 32 | #ifdef HAVE_SIN_OP 33 | "sin", 34 | #endif 35 | #ifdef HAVE_COS_OP 36 | "cos", 37 | #endif 38 | #ifdef HAVE_TAN_OP 39 | "tan", 40 | #endif 41 | #ifdef HAVE_ONES_COMPLIMENT_OP 42 | "compliment", 43 | #endif 44 | #ifdef HAVE_NOT_OP 45 | "not", 46 | #endif 47 | #ifdef HAVE_ADDITION_OP 48 | "+", 49 | #endif 50 | #ifdef HAVE_SUBTRACTION_OP 51 | "-", 52 | #endif 53 | #ifdef HAVE_MULTIPLY_OP 54 | "*", 55 | #endif 56 | #ifdef HAVE_DIVIDE_OP 57 | "/", 58 | #endif 59 | #ifdef HAVE_POWER_OP 60 | "power", 61 | #endif 62 | #ifdef HAVE_MODULO_OP 63 | "%", 64 | #endif 65 | #ifdef HAVE_AND_OP 66 | "and", 67 | #endif 68 | #ifdef HAVE_OR_OP 69 | "or", 70 | #endif 71 | #ifdef HAVE_XOR_OP 72 | "xor", 73 | #endif 74 | #ifdef HAVE_LOG_SHIFT_OP 75 | "log_shift", 76 | #endif 77 | #ifdef HAVE_LOG_RSHIFT_OP 78 | "log_rshift", 79 | #endif 80 | #ifdef HAVE_LOG_LSHIFT_OP 81 | "log_lshift", 82 | #endif 83 | #ifdef HAVE_ARITH_SHIFT_OP 84 | "arith_shift", 85 | #endif 86 | #ifdef HAVE_ROTATE_OP 87 | "rotate", 88 | #endif 89 | #ifdef HAVE_LROTATE_OP 90 | "lrotate", 91 | #endif 92 | #ifdef HAVE_RROTATE_OP 93 | "rrotate", 94 | #endif 95 | #ifdef HAVE_MASK_OP 96 | "mask", 97 | #endif 98 | #ifdef HAVE_GETBIT_OP 99 | "getbit", 100 | #endif 101 | #ifdef HAVE_LN_OP 102 | "ln", 103 | #endif 104 | #ifdef HAVE_GCD_OP 105 | "gcd", 106 | #endif 107 | #ifdef HAVE_EQ_COND 108 | "==", 109 | #endif 110 | #ifdef HAVE_GT_COND 111 | ">", 112 | #endif 113 | #ifdef HAVE_GE_COND 114 | ">=", 115 | #endif 116 | #ifdef HAVE_LT_COND 117 | "<", 118 | #endif 119 | #ifdef HAVE_LE_COND 120 | "<=", 121 | #endif 122 | #ifdef HAVE_AND_COND 123 | "&&", 124 | #endif 125 | #ifdef HAVE_OR_COND 126 | "||", 127 | #endif 128 | #ifdef HAVE_MIN_OP 129 | "min", 130 | #endif 131 | #ifdef HAVE_MAX_OP 132 | "max", 133 | #endif 134 | (char *)0xdeadbeef, 135 | }; 136 | 137 | 138 | 139 | 140 | #if defined(MULTIPLE_RESULTS) || defined(HAVE_FUNCTIONS) 141 | void print_sum_preamble(sum_t *sum) 142 | { 143 | #ifdef MULTIPLE_RESULTS 144 | dimension_t curr_result; 145 | #endif 146 | #ifdef HAVE_FUNCTIONS 147 | printf("seed=%d ",sum->seed); 148 | #endif 149 | #ifdef MULTIPLE_RESULTS 150 | for(curr_result=0;curr_result=sum->stack_depth||rec_depth<0) 169 | return; 170 | curr=&sum->stack[rec_depth]; 171 | curr_tree_member=tree_members[rec_depth]; 172 | #ifdef SIGNED_OPERATION 173 | if(curr->minus) 174 | printf("-"); 175 | #endif 176 | 177 | switch(curr->tag) 178 | { 179 | #ifdef HUNTER 180 | #ifdef HAVE_FUNCTIONS 181 | case function_tag: 182 | printf("f"); 183 | goto print_comma_seperated; 184 | break; 185 | #endif 186 | case dimension_tag: 187 | printf("n["DIMENSION_FORMAT"]",curr->val); 188 | break; 189 | #endif 190 | #ifdef HAVE_CONSTANTS_FILE 191 | case constant_tag: 192 | if(pass) 193 | printf(NUMBER_FORMAT" ",fundamental_list[curr->val]->value); 194 | else 195 | printf("%s",fundamental_list[curr->val]->name); 196 | break; 197 | #endif 198 | case integer_tag: 199 | printf(STACKVAL_FORMAT,curr->val); 200 | break; 201 | case arithmetic_operation_tag: 202 | op=curr->val; 203 | #ifdef HAVE_UNARY_OPERATORS 204 | if(curr_tree_member->depth==1) 205 | { 206 | switch(op) 207 | { 208 | #ifdef HAVE_FACTORIAL_OP 209 | case factorial_op: 210 | printf("("); 211 | recurse_sum_infix(curr_tree_member->child[0],sum); 212 | printf(")%s",operator_str[curr->val]); 213 | break; 214 | #endif 215 | default: 216 | printf("%s(",operator_str[curr->val]); 217 | recurse_sum_infix(curr_tree_member->child[0],sum); 218 | printf(")"); 219 | break; 220 | } 221 | } 222 | else 223 | #endif 224 | #ifdef HAVE_BINARY_OPERATORS 225 | { 226 | switch(op) 227 | { 228 | #ifdef HAVE_ADDITION_OP 229 | case addition_op: 230 | #endif 231 | #ifdef HAVE_SUBTRACTION_OP 232 | case subtraction_op: 233 | #endif 234 | #ifdef HAVE_MULTIPLY_OP 235 | case multiply_op: 236 | #endif 237 | #ifdef HAVE_DIVIDE_OP 238 | case divide_op: 239 | #endif 240 | #ifdef HAVE_MODULO_OP 241 | case modulo_op: 242 | #endif 243 | #ifdef HAVE_AND_OP 244 | case and_op: 245 | #endif 246 | #ifdef HAVE_OR_OP 247 | case or_op: 248 | #endif 249 | #ifdef HAVE_XOR_OP 250 | case xor_op: 251 | #endif 252 | #ifdef HAVE_LOG_SHIFT_OP 253 | case log_shift_op: 254 | #endif 255 | #ifdef HAVE_LOG_RSHIFT_OP 256 | case log_rshift_op: 257 | #endif 258 | #ifdef HAVE_LOG_LSHIFT_OP 259 | case log_lshift_op: 260 | #endif 261 | #ifdef HAVE_ARITH_SHIFT_OP 262 | case arith_shift_op: 263 | #endif 264 | #ifdef HAVE_ROTATE_OP 265 | case rotate_op: 266 | #endif 267 | #ifdef HAVE_LROTATE_OP 268 | case lrotate_op: 269 | #endif 270 | #ifdef HAVE_RROTATE_OP 271 | case rrotate_op: 272 | #endif 273 | printf("("); 274 | recurse_sum_infix(curr_tree_member->child[0],sum); 275 | #if defined(ARITHMETIC_OPERATORS)&&defined(SIGNED_OPERATION) 276 | if(op!=addition||!stack[curr_tree_member->child[1]].minus) 277 | #endif 278 | printf(" %s ",operator_str[curr->val]); 279 | recurse_sum_infix(curr_tree_member->child[1],sum); 280 | printf(")"); 281 | break; 282 | 283 | default: 284 | printf("%s",operator_str[curr->val]); 285 | goto print_comma_seperated; 286 | } 287 | } 288 | #endif 289 | break; 290 | } 291 | return; 292 | print_comma_seperated: 293 | printf("("); 294 | for(curr_child=0;curr_childdepth;curr_child++) 295 | { 296 | recurse_sum_infix(curr_tree_member->child[curr_child],sum); 297 | if(curr_childdepth-1) 298 | printf(","); 299 | } 300 | printf(")"); 301 | return; 302 | } 303 | 304 | void print_sum_infix(sum_t *sum) 305 | { 306 | struct infix_tree *curr_tree_member; 307 | int idx,idx1; 308 | depth_t depth; 309 | 310 | stack_entry *curr; 311 | memset(tree_members,0,sizeof(struct infix_tree *)*sum->stack_depth); 312 | for(idx=0;idxstack_depth;idx++) 313 | { 314 | curr=&sum->stack[idx]; 315 | depth=(is_operator(curr->tag) ? get_op_depth(curr):0); 316 | curr_tree_member=tree_members[idx]=alloca(offsetof(struct infix_tree,child[depth])); 317 | curr_tree_member->has_parent=FALSE; 318 | curr_tree_member->depth=depth; 319 | for(idx1=idx-1;idx1>=0&&depth>0;idx1--) 320 | { 321 | if(!tree_members[idx1]->has_parent) 322 | { 323 | tree_members[idx1]->has_parent=TRUE; 324 | curr_tree_member->child[--depth]=idx1; 325 | } 326 | } 327 | #if 0 328 | if(depth!=0&&debug) 329 | exit_error("bug in print_sum_infix\n"); 330 | #endif 331 | } 332 | #ifdef HAVE_CONSTANTS_FILE 333 | for(pass=0;pass<(fundamental_list ? 2:1);pass++) 334 | #endif 335 | { 336 | recurse_sum_infix(sum->stack_depth-1,sum); 337 | printf("\n"); 338 | } 339 | } 340 | #endif 341 | 342 | #ifdef HAVE_PRINT_SUM_RPN 343 | void print_sum_rpn(sum_t *sum) 344 | { 345 | int idx 346 | #ifdef HAVE_CONSTANTS_FILE 347 | ,pass 348 | #endif 349 | ; 350 | stack_entry *curr; 351 | #ifdef HAVE_CONSTANTS_FILE 352 | for(pass=0;pass<(fundamental_list ? 2:1);pass++) 353 | #endif 354 | { 355 | for(idx=0;idxstack_depth;idx++) 356 | { 357 | curr=&sum->stack[idx]; 358 | #ifdef SIGNED_OPERATION 359 | if(curr->minus) 360 | printf("-"); 361 | #endif 362 | switch(curr->tag) 363 | { 364 | #ifdef HUNTER 365 | #ifdef HAVE_FUNCTIONS 366 | case function_tag: 367 | printf("f "); 368 | break; 369 | #endif 370 | case dimension_tag: 371 | printf("n["DIMENSION_FORMAT"] ",curr->val); 372 | break; 373 | #endif 374 | #ifdef HAVE_CONSTANTS_FILE 375 | case constant_tag: 376 | if(pass) 377 | printf(NUMBER_FORMAT" ",fundamental_list[curr->val]->value); 378 | else 379 | printf("%s ",fundamental_list[curr->val]->name); 380 | break; 381 | #endif 382 | case integer_tag: 383 | printf(STACKVAL_FORMAT" ",curr->val); 384 | break; 385 | case arithmetic_operation_tag: 386 | printf(" %s ",operator_str[curr->val]); 387 | break; 388 | } 389 | } 390 | 391 | } 392 | printf("\n"); 393 | } 394 | #endif 395 | 396 | void print_sum_postamble(sum_t *sum) 397 | { 398 | if(max_num_answers!=-1) 399 | { 400 | num_answers++; 401 | if(num_answers>=max_num_answers) 402 | exit(0); 403 | } 404 | } 405 | 406 | void print_sum(sum_t *sum) 407 | { 408 | #if 0 409 | print_sum_preamble(sum); 410 | #endif 411 | print_sum_rpn(sum); 412 | print_sum_infix(sum); 413 | print_sum_postamble(sum); 414 | } 415 | 416 | #ifdef HAVE_ERROR_MEASUREMENTS 417 | char *error_measurment_str[NUM_ERROR_MEASUREMENTS]= 418 | { 419 | #ifdef HAVE_LMS_ERROR 420 | "lms", 421 | #endif 422 | #ifdef HAVE_ABS_ERROR 423 | "abs", 424 | #endif 425 | #ifdef HAVE_LMS_RATIOED_ERROR 426 | "lms ratioed", 427 | #endif 428 | #ifdef HAVE_ABS_RATIOED_ERROR 429 | "abs ratioed", 430 | #endif 431 | #ifdef HAVE_LMS_GT_ERROR 432 | "lms gt", 433 | #endif 434 | #ifdef HAVE_GT_ERROR 435 | "gt", 436 | #endif 437 | #ifdef HAVE_LMS_GT_RATIOED_ERROR 438 | "lms gt ratioed", 439 | #endif 440 | #ifdef HAVE_GT_RATIOED_ERROR 441 | "gt ratioed", 442 | #endif 443 | #ifdef HAVE_LMS_LT_ERROR 444 | "lms lt", 445 | #endif 446 | #ifdef HAVE_LT_ERROR 447 | "lt error", 448 | #endif 449 | #ifdef HAVE_LMS_LT_RATIOED_ERROR 450 | "lms lt ratioed", 451 | #endif 452 | #ifdef HAVE_LT_RATIOED_ERROR 453 | "lt ratioed", 454 | #endif 455 | }; 456 | 457 | #ifdef HAVE_DEBUG_ERROR_LIST 458 | void debug_error_list_func(calculate_sum_result *retval) 459 | { 460 | result_t testvals=*get_array_member(array_indices); 461 | #ifdef MULTIPLE_RESULTS 462 | int curr_answer,num_answers= 463 | #ifdef NUM_ANSWERS 464 | NUM_ANSWERS 465 | #else 466 | testvals->num_answers 467 | #endif 468 | ; 469 | number_t *answers= 470 | #if (!defined(NUM_ANSWERS)||defined(SPARSE_ARRAY_INDICES)) 471 | &testvals->answer[0]; 472 | #else 473 | &testvals.answer[0]; 474 | #endif 475 | 476 | for(curr_answer=0;curr_answererror_val); 506 | print_sum(&element->sum); 507 | #ifdef HAVE_DEBUG_ERROR_LIST 508 | { 509 | calculate_sum_result result=calculate_sum(&element->sum,debug_error_list_func); 510 | if(result.aborted) 511 | { 512 | fprintf(stderr,"BUG DEBUG_ERROR_LIST sum is illegal"); 513 | print_sum(&element->sum); 514 | exit(-1); 515 | } 516 | } 517 | #endif 518 | } 519 | } 520 | } 521 | } 522 | #endif 523 | -------------------------------------------------------------------------------- /simplify.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of fundamental a brute force searcher 3 | for relationships between constants & formulae for sequences. 4 | Copyright (C) 2004 D.J. Barrow dj_barrow@ariasoft.ie barrow_dj@yahoo.com 5 | 6 | It is licensed under GPL v2.1. 7 | */ 8 | #if 0 9 | #include "fundamental.h" 10 | #include "utils.h" 11 | #ifdef HAVE_SIMPLIFICATION_TEST 12 | /* 13 | This file has still to be written 14 | it is supposed to get rid of duplicate answers 15 | e.g. 3-3 = 0 , 3! = 6 & see if simplified versions 16 | of the sums may already be printed. 17 | 18 | Ideas 19 | First step is to evaluate integers then constants added multiplied 20 | divided together directly. 21 | Log tables for sine & cosine simplifications. 22 | Mathematics dictionary communative,distbutative,associative. 23 | Google for mathematics simplification algorithms. 24 | Common subexpression elimination see compiler books e.g. dragon book 25 | (requires 2 expressions for CSE to be useful in some cases, but may be useful in cases like (a*b)+(a*d)=a*(b+d)). 26 | Do test see if simplified sum & original sum aggree. 27 | Logic shift simplification for multiply divide of integers. 28 | Make algorithm iterative & keep repeating till no further simplifications 29 | occur. 30 | Boolean simplifications. 31 | Check whether simplified result already was generated. 32 | */ 33 | 34 | sum_t *simplify_sum=NULL; 35 | typedef struct 36 | { 37 | number_t result; 38 | simplify_result_tag_t result_tag; 39 | } simplify_result_t; 40 | 41 | simplify_result_t *simplify_result_stack=NULL; 42 | 43 | 44 | void init_simplifyable(void) 45 | { 46 | simplify_sum=(sum_t *)myalloc("simplify_sum",offsetof(sum_t,stack[max_stack_depth])); 47 | simplify_result_stack=(simplify_result_t *)myalloc("simplify_result_stack",sizeof(simplify_result_t)* 48 | ((max_stack_depth>>1) 49 | #if MAX_NUM_LOOPVARS 50 | +1 51 | #endif 52 | )); 53 | } 54 | 55 | 56 | #ifdef HAVE_BINARY_OPERATORS 57 | int do_simplify_binary_sum(simplify_result_t *simplify_result_ptr,number_t *operand,stack_entry *curr) 58 | { 59 | number_t *result_ptr=&simplify_result_ptr->result; 60 | operation op=curr->val; 61 | switch(op) 62 | { 63 | #ifdef HAVE_ADDITION_OP 64 | case addition_op: 65 | *result_ptr=operand[0]+operand[1]; 66 | break; 67 | #endif 68 | #ifdef HAVE_SUBTRACTION_OP 69 | case subtraction_op: 70 | *result_ptr=operand[0]-operand[1]; 71 | break; 72 | #endif 73 | #ifdef HAVE_MULTIPLY_OP 74 | case multiply_op: 75 | *result_ptr=SIGN_EXTEND(operand[0])*SIGN_EXTEND(operand[1]); 76 | break; 77 | #endif 78 | #ifdef HAVE_DIVIDE_OP 79 | case divide_op: 80 | if(operand[1]==0) 81 | abort_sum(-1,"division by zero aborting sum " 82 | NUMBER_FORMAT"/"NUMBER_FORMAT,operand[0],operand[1]); 83 | *result_ptr=SIGN_EXTEND(operand[0])/SIGN_EXTEND(operand[1]); 84 | break; 85 | #endif 86 | #ifdef HAVE_POWER_OP 87 | case power_op: 88 | #ifdef NUM_INTEGER_BITS 89 | #ifndef SIGNED_OPERATION 90 | if(IS_NEGATIVE(operand[1])) 91 | abort_sum(-1,"int power less than 0 aborting sum pow(" 92 | NUMBER_FORMAT","NUMBER_FORMAT")",operand[0],operand[1]); 93 | #endif 94 | if(operand[0]==0) 95 | { 96 | *result_ptr=0; 97 | break; 98 | } 99 | *result_ptr=1; 100 | if(operand[0]==1) 101 | break; 102 | if(operand[0]==-1) 103 | { 104 | if(operand[1]&1) 105 | *result_ptr=-1; 106 | break; 107 | } 108 | { 109 | number_t idx,oldresult=1; 110 | for(idx=1;idx<=operand[1];idx++) 111 | { 112 | *result_ptr*=operand[0]; 113 | if((*result_ptr/operand[0])!=oldresult) 114 | abort_sum(-1,"overflow aborting sum pow(" 115 | NUMBER_FORMAT","NUMBER_FORMAT")",operand[0],operand[1]); 116 | oldresult=*result_ptr; 117 | } 118 | } 119 | 120 | #else 121 | *result_ptr=pow(operand[0],operand[1]); 122 | #endif 123 | break; 124 | #endif 125 | #ifdef HAVE_MODULO_OP 126 | case modulo_op: 127 | if(operand[1]==0) 128 | abort_sum(-1,"modulo div by zero aborting sum "NUMBER_FORMAT 129 | "%"NUMBER_FORMAT,operand[0],operand[1]); 130 | #ifdef NUM_INTEGER_BITS 131 | *result_ptr=operand[0]%operand[1]; 132 | #else 133 | { 134 | number_t n=operand[0]/operand[1]; 135 | int_t n1; 136 | if(number_to_int_t(&n,&n1)) 137 | abort_sum(-1,"number out of range\n"); 138 | 139 | *result_ptr=n-n1; 140 | } 141 | #endif 142 | break; 143 | #endif 144 | #ifdef HAVE_AND_OP 145 | case and_op: 146 | *result_ptr=operand[0]&operand[1]; 147 | break; 148 | #endif 149 | #ifdef HAVE_OR_OP 150 | case or_op: 151 | *result_ptr=operand[0]|operand[1]; 152 | break; 153 | #endif 154 | #ifdef HAVE_XOR_OP 155 | case xor_op: 156 | *result_ptr=operand[0]^operand[1]; 157 | break; 158 | #endif 159 | #ifdef HAVE_LOG_SHIFT_OP 160 | case log_shift_op: 161 | #ifdef SIGNED_OPERATION 162 | if(IS_NEGATIVE(operand[1])) 163 | *result_ptr=((unsigned_number_t)operand[0])>>(MAKE_POSITIVE(operand[1])); 164 | else 165 | #endif 166 | *result_ptr=((unsigned_number_t)operand[0])<>operand[1]; 172 | break; 173 | #endif 174 | #ifdef HAVE_LOG_LSHIFT_OP 175 | case log_lshift_op: 176 | *result_ptr=operand[0]<>(MAKE_POSITIVE(operand[1])); 183 | else 184 | *result_ptr=operand[0]<>rotval)| 197 | (((unsigned_number_t)operand[0])<<(NUM_INTEGER_BITS-rotval))); 198 | } 199 | else 200 | #endif 201 | { 202 | rotval=operand[1]&(NUM_INTEGER_BITS-1); 203 | *result_ptr=((((unsigned_number_t)operand[0])<>(NUM_INTEGER_BITS-rotval))); 205 | } 206 | } 207 | break; 208 | #endif 209 | #ifdef HAVE_LROTATE_OP 210 | case lrotate_op: 211 | { 212 | number_t rotval; 213 | 214 | rotval=operand[1]&(NUM_INTEGER_BITS-1); 215 | *result_ptr=((((unsigned_number_t)operand[0])<>(NUM_INTEGER_BITS-rotval))); 217 | } 218 | break; 219 | #endif 220 | #ifdef HAVE_RROTATE_OP 221 | case rrotate_op: 222 | { 223 | number_t rotval; 224 | 225 | rotval=operand[1]&(NUM_INTEGER_BITS-1); 226 | *result_ptr=((((unsigned_number_t)operand[0])>>rotval)| 227 | (((unsigned_number_t)operand[0])<<(NUM_INTEGER_BITS-rotval))); 228 | } 229 | break; 230 | #endif 231 | #ifdef HAVE_MASK_OP 232 | case mask_op: 233 | { 234 | number_t mask[2],shiftval[2]; 235 | 236 | shiftval[0]=((operand[0])&NUM_INTEGER_BITS-1); 237 | shiftval[1]=((operand[1])&NUM_INTEGER_BITS-1); 238 | mask[0]=~(((unsigned_number_t)-1)<>(operand[1]&(NUM_INTEGER_BITS-1)))&1; 250 | break; 251 | #endif 252 | #ifdef HAVE_LN_OP 253 | case ln_op: 254 | /* log(operand[1]) to base operand[0] = log(operand[1])/ log operand[0] */ 255 | if(operand[0]<0||operand[1]<0||operand[0]==1) 256 | abort_sum(-1,"can't do log("NUMBER_FORMAT")/log("NUMBER_FORMAT")",operand[1],operand[0]); 257 | *result_ptr=log(operand[1])/log(operand[0]); 258 | break; 259 | #endif 260 | #ifdef HAVE_GCD_OP 261 | case gcd_op: 262 | if(SIGN_EXTEND(operand[0])<=0||SIGN_EXTEND(operand[1])<=0) 263 | abort_sum(-1,"can't do gcd("NUMBER_FORMAT","NUMBER_FORMAT")",operand[0],operand[1]); 264 | *result_ptr=euclid_calc_gcd(operand[0],operand[1]); 265 | break; 266 | #endif 267 | #ifdef HAVE_EQ_COND 268 | case eq_cond: 269 | *result_ptr=(operand[0]==operand[1] ? 1:0); 270 | break; 271 | #endif 272 | #ifdef HAVE_GT_COND 273 | case gt_cond: 274 | *result_ptr=(SIGN_EXTEND(operand[0])>SIGN_EXTEND(operand[1]) ? 1:0); 275 | break; 276 | #endif 277 | #ifdef HAVE_GE_COND 278 | case ge_cond: 279 | *result_ptr=(SIGN_EXTEND(operand[0])>=SIGN_EXTEND(operand[1]) ? 1:0); 280 | break; 281 | #endif 282 | #ifdef HAVE_LT_COND 283 | case lt_cond: 284 | *result_ptr=(SIGN_EXTEND(operand[0])SIGN_EXTEND(operand[1]) ? operand[0]:operand[1]); 300 | break; 301 | #endif 302 | default: 303 | return -2; 304 | } 305 | return 0; 306 | } 307 | #endif 308 | 309 | int do_simplify_sum(simplify_result_t **result_stack_head_ptrptr,stack_entry *curr) 310 | { 311 | number_t *operand,*result_ptr; 312 | operation op=curr->val; 313 | depth_t depth_change=1-op_depth[curr->val]; 314 | int retval; 315 | *result_stack_head_ptrptr+=depth_change; 316 | operand=result_ptr=(((*result_stack_head_ptrptr)-1)->result); 317 | 318 | switch(op) 319 | { 320 | #ifdef HAVE_FACTORIAL_OP 321 | case factorial_op: 322 | if(SIGN_EXTEND(operand[0])<1||SIGN_EXTEND(operand[0])>max_factorial) 323 | abort_sum(-1,"factorial out of bounds " 324 | NUMBER_FORMAT,operand[0]); 325 | *result_ptr= 326 | factorials[ 327 | #ifndef NUM_INTEGER_BITS 328 | (int_t) 329 | #endif 330 | operand[0]-1]; 331 | break; 332 | #endif 333 | 334 | #ifdef HAVE_ABS_OP 335 | case abs_op: 336 | if(IS_NEGATIVE(operand[0])) 337 | *result_ptr=MAKE_POSITIVE(operand[0]); 338 | break; 339 | #endif 340 | #ifdef HAVE_FLOOR_OP 341 | case floor_op: 342 | *result_ptr=floor(operand[0]); 343 | break; 344 | #endif 345 | #ifdef HAVE_CEIL_OP 346 | case ceil_op: 347 | *result_ptr=ceil(operand[0]); 348 | break; 349 | #endif 350 | #ifdef HAVE_RINT_OP 351 | case rint_op: 352 | *result_ptr=rint(operand[0]); 353 | break; 354 | #endif 355 | #ifdef HAVE_SIN_OP 356 | case sin_op: 357 | *result_ptr=sin(operand[0]); 358 | break; 359 | #endif 360 | #ifdef HAVE_COS_OP 361 | case cos_op: 362 | *result_ptr=cos(operand[0]); 363 | break; 364 | #endif 365 | #ifdef HAVE_TAN_OP 366 | case tan_op: 367 | *result_ptr=tan(operand[0]); 368 | break; 369 | #endif 370 | #ifdef HAVE_ONES_COMPLIMENT_OP 371 | case ones_compliment_op: 372 | *result_ptr=~operand[0]; 373 | break; 374 | 375 | #endif 376 | #ifdef HAVE_NOT_OP 377 | case not_op: 378 | *result_ptr=!operand[0]; 379 | break; 380 | #endif 381 | default: 382 | #ifdef HAVE_BINARY_OPERATORS 383 | if((retval=do_binary_sum(result_ptr,operand,curr))==-2) 384 | #endif 385 | exit_error("bad operation %d",op); 386 | #ifdef HAVE_BINARY_OPERATORS 387 | else 388 | return retval; 389 | #endif 390 | } 391 | return(0); 392 | } 393 | 394 | simplify_result_t *curr_simplify_result_ptr; 395 | int simplify_sum_switch(stack_entry *curr) 396 | { 397 | switch(curr->tag) 398 | { 399 | case integer_tag: 400 | #ifdef SIGNED_OPERATION 401 | if(curr->minus) 402 | *curr_simplify_result_ptr++=-(number_t)curr->val; 403 | else 404 | #endif 405 | *curr_simplify_result_ptr++=(number_t)curr->val; 406 | break; 407 | case arithmetic_operation_tag: 408 | if(do_simplify_sum(&curr_simplify_result_ptr,curr)) 409 | return TRUE; 410 | break; 411 | default: 412 | break; 413 | } 414 | #ifdef RESULT_MASK 415 | *(curr_simplify_result_ptr-1)&=RESULT_MASK; 416 | #endif 417 | return FALSE; 418 | } 419 | 420 | 421 | simplify_constants(sum_t *sum) 422 | { 423 | curr_simplify_result_ptr=&simplify_result_stack[0]; 424 | for(idx=0;idxstack_depth;idx++) 425 | { 426 | retval.aborted=simplify_sum_switch(&sum->stack[idx]); 427 | if(retval.aborted) 428 | goto skip; 429 | } 430 | if(curr_simplify_result_ptr!=&result_stack[1]) 431 | { 432 | fprintf(stderr,"Sum below is illegal curr_simplify_result_ptr(%p)" 433 | "!=&result_stack[1+RESULT_STACK_START](%p)\n", 434 | curr_simplify_result_ptr,&result_stack[1]); 435 | PRINT_SUM(sum); 436 | exit(-1); 437 | } 438 | } 439 | 440 | 441 | int is_simplifyable(sum_t *sum) 442 | { 443 | memcpy(&simplify_sum,sum,offsetof(sum_t,stack[sum->stack_depth])); 444 | memset(simplify_result_tag,0,sizeof(simplify_result_tag_t)* 445 | ((sum->_stack_depth>>1) 446 | #if MAX_NUM_LOOPVARS 447 | +1 448 | #endif 449 | )); 450 | simplify_constants(simplify_sum); 451 | return 0; 452 | } 453 | #endif /* HAVE_SIMPLIFICATION_TEST */ 454 | #endif 455 | -------------------------------------------------------------------------------- /list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * I grub it from linux kernel source code and fix it for user space 4 | * program. Of course, this is a GPL licensed header file. 5 | * 6 | * Here is a recipe to cook list.h for user space program 7 | * 8 | * 1. copy list.h from linux/include/list.h 9 | * 2. remove 10 | * - #ifdef __KERNE__ and its #endif 11 | * - all #include line 12 | * - prefetch() and rcu related functions 13 | * 3. add macro offsetof() and container_of 14 | * 15 | * - kazutomo@mcs.anl.gov 16 | */ 17 | #ifndef _LINUX_LIST_H 18 | #define _LINUX_LIST_H 19 | 20 | /** 21 | * @name from other kernel headers 22 | */ 23 | /*@{*/ 24 | 25 | /** 26 | * Get offset of a member 27 | */ 28 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 29 | 30 | /** 31 | * Casts a member of a structure out to the containing structure 32 | * @param ptr the pointer to the member. 33 | * @param type the type of the container struct this is embedded in. 34 | * @param member the name of the member within the struct. 35 | * 36 | */ 37 | #define container_of(ptr, type, member) ({ \ 38 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 39 | (type *)( (char *)__mptr - offsetof(type,member) );}) 40 | /*@}*/ 41 | 42 | 43 | /* 44 | * These are non-NULL pointers that will result in page faults 45 | * under normal circumstances, used to verify that nobody uses 46 | * non-initialized list entries. 47 | */ 48 | #define LIST_POISON1 ((void *) 0x00100100) 49 | #define LIST_POISON2 ((void *) 0x00200200) 50 | 51 | /** 52 | * Simple doubly linked list implementation. 53 | * 54 | * Some of the internal functions ("__xxx") are useful when 55 | * manipulating whole lists rather than single entries, as 56 | * sometimes we already know the next/prev entries and we can 57 | * generate better code by using them directly rather than 58 | * using the generic single-entry routines. 59 | */ 60 | struct list_head { 61 | struct list_head *next, *prev; 62 | }; 63 | 64 | #define LIST_HEAD_INIT(name) { &(name), &(name) } 65 | 66 | #define LIST_HEAD(name) \ 67 | struct list_head name = LIST_HEAD_INIT(name) 68 | 69 | #define INIT_LIST_HEAD(ptr) do { \ 70 | (ptr)->next = (ptr); (ptr)->prev = (ptr); \ 71 | } while (0) 72 | 73 | /* 74 | * Insert a new entry between two known consecutive entries. 75 | * 76 | * This is only for internal list manipulation where we know 77 | * the prev/next entries already! 78 | */ 79 | static inline void __list_add(struct list_head *new, 80 | struct list_head *prev, 81 | struct list_head *next) 82 | { 83 | next->prev = new; 84 | new->next = next; 85 | new->prev = prev; 86 | prev->next = new; 87 | } 88 | 89 | /** 90 | * list_add - add a new entry 91 | * @new: new entry to be added 92 | * @head: list head to add it after 93 | * 94 | * Insert a new entry after the specified head. 95 | * This is good for implementing stacks. 96 | */ 97 | static inline void list_add(struct list_head *new, struct list_head *head) 98 | { 99 | __list_add(new, head, head->next); 100 | } 101 | 102 | /** 103 | * list_add_tail - add a new entry 104 | * @new: new entry to be added 105 | * @head: list head to add it before 106 | * 107 | * Insert a new entry before the specified head. 108 | * This is useful for implementing queues. 109 | */ 110 | static inline void list_add_tail(struct list_head *new, struct list_head *head) 111 | { 112 | __list_add(new, head->prev, head); 113 | } 114 | 115 | 116 | /* 117 | * Delete a list entry by making the prev/next entries 118 | * point to each other. 119 | * 120 | * This is only for internal list manipulation where we know 121 | * the prev/next entries already! 122 | */ 123 | static inline void __list_del(struct list_head * prev, struct list_head * next) 124 | { 125 | next->prev = prev; 126 | prev->next = next; 127 | } 128 | 129 | /** 130 | * list_del - deletes entry from list. 131 | * @entry: the element to delete from the list. 132 | * Note: list_empty on entry does not return true after this, the entry is 133 | * in an undefined state. 134 | */ 135 | static inline void list_del(struct list_head *entry) 136 | { 137 | __list_del(entry->prev, entry->next); 138 | entry->next = LIST_POISON1; 139 | entry->prev = LIST_POISON2; 140 | } 141 | 142 | 143 | 144 | /** 145 | * list_del_init - deletes entry from list and reinitialize it. 146 | * @entry: the element to delete from the list. 147 | */ 148 | static inline void list_del_init(struct list_head *entry) 149 | { 150 | __list_del(entry->prev, entry->next); 151 | INIT_LIST_HEAD(entry); 152 | } 153 | 154 | /** 155 | * list_move - delete from one list and add as another's head 156 | * @list: the entry to move 157 | * @head: the head that will precede our entry 158 | */ 159 | static inline void list_move(struct list_head *list, struct list_head *head) 160 | { 161 | __list_del(list->prev, list->next); 162 | list_add(list, head); 163 | } 164 | 165 | /** 166 | * list_move_tail - delete from one list and add as another's tail 167 | * @list: the entry to move 168 | * @head: the head that will follow our entry 169 | */ 170 | static inline void list_move_tail(struct list_head *list, 171 | struct list_head *head) 172 | { 173 | __list_del(list->prev, list->next); 174 | list_add_tail(list, head); 175 | } 176 | 177 | /** 178 | * list_empty - tests whether a list is empty 179 | * @head: the list to test. 180 | */ 181 | static inline int list_empty(const struct list_head *head) 182 | { 183 | return head->next == head; 184 | } 185 | 186 | static inline void __list_splice(struct list_head *list, 187 | struct list_head *head) 188 | { 189 | struct list_head *first = list->next; 190 | struct list_head *last = list->prev; 191 | struct list_head *at = head->next; 192 | 193 | first->prev = head; 194 | head->next = first; 195 | 196 | last->next = at; 197 | at->prev = last; 198 | } 199 | 200 | /** 201 | * list_splice - join two lists 202 | * @list: the new list to add. 203 | * @head: the place to add it in the first list. 204 | */ 205 | static inline void list_splice(struct list_head *list, struct list_head *head) 206 | { 207 | if (!list_empty(list)) 208 | __list_splice(list, head); 209 | } 210 | 211 | /** 212 | * list_splice_init - join two lists and reinitialise the emptied list. 213 | * @list: the new list to add. 214 | * @head: the place to add it in the first list. 215 | * 216 | * The list at @list is reinitialised 217 | */ 218 | static inline void list_splice_init(struct list_head *list, 219 | struct list_head *head) 220 | { 221 | if (!list_empty(list)) { 222 | __list_splice(list, head); 223 | INIT_LIST_HEAD(list); 224 | } 225 | } 226 | 227 | /** 228 | * list_entry - get the struct for this entry 229 | * @ptr: the &struct list_head pointer. 230 | * @type: the type of the struct this is embedded in. 231 | * @member: the name of the list_struct within the struct. 232 | */ 233 | #define list_entry(ptr, type, member) \ 234 | container_of(ptr, type, member) 235 | 236 | /** 237 | * list_for_each - iterate over a list 238 | * @pos: the &struct list_head to use as a loop counter. 239 | * @head: the head for your list. 240 | */ 241 | 242 | #define list_for_each(pos, head) \ 243 | for (pos = (head)->next; pos != (head); \ 244 | pos = pos->next) 245 | 246 | /** 247 | * __list_for_each - iterate over a list 248 | * @pos: the &struct list_head to use as a loop counter. 249 | * @head: the head for your list. 250 | * 251 | * This variant differs from list_for_each() in that it's the 252 | * simplest possible list iteration code, no prefetching is done. 253 | * Use this for code that knows the list to be very short (empty 254 | * or 1 entry) most of the time. 255 | */ 256 | #define __list_for_each(pos, head) \ 257 | for (pos = (head)->next; pos != (head); pos = pos->next) 258 | 259 | /** 260 | * list_for_each_prev - iterate over a list backwards 261 | * @pos: the &struct list_head to use as a loop counter. 262 | * @head: the head for your list. 263 | */ 264 | #define list_for_each_prev(pos, head) \ 265 | for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ 266 | pos = pos->prev) 267 | 268 | /** 269 | * list_for_each_safe - iterate over a list safe against removal of list entry 270 | * @pos: the &struct list_head to use as a loop counter. 271 | * @n: another &struct list_head to use as temporary storage 272 | * @head: the head for your list. 273 | */ 274 | #define list_for_each_safe(pos, n, head) \ 275 | for (pos = (head)->next, n = pos->next; pos != (head); \ 276 | pos = n, n = pos->next) 277 | 278 | /** 279 | * list_for_each_entry - iterate over list of given type 280 | * @pos: the type * to use as a loop counter. 281 | * @head: the head for your list. 282 | * @member: the name of the list_struct within the struct. 283 | */ 284 | #define list_for_each_entry(pos, head, member) \ 285 | for (pos = list_entry((head)->next, typeof(*pos), member); \ 286 | &pos->member != (head); \ 287 | pos = list_entry(pos->member.next, typeof(*pos), member)) 288 | 289 | /** 290 | * list_for_each_entry_reverse - iterate backwards over list of given type. 291 | * @pos: the type * to use as a loop counter. 292 | * @head: the head for your list. 293 | * @member: the name of the list_struct within the struct. 294 | */ 295 | #define list_for_each_entry_reverse(pos, head, member) \ 296 | for (pos = list_entry((head)->prev, typeof(*pos), member); \ 297 | &pos->member != (head); \ 298 | pos = list_entry(pos->member.prev, typeof(*pos), member)) 299 | 300 | /** 301 | * list_prepare_entry - prepare a pos entry for use as a start point in 302 | * list_for_each_entry_continue 303 | * @pos: the type * to use as a start point 304 | * @head: the head of the list 305 | * @member: the name of the list_struct within the struct. 306 | */ 307 | #define list_prepare_entry(pos, head, member) \ 308 | ((pos) ? : list_entry(head, typeof(*pos), member)) 309 | 310 | /** 311 | * list_for_each_entry_continue - iterate over list of given type 312 | * continuing after existing point 313 | * @pos: the type * to use as a loop counter. 314 | * @head: the head for your list. 315 | * @member: the name of the list_struct within the struct. 316 | */ 317 | #define list_for_each_entry_continue(pos, head, member) \ 318 | for (pos = list_entry(pos->member.next, typeof(*pos), member); \ 319 | &pos->member != (head); \ 320 | pos = list_entry(pos->member.next, typeof(*pos), member)) 321 | 322 | /** 323 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry 324 | * @pos: the type * to use as a loop counter. 325 | * @n: another type * to use as temporary storage 326 | * @head: the head for your list. 327 | * @member: the name of the list_struct within the struct. 328 | */ 329 | #define list_for_each_entry_safe(pos, n, head, member) \ 330 | for (pos = list_entry((head)->next, typeof(*pos), member), \ 331 | n = list_entry(pos->member.next, typeof(*pos), member); \ 332 | &pos->member != (head); \ 333 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) 334 | 335 | /** 336 | * list_for_each_entry_safe_continue - iterate over list of given type 337 | * continuing after existing point safe against removal of list entry 338 | * @pos: the type * to use as a loop counter. 339 | * @n: another type * to use as temporary storage 340 | * @head: the head for your list. 341 | * @member: the name of the list_struct within the struct. 342 | */ 343 | #define list_for_each_entry_safe_continue(pos, n, head, member) \ 344 | for (pos = list_entry(pos->member.next, typeof(*pos), member), \ 345 | n = list_entry(pos->member.next, typeof(*pos), member); \ 346 | &pos->member != (head); \ 347 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) 348 | 349 | /** 350 | * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against 351 | * removal of list entry 352 | * @pos: the type * to use as a loop counter. 353 | * @n: another type * to use as temporary storage 354 | * @head: the head for your list. 355 | * @member: the name of the list_struct within the struct. 356 | */ 357 | #define list_for_each_entry_safe_reverse(pos, n, head, member) \ 358 | for (pos = list_entry((head)->prev, typeof(*pos), member), \ 359 | n = list_entry(pos->member.prev, typeof(*pos), member); \ 360 | &pos->member != (head); \ 361 | pos = n, n = list_entry(n->member.prev, typeof(*n), member)) 362 | 363 | 364 | 365 | 366 | /* 367 | * Double linked lists with a single pointer list head. 368 | * Mostly useful for hash tables where the two pointer list head is 369 | * too wasteful. 370 | * You lose the ability to access the tail in O(1). 371 | */ 372 | 373 | struct hlist_head { 374 | struct hlist_node *first; 375 | }; 376 | 377 | struct hlist_node { 378 | struct hlist_node *next, **pprev; 379 | }; 380 | 381 | #define HLIST_HEAD_INIT { .first = NULL } 382 | #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } 383 | #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) 384 | #define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL) 385 | 386 | static inline int hlist_unhashed(const struct hlist_node *h) 387 | { 388 | return !h->pprev; 389 | } 390 | 391 | static inline int hlist_empty(const struct hlist_head *h) 392 | { 393 | return !h->first; 394 | } 395 | 396 | static inline void __hlist_del(struct hlist_node *n) 397 | { 398 | struct hlist_node *next = n->next; 399 | struct hlist_node **pprev = n->pprev; 400 | *pprev = next; 401 | if (next) 402 | next->pprev = pprev; 403 | } 404 | 405 | static inline void hlist_del(struct hlist_node *n) 406 | { 407 | __hlist_del(n); 408 | n->next = LIST_POISON1; 409 | n->pprev = LIST_POISON2; 410 | } 411 | 412 | 413 | static inline void hlist_del_init(struct hlist_node *n) 414 | { 415 | if (n->pprev) { 416 | __hlist_del(n); 417 | INIT_HLIST_NODE(n); 418 | } 419 | } 420 | 421 | static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) 422 | { 423 | struct hlist_node *first = h->first; 424 | n->next = first; 425 | if (first) 426 | first->pprev = &n->next; 427 | h->first = n; 428 | n->pprev = &h->first; 429 | } 430 | 431 | 432 | 433 | /* next must be != NULL */ 434 | static inline void hlist_add_before(struct hlist_node *n, 435 | struct hlist_node *next) 436 | { 437 | n->pprev = next->pprev; 438 | n->next = next; 439 | next->pprev = &n->next; 440 | *(n->pprev) = n; 441 | } 442 | 443 | static inline void hlist_add_after(struct hlist_node *n, 444 | struct hlist_node *next) 445 | { 446 | next->next = n->next; 447 | n->next = next; 448 | next->pprev = &n->next; 449 | 450 | if(next->next) 451 | next->next->pprev = &next->next; 452 | } 453 | 454 | 455 | 456 | #define hlist_entry(ptr, type, member) container_of(ptr,type,member) 457 | 458 | #define hlist_for_each(pos, head) \ 459 | for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \ 460 | pos = pos->next) 461 | 462 | #define hlist_for_each_safe(pos, n, head) \ 463 | for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ 464 | pos = n) 465 | 466 | /** 467 | * hlist_for_each_entry - iterate over list of given type 468 | * @tpos: the type * to use as a loop counter. 469 | * @pos: the &struct hlist_node to use as a loop counter. 470 | * @head: the head for your list. 471 | * @member: the name of the hlist_node within the struct. 472 | */ 473 | #define hlist_for_each_entry(tpos, pos, head, member) \ 474 | for (pos = (head)->first; \ 475 | pos && ({ prefetch(pos->next); 1;}) && \ 476 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 477 | pos = pos->next) 478 | 479 | /** 480 | * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point 481 | * @tpos: the type * to use as a loop counter. 482 | * @pos: the &struct hlist_node to use as a loop counter. 483 | * @member: the name of the hlist_node within the struct. 484 | */ 485 | #define hlist_for_each_entry_continue(tpos, pos, member) \ 486 | for (pos = (pos)->next; \ 487 | pos && ({ prefetch(pos->next); 1;}) && \ 488 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 489 | pos = pos->next) 490 | 491 | /** 492 | * hlist_for_each_entry_from - iterate over a hlist continuing from existing point 493 | * @tpos: the type * to use as a loop counter. 494 | * @pos: the &struct hlist_node to use as a loop counter. 495 | * @member: the name of the hlist_node within the struct. 496 | */ 497 | #define hlist_for_each_entry_from(tpos, pos, member) \ 498 | for (; pos && ({ prefetch(pos->next); 1;}) && \ 499 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 500 | pos = pos->next) 501 | 502 | /** 503 | * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry 504 | * @tpos: the type * to use as a loop counter. 505 | * @pos: the &struct hlist_node to use as a loop counter. 506 | * @n: another &struct hlist_node to use as temporary storage 507 | * @head: the head for your list. 508 | * @member: the name of the hlist_node within the struct. 509 | */ 510 | #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ 511 | for (pos = (head)->first; \ 512 | pos && ({ n = pos->next; 1; }) && \ 513 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 514 | pos = n) 515 | 516 | 517 | #endif 518 | -------------------------------------------------------------------------------- /fundamental.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of fundamental a brute force searcher 3 | for relationships between constants & formulae for sequences. 4 | Copyright (C) 2004 D.J. Barrow dj_barrow@ariasoft.ie barrow_dj@yahoo.com 5 | 6 | It is licensed under GPL v2.1 7 | */ 8 | 9 | #include "fundamental_config.h" 10 | #if defined(SEQUENCE_HUNTER) || defined(REAL_HUNTER) 11 | #define HUNTER 12 | #endif 13 | 14 | #if defined(HAVE_FACTORIAL_OP) || \ 15 | defined(HAVE_ABS_OP) || \ 16 | defined(HAVE_FLOOR_OP)|| \ 17 | defined(HAVE_CEIL_OP) || \ 18 | defined(HAVE_RINT_OP) || \ 19 | defined(HAVE_SIN_OP) || \ 20 | defined(HAVE_COS_OP) || \ 21 | defined(HAVE_TAN_OP) || \ 22 | defined(HAVE_ONES_COMPLIMENT_OP) || \ 23 | defined(HAVE_NOT_OP) 24 | #define HAVE_UNARY_OPERATORS 25 | #endif 26 | 27 | #if defined(HAVE_ADDITION_OP) || \ 28 | defined(HAVE_SUBTRACTION_OP) || \ 29 | defined(HAVE_MULTIPLY_OP) || \ 30 | defined(HAVE_DIVIDE_OP) || \ 31 | defined(HAVE_POWER_OP) || \ 32 | defined(HAVE_MODULO_OP) || \ 33 | defined(HAVE_AND_OP) || \ 34 | defined(HAVE_OR_OP) || \ 35 | defined(HAVE_XOR_OP) || \ 36 | defined(HAVE_LOG_SHIFT_OP) || \ 37 | defined(HAVE_LOG_RSHIFT_OP) || \ 38 | defined(HAVE_LOG_LSHIFT_OP) || \ 39 | defined(HAVE_ARITH_SHIFT_OP) || \ 40 | defined(HAVE_ROTATE_OP) || \ 41 | defined(HAVE_MASK_OP) || \ 42 | defined(HAVE_GETBIT_OP) || \ 43 | defined(HAVE_LN_OP) || \ 44 | defined(HAVE_GCD_OP) || \ 45 | defined(HAVE_EQ_COND) || \ 46 | defined(HAVE_GT_COND) || \ 47 | defined(HAVE_GE_COND) || \ 48 | defined(HAVE_LT_COND) || \ 49 | defined(HAVE_LE_COND) || \ 50 | defined(HAVE_AND_COND) || \ 51 | defined(HAVE_OR_COND) || \ 52 | defined(HAVE_MIN_OP) || \ 53 | defined(HAVE_MAX_OP) 54 | #define HAVE_BINARY_OPERATORS 55 | #endif 56 | 57 | #if defined(HAVE_FLOOR_OP)|| \ 58 | defined(HAVE_CEIL_OP) || \ 59 | defined(HAVE_RINT_OP) || \ 60 | defined(HAVE_SIN_OP) || \ 61 | defined(HAVE_COS_OP) || \ 62 | defined(HAVE_TAN_OP) || \ 63 | defined(HAVE_LN_OP) 64 | #define HAVE_FLOATING_POINT_OPERATORS 65 | #endif 66 | 67 | 68 | #if defined(HAVE_AND_OP) || \ 69 | defined(HAVE_OR_OP) || \ 70 | defined(HAVE_XOR_OP) || \ 71 | defined(HAVE_LOG_SHIFT_OP) || \ 72 | defined(HAVE_LOG_RSHIFT_OP) || \ 73 | defined(HAVE_LOG_LSHIFT_OP) || \ 74 | defined(HAVE_ARITH_SHIFT_OP) || \ 75 | defined(HAVE_ROTATE_OP) || \ 76 | defined(HAVE_LROTATE_OP) || \ 77 | defined(HAVE_RROTATE_OP) || \ 78 | defined(HAVE_MASK_OP) || \ 79 | defined(HAVE_GETBIT_OP) 80 | #define HAVE_BOOLEAN_OPERATORS 81 | #endif 82 | 83 | #if defined(HAVE_EQ_COND) || \ 84 | defined(HAVE_GT_COND) || \ 85 | defined(HAVE_GE_COND) || \ 86 | defined(HAVE_LT_COND) || \ 87 | defined(HAVE_LE_COND) || \ 88 | defined(HAVE_AND_COND) || \ 89 | defined(HAVE_OR_COND) 90 | #define HAVE_CONDITIONALS 91 | #endif 92 | 93 | #if defined(HAVE_MIN_OP) || \ 94 | defined(HAVE_MAX_OP) 95 | #define HAVE_MIN_MAX_OPERATORS 96 | #endif 97 | 98 | #if defined(HAVE_LOG_RSHIFT_OP) || \ 99 | defined(HAVE_LOG_LSHIFT_OP) || \ 100 | defined(HAVE_SUBTRACTION_OP) || \ 101 | defined(HAVE_LROTATE_OP) || \ 102 | defined(HAVE_RROTATE_OP) 103 | #define HAVE_EXCESS_INTEGER_UNSIGNED_OPERATORS 104 | #endif 105 | 106 | #if defined(HAVE_LMS_ERROR) || \ 107 | defined(HAVE_ABS_ERROR) || \ 108 | defined(HAVE_LMS_RATIOED_ERROR) || \ 109 | defined(HAVE_ABS_RATIOED_ERROR) || \ 110 | defined(HAVE_LMS_GT_ERROR) || \ 111 | defined(HAVE_GT_ERROR) || \ 112 | defined(HAVE_LMS_GT_RATIOED_ERROR) || \ 113 | defined(HAVE_GT_RATIOED_ERROR) || \ 114 | defined(HAVE_LMS_LT_ERROR) || \ 115 | defined(HAVE_LT_ERROR) || \ 116 | defined(HAVE_LMS_LT_RATIOED_ERROR) || \ 117 | defined(HAVE_LT_RATIOED_ERROR) 118 | #define HAVE_ERROR_MEASUREMENTS 119 | #endif 120 | 121 | 122 | #if defined(HAVE_LMS_ERROR) || \ 123 | defined(HAVE_LMS_RATIOED_ERROR) || \ 124 | defined(HAVE_LMS_GT_ERROR) || \ 125 | defined(HAVE_LMS_GT_RATIOED_ERROR) || \ 126 | defined(HAVE_LMS_LT_ERROR) || \ 127 | defined(HAVE_LMS_LT_RATIOED_ERROR) 128 | #define HAVE_LMS_ERROR_MEASUREMENTS 129 | #endif 130 | 131 | #if defined(HAVE_LMS_RATIOED_ERROR) || \ 132 | defined(HAVE_LMS_GT_RATIOED_ERROR) || \ 133 | defined(HAVE_LMS_LT_RATIOED_ERROR) 134 | #define HAVE_LMS_RATIOED_ERROR_MEASUREMENTS 135 | #endif 136 | 137 | 138 | #if defined(HAVE_ABS_RATIOED_ERROR) || \ 139 | defined(HAVE_GT_RATIOED_ERROR) || \ 140 | defined(HAVE_LT_RATIOED_ERROR) 141 | #define HAVE_POWER1_RATIOED_ERROR_MEASUREMENTS 142 | #endif 143 | 144 | #if defined(HAVE_POWER1_RATIOED_ERROR_MEASUREMENTS) || \ 145 | defined(HAVE_LMS_RATIOED_ERROR_MEASUREMENTS) 146 | #define HAVE_RATIOED_ERROR_MEASUREMENTS 147 | #endif 148 | 149 | #if defined(HAVE_LMS_GT_ERROR) || \ 150 | defined(HAVE_GT_ERROR) || \ 151 | defined(HAVE_LMS_GT_RATIOED_ERROR) || \ 152 | defined(HAVE_GT_RATIOED_ERROR) 153 | #define HAVE_GT_ERROR_MEASUREMENTS 154 | #endif 155 | 156 | #if defined(HAVE_LMS_LT_ERROR) || \ 157 | defined(HAVE_LT_ERROR) || \ 158 | defined(HAVE_LMS_LT_RATIOED_ERROR) || \ 159 | defined(HAVE_LT_RATIOED_ERROR) 160 | #define HAVE_LT_ERROR_MEASUREMENTS 161 | #endif 162 | 163 | 164 | 165 | 166 | 167 | #include "fundamental_sanity.h" 168 | #include "defs.h" 169 | 170 | #ifndef NUM_INTEGER_BITS 171 | #include 172 | #endif 173 | //#define NDEBUG 174 | #include 175 | 176 | #ifdef NUM_INTEGER_BITS 177 | #if NUM_INTEGER_BITS>32 178 | #ifdef SIGNED_OPERATION 179 | typedef long long number_t; 180 | typedef long long uint_t; 181 | #define NUMBER_FORMAT "%lld" 182 | #else 183 | typedef unsigned long long number_t; 184 | typedef unsigned long long uint_t; 185 | #define NUMBER_FORMAT "%llu" 186 | #endif 187 | /* atoll will break for unsigned numbers > signed long long */ 188 | #define ASCII_TO_NUM atoll 189 | typedef unsigned long long unsigned_number_t; 190 | typedef unsigned long long uint_t; 191 | 192 | #if NUM_INTEGER_BITS!=64 193 | #define RESULT_MASK (((1ULL<32 */ 200 | #ifdef SIGNED_OPERATION 201 | typedef long number_t; 202 | typedef unsigned long uint_t; 203 | #define NUMBER_FORMAT "%ld" 204 | #define ASCII_TO_NUM atol 205 | #else 206 | typedef unsigned long number_t; 207 | typedef unsigned long uint_t; 208 | #define NUMBER_FORMAT "%lu" 209 | #define ASCII_TO_NUM (number_t)atoll 210 | #endif 211 | 212 | typedef unsigned long unsigned_number_t; 213 | 214 | #if NUM_INTEGER_BITS!=32 215 | #define RESULT_MASK (((1UL<>1)) 241 | #define MIN_INT_T (int_t)((uint_t)(~0ULL>>1)+1) 242 | #endif 243 | #ifndef NUM_INTEGER_BITS 244 | typedef double number_t; 245 | #define NUMBER_FORMAT "%e" 246 | #define ASCII_TO_NUM atof 247 | #endif 248 | 249 | 250 | #ifdef MULTIPLE_RESULTS 251 | typedef struct 252 | { 253 | #ifdef NUM_ANSWERS 254 | number_t answer[NUM_ANSWERS]; 255 | #else 256 | int num_answers; 257 | number_t answer[0]; 258 | #endif 259 | } 260 | #if defined(SPARSE_ARRAY_INDICES) || !defined(NUM_ANSWERS) 261 | result_array_t,*result_t; 262 | #else 263 | result_t; 264 | #endif /* SPARSE_ARRAY_INDICES */ 265 | #else 266 | typedef number_t result_t; 267 | #endif /* MULTIPLE_RESULTS */ 268 | 269 | 270 | #ifdef MULTIPLE_RESULTS 271 | #ifdef NUM_ANSWERS 272 | #ifdef SPARSE_ARRAY_INDICES 273 | extern result_t alloc_result(void); 274 | #endif 275 | #else /* NUM_ANSWERS */ 276 | extern result_t alloc_result(int num_answers); 277 | #endif /* NUM_ANSWERS */ 278 | #endif 279 | 280 | #ifdef REAL_HUNTER 281 | #define MULTI_DIMENSIONAL (!defined(NUM_HUNTER_DIMENSIONS) || NUM_HUNTER_DIMENSIONS>1) 282 | #ifndef NUM_HUMTER_DIMENSIONS 283 | extern int NUM_HUMTER_DIMENSIONS; 284 | #else 285 | #ifdef SEQUENCE_HUNTER 286 | #define MULTI_DIMENSIONAL (!defined(NUM_SEQUENCE_DIMENSIONS) || NUM_SEQUENCE_DIMENSIONS>1) 287 | #endif 288 | #endif 289 | #endif 290 | 291 | 292 | #ifdef SEQUENCE_HUNTER 293 | typedef unsigned long dimension_t; 294 | 295 | #ifdef HAVE_FUNCTIONS 296 | extern dimension_t curr_seed; 297 | #endif 298 | #define MAX_DIMENSION ((dimension_t)-1) 299 | #define DIMENSION_FORMAT "%lu" 300 | extern int sequence_func(result_t *retnums,dimension_t *array_indices); 301 | extern result_t *get_array_member(dimension_t *array_indices,dimension_t *idxptr); 302 | #endif 303 | #ifdef REAL_HUNTER 304 | #define DIMENSION_FORMAT "%lu" 305 | #endif 306 | 307 | 308 | typedef int depth_t; 309 | #define DEPTH_CHANGE_FORMAT "%d" 310 | 311 | #ifdef HAVE_PRINT_SUM_INFIX 312 | struct infix_tree; 313 | struct infix_tree 314 | { 315 | int has_parent; 316 | depth_t depth; 317 | depth_t child[]; 318 | }; 319 | extern struct infix_tree **tree_members; 320 | #endif 321 | 322 | typedef enum 323 | { 324 | null_op=-1, 325 | first_op=0, 326 | #ifdef HAVE_UNARY_OPERATORS 327 | first_unary_op=first_op, 328 | dummy_op0=first_unary_op-1, 329 | #ifdef HAVE_FACTORIAL_OP 330 | factorial_op, 331 | #endif 332 | #ifdef HAVE_ABS_OP 333 | abs_op, 334 | #endif 335 | #ifdef HAVE_FLOOR_OP 336 | floor_op, 337 | #endif 338 | #ifdef HAVE_CEIL_OP 339 | ceil_op, 340 | #endif 341 | #ifdef HAVE_RINT_OP 342 | rint_op, 343 | #endif 344 | #ifdef HAVE_SIN_OP 345 | sin_op, 346 | #endif 347 | #ifdef HAVE_COS_OP 348 | cos_op, 349 | #endif 350 | #ifdef HAVE_TAN_OP 351 | tan_op, 352 | #endif 353 | #ifdef HAVE_ONES_COMPLIMENT_OP 354 | ones_compliment_op, 355 | #endif 356 | #ifdef HAVE_NOT_OP 357 | not_op, 358 | #endif 359 | unary_op_idx, 360 | last_unary_op=unary_op_idx-1, 361 | #endif /* UNARY_OPERATORS */ 362 | #ifdef HAVE_BINARY_OPERATORS 363 | first_binary_op 364 | #ifndef HAVE_UNARY_OPERATORS 365 | =first_op 366 | #endif 367 | , 368 | dummy_op1=first_binary_op-1, 369 | #endif 370 | #ifdef HAVE_ADDITION_OP 371 | addition_op, 372 | #endif 373 | #ifdef HAVE_SUBTRACTION_OP 374 | subtraction_op, 375 | #endif 376 | #ifdef HAVE_MULTIPLY_OP 377 | multiply_op, 378 | #endif 379 | #ifdef HAVE_DIVIDE_OP 380 | divide_op, 381 | #endif 382 | #ifdef HAVE_POWER_OP 383 | power_op, 384 | #endif 385 | #ifdef HAVE_MODULO_OP 386 | modulo_op, 387 | #endif 388 | #ifdef HAVE_AND_OP 389 | and_op, 390 | #endif 391 | #ifdef HAVE_OR_OP 392 | or_op, 393 | #endif 394 | #ifdef HAVE_XOR_OP 395 | xor_op, 396 | #endif 397 | #ifdef HAVE_LOG_SHIFT_OP 398 | log_shift_op, 399 | #endif 400 | #ifdef HAVE_LOG_RSHIFT_OP 401 | log_rshift_op, 402 | #endif 403 | #ifdef HAVE_LOG_LSHIFT_OP 404 | log_lshift_op, 405 | #endif 406 | #ifdef HAVE_ARITH_SHIFT_OP 407 | arith_shift_op, 408 | #endif 409 | #ifdef HAVE_ROTATE_OP 410 | rotate_op, 411 | #endif 412 | #ifdef HAVE_LROTATE_OP 413 | lrotate_op, 414 | #endif 415 | #ifdef HAVE_RROTATE_OP 416 | rrotate_op, 417 | #endif 418 | #ifdef HAVE_MASK_OP 419 | mask_op, 420 | #endif 421 | #ifdef HAVE_GETBIT_OP 422 | getbit_op, 423 | #endif 424 | #ifdef HAVE_LN_OP 425 | ln_op, 426 | #endif 427 | #ifdef HAVE_GCD_OP 428 | gcd_op, 429 | #endif 430 | #ifdef HAVE_EQ_COND 431 | eq_cond, 432 | #endif 433 | #ifdef HAVE_GT_COND 434 | gt_cond, 435 | #endif 436 | #ifdef HAVE_GE_COND 437 | ge_cond, 438 | #endif 439 | #ifdef HAVE_LT_COND 440 | lt_cond, 441 | #endif 442 | #ifdef HAVE_LE_COND 443 | le_cond, 444 | #endif 445 | #ifdef HAVE_AND_COND 446 | and_cond, 447 | #endif 448 | #ifdef HAVE_OR_COND 449 | or_cond, 450 | #endif 451 | #ifdef HAVE_MIN_OP 452 | min_op, 453 | #endif 454 | #ifdef HAVE_MAX_OP 455 | max_op, 456 | #endif 457 | binary_op_idx, 458 | last_binary_op=binary_op_idx-1, 459 | num_operators, 460 | } operation; 461 | 462 | extern depth_t op_depth[num_operators]; 463 | 464 | #ifdef HAVE_UNARY_OPERATORS 465 | #define min_operator_depth (1) 466 | #ifndef HAVE_BINARY_OPERATORS 467 | #define max_operator_depth (1) 468 | #endif 469 | #else 470 | #ifdef HAVE_BINARY_OPERATORS 471 | #define min_operator_depth (2) 472 | #endif 473 | #endif 474 | 475 | #ifdef HAVE_BINARY_OPERATORS 476 | #define max_operator_depth (2) 477 | #endif 478 | 479 | #ifdef HAVE_CONSTANTS_FILE 480 | struct fundamental_constant 481 | { 482 | struct fundamental_constant *next; 483 | char type; 484 | int used; 485 | number_t value; 486 | char name[0]; 487 | }; 488 | typedef struct fundamental_constant fundamental_constant; 489 | extern fundamental_constant *head,**fundamental_list; 490 | extern int num_constants; 491 | #endif 492 | 493 | 494 | typedef enum 495 | { 496 | invalid_tag=-1, 497 | first_tag, 498 | dummy_tag=first_tag-1, 499 | #ifdef HUNTER 500 | dimension_tag, 501 | #endif 502 | #ifdef HAVE_CONSTANTS_FILE 503 | constant_tag, 504 | #endif 505 | integer_tag, 506 | last_number_tag=integer_tag, 507 | arithmetic_operation_tag, 508 | #ifdef HAVE_FUNCTIONS 509 | function_tag, 510 | #endif 511 | dummy_tag0, 512 | max_tag=dummy_tag0-1 513 | } stack_tag; 514 | 515 | 516 | #ifdef HAVE_SIMPLIFICATION_TEST 517 | typedef unsigned simplify_result_tag_t; 518 | void init_simplifyable(void); 519 | #endif /* HAVE_SIMPLIFICATION_TEST */ 520 | 521 | 522 | #define is_operator(tag) ((tag)>last_number_tag) 523 | #define is_number(tag) ((tag)<=last_number_tag) 524 | typedef long stackval_t; 525 | #define STACKVAL_FORMAT "%ld" 526 | 527 | 528 | 529 | 530 | 531 | #define abort_sum(err,format...) \ 532 | { \ 533 | debug_printf(format); \ 534 | return(err); \ 535 | } 536 | 537 | 538 | #ifdef MULTIPLE_RESULTS 539 | dimension_t *retvals; 540 | #ifdef NUM_ANSWERS 541 | #define MAX_NUM_RESULTS (NUM_ANSWERS) 542 | #else 543 | dimension_t MAX_NUM_RESULTS; 544 | #endif 545 | #endif 546 | 547 | 548 | extern int num_answers,max_num_answers; 549 | 550 | #ifdef HAVE_ERROR_MEASUREMENTS 551 | /* Better to leave as long double 12 byte float on intel to minimise risk of overflow */ 552 | typedef long double error_t; 553 | #define ERROR_FORMAT "%Le" 554 | 555 | enum 556 | { 557 | #ifdef HAVE_LMS_ERROR 558 | lms_error, 559 | #endif 560 | #ifdef HAVE_ABS_ERROR 561 | abs_error, 562 | #endif 563 | #ifdef HAVE_LMS_RATIOED_ERROR 564 | lms_ratioed_error, 565 | #endif 566 | #ifdef HAVE_ABS_RATIOED_ERROR 567 | abs_ratioed_error, 568 | #endif 569 | #ifdef HAVE_LMS_GT_ERROR 570 | lms_gt_error, 571 | #endif 572 | #ifdef HAVE_GT_ERROR 573 | gt_error, 574 | #endif 575 | #ifdef HAVE_LMS_GT_RATIOED_ERROR 576 | lms_gt_ratioed_error, 577 | #endif 578 | #ifdef HAVE_GT_RATIOED_ERROR 579 | gt_ratioed_error, 580 | #endif 581 | #ifdef HAVE_LMS_LT_ERROR 582 | lms_lt_error, 583 | #endif 584 | #ifdef HAVE_LT_ERROR 585 | lt_error, 586 | #endif 587 | #ifdef HAVE_LMS_LT_RATIOED_ERROR 588 | lms_lt_ratioed_error, 589 | #endif 590 | #ifdef HAVE_LT_RATIOED_ERROR 591 | lt_ratioed_error, 592 | #endif 593 | NUM_ERROR_MEASUREMENTS 594 | }; 595 | #endif 596 | 597 | typedef struct 598 | { 599 | stack_tag tag; 600 | #ifdef SIGNED_OPERATION 601 | int minus; 602 | #endif 603 | stackval_t val; 604 | } stack_entry; 605 | 606 | depth_t get_op_depth(stack_entry *curr); 607 | typedef struct 608 | { 609 | int stack_depth; 610 | #ifdef HAVE_FUNCTIONS 611 | dimension_t seed; 612 | #endif 613 | number_t *result_stack; 614 | stack_entry stack[]; 615 | } sum_t; 616 | 617 | 618 | #if defined(MULTIPLE_RESULTS) || defined(HAVE_FUNCTIONS) 619 | extern void print_sum_preamble(sum_t *sum); 620 | #define PRINT_SUM_PREAMBLE(sum) print_sum_preamble(sum); 621 | #else 622 | #define PRINT_SUM_PREAMBLE(sum) 623 | #endif 624 | 625 | #define PRINT_SUM_POSTAMBLE(sum) print_sum_postamble(sum); 626 | #ifdef HAVE_PRINT_SUM_INFIX 627 | extern void print_sum_infix(sum_t *sum); 628 | #endif 629 | #ifdef HAVE_PRINT_SUM_RPN 630 | extern void print_sum_rpn(sum_t *sum); 631 | #endif 632 | extern void print_sum(sum_t *sum); 633 | 634 | #if defined(HAVE_PRINT_SUM_INFIX) && defined(HAVE_PRINT_SUM_RPN) 635 | #define PRINT_SUM(sum1) {print_sum_preamble(sum1) print_sum_rpn(sum1);print_sum_infix(sum1);print_sum_postamble(sum1)} 636 | #endif 637 | #if defined(HAVE_PRINT_SUM_RPN) && !defined(HAVE_PRINT_SUM_INFIX) 638 | #define PRINT_SUM(sum1)\ 639 | PRINT_SUM_PREAMBLE(sum1)\ 640 | print_sum_rpn(sum1);\ 641 | PRINT_SUM_POSTAMBLE(sum1) 642 | #endif 643 | #if defined(HAVE_PRINT_SUM_INFIX) && !defined(HAVE_PRINT_SUM_RPN) 644 | #define PRINT_SUM(sum1)\ 645 | PRINT_SUM_PREAMBLE(sum1)\ 646 | print_sum_infix(sum1);\ 647 | PRINT_SUM_POSTAMBLE(sum1) 648 | #endif /* defined(HAVE_PRINT_SUM_INFIX) && defined(HAVE_PRINT_SUM_RPN) */ 649 | #ifdef HAVE_ERROR_MEASUREMENTS 650 | extern void print_error_measurements(void); 651 | #endif 652 | 653 | 654 | 655 | #ifdef HAVE_ERROR_MEASUREMENTS 656 | #include "list.h" 657 | typedef struct 658 | { 659 | struct list_head list; 660 | error_t error_val; 661 | int processed; 662 | sum_t sum; 663 | } error_list_element; 664 | 665 | extern struct list_head error_list[NUM_ERROR_MEASUREMENTS]; 666 | #endif 667 | typedef struct 668 | { 669 | #ifdef HUNTER 670 | int num_sequence_correct_depth; 671 | #endif 672 | #if !defined(NUM_INTEGER_BITS) && !defined(ERROR_OP) 673 | number_t sum_correct_error_tolerance; 674 | #endif 675 | int sum_correct; 676 | int aborted; 677 | } calculate_sum_result; 678 | 679 | typedef void (*calculate_sum_func_t)(calculate_sum_result *retval); 680 | extern calculate_sum_result calculate_sum(sum_t *sum,calculate_sum_func_t sum_func); 681 | #ifndef NUM_INTEGER_BITS 682 | extern int number_to_int_t(number_t *numval,int_t *intval); 683 | #endif 684 | #ifdef SEQUENCE_HUNTER 685 | //extern dimension_t *array_indices; 686 | #endif 687 | extern number_t *result_stack; 688 | extern int max_stack_depth; 689 | #ifdef REAL_HUNTER 690 | extern number_t *coord_and_result_array; 691 | extern int num_real_coord_idx; 692 | #ifndef NUM_HUNTER_DIMENSIONS 693 | extern number_t NUM_HUNTER_DIMENSIONS; 694 | #endif 695 | #endif 696 | #ifdef SEQUENCE_HUNTER 697 | #ifndef NUM_SEQUENCE_DIMENSIONS 698 | extern dimension_t NUM_SEQUENCE_DIMENSIONS; 699 | #endif 700 | #endif 701 | 702 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is fundamental 2 | 3 | 4 | 5 | Fundamental is a c command line program, a rough diamond which barely works beautifully but is my most original program to date. I've recently found out that it uses a technique called [Symbolic Regression](https://en.wikipedia.org/wiki/Symbolic_regression). It is also being marketed as Dirac because it has the inhuman talent of Dirac the famous Relativistic Detached almost Autistic Strange Genius Feynmans hero to pull inhuman crazy equations out of the air which fit data better than curve fitting, it can curve fit a sin x yes it can!!!!!, primative traditional polynomial curve fitting can't. 6 | 7 | There was code checked in around march 17th 2023 which could find loops if your forking the code to fix bugs take this code too its buggy & doesn't work but its more advanced about 30% extra code. It also does successive apporoximation a type of genetic algorithm this code might have bugs too. 8 | 9 | It found a formula for the smallest factor in a composite number the in project https://www.github.com/djbarrow/find_smallest_factor.git. This might help crack rsa the bank encryption scheme My program fundamental found a way to get the smallest factor of a number However I need more memory than atoms in the universe to complete the job for 2048 bit rsa it's limited at the moment to 2^31 on an 8GB ram machine. The result may be linked to fermats primality test to unzip the source tar -zxpvf find_smallest_factor.tgz I don't think I will crack rsa but it's a new approach and might lead to something with a better mathematician than me. 10 | 11 | I always believed rsa could be cracked on a zx spectrum Seeing as the did a differential question answer differential equation of the entire knowledge of google with sentence and paragraph attention in chatgpt rsa now looks like low hanging fruit. Now I might be closer. 12 | 13 | To protect banks I advise the following scheme Multiple encryption - Wikipedia 14 | 15 | I made an attempt at genetic programming/successive approximation in the process_fundamental related functions, 16 | I am unsure of the quality of this code due to mental health problems unfortunately im 56 now and code 17 | i wrote 20 years ago isn't easy to fix or understand and my mental health problems started 20 years ago 18 | I feel like Terry A Davis of templeos.org fame, I'm getting old I wish I wasn't, cest la vie. 19 | 20 | A YouTube video of the program running can be found here https://youtu.be/sD-pk9Pt4-Y 21 | 22 | The potential discoveries made by the program so far are as follows... 23 | I include 2 constants 2^1/12 the distance between semitones and the golden ratio. 24 | These constants are small and potentially can create the semi miraculous equations here without being 25 | miracolous at all I can only assume 1 in 10 any of these equations is significant. 26 | The reason i included semitones is string theory is 12 dimensional and so is western music an octave is 12 semitones. 27 | also people who have near death experiences say music is everywhere in heaven so i thought the quantity could 28 | be interesting see sidroth.org and iands.org for more info about peoples visits to heaven. 29 | However on thinking about it because the mass of neutron almost equals the mass of the proton the mass of electron being very close einsteins theory of relativity kindof implys mass of neutron = mass of proton + electron 30 | to the dufference the fix of to get this more accutate to one in a thousand is about 1.6 times the mass of the electron this is an 31 | easy factor to come up with any number near 1.5 will do so these results I unfortunately for me think are an easy fluke. 32 | 33 | Found match error=4.714556e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 34 | result=1.675008e-27 35 | mass_of_proton mass_of_electron mass_of_electron golden_ratio * + + 36 | 1.672623e-27 9.109390e-31 9.109390e-31 1.618034e+00 * + + 37 | (mass_of_proton + (mass_of_electron + (mass_of_electron * golden_ratio))) 38 | (1.672623e-27 + (9.109390e-31 + (9.109390e-31 * 1.618034e+00 ))) 39 | 40 | Found match error=7.948149e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 41 | result=1.675062e-27 42 | mass_of_proton mass_of_electron golden_ratio semitone_multiple + * + 43 | 1.672623e-27 9.109390e-31 1.618034e+00 1.059463e+00 + * + 44 | (mass_of_proton + (mass_of_electron * (golden_ratio + semitone_multiple))) 45 | (1.672623e-27 + (9.109390e-31 * (1.618034e+00 + 1.059463e+00 ))) 46 | 47 | Found match error=4.818072e-05 fundamental constant name=semitone_multiple value=1.059463e+00 48 | result=1.059412e+00 49 | 1 fine_structure_constant 5 pi + * + 50 | 1 7.297350e-03 5 3.141593e+00 + * + 51 | (1 + (fine_structure_constant * (5 + pi))) 52 | (1 + (7.297350e-03 * (5 + 3.141593e+00 ))) 53 | 54 | Found match error=9.784477e-05 fundamental constant name=mass_of_proton value=1.672623e-27 55 | result=1.672459e-27 56 | mass_of_neutron mass_of_electron fine_structure_constant e - * + 57 | 1.674929e-27 9.109390e-31 7.297350e-03 2.718282e+00 - * + 58 | (mass_of_neutron + (mass_of_electron * (fine_structure_constant - e))) 59 | (1.674929e-27 + (9.109390e-31 * (7.297350e-03 - 2.718282e+00 ))) 60 | 61 | Found match error=8.134724e-05 fundamental constant name=mass_of_proton value=1.672623e-27 62 | result=1.672759e-27 63 | mass_of_neutron mass_of_electron golden_ratio 4 - * + 64 | 1.674929e-27 9.109390e-31 1.618034e+00 4 - * + 65 | (mass_of_neutron + (mass_of_electron * (golden_ratio - 4))) 66 | (1.674929e-27 + (9.109390e-31 * (1.618034e+00 - 4))) 67 | 68 | Found match error=4.310236e-05 fundamental constant name=semitone_multiple value=1.059463e+00 69 | result=1.059509e+00 70 | 1 3 e fine_structure_constant * * + 71 | 1 3 2.718282e+00 7.297350e-03 * * + 72 | (1 + (3 * (e * fine_structure_constant))) 73 | (1 + (3 * (2.718282e+00 * 7.297350e-03 ))) 74 | 75 | Found match error=1.222877e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 76 | result=1.674909e-27 77 | mass_of_proton mass_of_electron mass_of_muon fine_structure_constant * + + 78 | 1.672623e-27 9.109390e-31 1.883532e-28 7.297350e-03 * + + 79 | (mass_of_proton + (mass_of_electron + (mass_of_muon * fine_structure_constant))) 80 | (1.672623e-27 + (9.109390e-31 + (1.883532e-28 * 7.297350e-03 ))) 81 | 82 | Found match error=4.892766e-05 fundamental constant name=mass_of_neutron value=1.674929e-27 83 | result=1.674847e-27 84 | mass_of_proton mass_of_muon golden_ratio fine_structure_constant * * + 85 | 1.672623e-27 1.883532e-28 1.618034e+00 7.297350e-03 * * + 86 | (mass_of_proton + (mass_of_muon * (golden_ratio * fine_structure_constant))) 87 | (1.672623e-27 + (1.883532e-28 * (1.618034e+00 * 7.297350e-03 ))) 88 | 89 | Found match error=4.899031e-05 fundamental constant name=mass_of_proton value=1.672623e-27 90 | result=1.672705e-27 91 | mass_of_neutron mass_of_muon golden_ratio fine_structure_constant * * - 92 | 1.674929e-27 1.883532e-28 1.618034e+00 7.297350e-03 * * - 93 | (mass_of_neutron - (mass_of_muon * (golden_ratio * fine_structure_constant))) 94 | (1.674929e-27 - (1.883532e-28 * (1.618034e+00 * 7.297350e-03 ))) 95 | 96 | Firstly have a look at potential_physics_discoveries.txt for discoveries check the equations from a physics standpoint are dimensionally correct the ones inolving e mass of proton neutron and electron and the golden ratio and fine structure constant are especially interesting. 97 | 98 | NEW FEATURE 99 | Fundamental can now find the formula of a field entered as individual points in a csv file of NUM_REAL_DIMENSIONS 100 | e.g. 101 | 102 | 1,2,0,3 103 | 104 | 0,2,3,5 105 | 106 | 0,3,2,5 107 | 108 | 4,5,0,9 109 | 110 | The first 3 values in this field are x,y,z coordinates the last value is the field value will yield the formula 111 | n[0]+(n[1]+n[2]) 112 | 113 | Fundamental is a toolbox for finding relationships between 114 | 115 | * numbers, e.g. is there any relationship between the numbers PI, e, the square root of 2? 116 | * sequences of numbers, e.g. the sequence 2, 4, 6, 8, 10, ... It could replace/compliment this [encylopedia of integer sequences (OEIS)](http://oeis.org/) website. 117 | 118 | It could have found the following formulas which started quantum physics had it been around in the 1860's & 1890's. [Balmer Series](http://www.colorado.edu/physics/2000/quantumzone/balmer.html) 119 | 120 | It could have found [Planck's Law](http://en.wikipedia.org/wiki/Planck%27s_law) if on a supercomputer or used SETI at home's computer network. 121 | 122 | It could with some improvements in pattern matching have found Mendeleev's periodic table of elements or did some of Murray Gell Mann's work for which he got a Nobel Prize in 1969 for developing the Standard Model in Physics. 123 | 124 | In short it's for hacking the laws of nature & mathematics 125 | 126 | it is in some ways related to curve fitting ( or more percisely a program for finding integer relations ) where you have some data & are looking for a formula to describe it, curve fitting can usually be done by a human, fundamental is more a brute force method where you tell fundamental what operators are allowed + - x / bitwise and or etc. The constants, e PI, it starts with the most simple sums & progresses towards the more complex. 127 | 128 | My original motivation for writing it was while reading Max Borns book on the theory or relativity I fell over a fantastic insight one of Maxwells equations. 129 | 130 |
sqrt(permability of material*permittivity of material ) = speed of light. 131 |
132 | 133 | They didn't at the time know that light was electromagnetic radiation. What I fell over was that there were redundant constants of physics & if a program mas made to search for interrelations between the constants of physics on might by brute force find redundancies, simplifications & potentially new laws of of physics, I was onto a winner which I knew I could pull off. I had the first prototype of "Fundamental" laws of Physics written in 36 hours around 300 lines of code. It found existing laws of physics but no new ones. 134 | 135 | It uses reverse polish notation (RPN) explained [here along with some explanations of the internals of fundamental not covered anywhere else](http://sinscienceandspirituality.blogspot.ie/2018/05/the-joys-of-reverse-polish-notation.html), the beauty of reverse polish notation is that there is no need for brackets the sum 2+3x2=8 or 10 depending on whether you interpret the sum as (2+3)x2 or 2+(3x2) reverse polish notation gets us out of this bind because the order of the numbers & operators gaurantees a unique & unambiguous algorithmic way to do the sum. It also makes it very easy to sequence or "count" through legal sums algorithmically & be gauranteed that each sum is unique. 136 | e.g. 137 | 2+3 is an illegal RPN sum as the + binary operator needs 2 numbers to its left. 138 | 2 3 + in RPN is equal to 5. 139 | 140 | This is the beautiful idea which made funamental possible. The only conditions you need to make in RPN to do any equation is that there needs to be one less binary operator than numbers in the equation. The first binary must have at least 2 numbers to it's left A unary operatior has to have at least 1 number to its left 141 | 142 | e.g. 143 | 5 ! ! ! 2 3 + 5 + + is a legal sum ! being the factorial unary operator. 144 | 145 | Also the equations generated using RPN are easily countable. e.g. it is easily algorithmically possible to write a program for every possible RPN equation with constraints. ( an example of constraints are only numbers between 0 and 5 are allowed & only the + & * operators are allowed * being the multiplication operator. 146 | 147 | One of the thing I've had no success with fundamental is finding a formula for the nth prime, primality testing & pulling out the smallest or largest factor from a very big number. 148 | 149 | Fundamental is a step towards automatic algorithm generation. I am very proud of Fundamental & have great hopes for it, it's by far my best idea to date, 150 | 151 | Although my program doesn't use genetic algorithms, it brute force searches a solution space of RPN sums, however, it can be configured to use successive approximation (I read about genetic programming before inventing fundamental and I'm sure i got inspired by wondering how data mining works). My program is almost identical in functionality to Eureqa & I am sure can find sums Eureqa can't as Eureqa calculates fitnesses of guesses & tries to find genetically fitter answers which won't work in cases where fundamental will,if I'm doing a bad job at explaining how fundamental works please watch [the following beautiful videos of Eureqa](http://formulize.nutonian.com/documentation/eureqa/). [A Isralei professors Eureqa moment.](http://www.haaretz.com/israel-news/an-israeli-professor-s-eureqa-moment-1.410881) Tony also has some code written but his [open source eureqa](https://github.com/verdverm) seems too simple to be as mature as fundamental, it is designed for paralell processing something yet to be done in fundamental. Tony also implemented [PGE](https://www.lri.fr/~hansen/proceedings/2013/GECCO/proceedings/p1021.pdf) but in python which means it would be slow. One last link for reference [Quora thread for alternatives to Eureqa](https://www.quora.com/Are-there-any-good-alternatives-to-Nutonian-Eureqa-Formulize-for-curve-fitting), [here is the deep learning approach to curve fitting](http://neuralnetworksanddeeplearning.com/chap4.html) 152 | 153 | It's open source & I hope someday it will help someone solve significant problems, if it does please give me some credit for helping you on your way. It may be of use in Mathematics, Chemistry, Physics & Economics for Modeling data without a known formula. The program could be enhanced to do automatic algorithm generation using an open source forth language engine like Paflof or else Java bytecode. however it will be about 20 years before computation speeds will make this possible. Here is a description of what it how it works & what it currently does. 154 | 155 | Fundamental internally uses reverse polish notation algorithm to search a solution space for a formula given test data, it can search for formulas for sequences of numbers as well as relationships between constants. To date it was successfully able to find the following by a brute force solution space search for.. 156 | generate the [Taylor Series for e(x)](http://en.wikipedia.org/wiki/Taylor_series) 157 | An estimate formula for the nth prime. 158 | Design an n bit adder using only boolean logic. 159 | It could have found the formula for the Balmier lines in the hydrogen spectrum 160 | 161 | [The Miraculous Bailey-Borwein-Plouffe Pi Algorithm](http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula) [Borweins Algorithm](http://en.wikipedia.org/wiki/Borwein's_algorithm) was found by a similar ( but fundamentally much different ) program. 162 | 163 | ## Example 164 | 165 | When set up properly you can enter a sequence like 166 | 5,8,11,14,17 as follows 167 | fundamental -h 5 -m 5 -i 5 5 8 11 14 17 168 | Setting -h to 5 sets the maximum integer in the solution space to 5. 169 | Setting -m to 5 sets the stack depth or the maximum complexity of the sum to 5 term. 170 | Setting -i to 5 tells fundamental that there are 5 terms following which contain the sequence. 171 | The output of the testrun is: 172 | 5 3 n[0] * + 173 | (5 + (3 * n[0])) 174 | 5 -3 -n[0] * + 175 | (5 + (-3 * -n[0])) 176 | So the sequence formula is y=f(n[0])=5+(3 x n[0]), n[0] being an integer. 177 | 178 | ## Accolades & Delusions of Grandeur ;) 179 | 180 | ### Pio a Friend and Fundamental 181 | 182 | Pio is a bright guy, speaks 5 languages, Degree in numerical computation & mathematics currently doing a hdip in cloud computing. I've been 6 years trying to convince Pio that Fundamental was more than curve fitting. After reading Carsten Otte's compliment he decided he'd better investigate himself. Now he's spouting things like GO FOR IT!!, Smart Cookie D.J., uv cracked it this time D.J. Google can't help but buy it. Now he is in disbelief that nothing like it has ever been done before. Stuart Russell & [Peter Norvig](http://norvig.com) in Artificial Intelligence a modern approach hint that it can be done but is totally impractical, my program proves otherwise. Pio has agreed to write a fisher price web interface for fundamental & explore data mining possibilities which he is learning in the cloud computing course.... Thanks Pio. 183 | 184 | 185 | 186 | A colleage at Pace in West Yorkshire who knew Richard Feynman personally said Fundamental was bloody useful. 187 | 188 | A colleague at IBM Boeblingen Carsten Otte had this to say... 189 | I browsed through the code of fundamental a bit. 190 | I find the idea brilliant, and I think this might be worth drilling deeper. 191 | 192 | 193 | 194 | Andrea said this after examining the code and me fixing a minor bug to get it going for him. 195 | Hello D.J. 196 | sorry for the long time to answer... 197 | i have had too many argument to study to understand well that ,,, 198 | I think your work it's absolutely fabulous ! 199 | 200 | 201 | [Fabrice Bellard](http://en.wikipedia.org/wiki/Fabrice_Bellard) didn't directly sing it's praises but here is what he'd to say 202 | Someone told me about a similar project some time ago and I find the idea interesting. Of course the problem is to limit the exponential growth of the search space. I guess that an exhaustive search cannot lead to very interesting discoveries because the programs are too small. But there may be ways to explore a subspace of the "interesting" possible programs with a well chosen language and search algorithm. 203 | 204 | 205 | 206 | I guess that you already know the [PSLQ algorithm](http://en.wikipedia.org/wiki/Integer_relation_algorithm) [( very intersting pdf here on the topic )](http://arminstraub.com/files/pslq.pdf)used to find the BBP Pi formula you mention. It just finds a linear combination with small integer coefficients of constants giving a zero result. It is very limited but already quite effective to find interesting relations. 207 | 208 | Most importantly is only 2k lines of code. 209 | 210 | This is not curve fitting as defined by Wikipedia, curve fitting can be done using pen & paper & it gauranteed to produce an answer for the class of problems it solves, fundamental typically does billions of calculations when used for curve fitting without gaurantee of an answer & can handle classes of problems not handleable by traditional curve fitting or Mathematica. 211 | 212 | ## Caveats 213 | 214 | Yes the code is buggy if you aren't acquainted with the gdb debugger now is the time to get familiar, the code compiles using gcc & runs on Linux & possibly Cygwin for Windows. 215 | 216 | The section of the code enabled loops ( e.g. needed to find the Taylor series expansion formula for e(x) ) by the MAX_NUM_LOOPVARS is hopelessly broken, don't use it & #ifdef it out, I'm currently rewriting fundamental so that it can develop code automatically for things like bubblesorts automatically rather than just the rather limited loop. 217 | 218 | ## Documentation 219 | 220 | Fundamental now contains a Fundamental Overview.doc readme explaining most of the internals of fundamental, please feel welcome to send questions to me at barrow_dj@yahoo.com and I will add detail to the document explaining your concern. 221 | 222 | P.S. Remember gdb is your friend when pulling out bugs use it you can call print_sum directly from the debugger to see how the sum trials are progressing. 223 | 224 | Please also look at github feynman.ai and their website it is more advanced in ways, feynman.ai code is in python I thought it was slow but it uses pytorch gpu magic I'm unsure if my code beats it python 100x slower vs gpu 100x faster, my code is tight pre processed C unthreaded and un networked, I like my code because its mine but this goes further than my code does in ambition. feynman.ai has dimensional analysis which I'm jealous of, it does more than my code for physics formula finding I wonder if the github feynman.ai does all it claims there isn't much code in the project and doing it in python rather than cython implys crapware, try merging the tidiest of my code with this. Also look at cern data files and jupiler note books and see if something in physics can be discovered. Nope my code doesn't have rpn to pytorch requiring a nvidia gpu most likely, feynman.ai is superior but it may have stolen the rpn idea from my code, I hope it did I got almost 3000 225 | readers of the joys of rpn in my sinscienceandspirituality.blogspot.com lets hope i was the origin of inspiring this code by the way symbolic regression was invented in 1975 which my code is a legacy of those who had similar ideas before me. My code was the best i could do i have to accept better now has been done. 226 | 227 | eureqa code is commercial and similar to my code slightly tidier as a commercial offering but feynman.ai is extremely interesting for physics. Tony Worm IBM github wrote a bloated java version of my code completely independently his pdf documenting his ideas is better than mine and will provide additional education for you java code java is 10x slower than c, and i use the c preprocessor to make my code more than 20x faster i basically #ifdef out unwanted code. A princeton doctorate looked at my code and did something interesting in julia with more distributed computing support google github symbolic regression princeton. 228 | 229 | The successive approximation/genetic algorithm HAVE_ERROR_MEASURMENTS is incomplete just leave it out of fundamental_config.h 230 | 231 | ## More about the Author 232 | I am a Christian, & I thank God for inspiring this code, my blog business card can be found here https://djbarrow.blogspot.com/2021/03/about-me_13.html and a Take on The Theory of everything can be found here https://sinscienceandspirituality.blogspot.com/2020/12/interesting-factoids-and-limitationsin.html 233 | -------------------------------------------------------------------------------- /fundamental.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of fundamental a brute force searcher 3 | for relationships between constants & formulae for sequences. 4 | Copyright (C) 2004 D.J. Barrow dj_barrow@ariasoft.ie barrow_dj@yahoo.com 5 | 6 | It is licensed under GPL v2.1 7 | */ 8 | #include "fundamental.h" 9 | #include 10 | #include "utils.h" 11 | #include "do_sum.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #ifdef HAVE_PROGRESS 19 | #include 20 | #include 21 | struct timeval *starttime; 22 | #endif 23 | #include "defs.h" 24 | #ifdef REAL_HUNTER 25 | #include "csv.h" 26 | number_t *coord_and_result_array=NULL; 27 | int real_coord_idx=0,num_real_coord_idx=0; 28 | #ifndef NUM_HUNTER_DIMENSIONS 29 | number_t NUM_HUNTER_DIMENSIONS=1; 30 | #endif 31 | #else 32 | #ifdef SEQUENCE_HUNTER 33 | dimension_t 34 | #ifdef HAVE_FUNCTIONS 35 | min_seed=0,max_seed=0, 36 | #endif 37 | *sequence_dimension,sequence_array_size,*sequence_dimension_multiplier; 38 | dimension_t *array_indices,*temp_dimensions; 39 | result_t *sequence_array; 40 | #ifndef NUM_SEQUENCE_DIMENSIONS 41 | dimension_t NUM_SEQUENCE_DIMENSIONS=1; 42 | #endif 43 | #endif 44 | #if defined(MULTIPLE_RESULTS) 45 | dimension_t *retvals; 46 | #ifndef NUM_ANSWERS 47 | dimension_t MAX_NUM_RESULTS; 48 | #endif 49 | #endif 50 | #endif // REAL_HUNTER 51 | 52 | 53 | #ifdef HAVE_CONSTANTS_FILE 54 | fundamental_constant *head=NULL,**fundamental_list=NULL; 55 | int num_constants; 56 | #endif 57 | 58 | int hi_int,total,max_stack_depth,curr_depth1; 59 | #if !defined(NUM_INTEGER_BITS) && !defined(ERROR_OP) 60 | number_t error_tolerance=0.0001; 61 | #endif 62 | 63 | sum_t *sum; 64 | 65 | 66 | int num_answers=0,max_num_answers=-1; 67 | 68 | 69 | 70 | #ifdef SEED 71 | #define MIN_SEED (SEED) 72 | #else 73 | #define MIN_SEED (0) 74 | #endif 75 | 76 | 77 | depth_t op_depth[num_operators]= 78 | { 79 | #ifdef HAVE_UNARY_OPERATORS 80 | [first_unary_op ... last_unary_op]=1, 81 | #endif 82 | #ifdef HAVE_BINARY_OPERATORS 83 | [first_binary_op ... last_binary_op]=2, 84 | #endif 85 | }; 86 | 87 | operation first_operator[max_operator_depth]= 88 | { 89 | #ifdef HAVE_UNARY_OPERATORS 90 | first_unary_op, 91 | #else 92 | 0, 93 | #endif 94 | #ifdef HAVE_BINARY_OPERATORS 95 | first_binary_op 96 | #endif 97 | }; 98 | 99 | 100 | #ifdef HAVE_ERROR_MEASUREMENTS 101 | error_t error_val[NUM_ERROR_MEASUREMENTS]; 102 | /* max_error_list_size must be >=2 */ 103 | int max_error_list_size=100; 104 | int num_error_list_elements[NUM_ERROR_MEASUREMENTS]; 105 | struct list_head error_list[NUM_ERROR_MEASUREMENTS]; 106 | int refinement_depth=8; 107 | int next_refinement_depth; 108 | int skip_depth=0; 109 | #define SKIP_DEPTH skip_depth 110 | #define MAX_STACK_DEPTH next_refinement_depth 111 | 112 | int error_sums_good() 113 | { 114 | int idx; 115 | 116 | for(idx=0;idxerror_val)) 118 | return 1; 119 | return 0; 120 | } 121 | 122 | int add_sum_to_list(int idx) 123 | { 124 | error_list_element *element; 125 | struct list_head *curr_error_list=&error_list[idx],*element1; 126 | error_t curr_error_val=error_val[idx]; 127 | error_list_element *new_entry=NULL; 128 | 129 | if(list_empty(curr_error_list)) 130 | goto add_entry; 131 | else 132 | { 133 | if(num_error_list_elements[idx]>=max_error_list_size&&curr_error_val>((error_list_element *)curr_error_list->prev)->error_val) 134 | return 1; 135 | list_for_each(element1,curr_error_list) 136 | { 137 | element=(error_list_element *)element1; 138 | if(element->error_val>curr_error_val||((struct list_head *)element)->next==curr_error_list) 139 | { 140 | if(element->error_val<=curr_error_val) 141 | { 142 | /* Special case for adding an element immeadiately after 143 | the first & only element in the list. */ 144 | element=(error_list_element *)curr_error_list; 145 | } 146 | if(num_error_list_elements[idx]>=max_error_list_size) 147 | { 148 | new_entry=(error_list_element *)curr_error_list->prev; 149 | list_del((struct list_head *)new_entry); 150 | if(new_entry==element) 151 | element=(error_list_element *)curr_error_list; 152 | } 153 | goto add_entry; 154 | } 155 | } 156 | } 157 | add_entry:; 158 | if(!new_entry) 159 | { 160 | new_entry=(error_list_element *)myalloc("new_entry",offsetof(error_list_element,sum.stack[max_stack_depth])); 161 | num_error_list_elements[idx]++; 162 | } 163 | new_entry->error_val=curr_error_val; 164 | new_entry->processed=FALSE; 165 | memcpy(&new_entry->sum,sum,offsetof(sum_t,stack[sum->stack_depth])); 166 | if(list_empty(curr_error_list)) 167 | list_add((struct list_head *)new_entry,curr_error_list); 168 | else 169 | __list_add((struct list_head *)new_entry, 170 | element->list.prev, 171 | (struct list_head *)element); 172 | return 0; 173 | } 174 | #else 175 | #define MAX_STACK_DEPTH (max_stack_depth) 176 | #define SKIP_DEPTH (0) 177 | #endif 178 | 179 | 180 | #ifdef HAVE_PROGRESS 181 | void print_progress(int sig) 182 | { 183 | depth_t i; 184 | struct timeval currtime,resulttime; 185 | long long depth_time[2],time_factor,est_time_remaining,summation,est_currdepth_time,time_at_currdepth; 186 | 187 | 188 | 189 | est_time_remaining=est_currdepth_time=0; 190 | gettimeofday(&currtime,NULL); 191 | if(sum->stack_depth>1) 192 | { 193 | timersub(&currtime,&starttime[sum->stack_depth],&resulttime); 194 | time_at_currdepth=resulttime.tv_sec; 195 | timersub(&starttime[sum->stack_depth],&starttime[sum->stack_depth-1],&resulttime); 196 | depth_time[0]=(resulttime.tv_sec*1000000)+resulttime.tv_usec; 197 | timersub(&starttime[sum->stack_depth-1],&starttime[sum->stack_depth-2],&resulttime); 198 | depth_time[1]=(resulttime.tv_sec*1000000)+resulttime.tv_usec; 199 | time_factor=depth_time[0]/depth_time[1]; 200 | est_currdepth_time=(depth_time[0]*time_factor)/1000000; 201 | summation=est_currdepth_time; 202 | est_currdepth_time-=time_at_currdepth; 203 | for(i=sum->stack_depth;i<=max_stack_depth;i++) 204 | { 205 | est_time_remaining+=summation; 206 | summation=summation*time_factor; 207 | } 208 | est_time_remaining-=time_at_currdepth; 209 | } 210 | timersub(&currtime,&starttime[0],&resulttime); 211 | printf("curr depth="DEPTH_CHANGE_FORMAT" max_stack_depth="DEPTH_CHANGE_FORMAT 212 | " time running=%ld secs est_currdepth_time=%lld secs est_time_remaining=%lld secs\n", 213 | sum->stack_depth,max_stack_depth,resulttime.tv_sec,est_currdepth_time,est_time_remaining); 214 | } 215 | #endif 216 | 217 | #ifdef MULTIPLE_RESULTS 218 | #ifdef NUM_ANSWERS 219 | #ifdef SPARSE_ARRAY_INDICES 220 | result_t alloc_result(void) 221 | { 222 | result_t result=(result_t)myalloc("result",sizeof(result_array_t)); 223 | return result; 224 | } 225 | #endif 226 | #else /* NUM_ANSWERS */ 227 | result_t alloc_result(int num_answers) 228 | { 229 | result_t result=(result_t)myalloc("result",offsetof(result_array_t,answer[num_answers])); 230 | result->num_answers=num_answers; 231 | return result; 232 | } 233 | #endif /* NUM_ANSWERS */ 234 | #endif 235 | 236 | 237 | depth_t get_op_depth(stack_entry *curr) 238 | { 239 | stack_tag curr_tag=curr->tag; 240 | switch(curr_tag) 241 | { 242 | case arithmetic_operation_tag: 243 | return op_depth[curr->val]; 244 | #ifdef HAVE_FUNCTIONS 245 | case function_tag: 246 | return NUM_SEQUENCE_DIMENSIONS; 247 | #endif 248 | default: 249 | if((long)curr>=(long)&sum&&(long)curr<(long)&sum->stack[max_stack_depth]) 250 | fprintf(stderr,"illegal tag in get_depth curr=%p tag="DEPTH_CHANGE_FORMAT"\n",curr,curr_tag); 251 | return ((long)&sum->stack[sum->stack_depth]-(long)curr)/(long)sizeof(&sum->stack[0]); 252 | #if 0 253 | else 254 | { 255 | exit(-1); 256 | return 0; 257 | } 258 | #endif 259 | 260 | } 261 | } 262 | 263 | 264 | 265 | depth_t get_depth_change(stack_entry *curr) 266 | { 267 | stack_tag curr_tag=curr->tag; 268 | if(is_number(curr_tag)) 269 | return(1); 270 | switch(curr_tag) 271 | { 272 | case arithmetic_operation_tag: 273 | return 1-op_depth[curr->val]; 274 | #ifdef HAVE_FUNCTIONS 275 | case function_tag: 276 | return 1-NUM_SEQUENCE_DIMENSIONS; 277 | #endif 278 | default: 279 | exit_error("illegal tag in get_depth_change curr=%p tag="DEPTH_CHANGE_FORMAT"\n",curr,curr_tag); 280 | 281 | } 282 | } 283 | 284 | 285 | #ifndef NUM_INTEGER_BITS 286 | int number_to_int_t(number_t *numval,int_t *intval) 287 | { 288 | if(*numval>MAX_INT_T||*numvalnum_real_coord_idx) 303 | { 304 | real_coord_idx=0; 305 | return 1; 306 | } 307 | return 0; 308 | } 309 | void init_real_coord_idx() 310 | { 311 | real_coord_idx=0; 312 | } 313 | #else 314 | #ifdef SEQUENCE_HUNTER 315 | result_t *get_array_member(dimension_t *array_indices,dimension_t *idxptr) 316 | { 317 | #if MULTI_DIMENSIONAL 318 | dimension_t curr_dimension,curr_index; 319 | dimension_t member_idx=0; 320 | 321 | for(curr_dimension=0;curr_dimension=sequence_dimension[curr_dimension]||curr_index<0) 325 | exit_error("get_array_member illegal dimension index" 326 | DIMENSION_FORMAT" attempted to access " 327 | DIMENSION_FORMAT" max="DIMENSION_FORMAT"\n",curr_dimension,curr_index, 328 | sequence_dimension[curr_dimension]); 329 | member_idx+=(sequence_dimension_multiplier[curr_dimension]*curr_index); 330 | } 331 | if(idxptr) 332 | *idxptr=member_idx; 333 | return(&sequence_array[member_idx]); 334 | #else 335 | if(array_indices[0]>=sequence_dimension[0]||array_indices[0]<0) 336 | exit_error("get_array_member illegal dimension index " 337 | " attempted to access " 338 | DIMENSION_FORMAT" max="DIMENSION_FORMAT"\n",array_indices[0], 339 | sequence_dimension[0]); 340 | if(idxptr) 341 | *idxptr=array_indices[0]; 342 | return(&sequence_array[array_indices[0]]); 343 | #endif 344 | } 345 | 346 | 347 | int increment_array_indices(dimension_t seed_idx 348 | #ifdef SPARSE_ARRAY_INDICES 349 | ,int skip_null 350 | #endif 351 | ) 352 | { 353 | #ifdef MULTI_DIMENSIONAL 354 | dimension_t curr_dimension=0; 355 | #endif 356 | #ifdef SPARSE_ARRAY_INDICES 357 | do 358 | { 359 | #endif 360 | #ifdef MULTI_DIMENSIONAL 361 | for(curr_dimension=0;curr_dimension=sequence_dimension[curr_dimension]) 365 | array_indices[curr_dimension]=seed_idx; 366 | else 367 | break; 368 | } 369 | #else 370 | array_indices[0]++; 371 | if(array_indices[0]>=sequence_dimension[0]) 372 | { 373 | array_indices[0]=seed_idx; 374 | return TRUE; 375 | } 376 | else 377 | return FALSE; 378 | #endif 379 | #ifdef SPARSE_ARRAY_INDICES 380 | } while(skip_null&&!*get_array_member(array_indices)); 381 | #endif 382 | #ifdef MULTI_DIMENSIONAL 383 | return curr_dimension>=NUM_SEQUENCE_DIMENSIONS; 384 | #endif 385 | } 386 | 387 | 388 | void init_array_indices(dimension_t seed_idx 389 | #ifdef SPARSE_ARRAY_INDICES 390 | ,int skip_null 391 | #endif 392 | ) 393 | { 394 | #if MULTI_DIMENSIONAL 395 | dimension_t curr_dimension; 396 | 397 | for(curr_dimension=0;curr_dimension=*max_dimensions||*numbers<0) 420 | return -1; 421 | else 422 | *dimensions=*numbers; 423 | } 424 | return(0); 425 | } 426 | #endif 427 | #endif 428 | #endif /* REAL_HUNTER */ 429 | typedef struct 430 | { 431 | long lo_val; 432 | long hi_val; 433 | stack_tag next_tag; 434 | } number_range_t; 435 | 436 | number_range_t number_range[last_number_tag+1]= 437 | { 438 | #ifdef HUNTER 439 | {0,-1,0}, 440 | #endif 441 | #ifdef HAVE_CONSTANTS_FILE 442 | {0,-1,0}, 443 | #endif 444 | 445 | {0,0,0}, 446 | }; 447 | 448 | stack_tag first_number; 449 | 450 | void init_number(stack_entry *curr) 451 | { 452 | #ifdef SIGNED_OPERATION 453 | curr->minus=FALSE; 454 | #endif 455 | curr->tag=first_number; 456 | curr->val=number_range[first_number].lo_val; 457 | } 458 | 459 | int increment_numbers() 460 | { 461 | int idx,done; 462 | stack_entry *curr; 463 | #ifdef HAVE_ERROR_MEASUREMENTS 464 | int have_number=FALSE; 465 | #endif 466 | done=FALSE; 467 | for(idx=0;idxstack_depth;idx++) 468 | { 469 | curr=&sum->stack[idx]; 470 | if(is_number(curr->tag)) 471 | { 472 | #ifdef HAVE_ERROR_MEASUREMENTS 473 | have_number=TRUE; 474 | #endif 475 | done=FALSE; 476 | #ifdef SIGNED_OPERATION 477 | if(curr->minus==FALSE) 478 | curr->minus=TRUE; 479 | else 480 | #endif 481 | { 482 | #ifdef SIGNED_OPERATION 483 | curr->minus=FALSE; 484 | #endif 485 | curr->val++; 486 | if(curr->val>number_range[curr->tag].hi_val) 487 | { 488 | if(curr->tag>=number_range[curr->tag].next_tag) 489 | done=TRUE; 490 | curr->tag=number_range[curr->tag].next_tag; 491 | curr->val=number_range[curr->tag].lo_val; 492 | if(done) 493 | continue; 494 | } 495 | } 496 | goto finished; 497 | } 498 | } 499 | finished:; 500 | done=(idx>=sum->stack_depth&&(done 501 | #ifdef HAVE_ERROR_MEASUREMENTS 502 | ||!have_number 503 | #endif 504 | )); 505 | return done; 506 | } 507 | 508 | 509 | 510 | #ifdef HAVE_FUNCTIONS 511 | void init_function(stack_entry *curr) 512 | { 513 | #ifdef SIGNED_OPERATION 514 | curr->minus=FALSE; 515 | #endif 516 | curr->tag=function_tag; 517 | } 518 | #endif 519 | 520 | 521 | void init_operation(stack_entry *curr,depth_t depth) 522 | { 523 | #ifdef SIGNED_OPERATION 524 | curr->minus=FALSE; 525 | #endif 526 | curr->tag=arithmetic_operation_tag; 527 | curr->val=first_operator[depth-1]; 528 | } 529 | 530 | 531 | /* counting order for binaries operators */ 532 | /* 000111,001011,001101,001110,010011,010101,010110,011001.....,111000 */ 533 | 534 | 535 | int increment_sum_order() 536 | { 537 | int idx 538 | #ifdef HAVE_FUNCTIONS 539 | ,num_functions 540 | #endif 541 | #ifdef MAX_NUM_LOOPVARS 542 | ,num_loopvars 543 | #endif 544 | ; 545 | depth_t depth_change,depth; 546 | stack_entry *curr; 547 | retry:; 548 | for(idx=curr_depth1;idx>=0;idx--) 549 | { 550 | curr=&sum->stack[idx]; 551 | switch(curr->tag) 552 | { 553 | #ifdef HUNTER 554 | case dimension_tag: 555 | #endif 556 | #ifdef HAVE_CONSTANTS_FILE 557 | case constant_tag: 558 | #endif 559 | case integer_tag: 560 | init_operation(curr,min_operator_depth); 561 | goto leave_loop; 562 | case arithmetic_operation_tag: 563 | depth=op_depth[curr->val]; 564 | if(depthdepth) 565 | { 566 | init_operation(curr,depth+1); 567 | goto leave_loop; 568 | } 569 | #ifdef HAVE_FUNCTIONS 570 | if(idx>=NUM_SEQUENCE_DIMENSIONS) 571 | { 572 | init_function(curr); 573 | goto leave_loop; 574 | } 575 | case function_tag: 576 | #endif 577 | init_number(curr); 578 | if(idx==SKIP_DEPTH) 579 | return 1; 580 | break; 581 | } 582 | } 583 | leave_loop:; 584 | #ifdef HAVE_FUNCTIONS 585 | num_functions= 586 | #endif 587 | #ifdef MAX_NUM_LOOPVARS 588 | num_loopvars= 589 | #endif 590 | 0; 591 | depth=(SKIP_DEPTH ? 1:0); 592 | for(idx=SKIP_DEPTH;idxstack_depth;idx++) 593 | { 594 | curr=&sum->stack[idx]; 595 | depth_change=get_depth_change(curr); 596 | depth+=depth_change; 597 | if(depth<1) 598 | goto retry; 599 | switch(curr->tag) 600 | { 601 | case arithmetic_operation_tag: 602 | if(depth_change==(min_operator_depth-1)&&idx==depth_change) 603 | return 1; 604 | break; 605 | #ifdef HAVE_FUNCTIONS 606 | case function_tag: 607 | num_functions++; 608 | break; 609 | #endif 610 | } 611 | } 612 | if(depth!=1) 613 | goto retry; 614 | return 0; 615 | } 616 | 617 | 618 | 619 | /* Inintialise the sum to the lowest valid sum */ 620 | int init_stack_list() 621 | { 622 | int idx; 623 | int retval=0; 624 | 625 | for(idx=SKIP_DEPTH;idxstack_depth;idx++) 626 | init_number(&sum->stack[idx]); 627 | if(sum->stack_depth>1) 628 | retval=increment_sum_order(); 629 | return retval; 630 | } 631 | 632 | int increment_operators(depth_t depth) 633 | { 634 | depth_t idx; 635 | int done=FALSE; 636 | stack_entry *curr; 637 | operation last_operation=(depthstack_depth;idx++) 641 | { 642 | curr=&sum->stack[idx]; 643 | if(curr->tag==arithmetic_operation_tag&&op_depth[curr->val]==depth) 644 | { 645 | curr->val++; 646 | if(curr->val>=last_operation) 647 | curr->val=first_operator[depth-1]; 648 | else 649 | break; 650 | } 651 | } 652 | return(idx>=sum->stack_depth); 653 | } 654 | 655 | 656 | 657 | #if defined(HAVE_RATIOED_ERROR_MEASUREMENTS) && (defined(HAVE_BLOCK_DIST_RATIOED_ERROR) || defined(HAVE_DIST_RATIOED_ERROR)) 658 | error_t calulate_error_ratio(dimension_t *array_indices) 659 | { 660 | #if MULTI_DIMENSIONAL 661 | error_t retval=0; 662 | dimension_t curr_dimension,curr_index; 663 | for(curr_dimension=0;curr_dimensionnum_answers 713 | #endif 714 | ; 715 | number_t *answers= 716 | #if (!defined(NUM_ANSWERS)||defined(SPARSE_ARRAY_INDICES)) 717 | &testvals->answer[0]; 718 | #else 719 | &testvals.answer[0]; 720 | #endif 721 | 722 | for(curr_answer=0;curr_answerresult_stack[0] - (error_t) 727 | #ifdef MULTIPLE_RESULTS 728 | *answers++ 729 | #else 730 | testvals 731 | #endif 732 | ; 733 | #ifdef HAVE_POWER1_RATIOED_ERROR_MEASUREMENTS 734 | error_ratioed_pow1 = error_pow1/calculate_error_ratio(array_indices); 735 | #endif 736 | #ifdef HAVE_LMS_ERROR_MEASUREMENTS 737 | error_lms=(error_pow1*error_pow1); 738 | #endif 739 | #ifdef HAVE_POWER1_RATIOED_ERROR_MEASUREMENTS 740 | error_ratioed_lms = error_lms/calculate_error_ratio(array_indices); 741 | #endif 742 | #ifdef HAVE_LMS_ERROR 743 | error_val[lms_error]+=error_lms; 744 | #endif 745 | #ifdef HAVE_ABS_ERROR 746 | error_val[abs_error]+=(error_pow1>=0 ? error_pow1 : -error_pow1); 747 | #endif 748 | 749 | #ifdef HAVE_GT_ERROR_MEASUREMENTS 750 | if(error_pow1>=0) 751 | { 752 | #ifdef HAVE_GT_ERROR 753 | error_val[gt_error]+=error_pow1; 754 | #endif 755 | #ifdef HAVE_LMS_GT_RATIOED_ERROR 756 | error_val[lms_gt_error]+=error_lms; 757 | #endif 758 | #ifdef HAVE_GT_RATIOED_ERROR 759 | error_val[gt_ratioed_error]+=error_ratioed_pow1; 760 | #endif 761 | } 762 | #endif 763 | #ifdef HAVE_LT_ERROR_MEASUREMENTS 764 | if(error_pow1<=0) 765 | { 766 | #ifdef HAVE_LT_ERROR 767 | error_val[lt_error]-=error_pow1; 768 | #endif 769 | #ifdef HAVE_LMS_LT_RATIOED_ERROR 770 | error_val[lms_lt_error]+=error_lms; 771 | #endif 772 | #ifdef HAVE_LT_RATIOED_ERROR 773 | error_val[lt_ratioed_error]-=error_ratioed_pow1; 774 | #endif 775 | } 776 | #endif 777 | #endif 778 | 779 | #ifdef NUM_INTEGER_BITS 780 | retval = (sum->result_stack[0]== 781 | #ifdef MULTIPLE_RESULTS 782 | *answers++ 783 | #else 784 | testvals 785 | #endif 786 | ); 787 | #else /* NUM_INTEGER_BITS */ 788 | { 789 | 790 | #ifdef ERROR_OP 791 | retval = (ERROR_OP(sum->result_stack[0])== 792 | #ifdef MULTIPLE_RESULTS 793 | *answers++ 794 | #else 795 | testvals 796 | #endif 797 | ); 798 | #else /* ERROR_OP */ 799 | if(sum->result_stack[0]==0) 800 | error1=( 801 | #ifdef MULTIPLE_RESULTS 802 | (*answers++) 803 | #else 804 | testvals 805 | #endif 806 | ); 807 | else 808 | error1=( 809 | #ifdef MULTIPLE_RESULTS 810 | (*answers++) 811 | #else 812 | testvals 813 | #endif 814 | /sum->result_stack[0])-1.0; 815 | if(error1<0.0) 816 | error1=-error1; 817 | #if 0 818 | retval = (error1stack_depth;idx++) 856 | { 857 | curr=&sum->stack[idx]; 858 | if(curr->tag==function_tag) 859 | { 860 | if(curr->minus==FALSE) 861 | { 862 | curr->minus=TRUE; 863 | break; 864 | } 865 | else 866 | curr->minus=FALSE; 867 | } 868 | } 869 | return(idx>=sum->stack_depth); 870 | } 871 | #endif 872 | #endif 873 | #endif 874 | #ifdef HAVE_CONSTANTS_FILE 875 | int check_sum() 876 | { 877 | int idx1,idx2; 878 | stack_entry *curr; 879 | fundamental_constant *curr_const; 880 | 881 | if(sum->result_stack[0]!=0) 882 | { 883 | for(idx1=0;idx1stack_depth;idx2++) 886 | { 887 | curr=&sum->stack[idx2]; 888 | if(curr->tag==constant_tag&&curr->val==idx1) 889 | goto Skip; 890 | } 891 | curr_const=fundamental_list[idx1]; 892 | if(result_correct(curr_const->value)) 893 | { 894 | printf("Found match " 895 | #ifndef NUM_INTEGER_BITS 896 | "error="NUMBER_FORMAT 897 | #endif 898 | " fundamental constant name=%s value="NUMBER_FORMAT"\n", 899 | #ifndef NUM_INTEGER_BITS 900 | error1, 901 | #endif 902 | curr_const->name,curr_const->value); 903 | return(idx1); 904 | } 905 | Skip:; 906 | } 907 | } 908 | return(-1); 909 | } 910 | #endif 911 | 912 | 913 | int compare_stack_entries(const void *c1, const void *c2) 914 | { 915 | return(((stack_entry *)c1)->tag-((stack_entry *)c1)->tag); 916 | } 917 | 918 | 919 | 920 | int loop_operators() 921 | { 922 | int done=TRUE; 923 | depth_t depth; 924 | 925 | for(depth=min_operator_depth;depth<=max_operator_depth&&done;depth++) 926 | done=increment_operators(depth); 927 | return done; 928 | } 929 | 930 | number_t *curr_result_ptr; 931 | int sum_switch(stack_entry *curr) 932 | { 933 | #ifdef HAVE_FUNCTIONS 934 | number_t *function_result_ptr 935 | #endif 936 | ; 937 | 938 | switch(curr->tag) 939 | { 940 | #ifdef HUNTER 941 | #ifdef HAVE_FUNCTIONS 942 | case function_tag: 943 | function_result_ptr=(curr_result_ptr-NUM_SEQUENCE_DIMENSIONS); 944 | if(cast_to_dimensions(temp_dimensions,array_indices,function_result_ptr)) 945 | { 946 | return TRUE; 947 | } 948 | *function_result_ptr=( 949 | #ifdef SIGNED_OPERATION 950 | curr->minus ? -*get_array_member(temp_dimensions,NULL) : 951 | #endif 952 | *get_array_member(temp_dimensions,NULL)); 953 | curr_result_ptr-=(NUM_SEQUENCE_DIMENSIONS-1); 954 | break; 955 | #endif 956 | case dimension_tag: 957 | #ifdef SIGNED_OPERATION 958 | if(curr->minus) 959 | *curr_result_ptr++= 960 | #ifdef SEQUENCE_HUNTER 961 | -array_indices[curr->val] 962 | #endif 963 | #ifdef REAL_HUNTER 964 | -get_dimension(real_coord_idx,curr->val) 965 | #endif 966 | ; 967 | else 968 | #endif 969 | *curr_result_ptr++= 970 | #ifdef SEQUENCE_HUNTER 971 | array_indices[curr->val] 972 | #endif 973 | #ifdef REAL_HUNTER 974 | get_dimension(real_coord_idx,curr->val) 975 | #endif 976 | ; 977 | break; 978 | #endif 979 | #ifdef HAVE_CONSTANTS_FILE 980 | case constant_tag: 981 | #ifdef SIGNED_OPERATION 982 | if(curr->minus) 983 | *curr_result_ptr++=-fundamental_list[curr->val]->value; 984 | else 985 | #endif 986 | *curr_result_ptr++=fundamental_list[curr->val]->value; 987 | break; 988 | #endif 989 | 990 | case integer_tag: 991 | #ifdef SIGNED_OPERATION 992 | if(curr->minus) 993 | *curr_result_ptr++=-(number_t)curr->val; 994 | else 995 | #endif 996 | *curr_result_ptr++=(number_t)curr->val; 997 | break; 998 | case arithmetic_operation_tag: 999 | if(do_sum(&curr_result_ptr,curr)) 1000 | return TRUE; 1001 | break; 1002 | } 1003 | #ifdef RESULT_MASK 1004 | *(curr_result_ptr-1)&=RESULT_MASK; 1005 | #endif 1006 | return FALSE; 1007 | } 1008 | void sum_correct_func(calculate_sum_result *retval) 1009 | { 1010 | #ifdef SEQUENCE_HUNTER 1011 | dimension_t idx; 1012 | #endif 1013 | if(!retval->aborted) 1014 | #ifdef HUNTER 1015 | if(!result_correct( 1016 | #ifdef REAL_HUNTER 1017 | get_real_member(real_coord_idx) 1018 | #endif 1019 | #ifdef SEQUENCE_HUNTER 1020 | *get_array_member(array_indices,&idx) 1021 | #endif 1022 | )) 1023 | retval->sum_correct=FALSE; 1024 | if(retval->sum_correct) 1025 | { 1026 | retval->num_sequence_correct_depth= 1027 | #ifdef REAL_HUNTER 1028 | result_coord_depth>=num_real_coord_idx;_ 1029 | #endif 1030 | #ifdef SEQUENCE_HUNTER 1031 | idx 1032 | #endif 1033 | +1; 1034 | } 1035 | #ifdef SEQUENCE_HUNTER 1036 | if(retval->num_sequence_correct_depth==sequence_array_size) 1037 | retval->sum_correct=TRUE; 1038 | #endif 1039 | #ifdef REAL_HUNTER 1040 | if(real_coord_depth+1>num_real_coord_idx) 1041 | retval->sum_correct=TRUE; 1042 | #endif 1043 | #endif 1044 | #ifdef HAVE_CONSTANTS_FILE 1045 | if(check_sum()==-1) 1046 | retval->sum_correct=FALSE; 1047 | #endif 1048 | } 1049 | calculate_sum_result calculate_sum(sum_t *sum,calculate_sum_func_t sum_func) 1050 | { 1051 | 1052 | int idx; 1053 | #ifdef HUNTER 1054 | int good; 1055 | #endif 1056 | calculate_sum_result retval; 1057 | retval.sum_correct=TRUE; 1058 | #if !defined(NUM_INTEGER_BITS) && !defined(ERROR_OP) 1059 | retval.sum_correct_error_tolerance=NAN; 1060 | retval.num_sequence_correct_depth=0; 1061 | #endif 1062 | #ifdef MULTIPLE_RESULTS 1063 | memset(retvals,0,MAX_NUM_RESULTS*sizeof(*retvals)); 1064 | #endif 1065 | #ifdef SEQUENCE_HUNTER 1066 | init_array_indices( 1067 | #ifdef HAVE_FUNCTIONS 1068 | sum->seed 1069 | #else 1070 | MIN_SEED 1071 | #endif 1072 | #ifdef SPARSE_ARRAY_INDICES 1073 | ,TRUE 1074 | #endif 1075 | ); 1076 | #endif 1077 | #ifdef REAL_HUNTER 1078 | init_real_coord_idx(); 1079 | #endif 1080 | #ifdef REAL_HUNTER 1081 | do 1082 | { 1083 | #endif 1084 | #ifdef SEQUENCE_HUNTER 1085 | do 1086 | { 1087 | #endif 1088 | curr_result_ptr=&sum->result_stack[0]; 1089 | for(idx=0;idxstack_depth;idx++) 1090 | { 1091 | retval.aborted=sum_switch(&sum->stack[idx]); 1092 | if(retval.aborted) 1093 | goto skip; 1094 | } 1095 | 1096 | if((curr_result_ptr<&sum->result_stack[0])&&(curr_result_ptr>&sum->result_stack[(max_stack_depth)])) 1097 | { 1098 | fprintf(stderr,"Sum below is illegal curr_result_ptr(%p)" 1099 | "!=&result_stack[0](%p)\n", 1100 | curr_result_ptr,&sum->result_stack[0]); 1101 | print_sum(sum); 1102 | exit(-1); 1103 | } 1104 | 1105 | 1106 | 1107 | sum_func(&retval); 1108 | skip: 1109 | #ifdef HUNTER 1110 | good=(!retval.aborted&&(retval.sum_correct 1111 | #ifdef HAVE_ERROR_MEASUREMENTS 1112 | ||error_sums_good() 1113 | #endif 1114 | ) ? 1:0); 1115 | if(good) 1116 | { 1117 | #if !defined(NUM_INTEGER_BITS) && !defined(ERROR_OP) 1118 | retval.sum_correct_error_tolerance= 1119 | (retval.sum_correct_error_tolerance==NAN ? error1 : 1120 | (retval.sum_correct_error_tolerance>error1 ? retval.sum_correct_error_tolerance: error1)); 1121 | #endif 1122 | } 1123 | #endif // HUNTER 1124 | #ifdef SEQUENCE_HUNTER 1125 | } 1126 | while(good&&!increment_array_indices( 1127 | #ifdef HAVE_FUNCTIONS 1128 | sum->seed 1129 | #else 1130 | MIN_SEED 1131 | #endif 1132 | #ifdef SPARSE_ARRAY_INDICES 1133 | ,TRUE 1134 | #endif 1135 | ) 1136 | ); 1137 | #endif /* SEQUENCE_HUNTER */ 1138 | #ifdef REAL_HUNTER 1139 | } 1140 | while(good&&!increment_real_coord_idx()); 1141 | #endif 1142 | return retval; 1143 | } 1144 | 1145 | 1146 | 1147 | void process_fundamentals() 1148 | { 1149 | int prev_num_sequence_correct_depth=0; 1150 | int cnt= 1151 | #ifdef HAVE_UNARY_OPERATORS 1152 | 2; 1153 | #else 1154 | #ifdef HAVE_BINARY_OPERATORS 1155 | 3; 1156 | #endif 1157 | #endif 1158 | for(sum->stack_depth= 1159 | (1+SKIP_DEPTH) 1160 | ;sum->stack_depth<=MAX_STACK_DEPTH; 1161 | 1162 | #if min_operator_depth==max_operator_depth==2 && (!defined(HAVE_FUNCTIONS) || NUM_SEQUENCE_DIMENSIONS==2) 1163 | sum->stack_depth+=2 1164 | #else 1165 | sum->stack_depth++ 1166 | #endif 1167 | 1168 | ) 1169 | { 1170 | curr_depth1=sum->stack_depth-1; 1171 | #ifdef HAVE_PROGRESS 1172 | gettimeofday(&starttime[sum->stack_depth],NULL); 1173 | #endif 1174 | #if defined(HAVE_FUNCTIONS) 1175 | for(sum->seed=min_seed;sum->seed<=max_seed;sum->seed++) 1176 | #endif 1177 | { 1178 | if(init_stack_list()) 1179 | goto skip_depth_label; 1180 | do 1181 | { 1182 | #if defined(HAVE_FUNCTIONS) && defined(SIGNED_OPERATION) 1183 | do 1184 | { 1185 | #endif 1186 | do 1187 | { 1188 | 1189 | do 1190 | { 1191 | #ifdef HAVE_ERROR_MEASUREMENTS 1192 | /* This I believe works for floating point values as well */ 1193 | memset(&error_val,0,sizeof(error_t)*NUM_ERROR_MEASUREMENTS); 1194 | #endif 1195 | 1196 | calculate_sum_result result=calculate_sum(sum,sum_correct_func); 1197 | if(!result.aborted) 1198 | { 1199 | #ifdef HAVE_ERROR_MEASUREMENTS 1200 | int idx; 1201 | for(idx=0;idxprev_num_sequence_correct_depth&&!result.aborted) 1207 | { 1208 | 1209 | print_sum(sum); 1210 | printf("sequence_correct_depth %d fully_correct %s\n",result.num_sequence_correct_depth,((result.sum_correct&&!result.aborted) ? "yes" : "no")); 1211 | prev_num_sequence_correct_depth=result.num_sequence_correct_depth; 1212 | } 1213 | #endif 1214 | } while(!increment_numbers()); 1215 | } while(!loop_operators()); 1216 | #if defined(HAVE_FUNCTIONS) && defined(SIGNED_OPERATION) 1217 | } while(!increment_functions()); 1218 | #endif 1219 | }while(!increment_sum_order()); 1220 | } 1221 | skip_depth_label:; 1222 | } 1223 | } 1224 | 1225 | #ifdef HAVE_ERROR_MEASUREMENTS 1226 | void process_fundamentals_have_error_measurements() 1227 | { 1228 | for(next_refinement_depth=refinement_depth;next_refinement_depth<=max_stack_depth;next_refinement_depth+=refinement_depth-1) 1229 | { 1230 | if(next_refinement_depth==refinement_depth) 1231 | process_fundamentals(); 1232 | else 1233 | { 1234 | int idx; 1235 | 1236 | for(idx=0;idxprocessed) 1244 | { 1245 | element->processed=TRUE; 1246 | memcpy(sum,&element->sum,offsetof(sum_t,stack[element->sum.stack_depth])); 1247 | skip_depth=element->sum.stack_depth; 1248 | process_fundamentals(); 1249 | } 1250 | } 1251 | } 1252 | } 1253 | } 1254 | print_error_measurements(); 1255 | } 1256 | 1257 | #define PROCESS_FUNDAMENTALS() process_fundamentals_have_error_measurements() 1258 | #else 1259 | #define PROCESS_FUNDAMENTALS() process_fundamentals() 1260 | #endif 1261 | 1262 | #ifdef HAVE_ERROR_MEASUREMENTS 1263 | static void signal_print_error_measurements(int signal) 1264 | { 1265 | printf("Intermediate results\n"); 1266 | print_error_measurements(); 1267 | } 1268 | #endif 1269 | 1270 | #ifdef SEQUENCE_HUNTER 1271 | void init_sequence(int argc,char *argv[],int curropt) 1272 | { 1273 | int idx; 1274 | sequence_dimension=myalloc("sequence_dimension",NUM_SEQUENCE_DIMENSIONS*sizeof(dimension_t)); 1275 | array_indices=myalloc("array_indices",NUM_SEQUENCE_DIMENSIONS*sizeof(dimension_t)); 1276 | temp_dimensions=myalloc("temp_dimensions",NUM_SEQUENCE_DIMENSIONS*sizeof(dimension_t)); 1277 | sequence_dimension_multiplier=myalloc("sequence_dimension_multiplier",NUM_SEQUENCE_DIMENSIONS*sizeof(dimension_t)); 1278 | sequence_array_size=1; 1279 | for(idx=0;idxnext=NULL; 1383 | strcpy(new_entry->name,name); 1384 | new_entry->type=type; 1385 | new_entry->value=value; 1386 | if(idx==0) 1387 | head=new_entry; 1388 | else 1389 | prev_entry->next=new_entry; 1390 | prev_entry=new_entry; 1391 | } 1392 | else 1393 | { 1394 | if(numassigned>0) 1395 | exit_error("syntax error on line %d or %s\n",idx+1,optarg); 1396 | break; 1397 | } 1398 | } 1399 | fclose(fstream); 1400 | if(idx==0) 1401 | exit_error("No entries found in file %s\n",optarg); 1402 | num_constants=idx; 1403 | fundamental_list=(fundamental_constant **)myalloc("fundamental_list",num_constants*sizeof(fundamental_constant *)); 1404 | if(fundamental_list) 1405 | { 1406 | fundamental_constant *curr_entry=head; 1407 | 1408 | for(idx=0;idxnext) 1412 | curr_entry=curr_entry->next; 1413 | } 1414 | } 1415 | else 1416 | exit_error("Ran out of memory allocating indexed_head\n"); 1417 | break; 1418 | #endif 1419 | case 'a': 1420 | max_num_answers=atoi(optarg); 1421 | break; 1422 | case 'm': 1423 | max_stack_depth=atoi(optarg); 1424 | if(max_stack_depth<1) 1425 | max_stack_depth=1; 1426 | #ifndef HAVE_UNARY_OPERATORS 1427 | max_stack_depth|=1; 1428 | #endif 1429 | sum=(sum_t *)myalloc("sum",offsetof(sum_t,stack[max_stack_depth])); 1430 | #ifdef HAVE_PRINT_SUM_INFIX 1431 | tree_members=(struct infix_tree **)myalloc("tree_members",sizeof(struct infix_tree *)*max_stack_depth); 1432 | #endif 1433 | sum->result_stack=(number_t *)myalloc("result_stack",sizeof(number_t)*((max_stack_depth))); 1434 | break; 1435 | #ifdef REAL_HUNTER 1436 | case 'f': 1437 | #ifndef NUM_HUNTER_DIMENSIONS 1438 | NUM_HUNTER_DIMENSIONS=atoi(optarg); 1439 | #endif 1440 | break; 1441 | case 'j': 1442 | readreals(optarg); 1443 | break; 1444 | #endif 1445 | #ifdef SEQUENCE_HUNTER 1446 | #ifndef MULTIPLE_RESULTS 1447 | case 'f': 1448 | case 'i': 1449 | #ifndef NUM_SEQUENCE_DIMENSIONS 1450 | NUM_SEQUENCE_DIMENSIONS=atoi(optarg); 1451 | #endif 1452 | #endif 1453 | case 's': 1454 | { 1455 | int curropt=optind 1456 | #ifdef NUM_SEQUENCE_DIMENSIONS 1457 | -1 1458 | #else 1459 | -((c=='i'||c=='f') ? 0:1) 1460 | #endif 1461 | ; 1462 | #ifdef HAVE_FUNCTIONS 1463 | min_seed=atoi(argv[curropt++]); 1464 | max_seed=atoi(argv[curropt++]); 1465 | if(max_seed<0||NUM_SEQUENCE_DIMENSIONS<1||min_seed>max_seed) 1466 | goto error; 1467 | #endif 1468 | init_sequence(argc,argv,curropt++); 1469 | #if 0 /* looks like old code */ 1470 | idx=optind+2+NUM_SEQUENCE_DIMENSIONS; 1471 | #endif 1472 | #if defined(MULTIPLE_RESULTS) && !defined(NUM_ANSWERS) 1473 | MAX_NUM_RESULTS=0; 1474 | #endif 1475 | #ifndef MULTIPLE_RESULTS 1476 | if(c=='f') 1477 | { 1478 | line=1; 1479 | fstream=fopen(argv[curropt++],"r"); 1480 | if(fstream==NULL) 1481 | { 1482 | perror(""); 1483 | exit_error("An error occured opening %s\n"); 1484 | } 1485 | } 1486 | #endif 1487 | do 1488 | { 1489 | int retval; 1490 | result_t result; 1491 | #ifndef MULTIPLE_RESULTS 1492 | if(c=='s') 1493 | #endif 1494 | { 1495 | if(!sequence_func(&result,array_indices)) 1496 | { 1497 | *get_array_member(array_indices,NULL)=result; 1498 | #if defined(MULTIPLE_RESULTS) && !defined(NUM_ANSWERS) 1499 | #ifdef SPARSE_ARRAY_INDICES 1500 | if(!result) 1501 | continue; 1502 | #endif 1503 | if(result->num_answers<=0) 1504 | exit_error("Illegal number of answers=%d\n",result->num_answers); 1505 | if(result->num_answers>MAX_NUM_RESULTS) 1506 | MAX_NUM_RESULTS=result->num_answers; 1507 | #endif 1508 | } 1509 | else 1510 | exit_error("illegal sequence attempt\n"); 1511 | } 1512 | #ifndef MULTIPLE_RESULTS 1513 | else if(c=='i') 1514 | *get_array_member(array_indices,NULL)=ASCII_TO_NUM(argv[curropt++]); 1515 | else if(c=='f') 1516 | { 1517 | numassigned=fscanf(fstream,"%39s\n",(char *)&numbuff); 1518 | if(numassigned==1) 1519 | *get_array_member(array_indices,NULL)=ASCII_TO_NUM(numbuff); 1520 | else 1521 | exit_error("syntax error in file %s or %s\n",optarg,line); 1522 | line++; 1523 | } 1524 | #endif 1525 | } while(!increment_array_indices(MIN_SEED 1526 | #ifdef SPARSE_ARRAY_INDICES 1527 | ,FALSE 1528 | #endif 1529 | )); 1530 | #ifndef MULTIPLE_RESULTS 1531 | if(c=='f') 1532 | fclose(fstream); 1533 | #endif 1534 | #ifdef MULTIPLE_RESULTS 1535 | retvals=myalloc("retvals",sizeof(*retvals)*MAX_NUM_RESULTS); 1536 | #endif 1537 | } 1538 | break; 1539 | #endif 1540 | #if !defined(NUM_INTEGER_BITS) && !defined(ERROR_OP) 1541 | case 'e': 1542 | error_tolerance=atof(optarg); 1543 | if(error_tolerance<0.0||error_tolerance>1.0) 1544 | exit_error("illegal tolerance specification must be between 0 & 1.\n"); 1545 | break; 1546 | #endif 1547 | #ifdef HAVE_ERROR_MEASUREMENTS 1548 | case 'r': 1549 | refinement_depth=atoi(optarg); 1550 | if(refinement_depth<=0||refinement_depth>=100) 1551 | exit_error("illegal refinement depth it must be between 0 & 100.\n"); 1552 | break; 1553 | #endif 1554 | default: 1555 | goto error; 1556 | } 1557 | } 1558 | if( 1559 | #ifdef HUNTER 1560 | #ifdef SEQUENCE_HUNTER 1561 | !sequence_dimension 1562 | #endif 1563 | #ifdef REAL_HUNTER 1564 | !coord_and_result_array 1565 | #endif 1566 | #ifdef HAVE_CONSTANTS_FILE 1567 | && 1568 | #endif 1569 | #endif 1570 | #ifdef HAVE_CONSTANTS_FILE 1571 | !fundamental_list 1572 | #endif 1573 | ) 1574 | goto error; 1575 | #ifdef HAVE_PROGRESS 1576 | starttime=myalloc("starttime",(max_stack_depth+1)*sizeof(*starttime)); 1577 | gettimeofday(&starttime[0],NULL); 1578 | signal(SIGUSR1,print_progress); 1579 | #endif 1580 | #ifdef HAVE_ERROR_MEASUREMENTS 1581 | signal(SIGUSR2,signal_print_error_measurements); 1582 | #endif 1583 | #ifdef SEQUENCE_HUNTER 1584 | number_range[dimension_tag].hi_val=NUM_SEQUENCE_DIMENSIONS-1; 1585 | #endif 1586 | #ifdef REAL_HUNTER 1587 | number_range[dimension_tag].hi_val=NUM_HUNTER_DIMENSIONS-1; 1588 | #endif 1589 | #ifdef HAVE_CONSTANTS_FILE 1590 | if(fundamental_list) 1591 | number_range[constant_tag].hi_val=num_constants-1; 1592 | #endif 1593 | number_range[integer_tag].hi_val=hi_int; 1594 | first_number=first_tag; 1595 | while(number_range[first_number].lo_val>number_range[first_number].hi_val) 1596 | first_number++; 1597 | curr_number=first_number; 1598 | next_number=first_number+1; 1599 | while(next_number<=last_number_tag) 1600 | { 1601 | if(number_range[next_number].lo_val<=number_range[next_number].hi_val) 1602 | { 1603 | number_range[curr_number].next_tag=next_number; 1604 | curr_number=next_number; 1605 | } 1606 | next_number++; 1607 | } 1608 | number_range[curr_number].next_tag=first_number; 1609 | PROCESS_FUNDAMENTALS(); 1610 | return 0; 1611 | error:; 1612 | exit_error("Usage\n" 1613 | "=====\n" 1614 | "%s -h hi_int -m max_stack_depth" 1615 | "<-a max_num_answers>" 1616 | #ifdef HAVE_CONSTANTS_FILE 1617 | " <-c constants file>" 1618 | #endif 1619 | #ifdef REAL_HUNTER 1620 | #ifndef NUM_HUNTER_DIMENSIONS 1621 | " -f num_hunter_dimensions " 1622 | #endif 1623 | " -j csvfile " 1624 | #endif 1625 | #ifdef SEQUENCE_HUNTER 1626 | " <<-s " 1627 | #ifdef HAVE_FUNCTIONS 1628 | "min_seed max_seed" 1629 | #endif 1630 | " dimensions > " 1631 | #ifndef MULTIPLE_RESULTS 1632 | "<-i " 1633 | #ifndef NUM_SEQUENCE_DIMENSIONS 1634 | "num_sequence_dimensions " 1635 | #endif 1636 | #ifdef HAVE_FUNCTIONS 1637 | "min_seed max_seed " 1638 | #endif 1639 | "dimensions sequence_values>> " 1640 | #ifndef MULTIPLE_RESULTS 1641 | "<-f " 1642 | #ifndef NUM_SEQUENCE_DIMENSIONS 1643 | "num_sequence_dimensions " 1644 | #endif 1645 | #ifdef HAVE_FUNCTIONS 1646 | "min_seed max_seed " 1647 | #endif 1648 | "dimensions sequence_file>>" 1649 | #endif 1650 | #endif 1651 | #endif /* MULTIPLE_RESULTS */ 1652 | #if !defined(NUM_INTEGER_BITS) && !defined(ERROR_OP) 1653 | " <-e error_tolerance >" 1654 | #endif 1655 | #ifdef HAVE_ERROR_MEASUREMENTS 1656 | " <-r refinement depth (default 8)>" 1657 | #endif 1658 | 1659 | "\n" 1660 | #ifdef NUM_SEQUENCE_DIMENSIONS 1661 | "NUM_SEQUENCE_DIMENSIONS is defined to be %d\n" 1662 | 1663 | #endif 1664 | ,argv[0] 1665 | #ifdef NUM_SEQUENCE_DIMENSIONS 1666 | ,NUM_SEQUENCE_DIMENSIONS 1667 | 1668 | #endif 1669 | ); 1670 | return -1; 1671 | } 1672 | --------------------------------------------------------------------------------