patricmutwiri / symja

Automatically exported from code.google.com/p/symja
0 stars 0 forks source link

Factorial Function Does Not Resolve Correctly in Numeric Mode #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The Factorial function does not properly handle doubles expressed as 
integers.  

Try solving Factorial[3] and you get 6, 
try 3.0! and instead of getting the value 6.0 you get Factorial[3.0] 

What version of the product are you using? On what operating system?
Symja 0.0.7 WinXP JRE 1.6

Aditional information:

Bug is in this block of code:

final IEvaluator module = symbol.getEvaluator();
if ((module != null) && (module instanceof ISymbolEvaluator)) {
  if (fNumericMode) {
    return ((ISymbolEvaluator) module).numericEval(symbol);
  }
  return ((ISymbolEvaluator) module).evaluate(symbol);
}
return null;

When fNumericMode is true, it calls Factorial.numericEval() instead of 
Factorial.evaluate().   Factorial inherits evaluate() from AbstractTrigArg1, 
which calls evaluateArg1() that Factorial overrides with 
the correct implementation.   

But when Factorial.numericEval() is called, it resolves in 
AbstractTrigArg1.numericEval(), which ends up calling 
Factorial.numericEvalD1() when the input is a number (e.g. 3.0) - and 
Factorial simply returns null for numericEvalD1(); hence the value doesn't 
calculate.   

I would speculate that either Factorial should implement numericEvalD1(), 
or it should not extend AbstractTrigArg1, or there is an issue with the way 
numeric implementations are resolved; but I'm not sure. 

I should note that it's possible that other system functions have this 
problem as well.  

Original issue reported on code.google.com by Speis...@gmail.com on 15 Oct 2009 at 8:55

GoogleCodeExporter commented 9 years ago
I made these changes to improve the Factorial[] function for numerical values:
http://code.google.com/p/symja/source/detail?r=260
http://code.google.com/p/symja/source/detail?r=261

Original comment by axelclk@gmail.com on 15 Oct 2009 at 9:41

GoogleCodeExporter commented 9 years ago

Original comment by axelclk@gmail.com on 14 Nov 2009 at 2:38

GoogleCodeExporter commented 9 years ago

Original comment by axelclk@gmail.com on 9 Jun 2010 at 3:57