Need a Maple program, - maple

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)

Related

How can I improve my BF factorial code to input large numbers and output the whole result?

I recently began again to do some BF for fun, and today I made a factorial code, which as I know is different than a lot I found in the net. I only need five cells to compute it but unfortunately I can't input number such as for example 100.
I'd like to know, if someone has an idea, how could I do to improve my code to be able to do that?
EDIT : A, B, C, D and E are the cells
++++ #For example we put four in input
[->+<] #Put A in B and A=0
[-] #If A=0 (which is true)
>- #Decrease B by one
[->+>+>+<<<] #Put B in C, D and E (at the end pointer is on B)
> #Move on C
[-<+>] #Put C in B and C=0
<+ #Add one in B
>>[-<<<+>>>] #Put D in A and D=0
> #Pointer move on E
[ #While
- #E is not null
<<<<
[->[->+>+<<]>[-<+>]<<]>[-]>>[-<<+>>] #Do A*B and put the result in B
>
[-<+<<<+>>>>] #Put E in A and D
<
[->+<] #Then put D in E
> #pointer goes on E to test the while condition
] #While end
<<< #If E is null go back to cell B
[-<+>] #Put B in A
< #Pointer on A at the end
Thank you in advance for your answers !
If you need help to visualise the code step by step go there
The best interpreter I use is this one, you can perform BF on 32 bits and count numbers of operations. It needs more than two thousands of billion to make factorial of 19... but it is really fast.
well you would need to implement some sort of bigint functionality. How to do so will not fit in an answer here (read: i don't know), considering that the only unbounded data structure that's easy to implement in bf is a single stack placed after any other cells you might want to use.
You could implement, for example, 16 bit operations in terms of multiple 8 bit operations (likewise 32 bit in terms of 16 and so on) but factorials grow really really fast and not even a 64 bit value can hold 100! (which is 3.1e158, which means you would need at least 529 bits to represent)
Good luck implementing bigints in BF

Modular arithmetic Basic cofusion

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.

Maximum Subarray variation

I have to solve a problem much like the maximum subarray problem. I have to find the largest subarray whose average is bigger than k. I thought the following trick. I can transform my array A[] of size n to a B[] where B[i] = A[i] - k. So now the average must be >0. But average greater than zero doesnt simply mean sum greater than zero? So I can directly apply Kadane's algorithm. Am I right? (always under the constraint that there is 1 positive value)
no, kadane's algorithm will still find you the subarray with the biggest sum...i have to solve the same problem. so far i kave find that if we create the array B as you mentioned above and then make the array C which contains the partial sums of the array B,then the maximum interval (i,j) that we are lookink for has the same number for i and j!!! for example:
array A is: 1 10 -1 -1 4 -1 7 2 8 1 .....and the given k is 5 then
array B is: -4 5 -6 -6 -1 -6 2 -3 3 -4
array C is:-4 1 -5 -11 -12 -18 -16 -19 -16 -20
so the subarray that we are looking for is [7,2,8], has length 3, and has the same first and last element which is -16!!!!
edit: i forgot to tell that we are searching for a O(n) or an O(n*logn) algorithm.... #lets_solve_it you are right but your algorithm is O(n^2) whitch is way to big for the data we want to handle. i 'm close to solve it with the function map in c++,whitch is something like a hash table. i thing this is the right diredtion because here the elements of the array C have direct relation with their indexes! Also our professor told us that another possible solution ,is to make again the array C and then take a (special?) pivot to do quicksort....but i don't totally understand what we expect from quicksort to do.
#panos7:
after you have created array C (partial sums array), you seek two values of C, Ci and Cj,
such that, Cj>=Ci, and, (j-i) is as "big" as possible. (j-i) --> MAX.
then return j-i.
in your example, -16>=-18 so you returned j-i=9-6=3
which is the correct answer!

How to generate all possible combinations n-bit strings?

Given a positive integer n, I want to generate all possible n bit combinations in matlab.
For ex : If n=3, then answer should be
000
001
010
011
100
101
110
111
How do I do it ?
I want to actually store them in matrix. I tried
for n=1:2^4
r(n)=dec2bin(n,5);
end;
but that gave error "In an assignment A(:) = B, the number of elements in A and B must be the same.
Just loop over all integers in [0,2^n), and print the number as binary. If you always want to have n digits (e.g. insert leading zeros), this would look like:
for ii=0:2^n-1,
fprintf('%0*s\n', n, dec2bin(ii));
end
Edit: there are a number of ways to put the results in a matrix. The easiest is to use
x = dec2bin(0:2^n-1);
which will produce an n-by-2^n matrix of type char. Each row is one of the bit strings.
If you really want to store strings in each row, you can do this:
x = cell(1, 2^n);
for ii=0:2^n-1,
x{ii} = dec2bin(ii);
end
However, if you're looking for efficient processing, you should remember that integers are already stored in memory in binary! So, the vector:
x = 0 : 2^n-1;
Contains the binary patterns in the most memory efficient and CPU efficient way possible. The only trade-off is that you will not be able to represent patterns with more than 32 of 64 bits using this compact representation.
This is a one-line answer to the question which gives you a double array of all 2^n bit combinations:
bitCombs = dec2bin(0:2^n-1) - '0'
So many ways to do this permutation. If you are looking to implement with an array counter: set an array of counters going from 0 to 1 for each of the three positions (2^0,2^1,2^2). Let the starting number be 000 (stored in an array). Use the counter and increment its 1st place (2^0). The number will be 001. Reset the counter at position (2^0) and increase counter at 2^1 and go on a loop till you complete all the counters.

Understanding colon notation in MATLAB

So I'm completely new to MATLAB and I'm trying to understand colon notation within mathematical operations. So, in this book I found this statement:
w(1:5)=j(1:5) + k(1:5);
I do not understand what it really does. I know that w(1:5) is pretty much iterating through the w array from index 1 through 5, but in the statement above, shouldn't all indexes of w be equal to j(5) + k(5) in the end? Or am I completely wrong on how this works? It'd be awesome if someone posted the equivalent in Java to that up there. Thanks in advance :-)
I am pretty sure this means
"The first 5 elements of w shall be the first 5 elements of j + the first 5 elements of k" (I am not sure if matlab arrays start with 0 or 1 though)
So:
w1 = j1+k1
w2 = j2+k2
w3 = j3+k3
w4 = j4+k4
w5 = j5+k5
Think "Vector addition" here.
w(1:5)=j(1:5) + k(1:5);
is the same that:
for i=1:5
w(i)=j(i)+k(i);
end
MATLAB uses vectors and matrices, and is heavily optimized to handle operations on them efficiently.
The expression w(1:5) means a vector consisting of the first 5 elements of w; the expression you posted adds two 5 element vectors (the first 5 elements of j and k) and assigns the result to the first five elements of w.
I think your problem comes from the way how do you call this statement. It is not an iteration, but rather simple assignment. Now we only need to understand what was assigned to what.
I will assume j,k, w are all vectors 1 by N.
j(1:5) - means elements from 1 to 5 of the vector j
j(1:5) + k(1:5) - will result in elementwise sum of both operands
w(1:5) = ... - will assign the result again elementwise to w
Writing your code using colon notation makes it less verbose and more efficient. So it is highly recommended to do so. Also, colon notation is the basic and very powerful feature of MATLAB. Make sure you understand it well, before you move on. MATLAB is very well documented so you can read on this topic here.