Skip to content

Commit f7850bd

Browse files
authored
Merge pull request #1243 from cbm755/bernoulli
Bernoulli B_1 moving to 1/2
2 parents 1fc231a + 1e11020 commit f7850bd

File tree

3 files changed

+63
-11
lines changed

3 files changed

+63
-11
lines changed

inst/@double/bernoulli.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%% Copyright (C) 2018-2019, 2022 Colin B. Macdonald
1+
%% Copyright (C) 2018-2019, 2022-2023 Colin B. Macdonald
22
%%
33
%% This file is part of OctSymPy.
44
%%
@@ -32,6 +32,19 @@
3232
%% @end group
3333
%% @end example
3434
%%
35+
%% Note there are two conventions in the literature about the sign of B_1,
36+
%% but for certain the absolute value is one half:
37+
%% @example
38+
%% @group
39+
%% @c Would render with an extra zero on earlier Octave
40+
%% @c doctest: +SKIP_IF(compare_versions (OCTAVE_VERSION(), '6.0.0', '<'))
41+
%% abs (bernoulli (1))
42+
%% @result{} 0.5000
43+
%% @end group
44+
%% @end example
45+
%% As of 2023, this numerical evaluation function is in a state of flux
46+
%% about which one it takes, @pxref{@@sym/bernoulli}.
47+
%%
3548
%% Polynomial example:
3649
%% @example
3750
%% @group
@@ -85,7 +98,14 @@
8598

8699
%!assert (bernoulli (0), 1)
87100
%!assert (bernoulli (3), 0)
88-
%!assert (bernoulli (1), -0.5, -eps)
101+
102+
%!test
103+
%! % two different definitions in literature
104+
%! assert (abs (bernoulli (1)), 0.5, -eps)
105+
106+
%!xtest
107+
%! % we want to use B_1 = 1/2, possible with a version-specific filter
108+
%! assert (bernoulli (1), 0.5, -eps)
89109

90110
%!test
91111
%! n = sym(88);
@@ -95,7 +115,7 @@
95115
%! assert (A, B, -eps);
96116

97117
%!test
98-
%! m = [0 1; 2 4];
118+
%! m = [0 2; 3 4];
99119
%! n = sym(m);
100120
%! A = bernoulli (m);
101121
%! B = double (bernoulli (n));

inst/@sym/bernoulli.m

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%% Copyright (C) 2014-2016, 2018-2019, 2022 Colin B. Macdonald
1+
%% Copyright (C) 2014-2016, 2018-2019, 2022-2023 Colin B. Macdonald
22
%%
33
%% This file is part of OctSymPy.
44
%%
@@ -22,12 +22,33 @@
2222
%% @deftypemethodx @@sym {@var{p} =} bernoulli (@var{n}, @var{x})
2323
%% Return symbolic Bernoulli numbers or Bernoulli polynomials.
2424
%%
25-
%% Examples:
25+
%% With a sufficiently recent SymPy version, the first seven
26+
%% Bernoulli numbers are:
2627
%% @example
2728
%% @group
28-
%% bernoulli(sym(6))
29+
%% @c doctest: +XFAIL_IF(pycall_sympy__ ('return Version(spver) < Version("1.12.dev")'))
30+
%% bernoulli (sym(0:6))
31+
%% @result{} (sym) [1 1/2 1/6 0 -1/30 0 1/42] (1×7 matrix)
32+
%% @end group
33+
%% @end example
34+
%%
35+
%% Note there are two different definitions in use which differ
36+
%% in the sign of the value of B_1. As of 2023 and a sufficiently
37+
%% recent SymPy library, we use the definition with positive one half:
38+
%% @example
39+
%% @group
40+
%% @c doctest: +XFAIL_IF(pycall_sympy__ ('return Version(spver) < Version("1.12.dev")'))
41+
%% bernoulli (sym(1))
42+
%% @result{} (sym) 1/2
43+
%% @end group
44+
%% @end example
45+
%%
46+
%% Other examples:
47+
%% @example
48+
%% @group
49+
%% bernoulli (sym(6))
2950
%% @result{} (sym) 1/42
30-
%% bernoulli(sym(7))
51+
%% bernoulli (sym(7))
3152
%% @result{} (sym) 0
3253
%% @end group
3354
%% @end example
@@ -36,7 +57,7 @@
3657
%% @example
3758
%% @group
3859
%% syms x
39-
%% bernoulli(2, x)
60+
%% bernoulli (2, x)
4061
%% @result{} (sym)
4162
%% 2 1
4263
%% x - x + ─
@@ -69,9 +90,19 @@
6990
%! assert (isequal (bernoulli(3,x), x^3 - 3*x^2/2 + x/2))
7091

7192
%!test
72-
%! m = sym([0 1; 8 888889]);
93+
%! % two different definitions in literature
94+
%! assert (isequal (abs (bernoulli (sym(1))), sym(1)/2))
95+
96+
%!test
97+
%! % we use B_1 = 1/2
98+
%! if (pycall_sympy__ ('return Version(spver) >= Version("1.12.dev")'))
99+
%! assert (isequal (bernoulli (sym(1)), sym(1)/2))
100+
%! end
101+
102+
%!test
103+
%! m = sym([0 2; 8 888889]);
73104
%! A = bernoulli (m);
74-
%! B = [1 -sym(1)/2; -sym(1)/30 0];
105+
%! B = [1 sym(1)/6; -sym(1)/30 0];
75106
%! assert (isequal (A, B))
76107

77108
%!test

inst/heaviside.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% Copyright (C) 2006 Sylvain Pelissier <[email protected]>
2-
%% Copyright (C) 2015-2016 Colin B. Macdonald <[email protected]>
2+
%% Copyright (C) 2015-2016, 2019, 2022 Colin B. Macdonald <[email protected]>
33
%%
44
%% This program is free software; you can redistribute it and/or modify it under
55
%% the terms of the GNU General Public License as published by the Free Software
@@ -35,6 +35,7 @@
3535
%% function returns 0.5 by default:
3636
%% @example
3737
%% @group
38+
%% @c Would render with an extra zero on earlier Octave
3839
%% @c doctest: +SKIP_IF(compare_versions (OCTAVE_VERSION(), '6.0.0', '<'))
3940
%% heaviside(0)
4041
%% @result{} 0.5000

0 commit comments

Comments
 (0)