Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3393620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:04:20+00:00 2026-05-18T04:04:20+00:00

I often need to check if expr1==expr2 , where checking for symbolic equality is

  • 0

I often need to check if expr1==expr2, where checking for symbolic equality is hard, but a numeric check suffices

To deal with such cases it would be neat to have TildeTilde work like Equal but instead of checking symbolic equality it would substitute unknowns with numeric values and check for numeric equality at several points.

Unknowns are things that “look like” variables in the expression. The ones I can think of have form x,x[1,2] and Subscript[x,2,3]. Any tips welcome!

edit

usually I do something like below, but it requires specifying variables, sometimes requires changing Chop tolerance, and “10 samples” seems arbitrary. An ideal tester would be a function that works like Equals and guarantees meaningful False answers. (to complement Equals which has meaningful True answers)

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, apparently Maple uses this algorithm for such equality testing

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:04:21+00:00Added an answer on May 18, 2026 at 4:04 am

    This is somewhat straightforward if you use FindMaximum as a jumping-off point:

    In[64]:= FindMaximum[expr1 - expr2, q, x]
    
    During evaluation of In[64]:= FindMaximum::fmgz: Encountered a gradient that
    is effectively zero. The result returned may not be a maximum; it may be a 
    minimum or a saddle point. >>
    
    Out[64]= {1.11022*10^-16, {q -> 1., x -> 1.}}
    

    Thus:

    approxEqual[lhs_, rhs_, tol_: 10^-10] :=
     Module[{vars},
      vars = DeleteDuplicates[
        Cases[{lhs,rhs}, s_Symbol /; Not[ValueQ[s]], Infinity]
      ];
      Chop[
        First[
         Quiet[FindMaximum[Abs[lhs - rhs], Evaluate[Sequence @@ vars]]]
        ], 
        tol] == 0
      ]
    
    In[65]:= approxEqual[expr1, expr2]
    Out[65]= True
    
    In[66]:= approxEqual[expr1, expr2, 10^-20]
    Out[66]= False
    

    Obviously, in general this is subject to various numerical error issues that you can address with AccuracyGoal / PrecisionGoal / WorkingPrecision / etc. options to FindMaximum. You could also repeat FindMaximum for multiple starting points for the variables.

    As an aside, note that TildeTilde, (i.e. ~~), is the infix operator for StringExpression.

    HTH!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In php, I often need to map a variable using an array ... but
We occasionally need to notify users about warnings or problems. But often times, especially
It's often the case when I need to check a method's arguments for not
I need to check a generic object for null, or default(T). But I have
I often need to run reduce (also called foldl / foldr, depending on your
I often need to design a dialog in Delphi/C++Builder that allows various properties of
I have two scripts that often need to be run with the same parameter:
Here at work, we often need to find a string from the list of
While developing products, we often need to create proprietary tools to test some of
When I am writing code in Python, I often need to remove items from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.