Lisp answers this question by having a bunch of equality predicates.
EQ is true if the objects are identical in the sense of occupying the same memory location.
EQUAL tests for equal trees, where the nodes are EQ
= is a test for numerical equality 1.0d0 and 1 for example.
There are also predicates eql and equalp.
For a symbolic math system, for an algebra that has subtraction and zero and simplification in it,
a test for
zerop( simplify(A-B)) is stronger than
equal (simplify(A), simplify(B))
The floating point heuristic is not a great idea, but may be useful.
A much more interesting program by W.A. Martin (circa 1968) and
similar work by Gaston Gonnet is based on (essentially) hashcoding.
That is , do all arithmetic in an expression in a large-ish finite field with
random values for variables. It was used this way:
If two expressions A B have the same hashcode, then assume they are
equal. If they differ in structure, decide which is "simpler" by, say,
counting nodes. If B has fewer nodes, then B is a simpler form for
A. replace all instances of A by B.
Does that make you squirm?
RJF