logicmoo

FIB examples

Feb 16th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

CL-USER> (defun fib (n)
CL-USER>>> (setq f (cons 0 1))
CL-USER>>> (setq i 0)
CL-USER>>> (while (< i n)
CL-USER>>> (setq f (cons (cdr f) (+ (car f) (cdr f))))
CL-USER>>> (setq i (+ i 1)))
CL-USER>>> (car f))

```prolog
:- lisp_compiled_eval(
                      [ defun,
                        u_fib,
                        [u_n],
                        [setq, u_f, [cons, 0, 1]],
                        [setq, u_i, 0],

                        [ u_while,
                          [<, u_i, u_n],
                          [setq, u_f, [cons, [cdr, u_f], [+, [car, u_f], [cdr, u_f]]]],
                          [setq, u_i, [+, u_i, 1]]
                        ],
                        [car, u_f]
                      ]).
## COMPILER
% 3,614,597 inferences, 0.599 CPU in 0.599 seconds (100% CPU, 6039330 Lips)
lambda_def(defun, u_fib, f_u_fib, [u_n], [[setq, u_f, [cons, 0, 1]], [setq, u_i, 0], [u_while, [<, u_i, u_n], [setq, u_f, [cons, [cdr, u_f], [+, [car, u_f], [cdr, u_f]]]], [setq, u_i, [+, u_i, 1]]], [car, u_f]]).
arglist_info(u_fib, f_u_fib, [u_n], arginfo{all:[u_n], allow_other_keys:0, aux:0, body:0, complex:0, env:0, key:0, names:[u_n], opt:0, req:[u_n], rest:0, sublists:0, whole:0}).
 init_args(x, f_u_fib).

Compiled Function: U::FIB

f_u_fib(N_In, FnResult) :-
        AEnv=[bv(u_n, N_In)],
        catch(( ( F=[0|1],
                  set_var(AEnv, u_f, F),
                  set_var(AEnv, u_i, 0),
                  call_addr_block(AEnv,
                                  (push_label(while287), get_var(AEnv, u_i, I_Get25), get_var(AEnv, u_n, N_Get26), (I_Get25<N_Get26->get_var(AEnv, u_f, Get30), f_cdr(Get30, Cdr_Ret), get_var(AEnv, u_f, Get31), f_car(Get31, Car_Ret), get_var(AEnv, u_f, Get32), f_cdr(Get32, Cdr_Ret46), 'f_+'(Car_Ret, Cdr_Ret46, CDR), F41=[Cdr_Ret|CDR], set_var(AEnv, u_f, F41), get_var(AEnv, u_i, I_Get33), 'f_+'(I_Get33, 1, I), set_var(AEnv, u_i, I), goto(while287, AEnv), _TBResult=_GORES34;_TBResult=[])),

                                  [ addr(addr_tagbody_1_while287,
                                         while287,
                                         '$unused',
                                         AEnv,
                                         (get_var(AEnv, u_i, I_Get), get_var(AEnv, u_n, N_Get), (I_Get<N_Get->get_var(AEnv, u_f, Cdr_Param), f_cdr(Cdr_Param, Cdr_Ret48), get_var(AEnv, u_f, Get16), f_car(Get16, Car_Ret49), get_var(AEnv, u_f, Get17), f_cdr(Get17, Cdr_Ret50), 'f_+'(Car_Ret49, Cdr_Ret50, CDR51), Set_var_Ret=[Cdr_Ret48|CDR51], set_var(AEnv, u_f, Set_var_Ret), get_var(AEnv, u_i, I_Get19), 'f_+'(I_Get19, 1, Set_var_Ret53), set_var(AEnv, u_i, Set_var_Ret53), goto(while287, AEnv), _1794=_GORES;_1794=[])))
                                  ]),
                  get_var(AEnv, u_f, Get37),
                  f_car(Get37, Car_Ret54)
                ),
                Car_Ret54=FnResult
              ),
              block_exit(u_fib, FnResult),
              true).
:- set_opv(u_fib, symbol_function, f_u_fib),
   DefunResult=u_fib.
## EXEC
% 399 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 1385094 Lips)
FIB
CL-USER> (fib 350)
:- lisp_compiled_eval([u_fib, 350]).
## COMPILER
% 30,012 inferences, 0.005 CPU in 0.005 seconds (100% CPU, 5823815 Lips)
:- f_u_fib(350, Fib_Ret).
## EXEC
% 283,857 inferences, 0.091 CPU in 0.092 seconds (99% CPU, 3119485 Lips)
6254449428820551641549772190170184190608177514674331726439961915653414425
```cl
CL-USER>         (defun my-map (f xs)
CL-USER>>>           (if xs
CL-USER>>>               (cons (eval (list f (car xs))) (my-map f (cdr xs)))
CL-USER>>>             ()))
:- lisp_compiled_eval(
                      [ defun,
                        u_my_map,
                        [u_f, u_xs],

                        [ if,
                          u_xs,

                          [ cons,
                            [eval, [list, u_f, [car, u_xs]]],
                            [u_my_map, u_f, [cdr, u_xs]]
                          ],
                          []
                        ]
                      ]).
## COMPILER
% 1,560,782 inferences, 0.254 CPU in 0.254 seconds (100% CPU, 6156864 Lips)
lambda_def(defun, u_my_map, f_u_my_map, [u_f, u_xs], [[if, u_xs, [cons, [eval, [list, u_f, [car, u_xs]]], [u_my_map, u_f, [cdr, u_xs]]], []]]).
arglist_info(u_my_map, f_u_my_map, [u_f, u_xs], arginfo{all:[u_f, u_xs], allow_other_keys:0, aux:0, body:0, complex:0, env:0, key:0, names:[u_f, u_xs], opt:0, req:[u_f, u_xs], rest:0, sublists:0, whole:0}).
 init_args(x, f_u_my_map).

Compiled Function: U::MY-MAP

f_u_my_map(In, Xs_In, FnResult) :-
        GEnv=[bv(u_f, In), bv(u_xs, Xs_In)],
        catch(( ( get_var(GEnv, u_xs, IFTEST),
                  (   IFTEST\==[]
                  ->  get_var(GEnv, u_f, Get),
                      get_var(GEnv, u_xs, Xs_Get11),
                      f_car(Xs_Get11, Car_Ret),
                      _958=[Get, Car_Ret],
                      f_sys_env_eval(GEnv, _958, Env_eval_Ret),
                      get_var(GEnv, u_f, Get12),
                      get_var(GEnv, u_xs, Xs_Get13),
                      f_cdr(Xs_Get13, Cdr_Ret),
                      f_u_my_map(Get12, Cdr_Ret, My_map_Ret),
                      TrueResult=[Env_eval_Ret|My_map_Ret],
                      _898=TrueResult
                  ;   _898=[]
                  )
                ),
                _898=FnResult
              ),
              block_exit(u_my_map, FnResult),
              true).
:- set_opv(u_my_map, symbol_function, f_u_my_map),
   DefunResult=u_my_map.
## EXEC
% 357 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 2375913 Lips)
MY-MAP
CL-USER>
CL-USER>>>         (defun plus1 (x) (+ 1 x))
:- lisp_compiled_eval([defun, u_plus1, [u_x], [+, 1, u_x]]).
## COMPILER
% 279,107 inferences, 0.041 CPU in 0.041 seconds (100% CPU, 6869395 Lips)
lambda_def(defun, u_plus1, f_u_plus1, [u_x], [[+, 1, u_x]]).
arglist_info(u_plus1, f_u_plus1, [u_x], arginfo{all:[u_x], allow_other_keys:0, aux:0, body:0, complex:0, env:0, key:0, names:[u_x], opt:0, req:[u_x], rest:0, sublists:0, whole:0}).
 init_args(x, f_u_plus1).

Compiled Function: U::PLUS1

f_u_plus1(X_In, FnResult) :-
        GEnv=[bv(u_x, X_In)],
        catch(( ( get_var(GEnv, u_x, X_Get),
                  'f_+'(1, X_Get, _580)
                ),
                _580=FnResult
              ),
              block_exit(u_plus1, FnResult),
              true).
:- set_opv(u_plus1, symbol_function, f_u_plus1),
   DefunResult=u_plus1.
## EXEC
% 357 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 2551750 Lips)
PLUS1
CL-USER>
CL-USER>>>         (my-map 'plus1 '(1 2 3))
:- lisp_compiled_eval([u_my_map, [quote, u_plus1], [quote, [1, 2, 3]]]).
## COMPILER
% 36,268 inferences, 0.005 CPU in 0.005 seconds (100% CPU, 7127828 Lips)
:- f_u_my_map(u_plus1, [1, 2, 3], My_map_Ret).
## EXEC
% 86,365 inferences, 0.012 CPU in 0.012 seconds (100% CPU, 7162086 Lips)
(2 3 4)

CL-USER>
Add Comment
Please, Sign In to add comment