Replacement rules which for elements of a vector which meet conditions

I’m trying to create a function which will replace elements of a list with their values modulo 1, i.e. Mod[x,1], but only if Abs[x]>1. So, for example, the function would yield:

f[{-1.5,-1,0,1}]={.5,-1,0,1}].

I’m trying to do this in an elegant way. For example, I have a function for a related purpose:

C1[v_] := v /. _?Negative -> 0;.

This replaces negative elements of a list with 0, and it’s very clean.

I’d like to do something similar. My efforts so far have included breaking it into two functions:

CLim[x_] := Mod[x, 1] /; Abs[x] > 1;

C2[v_] := CQubitLim /@ v; But then, when I apply C2 to a list, it only seems to apply on some elements, for example

C2[{1,0,1.5}]={Clim[1],CLim[0],0.5}

My other idea was to use a conditional rule

v:>Mod[v,1]/;Abs[v]>1

But this doesn’t seem to evaluate when I put a vector through it.

Any ideas much appreciated.

Plotting with conditions

I am trying to plot a function with condition that x>zeta. my input is

If[x > ζ, Plot[polarizedgpd[x, -3, Λ, 0.2], {x, ζ, 1}]] 

But my output is

If[x > 0.2,Plot[polarizedgpd[x, -3, Λ, 0.2], {x, ζ, 1}]] 

However, I am defining $ \zeta=0.2$ , but still not getting anything.

Would this WPDB setup result in potential race conditions?

I have a page on my site with numerous elements that can be liked/disliked through a simple admin-ajax call.

In the associated PHP code, it looks like this:

// Fetch the existing meta from this element. The array of users who already voted, and the current score. global $  wpdb; $  row = $  wpdb->get_row( "SELECT `rating_users`, `rating_score` FROM `table` WHERE `file_id` = $  file_id" );  $  voted_users   = $  row->rating_users? unserialize( $  row->rating_users) : array(); $  current_score = $  row->rating_score ?: 0;  // Now verify this current user has not already voted, check the array. foreach ($  voted_users as $  id => $  ip) {     // check if current user ID / IP has voted, exit if true... }  // Good to go, add this user to the list of users who have voted now. $  voted_users[] = array(     $  user_id => $  user_ip ); $  current_score++;  $  wpdb->update(     'table',     array(         'rating_users' => serialize( $  voted_users ),         'rating_score ' => $  current_score     ),     array(         'file_id' => $  file_id     ),     array( '%s', '%d' ),     array( '%d' ) ); 

So I feel like in between the time I (retrieve the current list of users who have voted / score…verify if this is a valid vote…and then adjust/update the values back into the database) another user could have initiated the same process – and thus are dealing with “wrong” data. Data would be lost as one process would override the other’s upon the wpdb->update call.

I haven’t verified this, as emulating a race condition is difficult, but seems valid – what is a better method of performing the above that wouldn’t result in this issue?

Find the missing initial conditions for system of ODES

I want to solve the following system of ODEs:

   s1` (t) = -(k1*s1 *(k2*s2 + s3))/N,    s2` (t) = ((k1*s1 *(k2*s2 + s3))/N) - k3*s2,     s3' (t) = k3*s2 - k4*s3      s4' (t) = k4*s3 

where k1=0.4029;k2=0.7;k3=0.41;k4=0.182; N=s1+s2+s3+s4; my problem I don’t have initial conditions, is there any possible way in mathematica to find the initial conditions and solve the system?

Thanks

Using NDSolve and PieceWise for boundary conditions for coupled PDEs

I’ve decided to try and use PieceWise in my boundary conditions for my 4 coupled PDEs, but it doesn’t seem to work out nicely. I’m receiving the error:

NDSolve::overdet: There are fewer dependent variables, {IPB[z,t],IPF[z,t],IS1B[z,t],IS1F[z,t]}, than equations, so the system is overdetermined.

Paramters:

ROCP = 1; RICP = 0; ROCS1 = 0.5; RICS1 = 1; L = 5 10^-2; n = 1.556; c = 3 10^10; lR = 3; R1 = 0.99;  gP = 20; gS1 = 20; sigmaSP = 10^-13;  toffset = 5 10^-9; twidth = 10 10^-9; Energy = 1.3 10^-13; rad = 0.015; PumpInt = ((Energy)/(twidth ))/(Pi rad^2) ; PumpPeak = Exp[0.5 ((-toffset)/(twidth))^2] PumpInt;  lc = n lR; alphaP = L/(2 lc); alphaS1 = (L - Log[R1])/(2 lc);  tmax = 20 10^-9; 

The 4 PDEs I’m solving are:

PDE = {D[IPF[z, t], z] == -(n/c) D[IPF[z, t], t] -       gP IPF[z, t]*(IS1F[z, t] + IS1B[z, t]) - alphaP IPF[z, t],    -D[IPB[z, t], z] == -(n/c) D[IPB[z, t], t] -       gP IPB[z, t] (IS1F[z, t] + IS1B[z, t]) - alphaP IPB[z, t],    D[IS1F[z, t], z] == -(n/c) D[IS1F[z, t], t] +       gS1 IS1F[z, t] (IPF[z, t] + IPB[z, t]) - alphaS1 IS1F[z, t] +       sigmaSP (IPF[z, t] + IPB[z, t]),    -D[IS1B[z, t], z] == -(n/c) D[IS1B[z, t], t] +       gS1 IS1B[z, t] (IPF[z, t] + IPB[z, t]) - alphaS1 IS1B[z, t] +       sigmaSP (IPF[z, t] + IPB[z, t])}; 

And the Boundary conditions are:

BC = {IPF[z, t] ==      PieceWise[{{PumpPeak*Exp[-0.5 ((t - toffset)/twidth)^2],         z == 0 && t > 0}, {0, 0 <= z <= lR && t == 0}}],    IPB[z, 0] == 0, IPB[lR, t] == IPF[lR, t] ROCP,    IS1F[0, t] == IS1B[0, t] RICS1, IS1B[lR, t] == IS1F[lR, t] ROCS1,     IS1F[z, 0] ==  0, IS1B[z, 0] ==  0}; 

And the NDSolve:

solInt = NDSolve[{PDE, BC}, {IPF, IPB, IS1F, IS1B}, {z, 0, lR}, {t, 0,      tmax}, MaxStepFraction -> {1/750, 1/10},     Method -> {"BDF", "MaxDifferenceOrder" -> 5},     InterpolationOrder -> All]; 

The main idea behind the boundary conditions is that IPF[z,t] = 0 at time t = 0 and for any z in the range 0 – lR, but for t > 0 and z = 0, it will have the form of the Gaussian equation.

Is it possible to impose these initial conditions?

Side note: Sorry if my post are similar, I didn’t know if I should piggyback on my last question or if this was something I should ask from scratch.

Cheers!

Under what conditions can malware bypass macOS Catalina’s permission system? [closed]

Catalina has some new security features which include System Preferences > Security & Privacy features, which requires apps to request access to specific computer functionality such as camera, microphone, full disk access, input monitoring, etc.

Under what conditions could malware bypass such requirements to use those components without permission, and would it still be visible inside System Preferences > Security & Privacy or would they be capable of hiding their presence?

Master theorem conditions

I read somewhere that for the master theorem to work, the value of a needs to be a constant and that f(n) cannot be negative. However, I do not understand why these conditions need to be satisfied .

Could someone help me understand by giving a simple proof maybe ?

What are the most/least resistant/immune conditions?

Related to this question What are the most and least-resisted damage types? what is the most and least resisted or immune conditions?

I was looking at the UA psionic spells and I saw Id Insinuation that causes the incapacitated condition and it got me thinking about how often if ever a creature is immune to incapacitation. I use a lot of creatures that have immunities to the same (seemingly) conditions while other conditions are rarely in the list of immune conditions.

Postgres 11+: are covering indices (INCLUDE) useful for join/where conditions?

I’d like to better understand when covering indices can be useful to make index-only scans possible in Postgres 11+. As the documentation says, given the covering index

CREATE INDEX tab_x_y ON tab(x) INCLUDE (y); 

queries like this can use it for index-only scans:

SELECT y FROM tab WHERE x = 'key'; 

Now I am wondering if such a covering index could also allow index-only scans when the covering columns appear as conditions. For instance, assume a covering index:

CREATE INDEX tab_x_y_z ON tab(x) INCLUDE (y, z); 

Would this allow for index-only scans for the following queries?

SELECT z FROM tab WHERE x = 'key' AND y = 1;  SELECT x, y, z FROM (VALUES ('key1'),('key2'),('key3')) sub(id) JOIN tab ON tab.x = sub.id WHERE y = 1; 

Find if there is matrix that satisfying the following conditions

Given a matrix $ A_{n\times n} = \{a_{ij}\}$ such that $ a_{ij}$ is a non-negative number and given 2 vectors $ (r_1,r_2,…,r_n)$ , $ (c_1,c_2,…,c_n)$ such that $ r_i,c_i\in \mathbb{Z}$ define an efficient algorithm that will determine if there’s a matrix $ B_{n\times n} = \{b_{ij}\}$ , $ b_{ij} \in \mathbb{Z}$ and

for every $ 1\leq i \leq n \sum b_{ij} = r_i$

for every $ 1\leq j \leq n \sum b_{ij} = c_j$

and

$ 0 \leq b_{ij} \leq a_{ij}$

Thought something with dynamic programming but didn’t manage to solve it.