How to compare two functions for equivalence, as in (λx.2*x) == (λx.x+x)?

后端 未结 6 1716
忘掉有多难
忘掉有多难 2020-11-30 21:11

Is there a way to compare two functions for equality? For example, (λx.2*x) == (λx.x+x) should return true, because those are obviously equivalent.

6条回答
  •  感动是毒
    2020-11-30 21:58

    In a language with symbolic computation like Mathematica:

    Or C# with a computer algebra library:

    MathObject f(MathObject x) => x + x;
    MathObject g(MathObject x) => 2 * x;
    
    {
        var x = new Symbol("x");
    
        Console.WriteLine(f(x) == g(x));
    }
    

    The above displays 'True' at the console.

提交回复
热议问题