On Tue, Feb 16, 2016 at 5:15 PM, Ondřej Čertík <[email protected]> wrote:
> On Tue, Feb 16, 2016 at 12:39 PM, Aaron Meurer <[email protected]> wrote:
>> The problem here isn't so much to do with trig identities as the big
>> numbers. The issue is that things like
>> factorial(847937526693730893984732849857349) and
>> 1342**(87236487262873**(8732498237693269832+3)+5)-1) evaluate
>> automatically, which causes Python to try to compute them until the
>> memory fills up and it crashes.
>>
>> The way I would fix this is to create a special BigInteger object,
>> which would wrap large integers and avoid explicit computation. For
>> example, BigInteger(10)**BigInteger(10)**BigInteger(100) would remain
>> unevaluated. It would then use some algorithms and the assumptions
>> system to compute facts. So something like
>> factorial(BigInteger(847937526693730893984732849857349)).is_integer
>> would be True, which would be enough for
>> sin(pi*factorial(BigInteger(847937526693730893984732849857349))) to
>> simplify. There are some cool things that you could do with this,
>> like (2**BigInteger(74207281) - 1).is_prime. For anyone interested,
>> there's probably enough cool stuff that could be done here for a GSoC
>> project.
>>
>> (By the way, I had an issue open in the issue tracker a while ago
>> about this, but I can't find it)
>
> Another point is that SymPy should not do automatic simplification of
> these large things, because the code to do that is not completely
> trivial and always fast. However, there should be a function in sympy
> that can do these simplifications when called explicitly by the user.
That's true, but I still think it's a good idea to have this. Take for
instance the googolplex, 10**10**100. You can represent this already
using Pow(10, Pow(10, 100, evaluate=False), evaluate=False). But there
are two issues with this. First is that evaluate=False is very
fragile. Any function that tries to rebuild the expression will cause
it to evaluate. And even if you fixed that issue some other function
might try to take the expression apart and use it to build some other
expressions. That's why I think you need a BigNumber wrapper for the
numbers, rather than some kind of hold property on the operators.
With BigNumber(10)**BigNumber(10)**BigNumber(100), no matter what
function you pass this to it won't accidentally try evaluating it,
because it will basically look the same as n**n**m for n, m =
symbols('n m', integer=True).
Second, you build these large numbers out of smaller numbers. Python
can represent a googol just fine
In [25]: 10**100
Out[25]:
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
it's the googolplex that you don't want to compute. But you don't want
to represent it as 10**
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
you want to represent it as 10**10**100. So even if Pow is smart
enough to not evaluate Pow(10,
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000),
it would still evaluate Pow(10, 100), so Pow(10, Pow(10, 100)) would
reasonably evaluate to Pow(10,
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000),
when you really want Pow(10, Pow(10, 100)). The same thing happens for
factorial.
However, I definitely am +1 for functions like factorial automatically
not trying to evaluate if the argument is above some reasonably large
value. My concern would just be with picking the value. Some people
might actually want to sit and wait to compute some large factorial.
Aaron Meurer
>
> Ondrej
>
>>
>> Aaron Meurer
>>
>> On Tue, Feb 16, 2016 at 2:02 PM, Jari-Pekka Ikonen
>> <[email protected]> wrote:
>>> Some trigonometric expressions can easily and quickly be simplified without
>>> ever calculating some of the functions in it just by using the known
>>> properties of the functions in the expression.
>>>
>>> For example:
>>>
>>> sin(2*pi)
>>>
>>> is 0. So:
>>>
>>> sin(pi*factorial(847937526693730893984732849857349))
>>>
>>> is also 0. This does not require calculation of the factorial, but the
>>> property knowledge, that the result of the factorial is an even integer.
>>>
>>> There are several other examples of expressions, like:
>>>
>>> tan(pi*(1342^(87236487262873^(8732498237693269832+3)+5)-1))
>>>
>>> is also 0. Several others:
>>>
>>> cos(pi*(factorial(8629264243264^64862423642638763847)+1/2))
>>>
>>> is 0.
>>>
>>> Could this be implemented in sympy? So many other examples would be much
>>> faster to calculate.
>>>
>>> --
>>> 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/218ff008-9f3a-479e-8b4e-bca49d646294%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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/CAKgW%3D6JTFaC9O08ymvq0tLb1p-1Lz2iuWFduCAL-ZSPyby8k0w%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/CADDwiVAA1PsNQX9W%3DO%3DsPXgdq%3DFJ0cSEeqhsWATGMYoiFmfcgg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
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/CAKgW%3D6%2BU8WQCEK7JFQB48ijQ%2Bgq3oMayjM_04mBVvXfZQbgUzw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.