(defclass FUZZY ()  ((fuzz-value    :initarg :fuzz-value    :initform 'nil    :reader fuzz-value    :accessor fuzz-value    :type t)   (fuzz-type    :initarg :fuzz-type    :initform 'universal    :reader fuzz-type    :accessor fuzz-type    :type symbol)   )   (:documentation "FUZZY (LOL class) : Used to define if an object that inherits thisclass is fuzzy or not.Slots are :fuzz-value and :type.")   )(defgeneric fuzzy-p (object)  (:documentation   "Tests if an object is fuzzy or not.Attention : if an object is both numerical and fuzzy but has a value,             fuzzy-p returns nil.In other words, priority is given to numerical (numerical) values.For instance try :(fuzzy-p (make-direction nil))(fuzzy-p (make-direction 10))."))#|(:documentation 'fuzzy-p)|#(defmethod fuzzy-p ((object fuzzy))  t)(defmethod fuzzy-p ((object t))  nil)(defclass FUZZNUM (fuzzy)  ((name    :initarg :name    :reader name    :initform ""    :accessor name    :type string)   (value    :initarg :value    :reader value    :initform '()    :accessor value    :type list)   (membership    :initarg :membership    :reader membership    :initform '()    :accessor membership    :type list)   (shape    :initarg :shape    :initform '(lambda (a x b) (+ (* a x) b))    :accessor shape    :type list)))(defmethod print-object ((fuzznum fuzznum) stream)  (format stream          "~S:~S" (name fuzznum) (fuzz-value fuzznum))  (values))(defmethod fuzzyf ((number integer) &key min max range func)  (when (null min)    (setf min (1- number)))  (when (null max)    (setf max (+ number (- number min))))  (when (null func)    (setf func '(lambda (a x b) (+ (* a x) b))))  (make-instance 'fuzznum    :fuzz-value (if range                   (read-from-string (format nil "~S->~S" number (+ number range)))                  number)    :fuzz-type 'fuzznum-discret    :name (read-from-string (symbol-name  (gensym "f")))    :value (remove 'nil                   (list min number (if (not range) nil (+ number range))  max))    :membership (remove 'nil                        (list 0 1 (when range 1) 0))    :shape func))#|(setf a (fuzzyf 5))(describe a)(value a)(setf b (fuzzyf 5 :min 3 :max 6))(describe b)ab(setf k (fuzzyf 5 :min 3 :max 8 :range 1))(fuzz-value k)k(value k)(membership k)(fuzz-value a)(fuzz-value b)(equal a c)(setf c a)(setf d (fuzzyf 5))(equalp a d)|#(defgeneric = (a b)  (:documentation   "Tests if a = b. Replace Standart function = and test on fuzzy elements."))(defmethod = ((a fuzznum) (b fuzznum))   (and (and (equal (value a)                    (value b))             (equal (membership a)                    (membership b)))        (equal (shape a) (shape b))))(defmethod = ((a number) (b number))   (eq a b))#|(= 1 1)(= a d)|#(defmethod & ((a t) (b t))  (list a b))(defmethod & ((a fuzznum) (b fuzznum))   (let ((min (max (apply #'min (value a)) (apply #'min (value b))))         (max (min (apply #'max (value a)) (apply #'max (value b))))          )     (if (= min max)       (make-instance 'fuzznum           :fuzz-value nil           :name (read-from-string (format nil "~S&~S" (name a) (name b)))           :value nil           :membership nil           )       (multiple-value-bind (a1 b1)                            (line-eq min 0 (max (cadr (value a)) (cadr (value b))) 1)         (multiple-value-bind (a2 b2)                              (line-eq max 0 (min (cadr (value a)) (cadr (value b))) 1)           (make-instance 'fuzznum             :fuzz-value (float (/ (- (+ b1 (* a1 (float (/ (- b2 b1) (- a1 a2))))) b1)                                   a1))             :name (read-from-string (format nil "~S&~S" (name a) (name b)))             :value (list min                          (float (/ (- (+ b1 (* a1 (float (/ (- b2 b1) (- a1 a2))))) b1)                                    a1))                          max)             :membership (list 0                               (+ b1 (* a1 (float (/ (- b2 b1) (- a1 a2)))))                               0)             ))))))#|(value (& (fuzzyf 5) (fuzzyf 6)))(membership (& (fuzzyf 5) (fuzzyf 6)))(type-of (& a b))(value (& (fuzzyf 5)    (fuzzyf 6)))(fmin (& (fuzzyf 5)    (fuzzyf 6)))(fmax (& (fuzzyf 5)    (fuzzyf 6)))(& a b)test :(& (fuzzyf 5)    (fuzzyf 7)) ; = 0.0 YES !!!(setf x (fuzzyf 5))(setf y (fuzzyf 7))(= a x)(setf z (& x y))(value z)(membership z)|#(defun line-eq (x1 y1 x2 y2)  "Donne les coefficients a b de la droite : y = ax + bpassant par les points (x1 y1) et (x2 y2)."  (if (= x1 x2) (values nil 0)      (let ((a (/ (- y2 y1) (- x2 x1)))            (b))        (setf b (- y1 (* a x1)))        (values a b))))(line-eq 5 0 6 1)(line-eq 6 1 7 0)(defun x& (#|(defun fNOT (p)  (- 1 p))(defun fOR (p q)  (if (>= p q)    p q))(defun fAND (p q)  (if (>= p q)    q p))|#;;; ******* fuzzy operations ************(defgeneric more (object)  (:documentation   "Add a quantity to the value slot of a numerical object."))(defmethod more ((object numerical))   (setf (value object) (+ (value object) (frac object)))   object)(defmethod more ((object modulo))   (setf (value object) (mod (+ (value object) (frac object)) (modulo object)))   object)(defgeneric less (object)  (:documentation   "Substract a quantity to the value slot of a numerical object."))(defmethod less ((object numerical))   (setf (value object) (- (value object) (frac object)))   object)(defmethod less ((object modulo))   (setf (value object) (mod (- (value object) (frac object)) (modulo object)))   object)  #|(setf a (make-direction 10))(value a)(more a)a(value a)(less a)(setf a (make-direction nil))(value a)(more a)a(value a)(less a)|#(defclass fuzznum ()  ((value    :initarg :value    :reader value    :initform '()    :accessor value    :type list)   (memb    :initarg :memb    :reader memb    :initform '()    :accessor memb    :type lsit)   (shape    :initarg :shape    :initform '(lambda (a x b) (+ (* a x) b))    :accessor shape    :type list)))