Kitonum

21560 Reputation

26 Badges

17 years, 137 days

MaplePrimes Activity


These are replies submitted by Kitonum

@brian bovril   Thank you for your interest in my post!

My program differs from Dr. Khan's one in the following points:

1. In my program all the numbers from the declared list should be used.
2. My program returns all solutions.
3. My program has many options for its use.

When solving your example in the maximum version (all arithmetic operations, arbitrary order numbers and the use of parentheses) creates a very long list to iterate. This will require a lot of time or Maple may report insufficient memory, etc. See my comment above.

Here are two workarounds:

1. Reduce the number of permissible operations. If you remove the division, then Maple returns 712 solutions, among which will be your variant at number 633:

NumbersGame(863, [25, 75, 1, 8, 5, 10], ["+", "-", "*"], "arbitrary order", yes):  # All solutions

nops(M);  # Number of the all solutions

seq(M[1+70*(i-1)], i = 1 .. 10);  # For example, 10 solutions

M[633];  # Your solution

 

 

2.  Another way - first generate all permutations of the original list, and then solve separately for each permutation, using the parentheses and the all 4 arithmetic operations.  Obtain the same solutions. It follows that there are no solutions that use the division sign:

k:=0:

P := combinat[permute]([25, 75, 1, 8, 5, 10]):

for p in P do

NumbersGame(863, p, yes);

if M::list then k:=k+1; L[k] := op(M) end if;

end do:

L:=convert(L, list);

nops(L);

                              712

@Carl Love   Compare:

plot3d(x*y, x = y .. 1, y = 0 .. 1, axes = normal)  and  plot3d(x*y, x = 0 .. 1, y = 0 .. x, axes = normal)  are the same.

But  int(x*y, [x = y .. 1, y = 0 .. 1]);  and  int(x*y, [x = 0 .. 1, y = 0 .. x]);  are not the same. The second is incorrect syntax for calculating of an integral.

The implication is true only in one direction.

 

Good to know that this is a saddle-shaped surface like  z=x^2-y^2 :

plot3d(x*y, x=-1..1, y=abs(x)-1..1-abs(x), axes=normal, view=[-3/2..3/2,-3/2..3/2,-1/2..1/2]);

@Preben Alsholm   Vote up!  I believe that a combination of manual and programmatic approaches there is a better way to work, because it allows you to achieve the best results.

@itsme   Thank you! Of cause, you are right.

@amrramadaneg   If you specify a function of two variables  x  and  y , defining the displacements, then the same can be done in automatic mode:

P:=[[0, 1], [2, 1], [2, -1], [0, -1]]:

A:=plottools[polygon](P, style=line,thickness = 2, color=red, numpoints=5000):

u:=(x,y)->[x+0.03*y, y+0.03*x];

B:=plottools[polygon](map(t->u(op(t)),P), style=line, thickness = 2, color=blue, numpoints=5000):

plots[display](A,B); 

 

 

If we have  n  different numbers passing in a certain order, the number of different ways  of parentheses setting  is equal to  C[n-1]=binomial(2*n-2, n-1)/n  (C[n] is nth Catalan number). Using this formula, we can easily calculate the number of of different variants in the exhaustive search of all variants. For example, if  n = 6 , using all four operations, the order of numbers is  arbitrary  and parentheses are used, the number of variants is

6!*4^5*eval(binomial(2*n-2, n-1)/n, n=6); 

                               30965760

Therefore, in such cases it is not recommended to take  n>6 , otherwise the time of calculation can be unacceptably large.

Consider a few more examples of the application  NumbersGame  procedure.

 

Example 4.  The problem: Is it possible to place between 14 numbers 1 .. 14  signs  "+"  and  "-"  so that the result is 0?

NumbersGame(0, [$ 1..14], ["+","-"]);

                          No solutions

 

Example 5.  The problem: What is the smallest number  n  such that placing between numbers  1..n  arithmetic operators we obtain the known mystical number 666 ?

for n from 6 do

NumbersGame(666, [$ 1..n]):

if nops(M)>0 then break fi;

od:

%;

 1 + 2 * 3 * 4 * 5 * 6 - 7 * 8 - 9 + 10 = 666,   1 + 2 * 3 * 4 * 5 * 6 + 7 - 8 * 9 + 10  =  666

 

Example 6. The problem: How smallest number of digits can write this number  666  using arithmetic operations and parentheses ?

for n from 3 do

T:=combinat[cartprod]([[$ 1..9] $ n]): 

while not T[finished] do

m:=T[nextvalue](): NumbersGame(666, m,  yes):

if nops(M)>0 then break  fi:

od:

if nops(M)>0 then break fi: 

od:

op(M);

        ( 2 + ( 8 * 9 ) ) * 9   =  666

 

 

 

 

@Markiyan Hirnyk  My code is correct, because there is not verified  a prime number  p  itself, but the next prime number is checked. Of course, you can write the equivalent code:

restart;

p:=41: n:=0:

while p<=107 do

sol:=msolve(y^2 + y - 11=0, p);

if  sol<>NULL then  n:=n+1; L[n]:=[p, sol]  fi;

p:=nextprime(p);

od:

L:=convert(L, list):

op(L);

@Vesnog   Read help to  name .

@Preben Alsholm  This system can be easily solved numerically, for example for  h1=0, h2=1.

restart;

Eq2 := diff(T(y), y, y)+(diff(sigma(y), y))*(diff(T(y), y))+(diff(T(y), y))^2+(exp(-y)+exp(y))^2 = 0;

Eq3 := diff(sigma(y), y, y)+diff(T(y), y, y) = 0;

bcs2 := T(0) = 0, T(1) = 1, sigma(0) = 0, sigma(1) = 1;

sol := dsolve({Eq2, Eq3, bcs2}, numeric);

plots[odeplot](sol, [[y, T(y)], [y, sigma(y)]], y = 0 .. 1, color = [red, blue]);

 

But if these values  h1  and  h2  are substituted into your explicit formulas, an error occurs "division by zero"

 

@Carl Love   Very ingenious way! Vote up.

@H-R   Read help to these commands. Everything is explained in detail.

@Dmitry Lyakhov

Examples:

A0:=(x,y)->x^3+y^2+1;  # or

A1:=unapply(x^3+y^2+1, x,y);

A0(2,3), A1(2,3);  

 

 

@Dmitry Lyakhov  If you speak in Russian, you can ask your questions here

@Markiyan Hirnyk  Only one inequality is allowed to multiply by a number. Should be

map(x->-3*x, `and`((1/3)*x-1 > 1, (1/3)*x-1 < 5));

                             -x < -6 and -18 < -x

@Markiyan Hirnyk  You are wrong. Just noticed that substitutions the inequality signs is not required. Maple does this automatically.

Example:

(-3)*(x < 2);

         -6 < -3*x

 

First 101 102 103 104 105 106 107 Last Page 103 of 133