semantics.qbk 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. [/
  2. Copyright (c) 2008-2009 Joachim Faulhaber
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. ]
  7. [section Semantics]
  8. ["Beauty is the ultimate defense against complexity] -- [/David Gelernter]
  9. [@http://en.wikipedia.org/wiki/David_Gelernter David Gelernter]
  10. In the *icl* we follow the notion, that the semantics of a ['*concept*] or
  11. ['*abstract data type*] can be expressed by ['*laws*]. We formulate
  12. laws over interval containers that can be evaluated for a given
  13. instantiation of the variables contained in the law. The following
  14. pseudocode gives a shorthand notation of such a law.
  15. ``
  16. Commutativity<T,+>:
  17. T a, b; a + b == b + a;
  18. ``
  19. This can of course be coded as a proper c++ class template which has
  20. been done for the validation of the *icl*. For sake of simplicity
  21. we will use pseudocode here.
  22. The laws that describe the semantics of the *icl's* class templates
  23. were validated using the Law based Test Automaton ['*LaBatea*],
  24. a tool that generates instances for the law's variables and then
  25. tests it's validity.
  26. Since the *icl* deals with sets, maps and relations, that are
  27. well known objects from mathematics, the laws that we are
  28. using are mostly /recycled/ ones. Also some of those laws are grouped
  29. in notions like e.g. /orderings/ or /algebras/.
  30. [section Orderings and Equivalences]
  31. [h4 Lexicographical Ordering and Equality]
  32. On all set and map containers of the icl, there is an `operator <`
  33. that implements a
  34. [@http://www.sgi.com/tech/stl/StrictWeakOrdering.html strict weak ordering].
  35. [/ (see also [@http://en.wikipedia.org/wiki/Strict_weak_ordering here]).]
  36. The semantics of `operator <` is the same as for an stl's
  37. [@http://www.sgi.com/tech/stl/SortedAssociativeContainer.html SortedAssociativeContainer],
  38. specifically
  39. [@http://www.sgi.com/tech/stl/set.html stl::set]
  40. and
  41. [@http://www.sgi.com/tech/stl/map.html stl::map]:
  42. ``
  43. Irreflexivity<T,< > : T a; !(a<a)
  44. Asymmetry<T,< > : T a,b; a<b implies !(b<a)
  45. Transitivity<T,< > : T a,b,c; a<b && b<c implies a<c
  46. ``
  47. `Operator <` depends on the icl::container's template parameter
  48. `Compare` that implements a ['strict weak ordering] for the container's
  49. `domain_type`.
  50. For a given `Compare` ordering, `operator <` implements a
  51. lexicographical comparison on icl::containers, that uses the
  52. `Compare` order to establish a unique sequence of values in
  53. the container.
  54. The induced equivalence of `operator <` is
  55. lexicographical equality
  56. which is implemented as `operator ==`.
  57. ``
  58. //equivalence induced by strict weak ordering <
  59. !(a<b) && !(b<a) implies a == b;
  60. ``
  61. Again this
  62. follows the semantics of the *stl*.
  63. Lexicographical equality is stronger than the equality
  64. of elements. Two containers that contain the same elements
  65. can be lexicographically unequal, if their elements are
  66. differently sorted. Lexicographical comparison belongs to
  67. the __bi_iterative__ aspect. Of all the different sequences that are valid
  68. for unordered sets and maps, one such sequence is
  69. selected by the `Compare` order of elements. Based on
  70. this selection a unique iteration is possible.
  71. [h4 Subset Ordering and Element Equality]
  72. On the __conceptual__ aspect only membership of elements
  73. matters, not their sequence. So there are functions
  74. `contained_in` and `element_equal` that implement
  75. the subset relation and the equality on elements.
  76. Yet, `contained_in` and `is_element_equal` functions are not
  77. really working on the level of elements. They also
  78. work on the basis of the containers templates
  79. `Compare` parameter. In practical terms we need to
  80. distinguish between lexicographical equality
  81. `operator ==` and equality of elements `is_element_equal`,
  82. if we work with interval splitting interval containers:
  83. ``
  84. split_interval_set<time> w1, w2; //Pseudocode
  85. w1 = {[Mon .. Sun)}; //split_interval_set containing a week
  86. w2 = {[Mon .. Fri)[Sat .. Sun)}; //Same week split in work and week end parts.
  87. w1 == w2; //false: Different segmentation
  88. is_element_equal(w1,w2); //true: Same elements contained
  89. ``
  90. For a constant `Compare` order on key elements,
  91. member function `contained_in` that is defined for all
  92. icl::containers implements a
  93. [@http://en.wikipedia.org/wiki/Partially_ordered_set partial order]
  94. on icl::containers.
  95. ``
  96. with <= for contained_in,
  97. =e= for is_element_equal:
  98. Reflexivity<T,<= > : T a; a <= a
  99. Antisymmetry<T,<=,=e=> : T a,b; a <= b && b <= a implies a =e= b
  100. Transitivity<T,<= > : T a,b,c; a <= b && b <= c implies a <= c
  101. ``
  102. The induced equivalence is the equality of elements that
  103. is implemented via function `is_element_equal`.
  104. ``
  105. //equivalence induced by the partial ordering contained_in on icl::container a,b
  106. a.contained_in(b) && b.contained_in(a) implies is_element_equal(a, b);
  107. ``
  108. [endsect][/ Orderings and Equivalences]
  109. [section Sets]
  110. For all set types `S` that are models concept `Set`
  111. (__icl_set__, __itv_set__, __sep_itv_set__ and __spl_itv_set__)
  112. most of the well known mathematical
  113. [@http://en.wikipedia.org/wiki/Algebra_of_sets laws on sets]
  114. were successfully checked via LaBatea. The next tables
  115. are giving an overview over the checked laws ordered by
  116. operations. If possible, the laws are formulated with
  117. the stronger lexicographical equality (`operator ==`)
  118. which implies the law's validity for the weaker
  119. element equality `is_element_equal`. Throughout this
  120. chapter we will denote element equality as `=e=` instead
  121. of `is_element_equal` where a short notation is advantageous.
  122. [h5 Laws on set union]
  123. For the operation ['*set union*] available as
  124. `operator +, +=, |, |=` and the neutral element
  125. `identity_element<S>::value()` which is the empty set `S()`
  126. these laws hold:
  127. ``
  128. Associativity<S,+,== >: S a,b,c; a+(b+c) == (a+b)+c
  129. Neutrality<S,+,== > : S a; a+S() == a
  130. Commutativity<S,+,== >: S a,b; a+b == b+a
  131. ``
  132. [h5 Laws on set intersection]
  133. For the operation ['*set intersection*] available as
  134. `operator &, &=` these laws were validated:
  135. ``
  136. Associativity<S,&,== >: S a,b,c; a&(b&c) == (a&b)&c
  137. Commutativity<S,&,== >: S a,b; a&b == b&a
  138. ``
  139. [/ FYI
  140. Neutrality has *not* been validated to avoid
  141. additional requirements on the sets template
  142. parameters.]
  143. [h5 Laws on set difference]
  144. For set difference there are only these laws. It is
  145. not associative and not commutative. It's neutrality
  146. is non symmetrical.
  147. ``
  148. RightNeutrality<S,-,== > : S a; a-S() == a
  149. Inversion<S,-,== >: S a; a - a == S()
  150. ``
  151. Summarized in the next table are laws that use `+`, `&` and `-`
  152. as a single operation. For all validated laws,
  153. the left and right hand sides of the equations
  154. are lexicographically equal, as denoted by `==` in the cells
  155. of the table.
  156. ``
  157. + & -
  158. Associativity == ==
  159. Neutrality == ==
  160. Commutativity == ==
  161. Inversion ==
  162. ``
  163. [h5 Distributivity Laws]
  164. Laws, like distributivity, that use more than one operation can
  165. sometimes be instantiated for different sequences of operators
  166. as can be seen below. In the two instantiations of the distributivity
  167. laws operators `+` and `&` are swapped. So we can have small operator
  168. signatures like `+,&` and `&,+` to describe such instantiations,
  169. which will be used below.
  170. Not all instances of distributivity laws hold for lexicographical equality.
  171. Therefore they are denoted using a /variable/ equality `=v=` below.
  172. ``
  173. Distributivity<S,+,&,=v= > : S a,b,c; a + (b & c) =v= (a + b) & (a + c)
  174. Distributivity<S,&,+,=v= > : S a,b,c; a & (b + c) =v= (a & b) + (a & c)
  175. RightDistributivity<S,+,-,=v= > : S a,b,c; (a + b) - c =v= (a - c) + (b - c)
  176. RightDistributivity<S,&,-,=v= > : S a,b,c; (a & b) - c =v= (a - c) & (b - c)
  177. ``
  178. The next table shows the relationship between
  179. law instances,
  180. [link boost_icl.introduction.interval_combining_styles interval combining style]
  181. and the
  182. used equality relation.
  183. ``
  184. +,& &,+
  185. Distributivity joining == ==
  186. separating == ==
  187. splitting =e= =e=
  188. +,- &,-
  189. RightDistributivity joining == ==
  190. separating == ==
  191. splitting =e= ==
  192. ``
  193. The table gives an overview over 12 instantiations of
  194. the four distributivity laws and shows the equalities
  195. which the instantiations holds for. For instance
  196. `RightDistributivity` with operator signature `+,-`
  197. instantiated for __spl_itv_sets__ holds only for
  198. element equality (denoted as `=e=`):
  199. ``
  200. RightDistributivity<S,+,-,=e= > : S a,b,c; (a + b) - c =e= (a - c) + (b - c)
  201. ``
  202. The remaining five instantiations of `RightDistributivity`
  203. are valid for lexicographical equality (demoted as `==`) as well.
  204. [link boost_icl.introduction.interval_combining_styles Interval combining styles]
  205. correspond to containers according to
  206. ``
  207. style set
  208. joining interval_set
  209. separating separate_interval_set
  210. splitting split_interval_set
  211. ``
  212. Finally there are two laws that combine all three major set operations:
  213. De Mogans Law and Symmetric Difference.
  214. [h5 DeMorgan's Law]
  215. De Morgans Law is better known in an incarnation where the unary
  216. complement operation `~` is used. `~(a+b) == ~a * ~b`. The version
  217. below is an adaption for the binary set difference `-`, which is
  218. also called ['*relative complement*].
  219. ``
  220. DeMorgan<S,+,&,=v= > : S a,b,c; a - (b + c) =v= (a - b) & (a - c)
  221. DeMorgan<S,&,+,=v= > : S a,b,c; a - (b & c) =v= (a - b) + (a - c)
  222. ``
  223. ``
  224. +,& &,+
  225. DeMorgan joining == ==
  226. separating == =e=
  227. splitting == =e=
  228. ``
  229. Again not all law instances are valid for lexicographical equality.
  230. The second instantiations only holds for element equality, if
  231. the interval sets are non joining.
  232. [h5 Symmetric Difference]
  233. ``
  234. SymmetricDifference<S,== > : S a,b,c; (a + b) - (a & b) == (a - b) + (b - a)
  235. ``
  236. Finally Symmetric Difference holds for all of icl set types and
  237. lexicographical equality.
  238. [/ pushout laws]
  239. [endsect][/ Sets]
  240. [section Maps]
  241. By definition a map is set of pairs. So we would expect maps to
  242. obey the same laws that are valid for sets. Yet
  243. the semantics of the *icl's* maps may be a different one, because
  244. of it's aggregating facilities, where the aggregating combiner
  245. operations are passed to combine the map's associated values.
  246. It turns out, that the aggregation on overlap principle
  247. induces semantic properties to icl maps in such a way,
  248. that the set of equations that are valid will depend on
  249. the semantics of the type `CodomainT` of the map's associated
  250. values.
  251. This is less magical as it might seem at first glance.
  252. If, for instance, we instantiate an __itv_map__ to
  253. collect and concatenate
  254. `std::strings` associated to intervals,
  255. ``
  256. interval_map<int,std::string> cat_map;
  257. cat_map += make_pair(interval<int>::rightopen(1,5),std::string("Hello"));
  258. cat_map += make_pair(interval<int>::rightopen(3,7),std::string(" World"));
  259. cout << "cat_map: " << cat_map << endl;
  260. ``
  261. we won't be able to apply `operator -=`
  262. ``
  263. // This will not compile because string::operator -= is missing.
  264. cat_map -= make_pair(interval<int>::rightopen(3,7),std::string(" World"));
  265. ``
  266. because, as std::sting does not implement `-=` itself, this won't compile.
  267. So all *laws*, that rely on `operator -=` or `-` not only will not be valid they
  268. can not even be stated.
  269. This reduces the set of laws that can be valid for a richer `CodomainT`
  270. type to a smaller set of laws and thus to a less restricted semantics.
  271. Currently we have investigated and validated two major instantiations
  272. of icl::Maps,
  273. * ['*Maps of Sets*] that will be called ['*Collectors*] and
  274. * ['*Maps of Numbers*] which will be called ['*Quantifiers*]
  275. both of which seem to have many interesting use cases for practical
  276. applications. The semantics associated with the term /Numbers/
  277. is a
  278. [@http://en.wikipedia.org/wiki/Monoid commutative monoid]
  279. for unsigned numbers
  280. and a
  281. [@http://en.wikipedia.org/wiki/Abelian_group commutative or abelian group]
  282. for signed numbers.
  283. From a practical point of view we can think
  284. of numbers as counting or quantifying the key values
  285. of the map.
  286. Icl ['*Maps of Sets*] or ['*Collectors*]
  287. are models of concept `Set`. This implies that all laws that have been
  288. stated as a semantics for `icl::Sets` in the previous chapter also hold for
  289. `Maps of Sets`.
  290. Icl ['*Maps of Numbers*] or ['*Quantifiers*] on the contrary are not models
  291. of concept `Set`.
  292. But there is a substantial intersection of laws that apply both for
  293. `Collectors` and `Quantifiers`.
  294. [table
  295. [[Kind of Map] [Alias] [Behavior] ]
  296. [[Maps of Sets] [Collector] [Collects items *for* key values] ]
  297. [[Maps of Numbers][Quantifier][Counts or quantifies *the* key values]]
  298. ]
  299. In the next two sections the law based semantics of ['*Collectors*]
  300. and ['*Quantifiers*] will be described in more detail.
  301. [endsect][/ Maps]
  302. [section Collectors: Maps of Sets]
  303. Icl `Collectors`, behave like `Sets`.
  304. This can be understood easily, if we consider, that
  305. every map of sets can be transformed to an equivalent
  306. set of pairs.
  307. For instance in the pseudocode below map `m`
  308. ``
  309. icl::map<int,set<int> > m = {(1->{1,2}), (2->{1})};
  310. ``
  311. is equivalent to set `s`
  312. ``
  313. icl::set<pair<int,int> > s = {(1,1),(1,2), //representing 1->{1,2}
  314. (2,1) }; //representing 2->{1}
  315. ``
  316. Also the results of add, subtract and other operations on `map m` and `set s`
  317. preserves the equivalence of the containers ['*almost*] perfectly:
  318. ``
  319. m += (1,3);
  320. m == {(1->{1,2,3}), (2->{1})}; //aggregated on collision of key value 1
  321. s += (1,3);
  322. s == {(1,1),(1,2),(1,3), //representing 1->{1,2,3}
  323. (2,1) }; //representing 2->{1}
  324. ``
  325. The equivalence of `m` and `s` is only violated if an
  326. empty set occurres in `m` by subtraction of a value pair:
  327. ``
  328. m -= (2,1);
  329. m == {(1->{1,2,3}), (2->{})}; //aggregated on collision of key value 2
  330. s -= (2,1);
  331. s == {(1,1),(1,2),(1,3) //representing 1->{1,2,3}
  332. }; //2->{} is not represented in s
  333. ``
  334. This problem can be dealt with in two ways.
  335. # Deleting value pairs form the Collector, if it's associated value
  336. becomes a neutral value or `identity_element`.
  337. # Using a different equality, called distinct equality in the laws
  338. to validate. Distinct equality only
  339. accounts for value pairs that that carry values unequal to the `identity_element`.
  340. Solution (1) led to the introduction of map traits, particularly trait
  341. ['*partial_absorber*], which is the default setting in all icl's map
  342. templates.
  343. Solution (2), is applied to check the semantics of icl::Maps for the
  344. partial_enricher trait that does not delete value pairs that carry
  345. identity elements. Distinct equality is implemented by a non member function
  346. called `is_distinct_equal`. Throughout this chapter
  347. distinct equality in pseudocode and law denotations is denoted
  348. as `=d=` operator.
  349. The validity of the sets of laws that make up `Set` semantics
  350. should now be quite evident. So the following text shows the
  351. laws that are validated for all `Collector` types `C`. Which are
  352. __icl_map__`<D,S,T>`, __itv_map__`<D,S,T>` and __spl_itv_map__`<D,S,T>`
  353. where `CodomainT` type `S` is a model of `Set` and `Trait` type `T` is either
  354. __pabsorber__ or __penricher__.
  355. [h5 Laws on set union, set intersection and set difference]
  356. ``
  357. Associativity<C,+,== >: C a,b,c; a+(b+c) == (a+b)+c
  358. Neutrality<C,+,== > : C a; a+C() == a
  359. Commutativity<C,+,== >: C a,b; a+b == b+a
  360. Associativity<C,&,== >: C a,b,c; a&(b&c) ==(a&b)&c
  361. Commutativity<C,&,== >: C a,b; a&b == b&a
  362. RightNeutrality<C,-,== >: C a; a-C() == a
  363. Inversion<C,-,=v= > : C a; a - a =v= C()
  364. ``
  365. All the fundamental laws could be validated for all
  366. icl Maps in their instantiation as Maps of Sets or Collectors.
  367. As expected, Inversion only holds for distinct equality,
  368. if the map is not a `partial_absorber`.
  369. ``
  370. + & -
  371. Associativity == ==
  372. Neutrality == ==
  373. Commutativity == ==
  374. Inversion partial_absorber ==
  375. partial_enricher =d=
  376. ``
  377. [h5 Distributivity Laws]
  378. ``
  379. Distributivity<C,+,&,=v= > : C a,b,c; a + (b & c) =v= (a + b) & (a + c)
  380. Distributivity<C,&,+,=v= > : C a,b,c; a & (b + c) =v= (a & b) + (a & c)
  381. RightDistributivity<C,+,-,=v= > : C a,b,c; (a + b) - c =v= (a - c) + (b - c)
  382. RightDistributivity<C,&,-,=v= > : C a,b,c; (a & b) - c =v= (a - c) & (b - c)
  383. ``
  384. Results for the distributivity laws are almost identical to
  385. the validation of sets except that
  386. for a `partial_enricher map` the law `(a & b) - c == (a - c) & (b - c)`
  387. holds for lexicographical equality.
  388. ``
  389. +,& &,+
  390. Distributivity joining == ==
  391. splitting partial_absorber =e= =e=
  392. partial_enricher =e= ==
  393. +,- &,-
  394. RightDistributivity joining == ==
  395. splitting =e= ==
  396. ``
  397. [h5 DeMorgan's Law and Symmetric Difference]
  398. ``
  399. DeMorgan<C,+,&,=v= > : C a,b,c; a - (b + c) =v= (a - b) & (a - c)
  400. DeMorgan<C,&,+,=v= > : C a,b,c; a - (b & c) =v= (a - b) + (a - c)
  401. ``
  402. ``
  403. +,& &,+
  404. DeMorgan joining == ==
  405. splitting == =e=
  406. ``
  407. ``
  408. SymmetricDifference<C,== > : C a,b,c; (a + b) - (a * b) == (a - b) + (b - a)
  409. ``
  410. Reviewing the validity tables above shows, that the sets of valid laws for
  411. `icl Sets` and `icl Maps of Sets` that are /identity absorbing/ are exactly the same.
  412. As expected, only for Maps of Sets that represent empty sets as associated values,
  413. called /identity enrichers/, there are marginal semantic differences.
  414. [endsect][/ Collectors]
  415. [section Quantifiers: Maps of Numbers]
  416. [h5 Subtraction on Quantifiers]
  417. With `Sets` and `Collectors` the semantics of
  418. `operator -` is
  419. that of /set difference/ which means, that you can
  420. only subtract what has been put into the container before.
  421. With `Quantifiers` that ['*count*] or ['*quantify*]
  422. their key values in some way,
  423. the semantics of `operator -` may be different.
  424. The question is how subtraction should be defined here?
  425. ``
  426. //Pseudocode:
  427. icl::map<int,some_number> q = {(1->1)};
  428. q -= (2->1);
  429. ``
  430. If type `some_number` is `unsigned` a /set difference/ kind of
  431. subtraction make sense
  432. ``
  433. icl::map<int,some_number> q = {(1->1)};
  434. q -= (2->1); // key 2 is not in the map so
  435. q == {(1->1)}; // q is unchanged by 'aggregate on collision'
  436. ``
  437. If `some_number` is a `signed` numerical type
  438. the result can also be this
  439. ``
  440. icl::map<int,some_number> q = {(1->1)};
  441. q -= (2->1); // subtracting works like
  442. q == {(1->1), (2-> -1)}; // adding the inverse element
  443. ``
  444. As commented in the example, subtraction of a key value
  445. pair `(k,v)` can obviously be defined as adding the ['*inverse element*]
  446. for that key `(k,-v)`, if the key is not yet stored in the map.
  447. [h4 Partial and Total Quantifiers and Infinite Vectors]
  448. Another concept, that we can think of, is that in a `Quantifier`
  449. every `key_value` is initially quantified `0`-times, where `0` stands
  450. for the neutral element of the numeric `CodomainT` type.
  451. Such a `Quantifier` would be totally defined on all values of
  452. it's `DomainT` type and can be
  453. conceived as an `InfiniteVector`.
  454. To create an infinite vector
  455. that is totally defined on it's domain we can set
  456. the map's `Trait` parameter to the value __tabsorber__.
  457. The __tabsorber__ trait fits specifically well with
  458. a `Quantifier` if it's `CodomainT` has an inverse
  459. element, like all signed numerical type have.
  460. As we can see later in this section this kind of
  461. a total `Quantifier` has the basic properties that
  462. elements of a
  463. [@http://en.wikipedia.org/wiki/Vector_space vector space]
  464. do provide.
  465. [h5 Intersection on Quantifiers]
  466. Another difference between `Collectors` and `Quantifiers`
  467. is the semantics of `operator &`, that has the meaning of
  468. set intersection for `Collectors`.
  469. For the /aggregate on overlap principle/ the operation `&`
  470. has to be passed to combine associated values on overlap
  471. of intervals or collision of keys. This can not be done
  472. for `Quantifiers`, since numeric types do not implement
  473. intersection.
  474. For `CodomainT` types that are not models of `Sets`
  475. `operator & ` is defined as ['aggregation on the intersection
  476. of the domains]. Instead of the `codomain_intersect` functor
  477. `codomain_combine` is used as aggregation operation:
  478. ``
  479. //Pseudocode example for partial Quantifiers p, q:
  480. interval_map<int,int> p, q;
  481. p = {[1 3)->1 };
  482. q = { ([2 4)->1};
  483. p & q =={ [2 3)->2 };
  484. ``
  485. So an addition or aggregation of associated values is
  486. done like for `operator +` but value pairs that have
  487. no common keys are not added to the result.
  488. For a `Quantifier` that is a model of an `InfiniteVector`
  489. and which is therefore defined for every key value of
  490. the `DomainT` type, this definition of `operator &`
  491. degenerates to the same sematics that `operaotor +`
  492. implements:
  493. ``
  494. //Pseudocode example for total Quantifiers p, q:
  495. interval_map<int,int> p, q;
  496. p = {[min 1)[1 3)[3 max]};
  497. ->0 ->1 ->0
  498. q = {[min 2)[2 4)[4 max]};
  499. ->0 ->1 ->0
  500. p&q =={[min 1)[1 2)[2 3)[3 4)[4 max]};
  501. ->0 ->1 ->2 ->1 ->0
  502. ``
  503. [h4 Laws for Quantifiers of unsigned Numbers]
  504. The semantics of icl Maps of Numbers is different
  505. for unsigned or signed numbers. So the sets of
  506. laws that are valid for Quantifiers will be different
  507. depending on the instantiation of an unsigned or
  508. a signed number type as `CodomainT` parameter.
  509. Again, we are presenting the investigated sets of laws, this time for
  510. `Quantifier` types `Q` which are
  511. __icl_map__`<D,N,T>`, __itv_map__`<D,N,T>` and __spl_itv_map__`<D,N,T>`
  512. where `CodomainT` type `N` is a `Number` and `Trait` type `T` is one of
  513. the icl's map traits.
  514. ``
  515. Associativity<Q,+,== >: Q a,b,c; a+(b+c) == (a+b)+c
  516. Neutrality<Q,+,== > : Q a; a+Q() == a
  517. Commutativity<Q,+,== >: Q a,b; a+b == b+a
  518. Associativity<Q,&,== >: Q a,b,c; a&(b&c) ==(a&b)&c
  519. Commutativity<Q,&,== >: Q a,b; a&b == b&a
  520. RightNeutrality<Q,-,== >: Q a; a-Q() == a
  521. Inversion<Q,-,=v= > : Q a; a - a =v= Q()
  522. ``
  523. For an `unsigned Quantifier`, an icl Map of `unsigned numbers`,
  524. the same basic laws apply that are
  525. valid for `Collectors`:
  526. ``
  527. + & -
  528. Associativity == ==
  529. Neutrality == ==
  530. Commutativity == ==
  531. Inversion absorbs_identities ==
  532. enriches_identities =d=
  533. ``
  534. The subset of laws, that relates to `operator +` and the neutral
  535. element `Q()` is that of a commutative monoid. This is the same
  536. concept, that applies for the `CodomainT` type. This gives
  537. rise to the assumption that an icl `Map` over a `CommutativeModoid`
  538. is again a `CommutativeModoid`.
  539. Other laws that were valid for `Collectors` are not valid
  540. for an `unsigned Quantifier`.
  541. [h4 Laws for Quantifiers of signed Numbers]
  542. For `Quantifiers` of signed numbers, or
  543. `signed Quantifiers`, the pattern of valid
  544. laws is somewhat different:
  545. ``
  546. + & -
  547. Associativity =v= =v=
  548. Neutrality == ==
  549. Commutativity == ==
  550. Inversion absorbs_identities ==
  551. enriches_identities =d=
  552. ``
  553. The differences are tagged as `=v=` indicating, that
  554. the associativity law is not uniquely valid for a single
  555. equality relation `==` as this was the case for
  556. `Collector` and `unsigned Quntifier` maps.
  557. The differences are these:
  558. ``
  559. +
  560. Associativity icl::map ==
  561. interval_map ==
  562. split_interval_map =e=
  563. ``
  564. For `operator +` the associativity on __spl_itv_maps__ is only valid
  565. with element equality `=e=`, which is not a big constrained, because
  566. only element equality is required.
  567. For `operator &` the associativity is broken for all maps
  568. that are partial absorbers. For total absorbers associativity
  569. is valid for element equality. All maps having the /identity enricher/
  570. Trait are associative wrt. lexicographical equality `==`.
  571. ``
  572. Associativity &
  573. absorbs_identities && !is_total false
  574. absorbs_identities && is_total =e=
  575. enriches_identities ==
  576. ``
  577. Note, that all laws that establish a commutative
  578. monoid for `operator +` and identity element `Q()` are valid
  579. for `signed Quantifiers`.
  580. In addition symmetric difference that does not
  581. hold for `unsigned Qunatifiers` is valid
  582. for `signed Qunatifiers`.
  583. ``
  584. SymmetricDifference<Q,== > : Q a,b,c; (a + b) - (a & b) == (a - b) + (b - a)
  585. ``
  586. For a `signed TotalQuantifier` `Qt` symmetrical difference degenerates to
  587. a trivial form since `operator &` and `operator +` become identical
  588. ``
  589. SymmetricDifference<Qt,== > : Qt a,b,c; (a + b) - (a + b) == (a - b) + (b - a) == Qt()
  590. ``
  591. [h5 Existence of an Inverse]
  592. By now `signed Quantifiers` `Q` are
  593. commutative monoids
  594. with respect to the
  595. `operator +` and the neutral element `Q()`.
  596. If the Quantifier's `CodomainT` type has an /inverse element/
  597. like e.g. `signed numbers` do,
  598. the `CodomainT` type is a
  599. ['*commutative*] or ['*abelian group*].
  600. In this case a `signed Quantifier` that is also ['*total*]
  601. has an ['*inverse*] and the following law holds:
  602. ``
  603. InverseElement<Qt,== > : Qt a; (0 - a) + a == 0
  604. ``
  605. Which means that each `TotalQuantifier` over an
  606. abelian group is an
  607. abelian group
  608. itself.
  609. This also implies that a `Quantifier` of `Quantifiers`
  610. is again a `Quantifiers` and a
  611. `TotalQuantifier` of `TotalQuantifiers`
  612. is also a `TotalQuantifier`.
  613. `TotalQuantifiers` resemble the notion of a
  614. vector space partially.
  615. The concept could be completed to a vector space,
  616. if a scalar multiplication was added.
  617. [endsect][/ Quantifiers]
  618. [section Concept Induction]
  619. Obviously we can observe the induction of semantics
  620. from the `CodomainT` parameter into the instantiations
  621. of icl maps.
  622. [table
  623. [[] [is model of] [if] [example]]
  624. [[`Map<D,Monoid>`] [`Modoid`] [] [`interval_map<int,string>`]]
  625. [[`Map<D,Set,Trait>`] [`Set`] [`Trait::absorbs_identities`][`interval_map<int,std::set<int> >`]]
  626. [[`Map<D,CommutativeMonoid>`][`CommutativeMonoid`][] [`interval_map<int,unsigned int>`]]
  627. [[`Map<D,CommutativeGroup>`] [`CommutativeGroup`] [`Trait::is_total`] [`interval_map<int,int,total_absorber>`]]
  628. ]
  629. [endsect][/ Concept Induction]
  630. [endsect][/ Semantics]