Interface to TIDES

This module contains tools to write the .c files needed for TIDES [TIDES] .

Tides is an integration engine based on the Taylor method. It is implemented as a c library. The user must translate its initial value problem (IVP) into a pair of .c files that will then be compiled and linked against the TIDES library. The resulting binary will produce the desired output. The tools in this module can be used to automate the generation of these files from the symbolic expression of the differential equation.

##########################################################################
#  Copyright (C) 2014 Miguel Marco <mmarco@unizar.es>, Marcos Rodriguez
#   <marcos@uunizar.es>
#
#  Distributed under the terms of the GNU General Public License (GPL):
#
#                  http://www.gnu.org/licenses/
##########################################################################

AUTHORS:

  • Miguel Marco (06-2014) - Implementation of tides solver
  • Marcos Rodriguez (06-2014) - Implementation of tides solver
  • Alberto Abad (06-2014) - tides solver
  • Roberto Barrio (06-2014) - tides solver

REFERENCES:

sage.interfaces.tides.genfiles_mintides(integrator, driver, f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-16, output='')

Generate the needed files for the min_tides library.

INPUT:

  • integrator – the name of the integrator file.
  • driver – the name of the driver file.
  • f – the function that determines the differential equation.
  • ics – a list or tuple with the initial conditions.
  • initial – the initial time for the integration.
  • final – the final time for the integration.
  • delta – the step of the output.
  • tolrel – the relative tolerance.
  • tolabs – the absolute tolerance.
  • output – the name of the file that the compiled integrator will write to

This function creates two files, integrator and driver, that can be used later with the min_tides library [TIDES].

sage.interfaces.tides.genfiles_mpfr(integrator, driver, f, ics, initial, final, delta, parameters=None, parameter_values=None, dig=20, tolrel=1e-16, tolabs=1e-16, output='')
Generate the needed files for the mpfr module of the tides library.

INPUT:

  • integrator – the name of the integrator file.
  • driver – the name of the driver file.
  • f – the function that determines the differential equation.
  • ics – a list or tuple with the initial conditions.
  • initial – the initial time for the integration.
  • final – the final time for the integration.
  • delta – the step of the output.
  • parameters – the variables inside the function that should be treated
    as parameters.
  • parameter_values – the values of the parameters for the particular
    initial value problem.
  • dig – the number of digits of precision that will be used in the integration
  • tolrel – the relative tolerance.
  • tolabs – the absolute tolerance.
  • output – the name of the file that the compiled integrator will write to

This function creates two files, integrator and driver, that can be used later with the tides library ([TIDES]).

sage.interfaces.tides.remove_constants(l1, l2)

Given two lists, remove the entries in the first that are real constants, and also the corresponding elements in the second one.

sage: from sage.interfaces.tides import subexpressions_list, remove_constants sage: f(a)=[1+cos(7)*a] sage: l1, l2 = subexpressions_list(f) sage: l1, l2 ([sin(7), cos(7), a*cos(7), a*cos(7) + 1], [(‘sin’, 7), (‘cos’, 7), (‘mul’, cos(7), a), (‘add’, 1, a*cos(7))]) sage: remove_constants(l1,l2) sage: l1, l2 ([a*cos(7), a*cos(7) + 1], [(‘mul’, cos(7), a), (‘add’, 1, a*cos(7))])
sage.interfaces.tides.remove_repeated(l1, l2)

Given two lists, remove the repeated elements in l1, and the elements in l2 that are on the same position. positions.

EXAMPLES:

sage: from sage.interfaces.tides import (subexpressions_list, remove_repeated)
sage: f(a)=[1 + a^2, arcsin(a)]
sage: l1, l2 = subexpressions_list(f)
sage: l1, l2
([a^2, a^2 + 1, a^2, -a^2, -a^2 + 1, sqrt(-a^2 + 1), arcsin(a)],
[('mul', a, a),
('add', 1, a^2),
('mul', a, a),
('mul', -1, a^2),
('add', 1, -a^2),
('pow', -a^2 + 1, 0.5),
('asin', a)])
sage: remove_repeated(l1, l2)
sage: l1, l2
([a^2, a^2 + 1, -a^2, -a^2 + 1, sqrt(-a^2 + 1), arcsin(a)],
[('mul', a, a),
('add', 1, a^2),
('mul', -1, a^2),
('add', 1, -a^2),
('pow', -a^2 + 1, 0.5),
('asin', a)])
sage.interfaces.tides.subexpressions_list(f, pars=None)

Construct the lists with the intermediate steps on the evaluation of the function.

INPUT:

  • f – a symbolic function of several components.
  • pars – a list of the parameters that appear in the function this should be the symbolic constants that appear in f but are not arguments.

OUTPUT:

  • a list of the intermediate subexpressions that appear in the evaluation of f.
  • a list with the operations used to construct each of the subexpressions. each element of this list is a tuple, formed by a string describing the operation made, and the operands.

For the trigonometric functions, some extra expressions will be added. These extra expressions will be used later to compute their derivatives.

EXAMPLES:

sage: from sage.interfaces.tides import subexpressions_list
sage: var('x,y')
(x, y)
sage: f(x,y) = [x^2+y, cos(x)/log(y)]
sage: subexpressions_list(f)
([x^2, x^2 + y, sin(x), cos(x), log(y), cos(x)/log(y)],
[('mul', x, x),
('add', y, x^2),
('sin', x),
('cos', x),
('log', y),
('div', log(y), cos(x))])
sage: f(a)=[cos(a), arctan(a)]
sage: from sage.interfaces.tides import subexpressions_list
sage: subexpressions_list(f)
([sin(a), cos(a), a^2, a^2 + 1, arctan(a)],
[('sin', a), ('cos', a), ('mul', a, a), ('add', 1, a^2), ('atan', a)])
sage: from sage.interfaces.tides import subexpressions_list
sage: var('s,b,r')
(s, b, r)
sage: f(t,x,y,z)= [s*(y-x),x*(r-z)-y,x*y-b*z]
sage: subexpressions_list(f,[s,b,r])
([-y,
x - y,
s*(x - y),
-s*(x - y),
-z,
r - z,
(r - z)*x,
-y,
(r - z)*x - y,
x*y,
b*z,
-b*z,
x*y - b*z],
[('mul', -1, y),
('add', -y, x),
('mul', x - y, s),
('mul', -1, s*(x - y)),
('mul', -1, z),
('add', -z, r),
('mul', x, r - z),
('mul', -1, y),
('add', -y, (r - z)*x),
('mul', y, x),
('mul', z, b),
('mul', -1, b*z),
('add', -b*z, x*y)])
sage: var('x, y')
(x, y)
sage: f(x,y)=[exp(x^2+sin(y))]
sage: from sage.interfaces.tides import *
sage: subexpressions_list(f)
([x^2, sin(y), cos(y), x^2 + sin(y), e^(x^2 + sin(y))],
[('mul', x, x),
('sin', y),
('cos', y),
('add', sin(y), x^2),
('exp', x^2 + sin(y))])