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

Several refactoring and bugfix. #145

Merged
merged 10 commits into from
Dec 5, 2022
Merged

Several refactoring and bugfix. #145

merged 10 commits into from
Dec 5, 2022

Conversation

odashi
Copy link
Collaborator

@odashi odashi commented Dec 4, 2022

Overview

This change contains following changes:

  • Fix a bug in FunctionExpander: the original implementation does not process nested functions if the outer function is retained.
  • More accurate judgment to add parenthesis around functions. The new implementation tries to remove some parenthesis, e.g., $\sin (x)$ --> $\sin x$.
  • Adjusts old codegen rules around tuple/list/set.
  • Simplifying some tests, and providing more exhaustive tests.
  • Some small refactoring.

Details

New features added by this change is follows:

  • FunctionRule dataclass, representing a codegen rule of a builtin function.
  • Defines the default precedence of ast.Call as a value just above unary operators so that unary operators are wrapped by parentheses:
    • sin(x) --> $\sin x$
    • sin(-x) --> $\sin (-x)$
    • -sin(-x) --> $- \sin x$
  • Factorial ( $x!$ ) is the special case of this rule: if either the function or argument is a factorial, it is always wrapped by parentheses to avoid confusion:
    • sin(factorial(x)) --> $\sin (x!)$
    • factorial(sin(x)) --> $(\sin x)!$
    • factorial(factorial(x)) --> $(x!)!$

References

  • NA

Blocked by

@odashi odashi merged commit eebbae7 into main Dec 5, 2022
@odashi odashi deleted the fix-func-syntax branch December 5, 2022 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants