User:Spekkio: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1:
<math>\pi</math>
 
 
 
{{mylangbegin}}
{{mylang|C|Active}}
Line 15 ⟶ 11:
{{mylang|x86 Assembly|Rusty}}
{{mylangend}}
 
 
Hello! I'm a Electronic Engineer, working with electronics developement.
 
 
I love computer programming, and my hobby is to program small simple computer programs.
 
I usually get stuck on an idea that I think would be fun to try and solve.
 
I love learning new programming languages.
 
Found this page recently, and it is perfect for me. :D
 
 
Currently I'm working on Huffman coding in C, and implementing a multi precision library to calculate
 
maclaurin series for different functions sin/cos/sqrt/pow etc... (see my recent post in [[Talk:Nth root]])
 
<lang lisp>
(defun factorial (n)
(if (= n 0)
1
(* n (factorial (- n 1)))))
 
(defun powint (a b)
(if (= b 0)
1
(* a (powint a (- b 1)))))
 
(defun binom (alpha n)
(if (= n 1)
alpha
(* (binom alpha (- n 1)) (/ (+ (- alpha n) 1) n))))
 
(defun pow (a b n)
(if (= n 0)
1
(+ (* (binom b n) (powint (- a 1) n)) (pow a b (- n 1)))))
 
(defun logS(x n) (if (= n 0) (* 2 x) (+ (* 2 (/ (powint x (+ (* 2 n) 1)) (+ (* 2 n) 1))) (logS x (- n 1)) ) ))
 
(defun loge(x n) (logS (/ (- x 1) (+ 1 x)) n))
 
(defun expon(x n) (if (= n 0) 1 (+ (/ (powint x n) (factorial n)) (expon x (- n 1)))))
 
(defun sqrtn(x n) (expon (* 1/2 (loge x n)) n))
 
(defun pown(x a n) (expon (* a (loge x n)) n))
 
(defun sine(x n)
(if (= n 0)
x
(+ (* (/ (powint -1 n) (factorial (+ (* 2 n) 1)) ) (powint x (+ (* 2 n) 1))) (sine x (- n 1)))))
 
(defun cosi(x n) (if (= n 0) 1 (+ (* (/ (powint -1 n) (factorial (* 2 n)) ) (powint x (* 2 n))) (cosi x (- n 1)))))
 
(defun tang(x n) (/ (sine x n) (cosi x n)))
 
(defun asine (x n)
(if (= n 0)
x
(+ (/ (* (factorial (* 2 n)) (powint x (+ (* 2 n) 1))) (* (powint 4 n) (powint (factorial n) 2) (+ (* 2 n) 1))) (asine x (- n 1)))))
 
(defun fibcalc (n p)
(let ((sqrtFive (sqrtn 5 p)))
(/ (- (powint (* 1/2 (+ 1 (sqrtFive))) n) (powint (* 1/2 (- 1 (sqrtFive))) n)) (sqrtFive))))
 
(defun fibrec (n)
(if (= n 0)
0
(if (= n 1)
1
(+ (fibrec (- n 1)) (fibrec (- n 2))))))
</lang>
Anonymous user