Note also that prod(range(1,n)) does *NOT* just multiple 1 times 2
times 3 in order.   Instead, it uses a tree approach so that the
multiplications involve objects with more balanced sizes, which is
much faster, e.g., for large integers multiplyling n*m with n and m
having similar sizes can overall be massively better than n * m with n
large and m tiny...

On Thu, Sep 22, 2022 at 2:54 PM kcrisman <kcris...@gmail.com> wrote:
>
> I'm not sure what you were expecting.  It does return 0, but it does so after 
> all the print statements are done.  Remember, your "test" function just 
> returns the input, so the map function just returns a list (well, a map 
> object, but ...) and then we prod everything in the list.  But that happens 
> AFTER you have done the map on test, and that requires printing out all of 
> them.  The prod can't finish up until the entire list has been processed via 
> map and the function "test".  I could imagine an alternate implementation of 
> prod which checked each time whether zero had been produced in an 
> intermediate step, but that doesn't appear to be in the code in "prod??".
>
> On Thursday, September 22, 2022 at 10:39:03 AM UTC-4 axio...@yahoo.de wrote:
>>
>> sage: def test(n):
>> ....:     print("n:", n)
>> ....:     return n
>> ....:
>> sage: l = [2,3,5,0,7,11,17,19]
>> sage: prod(map(test, l))
>> n: 2
>> n: 3
>> n: 5
>> n: 0
>> n: 7
>> n: 11
>> n: 17
>> n: 19
>> 0
>> I expected that it would return 0 once we multiply with 0.
>>
>> Martin
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-devel/9c864eb6-b8fd-42c4-b1e7-b7eef89deae0n%40googlegroups.com.



-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CACLE5GA6XoVHbu10Pdk3y9D-wOd4k7ppCC3Z0Sd__TCsYad%2B_A%40mail.gmail.com.

Reply via email to