Skip to content

Commit 25c6d94

Browse files
committed
add simplify identities
add simplify identities change description
1 parent 6980d29 commit 25c6d94

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

inst/@sym/simplify.m

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919
%% -*- texinfo -*-
2020
%% @documentencoding UTF-8
2121
%% @defmethod @@sym simplify (@var{x})
22+
%% @defmethodx @@sym simplify (@var{x}, @var{y})
2223
%% Simplify an expression.
2324
%%
25+
%% @var{y} can be 'special' or 'complete'.
26+
%% 'special' will simplify special function with identities.
27+
%% 'complete' will replace the identities and then simplify.
28+
%%
2429
%% Example:
2530
%% @example
2631
%% @group
@@ -47,15 +52,46 @@
4752
%% @end group
4853
%% @end example
4954
%%
55+
%% When @var{y} is 'special':
56+
%% @example
57+
%% @group
58+
%% syms x
59+
%% simplify(beta(x, 1), 'special')
60+
%% @result{} ans = (sym)
61+
%% Γ(x)
62+
%% ────────
63+
%% Γ(x + 1)
64+
%% @end group
65+
%% @end example
66+
%%
67+
%% When @var{y} is 'complete':
68+
%% @example
69+
%% @group
70+
%% syms x
71+
%% simplify(beta(x, 1), 'complete')
72+
%% @result{} ans = (sym)
73+
%% 1
74+
%%
75+
%% x
76+
%% @end group
77+
%% @end example
78+
%%
5079
%% @seealso{@@sym/isAlways, @@sym/factor, @@sym/expand, @@sym/rewrite}
5180
%% @end defmethod
5281

82+
%% Source: http://docs.sympy.org/dev/tutorial/simplification.html
5383

54-
function y = simplify(x)
55-
56-
cmd = 'return sp.simplify(*_ins),';
84+
function y = simplify(x, y)
5785

58-
y = python_cmd (cmd, x);
86+
if (nargin == 1)
87+
y = python_cmd('return simplify(*_ins),', x);
88+
elseif ( strcmp( y, 'special'))
89+
y = python_cmd('return expand_func(*_ins),', x);
90+
elseif ( strcmp( y, 'complete'))
91+
y = python_cmd('return simplify(expand_func(*_ins)),', x);
92+
else
93+
print_usage ();
94+
end
5995

6096
end
6197

@@ -66,3 +102,15 @@
66102
%! q = horner (p);
67103
%!assert(~isequal( p - q, 0))
68104
%!assert(isequal( simplify(p - q), 0))
105+
106+
%!test
107+
%! syms x
108+
%! A = simplify(beta(x, 1), 'special');
109+
%! B = gamma(x)/gamma(x+1);
110+
%! assert( isequal( A, B ))
111+
112+
%!test
113+
%! syms x
114+
%! A = simplify(beta(x, 1), 'complete');
115+
%! B = 1/x;
116+
%! assert( isequal( A, B ))

0 commit comments

Comments
 (0)