Git Product home page Git Product logo

Comments (7)

odashi avatar odashi commented on April 28, 2024 1

@MAKMED1337 Not sure, but it looks there should be another option to control the behavior around $\exp$ .

from latexify_py.

odashi avatar odashi commented on April 28, 2024 1

I also think our current implementation (#125) naturally solves #65 (comment) , as users can choose whether exp is expanded or not.

from latexify_py.

MAKMED1337 avatar MAKMED1337 commented on April 28, 2024

Is it better expit(x) to be $\frac{1}{1+e^{-x}}$ ?

from latexify_py.

odashi avatar odashi commented on April 28, 2024

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 $\frac{1}{1+\exp{(-x)}}$ or $\frac{1}{1+e^{-x}}$

This also involves some caveats:

  • It causes infinite replacement if the rule has identity or cyclic rules: f(x) -> f(x), or f(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.

ZibingZhang avatar ZibingZhang commented on April 28, 2024

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.

odashi avatar odashi commented on April 28, 2024

I think non-elementary functions (erf, erfc, gamma, lgamma) should be avoided from this option. Other candidates look fine to me.

from latexify_py.

odashi avatar odashi commented on April 28, 2024

This is generally supported in the current implementation. We'd support individual functions in separate issues (if needed).

from latexify_py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.