Question about using Maple's arrow (->) notation - complex-numbers

Hi can someone show me how to do this:
Your function should take a Maple list of complex numbers as its input and return the largest modulus from that list.

Hint: Use the map command to apply the abs command to some such list. Then apply the max command to that. Now repeat, by composing that second operation around the first. Finally, create an operator which takes L to that composed operation applied to L.
Look to the help-pages ?max, ?map, ?abs, and ?operators,functional, if necessary.

Related

how to get the longest string in an array in Openrefine

With GREL is it possible to get the longest string of an array ?
For example, if I have an array with 3 strings ["a","aaa","aa"], I want to obtain "aaa".
You can probably do that at the cost of a very complicated formula. It's typically to face this kind of case that Open Refine added Python (and Clojure) as scripting languages. Even if you don't know Python, you can find in two minutes the answer to the question "how to choose the longest string in list?" and simply copy and paste it (by adding a "return" instead of "print")
In this case :
return max(['a','aaa','aaaa','aa'], key=len)
EDIT
Just for the sake of the challenge, here is a possible solution with GREL.
value = "a,aa,aaaa,aa"
forEach(value.split(','), e, if(length(e)==sort(forEach(value.split(','), e, e.length()))[-1], e, null)).join(',').split(',')

Expand an expression in Maple contening modulus

I want to develop an expression such as |a+b+c|^2 . I tried the command " expand " but it does not work. ( it works without the modulus )
The issue is that expand is unable to recognize whether a, b and c are positive or negative. So, you make that clear then expand will work the way it should.
restart:
A:=abs(a+b+c)^2;
assume(a>0,b>0,c>0):expand(A);
a^2+2*a*b+2*a*c+b^2+2*b*c+c^2
if
assume(a>0,b>0,c<0):
then use
expand(simplify(A))
Now, lets take three complex numbers and then take its modulus square,
B:=abs((a1+b1*I)+(a2+b2*I)+(a3+b3*I))^2;
Once again the same issue as above.
assume(a1>0,b1<0,a2>0,b2<0,a3<0,b3>0):expand(simplify(B));
a1^2+2*a1*a2+2*a1*a3+a2^2+2*a2*a3+a3^2+b1^2+2*b1*b2+2*b1*b3+b2^2+2*b2*b3+b3^2
Finally, assign some random values for a's and b's and find modulus,
subs(a1=1,a2=1,a3=1,b1=1,b2=2,b3=3,B);

How to get Elemwise{tanh,no_inplace}.0 value

I am using Deep learning Theano. How can I see the content of a variable like this: Elemwise{tanh,no_inplace}.0. It is the input data of logistic layer.
Suppose your variable is called t. Then you can evaluate it by calling t.eval(). This may fail if input data are needed. In that case you need to supply them by providing a dictionary like this t.eval({input_var1: value1, input_var2: value2}). This is the ad-hoc way of evaluating a theano-expression.
The way it works in real programs is to create a function taking the necessary input, for example: f = theano.function([input_var1, input_var2], t), will yield a function that takes two input variables, calculates t from them and outputs the result.
Right now, you don't seem to print values but operations. The output Elemwise{tanh,no_inplace}.0 means, that you have an element wise operation of tanh, that is not done in place. You still need to create a function that takes input and executes your operation. Then you need to call that function and print the result. You can read more about that in the graph-structure part of their tutorial.

optimised minimum value using findall/3

I am trying to optimise and find the minimum Cost of a function. The program below uses findall/3 to iterate over all possible options of values which are generated from using the clpfd library provided by SWI-Prolog.
There are several Cost values that are generated using this program below which are gathered into a list. I know that in order to get the minimum value I can simply use the min_list/2 predicate available. However, what I want is that once the program finds a certain value, which is currently the minimum, while computing other options, if the value turns out to be greater than the minimum value, its not added the list.
So essentially, I want to optimise the program so that it simply accounts for the minimum value generated by the program.
optimise(input, arguments, Cost):-
findall(Cost, some_predicate(input, arguments, Cost), List).
some_predicate(input, arguments, Cost):-
Option in input..arguments, label(Option),
find_data(Option, Value),
find_cost(Value, Cost).
The above code has been modified so that it is condensed and but fulfils the purpose of the question.
I think that findall it's not the right tool: here is some code I wrote time ago, that could help you. For instance, given
member_(X,Y) :- member(Y,X).
we can get the lower element
?- integrate(min, member_([1,2,4,-3]), M).
M = -3
I applied the usual convention to postfix with underscore a library predicate that swaps arguments, to be able to meta call it.
Just take that code as an example, paying attention to nb_setarg usage.
To see if it could work 'out-of-the-box', try:
:- [lag].
optimise(Input, Arguments, Cost):-
integrate(min, some_predicate(Input, Arguments), Cost).

What does "in-place" mean?

Reverse words in a string (words are
separated by one or more spaces). Now
do it in-place.
What does in-place mean?
In-place means that you should update the original string rather than creating a new one.
Depending on the language/framework that you're using this could be impossible. (For example, strings are immutable in .NET and Java, so it would be impossible to perform an in-place update of a string without resorting to some evil hacks.)
In-place algorithms can only use O(1) extra space, essentially. Array reversal (essentially what the interview question boils down to) is a classic example. The following is taken from Wikipedia:
Suppose we want to reverse an array of n items. One simple way to do this is:
function reverse(a[0..n])
allocate b[0..n]
for i from 0 to n
b[n - i] = a[i]
return b
Unfortunately, this requires O(n) extra space to create the array b, and allocation is often a slow operation. If we no longer need a, we can instead overwrite it with its own reversal using this in-place algorithm:
function reverse-in-place(a[0..n])
for i from 0 to floor(n/2)
swap(a[i], a[n-i])
Sometimes doing something in-place is VERY HARD. A classic example is general non-square matrix transposition.
See also
In-place algorithm
In-place matrix transposition
You should change the content of the original string to the reverse without using a temporary storage variable to hold the string.