Items tagged with type

Hi,

I want to subtract two functions. One of them is numeric-type and the second is exact. Something like this:

solNum := dsolve(Dsys, numeric);

sol := dsolve(Dsys);

plot(solNum-sol)

In the last step there is an error (of course). How can I fix it?

Thank you very much

Hello,

I am working on a Dirichlet breakdown of primes. I need a way to check if a number is part of anothers number factorization.

Example: 30 = 2*3*5.

2 is therefore part of the ifactor of 30. 4 and 7 are not.
How do I check if, for instance, 7 is part of de factorization of 390?

Thanks in advance.

Trying to write a generat purpose procedure insteat of having 3 or 4 different named procceduers.

Need to determine the input types of say A,B,C

Proc(A,B,C)

1) A,B,C could be for the form 3/2 , 5x-7 , x^2-sqrt(x+3)  i.e numbers or formulas

2) A,B,C could be 2 elenent lists [2,3]  , [5x-6y,8x+2] ,[2,sqrt(3)]  i.e 2D points

3) A,B,C could be 3 element lists as above    i.e 3D points

4) A,B,C could be 2D vectors

5) A,B,C could be 3D vectors

A, B, C will not be of mixed types but would be good to check A, B, C for consistency and if not retrun an error

Looking to calculate output based on

If type 1) ......

elif type 2).....

.

.

elif type 5)...

end if

return.....

end proc

 

 

I know that whattype() is used to find the basic data type of an expression. Unfortunately that information is rarely useful. How can I dig down deeper and get Maple to tell me more about the expression?

I read somewhere that there is a properties() procedure that does that but I cannot find that procedure.

Thanks.

A wealth of knowledge is on display in MaplePrimes as our contributors share their expertise and step up to answer others’ queries. This post picks out one such response and further elucidates the answers to the posted question. I hope these explanations appeal to those of our readers who might not be familiar with the techniques embedded in the original responses.

The Question: Variable Identification

Don Carota wanted to know the best approach for finding variables that are not assigned to a value within an equation. He wrote:

I got a set of equations to solve, like this one:

eq[1]:=W[1,0]*(a*HRa[1,0]+b*ga[1,0]+c)=d*SR[1,1]/grid

a,b,c,d are numbers, like 2.0458 and so on.

When I want to solve the set, I need to tell Maple the command solve:

solve( {seq(eq[i],i=1..N)},{variables});  (N is an integer of course)

To set the variables, one must check each equation to write: {W[1,0],HRa[1,0],ga[1,0]...} and so on.

I know that I can use the command is(variable,assignable) to check if a variable has not a value assigned already and, according to true/false I can construct the set {variables} and solve the set of equations.

That´s an easy solution if I need to check variables under a certain pattern, like: X[1], X[2], X[3] since I can create a loop and check them one after the other. But my problem is that I have different names for variables or that variables change to assignable from assigned according to other conditions, so I can never be sure if W[1,0] is going to be a variable to compute in all steps instead of SR[1,1].

for example:

if a>3 then
SR[1,1]:=1/2;
else
W[1,0]:=300:
end if;

So, when I need to type solve, the {variables} part is different according to each case. Is there any command that allows me to insert an expression and Maple can return me the variables or parameters in the expression that are not numeric already?

(note that the link added to the is command above was added by me, not the original author)

dharr and Carl Love provided solutions that use the indets command.

The code provided by dharr is as follow:

  1. indets(eq[1],name);

Result: gives the indeterminates: {a, b, c, d, HRa[1, 0], SR[1, 1], W[1, 0], ga[1, 0]}

The code provided by Carl Love is as follows:

1.       indets(eq[1], assignable(name));

or, doing all equations at once,

2.       indets({entries(eq, nolist)}, assignable(name));

 

Further Explaining the indets and type commands.

Both dharr and Carl Love provided an answer that used the indets command. In essence the indets command used in this example contains two arguments: indets(expr, typename). Expr is a rational expression that only uses the operations such as addition, subtraction, division, and multiplication. Typename is a parameter used when the desired return is a set containing all subexpressions in expr that are of type typename.

Carl Love used the assignable(name) argument  for the typename parameter in order to return all the variables that can be assigned a value, excluding constants such as Pi that are also considered names. Indeed, assignable is a type and can be used without an additional argument. For example, the command indets(x+f(x)+y=1, assignable) returns {x,y,f(x)} because all three symbols can be assigned values. However, indets(x+f(x)+y=1, assignable(name)) returns just {x,y} because f(x) is of type function, not of type name. Similarly, indets(x+y=Pi, assignable) would return just {x,y} because Pi is not considered to be something that can be assigned to.

Carl’s second command used ({entries(eq, nolist)} as the expr parameter. In this version, eq is the table whose members are the individual equations. Remember, the syntax x[1] creates a table whose name is x, and whose entry is the object assigned to x[1]. The entries(t) function returns a sequence of the table members, each member being placed in list brackets. By including the option nolist, the return is then a sequence of table members without list brackets. 

Finally, note that different programmers will use different approaches to finding “indeterminants” in expressions. Dr. Lopez pointed out that some years ago he asked three different programmers about extracting the “assignable names” in an expression such as q:=x+Pi+cos(a). The naive indets(q) returns {a,x,cos(a)}, whereas indets(q,name) returns {Pi,a,x}. However, select(type,indets(q),name) returns {a,x}, as does indets(q,And(symbol,Not(constant))).

Don Carota’s question is able to showcase some of the different types that are within Maple’s platform. Therefore, it is important to go over what the type-checking function is and what it does. In many contexts, it is not necessary to know the exact value of an expression; instead it is enough to know if the value belongs to a group of expressions that have similarities. Such groups are knows as types.

Maple’s engine uses the type function in every single procedure to direct and maintain the flow of control in algorithms and to decide if the user’s input is valid. There are about 240 different types that Maple recognizes including: prime, string, symbol, list, etc.  Let’s see some examples of how the function works using elements from this question. 

Type has two parameters: an expression e, and a valid type expression t. To check that the output of the entries(eq,nolist) is indeed not a list, the type command can be used as follows:

As expected, the last command returns false! If you want to learn more about the type and indets commands you can visit their corresponding help pages: ?type, ?indets.

 

This blog was written by Maplesoft’s intern Pia under the supervision of Dr. Robert Lopez. We both hope that you find this useful. If there is a particular question on MaplePrimes that you would like further explained, please let us know. 

with(Student[LinearAlgebra]);
example1 := Matrix([[1, 2, 3], [4, 5, 6], [6, 7, 8]]);
whattype(example1);

testproc := proc (A) print(whattype(A)) end proc;

testproc(example1);

The whattype() calls output:

Matrix
proc() ... end proc

I don't understand why what is a Matrix type outside the procedure seems to change into this unrelated type? This is really bizarre. I feel like it may be something outside my code? Thank you.

I want to separate strings into substrings for example
input is "6,3,A,n,k,L,+,-" then the procedure breaks this string into substrings like 
if a member numeric b:="6,3",or if lowercase c:="n", if uppercase l:="A,L" else m:="+,-"
thanks

 

``

 

I would appreciate if anyone lets me know how to write circular references  (say 1 inside a circle to refer element 1. At present i do a drawing insert text and using.

 

Also i do not know how to remove the boundary of the overall drawing.

NULL

 

Download A_DOUBT_to_be_sent_to_prime_community.mw

Ramakrishnan V

rukmini_ramki@hotmail.com

Hi,


This is my first post here, so I apologize for any errors or breaking of posting etiquette. I encountered a strange problem suddenly tonight when I tried running a Maple worksheet I've run succesfully (several times, without changes) in the past. The problem occured on both Maple 18 and Maple 2015, unfortunately I haven't been able to recreate a minimal working example with the same error, since my other worksheets doesn't show the error even though they contain identical caluclations. The problem also persists between copies of the worksheet.

The error I'm recieving is
"Error, (in TypeTools/ac_var_local) unable to handle expressions as (((D@@2)(phi))(theta(t)))(t)"

It occurs whenever I try to differentiate some (not all) expressions containing the above variable. I have no idea what this error even means, and I can't find anything googling. As said previously, I haven't been able to produce the error so I can't really give a concise short example but the flow is as follows:

g0 := simplify(subs(diff(y(t), t, t) = F+N*v(t), lhs(aby)-lhs(aby_y)), 'size');
->Produces an expression containing (((D@@2)(phi))(theta(t)))(t)
diff(g0,t)
-> Gives Error

U := lhs(Vector([1, 0]).subs(subsVhcError, eom));
->Produces an expression containing (((D@@2)(phi))(theta(t)))(t)
diff(U,t)
-> Does not give error

Sorry that I can't be more descriptive, does anyone know have to sort this out, or might give me some more info on what the Error message might mean and how TypeTools are involved? As stated previously, the error just occured today and only affects one worksheet.

Edit: Link to worksheet with error
transverse_linearization.mw

 

I am trying to define a new typt and I am beating my head against the wall...

What I have working:

TypeTools:-AddType(Element,'record(l,R)');
 
This defines a type which I can then use in type(xpr,Element) to be false or true depending on whether xpr is a record containing (at least) entries l and R or not.

Now I want to define a type ExpandedLine that is a Vector of Element (Element in the sense above). In fact, in the context of my application I am willing to settle for ExpandedLine being a Vector of record.

Tried various approaches (and making sure Vector is in uneval quotes in the AddType statement) like:

TypeTools:-AddType(ExpandedLine,'Vector'(record));

and variations but no luck.

Any help is appreciated.

Mac Dude

 

Dear people in mapleprimes,

 

>define(INT, linear, conditional(INT(a::algebraic, X::name) = a*X, _type(a, freeof(X))), INT(X::name, X::name) = (1/2)*X^2);

>INT(2*x+4, x);

x^2 + 4*x

>INT(z+x, z);

(1/2)* z ^2+ x*z

is written in the help page of maple.

This code is to make a function INT.

What it means is that if INT(a::algebraic, x::name) then this is transformed into a*X, where a is independent from x.

And, INT(X::name,X::name) is transformed into (1/2)*X^2.

 

The first of what I want to ask you is the way of use of "_type", which is not in the help page, and as for names with "_" ahead, 

it is written that "_" means internal command for Maple, so not to use it. Is it right to use a name with "_" ahead of it here?

The second of what I want to know is the way to use "conditional."

Please teach me the meaning of this.

Thanks in advance.

 

I hope you will teach me the above questions.

 

Best wishes.

 

taro

 

 

My Maple is apparently getting rusty!  Question: how do I recognize a finite constant?

type(Pi, finite) is false (by design, apparently), while type(infinity, constant) is true.  So now I don't know quite what to 'ask' maple!

Hello
I encountered with a problem in understanding of structured types. I test following structured types:



the result is

true

false
false

I cannot understand two last results as I expected to receive trues. Could you explain me the result?
Thank you.

UPD
A code appropriate for copy/pase along with short problem solution is presented below

restart;
`type/A1`:={integer, rational};
`type/A2`:=integer or rational; #  it matchs the expressions that literally contain `or` (see @Carl Love's
answer below)
`type/A3`:=OR(integer, rational); # `Or` should be used rather then `OR` (see @acer's
answer below)

x:=5;
type(x, A1);
type(x, A2);
type(x, A3);

Hello.
I am trying to extract the terms that are a product of a commutative part and an operator part from the input expression. That is I am trying to extract a terms like a*A.B where A and B are quantum pperators.

I am trying to do it by creating corresponding structured type:

restart; 
with(Physics);
Physics[Setup](op = {A, B}, quiet);

`type/ProdComOp` := `&*`(commutative, specfunc(anything, Physics:-`*`));
z0 := u*A.B-A+k*B+B.A.B+g;
z1 := z0+v*A.B.A;
S1 := indets(z1, ProdComOp);

and all it is Ok. The result is 
But if

z2 := z0-v*A.B.A; 
S2 := indets(z2, ProdComOp);

then
however I expected to receive the same as S1.

How to handle the sign of the commutative part? Thank you.

Hi. I need to test if a variable is a dot-product of "anything"-s (usually it is quantum operators).
I try the following

restart; 
with(Physics);
Physics:-Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);
ap1 := Physics:-Creation(psi, 1, notation = explicit);
am1 := Physics:-Annihilation(psi, 1, notation = explicit);
ap2 := Physics:-Creation(psi, 2, notation = explicit);
am2 := Physics:-Annihilation(psi, 2, notation = explicit);

z1 := ap1.am1.ap2:
type(z1, ('`.`')(anything));

and get

false

whereas

z2 := a*b*c; 
type(z2, (':-`*`')(anything));

returns

true

I studied ?type,structured and other sources but didn't find any answer.

1 2 3 Page 1 of 3