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

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 


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


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

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

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


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


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


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. 

Please Wait...