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

On unary operators #23

Open
rll2021 opened this issue Feb 7, 2021 · 0 comments
Open

On unary operators #23

rll2021 opened this issue Feb 7, 2021 · 0 comments

Comments

@rll2021
Copy link

rll2021 commented Feb 7, 2021

Kai and I have had an off-line discussion along the following lines. I want to publish my thinking before submitting code changes.

The main branch insists on binarizing unary operators. We do this by prefixing cos(x), say, by +,-,*,/. If we want balance among the four arithmetic primitives, then all four variations must appear in the operators_XXX.csv file.

This seems to me unnecessary. Two changes are required in fx_eval_label():
1. Treat unary operators as left prefixes. Emit op+'('+arg+')'. Walk this node pre-order.
2. Parenthesize the arguments of (infix) binary operators. Emit '('+arg1+')+op+'('+arg2+')'. Walk this node in-order.

There are knock-on effects elsewhere in the code. These arise from the assumption that all operators are binary. I have found most (all?) of them. Fixing them permits unary minus also to work as expected.

The ternary case (if/then/else) eludes me. I know of no equivalent syntax that sympy.sympify will accept. I propose replacing this code with an easily interpretable error message.

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

1 participant