I often need to check if there is expr1==expr2where the check for symbolic equality is tough, but a numerical check is enough
To deal with such cases, it would be convenient to TildeTildework like Equal, but instead of checking symbolic equality, he would replace the unknowns with numerical values and check the numerical equality at several points.
Unknown are things that “look” like variables in an expression. I think they have a shape x, x[1,2]and Subscript[x,2,3]. Any advice is appreciated!
change
Usually I do something like below, but this requires variables to be specified, sometimes a change in the Chop tolerance is required, and the “10 samples” seem arbitrary. An ideal tester will be a function that works as Equalswell as guarantees reliable answers False. (in addition to Equalsthat has meaningful answers True)
approxEqual [expr1_, expr2_, vars_]: =
Chop [(expr1 - expr2 /. Thread [vars -> #]) & / @
RandomReal [{- 1, 1}, {10, Length [vars]}]] == Table [0, {10}];
expr1 = 1 / Sqrt [2] Log [Cosh [q + x / Sqrt [2]] Sech [q - x / Sqrt [2]]];
expr2 = Sqrt [2] ArcTanh [Tanh [q] Tanh [x / Sqrt [2]]];
approxEqual [expr1, expr2, {q, x}]
As a side note, Maple seems to use this algorithm for such equality testing.