3

An arithmetic function is maths that uses only the arithmetic operators, addition, subtraction, multiplication and division.

I already have a way of parsing the expressions into an AST, so what I’m imagining is a tree walking algorithm to determine this property.

For example:

x + 1 is injective.

x / x is not.

x + x / x is.

I'm not even sure where to start with functions of more than one input.

To reiterate the title of the question, is there an algorithm which takes as input an arithmetic function in the form of an ast and produces as output “true” if and only if that function is injective?

If so can you explain this algorithm in sufficient detail for it to be implemented?

Robin Davis
  • 622
  • 4
  • 10
  • 1
    https://math.stackexchange.com/ I think this will be relevant – VedantK Apr 02 '18 at 03:42
  • @VedX I thought about posting there (and of course searched there) but I am looking for an algorithm to implement for realsies after all... – Robin Davis Apr 02 '18 at 03:49
  • 1
    @RobinDavis, you should describe in what way your "function" is specified. In general case if "function" is just any pure function implemented by any algorithm, you even [can't predict if a function always return something for all inputs](https://en.wikipedia.org/wiki/Halting_problem). For a subset of all calculable functions specified in some limited way your question might have a definite answer. – SergGr Apr 02 '18 at 10:14
  • I'm voting to close this question as off-topic because not about programming. – duffymo Apr 02 '18 at 11:22
  • @serggr I thought “arithmetic function” was pretty specific but I’ll update the question. – Robin Davis Apr 02 '18 at 16:55
  • @duffymo I’m asking for an algorithm that could be implemented in a programming language. I’m not sure how that’s off topic. Is there another stack exchange for algorithms? – Robin Davis Apr 02 '18 at 16:59
  • 2
    Given the negative solution to Hilbert's 10th problem, I would be surprised if what you want can be done in general. I didn't vote to close it (though I could see why others did) but I do think that other sites might be better, such as [cs.se]). – John Coleman Apr 02 '18 at 17:14
  • @RobinDavis, sorry "arithmetic function" might be clear for you but not for everybody. Does it mean just a single expression of arithmetic operators? Or do you allow some conditional branching and loops? Like is `abs(x)` arithmetic for you? Is `n!` (factorial) arithmetic? P.S. [Computer Science](https://cs.stackexchange.com/) might be a better place for such theoretical questions. – SergGr Apr 02 '18 at 17:14
  • @serggr I know of no definition of “arithmetic” that allows for the operations you mentioned. Thanks, I’ll try out the CS exchange. – Robin Davis Apr 02 '18 at 17:15
  • @johncoleman that is really interesting about the 10th problem. Does that also apply to functions of one variable? – Robin Davis Apr 02 '18 at 17:19
  • 1
    @RobinDavis, I believe that many people consider Euler's totient function `φ(n)` to be an "arithmetic function" (for example [Wikipedia](https://en.wikipedia.org/wiki/Arithmetic_function#%CF%86(n)_%E2%80%93_Euler_totient_function) seems to agree with me on this) but AFAIK it can't be calculated using a single expression without loops. As for 10th problem that's really interesting point but I bet that if you restrict functions to only "a single expression of 4 base arithmetic operations", it doesn't hold and probably the answer to your question is "yes" but I don't know how. – SergGr Apr 02 '18 at 17:30
  • For dimension1 you should be able to decide if a solution to a polynomial diophantine equation exists (e.g. bounding possible solutions to a finite range that can be brute-forced). For dimension 4 or more there is no general solution. I don't really know what happens in dimensions 2 or 3. I suspect that Hilbert's 10th problem rules out a general solution to your problem that would apply to any number of variables, but for 1 variable, you should probably be able to come up with a solution. – John Coleman Apr 02 '18 at 17:30
  • I see that you posted this on Mathematics (where it is probably more likely to get an answer). In this case, you should probably delete this here since cross-posting is discouraged between different stack exchange communities. – John Coleman Apr 02 '18 at 18:07
  • @johncoleman Unfortunately it is now only possible for me to vote for deletion. – Robin Davis Apr 02 '18 at 18:08
  • 1
    That is odd. In any event, I hope that you find the answer that you seek. – John Coleman Apr 02 '18 at 18:09

0 Answers0