performance - Efficiency issue on Guile SCHEME: member and equal? -
performance - Efficiency issue on Guile SCHEME: member and equal? -
i new on scheme programming , after while succeeded on writing couple of scripts deal long maths formulas.
the issue execution pretty slow. after profiling realized execution takes 35% of time executing built-in functions equal? , member.
my question regarding whether there exist more efficient version of functions or should re-factor code in order remove calls?
i'm re-write code appreciate piece of advice.
thanks!
edit 1:
i add together code making question clearer. next function takes 2 parameters, pair (x,y) , term, x , y variable names(symbols), may symbol , number, list , symbol, etc. term list such
(+ w y z (* (- 1) x)) so after function execution
(+ w z) the code looks following:
(define (simp-by-term_eq t_cc t) (cond ((and (member (list '* (list '- 1) (car t_cc)) (cdr t)) (member (cadr t_cc) (cdr t))) (delete-1st (cadr t_cc) (delete-1st (list '* (list '- 1) (car t_cc)) (cdr t))) ) ((and (member (list '* (car t_cc) (list '- 1)) (cdr t)) (member (cadr t_cc) (cdr t))) (delete-1st (cadr t_cc) (delete-1st (list '* (car t_cc) (list '- 1)) (cdr t))) ) (else t) ) ) there several conditions previous 1 on function.
the equal function calls used filter callse such as
(filter (lambda (x) (and (not (equal? (list '* (car t_cc) (list '- 1)) x)) (not (equal? (list '* (list '- 1) (car t_cc)) x)))) t)
equal? needs test every part of list construction traverses both operands until has touched sequences , compared atomic values. if need test if it's same can utilize eq? checks pair has same address. evaluate #f when list construction same. that's ok. eqv? similar eq? works numbers , characters (but not strings).
you can utilize memq uses eq? instead of equal? , can utilize memqv uses eqv? works numbers , characters. i'm not familiar guile if have performance issues , using member perhaps should consider hash tables instead?
it happen need rethink algorithm utilize if need utilize equal?, without specific code it's hard more specific.
performance functional-programming scheme equality
Comments
Post a Comment