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

Differentiating between ReplaceAll and Division (Times [ , Power]) #3

Open
rocky opened this issue Oct 27, 2020 · 2 comments
Open

Differentiating between ReplaceAll and Division (Times [ , Power]) #3

rocky opened this issue Oct 27, 2020 · 2 comments

Comments

@rocky
Copy link
Contributor

rocky commented Oct 27, 2020

In mathics/Mathics#989 it was noticed that 1/.2 Is comes out ReplaceAll[1,2] rather than Times[1,Power[.2,-1]].

The fix there was to add a lookahead pattern for a number to distinguish these.

ANTLR4 has such a notion too which I think is called a semantic predicate or {...}? which might help the parser here.

@rljacobson
Copy link
Owner

The rules for how . is parsed are arcane. Here are my private notes on the subject from last summer:

1//..9 is ReplaceRepeated[1, 0.9`]
1//.9 is ReplaceRepeated[1, 9] should be 0.9[1]
1/.9 is Times[1, Power[0.9`, -1]]
1...9 is 9 ((1)...) or Hold[Times[RepeatedNull[1], 9]]
7//.9 is ReplaceRepeated[7, 9]
7// .9 is 0.9`[7]
1/.1->2 is 10. -> 2

7// .9 is 0.9`[7]

b; 7`b is 7. b
_.1 is Times[Optional[Blank[]], 1]

Rule: If . can be interpreted as part of an operator, it will be. The only exceptions are:

	b=.1
	a/:b=.1
	a/.1
	a.b (* The Dot operator. *)

This places the precedence of the decimal point between //. and /.—excepting for the Dot operator itself.

@rljacobson
Copy link
Owner

Pingback to #2 for reference, which references the edge case x_.. discussed here.

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

No branches or pull requests

2 participants