00001 # ifndef CPPAD_ADD_INCLUDED
00002 # define CPPAD_ADD_INCLUDED
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 namespace CppAD {
00017 
00018 template <class Base>
00019 AD<Base> AD<Base>::operator +(const AD<Base> &right) const
00020 {
00021         AD<Base> result;
00022         CPPAD_ASSERT_UNKNOWN( Parameter(result) );
00023 
00024         result.value_  = value_ + right.value_;
00025 
00026         if( Variable(*this) )
00027         {       if( Variable(right) )
00028                 {       
00029                         CPPAD_ASSERT_KNOWN(
00030                                 id_ == right.id_,
00031                                 "Adding AD objects that are"
00032                                 " variables on different tapes."
00033                         );
00034                         tape_this()->RecordOp(AddvvOp, 
00035                                 result, taddr_, right.taddr_
00036                         );
00037                 }
00038                 else if( IdenticalZero(right.value_) )
00039                 {       
00040                         result.make_variable(id_, taddr_);
00041                 }
00042                 else
00043                 {       
00044                         tape_this()->RecordOp(AddvpOp, 
00045                                 result, taddr_, right.value_
00046                         );
00047                 }
00048         }
00049         else if( Variable(right) )
00050         {       if( IdenticalZero(value_) )
00051                 {       
00052                         result.make_variable(right.id_, right.taddr_);
00053                 }
00054                 else
00055                 {       
00056                         right.tape_this()->RecordOp(AddpvOp, 
00057                                 result, value_, right.taddr_
00058                         );
00059                 }
00060         }
00061         return result;
00062 }
00063 
00064 
00065 CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(+)
00066 
00067 } 
00068 
00069 # endif