Comments (7)
@MAKMED1337 Not sure, but it looks there should be another option to control the behavior around
from latexify_py.
I also think our current implementation (#125) naturally solves #65 (comment) , as users can choose whether exp
is expanded or not.
from latexify_py.
Is it better expit(x)
to be
from latexify_py.
I think this can be solved by introducing function-level controls:
- Register replacement rules
Call -> AST
for each applicable functions. If the expanded AST has other calls, it is kept as-is. - Assin a flag for each rule to control whether the rule is applied or not.
- Add a flag to control the overall behavior (i.e., we perform the replacement if
all_flag && fn_flag[fn_name]
is True) - For the replacer routine (it may be NodeTransformer), if it finds a matched name, replace it to AST, and recursively applies the rules to replacements too.
This allows us to control the behavior more precisely. E.g., users can choose the result of expit(x)
from either
This also involves some caveats:
- It causes infinite replacement if the rule has identity or cyclic rules:
f(x) -> f(x)
, orf(x) -> g(x) and g(x) -> f(x)
, which may result in stack overflow. Since it is not easy to detect such behavior in advance, it may be necessary to constrain the maximum recursion of the replacements. - If
with_latex
takes every function-level flags, the syntax may become very complicated. I think providing a config function is better, something like:
import latexify
config = latexify.Config.defaults()
config.expand_function("expit")
@latexify.with_latex(config)
def f(x):
return expit(x)
# Will generate: \mathrm{f}(x) \triangleq \frac{1}{1+\exp{(-x)}}
from latexify_py.
List of methods in math
that I think we should allow expansion for:
-
exp(x)
->$e^x$ -
exp2(x)
->$2^x$ -
expm1(x)
->$\exp(x) - 1$ -
log1p(x)
->$\log(1 + x)$ -
pow(x, y)
->$x^y$ -
atan2(x)
->$\arctan(y / x)$ -
erf
-> too complicated, also I don't think integrals are supported... yet -
erfc
-> see above -
gamma
-> maybe for positive integers? I think it's best to leave alone for now -
lgamma
-> see above
Let me know what you think @odashi, and I'll get started on these
from latexify_py.
I think non-elementary functions (erf
, erfc
, gamma
, lgamma
) should be avoided from this option. Other candidates look fine to me.
from latexify_py.
This is generally supported in the current implementation. We'd support individual functions in separate issues (if needed).
from latexify_py.
Related Issues (20)
- Custom multiplication behavior (option to use \cdot everywhere) HOT 1
- Should `def(x): func(x)` generate `\func x` or `\func \mathopen{}\left( x \mathclose{}\right)`? HOT 2
- Fine-grained control over function name replacements
- Designing "plugin" interface HOT 3
- Use `latex.py` for to standardize codegen HOT 2
- Feedback From a User HOT 14
- Please add support for Python >3.11 HOT 2
- IPython extension to automatically use conversions on displayed objects HOT 1
- Better Identifier For Multi Index and RHS HOT 4
- Can you sub in values for show work? HOT 1
- Сonverting expressions or strings to latex format HOT 5
- Release New Version HOT 6
- Support for sqrt-like nth-roots when rendering x**(1/p)? HOT 2
- Support for log1p and expm1? HOT 4
- `if-elif` statements break if there's no `else` HOT 1
- Typo in \mathopen HOT 3
- Counterintuitive (wrong?) parenthesis when combining exp() and powers HOT 16
- Function docstring and reduce_assignments enabled does not play nice HOT 2
- Include .tex output examples in latexify_py/examples/examples.ipynb HOT 3
- math.pow not working properly on google colab HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from latexify_py.