Featured Posts

Hi
Two new things recently added to the latest version of Physics available on Maplesoft's R&D Physics webpage are worth mentioning outside the framework of Physics.

  • automaticsimplification. This means that after "Physics:-Setup(automaticsimplification=true)", the output corresponding to every single input (literally) gets automatically simplified in size before being returned to the screen. This is fantastically convenient for interactive work in most situations.

  • Add Physics:-Library:-Assume, to perform the same operations one typically performs with the  assume command, but without the side effect that the variables get redefined. So the variables do not get redefined, they only receive assumptions.

This new Assume implements the concept of an "extended assuming". It permits re-using expressions involving the variables being assumed, expressions that were entered before the assumptions were placed, as well as reusing all the expressions computed while the variables had assumptions, even after removing the variable's assumptions. None of this is possible when placing assumptions using the standard assume. The new routine also permits placing assumptions on global variables that have special meaning, that cannot be redefined, e.g. the cartesian, cylindrical or spherical coordinates sets, or the coordinates of a coordinate spacetime system within the Physics package, etc.

Examples:

 

with(Physics):

This is Physics from today:

Physics:-Version()[2]

`2014, December 9, 16:51 hours`

(1.1)
• 

Automatic simplification is here. At this point automaticsimplification is OFF by default.

Setup(automaticsimplification)

[automaticsimplification = false]

(1.2)

Hence, for instance, if you input the following expression, the computer just echoes your input:

Physics:-`*`(a, c)+Physics:-`*`(a, d)+Physics:-`*`(b, c)+Physics:-`*`(b, d)

a*c+a*d+b*c+b*d

(1.3)

There is however some structure behind (1.3) and, in most situations, it is convenient to have these structures
apparent, in part because they frequently provide hints on how to proceed ahead, but also because a more
compact expression is, roughly speaking, simpler to understand. To see this
automaticsimplification in action,
turn it ON:

Setup(automaticsimplification = true)

[automaticsimplification = true]

(1.4)

Recall this same expression (you could input it with the equation label (1.3) as well) 

Physics:-`*`(a, c)+Physics:-`*`(a, d)+Physics:-`*`(b, c)+Physics:-`*`(b, d)

(c+d)*(a+b)

(1.5)

What happened: this output, as everything else after you set automaticsimplification = true and with no
exceptions, is now further processed with simplify/size before being returned. And enjoy computing with frankly
shorter expressions all around! And no need anymore for "simplify(%, size)" every three or four input lines.

Another  example, typical in computer algebra where expressions become uncomfortably large and difficult to
read: convert the following input to 2D math input mode first, in order to compare what is being entered with the
automatically simplified output on the screen

-Physics:-`*`(Physics:-`*`(Physics:-`*`(3, sin(x)^(1/2)), cos(x)^2), sin(x)^m)+Physics:-`*`(Physics:-`*`(Physics:-`*`(3, sin(x)^(1/2)), cos(x)^2), cos(x)^n)+Physics:-`*`(Physics:-`*`(Physics:-`*`(4, sin(x)^(1/2)), cos(x)^4), sin(x)^m)-Physics:-`*`(Physics:-`*`(Physics:-`*`(4, sin(x)^(1/2)), cos(x)^4), cos(x)^n)

-4*(cos(x)^n-sin(x)^m)*sin(x)^(1/2)*cos(x)^2*(cos(x)^2-3/4)

(1.6)

You can turn automaticsimplification OFF the same way

Setup(automaticsimplification = false)

[automaticsimplification = false]

(1.7)
• 

New Library:-Assume facility; welcome to the world of "extended assuming" :)

 

Consider a generic variable, x. Nothing is known about it

about(x)

x:

  nothing known about this object

 

Each variable has associated a number that depends on the session, and the computer (internally) uses this
number to refer to the variable.

addressof(x)

18446744078082181054

(1.8)

When using the assume  command to place assumptions on a variable, this number, associated to it, changes,
for example:

assume(0 < x and x < Physics:-`*`(Pi, 1/2))

addressof(x)

18446744078179060574

(1.9)

Indeed, the variable x got redefined and renamed, it is not anymore the variable x referenced in (1.8).

about(x)

Originally x, renamed x~:

  is assumed to be: RealRange(Open(0),Open(1/2*Pi))

 


The semantics may seem confusing but that is what happened, you enter x and the computer thinks x~, not x 
anymore.This means two things:

1) all the equations/expressions, entered before placing the assumptions on x using assume, involve a variable x 
that is different than the one that exists after placing the assumptions, and so these previous expressions
cannot
be reused
. They involve a different variable.

2) Also, because, after placing the assumptions using assume, x refers to a different object, programs that depend
on the
x that existed before placing the assumptions will not recognize the new x redefined by assume .

 

For example, if x was part of a coordinate system and the spacetime metric g[mu, nu]depends on it, the new variable x
redefined within assume, being a different symbol, will not be recognized as part of the dependency of "g[mu,nu]." This
posed constant obstacles to working with curved spacetimes that depend on parameters or on coordinates that
have a restricted range. These problems are resolved entirely with this new
Library:-Assume, because it does not
redefine the variables. It only places assumptions on them, and in this sense it works like
assuming , not assume .
As another example, all the
Physics:-Vectors commands look for the cartesian, cylindrical or spherical coordinates
sets
[x, y, z], [rho, phi, z], [r, theta, phi] in order to determine how to proceed, but these variables disappear if you use
assume to place assumptions on them. For that reason, only assuming  was fully compatible with Physics, not assume.

 

To undo assumptions placed using the assume command one reassigns the variable x to itself:

x := 'x'

x

(1.10)

Check the numerical address: it is again equal to (1.8) 

addressof(x)

18446744078082181054

(1.11)

·All these issues get resolved with the new Library:-Assume, that uses all the implementation of the existing 
assume command but with a different approach: the variables being assumed do not get redefined, and hence:
a) you can reuse expressions/equations entered before placing the assumptions, you can also undo the
assumptions and reuse results obtained with assumptions. This is the concept of an
extended assuming. Also,
commands that depend on these assumed variables will all continue to work normally, before, during or after
placing the assumption, because
the variables do not get redefined.

Example:

about(x)

x:

  nothing known about this object

 

So this simplification attempt accomplishes nothing

simplify(arccos(cos(x)))

arccos(cos(x))

(1.12)

Let's assume now that 0 < x and x < (1/2)*Pi

Library:-Assume(0 < x and x < Physics:-`*`(Pi, 1/2))

{x::(RealRange(Open(0), Open((1/2)*Pi)))}

(1.13)

The new command echoes the internal format representing the assumption placed.

a) The address is still the same as (1.8)

addressof(x)

18446744078082181054

(1.14)

So the variable did not get redefined. The system however knows about the assumption - all the machinery of the
assume command is being used

about(x)

Originally x, renamed x:

  is assumed to be: RealRange(Open(0),Open(1/2*Pi))

 


Note that the renaming is to the variable itself - i.e. no renaming.

Hence, expressions entered before placing assumptions can be reused. For example, for (1.12), we now have

simplify(arccos(cos(x)))

x

(1.15)

To clear the assumptions on x, you can use either of Library:-Assume(x=x) or Library:-Assume(clear = {x, ...}) in
the case of many variables being cleared in one go, or in the case of a single variable being cleared:

Library:-Assume(clear = x)

about(x)

x:

  nothing known about this object

 


The implementation includes the additionally functionality, for that purpose add the keyword
additionally 
anywhere in the calling sequence. For example:

Library:-Assume(x::positive)

{x::(RealRange(Open(0), infinity))}

(1.16)

about(x)

Originally x, renamed x:

  is assumed to be: RealRange(Open(0),infinity)

 

Library:-Assume(additionally, x < 1)

{x::(RealRange(Open(0), Open(1)))}

(1.17)

Library:-Assume(x = x)

In summary, the new Library:-Assume command implements the concept of an extended assuming, that can be
turned ON and OFF at will at any moment without changing the variables involved.


Download AutomaticSimplificationAndAssume.mw

 

Edgardo S. Cheb-Terrab
Physics, Differential Equations and Mathematical Functions, Maplesoft

The procedure  NumbersGame  generalizes the well-known 24 game  (implementation in Maple see here), as well as related issues (see here and here).

 

Required parameters of the procedure:

Result is an integer or a fraction of any sign.

Numbers is a list of positive integers.

 

Optional parameters:

Operators is a list of permitted arithmetic operations. By default  Operators is  ["+","-","*","/"]

NumbersOrder is a string. It is equal to "strict order" or "arbitrary order" . By default  NumbersOrder is "strict order"

Parentheses is a symbol  no  or  yes . By default  Parentheses is  no 

 

The procedure puts the signs of operations from the list  Operators  between the numbers from  Numbers  so that the result is equal to Result. The procedure finds all possible solutions. The global  M  saves the list of the all solutions.

 

Code the procedure:

restart;

NumbersGame:=proc(Result::{integer,fraction}, Numbers::list(posint), Operators::list:=["+","-","*","/"], NumbersOrder::string:="strict order", Parentheses::symbol:=no)

local MyHandler, It, K, i, P, S, n, s, L, c;

global M;

uses StringTools, ListTools, combinat; 

 MyHandler := proc(operator,operands,default_value)

      NumericStatus( division_by_zero = false );

      return infinity;

   end proc;

   NumericEventHandler(division_by_zero=MyHandler); 

if Parentheses=yes then 

It:=proc(L1,L2)

local i, j, L;

for i in L1 do

for j in L2 do

L[i,j]:=seq(Substitute(Substitute(Substitute("( i Op j )","i",convert(i,string)),"j",convert(j,string)),"Op",Operators[k]), k=1..nops(Operators));

od; od;

L:=convert(L, list);

end proc; 

P:=proc(L::list)

local n, K, i, M1, M2, S;

n:=nops(L);

if n=1 then return L else

for i to n-1 do

M1:=P(L[1..i]); M2:=P(L[i+1..n]);

K[i]:=seq(seq(It(M1[j], M2[k]), k=1..nops(M2)), j=1..nops(M1))

od; fi;

K:=convert(K,list);

end proc;

if NumbersOrder="arbitrary order" then S:=permute(Numbers); K:=[seq(op(Flatten([op(P(s))])), s=S)] else  K:=[op(Flatten([op(P(Numbers))]))] fi; 

else 

if NumbersOrder="strict order" then

K:=[convert(Numbers[1],string)];

for i in Numbers[2..-1] do

K:=[seq(seq(cat(k, Substitute(Substitute(" j i","j",convert(j,string)),"i",convert(i,string))), k in K), j in Operators)]

od;   else 

S:=permute(Numbers);

for s in S do

L:=[convert(s[1],string)];

for i in s[2..-1] do

L:=[seq(seq(cat(k, Substitute(Substitute(" j i","j",convert(j,string)),"i",convert(i,string))), k in L), j in Operators)]

od; K[s]:=op(L) od; K:=convert(K,list) fi;  

fi; 

M:='M'; c:=0;

for i in K do

if parse(i)=Result then c:=c+1; if Parentheses=yes then M[i]:= convert(SubString(i,2..length(i)-1),symbol)=convert(Result,symbol) else M[i]:=convert(i,symbol)=convert(Result,symbol) fi; fi;

od; 

if c=0 then M:=[]; return `No solutions` else M:=convert(M,list);  op(M) fi; 

end proc:

 

Examples of use.

 

Example 1:

NumbersGame(1/20, [$ 1..9]);

     1 * 2 - 3 + 4 / 5 / 6 * 7 / 8 * 9 = 1/20

 

Example 2. Numbers in the list  Numbers  may be repeated and permitted operations can be reduced:

NumbersGame(15, [3,3,5,5,5], ["+","-"]);

         3 - 3 + 5 + 5 + 5 = 15

 

Example 3. 

NumbersGame(10, [1,2,3,4,5]);

         1 + 2 + 3 * 4 - 5 = 10

If the order of the number in Numbers is arbitrary, then the number of solutions is greatly increased (10 solutions displayed):

NumbersGame(10, [1,2,3,4,5], "arbitrary order"):

nops(M);

for i to 10 do

M[1+50*(i-1)] od;

If you use the parentheses, the number of solutions will increase significantly more (10 solutions displayed):

NumbersGame(10, [1,2,3,4,5], "arbitrary order", yes):

nops(M);

for i to 10 do

M[1+600*(i-1)] od;

Game.mws

 

 

 


MaplePrimes Questions Recent Unanswered Maple MapleSim Maple T.A.