home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.ai.fuzzy      Fuzzy logic... all warm and fuzzy-like      1,275 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 677 of 1,275   
   Dmitry A. Kazakov to All   
   Re: Fuzzy Union in C++ (1/2)   
   24 Jan 07 11:51:25   
   
   From: mailbox@dmitry-kazakov.de   
      
   On Wed, 24 Jan 2007 02:25:43 +0100, Seweryn Habdank-Wojewódzki wrote:   
      
   > Dmitry A. Kazakov wrote:   
   >   
   >> Right, it makes sense when dealing with fixed point types. It is a very   
   >> difficult problem though. [No, please, don't propose templates! (:-))]   
   >   
   > At the beginning you can start with template:   
      
   No. Let I have two different fixed-point types. One represents length in   
   inches another does height feet. Fixed-point formally means:   
      
      +, -, * and truncating division operations are exact.   
      
   Now what is the fixed-point type of the area inches*feet [accuracy,   
   ranges]? What is the fixed-point type of division of height to length   
   [accuracy ranges]? How these permanent changes of accuracy and ranges   
   propagate throughout a dimensioned expression?   
   [...]   
      
   > So why you as afraid to use templates. More over if you changing the code   
   > from double to long double, respectively to the machine.   
      
   Sorry, this is all C++ problematic, which is really irrelevant here. In a   
   language with properly designed numeric types (which C++ is not) you don't   
   care about the machine numbers. The numeric model there is simply to   
   specify the range and accuracy in terms of the application domain:   
      
   type ADC_Input is delta 0.01 range -10.0..10.0;   
      
   >> There exist others, like propagation of the unit constraint in homogenous   
   >> containers from the types of elements to the container type. I.e. how to   
   >> *automatically* get matrix from matrix>.   
   >   
   > It is possible, but it have completely no sense.   
   [...]   
      
   Of course it does. In physics and engineering:   
      
   (1.0m, 3.0m, 4.0m) = (1,0, 3.0, 4.0)m   
      
   >> Yes, sure. C++ has dynamic polymorphism. That was not the point. The point   
   >> was that it were unreachable using solely templates. Again, templates is a   
   >> design decision to achieve some goals. Which ones? Performance is not an   
   >> issue to me. What then?   
   >   
   > Static error checking. Many many error you can check in compilation time.   
   > The first kind it is compatibility of the types.   
      
   C++ and Ada are statically typed languages = you CANNOT get a type error at   
   run time unless you circumvent the type system.   
      
   > Next feature, you can do metaprogramming, like described earlier e.g.   
      
   Meta (generic) programming = programming in terms of sets of types. It is   
   achievable without templates, by using class-wide subprograms.   
      
   > Next is to check some representation of the type.   
      
   I don't know what this means. Why should I check type representations?   
   There is the type system for this.   
      
   > Next you can check it the type is derived from the other type.   
      
   That's the type system business.   
      
   > For me also important is shortening the code.   
      
   What about zip? (:-)) I saw no studies comparing templated code with normal   
   one. But I would expect templated code potentially longer, sufficiently   
   less readable and almost unmaintainable.   
      
   >> What is the gain? A pointer can be a plain parameter of a plain function.   
   >> The *only* reason for templates in C++ (and generics in Ada) is that a   
   >> *type* cannot be a plain parameter on anything but a template. All   
   >> first-class objects can be.   
   >   
   > Consider such a usage of templates   
   >   
   > #include    
   > #include    
   >   
   > template < typename T >   
   > class foo {   
   >    public:   
   >    foo ( T & t_ ):t(t_){};   
   >    T & operator()(){   
   >      return t;   
   >    };   
   >    private:   
   >    T & t;   
   > };   
   >   
   > template < typename T >   
   > class foo < T* >   
   > {   
   >     public:   
   >     foo ( T*& t_ ): t(t_ ){};   
   >     T & operator()(){   
   >        return *t;   
   >     };   
   >     private:   
   >     T *& t;   
   > };   
   >   
   > int main()   
   > {   
   >     std::string a = "a";   
   >     std::string b = "bb";   
   >     std::string * ptr_s = &b;   
   >     foo  fs(a);   
   >     foo  fptrs(ptr_s);   
   >   
   >     // independently of a type I am using "."   
   >     // so in more general concept, I can write   
   >     // one functor/function independently   
   >     // if I am working on pointer or not   
   >     std::cout << fs().length() << std::endl;   
   >     std::cout << fptrs().length() << std::endl;   
   > }   
      
   That is supposed to solve some problem. Which one? And you didn't answered   
   the question why X of T need to be passed to an instance of the template   
   Bar(T X) rather than to Bar(T X). It looks like you are fighting with   
   some language limitations...?   
      
   >>> for me complement of x is a fuzzy number, combined as membership function   
   >>> and its support. If read carefully my code in R, you can observe similar   
   >>> construction. It can be also dynamical,because you can define dynamical   
   >>> binders, too.   
   >>   
   >> Please elaborate.   
   >>   
   >> I meant that complement of a singleton in R is all R but one point.   
   >   
   > I do not understand that. If you have a fuzzy set e.g. triangle(-1,0,1)   
   > that easy complement is 1-triangle(-1,0,1). And that thing you can do using   
   > boost::lambda.   
   >   
   > generally in lambda notation   
   >   
   > lambda(x) : complement(x) = 1 - x   
      
   This is not a complement, it is pseudo inverse. I meant [fuzzy] complement:   
      
   forall A:R->[0,1] exists ~A:R->[0,1] defined as:   
      
      forall x in R ~A(x) = 1-A(x)   
      
   But if you wished a non-closed numeric operation, then there would be   
   nothing easier. Consider multiplication: x*y is not a triangle.   
      
   >> Decomposed into singletons it gives an uncountable set of.   
   >   
   > But you do not need to decompose anything.   
      
   How so? The result is a set. This set must be represented by the model,   
   which in this case is a finite map: x -> membership value.   
      
   >> This set can be   
   >> represented but for this a different model is required. You can't switch   
   >> models on the fly, as you are static.   
   >   
   > No, but you can define statically both models, and respectively to the   
   > situation you can switch models.   
      
   No you cannot, templates don't allow that. Formally you could have:   
      
      * : T x T -> T   
      
   But what is needed is   
      
      * : T1 x T1 -> T2   
      
   where Ti come from the same class of types (to be switched between). The   
   class is the set of all types which may appear as the template parameter T.   
   Further T2 is unknown until you see the actual arguments of *. I.e.   
   denoting T'Class as closure of the set of types to switch:   
      
      * : T1 x T1 -> T'Class   
      
   Templates cannot do that, per definition of.   
      
   Example:   
      
      T1 = Triangle,   
      T2 = 2-nd order curve   
      ...   
      * = fuzzy multiplication   
      T = { T1, T2, ...}   
      
   >>>>> Yes. but It depends on the assumptions of the project. Every time you   
   >>>>> will have a percent of simplifications, isn't it?   
   >>>>   
   >>>> Yuck! To redesign the whole mess each time I have new data?   
   >>>   
   >>> What you mean new data?   
   >>   
   >> What are the criteria for being redesigned?   
   >   
   > E.g. add an order of fuzzy set. I mean change from first order to second or   
   > more.   
      
   Adding to what? To the system (code) or to the inputs (data)?   
      
   >> Because there is little chance of their use. My use-cases do not include   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca