# The logic of segmentation

In this model, we distinguish five logical functors:

1. Conjunction
2. Alternative
3. Negation
4. Implication
5. Equivalence

The scope of this article focuses mainly on the on the relations among the first three items on the list, however, occasionally it brushes against the fourth one too. For that reason, let’s have a look at a so-called truth table, i.e. situations in which each action is true and others in which actions are false. Let’s analyze the following example:

`The writer of this piece is very smart and exceptionally handsome.`

This sentence is of course true, but why? Because we are dealing with conjunction sentences: I am very clever and incredibly handsome, so both sentences are true. However, if we said:

`The writer of this piece is young and exceptionally handsome.`

This sentence would be false, because although I am still incredibly handsome, the other part, about being young, is not so true. However, if we reformulate this sentence like this:

`The writer of this piece is young or incredibly handsome.`

The whole sentence remains true. And this is what the calculation of alternatives and conjunctions looks like. A conjunction is only true if both components are true, while the alternative is false only if both components are false.

The table looks like this:

We need this table mainly because of inferences based on negation. The alternative and conjunction combined with negation are transformed symmetrically, which we will need while working on collections.

Since an alternative is false only in one case, when both elements are false, the negation of the alternative will imply a conjunction of negation:

`(p⋁q) ⟶ ∼p∧∼q`

So, if the sentence `The writer is young or unbelievably handsome` is false, that is, the writer is neither young nor handsome. And the opposite is also true: since the conjunction is only true in one case, the negation of the conjunction will give us an alternative to negation:

`∼(p∧q) ⟶ ∼p⋁∼q`

In this case: if the sentence `Olgierd is young and incredibly handsome` is false, then either Olgierd is not young, he is not handsome, or he is neither young nor handsome.

## Logical functors and effects on sets

Ok, but what does any of this have to do with what Synerise does or anything else? Each logical (affirmative) sentence speaks of belonging to a certain set. When we say the phrase ‘Synerise is a cool company’, we also state that:

1. There is a set F that consists of cool companies;
2. There is Synerise, which belongs to the set F.

However, operations on sets are simply a segmentation, like this:

This kind of segmentation can be defined as collections: persons with names including A and persons who made a transaction. What do the operations on such collections look like?

Conjunction (AND) - the product of sets, the common part. If the segment we are looking for has the parameters “matching tag A” and “matching tag B”, then in the logical record it will look like this:

The alternative (OR) will be the sum of the sets. If the segment has the parameters “matching tag A” OR “matching tag B”, then, in the logical record, it should look like this:

Negation (NOT MATCHING) will be an exclusion from the set, which is simply saved as `x∉A or ~ (x∈A)`

## How to operate within the lack of parenthesis

Fine, but we have a more complicated action to do, which contains not just one conjunction and not just one alternative, but several conjunctions and several alternatives.

Examples of such sentences are:

1. Everyone born after the battle of Lepanto, who agreed to receive the newsletter and bought a soda or a candy bar last month.
2. Everyone who bought a soda and a candy bar and agreed to receive the newsletter or web push notifications.
3. Everyone who bought a soda and a candy bar or sanitary pads and visited the site.

Let’s rewrite the first sentence into the language of Synerise:

1. `birthdate` more than 7.10.1571
2. `newsletterAgreement` is TRUE
3. `productBuy` `\$name` contains SODA
4. `productBuy` `\$name` contains CANDY BAR

How does it look when it comes to combining an alternative/conjunction?

`1 AND 2 AND (3 OR 4)`

But Synerise does not add parentheses in the segmentation, so if we use this order, it will show us this way:

`1 AND 2 AND 3 OR 4`

And counts in this:

`((1 AND 2) AND 3) OR 4`

which means nothing less than this: everyone who was born after the battle of Lepanto, agreed to the newsletter and bought a soda, AND ALSO all who bought a candy bar.

Therefore, those who bought a candy bar in this arrangement could also have been born before 1571 and did not agree to the newsletter, but will be included in the segment.

So to avoid such a nasty situation, place it at the beginning:

`3 OR 4 AND 1 AND 2`

Which allows Synerise do this for the calculation:

`(3 OR 4) AND 1) AND 2`

that is: everyone who bought soda or candy bar and agreed to the newsletter and were born after 1571.

## Actions with negation and exclusion

The situation gets a bit more complicated when it comes to negation.

We can add NOT MATCHING to each MATCHING, we can add FALSE to each TRUE. This is of fundamental importance especially for the operations of exclusion in metrics, funnels and so on.

For example, suppose you want to exclude people tagged with A (belonging to file A) from the transaction metric. The transaction set T gives us the record: `\$totalAmount` for the transaction charge. We mark the exclusion in a filter by simply indicating people who do not belong to the set A.

Logically, the results look like this:

`x∈T ∧ x∉A ⟶ x∈(T\A)`

This is intuitive and simple. If the sum of the transaction is \$1000, and people with the A tag have generated \$200, then after such exclusion, the record will give us \$800.

Let’s assume, however, that we want to exclude people with two tags at once: tag A and tag B. So we have to negate two conditions. To correctly calculate the result, will we use a conjunction or alternative?

Here’s what the filter of conjunction excludes:

The calculation looks like this:

`x∈T ∧ (x∉A ∧ x∉B) ∧ A,B⊂T ⟶ x∈(T\(A∪B))`

The conjunction will therefore exclude people who were marked with both tags (they belong to the set A and to the set B), but the sum of the sets A and B, people marked with at least one of the tags. We are using an alternative.

This is the exclusion filter:

And the calculation:

`x∈T ∧ (x∉A ⋁ x∉B) ∧ A,B⊂T ⟶ x∈(T\A) ⋁ x∈(T\B)`

`x∈(T\A) ⋁ x∈(T\B) ⟶ x∈(T\A⋂B)`

The alternative of negation excludes the common part of collections A and B, people marked with both tags.

Translating it into arithmetic: if the sum of T is \$1000, people with the tag A generate \$200, people with the tag B - \$300, and those with both tags - \$100, are:

• the alternative of negation in the metric filter will give us \$900;
• the conjunction of negation in the metric filter will give us the result of \$600;

The negation in the filter can be done at the very top, and not in individual elements. In the case of exclusion, we will not deal with the conjunction of negation or the alternative of negation, respectively, but with the negation of conjunction or the negation of the alternative. Let’s take the first case: negation of conjunction.

The filter will look like this:

The logical calculation follows:

`∼(x∈A ∧ x∈B)`

In the classical propositional calculus, in order for a conjunction to result in 0, only one of the elements must give 0. Negative conjunction is thus transformed into an alternative of negation:

`∼(x∈A ∧ x∈B) ⟶ (x∉A ⋁ x∉B)`

So as in the example above, negating the conjunction A and B will give us the result `x∈ (T \A⋂B)`. The result is \$900.

As you probably guessed, if we use a negation at the top and an alternative at the bottom, it will be exactly the opposite.

Because an alternative gives 0 in only one case - when both members are 0 - negation of the alternative gives a conjunction of negation.

`∼(x∈A ⋁ x∈B) ⟶ (x∉A ∧ x∉B)`

This means that such a negation in the exclusion will give us the sum of collections A and B, i.e. `x∈ (T \(A∪B)`. The post-exclusion document will show \$600.

Let’s convert a more complex example. We exclude from the metrics people who have the A and B tag but do not have the C tag. What functor should we use? This is more difficult situation, because conjunction and alternative are two-argument functions, that is, the conjunction sentences and alternatives have two parts, and this case has three:

`x∉A`
`x∉B`
`x∈C`

When combining their conjunctions, remember to group them. This signifies the order (from left to right) and this order does not do anything with prioritizing the priority of functors.

If we exclude people who do not have the A and B tag, then - remembering how it looks in the calculation - we combine them with an alternative:

`x∉A ⋁ x∉B`

Which gives us the result:

`x∈T ∧ (x∉A ⋁ x∉B) ⟶ x∈ (T\A⋂B)`

The alternative `x∉A ⋁ x∉B` must therefore be at the beginning. The result is to exclude people who have both tags. Also, this result must be focused on the C-tag, namely from the excluded people to identify the people who have the tag, and their turnover to be included in the metric.

We exclude from the part of the common sets A and B the persons who belong to the set C.

`x∈T ∧ x∈C ∧ x∉(A⋂B) ⟶ x∈(T\((A⋂B)\C))`

The final mathematical result depends on the relation between C and A and B (that is, whether C is a subset of A or B, if it has only a common part, is it separate, etc.) - so we will not substitute numbers here.

And how will the original negation work in this case? Again, we have `x∉A ⋁ x∉B ∧ x∈C`. As we know, Synerise will make brackets in such a way that the alternative and then the conjunction will be converted first.

`(x∉A ⋁ x∉B) ∧ x∈C`

If we now add the NOT MATCHING segment at the top,, i.e. negate the entire action, then the calculation will look like this:

`~((x∉A ⋁ x∉B) ∧ x∈C) ⟶ ~(x∉A ⋁ x∉B) ⋁ ~(x∈C) ⟶ (x∈A ∧ x∈B) ⋁ x∉C`

If we apply this segment as a metric filter and convert transactions of all who do not meet the condition `(x∉A ⋁ x∉B) ∧ x∈C)`, this metric will count people who have A and B tags, as well as those who they do not have the C tag.

😕

### We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

### Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.