On Sat, Jun 19, 2021 at 7:03 AM Oscar Benjamin
<oscar.j.benja...@gmail.com> wrote:
>
> I agree that this should be changed in sympy itself. It is just a case that 
> someone needs to do the work for this. It's not just about disabling the 
> evaluation because then there are potentially other parts of the codebase 
> that might subtly break if evaluation does not happen. I would investigate 
> this by setting the limit to be very low and then running the test suite to 
> see what fails and whether the code that expects evaluation can be improved.

This is the tracking issue for this https://github.com/sympy/sympy/issues/6835

>
> Your suggestion above is to raise ValueError but I think that having an 
> evaluated power is probably better in many (but not all) situations.
>
> There are also some points to consider such as how a user could choose what 
> the limits should be in case they do want to work with extremely large 
> integers.
>
> Also I find that most often this issue arises as part of evalf. Changing the 
> Float._eval_power has no effect on the internal code of evalf. Basically 
> someone needs to go through all of the evalf routines and consider where 
> absurdly large numbers might appear and then abort the operation if some 
> limit would be exceeded. Probably this should be a controllable option for 
> evalf as well which has a maximum option for precision but not for the size 
> of the exponent.

This seems like something that would need to be implemented in mpmath,
not evalf. Fortunately, there it could be implemented in just a single
place (on the mpf type), and it wouldn't require doing bounds
estimates on every possible mpmath function. Furthermore, it is quite
rare to have mpfs with very large exponents, so it's unlikely this
would break much if we set the limit to some reasonably large number.
mpmath is actually relatively unique in that it does allow arbitrarily
large exponents. Most other arbitrary precision libraries that I've
seen allow arbitrarily large precision, but limit the exponent to a
machine word.

Aaron Meurer

>
> Oscar
>
> On Sat, 19 Jun 2021 at 13:28, Michał Pawłowski 
> <michal.bozydar.pawlow...@gmail.com> wrote:
>>
>> Hey, thank you. I figured out how to block integer power of integer, if 
>> result is tu high (over 10**4 decimal digits). I also figured out how to 
>> block integer and float multiplication when result is too high
>>
>> But I highly recomend, to put it in official release of new version of 
>> SymPy. My code can be broken. :(
>>
>> from mpmath import log10 as _log10
>> from mpmath import power as _pow
>> from mpmath import fabs as _fabs
>>
>> def checkIf_Pow_MaxValReached(b, e):
>>     b = _fabs(str(b))
>>     e = _fabs(str(e))
>>
>>     if b == 0:
>>         b = 1
>>
>>     b, e = str(b), str(e)
>>
>>     if _pow(e, 1) * _fabs(_log10(b)) > 10000:   #DO POPRRAWY
>>         raise ValueError("tooBig")
>>
>> I call this function in power.py file in __new__ method al the beginning
>>
>>         if evaluate:
>>             if b.is_integer and e.is_integer:
>>                 checkIf_Pow_MaxValReached(b, e)
>>
>> To block multiply i needed to edit numbers.py file inside of Integer class 
>> in __mul__ method.
>>
>> Please add this functionality into official sympy :(
>> piątek, 18 czerwca 2021 o 21:39:23 UTC+2 asme...@gmail.com napisał(a):
>>>
>>> Most likely the method you are looking for is in
>>> sympy/core/numbers.py. I would recommend taking a version of the
>>> expression that has small numbers and using a debugger to figure out
>>> what methods are called.
>>>
>>> You should be aware also that if you just type something like 2**100
>>> directly into Python, that doesn't involve SymPy at all and gets
>>> evaluated by Python, which we cannot prevent. SymPy only comes into
>>> play if one of the numbers is a SymPy type.
>>>
>>> Aaron Meurer
>>>
>>> On Mon, Jun 14, 2021 at 1:28 AM Michał Pawłowski
>>> <michal.bozyd...@gmail.com> wrote:
>>> >
>>> > Hello.
>>> >
>>> > I'm trying to modify sympy to avoid of hanging, when numer which is gonna 
>>> > to be computed is tu large. I know how to raise exception, but In which 
>>> > file should i look for power computing without eval?
>>> >
>>> > In core/numbers.py there are mothods for evaluation of numbers. But where 
>>> > should I look for methods for not evaluated powers?
>>> >
>>> > Thanks
>>> > Mike
>>> >
>>> > --
>>> > 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 sympy+un...@googlegroups.com.
>>> > To view this discussion on the web visit 
>>> > https://groups.google.com/d/msgid/sympy/c091e73e-782a-4b83-9b16-23797465fb66n%40googlegroups.com.
>>
>> --
>> 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 sympy+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sympy/d3d0f86f-afa4-4fbe-8821-70b75067fe45n%40googlegroups.com.
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/CAHVvXxS9rKkWB4-N5ebPG%2BY%2BTuuzZmeXr_7Q9Xau%3D2aYP4PvzA%40mail.gmail.com.

-- 
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 sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6Jm2BAu%3DuDCj1Dzr0DxcFs6jA36e08M6Saisy1-NbsZCQ%40mail.gmail.com.

Reply via email to