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

Option to render elementary differentials using summation notation #103

Open
ketch opened this issue Feb 28, 2023 · 5 comments
Open

Option to render elementary differentials using summation notation #103

ketch opened this issue Feb 28, 2023 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ketch
Copy link
Collaborator

ketch commented Feb 28, 2023

There is one thing that's in the TOMS paper that BSeries.jl actually still doesn't do, which is to write the elementary differentials for an unspecified RHS function $f$ using the notation that is used e.g. in the books of Hairer et. al. -- see column 5 of the table from the paper:
Screen Shot 2023-02-28 at 8 16 32 AM

I would like to add this option. Here's some simple code that generates this as a LaTeX string:

function elementary_differential_string(t)
    indices = ["i","j","k","l","m","n"];
    labels = copy(indices[1:length(t.level_sequence)]);
    edstring = ""
    for i in 1:order(t)
        edstring *= "f^{"
        edstring *= labels[i]
        edstring *= "}_{"
        for j in i+1:order(t)
            if t.level_sequence[j] == t.level_sequence[i]
                break
            elseif t.level_sequence[j]-t.level_sequence[i] == 1
                edstring *= labels[j]
            end
        end
        edstring *= "} "
    end
    edstring = replace(edstring,"_{}"=>"")
    return edstring
end

Before going ahead, I wanted to get your opinion (@ranocha).

  • Is direct string generation the best approach? In principle we could generate the products of partial derivatives symbolically first and then render those. This is more elegant but otherwise I don't see an advantage to it.
  • How should the user specify that they want the elementary differentials in this form? My plan is to implement a global option like the one in RootedTrees.jl for how to render trees.
  • There is a minor issue of needing enough distinct index labels for a given tree. My plan is to just start with "i" and go through the end of the alphabet. In practice it seems unlikely that someone would work with a tree that exhausts this.
@ranocha
Copy link
Owner

ranocha commented Feb 28, 2023

That's a nice feature to have 👍

  • Generating the string directly sounds reasonable to me.

  • Which use case(s) do we want to support?

    • The elementary differentials can be printed like this when calling latexify(series).
    • There is a function printing the elementary differential associated to a rooted tree like this.

    In the first case, a global option is okay with me. However, I think the second use case would also be nice, e.g.,
    to generate the content of the table you have shown above automatically. We should find a good name for such
    a function and add it to RootedTrees.jl, since it's just about the trees, not about B-series. We could still have a global
    option in BSeries.jl for the first use case.

  • That sounds reasonable. You can get a list of these labels as 'i':'z'. We should just check whether the rooted tree is small enough and throw an error otherwise.

  • We may also think about doing this for colored rooted trees. Then, the functions need to get additional indices specifying the color.

@ranocha ranocha added the enhancement New feature or request label Feb 28, 2023
@ketch
Copy link
Collaborator Author

ketch commented Feb 28, 2023

Thanks!

We should find a good name for such a function and add it to RootedTrees.jl, since it's just about the trees, not about B-series.

I am fine with that, although mapping trees to elementary differentials is something that is only done in the context of B-series. Then again, I guess that everything in RootedTrees.jl is aimed at working with B-series, and not with rooted trees more generally. So it's a question about the scope of RootedTrees.jl, which is up to you. If we implement this functionality in RootedTrees.jl, then the option to use it in latexify(series) could also just be an argument that is passed to latexify.

I agree that it would be nice to extend this to colored trees, and seems straightforward.

I'll prepare a PR that implements "use case 2" in RootedTrees.jl.

@ranocha
Copy link
Owner

ranocha commented Feb 28, 2023

Great, thanks!

Yeah, the scope of RootedTrees.jl may be a bit unclear. In our description, we write

A collection of functionality around rooted trees to generate order conditions for Runge-Kutta methods

That's why we also have the basic types RungeKuttaMethod etc. in there, see https://sciml.github.io/RootedTrees.jl/stable/tutorials/RK_order_conditions/ Thus, I think it's totally fine to add the new functionality there.

@ketch
Copy link
Collaborator Author

ketch commented Mar 2, 2023

I've thought about this a bit more. Currently, there are no functions dealing with elementary differentials in RootedTrees.jl. There are functions dealing with elementary differentials in BSeries.jl. If we add the proposed functionality to RootedTrees.jl, then we'll have

  • Functionality for computing concrete elementary differentials in BSeries.jl
  • Functionality for computing abstract elementary differentials in RootedTrees.jl

It may be a bit confusing for users (as it is for me).

After looking through both packages, it seems to me that the only reasonable place to put this functionality is in BSeries.jl under src/latexify.jl, since that's where we currently define LatexifyElementaryDifferential. If we think this functionality belongs in RootedTrees.jl, I think we should move that file to RootedTrees.jl.

@ranocha
Copy link
Owner

ranocha commented Mar 3, 2023

You are right. Let's keep this in BSeries.jl.

@ranocha ranocha added the good first issue Good for newcomers label May 2, 2023
@ranocha ranocha mentioned this issue May 2, 2023
34 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants