The question asks us to solve for x in the given equation c' = x^e mod N, given the fact that we already know c', e , mod N. I looked into my tutorial, bu they only gave us a way to get e, but not for x.
I have manually tried to solve it and got the equation:
log c' = e log x mod N
but I don't know how to put in in Sage Math.
This is from the tutorial to find e:
discrete_log (c',Mod(x,N))
The question is really asking how to find an e-th root of c' modulo N.
Say for example one wants to solve 12 = x^99 modulo 347.
This amounts to finding a 99-th root of 12 modulo 347.
Just set up the ring of integers modulo 347,
sage: A = Zmod(347)
sage: A
Ring of integers modulo 347
give a name to the element 12 in that ring,
sage: a = A(12)
and ask Sage for a 99-th root of this element:
sage: a.nth_root(99)
241
Check that this answers the question:
sage: A(241)^99
12
sage: pow(241, 99, 347)
12
sage: power_mod(241, 99, 347)
12
Samuel's answer is far more comprehensive than this, but if you are looking for a really quick fix, you could use this (naive) function for small moduli:
sage: solve_mod(x^99==12, 347)
[(241,)]
Related
I am just learning number theory .When I was reading modular arithmetic I came across this statement :
29 is congruent to 15 (mod 7).
So actually this statement actually shows just
29 is congruent to 15
and we are working under mod 7..mod 7 in brackets is just to show the modulus. It is not 29 is congruent to 15%7.It is 29 is congruent to 15 and we are working under modulus 7.
Your observation is correct. The word mod is actually used in two different senses: one of them is to clarify a relation as you describe
A = B (mod C)
means, e.g., that B-A is divisible by C. Or sometimes (but equivalently in the end), it means that you should be reading A and B as being notation, e.g., for elements of the algebraic structure integers modulo C rather than as notation for integers.
The other usage is as a binary operator: B mod C means the remainder when B is divided by C.
Usually it's straightforward to tell the difference from context... assuming you are actually aware of both possible usages. Also, in the first kind of usage, mod is usually set off from the others; e.g.
A = B mod C
is the first usage as a relation, but
A = B mod C
could go either way.
I want to ask Maple, for example, for which j the following is true:
10^j mod 543 = 82
How can I ask Maple this?
Also, is there a way to solve for j without a computer?
This is called the The Discrete Logarithm Problem. It is a difficult problem---computationally intensive. See the Wikipedia page. It has discussion of eight algorithms for the problem. The Maple command is numtheory:-mlog.
numtheory:-mlog(82, 10, 543);
Maple responds
12
To obtain all such integers j, use the extended form of the command:
numtheory:-mlog(82, 10, 543, 'c');
Maple again responds with 12, and c is set to 180, meaning that j = 12 + 180*k is a solution for any nonnegative integer k.
(X^2)(1,2)
X is a square matrix, I just want to get the element from position (1,2) from (X^2) why it does not work?
Indexing is syntactically not allowed in this case. The simplest workaround is to use getfield
X=magic(5)
X =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> getfield(X^2,{1,3})
ans =
725
That's not how Matlab works. You need to assign the result of the matrix multiplication to another matrix, then use it:
A = X^2;
disp(A(1,2));
This is assuming that you really did mean to do matrix multiplication, and not multiply element by element. In the latter case you could have done
disp(X(1,2)^2)
And if you are interested in matrix multiplied result, then
disp(X(1,:)*X(:,2))
will do it, since that is how element (1,2) is calculated. This last solution has the advantage of being very efficient since you only calculate the element you need, instead of computing the entire matrix and throwing N^2-1 elements away just to keep the one. For bigger matrices that will make a difference. Of course it makes the code slightly less readable so I would always recommend writing a comment in your code when you do that - your future self will thank you...
edit take a look at http://www.mathworks.com/matlabcentral/newsreader/view_thread/235798 - that thread broadly agrees with my first statement, although it hints that the syntax you desire might be "part of a future release". But that was said 6 years ago, and it's still not here... It also shows some pretty obscure workarounds; I recommend not going that route (because all the workarounds do is hide the fact that you compute the matrix, then pick just one element. So the workload on the computer is no smaller.)
I use Sequence Regression Trees to examine differences in career trajectories. Both in the plot as well as in the printed description of the tree, there are abbreviations that are not explained neither in the TraMineR help menu nor in Matthias Studer's paper on Sequence Regression Trees/Weighted Clusters.
Can you please let me know what the following abbreviations in the example below mean (d-plot on hierarchical advancement of 377 participants over 15 years (30 periods of 6 months each)? Thank you very much!
PRINTED OUTPUT
Dissimilarity tree:
Parameters: minSize=18.85, maxdepth=3, R=5000, pval=0.01
Formula: matOM ~ Age + Degree + Gender + YearsSinceGrad
Global R2: 0.011589
Fitted tree:
|-- Root (n: 377 disc: 0.55559)
|-> Age 0.011589
|-- <= 48 with NA (n: 260 disc: 0.53812)[(1,20)-(2,8)-(3,2)] *
|-- > 48 (n: 117 disc: 0.57369)[(1,14)-(2,12)-(3,4)] *
Question 1: disc = ? (--> Equals s2 in the plot, see below)
Question 2: [(1,20)-(2,8)-(3,2)] * = ? (Is this the most typical sequence?)
PLOTTED OUTPUT
Question 3: s2 = ? (Equals "disc" in printed output above)
Thank you for your remarks!
Question 1: Yes, 'disc' = 's2' in the plot (I have to fix this). This means "discrepancy". A high discrepancy means that there are a lot of variations accross the sequences. The range of the discrepancy is [0, maximum possible distance] and there is thus no threashold values. But you can compare some values.
The Levene test (which seems to be non-significant in your case, see the image) test the significativity of the difference in discrepancies. This test can be run with the dissassoc function. In the tree, the Levene test the equality of discrepancy in the terminal nodes (again, here differencies seems non significant).
Question 2: In the printed output, the sequence in square brackets [] is the centroid. This is the most central sequence of the subgroup.
Question 3: see answer to question 1.
Hope this helps.
I am New in Maple and have heard that, this maths software is powerful in symbolic calculation. S assume that we have a set of elements like
A:={a, aab, b, aba, abbb, abab...}
such that #A=20 and moreover, we know that some of these elements satisfy an equation, for example a^k=(ab)^2 for some positive integers k. I have written some loops including for and if and assuming A is a set of numbers, but I have exhausted. I see, I can’t arrange and link these functions together properly.
May I ask someone hint me, how maple can help me find the values of k for example in a finite range [1..10] satisfying the relation above?
I this you could do something like this:
restart:
A:={a,b,1000*a+111*b,101*b+1010*a,110*a+b};
A := {a, b, 110 a + b, 1000 a + 111 b, 101 b + 1010 a}
for i from 1 to 9 do
for j from 1 to 9 do
As:=subs(a=i,b=j,A);
for e in As do
for ee in As do
if((ee<>e) and (e<=ee^2)) then
for k from 1 to 10 while (e^k<ee^2) do
od;
if(e^k=ee^2) then
print(e,"^",k,"=",ee,"^2");
fi;
fi;
od;
od;
od;
od;
Just fill in the elements of your set and let it calculate. You could go slightly faster if you sort your set first (so you have A=[1,6,16,61]) and calculate all squared numbers. Then loop over the entries but only looking at those that are bigger (but that might not be what you are looking for)