On Wednesday, October 4, 2017 at 12:04:43 PM UTC+3, Nico Schlömer wrote:
>
> I have a function that takes in an integer value and returns a symbolic 
> fraction of it, e.g.,
> ```
> def r(n):
>     return sympy.Rational(n, 261)
> ```
> I would like to be able to provide integers and sympy.Symbols alike, but 
> the latter fails with
> ```
> TypeError: invalid input: n
> ```
> -- Right, one can simply use `n/261`.
>
> Since Rationals appear quite frequently in my code, I would like to avoid 
> constructions like
> ```
> x = n/261 if isinstance(n, sympy.Atom) else sympy.Rational(n, 261)
> ```
> (where sympy.Atom wouldn't even cover cases like `2n+1` in 
> either numerator or denominator).
>
> Is there a way to support integer and symbolic fractions from one 
> interface?
>
> Cheers,
> Nico
>

You could probably use  n/sympy.Integer(261),  or briefly  n/S(261)  where  
S = sympy.sympify.

Kalevi Suominen 

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/8cd0f808-265e-400c-99f6-ebbdf01a5cea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to