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

Setting for disabling lazy evaluation of multiplication #18

Closed
jsveiga opened this issue Feb 28, 2018 · 3 comments
Closed

Setting for disabling lazy evaluation of multiplication #18

jsveiga opened this issue Feb 28, 2018 · 3 comments
Labels

Comments

@jsveiga
Copy link

@jsveiga jsveiga commented Feb 28, 2018

Is this a request for a feature or a bug report?

Feature

What is the current behavior?

The "lazy evaluation of multiplication" may cause inconsistent or unexpected results (apart from the documented f(x) case), and there is no way to disable it.

Examples:

1E-2 evaluates to -2+E
N(1E-2) evaluates to 0.71828
(E is evaluated to Euler's number, 1E is evaluated as 1*E)

1e-2 evaluates to -2+e
N(1e-2) evaluates to -2.0+e
(e is evaluated as a variable (ok, case sensitive), 1e is evaluated as 1*e)

1.0E-2 evaluates to 0.01
1.0e-2 evaluates to 0.01
(e or E is evaluated as the usual scientific notation)

0x1 is evaluated as 1 (hex 1)
0y1 is evaluated as 0 (0 * y * 1)

Having the option to require the explicit "*", and throwing an error when it's not present would produce consistent and less typing-error-prone results.

What is the expected or desired behavior?

Having a setting, like for relaxedSyntax, for explicitMultiplication, turning off the "lazy evaluation of multiplication"

Please provide use cases for changing the current behavior:

When feeding user input to Symja, most (if not all) calculator users expect the scientific notation, 1e-10 for example, to work as expected (yes, it is possible to "sanitize" the input too, but disabling the feature in Symja would be ideal)

Please describe your development environment (OS, browser, etc.):

Linux, Android Studio 3.0.1

Symja is awesome, Thanks!

@axkr

This comment has been minimized.

Copy link
Owner

@axkr axkr commented Feb 28, 2018

Please verify, if a JUnit testcase could like the snippet below.

	public void testGithub18() {
		boolean old = Config.EXPLICIT_TIMES_OPERATOR;
		try {
			Config.EXPLICIT_TIMES_OPERATOR = false;
			if (!Config.EXPLICIT_TIMES_OPERATOR) {
				check("1E-2 // FullForm", "\"Plus(-2, E)\"");
				checkNumeric("1.0E-2 // FullForm", "\"0.7182818284590451\"");
				checkNumeric("1x-2 // FullForm", //
						"\"Plus(-2, x)\"");
				check("N(1E-2)", "0.71828");
				check("0x1", "0");
				check("0xf", "0");
				check("0y1", "0");
			}
			Config.EXPLICIT_TIMES_OPERATOR = true;
			if (Config.EXPLICIT_TIMES_OPERATOR) {
				check("1E-2 // FullForm", //
						"\"0.01\"");
				checkNumeric("1.0E-2 // FullForm", "\"0.01\"");
				checkNumeric("1x-2 // FullForm", //
						"Syntax error in line: 1 - End-of-file not reached.\n" + //
								"1x-2 // FullForm\n" + //
								" ^");
				check("N(1E-2)", "0.01");
				check("0x1", "1");
				check("0xf", "15");
				check("0y1", //
						"Syntax error in line: 1 - End-of-file not reached.\n" + //
								"0y1\n" + //
								" ^");
			}
		} finally {
			Config.EXPLICIT_TIMES_OPERATOR = old;
		}
	}
@jsveiga

This comment has been minimized.

Copy link
Author

@jsveiga jsveiga commented Mar 1, 2018

That would be perfect!

Please note that neither EXPLICIT_TIMES_OPERATOR = true nor false produces the same results as the current behavior albeit being consistent, so that may break backwards compatibility with apps relying or working around the current situation.

Thank you!

Joao

axkr added a commit that referenced this issue Mar 2, 2018
see especially MainTestCase#testGithub18() test case
axkr added a commit to tranleduy2000/symja_android_library that referenced this issue Mar 2, 2018
axkr added a commit that referenced this issue Mar 5, 2018
Setting for disabling lazy evaluation of multiplication

More tests to show the differences
axkr added a commit that referenced this issue Mar 5, 2018
multiplication

More tests to show the differences
@jsveiga

This comment has been minimized.

Copy link
Author

@jsveiga jsveiga commented Mar 12, 2018

Perfect! Thank You!

tranleduy2000 added a commit to tranleduy2000/symja_android_library that referenced this issue Mar 15, 2018
see especially MainTestCase#testGithub18() test case
tranleduy2000 added a commit to tranleduy2000/symja_android_library that referenced this issue Mar 15, 2018
@axkr axkr added the enhancement label Apr 6, 2018
tranleduy2000 added a commit to tranleduy2000/symja_android_library that referenced this issue Apr 30, 2018
@axkr axkr closed this Jun 23, 2018
axkr added a commit that referenced this issue Dec 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.