Found while writing worked examples for every member of AngouriMath.Extensions (#585, #746 item 4).
Three extension methods refuse an empty sequence by throwing something the caller cannot act on, while their neighbours in the same file accept one and answer correctly.
Measured on a master build (6b93b40, v2.3.0):
new Entity[0].SumAll(); // AngouriBugException: At least 1 child required
new Entity[0].MultiplyAll(); // AngouriBugException: At least 1 child required
new Entity[0].ToVector(); // System.IndexOutOfRangeException
MathS.Vector(); // System.IndexOutOfRangeException
new Entity[0].ToSet(); // { }
new Providedf[0].ToPiecewise(); // piecewise()
Two separate problems.
AngouriBugException is reachable from ordinary input. Its message ends "please report about it to the official repository", so an empty IEnumerable<Entity> — a list that a Where happened to filter to nothing — asks the user to file a bug report for their own data. It comes out of TreeAnalyzer.MultiHangBinary (Functions/TreeAnalyzer/Sort.Definition.cs:41), whose precondition is genuine; what is wrong is that SumAll/MultiplyAll pass an unchecked user array into it.
The mathematics gives the answer here rather than only the exception type: a fold over a monoid has an identity, so the empty sum is 0 and the empty product is 1. That is what Enumerable.Sum gives, what Aggregate with a seed gives, and what makes xs.Concat(ys).SumAll() == xs.SumAll() + ys.SumAll() hold for every pair including the empty one. Answering 0 and 1 is the fix I would expect; if that is unwanted, then an ArgumentException naming the empty argument, but not the internal one either way.
ToVector leaks a framework exception. System.IndexOutOfRangeException is not under AngouriMathBaseException, so it is outside the hierarchy Docs/Usage/Exceptions.md documents, and a caller who catches the documented base type does not catch this. It comes from MathS.Vector (Convenience/MathS.cs:4811) reading arr[0] before checking the length, so MathS.Vector() has it too and the extension only inherits it. A 0x1 matrix may or may not be a thing this library wants to have; either way the refusal should be an InvalidMatrixOperationException (or whichever member of the hierarchy fits) rather than an index error.
ToSet and ToPiecewise already take the empty sequence, which is why this reads as an oversight rather than a decision: the same argument gets three different receptions across one file.
Not fixed in the documentation PR that found it, because that PR must not change a single answer.
Found while writing worked examples for every member of
AngouriMath.Extensions(#585, #746 item 4).Three extension methods refuse an empty sequence by throwing something the caller cannot act on, while their neighbours in the same file accept one and answer correctly.
Measured on a
masterbuild (6b93b40, v2.3.0):Two separate problems.
AngouriBugExceptionis reachable from ordinary input. Its message ends "please report about it to the official repository", so an emptyIEnumerable<Entity>— a list that aWherehappened to filter to nothing — asks the user to file a bug report for their own data. It comes out ofTreeAnalyzer.MultiHangBinary(Functions/TreeAnalyzer/Sort.Definition.cs:41), whose precondition is genuine; what is wrong is thatSumAll/MultiplyAllpass an unchecked user array into it.The mathematics gives the answer here rather than only the exception type: a fold over a monoid has an identity, so the empty sum is
0and the empty product is1. That is whatEnumerable.Sumgives, whatAggregatewith a seed gives, and what makesxs.Concat(ys).SumAll() == xs.SumAll() + ys.SumAll()hold for every pair including the empty one. Answering0and1is the fix I would expect; if that is unwanted, then anArgumentExceptionnaming the empty argument, but not the internal one either way.ToVectorleaks a framework exception.System.IndexOutOfRangeExceptionis not underAngouriMathBaseException, so it is outside the hierarchyDocs/Usage/Exceptions.mddocuments, and a caller who catches the documented base type does not catch this. It comes fromMathS.Vector(Convenience/MathS.cs:4811) readingarr[0]before checking the length, soMathS.Vector()has it too and the extension only inherits it. A 0x1 matrix may or may not be a thing this library wants to have; either way the refusal should be anInvalidMatrixOperationException(or whichever member of the hierarchy fits) rather than an index error.ToSetandToPiecewisealready take the empty sequence, which is why this reads as an oversight rather than a decision: the same argument gets three different receptions across one file.Not fixed in the documentation PR that found it, because that PR must not change a single answer.