# Question:Apparent bug in "applyrule" for wildcard argument of symbol type

## Question:Apparent bug in "applyrule" for wildcard argument of symbol type

Maple

In Maple 2019, I'm using the "applyrule" function to write a simple routine for contracting vector indices, following the Einstein summation convention (repeated indices are summed).

Input:

applyrule(
vec(a::symbol, i::symbol) * vec(b::symbol, i::symbol) = dotproduct(a,b),
vec(a,k) * vec(b,k)
);

Output:

dotproduct(a, b)

So far it works as expected. Now I add an "uncontracted" vector, and the code seems to become unpredictable. First, let me show a case in which the code still works:

Input:

applyrule(
vec(a::symbol, i::symbol) * vec(b::symbol, i::symbol) = dotproduct(a,b),
vec(u,k) * vec(u,i) * vec(c,k)
);

Output:

dotproduct(c, u)*vec(u, i)

As expected, contraction has been done on the repeated index "k", but vec(u,i) was left alone. However, the above code fails if I simply change the variable name "u" to "a":

Input:

applyrule(
vec(a::symbol, i::symbol) * vec(b::symbol, i::symbol) = dotproduct(a,b),
vec(a,k) * vec(a,i) * vec(c,k)
);

Output:

vec(a, k)*vec(a, i)*vec(c, k)

Apparently, the rule was not applied because I used "a:symbol" in the transformation rule. But I thought "a::symbol" should be considered a wildcard that represents any symbol, including "a" itself?

Depending on the exact input, this bug sometimes shows up, sometimes not, but the above examples are verified to be reproducible. A simple workaround is always avoiding the use of the same variable, but this seems to be hack. Is there a proper solution?

﻿