;;; -*- Mode:Common-Lisp; Package:DME-user; Base:10; -*-

(in-package :dme-user)

;;;
;;; Definitions of the instances of operators and their eval functions
;;;

(define-q-operator = 
  "Q= is the n-ary q-operator for equating two or more q-expressions 
    Eg: (Q= (Term-1 voltage) (Term-2 voltage) (Term-3 voltage)) 
    (Q= (Term-1 current) (Q* (Term-1 voltage) (Resistor-1 resistance)))"
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-=-eqn)

(define-q-operator All=
  "All-Q= is the q-operator for equating a set of q-expressions. 
    Usually used in conjunction with the SetOf operator. 
    Eg: (All-Q= (SetOf X (Resistor-1 terminal) (X voltage))) which asserts 
    that all the terminals of Resistor-1 have the same voltage."
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-all-Q=)


(define-q-operator constant
  "Constant is a unary p-operator for specifying that the expression
   is constant.
    Eg: (Constant (Term-1 voltage) )"
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-constant)

(define-q-operator increasing
  "Increasing is a unary p-operator for specifying that the expression
   is increasing.
    Eg: (increasing (Term-1 voltage) )"
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-constant)

(define-q-operator decreasing
  "Decreasing is a unary p-operator for specifying that the expression
   is decreasing.
    Eg: (decreasing (Term-1 voltage) )"
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-constant)

(define-q-operator non-constant
  "Non-constant is a unary p-operator for specifying that the expression
   is non-constant.
    Eg: (non-constant (Term-1 voltage) )"
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-constant)

(define-q-operator non-increasing
  "Non-increasing is a unary p-operator for specifying that the expression 
  is non-increasing.
    Eg: (non-increasing (Term-1 voltage) )"
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-constant)

(define-q-operator non-decreasing
  "Non-decreasing is a unary p-operator for specifying that the expression
   is non-decreasing.
    Eg: (non-decreasing (Term-1 voltage) )"
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-constant)

(define-q-operator sum-to 
  "Q+= is the q-operator for expressing an additive component of some
   simulator variable. 
    Eg: (Q+= (Battery-1 current) (Term-11 current)) which asserts that 
       the current of Battery-1 is composed of a sum of which 
       the current thru Term-11 is a component. 
    A closed-world-assumption is needed to convert a bunch of such Q+= eqns
    into a Q= eqn."
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-=-eqn)


;;; +,*,-,/
(define-q-operator + 
  "Q+ is the nary q-operator for adding several q-expressions. 
    Eg: (Q+ (Term-12 current) (Term-13 current) (Term-14 current))."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-+-expr)


(define-q-operator - 
  "Q- is (i) the unary q-operator for expressing the negation of a
   q-expression 
 (ii) the binary q-operator for expressing the difference between its 2
   q-expression arguments. 
    Eg: (Q- (Term-14 voltage)) 
        (Q- (Term-12 current) (Term-13 current))"
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate---expr)


(define-q-operator * 
  "Q* is the nary q-operator for expressing the multiplication product
   of its q-expressions arguments. 
    Eg: (Q* (Term-12 current) (Resistor-13 resistance) "
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-*-expr)


(define-q-operator / 
  "Q/ is the binary q-operator for expressing the division of one
   q-expression by another. 
    Eg: (Q/ (Resistor-13 potentialDifference) (Resistor-13 resistance) "
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-/-expr)


(define-q-operator expt 
  "expt is the binary operator.  The meaning is the same as LISP expt.
    Eg: (Q+ (Term-12 current) (Term-13 current) (Term-14 current))."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-*-expr)

(define-q-operator exp
  "exp is the monadic exp operator.  The meaning is the same as LISP exp."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op)

(define-q-operator sqrt
  "sqrt is the monadic sqrt operator.  The meaning is the same as LISP sqrt."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op)

(define-q-operator sum 
  "All-Q+ is used in conjunction with the SetOf operator to express the
   sum of a group of q-terms.
    Eg: (All-Q+ (SetOf TERM (Device-12 inputTerminals) (TERM current))) 
       expresses the sum of the current flowing thru the input terminals of
       Device-12."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-all-Q+)


;;; M+, abs etc
(define-q-operator M+ 
  "QM+ is a unary q-operator for expressing a monotonic function of its
   q-expression argument. 
    Usually used in conjunction with Q= to express a monotonic relationship
    between 2 q-expressions. 
    Eg: (Q= (Block-11 position) (QM+ (Spring-11 displacement)). "
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-m
  :qsim-translation-function dme::qsim-translate-M+-expr)


(define-q-operator M- 
  "QM- is a unary q-operator for expressing an inverse monotonic function
   of its q-expression argument. 
    Usually used in conjunction with Q= to express an inverse  monotonic
    relationship between 2 q-expressions. 
    Eg: (Q= (Spring-11 acceleration) (QM- (Spring-11 displacement)). "
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-m
  :qsim-translation-function dme::qsim-translate-M--expr)


(define-q-operator M0+ 
  "QM0+ is a more specific version of QM+, such that (QM0+ <x>) is 0 when
   <x> is 0."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-m
  :qsim-translation-function dme::qsim-translate-M0+-expr)


(define-q-operator M0- 
  "QM0- is a more specific version of QM-, such that (QM0- <x>) is 0 when
   <x> is 0."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-m
  :qsim-translation-function dme::qsim-translate-M0--expr)


(define-q-operator Abs 
  "QAbs is a unary q-operator for expressing the absolute value of a
   q-expression term"
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op
  :qsim-translation-function dme::qsim-translate-absolute-expr)


;;; d/dt
(define-q-operator d/dt 
  "Qd/dt is a unary q-operator for expressing the time derivative of a
   q-expression term. 
    Often used in conjunction with Q=. 
    Eg: (Q= (Block-11 velocity) (Qd/dt (Block position))) "
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-d/dt
  :qsim-translation-function dme::qsim-translate-d/dt-expr)


;;; IncreaseAtRate etc
(define-q-operator Increase-at-rate 
  "IncreaseAtRate is a binary q-operator for expressing positive influencing
   components of a quantity-term. 
    Eg:  (IncreaseAtRate (Device-9 heatContent)
                         (Process-14 heatGenerationRate)) and 
        (DecreaseAtRate (Device-9 heatContent) (Process-26 heatRemovalRate))
     together 
      states that the heat content of Device-9 is changing 
     (assuming no other influences) 
      at a rate equal to the difference between Process-14's rate and
      Process-26's rate. 
    IncreaseAtRate expressions are constraints, and do not evaluate to values."
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-increase-at-rate)


(define-q-operator Decrease-at-rate 
  "DecreaseAtRate is a binary q-operator for expressing negative influencing
   components of a quantity-term. 
    Eg:  (IncreaseAtRate (Device-9 heatContent)
                         (Process-14 heatGenerationRate)) and 
         (DecreaseAtRate (Device-9 heatContent) (Process-26 heatRemovalRate))
         together 
      states that the heat content of Device-9 is changing
      (assuming no other influences) 
      at a rate equal to the difference between Process-14's rate and
      Process-26's rate. 
    DecreaseByAmt expressions are constraints, and do not evaluate to values."
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-decrease-at-rate)


(define-q-operator Increase-by-amt 
  "IncreaseByAmt is a binary q-operator for expressing a positive additive
   component of a quantity-term. 
    Eg:  (IncreaseByAmt (Battery-11 amtOfCharge) (Cell-12 amtOfCharge)) 
         (IncreaseByAmt (Battery-11 amtOfCharge) (Cell-13 amtOfCharge))
   together 
      states that the amt of charge in Battery-11 is the sum of the amt of
   charge in Cell-12 and Cell-13, and possibly other components too. 
    IncreaseByAmt expressions are constraints, and do not evaluate to values."
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-increase-by)


(define-q-operator Decrease-by-amt  
  "DecreaseByAmt is a binary q-operator for expressing a negative additive
   component of a quantity-term. 
    See IncreaseBtAmt."
  :class  q-constraint-operator
  :partial-eval-function dme::partial-eval-decrease-by)


;;; Mapping constructs
(define-q-operator ForEach 
  "ForEach is a mapping q-operator for iterating a set of q-constraints over
   each of a set of objects. 
    Eg: (ForEach TERM (Device-12 terminals) 
      (Q= (TERM voltage) 0)   
      (Q= (TERM current) 0))  
    ForEach expressions can be nested within one another for multiple loops."
  :class  q-mapping-operator
  :partial-eval-function dme::partial-eval-foreach)


(define-q-operator SetOf 
  "SetOf is a mapping q-operator for generating a set of q-expression terms
   for other operators like All-Q=. 
     Eg: (SetOf TERM (Device-12 terminals) 
                 (TERM voltage))
     would represent the set of q-expressions representing the voltages of
     each terminal of Device-12."
  :class q-mapping-operator
  :partial-eval-function dme::partial-eval-set-of)

#+CML
(define-q-operator cml-user::NIntegral
  "NIntegral ?????"
  :class q-expression-operator
  :partial-eval-function dme::partial-eval-nintegral)

#+CML
(define-q-operator cml-user::setofinstances
  "SetOfInstances ?????"
  :class q-expression-operator
  :partial-eval-function dme::partial-eval-setofinstances)

#+CML
(define-q-operator cml-user::deriv
  "Deriv ?????"
  :class q-expression-operator
  :partial-eval-function dme::partial-eval-deriv)

;;; Add SUM because of package problem

#+CML
(define-q-operator cml-user::sum 
  "All-Q+ is used in conjunction with the SetOf operator to express the
   sum of a group of q-terms.
    Eg: (All-Q+ (SetOf TERM (Device-12 inputTerminals) (TERM current))) 
       expresses the sum of the current flowing thru the input terminals of
       Device-12."
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-all-Q+)

#+CML

(define-q-operator cml-user::round
  "Round is the unary q-operator for rounding the value of its
argument
    Eg: (round (* 2.3 1.4))"
  :class  q-expression-operator
  :partial-eval-function dme::partial-eval-math-op
  )

;;; Don't delete this form-feed char.

;;; 
;;; Enable GNU Emacs version numbers.  Don't mess with these
;;; lines, or we'll find you and we'll kill you...
;;; 
;;; Local Variables:
;;; mode: lisp
;;; version-control: t  
;;; End:

This Lisp-to-HTML translation was brought to you by
François Gerbaux and Tom Gruber