Support for SciPy integrate package
Description
Adding support for the SciPy's integrate package would be useful. The quad, dblquad, and tplquad methods are used for single, double, and triple integrals respectively and they seem like a good starting point. You can read more about the methods here: https://docs.scipy.org/doc/scipy/tutorial/integrate.html. Not sure if there will need to be restrictions on these methods, but I appreciate any tips/suggestions for going about this.
Additional Flake8 Formatting Issue
I also ran the check.sh script before working on this feature and I noticed that the Flake8 formatting check was failing for long lines. Someone may have already fixed this but if they haven't, I can include the formatting corrections in with the SciPy work.
I guessed we can support the most simplest case, i.e., self-contained formulas:
scipy.integrate.quad(lambda x: f(x), a, b)
into:
$$\int_{a}^{b} f(x) dx$$
If the first argument is a reference to another callable, we need additional treatment. E.g.,
def f(x):
return g(x)
def myint():
return quad(f, a, b)
It would be good if we get $\mathrm{myint}() = \int_{a}^{b} g(x) dx$, but I also guess we also need some general solution to integrate multiple functions. This feature could be discussed separately.
As for flake8 failures, is it happening in the current main?
Yes, the failures are happening on the current main and I've pulled to verify that it is up to date. I'm getting E501 errors for lines being longer than 79 characters. Do you want to increase the maximum line length or just wrap the lines so they meet this requirement?
Currently the length limit is set to 88: https://github.com/google/latexify_py/blob/7f13cb6aa7346084617d84a6b51b417c9ed6e49c/pyproject.toml#L75
I think your runtime doesn't read pyproject.toml for some reason. Please check it.
You're right, thanks for clarifying! I'll investigate why pyproject.toml isn't being read
I also get the issue where ./checks.sh updates some files, and I have to run python3 black src to fix it. I think something later in the script undos the work black does.
black and isort updates the file unless the --check option, and this behavior is disabled in the current main. If you still get some errors, please make another issue for it. I'd like to focus on the SciPy feature in this issue.
Probably would add under Special treatments for some functions, but would want to match integrate.quad, not just the function name? Matching quad seems too ambiguous.
It's also getting to the point where we have lots of "special treatments", so maybe it's time to make this into a config value? But I think it's important here to choose carefully the default values for this config value. It's important that for very commonly used functions, that the behavior is default to handle specially, but for functions like zeros maybe this should have to be user specified.
Matching quad seems too ambiguous.
Yes I agreed that. I think this kind of feature should be provided as a plugin to avoid the confusion of the default behavior. One possible interface may be:
import latexify
from latexify.plugins.scipy import integrate
@latexify.function(plugins=[integrate])
def f(x):
...
Here latexify.plugins.scipy.integrate defines several expression rules that are applied additionally, e.g., quad to $\int$.
This design may be useful for any other kind of extensions IMO (and also provides a way to implement third-party extensions).
This is a great idea. Since there's probably multiple packages that define integration methods, this would solve trying to figure out which format it's in.
Since we want this to support third-party extensions, it would mean that throughout the generation process, we need to check the integrations and let them hook into the process, right? Each integration would be fully self contained, and would need no additional code in the generation process to make them work.
Let's go to the issue I created.