Skip to content

Commit

Permalink
Merge pull request #1293 from gnu-octave/changes
Browse files Browse the repository at this point in the history
SymPy 1.13 will be able to rewrite more special functins as integrals
  • Loading branch information
cbm755 authored Mar 5, 2024
2 parents 8b59525 + b556247 commit a89f268
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ on:
pull_request:
schedule:
- cron: '17 0 * * 0'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
# Just some misc stuff, minimal testing, diagnostics etc
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ octsympy 3.1.1+
* `sym(<array>, ratflag)` now respects `ratflag` (issue #1273).
* Changed metainfo.xml ID and corrected long-standing "Addon"
link to GNU Octave.

* Misc changes for SymPy development changes.


octsympy 3.1.1 (2023-03-19)
Expand Down
45 changes: 41 additions & 4 deletions inst/@sym/cosint.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Copyright (C) 2016-2022 Colin B. Macdonald
%% Copyright (C) 2016-2022, 2024 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand All @@ -19,7 +19,7 @@
%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym cosint (@var{x})
%% Symbolic cosint function.
%% Symbolic cosine integral function.
%%
%% Example:
%% @example
Expand All @@ -30,9 +30,34 @@
%% @end group
%% @end example
%%
%% Note: this file is autogenerated: if you want to edit it, you might
%% want to make changes to 'generate_functions.py' instead.
%% The cosine integral is an antiderivative of @code{cos(x)/x}:
%% @example
%% @group
%% diff (y, x)
%% @result{} (sym)
%% cos(x)
%% ──────
%% x
%% @end group
%% @end example
%%
%% More specifically:
%% @example
%% @group
%% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) > Version("1.12.1")'))
%% rewrite (y, 'Integral')
%% @result{} (sym)
%% x
%%
%% ⎮ 1 - cos(t)
%% log(x) - ⎮ ────────── dt + γ
%% ⎮ t
%%
%% 0
%% @end group
%% @end example
%%
%% @seealso{@@sym/sinint, eulergamma}
%% @end defmethod


Expand Down Expand Up @@ -73,3 +98,15 @@
%! h = function_handle (f);
%! B = h (d);
%! assert (A, B, -eps)

%!test
%! % rewrite
%! syms x
%! y1 = cosint (x);
%! y2 = rewrite (y1, 'Integral');
%! d1 = diff (y1, x);
%! d2 = diff (y2, x);
%! assert (isequal (d1, simplify(d2)))
%! v1 = double (subs (d1, x, 2));
%! v2 = double (subs (d2, x, 2));
%! assert (v1, v2, -eps)
5 changes: 3 additions & 2 deletions inst/@sym/disp.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Copyright (C) 2014-2016, 2018-2019 Colin B. Macdonald
%% Copyright (C) 2014-2016, 2018-2019, 2024 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -44,14 +44,15 @@
%% @end group
%%
%% @group
%% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) > Version("1.12.1")'))
%% disp(A, 'ascii')
%% @print{} [ /x\ / c*x\ ]
%% @print{} [ sin|-| floor\a / ]
%% @print{} [ \2/ ]
%% @print{} [ ]
%% @print{} [ /2*x\ / / x \\]
%% @print{} [acosh|---| ceiling|sin|--------||]
%% @print{} [ \ pi/ \ \Gamma(x)//]
%% @print{} [ \pi / \ \Gamma(x)//]
%%
%% disp(A, 'flat')
%% @print{} Matrix([[sin(x/2), floor(a**(c*x))], [acosh(2*x/pi), ceiling(sin(x/gamma(x)))]])
Expand Down
5 changes: 2 additions & 3 deletions inst/@sym/ei.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
%% syms x
%% f = ei(x)
%% @result{} f = (sym) Ei(x)
%% rewrite(f, 'Integral') % doctest: +XFAIL
%% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) > Version("1.12.1")'))
%% rewrite(f, 'Integral')
%% @result{} (sym)
%% x
%%
Expand All @@ -39,8 +40,6 @@
%% -∞
%% @end group
%% @end example
%% (@strong{Note} rewriting as an integral is not yet supported)
%% @c TODO: https://github.com/sympy/sympy/issues/26144
%%
%% Other examples:
%% @example
Expand Down
28 changes: 27 additions & 1 deletion inst/@sym/fresnelc.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
%% @defmethod @@sym fresnelc (@var{x})
%% Symbolic Fresnel Cosine function.
%%
%% Example:
%% The Fresnel Cosine function can be created with:
%% @example
%% @group
%% syms x
%% z = fresnelc (x)
%% @result{} z = (sym) C(x)
%% @end group
%% @end example
%%
%% There are different definitions in the literative involving
%% antiderivative of @code{cos(x^2)}. Here we have the normalized
%% Fresnel Cosine integral where:
%% @example
%% @group
%% diff (z)
%% @result{} (sym)
%% ⎛ 2⎞
Expand All @@ -36,6 +44,24 @@
%% @end group
%% @end example
%%
%% Specifically, the (normalized) Fresnel Cosine function is given by
%% the integral:
%% @example
%% @group
%% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) > Version("1.12.1")'))
%% rewrite (z, 'Integral')
%% @result{} (sym)
%% x
%%
%% ⎮ ⎛ 2⎞
%% ⎮ ⎜π⋅t ⎟
%% ⎮ cos⎜────⎟ dt
%% ⎮ ⎝ 2 ⎠
%%
%% 0
%% @end group
%% @end example
%%
%% @seealso{@@sym/fresnels}
%% @end defmethod

Expand Down
28 changes: 27 additions & 1 deletion inst/@sym/fresnels.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
%% @defmethod @@sym fresnels (@var{x})
%% Symbolic Fresnel Sine function.
%%
%% Example:
%% The Fresnel Sine function can be created with:
%% @example
%% @group
%% syms x
%% z = fresnels (x)
%% @result{} z = (sym) S(x)
%% @end group
%% @end example
%%
%% There are different definitions in the literative involving
%% antiderivative of @code{sin(x^2)}. Here we have the normalized
%% Fresnel Sine integral where:
%% @example
%% @group
%% diff (z)
%% @result{} (sym)
%% ⎛ 2⎞
Expand All @@ -36,6 +44,24 @@
%% @end group
%% @end example
%%
%% Specifically, the (normalized) Fresnel Sine function is given by
%% the integral:
%% @example
%% @group
%% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) > Version("1.12.1")'))
%% rewrite (z, 'Integral')
%% @result{} (sym)
%% x
%%
%% ⎮ ⎛ 2⎞
%% ⎮ ⎜π⋅t ⎟
%% ⎮ sin⎜────⎟ dt
%% ⎮ ⎝ 2 ⎠
%%
%% 0
%% @end group
%% @end example
%%
%% @seealso{@@sym/fresnelc}
%% @end defmethod

Expand Down
56 changes: 51 additions & 5 deletions inst/@sym/sinint.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Copyright (C) 2016-2022 Colin B. Macdonald
%% Copyright (C) 2016-2022, 2024 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand All @@ -19,9 +19,9 @@
%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym sinint (@var{x})
%% Symbolic sinint function.
%% Symbolic sine integral function.
%%
%% Example:
%% The sine integral function can be created with:
%% @example
%% @group
%% syms x
Expand All @@ -30,9 +30,44 @@
%% @end group
%% @end example
%%
%% Note: this file is autogenerated: if you want to edit it, you might
%% want to make changes to 'generate_functions.py' instead.
%% It is an antiderivative of @code{sin(x)/x}:
%% @example
%% @group
%% diff (y, x)
%% @result{} (sym)
%% sin(x)
%% ──────
%% x
%% @end group
%% @end example
%%
%% Specifically, the sine integral function is:
%% @example
%% @group
%% syms t
%% int (sin (t)/t, t, 0, x)
%% @result{} (sym) Si(x)
%% @end group
%% @end example
%%
%% This can instead be written in terms of the @code{sinc}
%% function (@pxref{@@sym/sinc}) where:
%% @example
%% @group
%% @c doctest: +SKIP_UNLESS(pycall_sympy__ ('return Version(spver) > Version("1.12.1")'))
%% rewrite (y, 'Integral')
%% @result{} (sym)
%% x
%%
%% ⎮ ⎛t⎞
%% ⎮ sinc⎜─⎟ dt
%% ⎮ ⎝π⎠
%%
%% 0
%% @end group
%% @end example
%%
%% @seealso{@@sym/cosint, @@sym/sinc}
%% @end defmethod


Expand Down Expand Up @@ -73,3 +108,14 @@
%! h = function_handle (f);
%! B = h (d);
%! assert (A, B, -eps)

%!test
%! % rewrite
%! syms x
%! y1 = sinint (x);
%! y2 = rewrite (y1, 'Integral');
%! d1 = diff (y1, x);
%! d2 = diff (y2, x);
%! v1 = double (subs (d1, x, 2));
%! v2 = double (subs (d2, x, 2));
%! assert (v1, v2, -eps)
4 changes: 1 addition & 3 deletions util/generate_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2014-2016, 2022 Colin B. Macdonald
# Copyright 2014-2016, 2022, 2024 Colin B. Macdonald
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
Expand Down Expand Up @@ -61,8 +61,6 @@
erfcinv
erfi||0,0|
dirac|DiracDelta
cosint|Ci|1,0.3374039229009681346626||2016
sinint|Si|1,0.9460830703671830149414||2016
coshint|Chi|1,0.8378669409802082408947||2016
sinhint|Shi|1,1.057250875375728514572||2016
logint|li|2,1.045163780117492784845||2016
Expand Down

0 comments on commit a89f268

Please sign in to comment.