MathParser.org-mXparser icon indicating copy to clipboard operation
MathParser.org-mXparser copied to clipboard

getMissingUserDefinedArguments work wrong in the latest version

Open ninh-mech opened this issue 2 years ago • 3 comments

Issue title:

  • getMissingUserDefinedArguments work wrong in the latest version

Issue content:

After I update to the latest version of mXparser, I got problem when use getMissingUserDefinedArguments fucntion. Example: my expression in string: "300+Caster_Attack*3"

var expression = new Expression("300+Caster_Attack*3"); 
expression.getMissingUserDefinedArguments();

At v4.4.2 : that function will be return a string array [0] : "Caster_Attack" At v.5.0.6 : that function will be return a string array [0]: "ast" [1]: "r_Attack"

If bug/question:

  • MathParser.org-mXparser verssion: v.5.0.6
  • Framework: .net

ninh-mech avatar Jun 24 '22 05:06 ninh-mech

Hi, Thank you for reporting. This is an "interesting" bug in the implementation of the implied multiplication. Please take a look at the following

Expression e = new Expression("300+Caster_Attack*3");
mXparser.consolePrintln(e.getCanonicalExpressionString());

The result [mXparser-v.5.0.6] 300+C*ast*e*r_Attack*3

  • "C" is a known keyword to the parser - the "C(n, k)" Binomial coefficient function. The error here is that the tokenizer should also look for the parentheses to be sure it can insert the multiplication sign.
  • "e" is also a know keyword to the parser - the "e" Euler's number. Here everything is ok.

Options, as of now, that you have to fix this

  • Use variable names that do not contain words known to the parser, see "e.getHelp()"
  • Remove "C" and "e" built-in tokens
Expression e = new Expression("300+Caster_Attack*3");
mXparser.removeBuiltinTokens("C", "e");
mXparser.consolePrintln(e.getCanonicalExpressionString());

[mXparser-v.5.0.6] 300+Caster_Attack*3

  • Turn off implied multiplication mode - locally
Expression e = new Expression("300+Caster_Attack*3");
e.disableImpliedMultiplicationMode();
mXparser.consolePrintln(e.getCanonicalExpressionString());

[mXparser-v.5.0.6] 300+Caster_Attack*3

  • Turn off implied multiplication mode - globally
mXparser.disableImpliedMultiplicationMode();
Expression e = new Expression("300+Caster_Attack*3");
mXparser.consolePrintln(e.getCanonicalExpressionString());

[mXparser-v.5.0.6] 300+Caster_Attack*3

I hope this helps :-)

Best regards

mariuszgromada avatar Jun 24 '22 08:06 mariuszgromada

Thank for the quick response! Those information is so helpful. I knew the solution for this problem. Thanks

ninh-mech avatar Jun 24 '22 08:06 ninh-mech

I think, I need to add the option in the implied multiplication allowing to select the variant

  1. Implied Multiplication with parser builtin keywords
  2. Implied Multiplication without parser builtin keywords

I will think more about it.

mariuszgromada avatar Jun 24 '22 08:06 mariuszgromada

Fixed - Tokenization fix in case of Implied Multiplication and known keywords that are functions, but no parameters are provided

mariuszgromada avatar Aug 21 '22 19:08 mariuszgromada

Dedicated Tutorial sections added

User defined arguments -> Case 5: Possible conflict between Implied Multiplication and getting list of missing user defined arguments + recommended solutions https://mathparser.org/mxparser-tutorial/user-defined-arguments/

User defined functions -> Case 7: Possible conflict between Implied Multiplication and getting list of missing user defined functions + recommended solutions https://mathparser.org/mxparser-tutorial/user-defined-functions/

Best regards

mariuszgromada avatar Oct 16 '22 19:10 mariuszgromada