public Term setPerference(Term term) 
	throws TermException
    {
	
	if (term.var == null) {

	    Operation op = term.operation;
	    Operation res = null;
	    
	    if (!op.modName.equals(this.modName)) {
		
		Operation[] ops = this.getOperationsWithName(op.getName());
		for (int i=0; i<ops.length; i++) {
		    if (ops[i].modName.equals(this.modName)) {
			if (res == null) {
			    res = ops[i];
			} else if (ops[i].less(this, res)) {
			    res = ops[i];			    
			}
		    }
		}
				
	    }

	    if (res == null) {
		res = op;
	    }
	    
	    Term[] terms = new Term[term.subterms.length];
	    for (int i=0; i<term.subterms.length; i++) {
		terms[i] = setPerference(term.subterms[i]);
	    }
	    
	    //System.out.println("res = "+res+"   "+term);
	    return new Term(this, res, terms);
	  	    
	}

	return term;
    }