## Recurring relationships – Recursive functions with a trick

A function is defined by the following repetition relations:

f (n) = 2 · f (n – 1) – f (n – 2) + 2 if n is even

f (n) = 3 · f (n – 2) if n is odd

where n> 0 and f (1) = f (2) = 1.

You have received three requests, left, right and p.

Find the value of (f (left) + f (left + 1) … + f (right-1) + f (right)) mod p.

** Note: You can solve this question in O (1) time without using a recursion. There is a mathematical trick here that I can not figure out to find the answer for huge values ​​of l and r.

Many Thanks.

## one-way functions [on hold]

I would like to know the current state of the art to prove the existence of a one-way function and, in particular, the latest results and the best candidates to fill this role. In particular, I would like to know which papers and articles to read in order to keep abreast of the latest developments. Many Thanks.

## Why has my Nikon J1 set all the functions apart from Smart Photo mode?

My Nikon J1, which is equipped with 10-30 lenses, does not work anymore, except in Smart Photo mode. When I try to use a different mode, the camera turns off. Does anyone have a solution?

## c ++ – What is needed to write good-performing functions like OpenCV

I tried to implement my own edge detector and make it as fast as possible.

I've tried to code most of the needed functions myself and only used opencv as input / output.

However, the performance is not comparable to opencvs cv :: Canny () as the input gets larger. Even if I use OpenMP on most of my loops, it's not as fast as opencv. My compiled OpenCV contains optimization libraries like IPP, etc.

I know the features of opencv may not be the fastest, but I still want to know what's required to write good-quality codes.

Take for example my conv2_h_sobel () functions (I split the Sobel kernel). Is there a way to improve its performance?

conv2_h_sobel () takes a 2D image and a 1D kernel as inputs and then performs a convolution process.

``````template
void conv2_h_sobel (const Mat & src, mat & dst, const vector& kernel) {

// parameter control
if (src.empty () || src.channels () == 3) {
cout << "conv2_h () input error.  n";
Return;
}
if (kernel.size ()% 2 == 0) {
cout << "conv2_h () - kernel size error.  n";
Return;
}

// In his
if (dst.empty ()) dst = Mat (src.rows, src.cols, CV_32FC1);

int k_size = kernel.size (),
src_rows = src.rows,
src_cols = src.cols;

int offset_col = k_size / 2;
int k_idx = -offset_col;

OMP_FOR (src_rows * (src_cols - offset_col)) // Automatically ignored if openmp is not supported
for (int i = 0; i <src_rows; i ++) {
const src_type * src_ptr = src.ptr(I);
dst_type * dst_ptr = dst.ptr(I);

for (int j = offset_col; j <(src_cols - offset_col); j ++) {

float sum = src_ptr[j - 1]  * Kernel[0];
sum + = src_ptr[j]      * Kernel[1];
dst_ptr[j] = sum + (src_ptr[j + 1]  * Kernel[2]);
}
}

};
``````

## Apply functions to leaves with a nested list structure, if these leaves are more complex expression trees

Is there a way to apply a h function to the following nested list?

{{a, b}, {c, d}, {{d, e}, {f, g}}

where should that be?

{H[a]H[c], {H[d]H[f]}}

h is applied to the first element of each (most deeply nested) sublist and replaces this sublist. The nesting is never deeper than in the above example. That is, the expression tree for the list has at most the depth 3.

The remainder of the list structure pattern is preserved.

Here are a, c, d and f Not Atoms. They are again expressions with heads. The heads, however, are not list heads.

Consider as an example

{{U[a]u[b]}, {u[v[v[v[v[c]], d}, {{d, e}, {f, g}}

Applying h to this should result in:

{H[u[u[u[u[a]]H[u[v[u[v[u[v[u[v[c]]], {H[d]H[f]}}

In other words, h is applied to this `leaves "the list expression given above where this`Leaves "are more complicated expressions.

## Non-liner optimization of a family of functions

I would like to have tips on the following problem (solution methods, problem category, etc.).
The context is about the simultaneous registration of multiple images ($$n$$ images, $$f_ {i, j}$$ the function that maps coordinates $$(x_i, y_i)$$ to $$(x_j, y_j)$$,

To let $$f_ {i, j} ^ k (x, y)$$ a polynomial function of order $$k$$ from $$mathbb {R} ^ 2$$ to $$mathbb {R} ^ 2$$With $$i, j in [1, n]$$,

For example when $$k = 0$$Such functions can be expressed as $$f_ {i, j} ^ 0 (x, y) = (a_ {ij} ^ 0, a_ {ij} ^ 1)$$,
Or when $$k = 1$$: $$f_ {i, j} ^ 1 (x, y) = (a_ {ij} ^ 0 + b_ {ij} ^ 0 x + c_ {ij} ^ 0 y, a_ {ij} ^ 1 + b_ {ij} ^ 1 y + c_ {ij} ^ 1 y)$$,

Accepted $$k$$ is fixed, is waived in the following.

This family of functions should take into account as much as possible in terms of property: $$f_ {i, j} = f_ {i, k} (f_ {k, j})$$,

I want to use this property to reduce the number of unknowns and get robust estimates of the coefficients.
In addition, I have a large number of matches that can be expressed as such: $$v = f_ {i, j} (u)$$,

My problem is this: How can I calculate the functions robustly? $$f_ {1, i}$$ ?

If $$k = 0$$The problem is quite simple: $$f_ {i, j} = f_ {i, k} (f_ {k, j}) = f_ {i, k} + f_ {k, j}$$ so I can write an over-constrained linear system and solve it with a Moore-Penrose inverse or an algorithm like RANSAC.

If k = 1 or 2, I do not know exactly how to proceed. I think I could try to design a custom convergence scheme with a given order of equation resolution and some convergence iterations.

As an example, if I solve $$f_ {1,2}$$to get then $$f_ {1,3}$$ I can use my matches of the form $$v = f_ {1,3} (u)$$ but also the games like $$v = f_ {2,3} (u) => f_ {1,2} (v) = f_ {1,3} (u)$$

Thanks, Thomas

## SQL Server – Can we put equal signs after aggregate functions in SQL?

I came across such a script

``````set @sum = sum = (case if somecol1 null is then DATEDIFF (d,[somecol2], somecol3) else 0 end)
``````

I can not understand the meaning of the equal sign after the second keyword sum. When I run the query, no errors are displayed, both with and without equal signs.
I want to know what equals signs should be after the keyword. Is it a mistake or not?

Many Thanks

## Calculus – Integration by substitution – Integral of symmetric functions applying properties or second substitution?

I need help with this integral: $$int_0 ^ 2 (x-1) e ^ {(x-1) ^ 2} ; mathrm {d} x$$

Okey. I choose $$u = x-1$$, so $$du = dx$$,

$$a = 0$$ and $$b = 2$$

$$u = g (x) = x-1$$

$$g (a) = g (0) = 0-1 = -1$$

$$g (b) = g (2) = 2-1 = 1$$

$$int_0 ^ 2 (x-1) e ^ {(x-1) ^ 2} ; mathrm {d} x$$
$$= int _ {- 1} ^ 1 ue ^ {u ^ 2} ; mathrm {d} u$$

I'm stuck here. I was wondering if I could use one of the properties of the symmetric functions integral there:

• If $$f$$ is then just $$int _ {- a} ^ f (x) ; mathrm {d} x = 2 int_ {0} ^ a f (x) ; mathrm {d} x$$
• If $$f$$ is so strange $$int _ {- a} ^ a f (x) ; mathrm {d} x = 0$$

To let $$h (u) = ue ^ {u ^ 2}$$, then $$h (-u) = – ue ^ {(- u) ^ 2} = – ue ^ {u ^ 2}$$, That's why it's strange. So I can use the second property and close it $$int_0 ^ 2 (x-1) e ^ {(x-1) ^ 2} ; mathrm {d} x = int _ {- 1} ^ 1 ue ^ {u ^ 2} ; mathrm {d} u = 0$$???

Or do I have a second substitution? $$int _ {- 1} ^ 1 ue ^ {u ^ 2} ; mathrm {d} u$$?

$$v = u ^ 2$$, so $$dv = 2u you$$. $$frac {1} {2} dv = u you$$

$$v = (1) ^ 2 = 1$$ and $$v = (- 1) ^ 2 = 1$$

Then,

$$int_0 ^ 2 (x-1) e ^ {(x-1) ^ 2} ; mathrm {d} x$$
$$= int _ {- 1} ^ 1 ue ^ {u ^ 2} ; mathrm {d} u$$
$$= int_ {1} ^ 1 e ^ {v} cdot frac {1} {2} mathrm {d} v$$
$$= frac {1} {2} int_ {1} ^ 1 e ^ {v} mathrm {d} v$$
$$= tfrac {1} {2} [e^{v}] Big | _ {1} ^ 1$$
$$= tfrac {1} {2} [e^{1}-e^{1}]$$
$$= tfrac {1} {2} [e-e]$$
$$= tfrac {1} {2} [0]$$
$$= 0$$

Are these analyzes okay? If so, which: integral of the properties of symmetric functions or second substitution, or both? If not, how can I work with it? Thank you in advance.

## Trigonometry – adding trigger functions with different frequencies

This is not possible in general. Think of the case $$C_1 = 1, C_2 = 0, omega = 1$$, Then you have to write
$$cos t = A cos (t + pi / 4) + B cos (2t + pi / 4)$$
The left side has no frequency $$2t$$ Stuff, so $$B$$ must be zero (this requires a little bit of proof, but not much). But that leaves you
$$cos t = A cos (t + pi / 4).$$
There is no value of $$A$$ This is true as you can see in the rating $$t = pi / 4, 3 pi / 4$$,

## postgresql – Filter sorted overlapping areas with window functions

I have the following record:

``````layer int
Period tstzrange
``````

I want to select all periods (from any level) that do not overlap with a period in the lower level. In other words, a period of layer 1 eliminates a period of layer 2 if they overlap.

We can assume that two periods within the same level never overlap.

This can easily be written with the following nested loop, which basically performs an anti-join:

``````Select period
from t like t1
where does not exist
(
choose 1
from t like t2
where t2.layer <t1.layer and
t2.period && t1.period
)
``````

Can this also be written via window functions?

For what it's worth, I've studied similar questions here on DBA, and in most answers the window function `Delay()` is used to find out if there is an earlier period that overlaps. This is useful if you can simply arrange the rows after the start time of the period. However, I believe that we have to order here on this question `Shift, period`, Sorting by period only would be wrong because, for example, a period of `10:00` to `12:00` in layer 2 should be considered after a period of time `11:00` to `13:00` in layer 1. Once we sort by, however `Shift, period`, two consecutive lines are probably / no longer necessarily linked, so I do not understand how `Delay()` can then be applied. I can not find an application from `Delay()` or other window functions to solve the problem.