Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50527 - in sandbox/itl: boost/itl boost/validate libs/itl/doc libs/itl_xt/test/meta_functors libs/validate/example/labat_single
From: afojgo_at_[hidden]
Date: 2009-01-09 17:34:47


Author: jofaber
Date: 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
New Revision: 50527
URL: http://svn.boost.org/trac/boost/changeset/50527

Log:
Refactored. Degenerated add_intersection for TotalQuantifiers. Stable {msvc-9.0, partly congcc-4.3-a7}
Added documentation. Semantics: Total and PartialQuantifiers.

Text files modified:
   sandbox/itl/boost/itl/interval_base_map.hpp | 86 ++++++++++++++++++++++++---------------
   sandbox/itl/boost/itl/interval_maps.hpp | 27 ------------
   sandbox/itl/boost/itl/map.hpp | 5 +
   sandbox/itl/boost/validate/typevalidater.h | 4
   sandbox/itl/libs/itl/doc/semantics.qbk | 80 +++++++++++++++++++++++++++++++------
   sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp | 18 +++++++
   sandbox/itl/libs/validate/example/labat_single/labat_single.cpp | 8 +-
   7 files changed, 146 insertions(+), 82 deletions(-)

Modified: sandbox/itl/boost/itl/interval_base_map.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_base_map.hpp (original)
+++ sandbox/itl/boost/itl/interval_base_map.hpp 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
@@ -186,8 +186,10 @@
 
     /// Comparison functor for domain values
     typedef ITL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
- /// Combine functor for codomain values
+ /// Combine functor for codomain value aggregation
     typedef ITL_COMBINE_CODOMAIN(Combine,CodomainT) codomain_combine;
+ /// Inverse Combine functor for codomain value aggregation
+ typedef typename inverse<codomain_combine>::type inverse_codomain_combine;
     /// Intersection functor for codomain values
     typedef ITL_SECTION_CODOMAIN(Section,CodomainT) codomain_intersect;
 
@@ -403,6 +405,7 @@
     */
     SubType& add(const value_type& x)
         { that()->template add_<codomain_combine>(x); return *that(); }
+
 //@}
 
 
@@ -472,11 +475,11 @@
     */
     SubType& subtract(const value_type& x)
     {
- typedef typename inverse<Combine<CodomainT> >::type InverseCombine;
+ //CL typedef typename inverse<Combine<CodomainT> >::type InverseCombine;
                 if(Traits::emits_neutrons && !is_set<codomain_type>::value)
- that()->template add_<InverseCombine>(x);
+ that()->template add_<inverse_codomain_combine>(x);
         else
- that()->template subtract_<InverseCombine>(x);
+ that()->template subtract_<inverse_codomain_combine>(x);
     
         return *that();
     }
@@ -952,15 +955,24 @@
 {
     typedef IntervalMap<DomainT,CodomainT,
                         Traits,Compare,Combine,Section,Interval,Alloc> sectant_type;
- if(sectant.empty())
- return;
- typename sectant_type::const_iterator common_lwb;
- typename sectant_type::const_iterator common_upb;
- if(!Set::common_range(common_lwb, common_upb, sectant, *this))
- return;
- typename sectant_type::const_iterator it = common_lwb;
- while(it != common_upb)
- add_intersection(intersection, *it++);
+
+ if(Traits::emits_neutrons)
+ {
+ intersection = *this;
+ intersection += sectant;
+ }
+ else
+ {
+ if(sectant.empty())
+ return;
+ typename sectant_type::const_iterator common_lwb;
+ typename sectant_type::const_iterator common_upb;
+ if(!Set::common_range(common_lwb, common_upb, sectant, *this))
+ return;
+ typename sectant_type::const_iterator it = common_lwb;
+ while(it != common_upb)
+ add_intersection(intersection, *it++);
+ }
 }
 
 template
@@ -973,26 +985,34 @@
                     const typename interval_base_map<SubType,DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
                     ::value_type& sectant)const
 {
- interval_type sectant_interval = sectant.KEY_VALUE;
- if(sectant_interval.empty()) return;
-
- typename ImplMapT::const_iterator fst_it = _map.lower_bound(sectant_interval);
- typename ImplMapT::const_iterator end_it = _map.upper_bound(sectant_interval);
-
- for(typename ImplMapT::const_iterator it=fst_it; it != end_it; it++)
- {
- interval_type common_interval;
- (*it).KEY_VALUE.intersect(common_interval, sectant_interval);
-
- if(!common_interval.empty())
- {
- section.that()->add( value_type(common_interval, (*it).CONT_VALUE) );
- if(is_set<CodomainT>::value)
- section.that()->template add<codomain_intersect>(value_type(common_interval, sectant.CONT_VALUE));
- else
- section.that()->template add<codomain_combine>(value_type(common_interval, sectant.CONT_VALUE));
- }
- }
+ if(Traits::emits_neutrons)
+ {
+ section = *this;
+ section.add(sectant);
+ }
+ else
+ {
+ interval_type sectant_interval = sectant.KEY_VALUE;
+ if(sectant_interval.empty()) return;
+
+ typename ImplMapT::const_iterator fst_it = _map.lower_bound(sectant_interval);
+ typename ImplMapT::const_iterator end_it = _map.upper_bound(sectant_interval);
+
+ for(typename ImplMapT::const_iterator it=fst_it; it != end_it; it++)
+ {
+ interval_type common_interval;
+ (*it).KEY_VALUE.intersect(common_interval, sectant_interval);
+
+ if(!common_interval.empty())
+ {
+ section.that()->add( value_type(common_interval, (*it).CONT_VALUE) );
+ if(is_set<CodomainT>::value)
+ section.that()->template add<codomain_intersect>(value_type(common_interval, sectant.CONT_VALUE));
+ else
+ section.that()->template add<codomain_combine>(value_type(common_interval, sectant.CONT_VALUE));
+ }
+ }
+ }
 }
 
 

Modified: sandbox/itl/boost/itl/interval_maps.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_maps.hpp (original)
+++ sandbox/itl/boost/itl/interval_maps.hpp 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
@@ -25,33 +25,6 @@
 //-----------------------------------------------------------------------------
 // addition +=
 //-----------------------------------------------------------------------------
-/*CL
-template
-<
- class SubType, class DomainT, class CodomainT, class Traits,
- ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc,
- template
- <
- class, class, class,
- ITL_COMPARE, ITL_COMBINE, ITL_SECTION, template<class,ITL_COMPARE>class, ITL_ALLOC
- >
- class IntervalMap
->
-interval_base_map<SubType,DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>&
-operator +=
-(
- interval_base_map<SubType,DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>& object,
- const IntervalMap<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>& operand
-)
-{
- typedef IntervalMap<DomainT,CodomainT,
- Traits,Compare,Combine,Section,Interval,Alloc> operand_type;
- const_FORALL(typename operand_type, elem_, operand)
- object.add(*elem_);
-
- return object;
-}
-*/
 template
 <
         class ObjectT,

Modified: sandbox/itl/boost/itl/map.hpp
==============================================================================
--- sandbox/itl/boost/itl/map.hpp (original)
+++ sandbox/itl/boost/itl/map.hpp 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
@@ -260,7 +260,10 @@
         /** Intersect map \c x2 and \c *this.
             So \c *this becomes the intersection of \c *this and \c x2 */
         map& operator *= (const map& x2)
- { Map::intersect(*this, x2); return *this; }
+ {
+ if(Traits::emits_neutrons) return *this += x2;
+ else{ Map::intersect(*this, x2); return *this; }
+ }
 
         /** Intersect set \c x2 and \c *this.
             So \c *this becomes the intersection of \c *this and \c x2 */

Modified: sandbox/itl/boost/validate/typevalidater.h
==============================================================================
--- sandbox/itl/boost/validate/typevalidater.h (original)
+++ sandbox/itl/boost/validate/typevalidater.h 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
@@ -550,8 +550,8 @@
             }
             else // !is_set && emits_neutrons //JODO && is_abelian_group<Type::value>
             {
- _lawChoice[inplaceSetBaseLaws] = 85;
- _lawChoice[inplaceSymmetricDifference] = 0;
+ _lawChoice[inplaceSetBaseLaws] = 80;
+ _lawChoice[inplaceSymmetricDifference] = 5;
                 _lawChoice[inplaceSelfRemovability] = 5;
                 _lawChoice[inplaceInverseRemovability] = 5;
                 _lawChoice[sectionAbsorbtion] = 5;

Modified: sandbox/itl/libs/itl/doc/semantics.qbk
==============================================================================
--- sandbox/itl/libs/itl/doc/semantics.qbk (original)
+++ sandbox/itl/libs/itl/doc/semantics.qbk 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
@@ -501,6 +501,8 @@
 
 [section Quantifiers: Maps of Numbers]
 
+[h5 Subtraction on Quantifiers]
+
 With `Sets` and `Collectors` the semantics of
 `operator -` is
 that of /set difference/ which means, that you can
@@ -533,17 +535,30 @@
 pair (k,v) can obviously defined as adding the ['*inverse element*]
 for that key (k,-v), if the key is not yet stored in the map.
 
-Another model, that we can think of, is that in a `Quantifier`
+[h4 Partial and Total Quantifiers and Infinite Vectors]
+
+Another concept, that we can think of, is that in a `Quantifier`
 every `key_value` is initially quantified `0`-times, where `0` stands
 for the neutral element of the numeric `CodomainT` type.
 Such a `Quantifier` would be totally defined on all values of
 it's `DomainT` type.
-So a `Quantifier` that has a signed numerical codomain type can be
-conceived as an `InfiniteVector`.
+Such a `Quantifier` can be conceived as an `InfiniteVector`.
 
-To become an infinite vector
+To create an infinite vector
 that is totally defined on it's domain we can set
 the map's `Trait` parameter to the value __emitter__.
+The __emitter__ trait fits specifically well with
+a `Quantifier` if it's `CodomainT` has an inverse
+element, like all signed numerical type have.
+
+As we can see later in this section this kind of
+a total `Quantifier` has the basic properties that
+elements of a
+vector space
+do provide.
+
+We will use the terms `TotalQuantifier` and
+`PartialQuantifier` for those objects.
 
 [table
 [[Trait] [CodomainT as number] [CodomainT more abstract] [Concept for Quanifier Map]]
@@ -551,22 +566,49 @@
 [[!emits_neutrons] [unsigned number] [commutative monoid] [hybrid type]]
 ]
 
+[h5 Intersection on Quantifiers]
+
 Another difference between `Collectors` and `Quantifiers`
-is the semantics of `operator *`, that has the meaing of
+is the semantics of `operator *`, that has the meaning of
 set intersection for `Collectors`.
 
-For the aggregate on overlap principle the operation `*`
+For the /aggregate on overlap principle/ the operation `*`
 has to be passed to combine associated values on overlap
 of intervals or collision of keys. This can not be done
 for `Quantifiers`, since numeric types do not implement
 intersection.
 
-[/ JODO * degeneriert zu +, + wird vector addition, - wird vector subraction, scalarprodukt kann definiert werden]
+For `CodomainT` types that are not models of `Sets`
+`operator *` is defined as aggregation on the intersection
+of the domains.
+``
+//Pseudocode example:
+interval_map<int,int> p, q;
+p = {[1 3)->1 };
+q = { ([2 4)->1};
+p*q =={ [2 3)->2 };
+``
+So an addition or aggregation of associated values is
+done like for `operator +` but value pairs that have
+no common keys are not added to the result.
+
+For `Quantifier` that is a model of an `InfiniteVector`
+and which is therefore defined for every key value of
+the `DomainT` type, this definition of `operator *`
+degenerates to the same sematics that `operaotor +`
+implements:
+``
+//Pseudocode example:
+interval_map<int,int> p, q;
+p = {[min 1)[1 3)[3 max]};
+ ->0 ->1 ->0
+q = {[min 2)[2 4)[4 max]};
+ ->0 ->1 ->0
+p*q =={[min 1)[1 2)[2 3)[3 4)[4 max]};
+ ->0 ->1 ->2 ->1 ->0
+``
+
 
-[/ JODO nur den InfiniteVector Fall beschreiben? Wie könnte man denn den hybrid benennen??
- gibt es interessante nicht numerische Beispiele für Quantifier?
- Was ist mit Quantifier of Quantifier
-]
 
 [h5 Laws on set union, set intersection and set difference]
 
@@ -589,8 +631,8 @@
 SelfRemovability<Q,-,=v= >: Q a: a - a =v= Q()
 ``
 
-For a `Quantifier Map` the same basic laws apply that are
-valid for `Collector Maps`:
+For a `Quantifier` the same basic laws apply that are
+valid for `Collectors`:
 
 ``
                                     + * -
@@ -601,6 +643,18 @@
                  enriches_neutrons =p=
 ``
 
+In addition also symmetrical difference is valid for
+`Qunatifiers` and the
+modified `operator *`.
+``
+SymmetricDifference<Q,== > : Q a,b,c: (a + b) - (a * b) == (a - b) + (b - a)
+``
+For a `TotalQuantifier` `Qt` symmetrical difference degenerates to
+a trivial form since `operator *` and `operator +` become identical
+``
+SymmetricDifference<Qt,== > : Qt a,b,c: (a + b) - (a + b) == (a - b) + (b - a) == 0
+``
+
 
 
 [endsect][/ Quantifiers]

Modified: sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp
==============================================================================
--- sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp (original)
+++ sandbox/itl/libs/itl_xt/test/meta_functors/meta_functors.cpp 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
@@ -223,9 +223,23 @@
 
 void quantifier_intersect_test()
 {
- interval_map<int,int,neutron_emitter> sec_map;
+ typedef interval_map<int,int> QuantifierT;
+ QuantifierT sec_map;
         sec_map += make_pair(interval<int>::rightopen(1,5), 1);
         sec_map *= make_pair(interval<int>::rightopen(3,7), 1);
+ //sec_map *= QuantifierT(make_pair(interval<int>::rightopen(3,7), 1));
+
+ cout << "sec_map: " << sec_map << endl;
+}
+
+void quantifier_subtract_test()
+{
+ typedef interval_map<int,nat> QuantifierT;
+ QuantifierT sec_map;
+ sec_map += make_pair(interval<int>::rightopen(1,5), 1);
+ sec_map -= make_pair(interval<int>::rightopen(3,7), 2);
+ sec_map += make_pair(interval<int>::rightopen(3,7), 3);
+ //sec_map *= QuantifierT(make_pair(interval<int>::rightopen(3,7), 1));
         
         cout << "sec_map: " << sec_map << endl;
 }
@@ -248,7 +262,7 @@
         */
         //codomain_test();
         //string_codomain_test();
- quantifier_intersect_test();
+ quantifier_subtract_test();
     return 0;
 }
 

Modified: sandbox/itl/libs/validate/example/labat_single/labat_single.cpp
==============================================================================
--- sandbox/itl/libs/validate/example/labat_single/labat_single.cpp (original)
+++ sandbox/itl/libs/validate/example/labat_single/labat_single.cpp 2009-01-09 17:34:46 EST (Fri, 09 Jan 2009)
@@ -47,10 +47,10 @@
     //map_cluster_star_pushout.setTrialsCount(1000);
     //map_cluster_star_pushout.run();
 
- typedef InplaceSymmetricDifference<interval_map<int, itl::set<int>, neutron_polluter >, std_equal> TestLawT;
- LawValidater<TestLawT, RandomGentor> test_law;
- test_law.setTrialsCount(1000);
- test_law.run();
+ //typedef InplaceSymmetricDifference<split_interval_map<int, int, neutron_emitter >, std_equal> TestLawT;
+ //LawValidater<TestLawT, RandomGentor> test_law;
+ //test_law.setTrialsCount(1000);
+ //test_law.run();
 
         //typedef InplaceDistributivity
         // <split_interval_map<int, itl::set<int>, neutron_absorber >,


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk