Maple: simplifying Im(a+I*b) - why it does not work for me? - maple

So I want to simplify z:=a+I*b; Im(z) where a, b are real variables So I try:
s:= 1+2*I
Im(s) // outputs 2
z:=a+I*b
Im(z) // outputs Im(a+I*b)
So I wonder is it any how possible to simplify Im(z) so to get b as output (here we look at general case meaning z could be any complex expression from real values (like a, b, c etc and complex I))?

You didn't tell Maple that a and b were real, so the simplification doesn't work because it doesn't necessarily hold. One way to get what you want is by using the assume command to let it know:
> s:=1+2*I;
s := 1 + 2 I
> Im(s);
2
> z:=a+I*b;
z := a + b I
> Im(z);
Im(a + b I)
> assume(a,real);
> assume(b,real);
> z;
a~ + b~ I
> Im(z);
b~

The evalc command works by considering unknowns as being real.
z:=a+I*b:
Im(z);
Im(a + I b)
evalc( Im(z) );
b
See its help-page, ?evalc.

Related

need a Maple program

Write a Maple code in order to find all the at most three digits Pythagorean triples (a, b, c), for
a, b, c > 0. We say that an integer triple(a, b, c) is a Pythagorean triple if a^2+b^2=c^2.
Hint: You might need to use the command type(sqrt(x),integer) as it returns true if x is a complete square. Get help for type from the help center.
one possibility. You can try to make it more efficient if needed.
result:=Array(1..999);
n:=0;
for a from 1 to 999 do
for b from a to 999 do
c:=sqrt(a^2+b^2);
if type(c,integer) and length(c)<=3 then
n:=n+1;
result(n):=[a,b,c];
fi;
od;
od;
result:=result(1..n);
To print them
for item in result do
print(item[1]^`2`+item[2]^`2`=item[3]^`2`)
od
....
Consider this:
isolve(a^2+b^2=c^2);

apply multiple vector to function

I have a simple function which returns a table:
F[("A";"B");(1,-1)]
I would like to apply this function passing vectors as inputs:
a:((`A;`B);(`B;`C);(`C;`D))
b:((1;-1);(1;-1);(1;-1))
I have tried:
F each a,b
F each a cross b
but this doesn't work or combines the vectors rather than keeping the 2 components separate. In addition when I do get it to work how do I row bind the resulting list of tables? I am coming from a python background.
You need to use ' each-both :
q)F:{ ([] enlist x; enlist y)} /if F is simply creating a table
q)F[("A";"B");(1,-1)]
x y
---------
"AB" 1 -1
q)a:((`A;`B);(`B;`C);(`C;`D))
q)b:((1;-1);(1;-1);(1;-1))
q)F'[a;b] /each-both
+`x`y!(,`A`B;,1 -1)
+`x`y!(,`B`C;,1 -1)
+`x`y!(,`C`D;,1 -1)
raze will format it to a table (i think row binding means appending the tables together)
q)raze F'[a;b]
x y
--------
A B 1 -1
B C 1 -1
C D 1 -1

Scala: property based testing: how to know all necssary test cases when writing test

I'm reading about Property based testing using Scala language. In this slide, they present this concept: For proving function a+b is true. we just only to prove those statements are true on random data:
a + b = b + a
a + 0 = a
a + 1 + 1 = a + 2
My question is: Which methodologies for checking that our test cases are enough, and can cover all cases on different data. For example on previous example, how can we sure that after our three properties run correctly, we can sure that our implementation is right.
First of all, I assume, you have a typo in #3, it's supposed to be + rather than *.
To answer your question, you most certainly can not be sure that your implementation is right if you prove these three properties. Consider this implementation for instance, that satisfies all three properties, but is definitely wrong:
def wrongPlus(a: Int, b: Int) = if(a < 3 || b <3) b a+b else 0
To definitively prove the (integer) addition, you need to have an independent implementation of next integer. Then, by definition:
1. a + 0 = a
2. a + next(b) = next(a + b)
If these properties hold for any a and b and some operation +, then + is indeed the addition.

Multiple output under minizinc

Try to learn minizinc but after going through examples, may I just confirm that I actually have to write some procedural language if I want to get multiple output or there is a more "natural to minizinc" way to get it.
For example, suppose I want to have all distinct digits add up to 3 the answers should be 0+3 1+2 2+1 3+0 ...
My mininzinc here:
% how to generate more than one result meeting the constraints
int: n=3;
var 0..9: a;
var 0..9: b;
include "alldifferent.mzn";
constraint all_different([a, b]);
constraint a + b = n;
solve satisfy;
output [
"a + b = n \t\n",
show(a), " + ",
show(b), " = ",
show(n)];
produce only 3+0. How to get to the other answers? Thanks for any advice in advance.
I looked at a post for minizinc 1.6 and it seemed to say left out the output statement would produce all the output (Easy way to print full solution (all decision variables) in minizinc). It does not work. Only one is output.
First of all, the default is to print all variables and their values for a solution, not all solutions.
Use the option -a to get all solutions. mzn-gecode --help to see all options. In your case mzn-gecode -a test.mzn which gives:
a + b = n
3 + 0 = 3
----------
a + b = n
0 + 3 = 3
----------
a + b = n
2 + 1 = 3
----------
a + b = n
1 + 2 = 3
----------
==========
Under configuration there is an option to change the default from printing the first solution after satisfaction. Change it to user-defined-behaviour: print all solutions ... You can have output statement, btw, as well.

In maple how to select one solution manually?

After some complicated integration maple gives a list of solutions defined on different domains of variables. I need to select just one of them. Domains are so complicated that assuming is not helpful: maple runs out of memory trying to figure out how these assumptions correspond to domains he found. However, it is pretty obvious, which solution I need.
Is it possible in maple to extract somehow solution by its number or just drop undefined solutions making maple to forget about domain where it is defined?
P.S. It is hard to copy-paste this solution as it is pretty long.
UPD Minimal working example:
> sln := int(1/x, x=a..b,AllSolutions):
> value(sln) assuming a>0, b>0;
{ -ln(a) + ln(b) a < b
{
{ 0 b = a
{
{ -ln(a) + ln(b) b < a
In this patricular example adding assuming a<b would help, but I would like to get ln(b)-ln(a) directly.
Have a look at convert. It can take your piecewise system and transform it to an array.
> sln := int(1/x, x=a..b,AllSolutions):
> s:=value(sln) assuming a>0, b>0;
{ -ln(a) + ln(b) a < b
{
s := { 0 b = a
{
{ -ln(a) + ln(b) b < a
> conv:=convert(s,list);
conv := [a < b, -ln(a) + ln(b), b = a, 0, b < a, -ln(a) + ln(b)]
> conv[2];
-ln(a) + ln(b)
You can select your favorite part by giving the right (even) index into the array or by matching the odd ones for the part you want (and then select the corresponding even one).