# Functional inverse

**URL:** <https://discourse.julialang.org/t/functional-inverse/10959>\
**Category:** Internals & Design\
**Created:** [May 17, 2018, 4:31pm UTC](https://discourse.julialang.org/t/functional-inverse/10959 "2018-05-17T16:31:05Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [May 18, 2018, 5:05am UTC](https://discourse.julialang.org/t/functional-inverse/10959/14 "2018-05-18T05:05:31Z")

</div>

> [@jlapeyre](#):
>
> A function `finv` that returns the functional inverse of a function.

You can define such a type of function with [Reduce.jl](https://github.com/chakravala/Reduce.jl) symbolic package:

```Julia
julia> using Reduce

julia> finv(f::Function) = collect(Algebra.solve(:($f(x) == y),:x))
finv (generic function with 1 method)

julia> finv(cos)
2-element Array{Expr,1}:
 :(x = acos(y) + 2 * arbint(5) * π)     
 :(x = -((acos(y) - 2 * arbint(5) * π)))

```

Also, to select the principal branch, set `allbranch` to off

```Julia
julia> allbranch(false)
false

julia> finv(cos)
1-element Array{Expr,1}:
 :(x = acos(y))

```

---

_[View the full topic](https://discourse.julialang.org/t/functional-inverse/10959)._
