@@ -71,9 +71,9 @@ partial record Modf
7171 {
7272 // x % a = value has one solution per period, so inverting it means introducing
7373 // an integer parameter the way the trigonometric inversions do. Until that is
74- // written, no solutions is the honest answer -- a wrong one would be worse .
74+ // written the equation is left unsolved: no solutions would claim it has none .
7575 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
76- => Enumerable . Empty < Entity > ( ) ;
76+ => throw new CannotInvertException ( ) ;
7777 }
7878
7979 partial record Powf
@@ -212,18 +212,21 @@ private protected override IEnumerable<Entity> InvertNode(Entity value, Entity x
212212
213213 partial record Factorialf
214214 {
215- // TODO: Inverse of factorial not implemented yet
215+ // The factorial is the gamma function one along, and the gamma function has no
216+ // zeros anywhere in the complex plane, so x! = 0 has no roots. Every other value
217+ // has some -- x! = 6 at 3 -- and no node here writes them.
216218 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
217- Enumerable . Empty < Entity > ( ) ;
219+ value is Integer { IsZero : true } ? Enumerable . Empty < Entity > ( ) : throw new CannotInvertException ( ) ;
218220 }
219221
220222 partial record Binomialf
221223 {
222224 // The preimage of a binomial coefficient is not a function of either argument
223225 // that can be undone: binomial(n, k) = binomial(n, n - k), and 1 is taken at
224- // every (n, 0) and (n, n).
226+ // every (n, 0) and (n, n). It has one all the same -- binomial(x, 2) = 3 at 3 and
227+ // at -2 -- so the equation is left unsolved rather than answered with none.
225228 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
226- Enumerable . Empty < Entity > ( ) ;
229+ throw new CannotInvertException ( ) ;
227230 }
228231
229232 partial record Derivativef
@@ -250,49 +253,50 @@ partial record Maximumf
250253 {
251254 // The unknown sits under a binder; see Summationf below.
252255 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
253- Enumerable . Empty < Entity > ( ) ;
256+ throw new CannotInvertException ( ) ;
254257 }
255258
256259 partial record Minimumf
257260 {
258261 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
259- Enumerable . Empty < Entity > ( ) ;
262+ throw new CannotInvertException ( ) ;
260263 }
261264
262265 partial record Argmaxf
263266 {
264267 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
265- Enumerable . Empty < Entity > ( ) ;
268+ throw new CannotInvertException ( ) ;
266269 }
267270
268271 partial record Argminf
269272 {
270273 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
271- Enumerable . Empty < Entity > ( ) ;
274+ throw new CannotInvertException ( ) ;
272275 }
273276
274277 partial record Summationf
275278 {
276279 // The unknown sits under a binder, and inverting would have to solve for it inside a
277280 // sum whose length may be symbolic. Declining is the honest answer -- and the wrong
278281 // one is on record: solving through an opaque Derivativef returns a non-solution,
279- // https://github.com/asc-community/AngouriMath/issues/964.
282+ // https://github.com/asc-community/AngouriMath/issues/964. Declining is leaving the
283+ // equation unsolved; no roots would claim it has none.
280284 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
281- Enumerable . Empty < Entity > ( ) ;
285+ throw new CannotInvertException ( ) ;
282286 }
283287
284288 partial record Productf
285289 {
286290 // Same reasoning as Summationf above.
287291 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
288- Enumerable . Empty < Entity > ( ) ;
292+ throw new CannotInvertException ( ) ;
289293 }
290294
291295 partial record Limitf
292296 {
293- // TODO: We can't just do a limit on the inverse function: https://math.stackexchange.com/q/3397326/627798
297+ // We can't just do a limit on the inverse function: https://math.stackexchange.com/q/3397326/627798
294298 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x ) =>
295- Enumerable . Empty < Entity > ( ) ;
299+ throw new CannotInvertException ( ) ;
296300 }
297301
298302 partial record Signumf
@@ -386,28 +390,28 @@ partial record Minf
386390 // of x. Nothing here can express that, and inventing a branch would answer
387391 // confidently and wrongly, so this declines the way Factorialf and Phif do.
388392 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
389- => Enumerable . Empty < Entity > ( ) ;
393+ => throw new CannotInvertException ( ) ;
390394 }
391395
392396 partial record Maxf
393397 {
394398 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
395- => Enumerable . Empty < Entity > ( ) ;
399+ => throw new CannotInvertException ( ) ;
396400 }
397401
398402 partial record Gcdf
399403 {
400404 // The preimage of a gcd is every pair whose greatest common divisor is the
401405 // value, which is not a function of x that can be undone.
402406 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
403- => Enumerable . Empty < Entity > ( ) ;
407+ => throw new CannotInvertException ( ) ;
404408 }
405409
406410 partial record Lcmf
407411 {
408412 // As for the gcd.
409413 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
410- => Enumerable . Empty < Entity > ( ) ;
414+ => throw new CannotInvertException ( ) ;
411415 }
412416
413417 partial record Boolean
@@ -564,7 +568,7 @@ partial record FiniteSet
564568 {
565569 // set{,,,} = value
566570 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
567- => this == x ? new [ ] { value } : Enumerable . Empty < Entity > ( ) ;
571+ => this == x ? new [ ] { value } : throw new CannotInvertException ( ) ;
568572 }
569573
570574 partial record Interval
@@ -580,14 +584,14 @@ private protected override IEnumerable<Entity> InvertNode(Entity value, Entity x
580584 return Left . Invert ( Right , x ) . Select ( c => c . Provided ( MathS . Equality ( Right , value ) ) ) ;
581585 else
582586 return Right . Invert ( Left , x ) . Select ( c => c . Provided ( MathS . Equality ( Left , value ) ) ) ;
583- return Enumerable . Empty < Entity > ( ) ;
587+ throw new CannotInvertException ( ) ;
584588 }
585589 }
586590
587591 partial record ConditionalSet
588592 {
589593 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
590- => this == x ? new [ ] { value } : Enumerable . Empty < Entity > ( ) ;
594+ => this == x ? new [ ] { value } : throw new CannotInvertException ( ) ;
591595 }
592596
593597 partial record SpecialSet
@@ -660,7 +664,7 @@ partial record IndexedSetOperation
660664 {
661665 // The unknown sits under a binder; see Summationf.
662666 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
663- => Enumerable . Empty < Entity > ( ) ;
667+ => throw new CannotInvertException ( ) ;
664668 }
665669
666670 partial record Powersetf
@@ -677,15 +681,15 @@ partial record Valuationf
677681 // valuation(n, p) = k has every multiple of p^k prime to p for a solution, a set the
678682 // inverter cannot hand back.
679683 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
680- => Enumerable . Empty < Entity > ( ) ;
684+ => throw new CannotInvertException ( ) ;
681685 }
682686
683687 partial record Primef
684688 {
685689 // prime(n) = p has the one solution n = pi(p) where p is prime and none otherwise,
686690 // and pi is not a node here; declined the way Phif is.
687691 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
688- => Enumerable . Empty < Entity > ( ) ;
692+ => throw new CannotInvertException ( ) ;
689693 }
690694
691695 partial record Phif
@@ -694,7 +698,7 @@ partial record Phif
694698 // There is an algorithm to find exactly one solution but we can do no more.
695699 // TODO: Mess with that...
696700 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
697- => Enumerable . Empty < Entity > ( ) ;
701+ => throw new CannotInvertException ( ) ;
698702 }
699703
700704 partial record Cardf
@@ -728,7 +732,7 @@ partial record Quantifier
728732 {
729733 // The unknown sits under a binder; see Summationf.
730734 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
731- => Enumerable . Empty < Entity > ( ) ;
735+ => throw new CannotInvertException ( ) ;
732736 }
733737
734738 partial record Providedf
@@ -758,14 +762,14 @@ partial record Application
758762 {
759763 // TODO
760764 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
761- => Enumerable . Empty < Entity > ( ) ;
765+ => throw new CannotInvertException ( ) ;
762766 }
763767
764768 partial record Lambda
765769 {
766770 // TODO
767771 private protected override IEnumerable < Entity > InvertNode ( Entity value , Entity x )
768- => Enumerable . Empty < Entity > ( ) ;
772+ => throw new CannotInvertException ( ) ;
769773 }
770774 }
771775}
0 commit comments