Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct ORD {
- struct ORD *p;
- int k;
- int n; /* if n=0, o is limit of all ORD's with finite n */
- } ORD;
- #define DECL_ORD(p_,k_,n_) ({ORD o_;o_.p=p_;o_.k=k_;o_.n=n_;&o_;})
- #define ORD_PLUS_N(o,n) DECL_ORD(o,1,n)
- #define ORD_TIMES_N(o,n) DECL_ORD(o,2,n)
- #define ORD_POWER_N(o,n) DECL_ORD(o,3,n)
- #define ORD_TETRATED_TO_N(o,n) DECL_ORD(o,4,n)
- #define OMEGA DECL_ORD(NULL,1,0)
- #define OMEGA_PLUS_ONE DECL_ORD(OMEGA,1,2)
- #define OMEGA_TIMES_TWO DECL_ORD(OMEGA,2,2) /* NOT DECL_ORD(OMEGA,1,0)! */
- #define OMEGA_TIMES_THREE DECL_ORD(OMEGA,2,2)
- #define OMEGA_SQUARED DECL_ORD(OMEGA,3,2) /* = DECL_ORD(OMEGA,2,0) */
- #define OMEGA_CUBED DECL_ORD(OMEGA,3,2)
- #define OMEGA_POWER_OMEGA DECL_ORD(OMEGA,4,2) /* = DECL_ORD(OMEGA,3,0) */
- #define EPSILON_ZERO DECL_ORD(OMEGA,5,2) /* = DECL_ORD(OMEGA,4,0)*/
- #define VEBLEN(n) DECL_ORD(OMEGA,n+4,2) /* defined until phi(omega,0) */
- #define ord_is_finite(o) (!o->p)
- #define ord_is_zero(o) (ord_is_finite(o)&&o->k==0&&o->n==0)
- #define ord_is_successor(o) (o->k==1||(ord_is_finite(o)&&o->k==0&&!ord_is_zero(o)))
- #define ord_is_omega(o) (!o->p&&o->k==1&&!o->p) // omega is (NULL,1,0)
- #define ord_dec(o) (!ord_is_successor(o)?(o->n>1?(o->n--&&1?o:o):o):o)
- /* the hard part :V */
- #define ord_get_fs(o,m) \
- ({ORD *r;if(!ord_is_finite(o)&&o->k>0){\
- if(o->n==0){if(!ord_is_omega(o)){o->n=m;r=o;}else{r=o}}\
- if(o->n==1){if(k>1){r=o->p;}else{r=o}}\
- else if(o->n==2){o->k--;o->n=m;r=o;}\
- else{if(k==0){r=p;}\
- if(k==1){r=o;}\
- else{o->n--;r=DECL_ORD(o,o->k-1,m);}\
- }else{r=(!ord_is_finite(o)&&!ord_is_omega(o)?ord_get_fs(o,m):o);}(r);})
- int _fast_growing_hiearchy(ORD o, int r, int n)
- {
- assert(n > 0);
- if (ord_is_zero(o)) {
- return n + r;
- }
- if (r > 1 || ord_is_successor(o)) {
- if (r > 1) {
- return _fast_growing_hiearchy(o, r - 1, _fast_growing_hiearchy(ord_dec(o), 1, n))
- }
- return _fast_growing_hiearchy(ord_dec(o), n, n);
- }
- if (ord_is_omega(o)) {
- return _fast_growing_hiearchy(n, 1, n)
- }
- return _fast_growing_hiearchy(ord_get_fs(o, n), 1, n)
- }
- int fast_growing_hiearchy(ORD o, int n)
- {
- return _fast_growing_hiearchy(o, 1, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement