<jupyter_start><jupyter_text>This notebook is part of https://github.com/AudioSceneDescriptionFormat/splines, see also https://splines.readthedocs.io/.[back to overview](natural.ipynb)  Non-Uniform Natural SplinesThe derivation is similar to[the uniform case](natural-uniform.ipynb),but this time the parameter intervals can have arbitrary values.<jupyter_code>import sympy as sp
sp.init_printing(order='grevlex')
from utility import NamedExpression
t = sp.symbols('t')<jupyter_output><empty_output><jupyter_text>Just like in the uniform case,we are considering two adjacent spline segments,but this time we must allow arbitrary parameter values:<jupyter_code>t3, t4, t5 = sp.symbols('t3:6')
b_monomial = sp.Matrix([t**3, t**2, t, 1]).T
b_monomial
coefficients3 = sp.symbols('a:dbm3')[::-1]
coefficients4 = sp.symbols('a:dbm4')[::-1]
b_monomial.dot(coefficients3)
p3 = NamedExpression(
    'pbm3',
    b_monomial.dot(coefficients3).subs(t, (t - t3)/(t4 - t3)))
p4 = NamedExpression(
    'pbm4',
    b_monomial.dot(coefficients4).subs(t, (t - t4)/(t5 - t4)))
display(p3, p4)
pd3 = p3.diff(t)
pd4 = p4.diff(t)
display(pd3, pd4)
equations = [
    p3.evaluated_at(t, t3).with_name('xbm3'),
    p3.evaluated_at(t, t4).with_name('xbm4'),
    p4.evaluated_at(t, t4).with_name('xbm4'),
    p4.evaluated_at(t, t5).with_name('xbm5'),
    pd3.evaluated_at(t, t3).with_name('xbmdot3'),
    pd3.evaluated_at(t, t4).with_name('xbmdot4'),
    pd4.evaluated_at(t, t4).with_name('xbmdot4'),
    pd4.evaluated_at(t, t5).with_name('xbmdot5'),
]<jupyter_output><empty_output><jupyter_text>We introduce a few new symbols to simplify the display,but we keep calculating with $t_i$:<jupyter_code>deltas = {
    t3: 0,
    t4: sp.Symbol('Delta3'),
    t5: sp.Symbol('Delta3') + sp.Symbol('Delta4'),
}
for e in equations:
    display(e.subs(deltas))
coefficients = sp.solve(equations, coefficients3 + coefficients4)
for c, e in coefficients.items():
    display(NamedExpression(c, e.subs(deltas)))
pdd3 = pd3.diff(t)
pdd4 = pd4.diff(t)
display(pdd3, pdd4)
sp.Eq(pdd3.expr.subs(t, t4), pdd4.expr.subs(t, t4))
_.subs(coefficients).subs(deltas).simplify()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15948076031525266, 'fraction_numerical': 0.03616133518776078, 'mean_word_length': 5.681114551083591, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '122797', 'license': 'MIT', 'n_tokens_mistral': 896, 'n_tokens_neox': 873, 'n_words': 160, 'path': 'doc/euclidean/natural-non-uniform.ipynb', 'repo_name': 'AudioSceneDescriptionFormat/splines', 'size': '2157'}