2 implementations of grad:
#1
/digego/extempore/tree/v0.8.9/libs/core/math.xtm ·
#2
/digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
(bind-func grad
(lambda (hash:i64 x:double y:double z:double)
(set! hash (bitwise-and hash 15))
(cond
((= hash 0) (+ x y))
((= hash 1) (+ (- 0. x) y))
((= hash 2) (- x y))
((= hash 3) (- (- 0. x) y))
((= hash 4) (+ x z))
((= hash 5) (+ (- 0. x) z))
((= hash 6) (- x z))
((= hash 7) (- (- 0. x) z))
((= hash 8) (+ y z))
((= hash 9) (+ (- 0. y) z))
((= hash 10) (- y z))
((= hash 11) (- (- 0. y) z))
((= hash 12) (+ y x))
((= hash 13) (+ (- 0. y) z))
((= hash 14) (- y x))
((= hash 15) (- (- 0. y) z))
(else 0.))))