Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMissingUserDefinedArguments work wrong in the latest version #265

Closed
ninh-mech opened this issue Jun 24, 2022 · 5 comments
Closed

getMissingUserDefinedArguments work wrong in the latest version #265

ninh-mech opened this issue Jun 24, 2022 · 5 comments
Labels

Comments

@ninh-mech
Copy link

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
@mariuszgromada
Copy link
Owner

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

@ninh-mech
Copy link
Author

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

@mariuszgromada
Copy link
Owner

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 added a commit that referenced this issue Aug 21, 2022
… that are functions, but no parameters are provided #265 fixed
@mariuszgromada
Copy link
Owner

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

@mariuszgromada
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants