-
-
Notifications
You must be signed in to change notification settings - Fork 894
Closed
Description
PR #566 introduced Product()
but I believe its return value for an empty slice is incorrect: it currently returns 0
but it should be 1
.
Operations such as Sum()
and Product()
are so-called fold operations with the initial value mathematically called identity element. Normally, the identity element of product operation is 1
, so Product(<empty slice>)
should return 1
(not 0
).
Supporting evidence:
-
Empty product - Wikipedia and Fold (higher-order function) - Wikipedia say the value of empty product is
1
. -
Rust's
Iterator::product()
returns1
for an empty slice.fn main() { println!("{}", Vec::<usize>::new().into_iter().product::<usize>()); //=> 1 }
-
Haskell's
product
returns1
for an empty list.module Main where main :: IO () main = do print $ product ([] :: [Int]) -- 1
Metadata
Metadata
Assignees
Labels
No labels