Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This example works to define InverseFunction on the first argument of a function

f = Function[{##} /. {x_, y_} :> Beta[x, y] - x + y];
g = InverseFunction[f, 1, 2];
g[3, 4]
(*Root[{1 + Beta[#1, 4] - #1 &, 1.17659010788279817113535497590}]*)
N[%]
(* 1.17659 *)

When changing the definition of f to use x_Integer instead of x it no longer works

f = Function[{##} /. {x_Integer, y_Integer} :> Beta[x, y] - x + y];
g = InverseFunction[f, 1, 2];
g[3, 4]

Returns unevaluated

InverseFunction[{##1} /. {x_Integer, y_Integer} :> Beta[x, y] - x + y &, 1, 2][3, 4]

How to make InverseFunction work on functions defined with restrictions on its arguments? I looked at ConditionalExpression but could not figure how to use it here.

V 9.01 on windows

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Since for real input there isn't any errors spat out, I assume the function is invertible in the first variable so one way to get the function you want is to constrain the inverse to be an integer. A way to do this is:

Clear[f, g, intg]
f[x_, y_] := Beta[x, y] - x + y;
g[z_, y_] := InverseFunction[f, 1, 2][z, y];
intg[z_, y_Integer] :=
 If[IntegerQ@# || IntegerPart@# == #, IntegerPart@#,] &@g[z, y]

The second condition in If is so that if the inversion is done numerically you force the result to be an integer (but this is to some accuracy i.e. 4 == 4. (1 + 1 10^-14) is True while 4 == 4. (1 + 1 10^-13) is False).

Now

f[3, 2]
(* -11/12 *)

and

intg[-11/12,2]
(* 3 *)

but

intg[-0.91666,2]

is unevaluated.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.