On 8/14/2013 7:44 AM, Wilhelm Haager wrote:
> Hi,
>
> I want to check whether an expression represents a circle in the
> xy-plane,
> but I don't understand the behavior of the pattern matching:
>
> (%i2) matchdeclare([xx,yy],numberp,rr,lambda([u],numberp(u) and u > 0));
> (%o2) done
>
> There is no match with the "+" sign in the expression:
>
> (%i3) defmatch(circlep,(y-yy)^2 + (x-xx)^2 = rr);
> (%o3) circlep
> (%i4) circlep((y-3)^2+(x-2)^2 = 25);
> (%o4) false
For a start, let me observe that the pattern matching program has
undergone some
alterations since I wrote it in 1969 or so.
Some of these changes are noted in the source code and consist of the
disabling of error messages. Some accompanying comments indicate
that ... because some programmer who went into the code and did not
understand it and did not understand the message, did not ask the author
for clarification,
decided to just strike it out.
Secondly, the process of pattern matching generally puts the objects
being matched
into a canonical form, so that in trying to match (y-yy)^2, before
anything happens,
that expression is changed to y^2-2*y*yy+yy^2.
So any idea that you are going to look for the difference of two items,
squared, is
nonsense. Indeed, if you want to look for expressions that are circles,
it seems to me
that your pattern is dreadfully inadequate. A circle can be written in
many forms.
>
> There is a match with a "-"-sign in the expression
> (that is, of course, no circle; but the matching is done in
> the expected way):
>
> (%i5) defmatch(circlep1,(x-xx)^2 - (y-yy)^2 = rr);
> (%o5) circlep1
> (%i6) circlep1((x-2)^2-(y-3)^2 = 25);
> (%o6) [rr = 25,yy = 3,xx = 2]
>
> Is there any explanation for that behavior,
I suspect it is that "-" takes exactly two arguments, but "+" takes
an arbitrary number.
The pattern matching looks, on the lhs, for the difference of exactly
two things with exponents of 2, and
you get lucky here.
Matching with a "+", the system probably first does the canonical
simplification of ratsimp.
> or could it be possible, that pattern matching is just not
> yet mature in Maxima?
It is certainly possible to write another pattern matcher program to do
whatever you expect.
There is, for example, one that looks like Mathematica's pattern
matcher, written
in lisp. Do not expect to be "unsurprised" by Mathematica's matching.
>
> Is there a possibility to conceive a pattern for recognizing a circle?
Sure. look for a pattern x^2+y^2 + U*x+V*y+W in ratsimp(lhs). then
test to see if W= U^2/4 + V^2/4.
RJF