pigeonhole | Pigeonhole project : Sieve support for Dovecot
kandi X-RAY | pigeonhole Summary
kandi X-RAY | pigeonhole Summary
This package is part of the Pigeonhole project (It adds support for the Sieve language (RFC 5228) and the ManageSieve protocol (RFC 5804) to the Dovecot Secure IMAP Server. In the literal sense, a pigeonhole is a a hole or recess inside a dovecot for pigeons to nest in. It is, however, also the name for one of a series of small, open compartments in a cabinet used for filing or sorting mail. As a verb, it describes the act of putting an item into one of those pigeonholes. The name `Pigeonhole' therefore well describes an important part of the functionality that this project adds to Dovecot: sorting and filing e-mail messages. The Sieve language is used to specify how e-mail needs to be processed. By writing Sieve scripts, users can customize how messages are delivered, e.g. whether they are forwarded or stored in special folders. Unwanted messages can be discarded or rejected, and, when the user is not available, the Sieve interpreter can send an automated reply. Above all, the Sieve language is meant to be simple, extensible and system independent. And, unlike most other mail filtering script languages, it does not allow users to execute arbitrary programs. This is particularly useful to prevent virtual users from having full access to the mail store. The intention of the language is to make it impossible for users to do anything more complex (and dangerous) than write simple mail filters. Using the ManageSieve protocol, users can upload their Sieve scripts remotely, without needing direct filesystem access through FTP or SCP. Additionally, a ManageSieve server always makes sure that uploaded scripts are valid, preventing compile failures at mail delivery. This package provides Sieve support as a plugin to Dovecot’s Local Delivery Agent (LDA) and Dovecot’s LMTP service. The ManageSieve protocol is provided is an additional service, next to Dovecot’s own POP3 and IMAP services.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pigeonhole
pigeonhole Key Features
pigeonhole Examples and Code Snippets
void sort(Integer[] array){
int maxElement = array[0];
for (int element: array) {
if (element > maxElement) maxElement = element;
}
int numOfPigeonholes = 1 + maxElement;
ArrayList[] pigeonHole
Community Discussions
Trending Discussions on pigeonhole
QUESTION
Hash Functions are incredibly useful and versatile. In general, they are used to map a space to one much smaller space. Of course that means that two objects may hash to the same value (collision), but this is because you are reducing the space (pigeonhole principle). The efficiency of the function largely depends on the size of the hash space.
It comes as a surprise then that a lot of Java hashCode functions are using multiplication to produce the hash code of a new object as e.g. follows (creating-a-hashcode-method-java)
...ANSWER
Answered 2021-Jun-04 at 11:47The answer to this is a mixture of different factors:
- On modern architecture, the time taken to perform a multiplication versus a shift may not end up being measurable overall within a given pipeline of instructions-- it has more to do with the availability of the relevant execution unit on the CPU than the "raw" time taken;
- In practice when integrating with standard collections libraries in day-to-day programming, it's often more important that a hash function is correct, "good enough" and easy to automate in an IDE than for it to be as perfect as possible;
- The collections libraries generally add secondary hash functions and potentially other techniques behind the scenes to overcome some of the weaknesses of what would otherwise be a poor hash function;
- With resizable collections, an effective hash function has the goal of dispersing its hashes across the available range for arbitrary sizes of hash tables (though as I say, it will get help from the built-in secondary function): multiplying by a "magic" constant is often a cheap way to achieve this (or, even if multiplication turned out to be a bit more expensive than a shift: still cheap enough, given the benefit); addition rather than XOR may help to allow this 'avalanche' effect slightly. (In most practical cases, you will probably find that they work equally well.)
- You can generally assume that the JIT compiler "knows" about equivalents such as shifting 5 places and subtracting 1 rather than multiplying by 31. Just because you write "*31" in the source code doesn't mean that it will literally be compiled to a multiplication instruction. (In practice, it might be, though, because despite what you think, the multiply instruction may well be "faster" on average on the architecture in question... It's usually better to make your code stick to the required logic and let the JIT compiler handle the low level optimisations in a case such as this.)
QUESTION
I am trying to proof the pigeonhole problem in Coq. Therefore I have the following lemma that I want to proof:
...ANSWER
Answered 2020-Nov-20 at 13:46The answer to the question you linked to contains this off-hand comment:
The case n=1 is impossible
This is good enough for a human mathematician, but not for Coq. You can tell Coq that you only want to prove cases where n >= 2 by adding that to the premises of the lemma:
QUESTION
use_module(library(clpfd)).
CLPFD seems to not be very quick in realizing that in
...ANSWER
Answered 2020-May-19 at 09:17In SWI Prolog 8.1:
I'm not too knowledgeable you seem "label" too early or too eagerly ("foreach of the labelings" smells fishy)
Try
QUESTION
In Software Foundations IndProp.v
one is asked to prove the pigeonhole principle, and one may use excluded middle, but it is mentioned that it is not strictly necessary. I've been trying to prove it without EM, but my brain seems to be wired classically.
Q: How would one prove the theorem without using excluded middle? How should one generally approach proofs for types without decidable equality, where one can't easily reason by cases?
I'd be very happy for a complete proof to look at, but please avoid posting it "in the clear", so as to not spoil the exercise in the Software Foundations course.
The definition uses two inductive predicates, In
and repeats
.
ANSWER
Answered 2017-Mar-03 at 23:17A possible constructive proof goes like this:
We prove pigeonhole_principle_NO_EM
by induction on l1
. Only the non-empty case is possible because of the length constraint. So, assume l1 = x :: l1'
. Now, check whether there is some element of l1'
which is mapped by f : (forall x, In x l1 -> In x l2)
to the same membership proof as x
. If there is such an x'
element, then it follows that x = x'
, therefore l1
repeats. If there is no such element, then we can get l2'
by removing the element that x
is mapped to from l2
, and apply the induction hypothesis to l2'
and the appropriate f' : forall x, In x l1' -> In x l2'
function.
That's it, but I note that actually formalizing this proof is not easy with the definitions given, because we need to prove heterogeneous or dependent equalities, since we have to compare membership proofs for possibly different elements.
As to the question of getting the hang of constructive proofs in general, an important skill or habit is always examining what kind of data we have, not just what kind of logical facts we know. In this case, membership proofs are actually indices pointing into lists, bundled together with proofs that the pointed-to elements equal certain values. If membership proofs didn't tell where exactly elements are located then this proof would not be possible constructively.
QUESTION
I am trying to implement a range mapper for TRNG output files for a C application with ranges of up to 4 bits in size. Due to the pigeonhole bias problem I have settled on using a discard algorithm.
My idea for a parsimonious algorithm would be something like:
-- Read 16 bytes from file and store as an indexed 128 bit unsigned integer bitbucket to be bitmask selected n bits at a time.
-- Predetermine as much as possible the ranges/buckets required for each input and store in an array.
-- For each n bits in the bitbucket select an input from the array that will not discard it if one exists. If 2 bits cannot find an input try 3 bits and if that cannot find an input try with 4 bits. At first when there are many inputs it should be easy not to discard, but as the choice of inputs gets low discards will become more common. I am not entirely sure if it is better to start with fewer bits and work my way up or to do the opposite.
The downside of this bit sipping range mapper seems to be that I need to assume about twice as much random input data as would be required with biased scaling methods. For instance a 9 bucket input from a 4 bit rand output will miss about 43% of the time.
Existing implementations/algorithms: This seems like an example of a more complex and efficient method of parsimonious range mapping but I find his explanation entirely impenetrable. Can anyone explain it to me in English or suggest a book I might read or a university class I might take that would give me a background to understand it?
There is also arc4random which seems to be a runtime optimized unbiased modulo discard implementation. Like almost all unbiased range mapper implementations I have found this seems not to particularly care about how much data it uses. That does not however mean that it is necessarily less data efficient because it has the advantage of fewer misses.
The basic idea of arc4random seems to be that as long as the number of pigeons (max_randvalue_output) is evenly divisible by the number of holes (rangeupperbound) the modulo function itself is an elegant and unbiased range mapper. However modulo only seems to be relevant when you are not bit sipping, i.e. when the output from the random source is more than ceil(log2(buckets)) bits.
There seems to be a tradeoff between the number of 'wasted' random bits and the percentage of discards. The percentage of misses is inversely proportional to the number of excess bits in the input to the range mapper. It seems like there should be a mathematical way to compare the data efficiency of a bit sipping range mapper with a more bit hungry version with fewer misses, but I don't know it.
So my plan is to just write two implementations: a bit sipping parsimonious type of range mapper that may or may not be a little like the mathforum example (which I don't understand) and an invariant byte input modulo range mapper which accepts byte inputs from a TRNG and uses a discard-from-the-top-of-largest-multiple modulo method of debiasing to match (x)n pigeons to n holes which is intended to be like arc4random. When finished I plan to post them on codereview.
I am basically looking for help or advice with any of these issues that might help me to write a more parsimonious but still unbiased range mapper particularly with respect to my parsimonious algorithm. Runtime efficiency is not a priority.
...ANSWER
Answered 2020-Mar-22 at 10:03There is a far simpler approach to generating random numbers in a range from a random bit stream, which is not only optimally efficient, but also exact. It's called the "Fast Dice Roller" method of J. Lumbroso:
"Optimal Discrete Uniform Generation from Coin Flips, and Applications", 2013.
See also this question.
QUESTION
I have PySpark code that pigeonholes conditions in a dataframe thus (this is a simplification to create a Minimal Working Example):
...ANSWER
Answered 2020-Feb-26 at 22:32If you want an "else" condition without true "error" (i.e. exception) handling, then take a look at pyspark.sql.Column.otherwise.
If you want try "error" (i.e. exception) handling, then you will need to wrap that try ... catch
logic as a user-defined function.
QUESTION
Given a set of non-negative distinct integers, and a value m
, determine if there is a subset of the given set with sum divisible by m
.
The solution on geeksforgeeks states that-
- If
n > m
there will always be a subset with sum divisible bym
(which is easy to prove with pigeonhole principle). So we need to handle only cases ofn <= m
.
Can somebody please explain what this case means and what is its relation to pigeonhole principle? Also how is this case different from n <= m
?
ANSWER
Answered 2020-Jan-06 at 19:53You should create a new set of numbers:
(Will notate as code for comfort reasons, sorry. also, will call the set n)
QUESTION
Lemma remove {A} (x : A) xs (p : In x xs) :
exists xs', (forall x', x' <> x -> In x' xs -> In x' xs') /\ (length xs = S (length xs')).
Proof.
induction xs.
- inversion p.
- destruct p.
+ subst x0.
exists xs.
split.
* intros x' neq pin.
destruct pin.
-- contradict neq. symmetry. assumption.
-- assumption.
* reflexivity.
+ destruct (IHxs H) as [xs' pxs']. clear IHxs.
destruct pxs' as [p1 plen]. rename x0 into x'.
exists (x' :: xs').
split.
* intros x'' neq pin.
destruct pin.
-- subst x'. left. reflexivity.
-- right. apply p1. assumption. assumption.
* simpl.
rewrite -> plen.
reflexivity.
Qed.
Theorem pigeonhole_principle: forall (X:Type) (l1 l2:list X),
excluded_middle ->
AllIn l1 l2 ->
length l2 < length l1 ->
repeats l1.
Proof.
induction l1; simpl; intros l2 ex_mid Hin Hlen.
- inversion Hlen.
- apply repeats_rest.
destruct (remove x l2) as [l2' Hl2].
+ apply Hin. left. reflexivity.
+ destruct Hl2 as [Hmap Hlen'].
rewrite Hlen' in Hlen.
clear Hlen'.
apply (IHl1 l2').
1 : { assumption. }
2 : { revert Hlen. unfold lt. intros. omega. }
clear Hlen IHl1.
revert Hin.
unfold AllIn.
intros.
apply Hmap.
2 : { apply Hin. right. assumption. }
...ANSWER
Answered 2019-Nov-02 at 03:22I came across this question when searching for answers while working through SF (Software Foundations), but managed to prove it myself. I'll provide a sketch for the SF version of the pigeonhole principle, using excluded_middle. The statement to prove is that if all elements in list l1
are in l2
and length l2
is less than length l1
, then l1
contains repeated elements.
The proof as SF suggests begins by induction on l1
. I'll omit the straightforward empty case. In the inductive case, destruct l2
. The case where l2
is empty is straightforward; we consider the other case.
Now, because of induction on l1
and destructuring on l2
, your statement to prove is about lists with a first member, let's call them x1::l1
and x2::l2
. Your membership hypothesis now looks like: all elements in x1::l1
are in x2::l2
.
But first, let us use excluded middle to state that either x1
in l1
or x1
not in l1
. If x1
in l1
, then trivially we can prove that x1::l1
has repeats. So moving forward, we may assume that x1
is not in l1
.
It suffices to match the inductive case that there exists an l2'
of the same length as l2
such that all elements of l1
are in l2'
.
Now consider the membership hypothesis on x1::l1
, with the forall variable introduced as x
:
By hypothesis, we know that x1
in x2::l2
. Now consider l2'
, where l2'
is x2::l2
with one instance of x1
removed (use in_split
). Now because x1
not in l1
, we can conclude that all members of l1
are also in l2'
and not the removed element. Then this satisfies the membership hypothesis in the induction, and some wrangling with lengths gives us length l2 = length l2'
, so that the length hypothesis is satisfied. We thus conclude that l1
contains repeats, and thus also x1::l1
.
Edit: previously, I also did a case analysis on whether or not x1
= x2
or x1
in l2
, and whether or not x
= x2
or x
in l2
, and solved the special cases in a more straightforward manner. It's not needed, and the general case also covers them.
QUESTION
data _∈_ {X : Set} (x : X) : (xs : List X) → Set where
here! : {xs : List X} → x ∈ x ∷ xs
there : {xs : List X} {y : X} (pr : x ∈ xs) → x ∈ y ∷ xs
remove : {X : Set} {x : X} (xs : List X) (pr : x ∈ xs) → List X
remove (_ ∷ xs) here! = xs
remove (y ∷ xs) (there pr) = y ∷ remove xs pr
...ANSWER
Answered 2019-Jun-24 at 19:49You need to use an informative proof of membership. Right now, your Any
takes values in Prop
, which, due to its limitations on elimination (see the error message you got), is consistent with the axiom forall (P: Prop) (x y: P), x = y
. This means that if you have some term that depends on a term whose type is in Prop
(as is the case with remove
), it has to only use the fact that such a term exists, not what term it is specifically. Generally, you can't use elimination (usually pattern matching) on a Prop
to produce anything other than something that's also a Prop
.
There are three essentially different proofs of In' 1 [1; 2; 1; 3; 1; 4]
, and, depending which proof is used, remove p
might be [2; 1; 4; 1; 4]
, [1; 2; 3; 1; 4]
or [1; 2; 1; 3; 4]
. So the output depends on the specific proof in an essential way.
To fix this, you can simply replace the Prop
in Inductive Any {A : Type} (P : A -> Type) : list A -> Prop
with Type
.1 Now we can eliminate into non-Prop
types and your definition of remove
works as written.
To answer your edits, I think the biggest issue is that some of your theorems/definitions need In'
to be a Prop
(because they depend on uninformative proofs) and others need the informative proof.
I think your best bet is to keep In'
as a Type
, but then prove uninformative versions of the theorems. In the standard libary, in Coq.Init.Logic
, there is an inductive type inhabited
.
QUESTION
Trying to get my feet wet using TypeScript and I keep running into trouble. An old function resurfaced today and just as an exercise, I was curious if I could convert it to TypeScript. So far it's been a complete pain in the neck.
...ANSWER
Answered 2017-Feb-19 at 00:34- this is a very impractical way of using functions in JS
- TS sucks at generics on function references, so a lot of intuition from Haskell just doesnt work here
back to your question, you have to provide names because TS syntax is such that requires you to do so, rational part is that a name of a parameter conveys additional meaning when the type alone fails to do so
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pigeonhole
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page