When I am sending emails my log says connection timed out.
when I ran traceroute: traceroute -T -p 25 alt4.aspmx.l.google.com , I am getting the following output.
traceroute to alt4.aspmx.l.google.com (74.125.141.27), 30 hops max, 60 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
Any ideas how to solve this.
To check connectivity run telnet alt4.aspmx.l.google.com 25 and on other screen run tcpdump -i any port 25 or icmp
And then analyze tcpdump output
Related
I have the following function with the variables:
b <- 1 ; d_uhpc <- 4
L_joint <- 8 ; A_bar <- 0.31
A_s <- (A_bar/L_joint)*12
L_unb <- 16 ; f_t <- 1.2
E_s <- 29000 ; E_uhpc <- 8000
ec <- function(x){
theta <- x[3]
eci <- seq(10^-3,1,10^-3)
while (TRUE) {
fc <- eci * E_uhpc
c <- (sqrt(A_s^2 * E_s^2 * eci^2 + fc * A_s * E_s * b * d_uhpc *eci + b^2 * f_t^2 * d_uhpc^2) +
b * f_t * d_uhpc - A_s * E_s *eci)/(b * fc + 2 * b * f_t)
ec <- (-2*theta*c)/L_unb
if (eci > abs(ec)) return("Error") else return(ec)
}
}
# sample rows
strain.analysis <- read.table(text="
L S theta
1 60 6 0.3876484
2 70 6 0.3650651
3 80 6 0.3619457
4 90 6 0.3089947
5 100 6 0.3131211
6 110 6 0.3479024", header=TRUE)
strain.analysis1 <- cbind(strain.analysis, vars = t(apply(strain.analysis,1,ec)))
The function does not understand the conditions correctly and just returns ec for all of the eci values regardless of the condition that it should only return ec when eci < abs(ec)
Below is an example of what I am trying to recreate in R.
Here's what I am thinking: your return statements in the while loop are incorrect as they exit the function ec and not only the while loop. I think your are after break. When I ran your code, with the eci as vector fixed, it only performed one loop for each row in the dataset.
Also, as mentioned before, eci cannot be a vector of length 1000. It has to start at 1E-6 and increment every loop with 1E-6 (per the figure). Your exit criteria are complicated and as we do not know what 0in is it cannot be correctly reconstructed.
Finally, in apply you can call a user-defined function but you have to pass it something.
Having said that, is this what you are after?
b <- 1
d_uhpc <- 4
L_joint <- 8
A_bar <- 0.31
A_s <- (A_bar/L_joint)*12
L_unb <- 16
f_t <- 1.2
E_s <- 29000
E_uhpc <- 8000
eci <- 1E-6
ec <- function(x){
#browser()
theta <- x[3]
while (TRUE) {
fc <- eci * E_uhpc
c <- (sqrt(A_s^2 * E_s^2 * eci^2 + fc * A_s * E_s * b * d_uhpc *eci + b^2 * f_t^2 * d_uhpc^2) +
b * f_t * d_uhpc - A_s * E_s *eci)/(b * fc + 2 * b * f_t)
ec <- (-2*theta*c)/L_unb
if (eci > abs(ec)) break
eci <- eci + 1E-6
}
if (c > d_uhpc | ((max(c(abs(ec), eci), na.rm = TRUE))/(min(c(abs(ec), eci), na.rm = TRUE))) - 1 > 0.05) return(NA_real_) else return(ec)
}
v <- apply(strain.analysis, 1, function(x) ec(x))
strain.analysis1 <- cbind(strain.analysis, v)
The code loops many times for each row of strain,analysis until the break condition is met. Based on the value of ec and eci the function returns either a value of NA_real_.
Here's how my output looks like:
> strain.analysis1
L S theta v
1 60 6 0.3876484 -0.06845568
2 70 6 0.3650651 -0.06447493
3 80 6 0.3619457 -0.06392507
4 90 6 0.3089947 -0.05459143
5 100 6 0.3131211 -0.05531879
6 110 6 0.3479024 -0.06144967
This is a more vectorized approach - it calculates all ec at once and then determines which ec meets the criteria. This means it is fast although it can use up more memory than #Paul van Oppen's solution.
eci <- seq(10^-6,1,10^-6)
fc <- eci * E_uhpc
const <- (sqrt(A_s^2 * E_s^2 * eci^2 + fc * A_s * E_s * b * d_uhpc *eci + b^2 * f_t^2 * d_uhpc^2) +
b * f_t * d_uhpc - A_s * E_s *eci)/(b * fc + 2 * b * f_t)
ec <- function(x){
theta = x[3]
ec = (-2*theta*const)/L_unb
comp = eci > abs(ec)
if (any(comp)) { ## at least one of our eci > abs(ec)
wm = which.max(comp)
if (comp[wm] == FALSE) ##which.max(c(FALSE, FALSE)) will still return something. We need NA_real_ in this case
return (NA_real_)
else
return(ec[wm])
}
else
return(ec[length(x)])
}
cbind(strain.analysis, V = apply(strain.analysis,1,ec))
#> L S theta V
#> 1 60 6 0.3876484 -0.06845568
#> 2 70 6 0.3650651 -0.06447493
#> 3 80 6 0.3619457 -0.06392507
#> 4 90 6 0.3089947 -0.05459143
#> 5 100 6 0.3131211 -0.05531879
#> 6 110 6 0.3479024 -0.06144967
I wasnt able to find any topic on this despite multiple searches. Apologies if this was already covered here.
Can anyone point me in the right direction for further research on the below topic:
I have played recently with the Fibonacci sequence and prime numbers. I have noticed that, at least for certain initial items in that sequence, if you mark all of the primes in the sequence (I did it for numbers: 2(odd prime),3,5,13,89,233,1597,28657) and check their place in the sequence, it also turns out to be a prime. I'm asssuming that 0 is the 0th item. To give some examples: for 2(odd prime) - which is the 3rd number of the sequence - 3 is also a prime, for 13 being 7th number of the sequence - 7 is also prime, for 233 - being 17th number of the sequence - 17 is also a prime. This seems to be true for all primes up to 17 item in the sequence, it then starts to diverge as 19th (19 being a prime) number of the sequence is 4181 which is not a prime.
To give a visual example:
item number Fib number
0 0
1 1
2 1
prime 3 2 prime !
not prm 4 3 prime
prime 5 5 prime !
6 8
prime 7 13 prime !
8 21
9 34
10 55
prime 11 89 prime !
12 144
prime 13 233 prime !
14 377
15 610
16 987
prime 17 1597 prime !
18 2584
prime 19 4181 not prime
20 6765
21 10946
22 17711
prime 23 28657 prime !
24 46368
25 75025
26 121393
27 196418
28 317811
prime 29 514229 prime !
30 832040
prime 31 1346269 not prime
32 2178309
33 3524578
34 5702887
35 9227465
36 14930352
prime 37 24157817 not prime
38 39088169
39 63245986
40 102334155
41 165580141
Despite there being certain numbers in the sequence which are primes but their sequence order number not being a prime and vice versa, it's still quite interesting to know why is there such a pattern and if it's true for majority of Fibonacci sequence numbers.
Again, apologies if this is something obvious.
TIA for any clarification on this!
You might want to look at A001605 and follow the links from there. The Online Encyclopedia of Integer Sequences is a fantastic resource for things like this.
I also discuss fibonacci primes at my blog.
You seem to be mixing two different thoughts here:
If I index the Fibonacci series with a prime, will I find a prime
there?
If I find a prime in the Fibonacci series, will its index be a
prime?
According to the Fibonacci Prime article in Wikipedia:
Except for the case n = 4, all Fibonacci primes have a prime index,
..., but not every prime is the index of a Fibonacci prime.
Which means 1 above doesn't hold, as you demonstrated with prime index 19, but 2 above always holds except for Fibonacci prime 3 whose Fibonacci index is 4.
To bring this back to programming, my Python code to reproduce your table (sorta):
def is_prime(n):
if n > 1 and n % 2 != 0 or n == 2:
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
break
else:
return n
return '*' * len(str(n))
print('n', 'f', sep='\t')
f, p, n = 0, 1, 0
while True:
print(is_prime(n), is_prime(f), sep='\t')
f, p, n = f + p, f, n + 1
OUTPUT
n f
* *
* *
2 *
3 2
* 3
5 5
* *
7 13
* **
* **
** **
11 89
** ***
13 233
** ***
** ***
** ***
17 1597
** ****
19 ****
** ****
** *****
** *****
23 28657
** *****
** *****
** ******
** ******
** ******
29 514229
** ******
31 *******
** *******
** *******
** *******
** *******
** ********
37 ********
** ********
** ********
** *********
41 *********
** *********
43 433494437
** *********
** **********
** **********
47 2971215073
** **********
** **********
** ***********
** ***********
** ***********
53 ***********
** ***********
** ************
** ************
** ************
** ************
59 ************
** *************
61 *************
** *************
** *************
** **************
** **************
** **************
67 **************
** **************
** ***************
** ***************
71 ***************
** ***************
73 ***************
** ****************
** ****************
** ****************
** ****************
** ****************
79 *****************
** *****************
** *****************
** *****************
83 99194853094755497
** ******************
** ******************
** ******************
** ******************
** *******************
89 *******************
** *******************
** *******************
** *******************
** ********************
I have problem with looping over the GRanges list.
my feature contains a list of objects:
feature file:
...
$Pol3
GRanges object with 205 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
1 chr1 [ 16545569, 16546385] *
2 chr1 [ 16678151, 16678447] *
3 chr1 [ 93847201, 93848017] *
4 chr1 [146039330, 146039547] *
5 chr1 [146038406, 146038434] *
... ... ... ...
180 chr8 [ 66112999, 66114487] *
181 chr8 [ 95269339, 95270155] *
182 chr8 [123157081, 123157461] *
183 chrX [ 18674543, 18675359] *
184 chrX [137437934, 137438750] *
-------
seqinfo: 17 sequences from an unspecified genome; no seqlengths
$FOS
GRanges object with 14383 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 [ 778602, 778872] *
[2] chr1 [ 966089, 966373] *
[3] chr1 [1000738, 1001022] *
[4] chr1 [1064238, 1064508] *
[5] chr1 [1080197, 1080467] *
... ... ... ...
[14379] chrX [155026485, 155026769] *
[14380] chrX [155068168, 155068452] *
[14381] chrX [155216229, 155216464] *
[14382] chrX [155881129, 155881399] *
[14383] chrX [155888227, 155888497] *
-------
seqinfo: 23 sequences from an unspecified genome; no seqlengths
...
and my interval is like:
GRanges object with 6 ranges and 1 metadata column:
seqnames ranges strand | id
<Rle> <IRanges> <Rle> | <character>
[1] chr1 [ 8409137, 8409637] * | region1
[2] chr1 [ 8789220, 8789720] * | region1
[3] chr1 [ 9615503, 9616003] * | region1
[4] chr1 [10960926, 10961426] * | region1
[5] chr1 [11797718, 11798218] * | region1
[6] chr1 [12434198, 12434698] * | region1
-------
seqinfo: 23 sequences from an unspecified genome; no seqlengths
For each object in feature file (e.g. $FOS) I am able to do
mtch = findOverlaps(interval, feature$FOS)
myRanges = ranges(mtch,ranges(interval),ranges(feature$FOS))
everything is fine for each object one by one but when I try to use lapply , the second step does not work
mtch <- lapply(feature, function(x) findOverlaps(x, interval))
myRanges = ranges(mtch,ranges(currmySegm),ranges(feature))
I get :
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'ranges' for signature '"list"'
OR
myRanges = ranges(mtch,ranges(interval),lapply(feature, function(x) ranges(x)))
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'ranges' for signature '"list"'
Thank so much for helping me
Step two should be something like this assuming you want to get ranges from the matches and the original GRange objects:
lapply(seq_along(mtch), function(i){
ranges(mtch[[i]], ranges(interval), ranges(features[[i]]))
})
I am looking through a field of bytes with hex values. The first 4 bytes map to one real-Value, a number. Now I need to know what decimal value it stands for and how to get this information?
ByteA = '12'; that means '18' in dec;
ByteB = '01'; that means '1' in dec;
ByteC = '00'; that means '0' in dec;
ByteD = '00'; that means '0' in dec;
Each byte gets multiplied by 256 ^ the position in the field, so it could be either:
Big-endian (most significant byte first)
18 * 256 ^ 3 = 301,989,888
1 * 256 ^ 2 = 65,536
0 * 256 ^ 1 = 0
0 * 256 ^ 0 = 0
-----------
302,055,424
Little-endian:
0 * 256 ^ 3 = 0
0 * 256 ^ 2 = 0
1 * 256 ^ 1 = 256
18 * 256 ^ 0 = 18
-----------
274
Most programming languages have built-in hex to decimal capabilities.
How to calculate modulus of 5^55 modulus 221 without much use of calculator?
I guess there are some simple principles in number theory in cryptography to calculate such things.
Okay, so you want to calculate a^b mod m. First we'll take a naive approach and then see how we can refine it.
First, reduce a mod m. That means, find a number a1 so that 0 <= a1 < m and a = a1 mod m. Then repeatedly in a loop multiply by a1 and reduce again mod m. Thus, in pseudocode:
a1 = a reduced mod m
p = 1
for(int i = 1; i <= b; i++) {
p *= a1
p = p reduced mod m
}
By doing this, we avoid numbers larger than m^2. This is the key. The reason we avoid numbers larger than m^2 is because at every step 0 <= p < m and 0 <= a1 < m.
As an example, let's compute 5^55 mod 221. First, 5 is already reduced mod 221.
1 * 5 = 5 mod 221
5 * 5 = 25 mod 221
25 * 5 = 125 mod 221
125 * 5 = 183 mod 221
183 * 5 = 31 mod 221
31 * 5 = 155 mod 221
155 * 5 = 112 mod 221
112 * 5 = 118 mod 221
118 * 5 = 148 mod 221
148 * 5 = 77 mod 221
77 * 5 = 164 mod 221
164 * 5 = 157 mod 221
157 * 5 = 122 mod 221
122 * 5 = 168 mod 221
168 * 5 = 177 mod 221
177 * 5 = 1 mod 221
1 * 5 = 5 mod 221
5 * 5 = 25 mod 221
25 * 5 = 125 mod 221
125 * 5 = 183 mod 221
183 * 5 = 31 mod 221
31 * 5 = 155 mod 221
155 * 5 = 112 mod 221
112 * 5 = 118 mod 221
118 * 5 = 148 mod 221
148 * 5 = 77 mod 221
77 * 5 = 164 mod 221
164 * 5 = 157 mod 221
157 * 5 = 122 mod 221
122 * 5 = 168 mod 221
168 * 5 = 177 mod 221
177 * 5 = 1 mod 221
1 * 5 = 5 mod 221
5 * 5 = 25 mod 221
25 * 5 = 125 mod 221
125 * 5 = 183 mod 221
183 * 5 = 31 mod 221
31 * 5 = 155 mod 221
155 * 5 = 112 mod 221
112 * 5 = 118 mod 221
118 * 5 = 148 mod 221
148 * 5 = 77 mod 221
77 * 5 = 164 mod 221
164 * 5 = 157 mod 221
157 * 5 = 122 mod 221
122 * 5 = 168 mod 221
168 * 5 = 177 mod 221
177 * 5 = 1 mod 221
1 * 5 = 5 mod 221
5 * 5 = 25 mod 221
25 * 5 = 125 mod 221
125 * 5 = 183 mod 221
183 * 5 = 31 mod 221
31 * 5 = 155 mod 221
155 * 5 = 112 mod 221
Therefore, 5^55 = 112 mod 221.
Now, we can improve this by using exponentiation by squaring; this is the famous trick wherein we reduce exponentiation to requiring only log b multiplications instead of b. Note that with the algorithm that I described above, the exponentiation by squaring improvement, you end up with the right-to-left binary method.
a1 = a reduced mod m
p = 1
while (b > 0) {
if (b is odd) {
p *= a1
p = p reduced mod m
}
b /= 2
a1 = (a1 * a1) reduced mod m
}
Thus, since 55 = 110111 in binary
1 * (5^1 mod 221) = 5 mod 221
5 * (5^2 mod 221) = 125 mod 221
125 * (5^4 mod 221) = 112 mod 221
112 * (5^16 mod 221) = 112 mod 221
112 * (5^32 mod 221) = 112 mod 221
Therefore the answer is 5^55 = 112 mod 221. The reason this works is because
55 = 1 + 2 + 4 + 16 + 32
so that
5^55 = 5^(1 + 2 + 4 + 16 + 32) mod 221
= 5^1 * 5^2 * 5^4 * 5^16 * 5^32 mod 221
= 5 * 25 * 183 * 1 * 1 mod 221
= 22875 mod 221
= 112 mod 221
In the step where we calculate 5^1 mod 221, 5^2 mod 221, etc. we note that 5^(2^k) = 5^(2^(k-1)) * 5^(2^(k-1)) because 2^k = 2^(k-1) + 2^(k-1) so that we can first compute 5^1 and reduce mod 221, then square this and reduce mod 221 to obtain 5^2 mod 221, etc.
The above algorithm formalizes this idea.
To add to Jason's answer:
You can speed the process up (which might be helpful for very large exponents) using the binary expansion of the exponent. First calculate 5, 5^2, 5^4, 5^8 mod 221 - you do this by repeated squaring:
5^1 = 5(mod 221)
5^2 = 5^2 (mod 221) = 25(mod 221)
5^4 = (5^2)^2 = 25^2(mod 221) = 625 (mod 221) = 183(mod221)
5^8 = (5^4)^2 = 183^2(mod 221) = 33489 (mod 221) = 118(mod 221)
5^16 = (5^8)^2 = 118^2(mod 221) = 13924 (mod 221) = 1(mod 221)
5^32 = (5^16)^2 = 1^2(mod 221) = 1(mod 221)
Now we can write
55 = 1 + 2 + 4 + 16 + 32
so 5^55 = 5^1 * 5^2 * 5^4 * 5^16 * 5^32
= 5 * 25 * 625 * 1 * 1 (mod 221)
= 125 * 625 (mod 221)
= 125 * 183 (mod 183) - because 625 = 183 (mod 221)
= 22875 ( mod 221)
= 112 (mod 221)
You can see how for very large exponents this will be much faster (I believe it's log as opposed to linear in b, but not certain.)
/* The algorithm is from the book "Discrete Mathematics and Its
Applications 5th Edition" by Kenneth H. Rosen.
(base^exp)%mod
*/
int modular(int base, unsigned int exp, unsigned int mod)
{
int x = 1;
int power = base % mod;
for (int i = 0; i < sizeof(int) * 8; i++) {
int least_sig_bit = 0x00000001 & (exp >> i);
if (least_sig_bit)
x = (x * power) % mod;
power = (power * power) % mod;
}
return x;
}
5^55 mod221
= ( 5^10 * 5^10 * 5^10 * 5^10 * 5^10 * 5^5) mod221
= ( ( 5^10) mod221 * 5^10 * 5^10 * 5^10 * 5^10 * 5^5) mod221
= ( 77 * 5^10 * 5^10 * 5^10 * 5^10 * 5^5) mod221
= ( ( 77 * 5^10) mod221 * 5^10 * 5^10 * 5^10 * 5^5) mod221
= ( 183 * 5^10 * 5^10 * 5^10 * 5^5) mod221
= ( ( 183 * 5^10) mod221 * 5^10 * 5^10 * 5^5) mod221
= ( 168 * 5^10 * 5^10 * 5^5) mod221
= ( ( 168 * 5^10) mod 221 * 5^10 * 5^5) mod221
= ( 118 * 5^10 * 5^5) mod221
= ( ( 118 * 5^10) mod 221 * 5^5) mod221
= ( 25 * 5^5) mod221
= 112
What you're looking for is modular exponentiation, specifically modular binary exponentiation. This wikipedia link has pseudocode.
Chinese Remainder Theorem comes to mind as an initial point as 221 = 13 * 17. So, break this down into 2 parts that get combined in the end, one for mod 13 and one for mod 17. Second, I believe there is some proof of a^(p-1) = 1 mod p for all non zero a which also helps reduce your problem as 5^55 becomes 5^3 for the mod 13 case as 13*4=52. If you look under the subject of "Finite Fields" you may find some good results on how to solve this.
EDIT: The reason I mention the factors is that this creates a way to factor zero into non-zero elements as if you tried something like 13^2 * 17^4 mod 221, the answer is zero since 13*17=221. A lot of large numbers aren't going to be prime, though there are ways to find large primes as they are used a lot in cryptography and other areas within Mathematics.
This is part of code I made for IBAN validation. Feel free to use.
static void Main(string[] args)
{
int modulo = 97;
string input = Reverse("100020778788920323232343433");
int result = 0;
int lastRowValue = 1;
for (int i = 0; i < input.Length; i++)
{
// Calculating the modulus of a large number Wikipedia http://en.wikipedia.org/wiki/International_Bank_Account_Number
if (i > 0)
{
lastRowValue = ModuloByDigits(lastRowValue, modulo);
}
result += lastRowValue * int.Parse(input[i].ToString());
}
result = result % modulo;
Console.WriteLine(string.Format("Result: {0}", result));
}
public static int ModuloByDigits(int previousValue, int modulo)
{
// Calculating the modulus of a large number Wikipedia http://en.wikipedia.org/wiki/International_Bank_Account_Number
return ((previousValue * 10) % modulo);
}
public static string Reverse(string input)
{
char[] arr = input.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
Jason's answer in Java (note i < exp).
private static void testModulus() {
int bse = 5, exp = 55, mod = 221;
int a1 = bse % mod;
int p = 1;
System.out.println("1. " + (p % mod) + " * " + bse + " = " + (p % mod) * bse + " mod " + mod);
for (int i = 1; i < exp; i++) {
p *= a1;
System.out.println((i + 1) + ". " + (p % mod) + " * " + bse + " = " + ((p % mod) * bse) % mod + " mod " + mod);
p = (p % mod);
}
}
Just provide another implementation of Jason's answer by C.
After discussing with my classmates, based on Jason's explanation, I like the recursive version more if you don't care about the performance very much:
For example:
#include<stdio.h>
int mypow( int base, int pow, int mod ){
if( pow == 0 ) return 1;
if( pow % 2 == 0 ){
int tmp = mypow( base, pow >> 1, mod );
return tmp * tmp % mod;
}
else{
return base * mypow( base, pow - 1, mod ) % mod;
}
}
int main(){
printf("%d", mypow(5,55,221));
return 0;
}
This is called modular exponentiation(https://en.wikipedia.org/wiki/Modular_exponentiation).
Let's assume you have the following expression:
19 ^ 3 mod 7
Instead of powering 19 directly you can do the following:
(((19 mod 7) * 19) mod 7) * 19) mod 7
But this can take also a long time due to a lot of sequential multipliations and so you can multiply on squared values:
x mod N -> x ^ 2 mod N -> x ^ 4 mod -> ... x ^ 2 |log y| mod N
Modular exponentiation algorithm makes assumptions that:
x ^ y == (x ^ |y/2|) ^ 2 if y is even
x ^ y == x * ((x ^ |y/2|) ^ 2) if y is odd
And so recursive modular exponentiation algorithm will look like this in java:
/**
* Modular exponentiation algorithm
* #param x Assumption: x >= 0
* #param y Assumption: y >= 0
* #param N Assumption: N > 0
* #return x ^ y mod N
*/
public static long modExp(long x, long y, long N) {
if(y == 0)
return 1 % N;
long z = modExp(x, Math.abs(y/2), N);
if(y % 2 == 0)
return (long) ((Math.pow(z, 2)) % N);
return (long) ((x * Math.pow(z, 2)) % N);
}
Special thanks to #chux for found mistake with incorrect return value in case of y and 0 comparison.