# Question:how to select all instances of function y() in an expression

## Question:how to select all instances of function y() in an expression

Maple 2018

I am learning how to do parsing in Maple.

I want to check that a user supplied an expression with correct argument to y(*) from some complicated expression. So I need to find all instanced of y() to check that its agument is only y(x) and nothing else.  For example, given this

```restart;
expr:=y(x)^2+x+y(x)+2*1/y(z)+sin(x)+sin(y(x))+y+f(z)/Int(sin(y(x)),x)+y(x,y,z);```

I need to obtain all these y(anything), like this

No matter where they show up in the expression. The above is just some made up example. The actual input will be a differential equation, and I want to check that the dependent variable y(x) has only x as its argument.

So I did the following

`candidates:=convert(select(has,expr,y),list);`

The problem now, is how to scan this list and check that each entry in it, the "y" in there has form y(x) and nothing else, so I can reject or accept the input. For example, the first one above is Ok, so the second one, but the third is not, since it function of z and not x. #4 is OK, #5 is not OK, since it has y without (x), and the last one is no OK, since it has 3 arguments, and so on.

I am not good in pattern matching in Maple. do I need to check match() for this? or patmatch()? If given single expresion like y(x), then I can handle it. I do something like

```expr:=y(x);
if type(expr,'function') and nops(expr)=1 and op(0,expr)=y and op(1,expr)=x then
print("OK");
else
print("not ok");
fi;```

But when the expression gets more complicated, like 1/y(z), then I need to check other things, and things gets complicated quickly. I think pattern matching is needed? or is there a better approach to do this that works in general?

How does Maple do it internally? When I type

`   dsolve(diff(y(x),x)+x+y(z)=0,y(x));`

Error, (in dsolve) found the indeterminate function y with different arguments {y(x), y(z)}

`dsolve(diff(y(x),x)+x+sin(y(z))=0,y(x));`

Error, (in dsolve) found the indeterminate function y with different arguments {y(x), y(z)}

```dsolve(diff(y(x),x)+x+y()=0,y(x));
```

So I need to do the same thing as Maple does. I looked at dsolve() code, but did not understand it how or where it does the parsing.

﻿