Solving Event Dependence in Event Driven Systems

There are 60 Million Shipments per day. Each shipment has about 50 metrics to be calculated. Each metric is calculated based on a type of the event(Let’s say event_1 has the required information to calculate metric_1, event_2 .. metric_2 and so on). All the events are independent of each other apart from one dependency, a single event(let’s say event_1) which has vital information required to process each of the other events.

The current design:

(In Order)Scenario 1:event_1 arrives first, we calculate metric_1 and store the vital information required to process other events in DynamoDB. Other events(event_4, event_2,….) arrive and are processed by accessing the information from DynamoDB.

(Out of Order)Scenario 2: event_3 arrives first, system checks for required information in DynamoDB and fails, the system places the event in the dead letter queue to be retried after a period of time. One event_1 arrives and is processed, the other events go through.

Is using a data store and retry mechanism the right approach to resolve the dependency on the base event(event_1)?

Are there better approaches/patterns to solve the event dependency problem?

Additional Context: Although I believe this information is irrelevant, I am giving it anyway if it helps. Source of Events: SNS topics, Event Processing: SNS->SQS->Lambda, Data Store: DynamoDB, Metrics are stored in RedShift.

Circular dependence and many references to the same object

I have tried to design a class diagram for my first game. But then I realized that there are some ugly parts.

First, there is reference from StateSystem to State and from State to StateSystem. The StateSystem object contains references to State instances and one of them is always current. StateSystem calls it’s update and render functions. But every instance of State also has to have a reference back to StateSystem, so it can change state to another one. I’d like to know how to avoid the circular dependence in this case.

Secondly, I don’t know where to hold reference(s) to the Input object. Generally, all classes which belong to the UI (green classes) need a reference to the same instance (only existing instance) of Input due to mouse collision detection. Input contains stored information about pressed keys, mouse coordinates and so on. Should I store the reference in every object that needs it?

Moreover, what about TextureManager class? The only thing it does is store Texture instances via string IDs (and preparing it for OpenGL) and when needed, it returns a texture according to a given ID. Should I consider using, for example, the Builder pattern and let only the “director” object own the texture manager and create concrete textures for objects?

Randomized Quick Selects’ time complexity dependence on k – the index to be selected

I was analyzing Randomized Quick Selects’ time complexity, as a function of n – the size of the input, and k – the index of the element that needs to be selected.
The time complexity dependence on n was linear as was expected, but the dependence on k was of an inverted parabola – i.e the time complexity was highest when trying to select the median and lowest when trying to select the first or last element of the array.

Is there an explanation for that?

Differential operator with dependence on differentiation variable

I was wondering if it would make sense to define a (generic) total differential operator as follows:

$ $ \frac{d}{d\alpha} = \frac{\partial}{\partial\alpha} + A \, d\alpha \tag{1}\label{1} $ $

where $ \alpha$ is the differentiation parameter and $ A$ is a generic term, not explicitly dependent on $ \alpha$ .

The problem with this is that I’m not sure whether it is mathematically correct to have a differential operator that is linearly dependent on the differential of the derivation parameter itself, i.e. $ d\alpha$ . Or rather, that includes a term directly proportional to $ d\alpha$ .

I know of the theta operator defined as:

$ $ \theta = z\frac{d}{dz} $ $

but I think this is different and probably not comparable to the case reported in equation $ \eqref{1}$ .

Thanks for any help.

Partial derivative and explicit dependence

Let’s say my variables are x and y.

I define a generic function $ f(x)=ax$ (for example).

At this point, I define a new variable $ n = \frac {y}{f(x)}$ , and a function $ g=g(n)$ of variable n.

The function g hasn’t an explicit dependence from variable $ x$ , so, according to the definition I was given of partial derivative, I have that $ \frac {\partial g(x,y)}{\partial x}$ is zero.

Now, if I put $ n = \frac {y}{f(x)}$ in the expression of $ g(n)$ , I obtain $ g(x,y)$ , function of $ x$ and $ y$ . now, obviously, $ \frac {\partial g(x,y)}{\partial x}$ is not zero, because $ g$ has an explicit dependence from $ x$ .

Obviously, there is something wrong. could somebody help me?

Closed Form Taylor Series with Functional Dependence

Suppose I have smooth functions $ f,g,y_0$ and $ y_1$ from $ \mathbb{R}$ to $ \mathbb{R}$ , such that $ $ y_1 = y_0 – \epsilon g(y_0)$ $ Then I consider $ $ f(y_0) = f(y_1 + \epsilon g(y_0))$ $ what is a closed from Taylor series in the small parameter $ \epsilon$ in terms of derivatives of $ f$ and $ g$ and only the function $ y_1$ ? The first few terms are

$ $ f(y_0) = f(y_1) + \epsilon f'(y_1) g(y_0) + \frac{1}{2}\epsilon^2 f”(y_1)g^2(y_0) +..$ $ $ $ = f(y_1) + \epsilon f'(y_1) [g(y_1) + \epsilon g'(y_1)g(y_0) + … ]$ $ $ $ + \frac{1}{2}\epsilon^2 f”(y_1)[g(y_1) + \epsilon g'(y_1)g(y_0) + … ]^2 +…$ $ grouping terms gives $ $ f(y_0) = f(y_1)+ \epsilon [f’g](y_1) + \epsilon^2[f’g’g + \frac{1}{2}f”g^2](y_1) + \epsilon^3[f’g’^2g + \frac{1}{2}f’g”g + \frac{1}{2}f”g’g + \frac{1}{6}f”’g^3](y_1) + O(\epsilon^4)$ $ But is there some way to write this as a more compact sum like $ $ f(y_0) \sim \sum_{n=0}^\infty\sum_{m=0}^n \epsilon^n \alpha(n,m)f^{(n)}g^{(m-n)}(y_1)$ $ I am having trouble identifying the pattern. I know there will be some product involved as well.

Linear dependence of directional derivative problem

Real analysis problem on directional derivatives.

For $ (x,y)\neq(0,0)$ , let $ $ f(x,y)=\frac{yx^6+y^3+x^3y}{x^6+y^2}$ $ and let $ f(x,y)=0$ when $ (x,y)=(0,0)$

a) Show that all directional derivatives of f exist at $ (0,0)$ , and depend linearly on the vector we differentiate along.

b) Show that nevertheless, f is not differentiable at $ (0,0)$ .

What I have so far:

a) Set $ u=(u_1,u_2)$ such that $ |u|=1$ . By definition $ $ D_u f=\lim_{h\to 0}\frac{f((x,y)+h(u_1,u_2))-f(x,y)}{h}$ $

So then we see $ $ D_u f(0,0)=\lim_{h\to 0}\frac{f((0,0)+h(u_1,u_2))-f(0,0)}{h}=\lim_{h\to 0}\frac{\frac{hu_2(hu_1)^6+(hu_2)^3+(hu_1)^3hu_2}{(hu_1)^6+(hu_2)^2}}{h}=\lim_{h\to 0}\frac{h^7u_2 u_1^6+h^3u_2^3+h^4u_1^3u_2}{h^7u_1^6+h^3u_2^2}=\lim_{h\to 0}\frac{h^4u_2 u_1^6+u_2^3+hu_1^3u_2}{h^4u_1^6+u_2^2}=\frac{u_2^3}{u_2^2}=u_2$ $

Hence all directional derivatives of f exist at (0,0). But how would I show that they depend linearly on the vector we differentiate along?

b) First set $ y=0$ , then $ \lim_{(x,y)\to(0,0)} f(x,y)=0$ . Next set $ y=x^3$ , then $ \lim_{(x,y)\to(0,0)} f(x,y)=\frac{1}{2}$ . Since the limits don’t match, the function is not continuous at the origin and thus not differentiable at the origin.

Type dependence and equivalence vs equality of categorical morphisms?

I will distinguish between mathematical functions and computational functions which I will think of for concreteness as $ \lambda$ -functions.

In every context I’ve encountered, the type signature of a lambda function depends only on its input-output relation. However, it seems to me that we can distinguish between two functions of the same input output types on the basis that they use a different set of types in their computation:

$ f:\mathbb N\to \mathbb N \quad f=\lambda x:\mathbb N, (x+1)$

$ g:\mathbb N\to \mathbb N \quad g=\lambda x:\mathbb N, (\text{toNat toInt } x + 1)$

Where $ \text{toNat}:\mathbb Z \to \mathbb N, \text{toInt}:\mathbb N \to \mathbb Z$ do the obvious thing.

In my own words, $ f$ and $ g$ have the same type signature but don’t have the same “type dependence” because $ g$ depends on $ \mathbb Z$ (is there a standard term for this?)

Question 1: Is there a standard theory of how to distinguish between $ f$ and $ g$ in terms of their “type dependence”?

—————

I want to think about the difference between “type signature” and “type dependence” in categorical terms.

If we have morphisms (which we will think of as $ \lambda$ -functions) $ f:A\to B$ and $ g:B\to C$ , then $ g\circ f$ has type signature $ g\circ f:A\to C$ , but in a sense, the function $ g\circ f$ has a type dependency on $ B$ .

Let’s say we have a $ \lambda$ -function $ h:A\to C$ , such that $ h$ computes the same as $ g\circ f$ , which we will denote as an equivalence $ h\equiv g\circ f$ , but $ h$ does not have a type dependence on $ B$ .

We want to be able to say: “the diagram containing $ f,g,h$ commutes” while only referring to the equivalence of $ h$ and $ g\circ f$ , not their actual equality.

Question 2. Is there some kind of pre-existing theory within category theory about these things related to what I’ve been calling “type dependence”?