-
Notifications
You must be signed in to change notification settings - Fork 223
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
Let sympy use log2(x) instead of log(x)/log(2) #712
Conversation
… log(x)/log(base)
codegen looks like an internal utility? https://docs.sympy.org/latest/modules/utilities/codegen.html Is there anything simpler we can use? |
Pull Request Test Coverage Report for Build 12207024711Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
I'm not familiar with sympy, so I'm not sure. The docs indicate that the regular
Grepping the sympy source code for instances of log2 did not reveal anything of note, though I may have missed it. |
I am a bit worried about using this version over just |
Good point. I asked over at sympy, and it seems it's a rare but supported function. It is documented at https://docs.sympy.org/latest/modules/codegen.html#sympy.codegen.cfunctions.log2 . |
Thanks! Okay I’m on board then. Now, one other thing is we need the codegen import:
This seems to have been done by some other package, but ideally we should also run this within PySR. |
I think this refers only to the callable, i.e. the function |
Just checking in on this – could you add the line
to the imports? This is needed according to the docs page. |
Can you check if that's correct? My understanding of the docs page is that it refers to the codegen callable, not the codegen namespace. The code only uses the namespace, so the import should not be not required. |
This comment was marked as outdated.
This comment was marked as outdated.
Seems like you need to import directly from the [ins] In [1]: import sympy
[ins] In [2]: sympy.codegen.cfunctions.log2(4.0)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 sympy.codegen.cfunctions.log2(4.0)
AttributeError: module 'sympy' has no attribute 'codegen' compared with: [ins] In [1]: from sympy.codegen.cfunctions import log2
[ins] In [2]: log2(4.0)
Out[2]: 2.00000000000000 So I think the reason this currently works at all is because some dependency is doing the |
Neat, thank you :) |
Fixes #711
The case of log10 is also included.
I was not immediately able to run the unit tests, but I tested it with this code:
Equation:
y = (10.003 / log10(x₀)) + log2(x₀ * x₀)
Translated to sympy:
log2(x0*x0) + 10.003168/log10(x0)