Also er handelt sich bei folgendem Code um LISP Quelltext und ihr braucht einen CommonLisp Interpreter um es zu Nutzen. Es leitet Gleichungen zu einer bestimmten Unbekannten ab, die Benutzung werde ich unten nochmal erklären.
Ich weiß es hat wenig bis nichts mit Gaming zu tun, aber ich denke und hoffe das hier dennoch ein paar einen Nutzen davon haben.
Bekannte Bugs:
Es kann vorkommen, dass die Unbekannte verloren geht, warum das ist und wann genau das passiert konnte ich noch nicht ausarbeiten, also wenn jemand eine Idee oder die Lösung hat her damit.
Code
- (defun constant? (arg) (numberp arg))
- (defun variable? (arg) (symbolp arg))
- (defun same-variable? (v1 v2) (and (variable? v1) (variable? v2) (equal v1 v2) ))
- (defun zero? (arg) (and (constant? arg) (zerop arg)))
- (defun only-constants? (arg1 arg2) (and (constant? arg1) (constant? arg2)))
- (defun sum? (arg) (if (not (atom arg)) (equal (first arg) '+) nil ))
- (defun addend (arg) (second arg))
- (defun augend (arg) (third arg))
- (defun product? (arg) (if (not (atom arg)) (equal (first arg) '*) nil ))
- (defun multiplier (arg) (second arg))
- (defun multiplicand (arg) (third arg))
- (defun pot? (arg) (if (not (atom arg)) (equal (first arg) '^) nil ))
- (defun base (arg) (second arg))
- (defun potent (arg) (third arg))
- (defun sin? (arg) (if (not (atom arg)) (equal (first arg) 'sin) nil ))
- (defun cosin? (arg) (if (not (atom arg)) (equal (first arg) 'cos) nil ))
- (defun rad (arg) (second arg))
- (defun quotient? (arg) (if (not (atom arg)) (equal (first arg) '/) nil ))
- (defun nummer (arg) (second arg))
- (defun divisor (arg) (third arg))
- (defun difference? (arg) (if (not (atom arg)) (equal (first arg) '-) nil ))
- (defun minuend (arg) (second arg))
- (defun subtrahend (arg) (third arg))
- (defun make-sum (arg1 arg2) (cond ((zero? arg1) arg2) ((zero? arg2) arg1) ((only-constants? arg1 arg2) (+ arg1 arg2)) (t (list '+ arg1 arg2)) ))
- (defun make-product (arg1 arg2) (cond ((or (zero? arg1) (zero? arg2)) 0) ((only-constants? arg1 arg2) (* arg1 arg2)) (t (list '* arg1 arg2)) ))
- (defun make-potent (arg1 arg2) (cond ((zero? arg2) 1) ((and (numberp arg2) (= arg2 1)) arg1) ((zero? arg1) 0) ((only-constants? arg1 arg2) (expt arg1 arg2)) (t (list '^ arg1 arg2)) ))
- (defun make-sin (arg1) (list 'sin arg1))
- (defun make-cos (arg1) (list 'cos arg1))
- (defun make-quotient (arg1 arg2) (cond ((zero? arg1) 0) ((zero? arg2) nil) ((only-constants? arg1 arg2) (/ arg1 arg2)) (t (list '/ arg1 arg2)) ))
- (defun make-difference (arg1 arg2) (cond ((zero? arg1) (make-product -1 arg2)) ((zero? arg2) arg1) ((only-constants? arg1 arg2) (- arg1 arg2)) (t (list '- arg1 arg2)) ))
- (defun deriv (exp var) (cond ((constant? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0) ) ((sin? exp) (make-product -1 (make-cos (rad exp)))) ((cosin? exp) (make-sin (rad exp))) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var) ) ) ((difference? exp) (make-difference (deriv (minuend exp) var) (deriv (subtrahend exp) var) ) ) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)) ) ) ((quotient? exp) (make-quotient (make-difference (make-product (deriv (nummer exp) var) (divisor exp)) (make-product (nummer exp) (deriv (divisor exp) var) ) ) (make-potent (divisor exp) 2) ) ) ((pot? exp) (make-product (potent exp) (make-potent (base exp) (- (potent exp) 1)) ) ) ))
- (defun pot (arg1 arg2) (if (not (zerop arg2)) (* arg1 (pot arg1 (- arg2 1))) 1))
Nutzung:
Fragen, Probleme und Bug hier oder aber in meinen Blog wo ich den Quelltext auch veröffentlicht habe.