From ffb3e0651add4602200669fde2c26fc06219a918 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Fri, 12 Jan 2024 13:29:46 +0100 Subject: [PATCH 01/14] Working version of elm_weights --- elm_weights.ipynb | 579 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 579 insertions(+) create mode 100644 elm_weights.ipynb diff --git a/elm_weights.ipynb b/elm_weights.ipynb new file mode 100644 index 00000000..29038a68 --- /dev/null +++ b/elm_weights.ipynb @@ -0,0 +1,579 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "import Pkg" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/RootedTrees.jl/Project.toml`\n", + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/RootedTrees.jl/Manifest.toml`\n" + ] + } + ], + "source": [ + "Pkg.add(\"LaTeXStrings\")" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "using RootedTrees\n", + "using LaTeXStrings\n" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "elm_weights (generic function with 1 method)" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "function elm_weights(t::RootedTree)\n", + " # Creating enough indices for the elementary weights\n", + " a = collect('d':'z') # all letters except of a,b and c\n", + " p = order(t)\n", + " n = ceil(Int,p/23)\n", + " alphabet = String[]\n", + " if n == 1\n", + " alphabet = [string(letter) for letter in a]\n", + " else\n", + " for i in 1:n\n", + " alphabet = vcat(alphabet,[letter * string(i) for letter in a])\n", + " end\n", + " end\n", + "\n", + " substrings = String[]\n", + " first_index = splice!(alphabet,1)\n", + " indices = [first_index]\n", + "\n", + " prev_tree = 0\n", + " tree_count = 1\n", + " for subtree in SubtreeIterator(t)\n", + " if subtree == prev_tree\n", + " tree_count += 1\n", + " continue\n", + " elseif tree_count > 1\n", + " if length(prev_tree.level_sequence) == 1\n", + " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", + " else\n", + " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", + " end\n", + " end\n", + " prev_tree = copy(subtree)\n", + " tree_count = 1\n", + " substring, idx = elm_weights_rec!(subtree,first_index,alphabet)\n", + " indices = vcat(indices,idx)\n", + " push!(substrings,substring)\n", + " end\n", + " if tree_count > 1\n", + " if length(prev_tree.level_sequence) == 1\n", + " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", + " else\n", + " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", + " end\n", + " end\n", + " pushfirst!(substrings,\"\\\\sum_{$(join(indices,\", \"))}b_{$(first_index)}\")\n", + " return latexstring(join(substrings))\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "elm_weights_rec! (generic function with 1 method)" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "function elm_weights_rec!(t::RootedTree,last_index,alphabet)\n", + " if length(t.level_sequence) == 1\n", + " return \"c_{$(last_index)}\", []\n", + " else\n", + " substrings = String[]\n", + " indices = String[]\n", + " if t.level_sequence[1] != 1 # Specialcase: Complete Tree\n", + " push!(substrings,\"a_{$(last_index),$(alphabet[1])}\")\n", + " index = splice!(alphabet,1)\n", + " push!(indices,index)\n", + " end\n", + " prev_tree = 0\n", + " tree_count = 1\n", + " for subtree in SubtreeIterator(t)\n", + " if subtree == prev_tree\n", + " tree_count += 1\n", + " continue\n", + " elseif tree_count > 1\n", + " if length(prev_tree.level_sequence) == 1\n", + " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", + " else\n", + " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", + " end\n", + " end\n", + " prev_tree = copy(subtree)\n", + " tree_count = 1\n", + " substring, idx = elm_weights_rec!(subtree,index,alphabet)\n", + " indices = vcat(indices,idx)\n", + " push!(substrings,substring)\n", + " end\n", + " if tree_count > 1\n", + " if length(prev_tree.level_sequence) == 1\n", + " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", + " else\n", + " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", + " end\n", + " end\n", + " return join(substrings), indices\n", + " end\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d}b_{d}$" + ], + "text/plain": [ + "L\"$\\sum_{d}b_{d}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d}b_{d}c_{d}$" + ], + "text/plain": [ + "L\"$\\sum_{d}b_{d}c_{d}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e}b_{d}a_{d,e}c_{e}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d}b_{d}c_{d}^{2}$" + ], + "text/plain": [ + "L\"$\\sum_{d}b_{d}c_{d}^{2}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 4]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 3]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 2, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d}b_{d}c_{d}^{3}$" + ], + "text/plain": [ + "L\"$\\sum_{d}b_{d}c_{d}^{3}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 4, 5]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e, f, g}b_{d}a_{d,e}a_{e,f}a_{f,g}c_{g}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e, f, g}b_{d}a_{d,e}a_{e,f}a_{f,g}c_{g}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 4, 4]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}^{2}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}^{2}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 4, 3]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{e}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{e}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 4, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{d}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{d}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 3, 3]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 3, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}c_{d}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}c_{d}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 2, 3]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e}b_{d}(a_{d,e}c_{e})^{2}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e}b_{d}(a_{d,e}c_{e})^{2}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 3, 2, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}^{2}$" + ], + "text/plain": [ + "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}^{2}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "RootedTree{Int64}: [1, 2, 2, 2, 2]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\sum_{d}b_{d}c_{d}^{4}$" + ], + "text/plain": [ + "L\"$\\sum_{d}b_{d}c_{d}^{4}$\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "here\n", + "here\n", + "here\n", + "here\n", + "here\n", + "here\n", + "here\n", + "here\n" + ] + } + ], + "source": [ + "for i in 1:5\n", + " for t in RootedTreeIterator(i)\n", + " display(t)\n", + " display(elm_weights(t))\n", + " end\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.10.0", + "language": "julia", + "name": "julia-1.10" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 0077d5755b923f8da60e136fa7f4fd43b8ddf758 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Sat, 20 Jan 2024 23:13:59 +0100 Subject: [PATCH 02/14] Final changes for pr --- Project.toml | 2 +- docs/src/tutorials/basics.md | 10 +++++ src/RootedTrees.jl | 86 +++++++++++++++++++++++++++++++++++- test/runtests.jl | 31 +++++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index c3ae61cd..e28e8452 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RootedTrees" uuid = "47965b36-3f3e-11e9-0dcf-4570dfd42a8c" authors = ["Hendrik Ranocha and contributors"] -version = "2.20.0" +version = "2.21.0" [deps] LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" diff --git a/docs/src/tutorials/basics.md b/docs/src/tutorials/basics.md index 149327f5..0e363b4e 100644 --- a/docs/src/tutorials/basics.md +++ b/docs/src/tutorials/basics.md @@ -84,6 +84,16 @@ In LaTeX this results in the following output: ![latex-elementary_differentials](https://user-images.githubusercontent.com/125130707/282897199-4967fe07-a370-4d64-b671-84f578a52391.png) +Similarly, to get the elemantary weight, corresponding to a `RootedTree`, as a [`LaTeXString`](https://github.com/JuliaStrings/LaTeXStrings.jl), you can use [`elementary_weight_latexstring`](@ref). + +```@example basics +for t in RootedTreeIterator(4) + println(elementary_weight_latexstring(t)) +end +``` + +![latex-elementary_weight_latexstring]() + ## Number of trees diff --git a/src/RootedTrees.jl b/src/RootedTrees.jl index a8683e52..6ecfba3c 100644 --- a/src/RootedTrees.jl +++ b/src/RootedTrees.jl @@ -17,7 +17,7 @@ end export RootedTree, rootedtree, rootedtree!, RootedTreeIterator, ColoredRootedTree, BicoloredRootedTree, BicoloredRootedTreeIterator -export butcher_representation, elementary_differential +export butcher_representation, elementary_differential, elementary_weight_latexstring export α, β, γ, density, σ, symmetry, order, root_color @@ -1453,6 +1453,90 @@ function rec_elementary_differential(t::RootedTree) return el_diff end +""" + elementary_weight_latexstring(t::RootedTree) + +Returns the elementary_weight as a `LaTeXString` +from the package [LaTeXStrings.jl](https://github.com/JuliaStrings/LaTeXStrings.jl). +""" +function elementary_weight_latexstring(t::RootedTree) + # Creating the alphabet for the indices + a = collect('d':'z') # all letters except of a,b and c + p = order(t) + n = ceil(Int, p / 23) + alphabet = String[] + # if the tree could need more than the 23 available letters, the letter get a number as a suffix + if n == 1 + alphabet = [string(letter) for letter in a] + else + for i in 1:n + alphabet = vcat(alphabet, [letter * string(i) for letter in a]) + end + end + + + substrings = String[] + first_index = splice!(alphabet, 1) + indices = [first_index] + + substring, idx, _ = elm_weights_rec!(t, first_index, alphabet) # Call the recursive function + indices = vcat(indices, idx) + push!(substrings, substring) + + pushfirst!(substrings, "\\sum_{$(join(indices,", "))}b_{$(first_index)}") + return latexstring(join(substrings)) +end + +# Function used to go recursively through the RootedTree +# to generate the elementary weight of the tree. +function elm_weights_rec!(t::RootedTree, last_index, a) + alphabet = copy(a) + # leaf-node + if length(t.level_sequence) == 1 && t.level_sequence[1] != 1 + return "c_{$(last_index)}", [], alphabet + else + substrings = String[] + indices = String[] + if t.level_sequence[1] != 1 # Specialcase: Complete Tree + push!(substrings, "a_{$(last_index),$(alphabet[1])}") + index = splice!(alphabet, 1) + push!(indices, index) + else + index = last_index + end + # counting identical trees + prev_tree = 0 + tree_count = 1 + for subtree in SubtreeIterator(t) + if subtree == prev_tree + tree_count += 1 + continue + # When reaching the last one of identical trees, the substring gets the number of trees as an exponent + elseif tree_count > 1 + if length(prev_tree.level_sequence) == 1 + substrings[end] = "$(substrings[end])^{$tree_count}" + else + substrings[end] = "($(substrings[end]))^{$tree_count}" + end + end + prev_tree = copy(subtree) + tree_count = 1 + substring, idx, alphabet = elm_weights_rec!(subtree, index, alphabet) + indices = vcat(indices, idx) + push!(substrings, substring) + end + # Specialcase: The identical trees were the last ones + if tree_count > 1 + if length(prev_tree.level_sequence) == 1 + substrings[end] = "$(substrings[end])^{$tree_count}" + else + substrings[end] = "($(substrings[end]))^{$tree_count}" + end + end + return join(substrings), indices, alphabet + end +end + include("colored_trees.jl") include("latexify.jl") include("plot_recipes.jl") diff --git a/test/runtests.jl b/test/runtests.jl index 91adbaa7..4993fe38 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -304,6 +304,7 @@ using Aqua: Aqua @test butcher_representation(empty(t1)) == "∅" @test RootedTrees.latexify(empty(t1)) == "\\varnothing" @test elementary_differential(t1) == L"$f$" + @test elementary_weight_latexstring(t1) == L"$\sum_{d}b_{d}$" @inferred order(t1) @inferred σ(t1) @@ -325,6 +326,7 @@ using Aqua: Aqua @test latexify(t2) == latex_string @test RootedTrees.subtrees(t2) == [rootedtree([2])] @test elementary_differential(t2) == L"$f^{\prime}f$" + @test elementary_weight_latexstring(t2) == L"$\sum_{d}b_{d}c_{d}$" t3 = rootedtree([1, 2, 2]) @test order(t3) == 3 @@ -339,6 +341,7 @@ using Aqua: Aqua @test latexify(t3) == latex_string @test RootedTrees.subtrees(t3) == [rootedtree([2]), rootedtree([2])] @test elementary_differential(t3) == L"$f^{\prime\prime}(f, f)$" + @test elementary_weight_latexstring(t3) == L"$\sum_{d}b_{d}c_{d}^{2}$" t4 = rootedtree([1, 2, 3]) @test order(t4) == 3 @@ -353,6 +356,7 @@ using Aqua: Aqua @test latexify(t4) == latex_string @test RootedTrees.subtrees(t4) == [rootedtree([2, 3])] @test elementary_differential(t4) == L"$f^{\prime}f^{\prime}f$" + @test elementary_weight_latexstring(t4) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}$" t5 = rootedtree([1, 2, 2, 2]) @test order(t5) == 4 @@ -365,6 +369,7 @@ using Aqua: Aqua @test RootedTrees.subtrees(t5) == [rootedtree([2]), rootedtree([2]), rootedtree([2])] @test elementary_differential(t5) == L"$f^{\prime\prime\prime}(f, f, f)$" + @test elementary_weight_latexstring(t5) == L"$\sum_{d}b_{d}c_{d}^{3}$" t6 = rootedtree([1, 2, 2, 3]) @inferred RootedTrees.subtrees(t6) @@ -377,6 +382,7 @@ using Aqua: Aqua @test butcher_representation(t6) == "[[τ]τ]" @test RootedTrees.subtrees(t6) == [rootedtree([2, 3]), rootedtree([2])] @test elementary_differential(t6) == L"$f^{\prime\prime}(f^{\prime}f, f)$" + @test elementary_weight_latexstring(t6) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$" t7 = rootedtree([1, 2, 3, 3]) @test order(t7) == 4 @@ -386,6 +392,7 @@ using Aqua: Aqua @test t7 == t1 ∘ t3 @test butcher_representation(t7) == "[[τ²]]" @test elementary_differential(t7) == L"$f^{\prime}f^{\prime\prime}(f, f)$" + @test elementary_weight_latexstring(t7) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}$" t8 = rootedtree([1, 2, 3, 4]) @test order(t8) == 4 @@ -395,6 +402,8 @@ using Aqua: Aqua @test t8 == t1 ∘ t4 @test butcher_representation(t8) == "[[[τ]]]" @test elementary_differential(t8) == L"$f^{\prime}f^{\prime}f^{\prime}f$" + @test elementary_weight_latexstring(t8) == + L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}$" t9 = rootedtree([1, 2, 2, 2, 2]) @test order(t9) == 5 @@ -405,6 +414,7 @@ using Aqua: Aqua @test t9 == t5 ∘ t1 @test butcher_representation(t9) == "[τ⁴]" @test elementary_differential(t9) == L"$f^{(4)}(f, f, f, f)$" + @test elementary_weight_latexstring(t9) == L"$\sum_{d}b_{d}c_{d}^{4}$" t10 = rootedtree([1, 2, 2, 2, 3]) @test order(t10) == 5 @@ -416,6 +426,8 @@ using Aqua: Aqua @test butcher_representation(t10) == "[[τ]τ²]" @test elementary_differential(t10) == L"$f^{\prime\prime\prime}(f^{\prime}f, f, f)$" + @test elementary_weight_latexstring(t10) == + L"$\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}^{2}$" t11 = rootedtree([1, 2, 2, 3, 3]) @test order(t11) == 5 @@ -426,6 +438,8 @@ using Aqua: Aqua @test butcher_representation(t11) == "[[τ²]τ]" @test elementary_differential(t11) == L"$f^{\prime\prime}(f^{\prime\prime}(f, f), f)$" + @test elementary_weight_latexstring(t11) == + L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}c_{d}$" t12 = rootedtree([1, 2, 2, 3, 4]) @test order(t12) == 5 @@ -437,6 +451,8 @@ using Aqua: Aqua @test butcher_representation(t12) == "[[[τ]]τ]" @test elementary_differential(t12) == L"$f^{\prime\prime}(f^{\prime}f^{\prime}f, f)$" + @test elementary_weight_latexstring(t12) == + L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{d}$" t13 = rootedtree([1, 2, 3, 2, 3]) @test order(t13) == 5 @@ -448,6 +464,8 @@ using Aqua: Aqua @test butcher_representation(t13) == "[[τ][τ]]" @test elementary_differential(t13) == L"$f^{\prime\prime}(f^{\prime}f, f^{\prime}f)$" + @test elementary_weight_latexstring(t13) == + L"$\sum_{d, e}b_{d}(a_{d,e}c_{e})^{2}$" t14 = rootedtree([1, 2, 3, 3, 3]) @test order(t14) == 5 @@ -459,6 +477,7 @@ using Aqua: Aqua @test butcher_representation(t14) == "[[τ³]]" @test elementary_differential(t14) == L"$f^{\prime}f^{\prime\prime\prime}(f, f, f)$" + @test elementary_weight_latexstring(t14) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$" t15 = rootedtree([1, 2, 3, 3, 4]) @test order(t15) == 5 @@ -470,6 +489,8 @@ using Aqua: Aqua @test butcher_representation(t15) == "[[[τ]τ]]" @test elementary_differential(t15) == L"$f^{\prime}f^{\prime\prime}(f^{\prime}f, f)$" + @test elementary_weight_latexstring(t15) == + L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{e}$" t16 = rootedtree([1, 2, 3, 4, 4]) @test order(t16) == 5 @@ -481,6 +502,8 @@ using Aqua: Aqua @test butcher_representation(t16) == "[[[τ²]]]" @test elementary_differential(t16) == L"$f^{\prime}f^{\prime}f^{\prime\prime}(f, f)$" + @test elementary_weight_latexstring(t16) == + L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}^{2}$" t17 = rootedtree([1, 2, 3, 4, 5]) @test order(t17) == 5 @@ -492,6 +515,14 @@ using Aqua: Aqua @test butcher_representation(t17) == "[[[[τ]]]]" @test elementary_differential(t17) == L"$f^{\prime}f^{\prime}f^{\prime}f^{\prime}f$" + @test elementary_weight_latexstring(t17) == + L"$\sum_{d, e, f, g}b_{d}a_{d,e}a_{e,f}a_{f,g}c_{g}$" + + # test elementary_weight_latexstring which needs more than 23 indices + + t18 = rootedtree(collect(1:25)) + @test elementary_weight_latexstring(t18) == + L"$\sum_{d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1, q1, r1, s1, t1, u1, v1, w1, x1, y1, z1, d2}b_{d1}a_{d1,e1}a_{e1,f1}a_{f1,g1}a_{g1,h1}a_{h1,i1}a_{i1,j1}a_{j1,k1}a_{k1,l1}a_{l1,m1}a_{m1,n1}a_{n1,o1}a_{o1,p1}a_{p1,q1}a_{q1,r1}a_{r1,s1}a_{s1,t1}a_{t1,u1}a_{u1,v1}a_{v1,w1}a_{w1,x1}a_{x1,y1}a_{y1,z1}a_{z1,d2}c_{d2}$" # test non-canonical representation level_sequence = [1, 2, 3, 2, 3, 4, 2, 3, 2, 3, 4, 5, 6, 2, 3, 4] From b203f251985ce63efea868d65dc44ee2265b32b4 Mon Sep 17 00:00:00 2001 From: Philipp <125130707+pw0lf@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:17:57 +0100 Subject: [PATCH 03/14] Delete elm_weights.ipynb --- elm_weights.ipynb | 579 ---------------------------------------------- 1 file changed, 579 deletions(-) delete mode 100644 elm_weights.ipynb diff --git a/elm_weights.ipynb b/elm_weights.ipynb deleted file mode 100644 index 29038a68..00000000 --- a/elm_weights.ipynb +++ /dev/null @@ -1,579 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [], - "source": [ - "import Pkg" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/RootedTrees.jl/Project.toml`\n", - "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/RootedTrees.jl/Manifest.toml`\n" - ] - } - ], - "source": [ - "Pkg.add(\"LaTeXStrings\")" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [], - "source": [ - "using RootedTrees\n", - "using LaTeXStrings\n" - ] - }, - { - "cell_type": "code", - "execution_count": 117, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "elm_weights (generic function with 1 method)" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "function elm_weights(t::RootedTree)\n", - " # Creating enough indices for the elementary weights\n", - " a = collect('d':'z') # all letters except of a,b and c\n", - " p = order(t)\n", - " n = ceil(Int,p/23)\n", - " alphabet = String[]\n", - " if n == 1\n", - " alphabet = [string(letter) for letter in a]\n", - " else\n", - " for i in 1:n\n", - " alphabet = vcat(alphabet,[letter * string(i) for letter in a])\n", - " end\n", - " end\n", - "\n", - " substrings = String[]\n", - " first_index = splice!(alphabet,1)\n", - " indices = [first_index]\n", - "\n", - " prev_tree = 0\n", - " tree_count = 1\n", - " for subtree in SubtreeIterator(t)\n", - " if subtree == prev_tree\n", - " tree_count += 1\n", - " continue\n", - " elseif tree_count > 1\n", - " if length(prev_tree.level_sequence) == 1\n", - " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", - " else\n", - " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", - " end\n", - " end\n", - " prev_tree = copy(subtree)\n", - " tree_count = 1\n", - " substring, idx = elm_weights_rec!(subtree,first_index,alphabet)\n", - " indices = vcat(indices,idx)\n", - " push!(substrings,substring)\n", - " end\n", - " if tree_count > 1\n", - " if length(prev_tree.level_sequence) == 1\n", - " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", - " else\n", - " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", - " end\n", - " end\n", - " pushfirst!(substrings,\"\\\\sum_{$(join(indices,\", \"))}b_{$(first_index)}\")\n", - " return latexstring(join(substrings))\n", - "end" - ] - }, - { - "cell_type": "code", - "execution_count": 126, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "elm_weights_rec! (generic function with 1 method)" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "function elm_weights_rec!(t::RootedTree,last_index,alphabet)\n", - " if length(t.level_sequence) == 1\n", - " return \"c_{$(last_index)}\", []\n", - " else\n", - " substrings = String[]\n", - " indices = String[]\n", - " if t.level_sequence[1] != 1 # Specialcase: Complete Tree\n", - " push!(substrings,\"a_{$(last_index),$(alphabet[1])}\")\n", - " index = splice!(alphabet,1)\n", - " push!(indices,index)\n", - " end\n", - " prev_tree = 0\n", - " tree_count = 1\n", - " for subtree in SubtreeIterator(t)\n", - " if subtree == prev_tree\n", - " tree_count += 1\n", - " continue\n", - " elseif tree_count > 1\n", - " if length(prev_tree.level_sequence) == 1\n", - " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", - " else\n", - " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", - " end\n", - " end\n", - " prev_tree = copy(subtree)\n", - " tree_count = 1\n", - " substring, idx = elm_weights_rec!(subtree,index,alphabet)\n", - " indices = vcat(indices,idx)\n", - " push!(substrings,substring)\n", - " end\n", - " if tree_count > 1\n", - " if length(prev_tree.level_sequence) == 1\n", - " substrings[end] = \"$(substrings[end])^{$tree_count}\"\n", - " else\n", - " substrings[end] = \"($(substrings[end]))^{$tree_count}\"\n", - " end\n", - " end\n", - " return join(substrings), indices\n", - " end\n", - "end" - ] - }, - { - "cell_type": "code", - "execution_count": 127, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d}b_{d}$" - ], - "text/plain": [ - "L\"$\\sum_{d}b_{d}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d}b_{d}c_{d}$" - ], - "text/plain": [ - "L\"$\\sum_{d}b_{d}c_{d}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e}b_{d}a_{d,e}c_{e}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d}b_{d}c_{d}^{2}$" - ], - "text/plain": [ - "L\"$\\sum_{d}b_{d}c_{d}^{2}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 4]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 3]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 2, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d}b_{d}c_{d}^{3}$" - ], - "text/plain": [ - "L\"$\\sum_{d}b_{d}c_{d}^{3}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 4, 5]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e, f, g}b_{d}a_{d,e}a_{e,f}a_{f,g}c_{g}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e, f, g}b_{d}a_{d,e}a_{e,f}a_{f,g}c_{g}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 4, 4]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}^{2}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}^{2}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 4, 3]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{e}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{e}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 4, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{d}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{d}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 3, 3]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 3, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}c_{d}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}c_{d}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 2, 3]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e}b_{d}(a_{d,e}c_{e})^{2}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e}b_{d}(a_{d,e}c_{e})^{2}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 3, 2, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}^{2}$" - ], - "text/plain": [ - "L\"$\\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}^{2}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "RootedTree{Int64}: [1, 2, 2, 2, 2]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "$\\sum_{d}b_{d}c_{d}^{4}$" - ], - "text/plain": [ - "L\"$\\sum_{d}b_{d}c_{d}^{4}$\"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "here\n", - "here\n", - "here\n", - "here\n", - "here\n", - "here\n", - "here\n", - "here\n" - ] - } - ], - "source": [ - "for i in 1:5\n", - " for t in RootedTreeIterator(i)\n", - " display(t)\n", - " display(elm_weights(t))\n", - " end\n", - "end" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Julia 1.10.0", - "language": "julia", - "name": "julia-1.10" - }, - "language_info": { - "file_extension": ".jl", - "mimetype": "application/julia", - "name": "julia", - "version": "1.10.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} From 4626e9f801885d4c21914c514d4fc2c556cc6cc8 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Sat, 20 Jan 2024 23:30:59 +0100 Subject: [PATCH 04/14] Fixed typo --- docs/src/tutorials/basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/tutorials/basics.md b/docs/src/tutorials/basics.md index 0e363b4e..5f2c92dc 100644 --- a/docs/src/tutorials/basics.md +++ b/docs/src/tutorials/basics.md @@ -84,7 +84,7 @@ In LaTeX this results in the following output: ![latex-elementary_differentials](https://user-images.githubusercontent.com/125130707/282897199-4967fe07-a370-4d64-b671-84f578a52391.png) -Similarly, to get the elemantary weight, corresponding to a `RootedTree`, as a [`LaTeXString`](https://github.com/JuliaStrings/LaTeXStrings.jl), you can use [`elementary_weight_latexstring`](@ref). +Similarly, to get the elementary weight, corresponding to a `RootedTree`, as a [`LaTeXString`](https://github.com/JuliaStrings/LaTeXStrings.jl), you can use [`elementary_weight_latexstring`](@ref). ```@example basics for t in RootedTreeIterator(4) From dd6a73a9652fd459dae2135221451ec17c75ff53 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Sat, 20 Jan 2024 23:32:37 +0100 Subject: [PATCH 05/14] Added changes by JuliaFormatter --- src/RootedTrees.jl | 3 +-- test/runtests.jl | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/RootedTrees.jl b/src/RootedTrees.jl index 6ecfba3c..125071f2 100644 --- a/src/RootedTrees.jl +++ b/src/RootedTrees.jl @@ -1474,7 +1474,6 @@ function elementary_weight_latexstring(t::RootedTree) end end - substrings = String[] first_index = splice!(alphabet, 1) indices = [first_index] @@ -1511,7 +1510,7 @@ function elm_weights_rec!(t::RootedTree, last_index, a) if subtree == prev_tree tree_count += 1 continue - # When reaching the last one of identical trees, the substring gets the number of trees as an exponent + # When reaching the last one of identical trees, the substring gets the number of trees as an exponent elseif tree_count > 1 if length(prev_tree.level_sequence) == 1 substrings[end] = "$(substrings[end])^{$tree_count}" diff --git a/test/runtests.jl b/test/runtests.jl index 4993fe38..52f0f578 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -382,7 +382,8 @@ using Aqua: Aqua @test butcher_representation(t6) == "[[τ]τ]" @test RootedTrees.subtrees(t6) == [rootedtree([2, 3]), rootedtree([2])] @test elementary_differential(t6) == L"$f^{\prime\prime}(f^{\prime}f, f)$" - @test elementary_weight_latexstring(t6) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$" + @test elementary_weight_latexstring(t6) == + L"$\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$" t7 = rootedtree([1, 2, 3, 3]) @test order(t7) == 4 @@ -477,7 +478,8 @@ using Aqua: Aqua @test butcher_representation(t14) == "[[τ³]]" @test elementary_differential(t14) == L"$f^{\prime}f^{\prime\prime\prime}(f, f, f)$" - @test elementary_weight_latexstring(t14) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$" + @test elementary_weight_latexstring(t14) == + L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$" t15 = rootedtree([1, 2, 3, 3, 4]) @test order(t15) == 5 From 757089fc6a280a05478bd01d648412f595b2aeff Mon Sep 17 00:00:00 2001 From: philippwolf Date: Sat, 20 Jan 2024 23:43:00 +0100 Subject: [PATCH 06/14] Added test for codecoverage --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 52f0f578..54c5e069 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -526,6 +526,10 @@ using Aqua: Aqua @test elementary_weight_latexstring(t18) == L"$\sum_{d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1, q1, r1, s1, t1, u1, v1, w1, x1, y1, z1, d2}b_{d1}a_{d1,e1}a_{e1,f1}a_{f1,g1}a_{g1,h1}a_{h1,i1}a_{i1,j1}a_{j1,k1}a_{k1,l1}a_{l1,m1}a_{m1,n1}a_{n1,o1}a_{o1,p1}a_{p1,q1}a_{q1,r1}a_{r1,s1}a_{s1,t1}a_{t1,u1}a_{u1,v1}a_{v1,w1}a_{w1,x1}a_{x1,y1}a_{y1,z1}a_{z1,d2}c_{d2}$" + t19 = rootedtree([1, 2, 2, 3, 2, 3]) + @test elementary_weight_latexstring(t19) == + L"$\sum_{d, e}b_{d}(a_{d,e}c_{e})^{2}c_{d}$" + # test non-canonical representation level_sequence = [1, 2, 3, 2, 3, 4, 2, 3, 2, 3, 4, 5, 6, 2, 3, 4] @test σ(rootedtree(level_sequence)) == σ(RootedTrees.RootedTree(level_sequence)) From ad25f02696233660d0fb855e78346766efe6ce6f Mon Sep 17 00:00:00 2001 From: philippwolf Date: Wed, 24 Jan 2024 17:24:10 +0100 Subject: [PATCH 07/14] Renamed elementary_differential to elementary_differential_latexstring and deprecated the old one --- docs/src/tutorials/basics.md | 4 ++-- src/RootedTrees.jl | 6 ++++-- test/runtests.jl | 34 +++++++++++++++++----------------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/docs/src/tutorials/basics.md b/docs/src/tutorials/basics.md index 5f2c92dc..1a35e577 100644 --- a/docs/src/tutorials/basics.md +++ b/docs/src/tutorials/basics.md @@ -73,11 +73,11 @@ savefig("basics_tree.png"); nothing # hide ![](basics_tree.png) -To get the elementary differential, corresponding to a `RootedTree`, as a [`LaTeXString`](https://github.com/JuliaStrings/LaTeXStrings.jl), you can use [`elementary_differential`](@ref). +To get the elementary differential, corresponding to a `RootedTree`, as a [`LaTeXString`](https://github.com/JuliaStrings/LaTeXStrings.jl), you can use [`elementary_differential_latexstring`](@ref). ```@example basics for t in RootedTreeIterator(4) - println(elementary_differential(t)) + println(elementary_differential_latexstring(t)) end ``` In LaTeX this results in the following output: diff --git a/src/RootedTrees.jl b/src/RootedTrees.jl index 125071f2..d3cf1a78 100644 --- a/src/RootedTrees.jl +++ b/src/RootedTrees.jl @@ -1417,14 +1417,16 @@ function butcher_representation(t::RootedTree, normalize::Bool = true) return result end +@depracate elementary_differential(t::RootedTree) elementary_differential_latexstring(t) + """ - elementary_differential(t::RootedTree) + elementary_differential_latexstring(t::RootedTree) Returns the elementary differential as a `LaTeXString` from the package [LaTeXStrings.jl](https://github.com/JuliaStrings/LaTeXStrings.jl). """ -function elementary_differential(t::RootedTree) +function elementary_differential_latexstring(t::RootedTree) return latexstring(rec_elementary_differential(t)) end diff --git a/test/runtests.jl b/test/runtests.jl index 54c5e069..7f94b144 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -303,7 +303,7 @@ using Aqua: Aqua @test isempty(RootedTrees.subtrees(t1)) @test butcher_representation(empty(t1)) == "∅" @test RootedTrees.latexify(empty(t1)) == "\\varnothing" - @test elementary_differential(t1) == L"$f$" + @test elementary_differential_latexstring(t1) == L"$f$" @test elementary_weight_latexstring(t1) == L"$\sum_{d}b_{d}$" @inferred order(t1) @@ -325,7 +325,7 @@ using Aqua: Aqua @test RootedTrees.latexify(t2) == latex_string @test latexify(t2) == latex_string @test RootedTrees.subtrees(t2) == [rootedtree([2])] - @test elementary_differential(t2) == L"$f^{\prime}f$" + @test elementary_differential_latexstring(t2) == L"$f^{\prime}f$" @test elementary_weight_latexstring(t2) == L"$\sum_{d}b_{d}c_{d}$" t3 = rootedtree([1, 2, 2]) @@ -340,7 +340,7 @@ using Aqua: Aqua @test RootedTrees.latexify(t3) == latex_string @test latexify(t3) == latex_string @test RootedTrees.subtrees(t3) == [rootedtree([2]), rootedtree([2])] - @test elementary_differential(t3) == L"$f^{\prime\prime}(f, f)$" + @test elementary_differential_latexstring(t3) == L"$f^{\prime\prime}(f, f)$" @test elementary_weight_latexstring(t3) == L"$\sum_{d}b_{d}c_{d}^{2}$" t4 = rootedtree([1, 2, 3]) @@ -355,7 +355,7 @@ using Aqua: Aqua @test RootedTrees.latexify(t4) == latex_string @test latexify(t4) == latex_string @test RootedTrees.subtrees(t4) == [rootedtree([2, 3])] - @test elementary_differential(t4) == L"$f^{\prime}f^{\prime}f$" + @test elementary_differential_latexstring(t4) == L"$f^{\prime}f^{\prime}f$" @test elementary_weight_latexstring(t4) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}$" t5 = rootedtree([1, 2, 2, 2]) @@ -368,7 +368,7 @@ using Aqua: Aqua @test butcher_representation(t5) == "[τ³]" @test RootedTrees.subtrees(t5) == [rootedtree([2]), rootedtree([2]), rootedtree([2])] - @test elementary_differential(t5) == L"$f^{\prime\prime\prime}(f, f, f)$" + @test elementary_differential_latexstring(t5) == L"$f^{\prime\prime\prime}(f, f, f)$" @test elementary_weight_latexstring(t5) == L"$\sum_{d}b_{d}c_{d}^{3}$" t6 = rootedtree([1, 2, 2, 3]) @@ -381,7 +381,7 @@ using Aqua: Aqua @test t6 == t2 ∘ t2 == t4 ∘ t1 @test butcher_representation(t6) == "[[τ]τ]" @test RootedTrees.subtrees(t6) == [rootedtree([2, 3]), rootedtree([2])] - @test elementary_differential(t6) == L"$f^{\prime\prime}(f^{\prime}f, f)$" + @test elementary_differential_latexstring(t6) == L"$f^{\prime\prime}(f^{\prime}f, f)$" @test elementary_weight_latexstring(t6) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$" @@ -392,7 +392,7 @@ using Aqua: Aqua @test β(t7) == α(t7) * γ(t7) @test t7 == t1 ∘ t3 @test butcher_representation(t7) == "[[τ²]]" - @test elementary_differential(t7) == L"$f^{\prime}f^{\prime\prime}(f, f)$" + @test elementary_differential_latexstring(t7) == L"$f^{\prime}f^{\prime\prime}(f, f)$" @test elementary_weight_latexstring(t7) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}$" t8 = rootedtree([1, 2, 3, 4]) @@ -402,7 +402,7 @@ using Aqua: Aqua @test α(t8) == 1 @test t8 == t1 ∘ t4 @test butcher_representation(t8) == "[[[τ]]]" - @test elementary_differential(t8) == L"$f^{\prime}f^{\prime}f^{\prime}f$" + @test elementary_differential_latexstring(t8) == L"$f^{\prime}f^{\prime}f^{\prime}f$" @test elementary_weight_latexstring(t8) == L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}$" @@ -414,7 +414,7 @@ using Aqua: Aqua @test β(t9) == α(t9) * γ(t9) @test t9 == t5 ∘ t1 @test butcher_representation(t9) == "[τ⁴]" - @test elementary_differential(t9) == L"$f^{(4)}(f, f, f, f)$" + @test elementary_differential_latexstring(t9) == L"$f^{(4)}(f, f, f, f)$" @test elementary_weight_latexstring(t9) == L"$\sum_{d}b_{d}c_{d}^{4}$" t10 = rootedtree([1, 2, 2, 2, 3]) @@ -425,7 +425,7 @@ using Aqua: Aqua @test β(t10) == α(t10) * γ(t10) @test t10 == t3 ∘ t2 == t6 ∘ t1 @test butcher_representation(t10) == "[[τ]τ²]" - @test elementary_differential(t10) == + @test elementary_differential_latexstring(t10) == L"$f^{\prime\prime\prime}(f^{\prime}f, f, f)$" @test elementary_weight_latexstring(t10) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}^{2}$" @@ -437,7 +437,7 @@ using Aqua: Aqua @test α(t11) == 4 @test t11 == t2 ∘ t3 == t7 ∘ t1 @test butcher_representation(t11) == "[[τ²]τ]" - @test elementary_differential(t11) == + @test elementary_differential_latexstring(t11) == L"$f^{\prime\prime}(f^{\prime\prime}(f, f), f)$" @test elementary_weight_latexstring(t11) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}c_{d}$" @@ -450,7 +450,7 @@ using Aqua: Aqua @test β(t12) == α(t12) * γ(t12) @test t12 == t2 ∘ t4 == t8 ∘ t1 @test butcher_representation(t12) == "[[[τ]]τ]" - @test elementary_differential(t12) == + @test elementary_differential_latexstring(t12) == L"$f^{\prime\prime}(f^{\prime}f^{\prime}f, f)$" @test elementary_weight_latexstring(t12) == L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{d}$" @@ -463,7 +463,7 @@ using Aqua: Aqua @test β(t13) == α(t13) * γ(t13) @test t13 == t4 ∘ t2 @test butcher_representation(t13) == "[[τ][τ]]" - @test elementary_differential(t13) == + @test elementary_differential_latexstring(t13) == L"$f^{\prime\prime}(f^{\prime}f, f^{\prime}f)$" @test elementary_weight_latexstring(t13) == L"$\sum_{d, e}b_{d}(a_{d,e}c_{e})^{2}$" @@ -476,7 +476,7 @@ using Aqua: Aqua @test β(t14) == α(t14) * γ(t14) @test t14 == t1 ∘ t5 @test butcher_representation(t14) == "[[τ³]]" - @test elementary_differential(t14) == + @test elementary_differential_latexstring(t14) == L"$f^{\prime}f^{\prime\prime\prime}(f, f, f)$" @test elementary_weight_latexstring(t14) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{3}$" @@ -489,7 +489,7 @@ using Aqua: Aqua @test β(t15) == α(t15) * γ(t15) @test t15 == t1 ∘ t6 @test butcher_representation(t15) == "[[[τ]τ]]" - @test elementary_differential(t15) == + @test elementary_differential_latexstring(t15) == L"$f^{\prime}f^{\prime\prime}(f^{\prime}f, f)$" @test elementary_weight_latexstring(t15) == L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}c_{e}$" @@ -502,7 +502,7 @@ using Aqua: Aqua @test β(t16) == α(t16) * γ(t16) @test t16 == t1 ∘ t7 @test butcher_representation(t16) == "[[[τ²]]]" - @test elementary_differential(t16) == + @test elementary_differential_latexstring(t16) == L"$f^{\prime}f^{\prime}f^{\prime\prime}(f, f)$" @test elementary_weight_latexstring(t16) == L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}^{2}$" @@ -515,7 +515,7 @@ using Aqua: Aqua @test β(t17) == α(t17) * γ(t17) @test t17 == t1 ∘ t8 @test butcher_representation(t17) == "[[[[τ]]]]" - @test elementary_differential(t17) == + @test elementary_differential_latexstring(t17) == L"$f^{\prime}f^{\prime}f^{\prime}f^{\prime}f$" @test elementary_weight_latexstring(t17) == L"$\sum_{d, e, f, g}b_{d}a_{d,e}a_{e,f}a_{f,g}c_{g}$" From 675447d1d58444c82c2edd737ae54fa190427228 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Wed, 24 Jan 2024 17:24:45 +0100 Subject: [PATCH 08/14] Changed version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e28e8452..1aafc9c5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RootedTrees" uuid = "47965b36-3f3e-11e9-0dcf-4570dfd42a8c" authors = ["Hendrik Ranocha and contributors"] -version = "2.21.0" +version = "3.0.0" [deps] LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" From 7d39d5413dcdbcff7724ef69649b97bf3a74d093 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Wed, 24 Jan 2024 17:33:54 +0100 Subject: [PATCH 09/14] Forgot to export the new funciton --- src/RootedTrees.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RootedTrees.jl b/src/RootedTrees.jl index d3cf1a78..92d84f44 100644 --- a/src/RootedTrees.jl +++ b/src/RootedTrees.jl @@ -17,7 +17,7 @@ end export RootedTree, rootedtree, rootedtree!, RootedTreeIterator, ColoredRootedTree, BicoloredRootedTree, BicoloredRootedTreeIterator -export butcher_representation, elementary_differential, elementary_weight_latexstring +export butcher_representation, elementary_differential, elementary_differential_latexstring ,elementary_weight_latexstring export α, β, γ, density, σ, symmetry, order, root_color @@ -1417,7 +1417,7 @@ function butcher_representation(t::RootedTree, normalize::Bool = true) return result end -@depracate elementary_differential(t::RootedTree) elementary_differential_latexstring(t) +@deprecate elementary_differential(t::RootedTree) elementary_differential_latexstring(t) """ elementary_differential_latexstring(t::RootedTree) From fbed5621d0b9c701a80aa162bdf93233fff03bc5 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Wed, 24 Jan 2024 17:34:45 +0100 Subject: [PATCH 10/14] Added changes of the Formatter --- src/RootedTrees.jl | 3 ++- test/runtests.jl | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/RootedTrees.jl b/src/RootedTrees.jl index 92d84f44..faf01ee7 100644 --- a/src/RootedTrees.jl +++ b/src/RootedTrees.jl @@ -17,7 +17,8 @@ end export RootedTree, rootedtree, rootedtree!, RootedTreeIterator, ColoredRootedTree, BicoloredRootedTree, BicoloredRootedTreeIterator -export butcher_representation, elementary_differential, elementary_differential_latexstring ,elementary_weight_latexstring +export butcher_representation, elementary_differential, elementary_differential_latexstring, + elementary_weight_latexstring export α, β, γ, density, σ, symmetry, order, root_color diff --git a/test/runtests.jl b/test/runtests.jl index 7f94b144..98ade6ef 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -368,7 +368,8 @@ using Aqua: Aqua @test butcher_representation(t5) == "[τ³]" @test RootedTrees.subtrees(t5) == [rootedtree([2]), rootedtree([2]), rootedtree([2])] - @test elementary_differential_latexstring(t5) == L"$f^{\prime\prime\prime}(f, f, f)$" + @test elementary_differential_latexstring(t5) == + L"$f^{\prime\prime\prime}(f, f, f)$" @test elementary_weight_latexstring(t5) == L"$\sum_{d}b_{d}c_{d}^{3}$" t6 = rootedtree([1, 2, 2, 3]) @@ -381,7 +382,8 @@ using Aqua: Aqua @test t6 == t2 ∘ t2 == t4 ∘ t1 @test butcher_representation(t6) == "[[τ]τ]" @test RootedTrees.subtrees(t6) == [rootedtree([2, 3]), rootedtree([2])] - @test elementary_differential_latexstring(t6) == L"$f^{\prime\prime}(f^{\prime}f, f)$" + @test elementary_differential_latexstring(t6) == + L"$f^{\prime\prime}(f^{\prime}f, f)$" @test elementary_weight_latexstring(t6) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}c_{d}$" @@ -392,7 +394,8 @@ using Aqua: Aqua @test β(t7) == α(t7) * γ(t7) @test t7 == t1 ∘ t3 @test butcher_representation(t7) == "[[τ²]]" - @test elementary_differential_latexstring(t7) == L"$f^{\prime}f^{\prime\prime}(f, f)$" + @test elementary_differential_latexstring(t7) == + L"$f^{\prime}f^{\prime\prime}(f, f)$" @test elementary_weight_latexstring(t7) == L"$\sum_{d, e}b_{d}a_{d,e}c_{e}^{2}$" t8 = rootedtree([1, 2, 3, 4]) @@ -402,7 +405,8 @@ using Aqua: Aqua @test α(t8) == 1 @test t8 == t1 ∘ t4 @test butcher_representation(t8) == "[[[τ]]]" - @test elementary_differential_latexstring(t8) == L"$f^{\prime}f^{\prime}f^{\prime}f$" + @test elementary_differential_latexstring(t8) == + L"$f^{\prime}f^{\prime}f^{\prime}f$" @test elementary_weight_latexstring(t8) == L"$\sum_{d, e, f}b_{d}a_{d,e}a_{e,f}c_{f}$" From 9d8c7ef1db74a5285f10b1dbe6b719e0b16b9e3c Mon Sep 17 00:00:00 2001 From: Philipp <125130707+pw0lf@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:16:58 +0100 Subject: [PATCH 11/14] Update Project.toml Co-authored-by: Hendrik Ranocha --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1aafc9c5..e28e8452 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RootedTrees" uuid = "47965b36-3f3e-11e9-0dcf-4570dfd42a8c" authors = ["Hendrik Ranocha and contributors"] -version = "3.0.0" +version = "2.21.0" [deps] LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" From 73853ec1f79fe7d4810bb5db8e885d50ac7f1ecb Mon Sep 17 00:00:00 2001 From: Philipp <125130707+pw0lf@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:18:45 +0100 Subject: [PATCH 12/14] Update src/RootedTrees.jl Co-authored-by: Hendrik Ranocha --- src/RootedTrees.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RootedTrees.jl b/src/RootedTrees.jl index faf01ee7..adfa6ed0 100644 --- a/src/RootedTrees.jl +++ b/src/RootedTrees.jl @@ -17,7 +17,7 @@ end export RootedTree, rootedtree, rootedtree!, RootedTreeIterator, ColoredRootedTree, BicoloredRootedTree, BicoloredRootedTreeIterator -export butcher_representation, elementary_differential, elementary_differential_latexstring, +export butcher_representation, elementary_differential_latexstring, elementary_weight_latexstring export α, β, γ, density, σ, symmetry, order, root_color From 9550ae4170ea3d493bf02d6cff101f28296e7317 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Thu, 25 Jan 2024 11:22:15 +0100 Subject: [PATCH 13/14] Added picture for docu --- docs/src/tutorials/basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/tutorials/basics.md b/docs/src/tutorials/basics.md index 1a35e577..7b691172 100644 --- a/docs/src/tutorials/basics.md +++ b/docs/src/tutorials/basics.md @@ -92,7 +92,7 @@ for t in RootedTreeIterator(4) end ``` -![latex-elementary_weight_latexstring]() +![latex elemenary weights](https://private-user-images.githubusercontent.com/125130707/298310491-8a035faf-fd1a-4fc0-92be-c3387eb53177.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDYxNjY1ODAsIm5iZiI6MTcwNjE2NjI4MCwicGF0aCI6Ii8xMjUxMzA3MDcvMjk4MzEwNDkxLThhMDM1ZmFmLWZkMWEtNGZjMC05MmJlLWMzMzg3ZWI1MzE3Ny5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwMTI1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDEyNVQwNzA0NDBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kYzQyYjM0MWY0MDU5YWZlYzBmODA4MjFiZGIxN2E3YjhkYTdmZDNkYTU5NmI5OTEwNWFiZjg0OGZjNDg1MzZhJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.GB-PigOlQqenzgruzWg19qslzM6RXeX4xWwCNreOvNY) ## Number of trees From 96ca61bf0e9cb5952bb5d4e682a4509fc56b73e4 Mon Sep 17 00:00:00 2001 From: philippwolf Date: Thu, 25 Jan 2024 11:34:35 +0100 Subject: [PATCH 14/14] Deleted redundant part of code --- src/RootedTrees.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/RootedTrees.jl b/src/RootedTrees.jl index adfa6ed0..31b732b5 100644 --- a/src/RootedTrees.jl +++ b/src/RootedTrees.jl @@ -1515,11 +1515,7 @@ function elm_weights_rec!(t::RootedTree, last_index, a) continue # When reaching the last one of identical trees, the substring gets the number of trees as an exponent elseif tree_count > 1 - if length(prev_tree.level_sequence) == 1 - substrings[end] = "$(substrings[end])^{$tree_count}" - else - substrings[end] = "($(substrings[end]))^{$tree_count}" - end + substrings[end] = "($(substrings[end]))^{$tree_count}" end prev_tree = copy(subtree) tree_count = 1