Language: C++

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1LL<<59)

#define int ll

typedef array<int,27> AI;
typedef vector<AI> EX;
typedef string::const_iterator State;

string normalize(string s){
	string t="";
	rep(i,s.size()){
		if(s[i]!=' ')t+=s[i];
		else if(i+1==s.size()||s[i+1]!=' ') t+=s[i];
	}
	rep(i,t.size()-1)assert(t[i]!=' '||t[i+1]!=' ');

	string u="";
	rep(i,t.size()){
		char ch = t[i];
		if(ch!=' '){u+=ch;continue;}

		if(!(i-1<0||t[i-1]=='('||t[i-1]=='-'||t[i-1]=='+'||t[i-1]=='^')&&!(i+1>=t.size()||t[i+1]==')'||t[i+1]=='-'||t[i+1]=='+'||t[i+1]=='^'))u+=' ';
	}
	rep(i,u.size())if(u[i]==' ')u[i] = '*';
	
	string ret = "";
	rep(i,u.size()){
		ret+=u[i];
		if(i+1>=u.size())continue;
		if(isdigit(u[i])){
			if(u[i+1]=='('||isalpha(u[i+1]))ret+='*';
		}
		if(isalpha(u[i])){
			if(u[i+1]=='('||isnumber(u[i+1])||isalpha(u[i+1]))ret+='*';
		}
	}
	return ret;
}

EX E(State &beg);


int dig(State &beg){
	assert(isdigit(*beg));
	string res = "";
	while(isdigit(*beg)){
		res+=*beg;
		beg++;
	}
	return  stoll(res);
}


EX P(State &beg){
	if(isdigit(*beg)){
		int res = dig(beg);
		AI ret;
		ret[0]=res;
		for(int i=1;i<ret.size();i++)ret[i]=0;
		return EX(1,ret);
	}
	else{
		assert(isalpha(*beg));
		char ch = *beg;
		beg++;

		if(*beg=='^'){
			beg++;
			int t = dig(beg);
			AI ret;
			rep(i,ret.size()){
				if(i==ch-'a'+1)ret[i] = t;
				else ret[i] = 0;
			}
			ret[0]=1;
			
			return EX(1,ret);
		}
		else{
			AI ret;
			rep(i,ret.size()){
				if(i==ch-'a'+1)ret[i] = 1;
				else ret[i] = 0;
			}
			ret[0]=1;

			return EX(1,ret);
		}
	}
}


AI mul(AI a,AI b){
	AI ret;
	ret[0] = a[0]*b[0];
	for(int i=1;i<a.size();i++){
		ret[i] = a[i]+b[i];
	}
	return ret;
}

EX mulEX(EX a,EX b){
	EX ret;
	rep(i,a.size()){
		rep(j,b.size()){
			ret.pb(mul(a[i],b[j]));
		}
	}
	return ret;
}


EX T(State &beg){
	EX ret;
	if(*beg=='('){
		beg++;
		ret = E(beg);
		beg++;
	}
	else{
		assert(isdigit(*beg)||isalpha(*beg));
		ret = P(beg);
	}
	
	while(*beg=='*'){
		beg++;
		EX t = T(beg);
		ret = mulEX(ret,t);
	}
	return ret;
}


bool isSame(AI a,AI b){
	for(int i=1;i<a.size();i++){
		if( a[i]!=b[i] )return false;
	}
	return true;
}


EX E(State &beg){
	EX res = T(beg);
	
	while(*beg=='+'||*beg=='-'){
		if(*beg=='+'){
			beg++;
			EX t = T(beg);
			rep(i,t.size()){
				bool f=false;
				rep(j,res.size()){
					if(isSame(t[i],res[j])){
						f=true;
						res[j][0]+=t[i][0];
						break;
					}
				}
				if(!f){
					res.pb(t[i]);
				}
			}
		}else if(*beg=='-'){
			beg++;
			EX t = T(beg);
			rep(i,t.size()){
				bool f=false;
				rep(j,res.size()){
					if(isSame(t[i],res[j])){
						f=true;
						res[j][0]-=t[i][0];
						break;
					}
				}
				if(!f){
					t[i][0]*=-1;
					res.pb(t[i]);
				}
			}
		}
	}
	return res;
}


bool isMatch(EX a,EX b){
	sort(all(a));
	sort(all(b));
	if(a==b)return true;
	else return false;
}


void output(vector<EX> ans){
	rep(i,ans.size()){
		rep(j,ans[i].size()){
			rep(k,ans[i][j].size()){
				cout<<ans[i][j][k]<<" ";
			}
			cout<<endl;
		}
		cout<<endl<<endl;
	}
}


signed main(){
	assert(normalize("(a - b) (0-b+a) - 1a ^ 2 - b ^ 2")=="(a-b)*(0-b+a)-1*a^2-b^2");
	while(1){
		vector<string> vs;
		string s;
		while(getline(cin,s)&&s!="."){
			vs.pb(s);
		}
		if(vs.size()==0)break;
		
		rep(i,vs.size()) vs[i] = normalize(vs[i]);
		
		vector<EX> ans;
		rep(i,vs.size()){
			State beg = vs[i].begin();
			EX res = E(beg);
			ans.pb(res);
		}
		
//		rep(i,vs.size())cout<<vs[i]<<" ";cout<<endl;
//		output(ans);
		
		for(int i=1;i<ans.size();i++){
			if(isMatch(ans[0],ans[i])){
				cout<<"yes"<<endl;
			}
			else cout<<"no"<<endl;
		}
		cout<<"."<<endl;
	}
}

Compiler output:
a.cc: In function 'std::string normalize(std::string)':
a.cc:41:41: error: 'isnumber' was not declared in this scope
   41 |                         if(u[i+1]=='('||isnumber(u[i+1])||isalpha(u[i+1]))ret+='*';
      |                                         ^~~~~~~~