;;;;; ;;;;; ;;;;; Mathematical Functions ;;;;; ;;;;; (define \$abs (lambda [\$x] (if (rational? x) (b.abs x) x))) (define \$neg (lambda [\$x] (if (rational? x) (b.neg x) (* -1 x)))) (define \$exp (lambda [\$x] (if (float? x) (b.exp x) (if (term? x) (match x term-expr {[,0 1] [,1 e] [ (** -1 a)] [_ (`exp x)]}) (`exp x))))) (define \$log (lambda [\$x] (if (float? x) (b.log x) (match x math-expr {[,1 0] [,e 1] [_ (`log x)]})))) (define \$cos (lambda [\$x] (if (float? x) (b.cos x) (match x math-expr {[,0 1] [>> (** -1 (abs n))] [
,2> 0] [_ (`cos x)]})))) (define \$sin (lambda [\$x] (if (float? x) (b.sin x) (match x math-expr {[,0 0] [ 0] [
,2> (** -1 (/ (- (abs n) 1) 2))] [_ (`sin x)]})))) (define \$tan (lambda [\$x] (if (float? x) (b.tan x) (match x math-expr {[,0 0] [_ (`tan x)]})))) (define \$cosh (lambda [\$x] (if (float? x) (b.cosh x) (match x math-expr {[,0 1] [_ (`cosh x)]})))) (define \$sinh (lambda [\$x] (if (float? x) (b.sinh x) (match x math-expr {[,0 0] [_ (`sinh x)]})))) (define \$tanh (lambda [\$x] (if (float? x) (b.tanh x) (match x math-expr {[,0 0] [_ (`tanh x)]})))) (define \$sinc (lambda [\$x] (if (float? x) (if (eq? x 0.0) 1.0 (/ (b.sin x) x)) (match x math-expr {[,0 1] [_ (/ (sin x) x)]})))) (define \$sigmoid (lambda [\$z] (/ 1 (+ 1 (exp (* -1 z)))))) (define \$kronecker-delta (cambda \$js (if (all (eq? \$ (car js)) (cdr js)) 1 0))) (define \$euler-totient-function (lambda [\$n] (* n (product (map (lambda [\$p] (- 1 (/ 1 p))) (unique (p-f n))))))) (define \$ε (memoized-lambda [\$n] (let {[[\$es \$os] (even-and-odd-permutations' n)]} (generate-tensor (cambda \$is (if (member? is es) 1 (if (member? is os) -1 0))) (take n (repeat1 n)))))) (define \$ε' (memoized-lambda [\$n \$k] (let {[[\$es \$os] (even-and-odd-permutations' n)]} (generate-tensor (cambda \$is (match (drop k is) (list integer) {[>>> 0] [_ (if (member? is es) 1 (if (member? is os) -1 0))]})) (take n (repeat1 n))))))