Igor Proskurin

80 Reputation

2 Badges

1 years, 4 days

MaplePrimes Activity


These are answers submitted by

According to  Maple Programming Guide, Sec. 6.2 Defining and Executing Procedures, the procedures in Maple are declared using the following syntax (6 Procedures - Maple Help (maplesoft.com)): 

proc( parameterDeclarations ) :: returnType;

     description shortDescription;

     option optionSequence;

     local localVariableDeclarations;

     global globalVariableDeclarations;

     statementSequence

end proc

 

So all local variable declarations take place before the statement sequence. After variables are declared local, they can be used (defined) in the statement sequence. In this case, declaring variable local inside an if-branch (if statement/expression), probably, just breaks this syntax.

I reproduced this error on my side. The problems looks to be specific to calling latex( 1.0 * a^(1/2)) (with literal 1.0). It  somehow does not like a combination of a floting point 1.0 times some symbolic expression with ^ (power). Interestingly, latex( 2.0 * a^(1/2)) works.

restart;

interface(version);

`Standard Worksheet Interface, Maple 2023.2, Windows 11, October 25 2023 Build ID 1753458`

(1)

latex(1.0 * sqrt(a^2 + b^2));

Error, (in unknown) invalid input: ^ expects 2 arguments, but received 1

 

latex(1 * sqrt(a^2 + b^2));

\sqrt{a^{2}+b^{2}}

 

latex(1.0 * sqrt(a));

Error, (in unknown) invalid input: ^ expects 2 arguments, but received 1

 

latex(1.0 * sqrt(2));

Error, (in unknown) invalid input: ^ expects 2 arguments, but received 1

 

latex(1.0 * sqrt(2.0));

 1.414213562

 

latex(1.0 * a^(1/3));

Error, (in unknown) invalid input: ^ expects 2 arguments, but received 1

 

latex(1.0 * a^{1.0/3.0});

a^{\left\{ 0.3333333333\right\}}

 

latex(2.0 * sqrt(a));

 2.0 \sqrt{a}

 

 

Download latex_power.mw

It looks like you need to impose assumptions on on functions f(x) and g(x). The following example works for me in Maple2023.2:

restart;
assume(g(x) in RealRange(-infinity, infinity) and f(x) in RealRange(-infinity, infinity));
is(g(x)^2 + f(x)^4, 'nonnegative');
is(g(x)^2 - f(x)^4, 'nonnegative');

true

 

false

(1)

 

Download assume.mw

This works for me in Maple 2022.2:

expr := (l * h * t * sqrt(4 * k^2 * a^2 * t^2 + m^2 )) / (sqrt(2 * I * k * t * a + m) * sqrt(-2 * I * k * t * a + m) * m);

simplify(evalc(expr)) assuming m >0 and k > 0 and a > 0 and t > 0;

It looks like just using `eval` is not enough here, and using `evalc` forces it to simplify real and imaginary parts in the square roots.

I guess the difference between comparing List and Vectors comes from mutability vs immutability of these data structures. Lists are immutable, and Vectors, Matrices, and Arrays are mutable. According to the Maple's help (3 Maple Expressions - Maple Help (maplesoft.com)): 

In general, expressions are compared for equality according to their memory address. That is, two expressions are considered equal in a Boolean context if they have the same address in memory.

Vectors are mutable so `Tv` and `Sv` have different memory addresses and `evalb(Tv = Sv)` returns `false` (it checks if they both reference the same location in the memory). To compare Vectors and Matrices for equalisty, there is `LinearAlgebra:-Equal()` method which compares them in mathematical sense, so that  `LinearAlgebra:-Equal(Tv, Sv) = true`.

Also this may help: 4 Basic Data Structures - Maple Help (maplesoft.com) section "Testing If Two Arrays Are Equal":

For Arrays, there are two notions of equality: do two references point to the same Array, or are they different Arrays that store the same values. To determine if two references refer to the same Array, use = and evalb. To test if two Arrays contain the same elements, use the EqualEntries command.

Page 1 of 1