0

In JavaScript or any other programming languages that functions are first-class object, we can confirm as below:

const f = a => a * 2;

console.log(
  f(1) 
); //2

console.log(
  (a => f(a))(1)
); //2

Although comparing the functions with actual inputs seems a typical way, reviewing an answer:

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

I want to try SMT solvers in JavaScript to solve this problem, but don't know exactly how.

Any idea? Thanks.

There is

https://www.npmjs.com/package/logic-solver

https://jgalenson.github.io/research.js/demos/minisat.html

smooth_writing
  • 299
  • 1
  • 6
  • 1
    We don't know either, and this is a far too broad problem to be answered on SO. Regarding JS specifically, you'll want to start parsing the function code into an AST, and then check whether the function is pure (a whole topic on its own) to make sure you can even reason about it properly. Only then you can start transforming the syntax tree into a format that a solver would accept as input. – Bergi Aug 29 '20 at 21:19
  • 1
    Maybe you find [JSCert](http://www.jscert.org/index.html) interesting as it seems to provide ways to analyze JavaScript in the interactive theorem prover Coq. Moreover, Coq has [plugins](https://smtcoq.github.io/) to use SMT solvers – tphilipp Sep 09 '20 at 09:34

0 Answers0