Define a function f(x) such that f(f(x)) = -x
\[f(x)=-|x|\]
\[f(f(x)) = -|-|x||\]\[f(f(-1)) \neq 1 \]
@Anwar f(f(x)) = -(-x) = x :-P
:/
This can be done in a few lines in Python. Python 1, Math 0 :-D
why not C?
It might be possible in C..... let me think
maybe easier in C++
because Python (at least the default one) is C's baby, and if Python can do it, then C can :-D
in python you can't even i++ :D
What's the definition of the function? Don't give us Python code; the code is just the encapsulation of that definition. What is the definition itself in ordinary mathematical notation?
I was hoping someone could figure it out for me :( I think it has to do with complex numbers. f(x) = x*i
oh, so it's not a real valued function? Then it's trivial.
right
but the question said we can't use complex numbers :(
In which case, it's not trivial. Do you know the answer? I don't. I'd like you to tell me.
I don't know either, but it's one line in Python
f = lambda x: (lambda: -x) if (not hasattr(x, '__call__')) else x()
decode the line for us and tell us then. You're the Python expert.
I can't read that.
it just says f is a function that returns a function that returns the additive inverse of a number if the argument is not a function and calls its input otherwise.
Oh, so it's not a regular mathematical function at all.
is it possible to make it a regular math function?
i don't think so, but i'll think about it a little.
Join our real-time social learning platform and learn together with your friends!