symbolic-2.2.4/0000755000175000001440000000000012633614672012032 5ustar cbmuserssymbolic-2.2.4/octsympy_tests_matlab.m0000644000175000001440000000165512633614672016650 0ustar cbmusersaddpath(pwd) base = 'tests_matlab'; files = dir(base); cd(base); % usually I'd just use cputime(), but some of our IPC mechanisms are % light on CPU and heavy on IO. totaltime = clock(); totalcputime = cputime(); num_tests = 0; % do tests in random order: %rng('shuffle') %for i=randperm(length(files)) for i=1:length(files) mfile = files(i).name; % detect tests b/c directory contains other stuff (e.g., surdirs and % helper files) if ( (~files(i).isdir) && strncmp(mfile, 'test', 4) && mfile(end) ~= '~') testtime = clock(); str = mfile(1:end-2); num_tests = num_tests + 1; fprintf(['>>> Running test(s) in: ' mfile ' ']); % no newline eval(str) testtime = etime(clock(), testtime); end end totaltime = etime(clock(),totaltime); totalcputime = cputime() - totalcputime; fprintf('\n***** Ran tests from %d files, %g seconds (%gs CPU) *****\n', ... num_tests, totaltime, totalcputime); cd('..') symbolic-2.2.4/CONTRIBUTORS0000644000175000001440000000073012633614672013712 0ustar cbmusersAuthors and Contributors ======================== Colin B. Macdonald Willem J. Atsma Andrés Prieto Carnë Draug Vadim Gribanov Alexander Misel Mike Miller (Please contact the developers if your name should be here but isn't!) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Thanks also to the authors of the original GiNaC-based symbolic package: Ben Sapp pkienzle Michael Goffioul Willem J. Atsma Rafael Laboissiere Thomas Weber adb014 hauberg symbolic-2.2.4/README.bundled.md0000644000175000001440000000350612633614672014731 0ustar cbmusersWindows Package Bundled Software ================================ To avoid dependencies, the experimental Windows package includes bundled third-party binaries and source. Single-File Stand-alone Python 2.7.8 for Windows ------------------------------------------------ This is by David Manthey. md5sum: a2b39f1a8ca2174e0fcec807b9572136 py.exe available from: [www.orbitals.com/programs/pyexe.html](http://www.orbitals.com/programs/pyexe.html) License: doesn't have a formal license, but something like public domain, see README. Here are two parts of the README file: > I have often wanted a stand-alone version of python that would be a single > Windows executable. This is my attempt to make a generally useful executable. > > It consists of Python 2.7.8, plus pywin32-219, and includes all packages that > py2exe sensibly includes without extra work. > Go ahead and use the executable or source as you see fit. Credit is > appreciated, but not necessary. I accept no liability. > > If you found this useful, let me know. If there is an issue, also let me know. > Obviously, one could include more or less libraries to either add features or > reduce the size of the executable. I don't intend to make alternate versions > with different libraries. > > 5/20/13 - David Manthey - manthey@orbitals.com SymPy ----- From the README: > A Python library for symbolic mathematics. > > http://sympy.org/ > > See the AUTHORS file for the list of authors. > > And many more people helped on the SymPy mailing list, reported bugs, helped > organize SymPy's participation in the Google Summer of Code, the Google Highly > Open Participation Contest, Google Code-In, wrote and blogged about SymPy... > > License: New BSD License (see the LICENSE file for details) covers all files > in the sympy repository unless stated otherwise. symbolic-2.2.4/src/0000755000175000001440000000000012633614673012622 5ustar cbmuserssymbolic-2.2.4/src/bootstrap0000755000175000001440000000011712633614672014563 0ustar cbmusers#! /bin/sh aclocal autoconf echo "$0: done. Now you can run './configure'." symbolic-2.2.4/src/Makefile0000644000175000001440000000440112633614672014260 0ustar cbmusers# OctSymPy does need an Makefile for "pkg install octsympy". # We have this Makefile mainly for post-processing the code to make a # package for Matlab. Also, for legacy reasons, the Makefile can # regenerate the autogenerated .m files. OCTAVE ?= octave PYTHON ?= python default: echo "no installation steps are needed" matlab: ml_copy ml_convert ml_extract_tests clean: matlab_clean ####################################################### codegen: ${PYTHON} generate_functions.py install codegen_clean: ${PYTHON} generate_functions.py clean ml_extract_tests: ml_copy mkdir -p ../matlab/tests_matlab/ cp -ra ../extract_tests_for_matlab.m ../matlab/ cp -ra ../octsympy_tests_matlab.m ../matlab/ cd ../matlab/; ${OCTAVE} -q --eval "extract_tests_for_matlab" rm -f ../matlab/extract_tests_for_matlab.m ml_copy: ml_convert cp -ra ../inst/private ../matlab/ mv ../matlab/private/my_print_usage.m ../matlab/private/print_usage.m cp -ra ../inst/@sym/private ../matlab/@sym/ cp -ra ../inst/@symfun/private ../matlab/@symfun/ cp -ra ../matlab/private/print_usage.m ../matlab/@sym/private/ cp -ra ../matlab/private/print_usage.m ../matlab/@symfun/private/ cp -af ../CONTRIBUTORS ../matlab/ cp -af ../NEWS ../matlab/ cp -af ../COPYING ../matlab/ cp -af ../matlab_smt_differences.md ../matlab/ cp -af ../README.md ../matlab/ cp -af ../README.matlab.md ../matlab/ rm -f ../matlab/octsympy_tests.m ml_convert: mkdir -p ../matlab/@sym/ mkdir -p ../matlab/@symfun/ mkdir -p ../matlab/@logical/ cp -ra ../convert_comments.m ../matlab/ cd ../matlab/; ${OCTAVE} -q --eval "convert_comments('../inst/', '', '../matlab/')" cd ../matlab/; ${OCTAVE} -q --eval "convert_comments('../inst/', '@symfun', '../matlab/')" cd ../matlab/; ${OCTAVE} -q --eval "convert_comments('../inst/', '@sym', '../matlab/')" cd ../matlab/; ${OCTAVE} -q --eval "convert_comments('../inst/', '@logical', '../matlab/')" rm -f ../matlab/convert_comments.m matlab_clean: rm -f ../matlab/*.m rm -f ../matlab/CONTRIBUTORS rm -f ../matlab/COPYING rm -f ../matlab/NEWS rm -f ../matlab/*.md rm -rf ../matlab/@sym rm -rf ../matlab/@symfun rm -rf ../matlab/@logical rm -rf ../matlab/private rm -rf ../matlab/tests_matlab distclean: rm -f configure config.log aclocal.m4 rm -rf autom4te.cache symbolic-2.2.4/src/aclocal.m40000644000175000001440000002105212633614673014462 0ustar cbmusers# generated automatically by aclocal 1.15 -*- Autoconf -*- # Copyright (C) 1996-2014 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) # =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_compare_version.html # =========================================================================== # # SYNOPSIS # # AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) # # DESCRIPTION # # This macro compares two version strings. Due to the various number of # minor-version numbers that can exist, and the fact that string # comparisons are not compatible with numeric comparisons, this is not # necessarily trivial to do in a autoconf script. This macro makes doing # these comparisons easy. # # The six basic comparisons are available, as well as checking equality # limited to a certain number of minor-version levels. # # The operator OP determines what type of comparison to do, and can be one # of: # # eq - equal (test A == B) # ne - not equal (test A != B) # le - less than or equal (test A <= B) # ge - greater than or equal (test A >= B) # lt - less than (test A < B) # gt - greater than (test A > B) # # Additionally, the eq and ne operator can have a number after it to limit # the test to that number of minor versions. # # eq0 - equal up to the length of the shorter version # ne0 - not equal up to the length of the shorter version # eqN - equal up to N sub-version levels # neN - not equal up to N sub-version levels # # When the condition is true, shell commands ACTION-IF-TRUE are run, # otherwise shell commands ACTION-IF-FALSE are run. The environment # variable 'ax_compare_version' is always set to either 'true' or 'false' # as well. # # Examples: # # AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) # AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) # # would both be true. # # AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) # AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) # # would both be false. # # AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) # # would be true because it is only comparing two minor versions. # # AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) # # would be true because it is only comparing the lesser number of minor # versions of the two values. # # Note: The characters that separate the version numbers do not matter. An # empty string is the same as version 0. OP is evaluated by autoconf, not # configure, so must be a string, not a variable. # # The author would like to acknowledge Guido Draheim whose advice about # the m4_case and m4_ifvaln functions make this macro only include the # portions necessary to perform the specific comparison specified by the # OP argument in the final configure script. # # LICENSE # # Copyright (c) 2008 Tim Toolan # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 11 dnl ######################################################################### AC_DEFUN([AX_COMPARE_VERSION], [ AC_REQUIRE([AC_PROG_AWK]) # Used to indicate true or false condition ax_compare_version=false # Convert the two version strings to be compared into a format that # allows a simple string comparison. The end result is that a version # string of the form 1.12.5-r617 will be converted to the form # 0001001200050617. In other words, each number is zero padded to four # digits, and non digits are removed. AS_VAR_PUSHDEF([A],[ax_compare_version_A]) A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/[[^0-9]]//g'` AS_VAR_PUSHDEF([B],[ax_compare_version_B]) B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/[[^0-9]]//g'` dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary dnl # then the first line is used to determine if the condition is true. dnl # The sed right after the echo is to remove any indented white space. m4_case(m4_tolower($2), [lt],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` ], [gt],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` ], [le],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` ], [ge],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` ],[ dnl Split the operator from the subversion count if present. m4_bmatch(m4_substr($2,2), [0],[ # A count of zero means use the length of the shorter version. # Determine the number of characters in A and B. ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'` ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'` # Set A to no more than B's length and B to no more than A's length. A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` ], [[0-9]+],[ # A count greater than zero means use only that many subversions A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` ], [.+],[ AC_WARNING( [illegal OP numeric parameter: $2]) ],[]) # Pad zeros at end of numbers to make same length. ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" B="$B`echo $A | sed 's/./0/g'`" A="$ax_compare_version_tmp_A" # Check for equality or inequality as necessary. m4_case(m4_tolower(m4_substr($2,0,2)), [eq],[ test "x$A" = "x$B" && ax_compare_version=true ], [ne],[ test "x$A" != "x$B" && ax_compare_version=true ],[ AC_WARNING([illegal OP parameter: $2]) ]) ]) AS_VAR_POPDEF([A])dnl AS_VAR_POPDEF([B])dnl dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. if test "$ax_compare_version" = "true" ; then m4_ifvaln([$4],[$4],[:])dnl m4_ifvaln([$5],[else $5])dnl fi ]) dnl AX_COMPARE_VERSION # =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_python_module.html # =========================================================================== # # SYNOPSIS # # AX_PYTHON_MODULE(modname[, fatal, python]) # # DESCRIPTION # # Checks for Python module. # # If fatal is non-empty then absence of a module will trigger an error. # The third parameter can either be "python" for Python 2 or "python3" for # Python 3; defaults to Python 3. # # LICENSE # # Copyright (c) 2008 Andrew Collier # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 8 AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE]) AC_DEFUN([AX_PYTHON_MODULE],[ if test -z $PYTHON; then if test -z "$3"; then PYTHON="python3" else PYTHON="$3" fi fi PYTHON_NAME=`basename $PYTHON` AC_MSG_CHECKING($PYTHON_NAME module: $1) $PYTHON -c "import $1" 2>/dev/null if test $? -eq 0; then AC_MSG_RESULT(yes) eval AS_TR_CPP(HAVE_PYMOD_$1)=yes else AC_MSG_RESULT(no) eval AS_TR_CPP(HAVE_PYMOD_$1)=no # if test -n "$2" then AC_MSG_ERROR(failed to find required module $1) exit 1 fi fi ]) symbolic-2.2.4/src/m4/0000755000175000001440000000000012633614672013141 5ustar cbmuserssymbolic-2.2.4/src/m4/ax_python_module.m40000644000175000001440000000230112633614672016755 0ustar cbmusers# =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_python_module.html # =========================================================================== # # SYNOPSIS # # AX_PYTHON_MODULE(modname[, fatal]) # # DESCRIPTION # # Checks for Python module. # # If fatal is non-empty then absence of a module will trigger an error. # # LICENSE # # Copyright (c) 2008 Andrew Collier # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 6 AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE]) AC_DEFUN([AX_PYTHON_MODULE],[ if test -z $PYTHON; then PYTHON="python" fi PYTHON_NAME=`basename $PYTHON` AC_MSG_CHECKING($PYTHON_NAME module: $1) $PYTHON -c "import $1" 2>/dev/null if test $? -eq 0; then AC_MSG_RESULT(yes) eval AS_TR_CPP(HAVE_PYMOD_$1)=yes else AC_MSG_RESULT(no) eval AS_TR_CPP(HAVE_PYMOD_$1)=no # if test -n "$2" then AC_MSG_ERROR(failed to find required module $1) exit 1 fi fi ]) symbolic-2.2.4/src/m4/ax_compare_version.m40000644000175000001440000001465212633614672017276 0ustar cbmusers# =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_compare_version.html # =========================================================================== # # SYNOPSIS # # AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) # # DESCRIPTION # # This macro compares two version strings. Due to the various number of # minor-version numbers that can exist, and the fact that string # comparisons are not compatible with numeric comparisons, this is not # necessarily trivial to do in a autoconf script. This macro makes doing # these comparisons easy. # # The six basic comparisons are available, as well as checking equality # limited to a certain number of minor-version levels. # # The operator OP determines what type of comparison to do, and can be one # of: # # eq - equal (test A == B) # ne - not equal (test A != B) # le - less than or equal (test A <= B) # ge - greater than or equal (test A >= B) # lt - less than (test A < B) # gt - greater than (test A > B) # # Additionally, the eq and ne operator can have a number after it to limit # the test to that number of minor versions. # # eq0 - equal up to the length of the shorter version # ne0 - not equal up to the length of the shorter version # eqN - equal up to N sub-version levels # neN - not equal up to N sub-version levels # # When the condition is true, shell commands ACTION-IF-TRUE are run, # otherwise shell commands ACTION-IF-FALSE are run. The environment # variable 'ax_compare_version' is always set to either 'true' or 'false' # as well. # # Examples: # # AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) # AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) # # would both be true. # # AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) # AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) # # would both be false. # # AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) # # would be true because it is only comparing two minor versions. # # AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) # # would be true because it is only comparing the lesser number of minor # versions of the two values. # # Note: The characters that separate the version numbers do not matter. An # empty string is the same as version 0. OP is evaluated by autoconf, not # configure, so must be a string, not a variable. # # The author would like to acknowledge Guido Draheim whose advice about # the m4_case and m4_ifvaln functions make this macro only include the # portions necessary to perform the specific comparison specified by the # OP argument in the final configure script. # # LICENSE # # Copyright (c) 2008 Tim Toolan # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 11 dnl ######################################################################### AC_DEFUN([AX_COMPARE_VERSION], [ AC_REQUIRE([AC_PROG_AWK]) # Used to indicate true or false condition ax_compare_version=false # Convert the two version strings to be compared into a format that # allows a simple string comparison. The end result is that a version # string of the form 1.12.5-r617 will be converted to the form # 0001001200050617. In other words, each number is zero padded to four # digits, and non digits are removed. AS_VAR_PUSHDEF([A],[ax_compare_version_A]) A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/[[^0-9]]//g'` AS_VAR_PUSHDEF([B],[ax_compare_version_B]) B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/[[^0-9]]//g'` dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary dnl # then the first line is used to determine if the condition is true. dnl # The sed right after the echo is to remove any indented white space. m4_case(m4_tolower($2), [lt],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` ], [gt],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` ], [le],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` ], [ge],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` ],[ dnl Split the operator from the subversion count if present. m4_bmatch(m4_substr($2,2), [0],[ # A count of zero means use the length of the shorter version. # Determine the number of characters in A and B. ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'` ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'` # Set A to no more than B's length and B to no more than A's length. A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` ], [[0-9]+],[ # A count greater than zero means use only that many subversions A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` ], [.+],[ AC_WARNING( [illegal OP numeric parameter: $2]) ],[]) # Pad zeros at end of numbers to make same length. ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" B="$B`echo $A | sed 's/./0/g'`" A="$ax_compare_version_tmp_A" # Check for equality or inequality as necessary. m4_case(m4_tolower(m4_substr($2,0,2)), [eq],[ test "x$A" = "x$B" && ax_compare_version=true ], [ne],[ test "x$A" != "x$B" && ax_compare_version=true ],[ AC_WARNING([illegal OP parameter: $2]) ]) ]) AS_VAR_POPDEF([A])dnl AS_VAR_POPDEF([B])dnl dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. if test "$ax_compare_version" = "true" ; then m4_ifvaln([$4],[$4],[:])dnl m4_ifvaln([$5],[else $5])dnl fi ]) dnl AX_COMPARE_VERSION symbolic-2.2.4/src/generate_functions.py0000755000175000001440000001162312633614672017063 0ustar cbmusers#!/usr/bin/python """generate_functions.py Yo dawg, I heard you like code generation so I wrote a code generator to write your code generators! """ import sys import os input_list = """sqrt exp log abs|Abs|-1 floor ceil|ceiling|3/2 sin sinh asin asinh cos cosh acos acosh tan tanh atan atanh||1/2 csc sec cot coth acot acoth||2 sign factorial gamma erf erfc erfinv||1/2 erfcinv|||% Note: the erfcinv unit test fails on Octave < 3.8 erfi||0,0| heaviside|Heaviside|1,1 dirac|DiracDelta|1,0 nextprime||123,127 """ # todo: #psi(x)|polygamma(0,x) #psi(k,x)|polygamma(k,x) # sec, csc don't have hyperbolic or arc #sech asec asech #csch acsc acsch copyright_block = \ """%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . """ def process_input_list(L): """replace L with a list of dictionaries""" LL = L.splitlines(); L = []; for it in LL: it = it.split('|') #print it f = it[0] d = {'name':f} if len(it) >= 2 and it[1] != '': d['spname'] = it[1] else: d['spname'] = f if len(it) >= 3 and it[2] != '': testvals = it[2].split(',') if len(testvals) == 2: (d['test_in_val'],d['test_out_val']) = testvals d['out_val_from_oct'] = False else: (d['test_in_val'],) = testvals d['out_val_from_oct'] = True d['octname'] = f else: d['test_in_val'] = '1' d['out_val_from_oct'] = True d['octname'] = f if (len(it) >= 4): d['extra_code'] = it[3] else: d['extra_code'] = '' L.append(d); return L def remove_all(L): """FIXME: all a bit hacky, should do better""" for d in L: f = d['name']; fname = '../inst/@sym/%s.m' % f try: os.unlink(fname) except: True def autogen_functions(L, where): for d in L: f = d['name']; fname = '%s/@sym/%s.m' % (where,f) print fname fd = open(fname, "w") fd.write(copyright_block) fd.write('\n%% -*- texinfo -*-\n') fd.write("%%%% @deftypefn {Function File} {@var{y} =} %s (@var{x})\n" % f) fd.write("%%%% Symbolic %s function.\n" % f) fd.write( \ """%% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic """) fd.write("function y = %s(x)\n" % f) #fd.write('\n') if len(d['extra_code']) > 0: fd.write("\n %s\n\n" % d['extra_code']) fd.write(" y = uniop_helper (x, '%s');\n" % d['spname']) fd.write("end\n") # tests fd.write("\n\n%!shared x, d\n") fd.write("%%! d = %s;\n" % d['test_in_val']) fd.write("%%! x = sym('%s');\n\n" % d['test_in_val']) fd.write("%!test\n") fd.write("%%! f1 = %s(x);\n" % f) if d['out_val_from_oct']: fd.write("%%! f2 = %s(d);\n" % f) else: fd.write("%%! f2 = %s;\n" % d['test_out_val']) fd.write("%! assert( abs(double(f1) - f2) < 1e-15 )\n\n") fd.write("%!test\n") fd.write("%! D = [d d; d d];\n") fd.write("%! A = [x x; x x];\n") fd.write("%%! f1 = %s(A);\n" % f) if d['out_val_from_oct']: fd.write("%%! f2 = %s(D);\n" % f) else: fd.write("%%! f2 = %s;\n" % d['test_out_val']) fd.write("%! f2 = [f2 f2; f2 f2];\n") fd.write("%! assert( all(all( abs(double(f1) - f2) < 1e-15 )))\n") fd.close() def print_usage(): print """ Run this script with one argument: python generate_functions install: make m files in ../inst/@sym python generate_functions clean: remove them from above """ if __name__ == "__main__": L = process_input_list(input_list) print sys.argv if len(sys.argv) <= 1: print_usage() elif sys.argv[1] == 'install': print "***** Generating code for .m files from template ****" autogen_functions(L, '../inst') elif sys.argv[1] == 'clean': print "cleaning up" remove_all(L) else: print_usage() symbolic-2.2.4/src/configure0000755000175000001440000016225012633614673014537 0ustar cbmusers#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for Octave-Forge symbolic package 2.2.4. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='Octave-Forge symbolic package' PACKAGE_TARNAME='octave-forge-symbolic-package' PACKAGE_VERSION='2.2.4' PACKAGE_STRING='Octave-Forge symbolic package 2.2.4' PACKAGE_BUGREPORT='' PACKAGE_URL='' ac_subst_vars='AWK PYTHON SORT target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking ' ac_precious_vars='build_alias host_alias target_alias' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures Octave-Forge symbolic package 2.2.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/octave-forge-symbolic-package] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of Octave-Forge symbolic package 2.2.4:";; esac cat <<\_ACEOF Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF Octave-Forge symbolic package configure 2.2.4 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by Octave-Forge symbolic package $as_me 2.2.4, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ## Window users seem to often have their path misconfigured (issue #236) ## so we check if we really are running GNU sort # Extract the first word of "sort", so it can be a program name with args. set dummy sort; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_SORT+:} false; then : $as_echo_n "(cached) " >&6 else case $SORT in [\\/]* | ?:[\\/]*) ac_cv_path_SORT="$SORT" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_SORT="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi SORT=$ac_cv_path_SORT if test -n "$SORT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SORT" >&5 $as_echo "$SORT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU coreutils" >&5 $as_echo_n "checking for GNU coreutils... " >&6; } $SORT --version 2>/dev/null | grep -q GNU if test $? -ne 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "The sort program is not GNU sort. Please configure your PATH" "$LINENO" 5 else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi # Extract the first word of "python", so it can be a program name with args. set dummy python; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_PYTHON+:} false; then : $as_echo_n "(cached) " >&6 else case $PYTHON in [\\/]* | ?:[\\/]*) ac_cv_path_PYTHON="$PYTHON" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_PYTHON="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi PYTHON=$ac_cv_path_PYTHON if test -n "$PYTHON"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5 $as_echo "$PYTHON" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test -z $PYTHON; then as_fn_error $? "Failed to find Python" "$LINENO" 5 fi if test -z $PYTHON; then if test -z ""; then PYTHON="python3" else PYTHON="" fi fi PYTHON_NAME=`basename $PYTHON` { $as_echo "$as_me:${as_lineno-$LINENO}: checking $PYTHON_NAME module: sympy" >&5 $as_echo_n "checking $PYTHON_NAME module: sympy... " >&6; } $PYTHON -c "import sympy" 2>/dev/null if test $? -eq 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } eval HAVE_PYMOD_SYMPY=yes else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } eval HAVE_PYMOD_SYMPY=no # if test -n "fatal" then as_fn_error $? "failed to find required module sympy" "$LINENO" 5 exit 1 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SymPy version" >&5 $as_echo_n "checking for SymPy version... " >&6; } min_sympy_version='0.7.5' version=`$PYTHON -c "import sympy; print(sympy.__version__)" 2>/dev/null` if test $? -eq 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $version" >&5 $as_echo "$version" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "Failed to import SymPy" "$LINENO" 5 fi for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_AWK+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 $as_echo "$AWK" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$AWK" && break done # Used to indicate true or false condition ax_compare_version=false # Convert the two version strings to be compared into a format that # allows a simple string comparison. The end result is that a version # string of the form 1.12.5-r617 will be converted to the form # 0001001200050617. In other words, each number is zero padded to four # digits, and non digits are removed. ax_compare_version_A=`echo "$version" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/[^0-9]//g'` ax_compare_version_B=`echo "$min_sympy_version" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/[^0-9]//g'` ax_compare_version=`echo "x$ax_compare_version_A x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version_A}/true/;s/x${ax_compare_version_B}/false/;1q"` if test "$ax_compare_version" = "true" ; then : else as_fn_error $? "SymPy version $min_sympy_version or later is required" "$LINENO" 5 fi symbolic-2.2.4/src/autom4te.cache/0000755000175000001440000000000012633614673015426 5ustar cbmuserssymbolic-2.2.4/src/autom4te.cache/output.00000644000175000001440000016265212633614673017063 0ustar cbmusers@%:@! /bin/sh @%:@ Guess values for system-dependent variables and create Makefiles. @%:@ Generated by GNU Autoconf 2.69 for Octave-Forge symbolic package 2.2.4. @%:@ @%:@ @%:@ Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @%:@ @%:@ @%:@ This configure script is free software; the Free Software Foundation @%:@ gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in @%:@( *posix*) : set -o posix ;; @%:@( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in @%:@( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in @%:@(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in @%:@ (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in @%:@( *posix*) : set -o posix ;; @%:@( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in @%:@( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in @%:@ (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## @%:@ as_fn_unset VAR @%:@ --------------- @%:@ Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset @%:@ as_fn_set_status STATUS @%:@ ----------------------- @%:@ Set @S|@? to STATUS, without forking. as_fn_set_status () { return $1 } @%:@ as_fn_set_status @%:@ as_fn_exit STATUS @%:@ ----------------- @%:@ Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } @%:@ as_fn_exit @%:@ as_fn_mkdir_p @%:@ ------------- @%:@ Create "@S|@as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } @%:@ as_fn_mkdir_p @%:@ as_fn_executable_p FILE @%:@ ----------------------- @%:@ Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } @%:@ as_fn_executable_p @%:@ as_fn_append VAR VALUE @%:@ ---------------------- @%:@ Append the text in VALUE to the end of the definition contained in VAR. Take @%:@ advantage of any shell optimizations that allow amortized linear growth over @%:@ repeated appends, instead of the typical quadratic growth present in naive @%:@ implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append @%:@ as_fn_arith ARG... @%:@ ------------------ @%:@ Perform arithmetic evaluation on the ARGs, and store the result in the @%:@ global @S|@as_val. Take advantage of shells that can avoid forks. The arguments @%:@ must be portable across @S|@(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith @%:@ as_fn_error STATUS ERROR [LINENO LOG_FD] @%:@ ---------------------------------------- @%:@ Output "`basename @S|@0`: error: ERROR" to stderr. If LINENO and LOG_FD are @%:@ provided, also output the error to LOG_FD, referencing LINENO. Then exit the @%:@ script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } @%:@ as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in @%:@((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIB@&t@OBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='Octave-Forge symbolic package' PACKAGE_TARNAME='octave-forge-symbolic-package' PACKAGE_VERSION='2.2.4' PACKAGE_STRING='Octave-Forge symbolic package 2.2.4' PACKAGE_BUGREPORT='' PACKAGE_URL='' ac_subst_vars='AWK PYTHON SORT target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking ' ac_precious_vars='build_alias host_alias target_alias' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures Octave-Forge symbolic package 2.2.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX @<:@@S|@ac_default_prefix@:>@ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX @<:@PREFIX@:>@ By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root @<:@DATAROOTDIR/doc/octave-forge-symbolic-package@:>@ --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of Octave-Forge symbolic package 2.2.4:";; esac cat <<\_ACEOF Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF Octave-Forge symbolic package configure 2.2.4 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by Octave-Forge symbolic package $as_me 2.2.4, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in @%:@(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ## Window users seem to often have their path misconfigured (issue #236) ## so we check if we really are running GNU sort # Extract the first word of "sort", so it can be a program name with args. set dummy sort; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_SORT+:} false; then : $as_echo_n "(cached) " >&6 else case $SORT in [\\/]* | ?:[\\/]*) ac_cv_path_SORT="$SORT" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_SORT="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi SORT=$ac_cv_path_SORT if test -n "$SORT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SORT" >&5 $as_echo "$SORT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU coreutils" >&5 $as_echo_n "checking for GNU coreutils... " >&6; } $SORT --version 2>/dev/null | grep -q GNU if test $? -ne 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "The sort program is not GNU sort. Please configure your PATH" "$LINENO" 5 else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi # Extract the first word of "python", so it can be a program name with args. set dummy python; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_PYTHON+:} false; then : $as_echo_n "(cached) " >&6 else case $PYTHON in [\\/]* | ?:[\\/]*) ac_cv_path_PYTHON="$PYTHON" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_PYTHON="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi PYTHON=$ac_cv_path_PYTHON if test -n "$PYTHON"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5 $as_echo "$PYTHON" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test -z $PYTHON; then as_fn_error $? "Failed to find Python" "$LINENO" 5 fi if test -z $PYTHON; then if test -z ""; then PYTHON="python3" else PYTHON="" fi fi PYTHON_NAME=`basename $PYTHON` { $as_echo "$as_me:${as_lineno-$LINENO}: checking $PYTHON_NAME module: sympy" >&5 $as_echo_n "checking $PYTHON_NAME module: sympy... " >&6; } $PYTHON -c "import sympy" 2>/dev/null if test $? -eq 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } eval HAVE_PYMOD_SYMPY=yes else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } eval HAVE_PYMOD_SYMPY=no # if test -n "fatal" then as_fn_error $? "failed to find required module sympy" "$LINENO" 5 exit 1 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SymPy version" >&5 $as_echo_n "checking for SymPy version... " >&6; } min_sympy_version='0.7.5' version=`$PYTHON -c "import sympy; print(sympy.__version__)" 2>/dev/null` if test $? -eq 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $version" >&5 $as_echo "$version" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "Failed to import SymPy" "$LINENO" 5 fi for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_AWK+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 $as_echo "$AWK" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$AWK" && break done # Used to indicate true or false condition ax_compare_version=false # Convert the two version strings to be compared into a format that # allows a simple string comparison. The end result is that a version # string of the form 1.12.5-r617 will be converted to the form # 0001001200050617. In other words, each number is zero padded to four # digits, and non digits are removed. ax_compare_version_A=`echo "$version" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/[^0-9]//g'` ax_compare_version_B=`echo "$min_sympy_version" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/[^0-9]//g'` ax_compare_version=`echo "x$ax_compare_version_A x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version_A}/true/;s/x${ax_compare_version_B}/false/;1q"` if test "$ax_compare_version" = "true" ; then : else as_fn_error $? "SymPy version $min_sympy_version or later is required" "$LINENO" 5 fi symbolic-2.2.4/src/autom4te.cache/output.10000644000175000001440000016265212633614673017064 0ustar cbmusers@%:@! /bin/sh @%:@ Guess values for system-dependent variables and create Makefiles. @%:@ Generated by GNU Autoconf 2.69 for Octave-Forge symbolic package 2.2.4. @%:@ @%:@ @%:@ Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @%:@ @%:@ @%:@ This configure script is free software; the Free Software Foundation @%:@ gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in @%:@( *posix*) : set -o posix ;; @%:@( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in @%:@( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in @%:@(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in @%:@ (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in @%:@( *posix*) : set -o posix ;; @%:@( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in @%:@( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in @%:@ (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## @%:@ as_fn_unset VAR @%:@ --------------- @%:@ Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset @%:@ as_fn_set_status STATUS @%:@ ----------------------- @%:@ Set @S|@? to STATUS, without forking. as_fn_set_status () { return $1 } @%:@ as_fn_set_status @%:@ as_fn_exit STATUS @%:@ ----------------- @%:@ Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } @%:@ as_fn_exit @%:@ as_fn_mkdir_p @%:@ ------------- @%:@ Create "@S|@as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } @%:@ as_fn_mkdir_p @%:@ as_fn_executable_p FILE @%:@ ----------------------- @%:@ Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } @%:@ as_fn_executable_p @%:@ as_fn_append VAR VALUE @%:@ ---------------------- @%:@ Append the text in VALUE to the end of the definition contained in VAR. Take @%:@ advantage of any shell optimizations that allow amortized linear growth over @%:@ repeated appends, instead of the typical quadratic growth present in naive @%:@ implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append @%:@ as_fn_arith ARG... @%:@ ------------------ @%:@ Perform arithmetic evaluation on the ARGs, and store the result in the @%:@ global @S|@as_val. Take advantage of shells that can avoid forks. The arguments @%:@ must be portable across @S|@(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith @%:@ as_fn_error STATUS ERROR [LINENO LOG_FD] @%:@ ---------------------------------------- @%:@ Output "`basename @S|@0`: error: ERROR" to stderr. If LINENO and LOG_FD are @%:@ provided, also output the error to LOG_FD, referencing LINENO. Then exit the @%:@ script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } @%:@ as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in @%:@((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIB@&t@OBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='Octave-Forge symbolic package' PACKAGE_TARNAME='octave-forge-symbolic-package' PACKAGE_VERSION='2.2.4' PACKAGE_STRING='Octave-Forge symbolic package 2.2.4' PACKAGE_BUGREPORT='' PACKAGE_URL='' ac_subst_vars='AWK PYTHON SORT target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking ' ac_precious_vars='build_alias host_alias target_alias' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures Octave-Forge symbolic package 2.2.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX @<:@@S|@ac_default_prefix@:>@ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX @<:@PREFIX@:>@ By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root @<:@DATAROOTDIR/doc/octave-forge-symbolic-package@:>@ --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of Octave-Forge symbolic package 2.2.4:";; esac cat <<\_ACEOF Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF Octave-Forge symbolic package configure 2.2.4 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by Octave-Forge symbolic package $as_me 2.2.4, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF @%:@define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in @%:@(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ## Window users seem to often have their path misconfigured (issue #236) ## so we check if we really are running GNU sort # Extract the first word of "sort", so it can be a program name with args. set dummy sort; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_SORT+:} false; then : $as_echo_n "(cached) " >&6 else case $SORT in [\\/]* | ?:[\\/]*) ac_cv_path_SORT="$SORT" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_SORT="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi SORT=$ac_cv_path_SORT if test -n "$SORT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SORT" >&5 $as_echo "$SORT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU coreutils" >&5 $as_echo_n "checking for GNU coreutils... " >&6; } $SORT --version 2>/dev/null | grep -q GNU if test $? -ne 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "The sort program is not GNU sort. Please configure your PATH" "$LINENO" 5 else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi # Extract the first word of "python", so it can be a program name with args. set dummy python; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_PYTHON+:} false; then : $as_echo_n "(cached) " >&6 else case $PYTHON in [\\/]* | ?:[\\/]*) ac_cv_path_PYTHON="$PYTHON" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_PYTHON="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi PYTHON=$ac_cv_path_PYTHON if test -n "$PYTHON"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5 $as_echo "$PYTHON" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test -z $PYTHON; then as_fn_error $? "Failed to find Python" "$LINENO" 5 fi if test -z $PYTHON; then if test -z ""; then PYTHON="python3" else PYTHON="" fi fi PYTHON_NAME=`basename $PYTHON` { $as_echo "$as_me:${as_lineno-$LINENO}: checking $PYTHON_NAME module: sympy" >&5 $as_echo_n "checking $PYTHON_NAME module: sympy... " >&6; } $PYTHON -c "import sympy" 2>/dev/null if test $? -eq 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } eval HAVE_PYMOD_SYMPY=yes else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } eval HAVE_PYMOD_SYMPY=no # if test -n "fatal" then as_fn_error $? "failed to find required module sympy" "$LINENO" 5 exit 1 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SymPy version" >&5 $as_echo_n "checking for SymPy version... " >&6; } min_sympy_version='0.7.5' version=`$PYTHON -c "import sympy; print(sympy.__version__)" 2>/dev/null` if test $? -eq 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $version" >&5 $as_echo "$version" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "Failed to import SymPy" "$LINENO" 5 fi for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_AWK+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 $as_echo "$AWK" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$AWK" && break done # Used to indicate true or false condition ax_compare_version=false # Convert the two version strings to be compared into a format that # allows a simple string comparison. The end result is that a version # string of the form 1.12.5-r617 will be converted to the form # 0001001200050617. In other words, each number is zero padded to four # digits, and non digits are removed. ax_compare_version_A=`echo "$version" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/[^0-9]//g'` ax_compare_version_B=`echo "$min_sympy_version" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ -e 's/[^0-9]//g'` ax_compare_version=`echo "x$ax_compare_version_A x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version_A}/true/;s/x${ax_compare_version_B}/false/;1q"` if test "$ax_compare_version" = "true" ; then : else as_fn_error $? "SymPy version $min_sympy_version or later is required" "$LINENO" 5 fi symbolic-2.2.4/src/autom4te.cache/requests0000644000175000001440000001112712633614673017226 0ustar cbmusers# This file was generated. # It contains the lists of macros which have been traced. # It can be safely removed. @request = ( bless( [ '0', 1, [ '/usr/share/autoconf' ], [ '/usr/share/autoconf/autoconf/autoconf.m4f', '-', '/usr/share/aclocal-1.15/internal/ac-config-macro-dirs.m4', '/usr/share/aclocal/ax_compare_version.m4', '/usr/share/aclocal/ax_python_module.m4', 'configure.ac' ], { 'AC_DEFUN_ONCE' => 1, '_m4_warn' => 1, 'm4_include' => 1, 'AC_CONFIG_MACRO_DIR' => 1, '_AM_CONFIG_MACRO_DIRS' => 1, 'include' => 1, 'AC_CONFIG_MACRO_DIR_TRACE' => 1, 'm4_pattern_forbid' => 1, 'AX_COMPARE_VERSION' => 1, 'AC_PYTHON_MODULE' => 1, 'AC_DEFUN' => 1, 'AU_DEFUN' => 1, 'AX_PYTHON_MODULE' => 1, 'm4_pattern_allow' => 1, '_AM_AUTOCONF_VERSION' => 1 } ], 'Autom4te::Request' ), bless( [ '1', 1, [ '/usr/share/autoconf' ], [ '/usr/share/autoconf/autoconf/autoconf.m4f', 'aclocal.m4', 'configure.ac' ], { 'AC_CONFIG_HEADERS' => 1, 'LT_SUPPORTED_TAG' => 1, 'AC_SUBST' => 1, 'AM_XGETTEXT_OPTION' => 1, 'AC_CONFIG_SUBDIRS' => 1, 'AC_CANONICAL_HOST' => 1, 'AH_OUTPUT' => 1, 'm4_pattern_allow' => 1, 'AC_PROG_LIBTOOL' => 1, 'AM_GNU_GETTEXT' => 1, '_AM_COND_ENDIF' => 1, 'AM_PROG_F77_C_O' => 1, 'AM_POT_TOOLS' => 1, 'include' => 1, 'm4_sinclude' => 1, 'AC_CONFIG_AUX_DIR' => 1, '_m4_warn' => 1, 'AM_SILENT_RULES' => 1, '_AM_COND_ELSE' => 1, '_AM_SUBST_NOTMAKE' => 1, 'AC_FC_FREEFORM' => 1, 'AM_ENABLE_MULTILIB' => 1, 'LT_CONFIG_LTDL_DIR' => 1, 'AM_MAINTAINER_MODE' => 1, '_LT_AC_TAGCONFIG' => 1, 'AM_INIT_AUTOMAKE' => 1, 'AC_FC_PP_SRCEXT' => 1, 'AC_CONFIG_LIBOBJ_DIR' => 1, 'AC_INIT' => 1, '_AM_MAKEFILE_INCLUDE' => 1, 'AM_PROG_AR' => 1, 'AM_PROG_MOC' => 1, 'AM_PROG_CXX_C_O' => 1, 'AM_MAKEFILE_INCLUDE' => 1, 'AC_LIBSOURCE' => 1, 'AC_REQUIRE_AUX_FILE' => 1, 'AC_SUBST_TRACE' => 1, 'm4_include' => 1, 'AM_NLS' => 1, 'AM_PROG_FC_C_O' => 1, 'AC_CANONICAL_SYSTEM' => 1, 'AC_CANONICAL_BUILD' => 1, 'AM_AUTOMAKE_VERSION' => 1, 'AC_FC_SRCEXT' => 1, 'AM_GNU_GETTEXT_INTL_SUBDIR' => 1, 'AC_CONFIG_FILES' => 1, 'sinclude' => 1, 'AC_FC_PP_DEFINE' => 1, 'AC_CANONICAL_TARGET' => 1, 'LT_INIT' => 1, '_AM_COND_IF' => 1, 'AM_PROG_CC_C_O' => 1, 'AM_PATH_GUILE' => 1, 'AC_DEFINE_TRACE_LITERAL' => 1, 'AC_CONFIG_LINKS' => 1, 'AM_CONDITIONAL' => 1, 'm4_pattern_forbid' => 1 } ], 'Autom4te::Request' ) ); symbolic-2.2.4/src/autom4te.cache/traces.00000644000175000001440000001770512633614673017002 0ustar cbmusersm4trace:/usr/share/aclocal/ax_compare_version.m4:85: -1- AC_DEFUN([AX_COMPARE_VERSION], [ AC_REQUIRE([AC_PROG_AWK]) # Used to indicate true or false condition ax_compare_version=false # Convert the two version strings to be compared into a format that # allows a simple string comparison. The end result is that a version # string of the form 1.12.5-r617 will be converted to the form # 0001001200050617. In other words, each number is zero padded to four # digits, and non digits are removed. AS_VAR_PUSHDEF([A],[ax_compare_version_A]) A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/[[^0-9]]//g'` AS_VAR_PUSHDEF([B],[ax_compare_version_B]) B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ -e 's/[[^0-9]]//g'` dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary dnl # then the first line is used to determine if the condition is true. dnl # The sed right after the echo is to remove any indented white space. m4_case(m4_tolower($2), [lt],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` ], [gt],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` ], [le],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` ], [ge],[ ax_compare_version=`echo "x$A x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` ],[ dnl Split the operator from the subversion count if present. m4_bmatch(m4_substr($2,2), [0],[ # A count of zero means use the length of the shorter version. # Determine the number of characters in A and B. ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'` ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'` # Set A to no more than B's length and B to no more than A's length. A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` ], [[0-9]+],[ # A count greater than zero means use only that many subversions A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` ], [.+],[ AC_WARNING( [illegal OP numeric parameter: $2]) ],[]) # Pad zeros at end of numbers to make same length. ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" B="$B`echo $A | sed 's/./0/g'`" A="$ax_compare_version_tmp_A" # Check for equality or inequality as necessary. m4_case(m4_tolower(m4_substr($2,0,2)), [eq],[ test "x$A" = "x$B" && ax_compare_version=true ], [ne],[ test "x$A" != "x$B" && ax_compare_version=true ],[ AC_WARNING([illegal OP parameter: $2]) ]) ]) AS_VAR_POPDEF([A])dnl AS_VAR_POPDEF([B])dnl dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. if test "$ax_compare_version" = "true" ; then m4_ifvaln([$4],[$4],[:])dnl m4_ifvaln([$5],[else $5])dnl fi ]) m4trace:/usr/share/aclocal/ax_python_module.m4:28: -1- AU_DEFUN([AC_PYTHON_MODULE], [m4_if($#, 0, [AX_PYTHON_MODULE], [AX_PYTHON_MODULE($@)])]) m4trace:/usr/share/aclocal/ax_python_module.m4:28: -1- AC_DEFUN([AC_PYTHON_MODULE], [AC_DIAGNOSE([obsolete], [The macro `AC_PYTHON_MODULE' is obsolete. You should run autoupdate.])dnl m4_if($#, 0, [AX_PYTHON_MODULE], [AX_PYTHON_MODULE($@)])]) m4trace:/usr/share/aclocal/ax_python_module.m4:29: -1- AC_DEFUN([AX_PYTHON_MODULE], [ if test -z $PYTHON; then if test -z "$3"; then PYTHON="python3" else PYTHON="$3" fi fi PYTHON_NAME=`basename $PYTHON` AC_MSG_CHECKING($PYTHON_NAME module: $1) $PYTHON -c "import $1" 2>/dev/null if test $? -eq 0; then AC_MSG_RESULT(yes) eval AS_TR_CPP(HAVE_PYMOD_$1)=yes else AC_MSG_RESULT(no) eval AS_TR_CPP(HAVE_PYMOD_$1)=no # if test -n "$2" then AC_MSG_ERROR(failed to find required module $1) exit 1 fi fi ]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^_?A[CHUM]_]) m4trace:configure.ac:2: -1- m4_pattern_forbid([_AC_]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^LIBOBJS$], [do not use LIBOBJS directly, use AC_LIBOBJ (see section `AC_LIBOBJ vs LIBOBJS']) m4trace:configure.ac:2: -1- m4_pattern_allow([^AS_FLAGS$]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^_?m4_]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^dnl$]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^_?AS_]) m4trace:configure.ac:2: -1- m4_pattern_allow([^SHELL$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PATH_SEPARATOR$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_NAME$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_VERSION$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_STRING$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_URL$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^exec_prefix$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^prefix$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^program_transform_name$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^bindir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^sbindir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^libexecdir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^datarootdir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^datadir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^sysconfdir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^sharedstatedir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^localstatedir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^includedir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^oldincludedir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^docdir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^infodir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^htmldir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^dvidir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^pdfdir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^psdir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^libdir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^localedir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^mandir$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_NAME$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_VERSION$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_STRING$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_URL$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^DEFS$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^ECHO_C$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^ECHO_N$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^ECHO_T$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^LIBS$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^build_alias$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^host_alias$]) m4trace:configure.ac:2: -1- m4_pattern_allow([^target_alias$]) m4trace:configure.ac:6: -1- m4_pattern_allow([^SORT$]) m4trace:configure.ac:17: -1- m4_pattern_allow([^PYTHON$]) m4trace:configure.ac:22: -1- AX_PYTHON_MODULE([sympy], [fatal]) m4trace:configure.ac:33: -1- AX_COMPARE_VERSION([$version], [ge], [$min_sympy_version], [], [ AC_MSG_ERROR(SymPy version $min_sympy_version or later is required) ]) m4trace:configure.ac:33: -1- m4_pattern_allow([^AWK$]) symbolic-2.2.4/src/autom4te.cache/traces.10000644000175000001440000002330112633614673016770 0ustar cbmusersm4trace:configure.ac:2: -1- AC_INIT([Octave-Forge symbolic package], [2.2.4]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^_?A[CHUM]_]) m4trace:configure.ac:2: -1- m4_pattern_forbid([_AC_]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^LIBOBJS$], [do not use LIBOBJS directly, use AC_LIBOBJ (see section `AC_LIBOBJ vs LIBOBJS']) m4trace:configure.ac:2: -1- m4_pattern_allow([^AS_FLAGS$]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^_?m4_]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^dnl$]) m4trace:configure.ac:2: -1- m4_pattern_forbid([^_?AS_]) m4trace:configure.ac:2: -1- AC_SUBST([SHELL]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([SHELL]) m4trace:configure.ac:2: -1- m4_pattern_allow([^SHELL$]) m4trace:configure.ac:2: -1- AC_SUBST([PATH_SEPARATOR]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([PATH_SEPARATOR]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PATH_SEPARATOR$]) m4trace:configure.ac:2: -1- AC_SUBST([PACKAGE_NAME], [m4_ifdef([AC_PACKAGE_NAME], ['AC_PACKAGE_NAME'])]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([PACKAGE_NAME]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_NAME$]) m4trace:configure.ac:2: -1- AC_SUBST([PACKAGE_TARNAME], [m4_ifdef([AC_PACKAGE_TARNAME], ['AC_PACKAGE_TARNAME'])]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([PACKAGE_TARNAME]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) m4trace:configure.ac:2: -1- AC_SUBST([PACKAGE_VERSION], [m4_ifdef([AC_PACKAGE_VERSION], ['AC_PACKAGE_VERSION'])]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([PACKAGE_VERSION]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_VERSION$]) m4trace:configure.ac:2: -1- AC_SUBST([PACKAGE_STRING], [m4_ifdef([AC_PACKAGE_STRING], ['AC_PACKAGE_STRING'])]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([PACKAGE_STRING]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_STRING$]) m4trace:configure.ac:2: -1- AC_SUBST([PACKAGE_BUGREPORT], [m4_ifdef([AC_PACKAGE_BUGREPORT], ['AC_PACKAGE_BUGREPORT'])]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([PACKAGE_BUGREPORT]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) m4trace:configure.ac:2: -1- AC_SUBST([PACKAGE_URL], [m4_ifdef([AC_PACKAGE_URL], ['AC_PACKAGE_URL'])]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([PACKAGE_URL]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_URL$]) m4trace:configure.ac:2: -1- AC_SUBST([exec_prefix], [NONE]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([exec_prefix]) m4trace:configure.ac:2: -1- m4_pattern_allow([^exec_prefix$]) m4trace:configure.ac:2: -1- AC_SUBST([prefix], [NONE]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([prefix]) m4trace:configure.ac:2: -1- m4_pattern_allow([^prefix$]) m4trace:configure.ac:2: -1- AC_SUBST([program_transform_name], [s,x,x,]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([program_transform_name]) m4trace:configure.ac:2: -1- m4_pattern_allow([^program_transform_name$]) m4trace:configure.ac:2: -1- AC_SUBST([bindir], ['${exec_prefix}/bin']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([bindir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^bindir$]) m4trace:configure.ac:2: -1- AC_SUBST([sbindir], ['${exec_prefix}/sbin']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([sbindir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^sbindir$]) m4trace:configure.ac:2: -1- AC_SUBST([libexecdir], ['${exec_prefix}/libexec']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([libexecdir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^libexecdir$]) m4trace:configure.ac:2: -1- AC_SUBST([datarootdir], ['${prefix}/share']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([datarootdir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^datarootdir$]) m4trace:configure.ac:2: -1- AC_SUBST([datadir], ['${datarootdir}']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([datadir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^datadir$]) m4trace:configure.ac:2: -1- AC_SUBST([sysconfdir], ['${prefix}/etc']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([sysconfdir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^sysconfdir$]) m4trace:configure.ac:2: -1- AC_SUBST([sharedstatedir], ['${prefix}/com']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([sharedstatedir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^sharedstatedir$]) m4trace:configure.ac:2: -1- AC_SUBST([localstatedir], ['${prefix}/var']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([localstatedir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^localstatedir$]) m4trace:configure.ac:2: -1- AC_SUBST([includedir], ['${prefix}/include']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([includedir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^includedir$]) m4trace:configure.ac:2: -1- AC_SUBST([oldincludedir], ['/usr/include']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([oldincludedir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^oldincludedir$]) m4trace:configure.ac:2: -1- AC_SUBST([docdir], [m4_ifset([AC_PACKAGE_TARNAME], ['${datarootdir}/doc/${PACKAGE_TARNAME}'], ['${datarootdir}/doc/${PACKAGE}'])]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([docdir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^docdir$]) m4trace:configure.ac:2: -1- AC_SUBST([infodir], ['${datarootdir}/info']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([infodir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^infodir$]) m4trace:configure.ac:2: -1- AC_SUBST([htmldir], ['${docdir}']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([htmldir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^htmldir$]) m4trace:configure.ac:2: -1- AC_SUBST([dvidir], ['${docdir}']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([dvidir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^dvidir$]) m4trace:configure.ac:2: -1- AC_SUBST([pdfdir], ['${docdir}']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([pdfdir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^pdfdir$]) m4trace:configure.ac:2: -1- AC_SUBST([psdir], ['${docdir}']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([psdir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^psdir$]) m4trace:configure.ac:2: -1- AC_SUBST([libdir], ['${exec_prefix}/lib']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([libdir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^libdir$]) m4trace:configure.ac:2: -1- AC_SUBST([localedir], ['${datarootdir}/locale']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([localedir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^localedir$]) m4trace:configure.ac:2: -1- AC_SUBST([mandir], ['${datarootdir}/man']) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([mandir]) m4trace:configure.ac:2: -1- m4_pattern_allow([^mandir$]) m4trace:configure.ac:2: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_NAME]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_NAME$]) m4trace:configure.ac:2: -1- AH_OUTPUT([PACKAGE_NAME], [/* Define to the full name of this package. */ @%:@undef PACKAGE_NAME]) m4trace:configure.ac:2: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_TARNAME]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) m4trace:configure.ac:2: -1- AH_OUTPUT([PACKAGE_TARNAME], [/* Define to the one symbol short name of this package. */ @%:@undef PACKAGE_TARNAME]) m4trace:configure.ac:2: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_VERSION]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_VERSION$]) m4trace:configure.ac:2: -1- AH_OUTPUT([PACKAGE_VERSION], [/* Define to the version of this package. */ @%:@undef PACKAGE_VERSION]) m4trace:configure.ac:2: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_STRING]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_STRING$]) m4trace:configure.ac:2: -1- AH_OUTPUT([PACKAGE_STRING], [/* Define to the full name and version of this package. */ @%:@undef PACKAGE_STRING]) m4trace:configure.ac:2: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_BUGREPORT]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) m4trace:configure.ac:2: -1- AH_OUTPUT([PACKAGE_BUGREPORT], [/* Define to the address where bug reports for this package should be sent. */ @%:@undef PACKAGE_BUGREPORT]) m4trace:configure.ac:2: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_URL]) m4trace:configure.ac:2: -1- m4_pattern_allow([^PACKAGE_URL$]) m4trace:configure.ac:2: -1- AH_OUTPUT([PACKAGE_URL], [/* Define to the home page for this package. */ @%:@undef PACKAGE_URL]) m4trace:configure.ac:2: -1- AC_SUBST([DEFS]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([DEFS]) m4trace:configure.ac:2: -1- m4_pattern_allow([^DEFS$]) m4trace:configure.ac:2: -1- AC_SUBST([ECHO_C]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([ECHO_C]) m4trace:configure.ac:2: -1- m4_pattern_allow([^ECHO_C$]) m4trace:configure.ac:2: -1- AC_SUBST([ECHO_N]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([ECHO_N]) m4trace:configure.ac:2: -1- m4_pattern_allow([^ECHO_N$]) m4trace:configure.ac:2: -1- AC_SUBST([ECHO_T]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([ECHO_T]) m4trace:configure.ac:2: -1- m4_pattern_allow([^ECHO_T$]) m4trace:configure.ac:2: -1- AC_SUBST([LIBS]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([LIBS]) m4trace:configure.ac:2: -1- m4_pattern_allow([^LIBS$]) m4trace:configure.ac:2: -1- AC_SUBST([build_alias]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([build_alias]) m4trace:configure.ac:2: -1- m4_pattern_allow([^build_alias$]) m4trace:configure.ac:2: -1- AC_SUBST([host_alias]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([host_alias]) m4trace:configure.ac:2: -1- m4_pattern_allow([^host_alias$]) m4trace:configure.ac:2: -1- AC_SUBST([target_alias]) m4trace:configure.ac:2: -1- AC_SUBST_TRACE([target_alias]) m4trace:configure.ac:2: -1- m4_pattern_allow([^target_alias$]) m4trace:configure.ac:6: -1- AC_SUBST([SORT]) m4trace:configure.ac:6: -1- AC_SUBST_TRACE([SORT]) m4trace:configure.ac:6: -1- m4_pattern_allow([^SORT$]) m4trace:configure.ac:17: -1- AC_SUBST([PYTHON]) m4trace:configure.ac:17: -1- AC_SUBST_TRACE([PYTHON]) m4trace:configure.ac:17: -1- m4_pattern_allow([^PYTHON$]) m4trace:configure.ac:33: -1- AC_SUBST([AWK]) m4trace:configure.ac:33: -1- AC_SUBST_TRACE([AWK]) m4trace:configure.ac:33: -1- m4_pattern_allow([^AWK$]) symbolic-2.2.4/src/configure.ac0000644000175000001440000000167512633614672015120 0ustar cbmusersAC_PREREQ([2.67]) AC_INIT([Octave-Forge symbolic package], [2.2.4]) ## Window users seem to often have their path misconfigured (issue #236) ## so we check if we really are running GNU sort AC_PATH_PROG(SORT, sort) AC_MSG_CHECKING(for GNU coreutils) $SORT --version 2>/dev/null | grep -q GNU if test $? -ne 0; then AC_MSG_RESULT(no) AC_MSG_ERROR([The sort program is not GNU sort. Please configure your PATH]) else AC_MSG_RESULT(yes) fi AC_PATH_PROG(PYTHON, python) if test -z $PYTHON; then AC_MSG_ERROR(Failed to find Python) fi AX_PYTHON_MODULE(sympy, fatal) AC_MSG_CHECKING(for SymPy version) min_sympy_version='0.7.5' version=`$PYTHON -c "import sympy; print(sympy.__version__)" 2>/dev/null` if test $? -eq 0; then AC_MSG_RESULT($version) else AC_MSG_RESULT(no) AC_MSG_ERROR(Failed to import SymPy) fi AX_COMPARE_VERSION($version, ge, $min_sympy_version, [], [ AC_MSG_ERROR(SymPy version $min_sympy_version or later is required) ]) symbolic-2.2.4/DESCRIPTION0000644000175000001440000000140312633614672013536 0ustar cbmusersName: symbolic Version: 2.2.4 Date: 2015-12-14 Author: Colin B. Macdonald Maintainer: Colin B. Macdonald Title: Octave Symbolic Package using SymPy Description: The Octave-Forge Symbolic package adds symbolic calculation features to GNU Octave. These include common Computer Algebra System tools such as algebraic operations, calculus, equation solving, Fourier and Laplace transforms, variable precision arithmetic and other features. Internally, the package uses [SymPy](www.sympy.org), but no knowledge of Python is required. Compatibility with other symbolic toolboxes is intended. Categories: symbolic Url: http://github.com/cbm755/octsympy SystemRequirements: python, sympy (>= 0.7.5) BuildRequires: python, sympy (>= 0.7.5) symbolic-2.2.4/COPYING0000644000175000001440000010446112633614672013073 0ustar cbmusersGNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {one line to give the program's name and a brief idea of what it does.} Copyright (C) {year} {name of author} This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: {project} Copyright (C) {year} {fullname} This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . symbolic-2.2.4/make_release_packages.sh0000755000175000001440000000222612633614672016646 0ustar cbmusers#!/bin/sh # for day-to-day testing VER=2.2.4-dev # for release #VER=2.2.4 #TAG=v${VER} #---------------------------------------------------------------- PKG=symbolic-$VER DIR=$PKG MLPKG=octsympy-matlab-$VER MLDIR=$MLPKG echo "Making packages for octsympy-$VER." read -p "Press [Enter] to git clone and make packages..." # checkout a clean copy rm -rf octsympy git clone https://github.com/cbm755/octsympy.git pushd octsympy if [ -z $TAG]; then git checkout master else git checkout tags/${TAG} fi popd # clean up rm -f ${PKG}.tar.gz ${PKG}.zip rm -f ${MLPKG}.tar.gz ${MLPKG}.zip rm -rf ${DIR} rm -rf ${MLDIR} cp -r octsympy ${DIR} # remove .git dir and other things not needed for package pushd ${DIR}/ rm .gitignore rm -rf .git/ rm -f screenshot.png rm -f screenshot-install.png popd # make clean pushd ${DIR}/src/ make distclean ./bootstrap make clean popd # here are the packages tar -zcvf ${PKG}.tar.gz ${DIR} zip -r ${PKG}.zip ${DIR} # Now, matlab packages pushd ${DIR}/src/ make matlab popd cp -ra ${DIR}/matlab ${MLDIR} tar -zcvf ${MLPKG}.tar.gz ${MLDIR} zip -r ${MLPKG}.zip ${MLDIR} md5sum ${PKG}.tar.gz ${PKG}.zip ${MLPKG}.tar.gz ${MLPKG}.zip symbolic-2.2.4/inst/0000755000175000001440000000000012633614672013007 5ustar cbmuserssymbolic-2.2.4/inst/python_cmd.m0000644000175000001440000002175212633614672015340 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {[@var{a}, @var{b}, @dots{}] =} python_cmd (@var{cmd}, @var{x}, @var{y}, @dots{}) %% Run some Python command on some objects and return other objects. %% %% Here @var{cmd} is a string of Python code. %% Inputs @var{x}, @var{y}, @dots{} can be a variety of objects %% (possible types listed below). Outputs @var{a}, @var{b}, @dots{} are %% converted from Python objects: not all types are possible, see %% below. %% %% Example: %% @example %% @group %% >> x = 10; y = 2; %% >> cmd = '(x,y) = _ins; return (x+y,x-y)'; %% >> [a, b] = python_cmd (cmd, x, y) %% @result{} a = 12 %% @result{} b = 8 %% @end group %% @end example %% %% The inputs will be in a list called '_ins'. The command should %% end by outputing a tuple of return arguments. %% If you have just one return value, you probably want to append %% an extra comma. Either of these approaches will work: %% @example %% @group %% >> cmd = '(x,y) = _ins; return (x+y,)'; %% >> a = python_cmd (cmd, x, y) %% @result{} a = 12 %% >> cmd = '(x,y) = _ins; return x+y,'; %% >> a = python_cmd (cmd, x, y) %% @result{} a = 12 %% @end group %% @end example %% (Python gurus will know why). %% %% Instead of @code{return}, you can append to the Python list %% @code{_outs}: %% @example %% @group %% >> cmd = '(x,y) = _ins; _outs.append(x**y)'; %% >> a = python_cmd (cmd, x, y) %% @result{} a = 100 %% @end group %% @end example %% %% You can also pass a cell-array of lines of code. But be careful %% with whitespace: its Python! %% @example %% @group %% >> cmd = @{ '(x,) = _ins' %% .. 'if x.is_Matrix:' %% .. ' return (x.T,)' %% .. 'else:' %% .. ' return (x,)' @}; %% @end group %% @end example %% The cell array can be either a row or a column vector. %% Each of these strings probably should not have any newlines %% (other than escaped ones e.g., inside strings). An exception %% might be Python triple-quoted """ multiline strings """. %% FIXME: test this. %% It might be a good idea to avoid blank lines as they can cause %% problems with some of the IPC mechanisms. %% %% Possible input types: %% @itemize %% @item sym objects %% @item strings (char) %% @item scalar doubles %% @end itemize %% They can also be cell arrays of these items. Multi-D cell %% arrays may not work properly. %% %% Possible output types: %% @itemize %% @item SymPy objects (Matrix and Expr at least) %% @item int %% @item float %% @item string %% @item unicode strings %% @item bool %% @item dict (converted to structs) %% @item lists/tuples (converted to cell vectors) %% @end itemize %% FIXME: add a py_config to change the header? The python %% environment is defined in python_header.py. Changing it is %% currently harder than it should be. %% %% Note: if you don't pass in any syms, this shouldn't need SymPy. %% But it still imports it in that case. If you want to run this %% w/o having the SymPy package, you'd need to hack a bit. %% %% @seealso{evalpy} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: python function varargout = python_cmd(cmd, varargin) if (~iscell(cmd)) cmd = {cmd}; end %% IPC interface % the ipc mechanism shall put the input variables in the tuple % '_ins' and it will return to us whatever we put in the tuple % '_outs'. There is no particular reason this needs to define % a function, I just thought it isolates local variables a bit. cmd = indent_lines(cmd, 4); cmd = { 'def _fcn(_ins):' ... ' _outs = []' ... cmd{:} ... ' return _outs' ... '_outs = _fcn(_ins)' }; [A, db] = python_ipc_driver('run', cmd, varargin{:}); if (~iscell(A)) disp(A) % Python state undefined, so reset it (overkill for nostateful ipc) sympref reset error('OctSymPy:python_cmd:unexpected', 'python_cmd: unexpected return') end M = length(A); varargout = cell(1,M); for i=1:M varargout{i} = A{i}; end if nargout ~= M warning('number of outputs don''t match, was this intentional?') end end %!test %! % general test %! x = 10; y = 6; %! cmd = '(x,y) = _ins; return (x+y,x-y)'; %! [a,b] = python_cmd (cmd, x, y); %! assert (a == x + y && b == x - y) %!test %! % bool %! assert (python_cmd ('return True,')) %! assert (~python_cmd ('return False,')) %!test %! % float %! assert (abs(python_cmd ('return 1.0/3,') - 1/3) < 1e-15) %!test %! % int %! assert (python_cmd ('return 123456,') == 123456) %!test %! % string %! x = 'octave'; %! cmd = 's = _ins[0]; return s.capitalize(),'; %! y = python_cmd (cmd, x); %! assert (strcmp(y, 'Octave')) %!test %! % string with newlines %! % FIXME: escaped in input should still be escaped in output %! x = 'a string\nbroke off\nmy guitar\n'; %! x2 = sprintf(x); %! y = python_cmd ('return _ins', x); %! x3 = strrep(x2, sprintf('\n'), sprintf('\r\n')); % windows %! assert (strcmp(y, x2) || strcmp(y, x3)) %!test %! % bug: cmd string with newlines, works with cell %! % FIXME: no addition escaping for this one %! y = python_cmd ('return "string\nbroke",'); %! y2 = sprintf('string\nbroke'); %! y3 = strrep(y2, sprintf('\n'), sprintf('\r\n')); % windows %! assert (strcmp(y, y2) || strcmp(y, y3)) %%!test %%! % FIXME: newlines: should be escaped for import? %%! x = 'a string\nbroke off\nmy guitar\n'; %%! x2 = sprintf(x); %%! y = python_cmd ('return _ins', x2); %%! assert (strcmp(y, x2)) %!test %! % string with XML escapes %! x = '<> >< <<>>'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, x)) %! x = '&'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, x)) %!test %! % strings with double quotes %! % maybe its sensible to need to escape double-quotes to send to python? %! % FIXME: or we could escape ", \, \n automatically? %! x = 'a\"b\"c'; %! expy = 'a"b"c'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, expy)) %! x = '\"'; %! expy = '"'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, expy)) %!test %! % cmd has double quotes, these must be escaped by user %! % (of course: she is writing python code) %! expy = 'a"b"c'; %! y = python_cmd ('return "a\"b\"c",'); %! assert (strcmp(y, expy)) %!test %! % strings with quotes %! x = 'a''b'; % this is a single quote %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, x)) %!test %! % strings with quotes %! x = '\"a''b\"c''\"d'; %! y1 = '"a''b"c''"d'; %! cmd = 's = _ins[0]; return s,'; %! y2 = python_cmd (cmd, x); %! assert (strcmp(y1, y2)) %!test %! % strings with printf escapes %! x = '% %% %%% %%%% %s %g %%s'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, x)) %!test %! % cmd with printf escapes %! x = '% %% %%% %%%% %s %g %%s'; %! y = python_cmd (['return "' x '",']); %! assert (strcmp(y, x)) %!test %! % cmd w/ backslash and \n must be escaped by user %! expy = 'a\b\\c\nd\'; %! y = python_cmd ('return "a\\b\\\\c\\nd\\",'); %! assert (strcmp(y, expy)) %!test %! % slashes: FIXME: auto escape backslashes %! x = '/\\ // \\\\ \\/\\/\\'; %! z = '/\ // \\ \/\/\'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, z)) %!test %! % strings with special chars %! x = '!@#$^&* you!'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, x)) %! x = '~-_=+[{]}|;:,.?'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, x)) %!xtest %! % string with backtick trouble for system -c (sysoneline) %! x = '`'; %! y = python_cmd ('return _ins', x); %! assert (strcmp(y, x)) %!test %! % unicode %! s1 = '我爱你'; %! cmd = 'return u"\u6211\u7231\u4f60",'; %! s2 = python_cmd (cmd); %! assert (strcmp (s1, s2)) %%!test %%! % unicode passthru: FIXME: how to get unicode back to Python? %%! s1 = '我爱你' %%! cmd = 'return (_ins[0],)'; %%! s2 = python_cmd (cmd, s1) %%! assert (strcmp (s1, s2)) %%!test %%! % unicode w/ slashes, escapes, etc FIXME %%! s1 = '我爱你<>\\&//\\#%% %\\我' %%! s3 = '我爱你<>\&//\#%% %\我' %%! cmd = 'return u"\u6211\u7231\u4f60",'; %%! s2 = python_cmd (cmd) %%! assert (strcmp (s2, s3)) %!test %! % list, tuple %! assert (isequal (python_cmd ('return [1,2,3],'), {1, 2, 3})) %! assert (isequal (python_cmd ('return (4,5),'), {4, 5})) %! assert (isequal (python_cmd ('return (6,),'), {6,})) %! assert (isequal (python_cmd ('return [],'), {})) %!test %! % dict %! cmd = 'd = dict(); d["a"] = 6; d["b"] = 10; return d,'; %! d = python_cmd (cmd); %! assert (d.a == 6 && d.b == 10) symbolic-2.2.4/inst/@logical/0000755000175000001440000000000012633614672014521 5ustar cbmuserssymbolic-2.2.4/inst/@logical/isAlways.m0000644000175000001440000000255412633614672016501 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{r} =} isAlways (@var{t}) %% Test if expression is mathematically true. %% %% For inputs of type logical (true/false) this is just the %% logical itself. See sym/isAlways for why we need this function. %% %% Examples: %% @example %% @group %% >> isAlways(true) %% @result{} ans = 1 %% >> isAlways(false) %% @result{} ans = 0 %% @end group %% @end example %% %% @seealso{sym/isAlways} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = isAlways(p) r = p; end %!assert(isAlways(true)) %!assert(~isAlways(false)) symbolic-2.2.4/inst/sympref.m0000644000175000001440000002172412633614672014660 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{r} =} sympref () %% @deftypefnx {Function File} {@var{r} =} sympref (@var{cmd}) %% @deftypefnx {Function File} {} sympref @var{cmd} %% @deftypefnx {Function File} {} sympref @var{cmd} @var{args} %% Preferences for the OctSymPy symbolic computing package. %% %% @code{sympref} can set or get various preferences and %% configurations. The various choices for @var{cmd} and %% @var{args} are documented below. %% %% %% @strong{Python executable} path/command: %% @example %% @group %% >> sympref python '/usr/bin/python' @c doctest: +SKIP %% >> sympref python 'C:\Python\python.exe' @c doctest: +SKIP %% >> sympref python 'N:\myprogs\py.exe' @c doctest: +SKIP %% @end group %% @end example %% Default is an empty string; in which case OctSymPy just runs %% @code{python} and assumes the path is set appropriately. %% %% @strong{Display} of syms: %% @example %% @group %% >> sympref display %% @result{} ans = unicode %% @end group %% @group %% >> syms x %% >> sympref display flat %% >> sin(x/2) %% @result{} (sym) sin(x/2) %% %% >> sympref display ascii %% >> sin(x/2) %% @result{} (sym) %% /x\ %% sin|-| %% \2/ %% %% >> sympref display unicode %% >> sin(x/2) %% @result{} (sym) %% ⎛x⎞ %% sin⎜─⎟ %% ⎝2⎠ %% %% >> sympref display default %% @end group %% @end example %% By default OctSymPy uses the unicode pretty printer to display %% symbolic expressions. If that doesn't work (e.g., if you %% see @code{?} characters) then try the @code{ascii} option. %% %% @strong{Communication mechanism}: %% @example %% >> sympref ipc %% @result{} ans = default %% @end example %% The default will typically be the @code{popen2} mechanism which %% uses a pipe to communicate with Python and should be fairly fast. %% If that doesn't work, try @code{sympref display system} which is %% much slower, as a new Python %% process is started for each operation (many commands use more %% than one operation). %% Other options for @code{sympref ipc} include: %% @itemize %% @item @code{sympref ipc popen2}: force popen2 choice (e.g., %% on Matlab were it would not be the default). %% @item @code{sympref ipc system}: construct a long string of %% the command and pass it directly to the python interpreter with %% the @code{system()} command. This typically assembles a multiline %% string for the commands, except on Windows where a long one-line %% string is used. %% @item @code{sympref ipc systmpfile}: output the python commands %% to a @code{tmp_python_cmd.py} file and then call that [for %% debugging, may not be supported long-term]. %% @item @code{sympref ipc sysoneline}: put the python commands all %% on one line and pass to @code{python -c} using a call to @code{system()}. %% [for debugging, may not be supported long-term]. %% @end itemize %% %% @strong{Reset}: reset the SymPy communication mechanism. This can be %% useful after an error occurs and the connection with Python %% becomes confused. %% @example %% >> sympref reset @c doctest: +SKIP %% @end example %% %% @strong{Snippets}: when displaying a sym object, we quote the SymPy %% representation (or a small part of it): %% @example %% @group %% >> syms x %% >> y = [pi x]; %% >> sympref snippet on %% >> y %% @result{} y = (sym 1×2 matrix) “...([[pi, Symbol('x')]])” %% [π x] %% >> sympref snippet off %% >> y %% @result{} y = (sym) [π x] (1×2 matrix) %% >> sympref snippet default %% @end group %% @end example %% %% @strong{Default precision}: control the number of digits used by %% variable-precision arithmetic (see also the @ref{digits} command). %% @example %% @group %% >> sympref digits % get %% @result{} ans = 32 %% >> sympref digits 64 % set %% >> sympref digits default %% @end group %% @end example %% %% %% Report the @strong{version} number: %% @example %% @group %% >> sympref version %% @result{} 2.2.4 %% @end group %% @end example %% %% @seealso{sym, syms} %% @end deftypefn function varargout = sympref(cmd, arg) persistent settings if (isempty(settings)) settings = 42; sympref('defaults') end if (nargin == 0) varargout{1} = settings; return end switch lower(cmd) case 'defaults' settings = []; settings.ipc = 'default'; settings.whichpython = ''; sympref ('display', 'default') sympref ('digits', 'default') sympref ('snippet', 'default') case 'version' assert (nargin == 1) varargout{1} = '2.2.4'; case 'display' if (nargin == 1) varargout{1} = settings.display; else arg = lower (arg); if (strcmp (arg, 'default')) arg = 'unicode'; if (ispc () && (~isunix ())) % Unicode not working on Windows, Issue #83. arg = 'ascii'; end end assert(strcmp(arg, 'flat') || strcmp(arg, 'ascii') || ... strcmp(arg, 'unicode')) settings.display = arg; end case 'digits' if (nargin == 1) varargout{1} = settings.digits; else if (ischar(arg)) if (strcmpi(arg, 'default')) arg = 32; else arg = str2double(arg); end end arg = int32(arg); assert(arg > 0, 'precision must be positive') settings.digits = arg; end case 'snippet' if (nargin == 1) varargout{1} = settings.snippet; else if (strcmpi(arg, 'default')) settings.snippet = false; % Should be false for a release else settings.snippet = tf_from_input(arg); end end case 'python' if (nargin == 1) varargout{1} = settings.whichpython; elseif (isempty(arg) || strcmp(arg,'[]')) settings.whichpython = ''; sympref('reset') else settings.whichpython = arg; sympref('reset') end case 'ipc' if (nargin == 1) varargout{1} = settings.ipc; else sympref('reset') settings.ipc = arg; switch arg case 'default' disp('Choosing the default [autodetect] octsympy communication mechanism') case 'system' disp('Forcing the system() octsympy communication mechanism') case 'popen2' disp('Forcing the popen2() octsympy communication mechanism') case 'systmpfile' disp('Forcing systmpfile ipc: warning: this is for debugging') case 'sysoneline' disp('Forcing sysoneline ipc: warning: this is for debugging') otherwise warning('Unsupported IPC mechanism: hope you know what you''re doing') end end case 'reset' disp('Resetting the octsympy communication mechanism'); r = python_ipc_driver('reset', []); if (nargout == 0) if (~r) disp('Problem resetting'); end else varargout{1} = r; end %case 'path' %pkg_path = fileparts (mfilename ('fullpath')); % or %pkg_l = pkg ('list'); %idx = strcmp ('octsympy', cellfun (@(x) x.name, pkg_l, "UniformOutput", false)); %if (~ any (idx)) % error ('the package %s is not installed', your_pkg); %end %pkg_path = pkg_l{idx}.dir otherwise print_usage (); end end function r = tf_from_input(s) if (~ischar(s)) r = logical(s); elseif (strcmpi(s, 'true')) r = true; elseif (strcmpi(s, 'false')) r = false; elseif (strcmpi(s, 'on')) r = true; elseif (strcmpi(s, 'off')) r = false; elseif (strcmpi(s, '[]')) r = false; else r = str2double(s); assert(~isnan(r), 'invalid expression to convert to bool') r = logical(r); end end %!test %! % system should work on all system, but just runs sysoneline on windows %! fprintf('\nRunning some tests that reset the IPC and produce output\n'); %! sympref('ipc', 'system'); %! pause(1); %! syms x %! pause(2); %!test %! % sysoneline should work on all systems %! fprintf('\n'); %! sympref('ipc', 'sysoneline'); %! pause(1); %! syms x %! pause(2); %!test %! sympref('defaults') %! assert(strcmp(sympref('ipc'), 'default')) %!test %! fprintf('\n'); %! syms x %! r = sympref('reset'); %! pause(1); %! syms x %! pause(2); %! assert(r) symbolic-2.2.4/inst/findsymbols.m0000644000175000001440000001142212633614672015516 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{l} =} findsymbols (@var{x}) %% Return a list (cell array) of the symbols in an expression. %% %% The list is sorted alphabetically. @xref{symvar}, for details. %% %% If two variables have the same symbol but different assumptions, %% they will both appear in the output. It is not well-defined %% in what order they appear. %% %% @var{x} could be a sym, sym array, cell array, or struct. %% %% @example %% @group %% >> syms x y z %% >> C = @{x, 2*x*y, [1 x; sin(z) pi]@}; %% >> findsymbols (C) %% @result{} %% @{ %% (sym) x %% (sym) y %% (sym) z %% @} %% @end group %% @end example %% %% Note E, I, pi, etc are not counted as symbols. %% %% Note only returns symbols actually appearing in the RHS of a %% @code{symfun}. %% %% @seealso{symvar, findsym} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function L = findsymbols(obj, dosort) if nargin == 1 dosort = true; end if isa(obj, 'sym') cmd = { 'x = _ins[0]' 'if sympy.__version__ == "0.7.5":' % deprecate with Issue #164 ' if not x.is_Matrix:' ' s = x.free_symbols' ' else:' ' s = set()' ' for i in x.values():' ' s = s.union(i.free_symbols)' 'else:' ' s = x.free_symbols' 'l = list(s)' 'l = sorted(l, key=str)' 'return l,' }; L = python_cmd (cmd, obj); elseif iscell(obj) %fprintf('Recursing into a cell array of numel=%d\n', numel(obj)) L = {}; for i=1:numel(obj) temp = findsymbols(obj{i}, false); if ~isempty(temp) L = {L{:} temp{:}}; end end elseif isstruct(obj) %fprintf('Recursing into a struct array of numel=%d\n', numel(obj)) L = {}; fields = fieldnames(obj); for i=1:numel(obj) for j=1:length(fields) thisobj = getfield(obj, {i}, fields{j}); temp = findsymbols(thisobj, false); if ~isempty(temp) L = {L{:} temp{:}}; end end end else L = {}; end % sort and make unique using internal representation if dosort Ls = {}; for i=1:length(L) Ls{i} = char(L{i}); end [tilde, I] = unique(Ls); L = L(I); end end %!test %! syms x b y n a arlo %! z = a*x + b*pi*sin (n) + exp (y) + exp (sym (1)) + arlo; %! s = findsymbols (z); %! assert (isequal ([s{:}], [a,arlo,b,n,x,y])) %!test %! syms x %! s = findsymbols (x); %! assert (isequal (s{1}, x)) %!test %! syms z x y a %! s = findsymbols ([x y; 1 a]); %! assert (isequal ([s{:}], [a x y])) %!assert (isempty (findsymbols (sym (1)))) %!assert (isempty (findsymbols (sym ([1 2])))) %!assert (isempty (findsymbols (sym (nan)))) %!assert (isempty (findsymbols (sym (inf)))) %!assert (isempty (findsymbols (exp (sym (2))))) %!test %! % diff. assumptions make diff. symbols %! x1 = sym('x'); %! x2 = sym('x', 'positive'); %! f = x1*x2; %! assert (length (findsymbols (f)) == 2) %!test %! % symfun or sym %! syms x f(y) %! a = f*x; %! b = f(y)*x; %! assert (isequal (findsymbols(a), {x y})) %! assert (isequal (findsymbols(b), {x y})) %!test %! % findsymbols on symfun does not find the argnames (unless they %! % are on the RHS of course, this matches SMT 2014a). %! syms a x y %! f(x, y) = a; % const symfun %! assert (isequal (findsymbols(f), {a})) %! syms a x y %! f(x, y) = a*y; %! assert (isequal (findsymbols(f), {a y})) %!test %! % sorts lexigraphically, same as symvar *with single input* %! % (note symvar does something different with 2 inputs). %! syms A B a b x y X Y %! f = A*a*B*b*y*X*Y*x; %! assert (isequal (findsymbols(f), {A B X Y a b x y})) %! assert (isequal (symvar(f), [A B X Y a b x y])) %!test %! % symbols in matpow %! syms x y %! syms n %! if (str2num(strrep(python_cmd ('return sp.__version__,'), '.', ''))<=75) %! disp('skipping known failure b/c SymPy <= 0.7.5') %! else %! A = [sin(x) 2; y 1]; %! B = A^n; %! L = findsymbols(B); %! assert (isequal (L, {n x y})) %! end symbolic-2.2.4/inst/private/0000755000175000001440000000000012633614672014461 5ustar cbmuserssymbolic-2.2.4/inst/private/python_copy_vars_from.m0000644000175000001440000000073712633614672021277 0ustar cbmusersfunction s = python_copy_vars_from(out, tryexcept) %private function if (nargin == 1) tryexcept = true; end if (~tryexcept) %% no error checking s = { sprintf('octoutput_drv(%s)', out) }; else %% with try-except block s = { 'try:' ... sprintf(' octoutput_drv(%s)', out) ... 'except:' ... ' octoutput_drv("PYTHON: Error in var export")' ... ' myerr(sys.exc_info())' ... ' raise' }; end symbolic-2.2.4/inst/private/python_header.m0000644000175000001440000000215612633614672017474 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . function s = python_header() %private persistent PyStrCache if (isempty(PyStrCache)) thisdir = fileparts (mfilename ('fullpath')); pyfile = fullfile (thisdir, 'python_header.py'); PyStrCache = fileread (pyfile); % octave 3.6 workaround sz = size(PyStrCache); if (sz(1) > sz(2)) PyStrCache = PyStrCache'; end end s = PyStrCache; end symbolic-2.2.4/inst/private/python_ipc_driver.m0000644000175000001440000000317412633614672020373 0ustar cbmusersfunction [A, db] = python_ipc_driver(what, cmd, varargin) %PYTHON_IPC_DRIVER Run Python/SymPy command and return strings which_ipc = sympref('ipc'); %% version check if exist('octave_config_info', 'builtin') if (compare_versions (OCTAVE_VERSION (), '3.6.4', '<')) fprintf(['\n********************************************************************\n' ... 'Your Octave version is %s but Octsympy is currently untested on\n' ... 'anything before 3.6.4. For example, persistent variables don''t\n' ... 'seem to work properly on 3.2.4.\n\n'], ... OCTAVE_VERSION ()) warning('Old Octave version detected: probably trouble ahead!') fprintf('\n********************************************************************\n\n') fflush(stdout); end end if (strcmp(lower(which_ipc), 'default')) if (exist('popen2') > 1) which_ipc = 'popen2'; else which_ipc = 'system'; end end switch lower(which_ipc) case 'popen2' [A, db] = python_ipc_popen2(what, cmd, varargin{:}); case 'system' if (ispc () && (~isunix ())) [A, db] = python_ipc_sysoneline(what, cmd, false, varargin{:}); else [A, db] = python_ipc_system(what, cmd, false, varargin{:}); end case 'systmpfile' %% for debugging, not intended for long-term usage [A, db] = python_ipc_system(what, cmd, true, varargin{:}); case 'sysoneline' %% for debugging, not intended for long-term usage [A, db] = python_ipc_sysoneline(what, cmd, false, varargin{:}); otherwise error('invalid ipc mechanism') end symbolic-2.2.4/inst/private/extractblock.m0000644000175000001440000001071412633614672017327 0ustar cbmusersfunction A = extractblock(out) %private function %note: only parses the first (I think). No %particular reason it could not do more than one. % Parse xml (no xmlread in octave and this is probably faster) % this regexp creates pairs like { "text after tag"} Z = regexp(out, '(<[^<>]*>)([^<>]*)' ,'tokens'); % Now we have some code that crawls over those pairs and creates % the octave objects. i = 1; [i, A] = helper(Z, i, false); % assert (i == length(Z)), no; might be other stuff or another block assert(length(A) == 1) A = A{1}; end function [i, A] = helper(data, i, inblock) initem = false; A = {}; while (1) switch data{i}{1} case '' inblock = true; case '' assert(inblock); return case '' assert (inblock) assert (initem) item{length(item)+1} = data{i}{2}; case '' assert (inblock) assert (initem) item{length(item)+1} = []; case '' assert (inblock) assert (initem) case '' % next fields are for the item assert (inblock) assert (~initem) item = {}; initem = true; case '' assert (inblock) assert (initem) %A = [A {item}]; temp = process_item(item); %A{length(A)+1} = item; A{length(A)+1} = temp; initem = false; case '' %disp('down into list') [i, List] = helper(data, i+1, inblock); if initem item{length(item)+1} = List; else A{length(A)+1} = List; end case '' List = {}; if initem item{length(item)+1} = List; else A{length(A)+1} = List; end case '' assert (inblock) return otherwise %if strcmpi(data{i}{1}(1:5), ''s for these not raw ? str = str_post_xml_filter(C{2}); flat = str_post_xml_filter(C{5}); ascii = str_post_xml_filter(C{6}); unicode = str_post_xml_filter(C{7}); % empty [] here identifies this to the sym ctor r = sym([], str, [sz1 sz2], flat, ascii, unicode); case OCTCODE_DICT %warning('FIXME: wip'); keys = C{2}{1}; vals = C{3}{1}; % FIXME: why the {1} here? %r = cell2struct(C{2}{1}, C{3}{1}) % no assert(length(keys) == length(vals)) r = struct(); for i=1:length(keys) r = setfield (r, keys{i}, vals{i}); end case OCTCODE_ERROR assert(M == 2) str1 = str_post_xml_filter(C{2}); str2 = str_post_xml_filter(C{3}); disp('extractblock: read an error back from python') str1 str2 %disp('Continuing, but unsure if its safe to do so!') r = 'there was a python error'; error('error reading back from python') otherwise C error('extractblock: not implemented or something wrong'); end end function r = str_post_xml_filter(r) r = strrep(r, '<', '<'); r = strrep(r, '>', '>'); r = strrep(r, '"', '"'); % must be last: r = strrep(r, '&', '&'); end symbolic-2.2.4/inst/private/magic_str_str.m0000644000175000001440000000240712633614672017502 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{s} =} magic_str_str (@var{x}) %% Recognize special string values and substitute others. %% %% Private function. %% %% @seealso{sym, vpa} %% @end deftypefn function s = magic_str_str(x, varargin) if (~ischar(x)) error('OctSymPy:magic_str_str:notstring', ... 'Expected a string'); end if (strcmpi(x, 'inf')) || (strcmpi(x, '+inf')) s = 'oo'; elseif (strcmpi(x, '-inf')) s = '-oo'; elseif (strcmpi(x, 'i')) s = 'I'; else s = x; end end symbolic-2.2.4/inst/private/my_print_usage.m0000644000175000001440000000272412633614672017671 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} print_usage () %% Wrapper for print_usage on Matlab. %% %% Matlab has no print_usage function. Preparing %% the Matlab package should rename this from %% "my_print_usage.m" to "print_usage.m". %% %% @seealso{error} %% @end deftypefn function print_usage () % if we are on Octave if (exist ('octave_config_info', 'builtin')) %evalin ('caller', 'print_usage ();' ); %return end H = dbstack; name = H(2).name; msgid = sprintf('%s:invalidCall', name); errmsg = sprintf('Invalid call to "%s": see documentation', name); %error('Invalid call to "%s": see documentation', name) ME = MException(msgid, errmsg); ME.throwAsCaller(); end symbolic-2.2.4/inst/private/python_copy_vars_to.m0000644000175000001440000000630012633614672020746 0ustar cbmusersfunction L = python_copy_vars_to(in, te, varargin) %private function if (~te) %% no error checking L = do_list(0, in, varargin); L = { sprintf('%s = []', in) ... L{:} }; else %% put inside try-except L = do_list(4, in, varargin); L = { 'try:' ... sprintf(' %s = []', in) ... L{:} ... ' octoutput_drv("PYTHON: successful variable import")' ... 'except:' ... ' octoutput_drv("PYTHON: Error in variable import")' ... ' myerr(sys.exc_info())' ... ' raise' }; end end function a = do_list(indent, in, varlist) sp = repmat(' ', 1, indent); a = {}; c = 0; for i = 1:numel(varlist) x = varlist{i}; if (isa(x,'sym')) c=c+1; a{c} = [sp '# sym']; % need to be careful here: pickle might have escape codes % .append(pickle.loads("""%s"""))', x.pickle) % The extra printf around the pickle helps if it still has % escape codes (and seems harmless if it does not) % Issue #107: x.pickle fails for matrices, use char() as workaround c=c+1; a{c} = sprintf('%s%s.append(%s)', sp, in, sprintf(char(x))); elseif (ischar(x)) c=c+1; a{c} = [sp in '.append("' x '")']; % or do we want a printf() around the string? %c=c+1; a{c} = sprintf('%s%s.append("%s")', sp, in, x); elseif (islogical(x) && isscalar(x)) if (x) c=c+1; a{c} = [sp in '.append(True)']; else c=c+1; a{c} = [sp in '.append(False)']; end elseif (isinteger(x) && isscalar(x)) c=c+1; a{c} = sprintf('%s%s.append(%s) # int type', ... sp, in, num2str(x, '%ld')); elseif (isfloat(x) && isscalar(x)) % Floating point input. By default, all Octave numbers are % IEEE double: we pass these using the exact hex % representation. We could detect and treat % (double-precision) integers specially (which might % help with indexing in some places) but I think it might be % too magical. For now, all doubles become floats in Python. if (isa(x, 'single')) x = double(x); % don't hate, would happen in Python anyway end c=c+1; a{c} = sprintf('%s%s.append(hex2d("%s")) # double', ... sp, in, num2hex(x)); elseif (iscell(x)) c=c+1; a{c} = [sp '# cell array: xfer to list']; inn = [in 'n']; c=c+1; a{c} = sprintf('%s%s = []', sp, inn); c=c+1; a{c} = sprintf('%s%s.append(%s)', sp, in, inn); b = do_list(indent, inn, x); a = {a{:} b{:}}; c = length(a); elseif (isstruct(x) && isscalar(x)) c=c+1; a{c} = [sp '# struct: xfer to dict']; inkeys = [in 'k']; invalues = [in 'v']; c=c+1; a{c} = sprintf('%s%s = []', sp, inkeys); b = do_list(indent, inkeys, fieldnames(x)); a = {a{:} b{:}}; c = length(a); c=c+1; a{c} = sprintf('%s%s = []', sp, invalues); b = do_list(indent, invalues, struct2cell(x)); a = {a{:} b{:}}; c = length(a); c=c+1; a{c} = sprintf('%s%s.append(dict(zip(%s,%s)))', sp, in, inkeys, invalues); else i, x error('don''t know how to move that variable to python'); end end c=c+1; a{c} = [sp '# end of a list']; end symbolic-2.2.4/inst/private/python_ipc_popen2.m0000644000175000001440000000733012633614672020301 0ustar cbmusersfunction [A, out] = python_ipc_popen2(what, cmd, varargin) % "out" provided for debugging persistent fin fout pid py_startup_timeout = 30; % seconds if (strcmp(what, 'reset')) if (~isempty(pid)) disp('Closing the Python pipe...'); end if (~isempty(fin)) t = fclose(fin); fin = []; waitpid(pid); pid = []; A = (t == 0); else A = true; end if (~isempty(fout)) t = fclose(fout); fout = []; A = A && (t == 0); end out = []; return end if ~(strcmp(what, 'run')) error('unsupported command') end newl = sprintf('\n'); vstr = sympref('version'); if isempty(pid) disp(['OctSymPy v' vstr ': this is free software without warranty, see source.']) disp('Initializing communication with SymPy using a popen2() pipe.') pyexec = sympref('python'); if (isempty(pyexec)) if (ispc() && ~isunix()) % Octave popen2 on Windows can't tolerate stderr output % https://savannah.gnu.org/bugs/?43036 disp(['Detected Windows: using "winwrapy.bat" to workaround Octave bug #43036']) pyexec = 'winwrapy.bat'; else pyexec = 'python'; end end % perhaps the the '-i' is not always wanted? [fin, fout, pid] = popen2 (pyexec, '-i'); fprintf('Some output from the Python subprocess (pid %d) might appear next.\n', pid) %fprintf('Technical details: fin = %d, fout = %d, pid = %d.\n', fin, fout, pid) fflush (stdout); if (pid < 0) error('popen2() failed'); end % repeated from python_header.py: kill prompt ASAP fprintf (fin, 'import sys\nsys.ps1 = ""; sys.ps2 = ""\n\n') fflush(fin); %sleep(0.05); %disp('') headers = python_header(); fputs (fin, headers); fprintf (fin, '\n\n'); %fflush(fin); %sleep(0.05); disp(''); % print a block then read it to make sure we're live fprintf (fin, 'octoutput_drv(("Communication established.", sympy.__version__, sys.version))\n\n'); fflush(fin); % if any exceptions in start-up, we probably get those instead [out, err] = readblock(fout, py_startup_timeout); if (err) error('OctSymPy:python_ipc_popen2:timeout', ... 'ipc_popen2: something wrong? timed out starting python') end A = extractblock(out); fprintf('\n') if (isempty(strfind(A{1}, 'established'))) A out error('ipc_popen2: something has gone wrong in starting python') else disp(['OctSymPy: ' A{1} ' SymPy v' A{2} '.']); % on unix we're seen this on stderr if (ispc() && ~isunix()) disp(['Python ' strrep(A{3}, newl, '')]) end end end %% load all the inputs into python as pickles % they will be in the list '_ins' % there is a try-except block here, sends a block if sucessful loc = python_copy_vars_to('_ins', true, varargin{:}); write_lines(fin, loc, true); fflush(fin); [out, err] = readblock(fout, inf); if (err) error('OctSymPy:python_ipc_popen2:xfer', ... 'ipc_popen2: xfer vars: something wrong? timed out?') end % could extractblock here, but just search for keyword instead if (isempty(strfind(out, 'successful'))) out A = extractblock(out) error('ipc_popen2: failed to send variables to python?') end %% The actual command % cmd will be a snippet of python code that does something % with _ins and produce _outs. s = python_format_cmd(cmd); %% output, or perhaps a thrown error s2 = python_copy_vars_from('_outs'); write_lines(fin, s, true) write_lines(fin, s2, true) fflush(fin); [out, err] = readblock(fout, inf); if (err) error('OctSymPy:python_ipc_popen2:cmderr', ... 'ipc_popen2: cmd error? read block returned error'); end A = extractblock(out); symbolic-2.2.4/inst/private/python_format_cmd.m0000644000175000001440000000126212633614672020354 0ustar cbmusersfunction s = python_format_cmd(cmd, tryexcept) %private function % cmd will be a snippet of python code that does something % with _ins and produce _outs. if (nargin == 1) tryexcept = true; end if (~tryexcept) %% no error checking s = cmd; else %% with try-except block % replace blank lines w/ empty comments I = cellfun(@isempty, cmd); % cmd(I) = '#'; % fails on matlab cmd(I) = repmat({'#'}, 1, nnz(I)); cmd = indent_lines(cmd, 4); s = { 'try:' ... cmd{:} ... 'except:' ... ' octoutput_drv("PYTHON: Error in cmd")' ... ' myerr(sys.exc_info())' ... ' raise' }; end symbolic-2.2.4/inst/private/readblock.m0000644000175000001440000000532312633614672016570 0ustar cbmusersfunction [A, err] = readblock(fout, timeout) %private function: read one block % how long to wait before displaying "Waiting..." wait_disp_thres = 4.0; tagblock = ''; tagendblock = ''; err = false; EAGAIN = errno ('EAGAIN'); % Windows emits this when pipe is waiting (see % octave/libinterp/corefcn/syscalls.cc test code) EINVAL = errno ('EINVAL'); done = false; started = false; nwaits = 0; dispw = false; start = time(); fclear (fout); % otherwise, fails on next call do if (ispc () && (~isunix ())) errno (0); % win32, see syscalls.cc test code end s = fgets (fout); if (ischar (s)) %fputs (stdout, s); if (started) A = [A s]; end % here is the tag, so start recording output if (strncmp(s, tagblock, length(tagblock))) started = true; A = s; end % if we see the end tag, we're done if (strncmp(s, tagendblock, length(tagendblock))) done = true; end elseif (errno() == EAGAIN || errno() == EINVAL) waitdelta = exp(nwaits/10)/1e4; if (time() - start <= wait_disp_thres) %fprintf(stdout, 'W'); % debugging, in general do nothing elseif (~dispw) fprintf(stdout, 'Waiting...') dispw = true; else fprintf(stdout, '.') end fclear (fout); %if (ispc () && (~isunix ())) %errno (0); % maybe can do this on win32? %end sleep (waitdelta); nwaits = nwaits + 1; elseif (errno() == 0) waitdelta = exp(nwaits/10)/1e4; if (time() - start <= wait_disp_thres) %fprintf(stdout, 'W'); % debugging, in general do nothing elseif (~dispw) fprintf(stdout, '[usually something wrong if you see stars] Waiting***') dispw = true; else fprintf(stdout, '*') end fclear (fout); %if (ispc () && (~isunix ())) %errno (0); % maybe can do this on win32? %end sleep (waitdelta); nwaits = nwaits + 1; else warning ('OctSymPy:readblock:invaliderrno', ... sprintf('readblock: s=%d, errno=%d, perhaps error in the command?', s, errno())) sleep(0.1) % FIXME; replace with waitdelta etc end %disp('paused'); pause if (time() - start > timeout) warning('OctSymPy:readblock:timeout', ... sprintf('readblock: timeout of %g exceeded, breaking out', timeout)); if (started) disp('output so far:') A else disp('no output so far') A = ''; end A = [A '\nFAILED TIMEOUT\n']; err = true; break end until (done) if (dispw) fprintf(stdout, '\n') end %fclose (fout); %waitpid (pid); symbolic-2.2.4/inst/private/indent_lines.m0000644000175000001440000000045312633614672017314 0ustar cbmusersfunction B = indent_lines(A, n) % indent each line in the cell array A by n spaces pad = repmat(' ', 1, n); if (0 == 1) % 27s B = cellfun(@(x) [pad x], A, 'UniformOutput', false); else % 23s B = cell(size(A)); for i = 1:numel(A) B{i} = [pad A{i}]; end end end symbolic-2.2.4/inst/private/valid_sym_assumptions.m0000644000175000001440000000206412633614672021275 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{L}} valid_sym_assumptions () %% @deftypefnx {Function File} {} syms %% Return list of valid assumptions. %% %% @end deftypefn function L = valid_sym_assumptions() L = {'real', 'positive', 'negative', 'integer', 'even', 'odd', ... 'rational', 'finite'}; end symbolic-2.2.4/inst/private/python_ipc_sysoneline.m0000644000175000001440000000603012633614672021262 0ustar cbmusersfunction [A, out] = python_ipc_sysoneline(what, cmd, mktmpfile, varargin) % "out" is provided for debugging persistent show_msg if (strcmp(what, 'reset')) show_msg = []; A = true; out = []; return end if ~(strcmp(what, 'run')) error('unsupported command') end vstr = sympref('version'); if (isempty(show_msg)) disp(['OctSymPy v' vstr ': this is free software without warranty, see source.']) disp('Using system()-based communication with Python [sysoneline].') disp('Warning: this will be *SLOW*. Every round-trip involves executing a') disp('new Python process and many operations involve several round-trips.') show_msg = true; end newl = sprintf('\n'); %% Headers % embedding the headers in the -c command is too long for % Windows. We have a 8000 char budget, and the header uses all % of it. mydir = fileparts (mfilename ('fullpath')); % execfile() only works on python 2 headers = ['exec(open(\"' mydir filesep() 'python_header.py\").read()); ']; %s = python_header_embed2(); %headers = ['exec(\"' s '\"); ']; %% load all the inputs into python as pickles s = python_copy_vars_to('_ins', true, varargin{:}); % extra escaping s = myesc(s); % join all the cell arrays with escaped newline s = mystrjoin(s, '\\n'); s1 = ['exec(\"' s '\"); ']; %% The actual command % cmd will be a snippet of python code that does something % with _ins and produce _outs. s = python_format_cmd(cmd); s = myesc(s); s = mystrjoin(s, '\\n'); s2 = ['exec(\"' s '\"); ']; %% output, or perhaps a thrown error s = python_copy_vars_from('_outs'); s = myesc(s); s = mystrjoin(s, '\\n'); s3 = ['exec(\"' s '\");']; pyexec = sympref('python'); if (isempty(pyexec)) pyexec = 'python'; end bigs = [headers s1 s2 s3]; if (~mktmpfile) %% paste all the commands into the system() command line % python -c [status,out] = system([pyexec ' -c "' bigs '"']); else %% Generate a temp shell script then execute it with system() % This is for debugging ipc; not intended for general use fname = 'tmp_python_cmd.sh'; fd = fopen(fname, 'w'); fprintf(fd, '#!/bin/sh\n\n'); fprintf(fd, '# temporary autogenerated code\n\n'); fputs(fd, [pyexec ' -c "']); fputs(fd, bigs); fputs(fd, '"'); fclose(fd); [status,out] = system(['sh ' fname]); end if status ~= 0 status out error('system() call failed!'); end % there should be two blocks ind = strfind(out, ''); assert(length(ind) == 2) out1 = out(ind(1):(ind(2)-1)); % could extractblock here, but just search for keyword instead if (isempty(strfind(out1, 'successful'))) error('failed to import variables to python?') end A = extractblock(out(ind(2):end)); end function s = myesc(s) for i = 1:length(s) % order is important here % escape quotes twice s{i} = strrep(s{i}, '\', '\\\\'); % dbl-quote is rather special here % /" -> ///////" -> ///" -> /" -> " s{i} = strrep(s{i}, '"', '\\\"'); end end symbolic-2.2.4/inst/private/mystrjoin.m0000644000175000001440000000246012633614672016677 0ustar cbmusersfunction s = mystrjoin(A, sepchar) % replacement for strjoin until Octave 3.6 is old persistent have_strjoin if isempty(have_strjoin) % this test is slow if it does not exist (6s for 1000 calls) % (28s w/, 24 w/o) so we cache the result if (exist('strjoin') > 1) have_strjoin = true; else have_strjoin = false; end end if (have_strjoin) s = strjoin(A, sepchar); return end %% we have no strjoin, do our own n = numel(A); % The builtin strjoin in Octave and Matlab do this too (that is, need % to call with '\\n' to join with '\n'. sepchar = sprintf(sepchar); if (n == 0) s = ''; else s = A{1}; end for i = 2:n s = [s sepchar A{i}]; end end %try % s = strjoin(A, sepchar); %catch % [msg, msgid] = lasterr (); % if ~strncmp(msg, '''strjoin'' undefined', 19) % error(msgid, msg) % end %end % for loop above is 23s % 23s %L(2,:) = repmat({newl}, 1, length(L)); %fputs(f, [L{:}]); % 27s %B = cellfun(@(x) fputs(f, [x newl]), L); % 27s %B = cellfun(@(x) [x newl], L, 'UniformOutput', false); %fputs (f, [B{:}]); % 30s %B = cellfun(@(x) [x newl], L, 'UniformOutput', false); %B = cellfun(@(x) fputs(f, x), B); % 24 s %for i = 1:length(L) % fputs (f, L{i}); % fputs (f, newl); %end symbolic-2.2.4/inst/private/write_lines.m0000644000175000001440000000025012633614672017160 0ustar cbmusersfunction A = write_lines(f, L, xtra) %private function newl = sprintf('\n'); if (xtra) L(end+1:end+2) = {'' ''}; end fputs(f, mystrjoin(L, newl)); end symbolic-2.2.4/inst/private/magic_double_str.m0000644000175000001440000000323612633614672020145 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {[@var{s}, @var{flag}] =} magic_double_str (@var{x}) %% Recognize special double values. %% %% Private helper function. %% %% Caution: there are two copies of this file for technical %% reasons: make sure you modify both of them! %% %% @seealso{sym, vpa} %% @end deftypefn function [s, flag] = magic_double_str(x) flag = 1; if (~isa(x, 'double') || ~isreal(x)) error('OctSymPy:magic_double_str:notrealdouble', ... 'Expected a real double precision number'); end % NOTE: yes, these are floating point equality checks! if (x == pi) s = 'pi'; elseif (x == -pi) s = '-pi'; elseif ((isinf(x)) && (x > 0)) s = 'inf'; elseif ((isinf(x)) && (x < 0)) s = '-inf'; elseif (isnan(x)) s = 'nan'; elseif (isreal(x) && (mod(x,1) == 0)) % is integer s = num2str(x); % better than sprintf('%d', large) else s = ''; flag = 0; end end symbolic-2.2.4/inst/private/python_ipc_system.m0000644000175000001440000000513012633614672020416 0ustar cbmusersfunction [A, out] = python_ipc_system(what, cmd, mktmpfile, varargin) % "out" is provided for debugging persistent show_msg if (strcmp(what, 'reset')) show_msg = []; A = true; out = []; return end if ~(strcmp(what, 'run')) error('unsupported command') end vstr = sympref('version'); if (isempty(show_msg)) disp(['OctSymPy v' vstr ': this is free software without warranty, see source.']) disp('You are using the slower system() communications with SymPy.') disp('Warning: this will be *SLOW*. Every round-trip involves executing a') disp('new python process and many operations involve several round-trips.') show_msg = true; end newl = sprintf('\n'); %% Headers headers = python_header(); %% load all the inputs into python as pickles s1 = python_copy_vars_to('_ins', true, varargin{:}); %% The actual command % cmd will be a snippet of python code that does something % with _ins and produce _outs. s2 = python_format_cmd(cmd); %% output, or perhaps a thrown error s3 = python_copy_vars_from('_outs'); % join all the cell arrays with newlined s = mystrjoin([s1 s2 s3], newl); pyexec = sympref('python'); if (isempty(pyexec)) pyexec = 'python'; end %% FIXME: Issue #63: with new regexp code on Matlab % workaround: % sympref python 'LD_LIBRARY_PATH="" python' % to prevent a conflict with the expat shipped with Matlab 2014a % See here with oracle % https://bugzilla.redhat.com/show_bug.cgi?id=821337 % FIXME: make this the default on Matlab install? bigs = [headers s]; if (~mktmpfile) %% paste all the commands into the system() command line % escaping: cmd or inputs might have \" % " -> \" % \" -> \\\" % \n -> \\n bigs = strrep(bigs, '\', '\\'); bigs = strrep(bigs, '"', '\"'); [status,out] = system([pyexec ' -c "' bigs '"']); else %% Generate a temp .py file then execute it with system() % can be useful for debugging, or if "python -c" fails for you fname = 'tmp_python_cmd.py'; fd = fopen(fname, 'w'); fprintf(fd, '# temporary autogenerated code\n\n'); fputs(fd, bigs); fclose(fd); [status,out] = system([pyexec ' ' fname]); end if status ~= 0 status out error('system() call failed!'); end % there should be two blocks ind = strfind(out, ''); assert(length(ind) == 2) out1 = out(ind(1):(ind(2)-1)); % could extractblock here, but just search for keyword instead if (isempty(strfind(out1, 'successful'))) error('failed to import variables to python?') end A = extractblock(out(ind(2):end)); symbolic-2.2.4/inst/private/python_header.py0000644000175000001440000002253012633614672017666 0ustar cbmusers# Part of OctSymPy. # In some cases this code is fed into stdin: two blank lines between # try-except blocks, no blank lines within each block. from __future__ import print_function from __future__ import division import sys sys.ps1 = ""; sys.ps2 = "" def myerr(e): # hardcoded in case no xml print("") print("\n9999\n") print(str(e[0]).replace("&", "&").replace("<", "<").replace(">", ">")) print("") print(str(e[1]).replace("&", "&").replace("<", "<").replace(">", ">")) print("\n") print("\n") try: import sympy import sympy as sp # need this to reactivate from srepr from sympy import * import sympy.printing from sympy.logic.boolalg import Boolean, BooleanFunction from sympy.core.relational import Relational # temporary? for piecewise support from sympy.functions.elementary.piecewise import ExprCondPair import copy import binascii import struct import xml.etree.ElementTree as ET except: myerr(sys.exc_info()) raise try: def dbout(l): sys.stderr.write("pydebug: " + str(l) + "\n") def d2hex(x): # used to pass doubles back-and-forth (.decode for py3) return binascii.hexlify(struct.pack(">d", x)).decode() def hex2d(s): if sys.version_info >= (3, 0): bins = bytes([int(s[x:x+2], 16) for x in range(0, len(s), 2)]) else: bins = "".join(chr(int(s[x:x+2], 16)) for x in range(0, len(s), 2)) return struct.unpack(">d", bins)[0] def dictdiff(a, b): """ keys from a that are not in b, used by evalpy() """ n = dict() for k in a: if not k in b: n[k] = a[k] return n except: myerr(sys.exc_info()) raise # FIXME: Remove all this when we deprecate 0.7.6.x support. if not (sympy.__version__ == "0.7.5" or sympy.__version__.startswith("0.7.6")): my_srepr = sympy.srepr else: def _monkey_patch_matpow_doit(self, **kwargs): deep = kwargs.get('deep', True) if deep: args = [arg.doit(**kwargs) for arg in self.args] else: args = self.args base = args[0] exp = args[1] if isinstance(base, MatrixBase) and exp.is_number: if exp is S.One: return base return base**exp if exp.is_zero and base.is_square: return Identity(base.shape[0]) elif exp is S.One: return base return MatPow(base, exp) sympy.MatPow.doit = _monkey_patch_matpow_doit sympy.MatAdd.doit_orig = sympy.MatAdd.doit def _monkey_patch_matadd_doit(self, **kwargs): deep = kwargs.get('deep', True) if deep: args = [arg.doit(**kwargs) for arg in self.args] else: args = self.args return MatAdd(*args).doit_orig(**kwargs) sympy.MatAdd.doit = _monkey_patch_matadd_doit try: class _ReprPrinter_w_asm(sympy.printing.repr.ReprPrinter): def _print_Symbol(self, expr): asm = expr.assumptions0 # SymPy < 0.7.7: srepr does not list assumptions. # Abbreviate some common cases. asm_default = {"commutative":True} asm_real = {"commutative":True, "complex":True, "hermitian":True, "imaginary":False, "real":True} asm_pos = {"commutative":True, "complex":True, "hermitian":True, "imaginary":False, "negative":False, "nonnegative":True, "nonpositive":False, "nonzero":True, "positive":True, "real":True, "zero":False} asm_neg = {"commutative":True, "complex":True, "hermitian":True, "imaginary":False, "negative":True, "nonnegative":False, "nonpositive":True, "nonzero":True, "positive":False, "prime":False, "composite":False, "real":True, "zero":False} if asm == asm_default: xtra = "" elif asm == asm_real: xtra = ", real=True" elif asm == asm_pos: xtra = ", positive=True" elif asm == asm_neg: xtra = ", negative=True" else: xtra = "" for (key, val) in asm.items(): xtra = xtra + ", %s=%s" % (key, val) return "%s(%s%s)" % (expr.__class__.__name__, self._print(expr.name), xtra) # def my_srepr(expr, **settings): """return expr in repr form w/ assumptions listed""" return _ReprPrinter_w_asm(settings).doprint(expr) except: myerr(sys.exc_info()) raise try: def objectfilter(x): """Perform final fixes before passing objects back to Octave""" if isinstance(x, sp.Matrix) and x.shape == (1, 1): return x[0, 0] #elif isinstance(x, sp.MatrixExpr): # return x.doit() return x # def octoutput_drv(x): xroot = ET.Element("output_block") octoutput(x, xroot) # simple, but no newlines and escapes unicode #print(ET.tostring(xroot)) #print("\n") # Clashes with some expat lib in Matlab, Issue #63 import xml.dom.minidom as minidom DOM = minidom.parseString(ET.tostring(xroot)) if sys.version_info >= (3, 0): print(DOM.toprettyxml(indent="", newl="\n")) else: print(DOM.toprettyxml(indent="", newl="\n", encoding="utf-8")) except: myerr(sys.exc_info()) raise try: # FIXME: unicode may not have enough escaping, but cannot string_escape def octoutput(x, et): OCTCODE_INT = 1001 OCTCODE_DOUBLE = 1002 OCTCODE_STR = 1003 OCTCODE_USTR = 1004 OCTCODE_BOOL = 1005 OCTCODE_DICT = 1010 OCTCODE_SYM = 1020 x = objectfilter(x) if isinstance(x, bool): a = ET.SubElement(et, "item") f = ET.SubElement(a, "f") f.text = str(OCTCODE_BOOL) f = ET.SubElement(a, "f") f.text = str(x) elif isinstance(x, (sp.Basic, sp.MatrixBase)): if isinstance(x, (sp.Matrix, sp.ImmutableMatrix)): _d = x.shape elif isinstance(x, (sp.Expr, Boolean)): _d = (1, 1) elif isinstance(x, sp.MatrixExpr): # nan for symbolic size _d = [float('nan') if (isinstance(r, sp.Basic) and not r.is_Integer) else r for r in x.shape] else: dbout("Treating unexpected SymPy obj as scalar: " + str(type(x))) _d = (1,1) pretty_ascii = sp.pretty(x, use_unicode=False) pretty_unicode = sp.pretty(x, use_unicode=True) a = ET.SubElement(et, "item") f = ET.SubElement(a, "f") f.text = str(OCTCODE_SYM) f = ET.SubElement(a, "f") f.text = my_srepr(x) f = ET.SubElement(a, "f") f.text = str(_d[0]) f = ET.SubElement(a, "f") f.text = str(_d[1]) f = ET.SubElement(a, "f") f.text = str(x) f = ET.SubElement(a, "f") f.text = pretty_ascii f = ET.SubElement(a, "f") f.text = pretty_unicode elif isinstance(x, (list, tuple)): c = ET.SubElement(et, "list") for y in x: octoutput(y, c) elif isinstance(x, int): a = ET.SubElement(et, "item") f = ET.SubElement(a, "f") f.text = str(OCTCODE_INT) f = ET.SubElement(a, "f") f.text = str(x) elif isinstance(x, float): # We pass IEEE doubles using the exact hex representation a = ET.SubElement(et, "item") f = ET.SubElement(a, "f") f.text = str(OCTCODE_DOUBLE) f = ET.SubElement(a, "f") f.text = d2hex(x) elif isinstance(x, str) or (sys.version_info < (3, 0) and isinstance(x, unicode)): a = ET.SubElement(et, "item") f = ET.SubElement(a, "f") f.text = str(OCTCODE_STR) f = ET.SubElement(a, "f") f.text = x elif isinstance(x, dict): # Note: the dict cannot be too complex, keys must convert to # strings for example. Values can be dicts, lists. a = ET.SubElement(et, "item") f = ET.SubElement(a, "f") f.text = str(OCTCODE_DICT) # Convert keys to strings keystr = [str(y) for y in x.keys()] c = ET.SubElement(a, "list") octoutput(keystr, c) c = ET.SubElement(a, "list") # FIXME: bit of a kludge, use iterable instead of list, tuple above? if sys.version_info >= (3, 0): octoutput(list(x.values()), c) else: octoutput(x.values(), c) else: dbout("error exporting variable:") dbout("x: " + str(x)) dbout("type: " + str(type(x))) octoutput("python does not know how to export type " + str(type(x)), et) except: myerr(sys.exc_info()) raise # end of python header, now couple blank lines symbolic-2.2.4/inst/private/mystrsplit.m0000644000175000001440000000053512633614672017074 0ustar cbmusersfunction tok = mystrsplit(str, sep) % like strsplit but less erratic across old octave/matlab n = []; for i = 1:length(sep) n = [n strfind(str, sep{i})]; end n = sort(unique(n)); endd = [n-1 length(str)]; start = [1 n+1]; tok = {}; c = 0; for i=1:length(start) c = c + 1; tok{c} = str(start(i):endd(i)); end end symbolic-2.2.4/inst/@symfun/0000755000175000001440000000000012633614672014430 5ustar cbmuserssymbolic-2.2.4/inst/@symfun/ldivide.m0000644000175000001440000000224112633614672016225 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} ldivide (@var{f}, @var{g}) %% Component-wise backslash division of symbolic functions. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = ldivide(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 .\ s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f .\ f, 'symfun')) %! assert( isa(f .\ x, 'symfun')) symbolic-2.2.4/inst/@symfun/symfun.m0000644000175000001440000001675112633614672016141 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{f} =} symfun (@var{expr}, @var{vars}) %% Define a symbolic function (not usually called directly). %% %% A symfun can be abstract or concrete. An abstract symfun %% represents an unknown function (for example, in a differential %% equation). A concrete symfun represents a known function such as %% @iftex %% @math{f(x) = \sin(x)}. %% @end iftex %% @ifnottex %% f(x) = sin(x). %% @end ifnottex %% %% A concrete symfun: %% @example %% >> syms x %% >> f(x) = sin(x) %% @result{} f(x) = (symfun) sin(x) %% >> f %% @result{} f(x) = (symfun) sin(x) %% >> f(1) %% @result{} ans = (sym) sin(1) %% >> f(x) %% @result{} ans = (sym) sin(x) %% @end example %% %% An abstract symfun: %% @example %% >> syms g(x) %% >> g %% @result{} g(x) = (symfun) g(x) %% @end example %% and note this creates the sym @code{x} automatically. %% %% Alternatively: %% @example %% >> x = sym('x'); %% >> g(x) = sym('g(x)') %% @result{} g(x) = (symfun) g(x) %% @end example %% Note the following is @strong{not} the way to create an abstract %% symfun: %% @example %% >> g = sym('g(x)') % just the symbolic expression g(x) %% @result{} g = (sym) g(x) %% @end example %% Instead, use @code{g(x)} on the left-hand side as above. %% %% You can make multidimensional concrete or abstract symfuns: %% @example %% >> syms x y %% >> g(x, y) = 2*x + sin(y) %% @result{} g(x, y) = (symfun) 2⋅x + sin(y) %% >> syms g(x, y) %% >> g %% @result{} g(x, y) = (symfun) g(x, y) %% @end example %% However, on old versions of Octave (before 4.0), one needs to %% workaround a parsing bug: %% @example %% >> syms 'g(x, y)' %% >> g %% @result{} g(x, y) = (symfun) g(x, y) %% @end example %% %% As the above examples demonstrate, it is usually not necessary to %% call symfun directly. However, it can be done: %% @example %% >> syms x y %% >> f = symfun(sin(x), x) %% @result{} f(x) = (symfun) sin(x) %% >> F = symfun(x*y, [x y]) %% @result{} F(x, y) = (symfun) x⋅y %% >> g = symfun(sym('g(x)'), x) %% @result{} g(x) = (symfun) g(x) %% >> G = symfun(sym('G(x, y)'), [x y]) %% @result{} G(x, y) = (symfun) G(x, y) %% @end example %% %% This allows, for example, creating an abstract function formally %% of @code{x}, @code{y} but depending only on @code{x}: %% @example %% >> syms x y %% >> h = symfun(sym('h(x)'), [x y]) %% @result{} h(x, y) = (symfun) h(x) %% @end example %% which is the same as: %% @example %% >> h(x,y) = sym('h(x)') %% @result{} h(x, y) = (symfun) h(x) %% @end example %% %% @seealso{sym, syms} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, symbols, CAS function f = symfun(expr, vars) if (nargin == 0) % octave docs say need a no-argument default for loading from files expr = sym(0); vars = sym('x'); elseif (nargin == 1) print_usage (); end % if the vars are in a sym array, put them in a cell array if (isa( vars, 'sym')) varsarray = vars; vars = cell(1, numel(varsarray)); for i = 1:numel(varsarray) vars{i} = varsarray(i); end end if (ischar (expr)) % FIXME: drop this later warning('symfun: deprecated: symfun(''f'', x) format not supported') tok = mystrsplit(expr, {'(', ')', ','}); fname = strtrim(tok{1}); assert (isvarname (fname)) cmd = {['_f = sp.Function("' fname '")(*_ins)'] ... 'return (_f,)' }; expr = python_cmd (cmd, vars{:}); end if (isa(expr, 'symfun')) % allow symfun(, x) expr = expr.sym; else % e.g., allow symfun(, x) expr = sym(expr); end assert (isa (vars, 'cell')) for i=1:length(vars) assert (isa (vars{i}, 'sym')) end f.vars = vars; f = class(f, 'symfun', expr); superiorto ('sym'); end %!test %! syms x y %! syms f(x) %! assert(isa(f,'symfun')) %! clear f %! f(x,y) = sym('f(x,y)'); %! assert(isa(f,'symfun')) %!test %! % symfuns are syms as well %! syms x %! f(x) = 2*x; %! assert (isa (f, 'symfun')) %! assert (isa (f, 'sym')) %! assert (isequal (f(3), 6)) %! assert (isequal (f(sin(x)), 2*sin(x))) %!test %! syms x y %! f = symfun(sym('f(x)'), {x}); %! assert(isa(f, 'symfun')) %! f = symfun(sym('f(x,y)'), [x y]); %! assert(isa(f, 'symfun')) %! f = symfun(sym('f(x,y)'), {x y}); %! assert(isa(f, 'symfun')) %!test %! % rhs is not sym %! syms x %! f = symfun(8, x); %! assert (isa (f,'symfun')) %! assert (isequal (f(10), sym(8))) %!test %! % vector symfun %! syms x y %! F(x,y) = [1; 2*x; y; y*sin(x)]; %! assert (isa (F, 'symfun')) %! assert (isa (F, 'sym')) %! assert (isequal (F(sym(pi)/2,4) , [sym(1); sym(pi); 4; 4] )) %!test %! x = sym('x'); %! y = sym('y'); %! f(x) = sym('f(x)'); %! g(x,y) = sym('g(x,y)'); %! % make sure these don't fail %! f(1); %! g(1,2); %! g(x,y); %! diff(g, x); %! diff(g, y); %!test %! % defining 1D symfun in terms of a 2D symfun %! syms x y t %! syms 'g(x,y)' %! f(t) = g(t,t); %! f(5); %! assert (length (argnames (f)) == 1) %! assert (isequal (argnames (f), t)) %! assert (isequal( diff(f,x), sym(0))) %!test %! % replace g with shorter and specific fcn %! syms x g(x) %! g; %! g(x) = 2*x; %! assert( isequal (g(5), 10)) %!test %! % octave <= 3.8 needs quotes on 2D symfuns, so make sure it works %! syms x y %! syms 'f(x)' %! syms 'g(x,y)' %! assert (isa (f, 'symfun')) %! assert (isa (g, 'symfun')) %!test %! % Bug #41: Octave <= 3.8 parser fails without quotes around 2D fcn %! % (put inside eval to hide from 3.6 parser) %! if exist('octave_config_info', 'builtin') %! if (compare_versions (OCTAVE_VERSION (), '4.0.0', '>=')) %! syms x y %! eval('syms g(x,y)') %! assert (isa (g, 'symfun')) %! end %! else % matlab %! syms x y %! eval('syms g(x,y)') %! assert (isa (g, 'symfun')) %! end %!test %! % syms f(x) without defining x %! clear %! syms f(x) %! assert(isa(f, 'symfun')) %! assert(isa(x, 'sym')) %!test %! syms x y %! f(x) = x^2; %! g(x,y) = sym('g(x,y)'); %! f2 = 2*f; %! assert( isequal (f2(4), 32)) %! assert( isa(f2, 'symfun')) %! assert( isa(2*g, 'symfun')) %! assert( isa(0*g, 'symfun')) % in SMT, this is the zero symfun %!test %! % syms has its own parsing code, check it works %! syms 'f(x,y)' %! g = f; %! syms 'f(x, y)' %! assert (isequal (f, g)) %! syms 'f( x, y )' %! assert (isequal (f, g)) %!test %! % syms own parsing code should not reorder the vars %! syms 'f(y, x)' %! v = f.vars; %! assert (isequal (v{1}, y) && isequal (v{2}, x)) %!test %! % assignment of symfun to symfun, issue #189 %! syms t %! x(t) = 2*t; %! y(t) = x; %! assert (isa (y, 'symfun')) %! y = symfun(x, t); %! assert (isa (y, 'symfun')) %! % others %! y = x; %! assert (isa (y, 'symfun')) %! y(t) = x(t); %! assert (isa (y, 'symfun')) %!test %! % assignment of generic symfun to symfun %! syms t x(t) %! y(t) = x; %! assert (isa (y, 'symfun')) %! y = symfun(x, t); %! assert (isa (y, 'symfun')) symbolic-2.2.4/inst/@symfun/private/0000755000175000001440000000000012633614672016102 5ustar cbmuserssymbolic-2.2.4/inst/@symfun/private/mystrsplit.m0000644000175000001440000000053512633614672020515 0ustar cbmusersfunction tok = mystrsplit(str, sep) % like strsplit but less erratic across old octave/matlab n = []; for i = 1:length(sep) n = [n strfind(str, sep{i})]; end n = sort(unique(n)); endd = [n-1 length(str)]; start = [1 n+1]; tok = {}; c = 0; for i=1:length(start) c = c + 1; tok{c} = str(start(i):endd(i)); end end symbolic-2.2.4/inst/@symfun/private/helper_symfun_binops.m0000644000175000001440000000243712633614672022520 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . function [vars,s1,s2] = helper_symfun_binops(f, g) if (isa(f,'symfun')) && (isa(g, 'symfun')) %disp('debug: symfun symfun') if ~isequal(f.vars, g.vars) error('arithmetric operators on symfuns must have same vars') end vars = f.vars; s1 = f.sym; s2 = g.sym; elseif (isa(f,'symfun')) %disp('debug: symfun sym') vars = f.vars; s1 = f.sym; s2 = g; elseif (isa(g, 'symfun')) %disp('debug: sym symfun') vars = g.vars; s1 = f; s2 = g.sym; else error('Tertium Non Datur') end symbolic-2.2.4/inst/@symfun/symvar.m0000644000175000001440000001266612633614672016142 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{vars} =} symvar (@var{f}) %% @deftypefnx {Function File} {@var{vars} =} symvar (@var{f}, @var{n}) %% Find symbols in symfun and return them as a symbolic vector. %% %% If @var{n} specified, we take from the explicit function variables %% first followed by the output of @code{symvar} on any other symbols %% in the sym (expression) of the symfun. %% %% Example: %% @example %% @group %% >> syms a x f(t, s) %% >> symvar (f, 1) %% @result{} (sym) t %% >> symvar (f, 2) %% @result{} (sym) [t s] (1×2 matrix) %% @end group %% @end example %% Note preference for the arguments of the symfun: %% @example %% @group %% >> h = f*a + x %% @result{} h(t, s) = (symfun) a⋅f(t, s) + x %% >> symvar (h, 1) %% @result{} (sym) t %% >> symvar (h, 2) %% @result{} (sym) [t s] (1×2 matrix) %% >> symvar (h, 3) %% @result{} (sym) [t s x] (1×3 matrix) %% >> symvar (h, 4) %% @result{} (sym) [t s x a] (1×4 matrix) %% @end group %% @end example %% %% On the other hand, if @var{n} is omitted, the results are %% sorted as explained elsewhere (@pxref{@@sym/symvar}). %% For example: %% @example %% @group %% >> symvar (f, 2) %% @result{} (sym) [t s] (1×2 matrix) %% >> symvar (f) %% @result{} (sym) [s t] (1×2 matrix) %% >> symvar (h) %% @result{} (sym) [a s t x] (1×4 matrix) %% @end group %% @end example %% %% @strong{Compatibility with other implementations}: the output generally %% matches the equivalent command in the Matlab Symbolic Toolbox %% (tested with version 2014a). For example: %% @example %% @group %% >> syms x y s t %% >> f(t, s) = 1 %% @result{} f(t, s) = (symfun) 1 %% >> symvar (f, 1) %% @result{} (sym) t %% >> symvar (f, 2) %% @result{} (sym) [t s] (1×2 matrix) %% @end group %% @end example %% However, when the symfun formula does not depend on the %% arguments, the results are not the same: %% @example %% @group %% >> symvar (f) % SMT would give [] %% @result{} (sym) [s t] (1×2 matrix) %% @end group %% @end example %% %% If two variables have the same symbol but different assumptions, %% they will both appear in the output. It is not well-defined %% in what order they appear. %% %% @seealso{findsym, findsymbols, argnames, formula} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function vars = symvar(F, Nout) if (nargin == 1) % Note: symvar(symfun) differs from SMT, see test below vars = symvar([F.vars{:} F.sym(:)]); else assert(Nout >= 0, 'number of requested symbols should be positive') M = length(F.vars); vars = sym([]); % take first few from F.vars for i = 1:min(Nout, M) vars(i) = F.vars{i}; end if (Nout == length(vars)) return end symvars = symvar(F.sym, inf); symvars = remove_dupes(symvars, vars); vars = [vars symvars(1:min(end, Nout-M))]; end end function a = remove_dupes(symvars, vars) M = length(vars); % ones(1, 3, 'logical') doesn't work in Matlab keep = logical(ones(1, length(symvars))); for j = 1:length(symvars) for i = 1:M if (strcmp(char(symvars(j)), char(vars(i)))) keep(j) = false; break end end end a = symvars(keep); end %!test %! % basic, quotes are oct 3.6 workaround %! syms 'f(t, s)' %! assert (isequal (symvar (f, 0), sym([]))) %! assert (isequal (symvar (f, 1), t)) %! assert (isequal (symvar (f, 2), [t s])) %! assert (isequal (symvar (f, 3), [t s])) %!test %! % note preference for vars of symfun, if n requested %! syms x f(y) %! assert (isequal (symvar(f*x, 1), y)) %! assert (isequal (symvar(f(y)*x, 1), x)) %!test %! % symfun, checked smt %! syms x f(y) %! a = f*x; %! b = f(y)*x; %! assert (isequal (symvar(a), [x y])) %! assert (isequal (symvar(b), [x y])) %!test %! % preference for the explicit variables %! syms a x 'f(t, s)' %! h = f*a + x; %! assert (isequal (symvar (h, 1), t)) %! assert (isequal (symvar (h, 2), [t s])) %! assert (isequal (symvar (h, 3), [t s x])) %! assert (isequal (symvar (h, 4), [t s x a])) %! assert (isequal (symvar (h, 5), [t s x a])) %! assert (isequal (symvar (h), [a s t x])) %!test %! % symfun dep on some vars only, matches smt w/ n %! syms x s t %! f(s) = x; %! g(s, t) = x*s; %! assert (isequal (symvar(f, 1), s)) %! assert (isequal (symvar(f, 2), [s x])) %! assert (isequal (symvar(g, 1), s)) %! assert (isequal (symvar(g, 2), [s t])) %! assert (isequal (symvar(g, 3), [s t x])) %!test %! % A documented difference from SMT on symvar(symfun) w/o n %! syms x s t %! f(s) = x; %! g(s, t) = x*s; %! % SMT would have %! %assert (isequal (symvar(f), x)) % no s %! %assert (isequal (symvar(g), [s x])) % no t %! assert (isequal (symvar(f), [s x])) %! assert (isequal (symvar(g), [s t x])) symbolic-2.2.4/inst/@symfun/mtimes.m0000644000175000001440000000221112633614672016100 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} mtimes (@var{f}, @var{g}) %% Symbolic function multiplication (*). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = mtimes(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 * s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f * f, 'symfun')) %! assert( isa(f * x, 'symfun')) symbolic-2.2.4/inst/@symfun/power.m0000644000175000001440000000244712633614672015751 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} power (@var{f}, @var{g}) %% Symbolic function componentwise exponentiation (dot^). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = power(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 .^ s2, vars); end %!test %! syms x %! f(x) = 2*x; %! h = f.^f; %! assert( isa(h, 'symfun')) %! assert( isequal (h.sym, (2*x)^(2*x))) %!test %! syms x %! f(x) = [x 2*x]; %! h = f.^[x 3]; %! assert( isa(h, 'symfun')) %! assert( isequal (h.sym, [x^x 8*x^3])) symbolic-2.2.4/inst/@symfun/priv_disp_name.m0000644000175000001440000000315212633614672017606 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{s} =} priv_disp_name (@var{f}) %% A string appropriate for representing the name of this symfun. %% %% Private method: this is not the method you are looking for. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function s = priv_disp_name(f, input_name) if (isempty(input_name)) s = input_name; return end vars = f.vars; if length(vars) == 0 varstr = ''; else v = vars{1}; varstr = v.flat; end for i = 2:length(vars); v = vars{i}; varstr = [varstr ', ' v.flat]; end s = [input_name, '(', varstr, ')']; end %!test %! syms f(x) %! s = priv_disp_name(f, 'f'); %! assert (strcmp (s, 'f(x)')) %!test %! syms x y %! g(y, x) = x + y; %! s = priv_disp_name(g, 'g'); %! assert (strcmp (s, 'g(y, x)')) %!test %! syms f(x) %! assert (isempty (priv_disp_name(f, ''))) symbolic-2.2.4/inst/@symfun/minus.m0000644000175000001440000000472712633614672015753 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} minus (@var{f}, @var{g}) %% Subtract one symbolic function from another (-). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = minus(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 - s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f - f, 'symfun')) %! assert( isa(f - x, 'symfun')) %!test %! % Octave bug: https://savannah.gnu.org/bugs/?42735 %! syms x %! f(x) = x^2; %! g = x^2; %! s = warning('off', 'OctSymPy:sym:arithmetic:workaround42735'); %! h = x - f; assert(isa(h, 'symfun') && isequal(h.sym, x - g)) %! h = x + f; assert(isa(h, 'symfun') && isequal(h.sym, x + g)) %! h = x * f; assert(isa(h, 'symfun') && isequal(h.sym, x * g)) %! h = x / f; assert(isa(h, 'symfun') && isequal(h.sym, x / g)) %! h = x ^ f; assert(isa(h, 'symfun') && isequal(h.sym, x ^ g)) %! h = x .* f; assert(isa(h, 'symfun') && isequal(h.sym, x .* g)) %! h = x ./ f; assert(isa(h, 'symfun') && isequal(h.sym, x ./ g)) %! h = x .^ f; assert(isa(h, 'symfun') && isequal(h.sym, x .^ g)) %! warning(s); %!test %! % different variables %! syms x y %! f(x) = 2*x; %! g(y) = sin(y); %! h = f - g(x); %! assert( isa(h, 'symfun')) %! assert( isequal (argnames (h), argnames (f))) %! assert( isequal (h.sym, 2*x - sin(x))) %! % and even if rh-sym has a dummy variable: %! h = f - g(y); %! assert( isa(h, 'symfun')) %! assert( isequal (argnames (h), argnames(f))) %! assert( isequal (h.sym, 2*x - sin(y))) %!test %! % different variables, f has more %! syms x y %! f(x,y) = 2*x*y; %! g(y) = sin(y); %! h = f - g(y) + g(x); %! assert( isa(h, 'symfun')) %! assert( isequal (argnames (h), argnames (f))) %! assert( isequal (h.sym, 2*x*y - sin(y) + sin(x))) symbolic-2.2.4/inst/@symfun/times.m0000644000175000001440000000242512633614672015732 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} times (@var{f}, @var{g}) %% Symbolic function componentwise multiplication (dot*). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = times(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 .* s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f .* f, 'symfun')) %! assert( isa(f .* x, 'symfun')) %!test %! syms x %! f(x) = [x 2*x]; %! h = f.*[x 3]; %! assert( isa(h, 'symfun')) %! assert( isequal (h.sym, [x^2 6*x])) symbolic-2.2.4/inst/@symfun/size.m0000644000175000001440000000323012633614672015556 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{d} =} size (@var{x}) %% @deftypefnx {Function File} {[@var{n}, @var{m}] =} size (@var{x}) %% @deftypefnx {Function File} {@var{d} =} size (@var{x}, @var{dim}) %% Return the size of a symbolic function. %% %% @seealso{length, numel} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [n, m] = size(x, dim) n = [1 1]; if (nargin == 2) && (nargout == 2) print_usage (); elseif (nargout == 2) m = 1; n = 1; elseif (nargin == 2) n = 1; end end %!test %! syms x %! f(x) = x; %! d = size(f); %! assert (isequal (d, [1 1])) %! [n, m] = size(f); %! assert (isequal ([n m], [1 1])) %! assert (size(f, 1) == 1) %! assert (size(f, 2) == 1) %!test %! syms x %! f(x) = [1 x]; %! d = size(f); %! assert (isequal (d, [1 1])) %! [n, m] = size(f); %! assert (isequal ([n m], [1 1])) %! assert (size(f, 1) == 1) %! assert (size(f, 2) == 1) symbolic-2.2.4/inst/@symfun/argnames.m0000644000175000001440000000336412633614672016411 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald and others %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{vars} =} argnames (@var{f}) %% Return the independent variables in a symfun. %% %% The counterpart of @code{argname} is @code{formula}: %% @code{argname} for the independent %% variables and @code{formula} for the dependent expression. %% %% Examples: %% @example %% @group %% >> syms x y %% >> f(x, y) = x^2; %% >> argnames(f) %% @result{} (sym) [x y] (1×2 matrix) %% @end group %% @end example %% %% @seealso{@@symfun/formula, symvar, findsym, findsymbols} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function vars = argnames(F) vars = [F.vars{:}]; end %!test %! % basic test %! syms f(x) %! assert (isequal (argnames (f), x)) %!test %! % Multiple variables, abstract symfun (quotes are oct 3.6 workaround) %! syms 'f(t, x, y)' %! assert (isequal (argnames (f), [t x y])) %!test %! % Concrete symfun %! syms x y z t %! f(t, x, y) = x + y + z; %! assert (isequal (argnames (f), [t x y])) symbolic-2.2.4/inst/@symfun/numel.m0000644000175000001440000000227712633614672015736 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{n} =} numel (@var{f}) %% Number of elements in symbolic array of symfuns. %% %% FIXME: Why do I need this in the subclass symfun? why is it called so much? %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function n = numel(f) % see issue #107, #109 n = 1; end %!test %! syms x %! f(x) = x^2; %! assert(numel(f)==1) %!test %! syms x %! f(x) = [1 x]; %! assert(numel(f)==1) symbolic-2.2.4/inst/@symfun/rdivide.m0000644000175000001440000000244012633614672016234 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} rdivide (@var{f}, @var{g}) %% Forward slash component division of symbolic functions (dot/). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = rdivide(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 ./ s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f./f, 'symfun')) %! assert( isa(f./[x x^2], 'symfun')) %!test %! syms x %! f(x) = [x 2*x]; %! h = f./[x 2]; %! assert( isa(h, 'symfun')) %! assert( isequal (h.sym, [1 x])) symbolic-2.2.4/inst/@symfun/plus.m0000644000175000001440000000221012633614672015564 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} plus (@var{f}, @var{g}) %% Add two symbolic functions together (+). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = plus(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 + s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f + f, 'symfun')) %! assert( isa(f + x, 'symfun')) symbolic-2.2.4/inst/@symfun/int.m0000644000175000001440000000564412633614672015411 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} int (@var{f}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{x}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{x}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{x}, [@var{a}, @var{b}]) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, [@var{a}, @var{b}]) %% Symbolic integration of a symfun. %% %% Indefinite integrals of a symfun returns a symfun. Definite %% integrals return a sym. %% %% See help for sym int. %% %% @seealso{diff} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, integration function F = int(f, varargin) if (nargin == 1) indefinite = true; elseif (nargin == 2) && (numel(varargin{1}) == 1) % "int(f, x)" but not "int(f, [a b])" indefinite = true; else indefinite = false; end F = int(f.sym, varargin{:}); if (indefinite) F = symfun(F, f.vars); end end %!test %! % indefinite integral of symfun gives symfun %! syms x %! f(x) = x^2; %! g = int(f); %! assert (isa(g, 'symfun')) %! g = int(f, x); %! assert (isa(g, 'symfun')) %!test %! % indefinite integral of abstract symfun gives symfun %! syms f(x) %! g = int(f); %! assert (isa(g, 'symfun')) %! g = int(f, x); %! assert (isa(g, 'symfun')) %!test %! % definite integral does not give symfun %! syms x %! f(x) = x^2; %! g = int(f, x, 0, 2); %! assert (isa(g, 'sym')) %! assert (~isa(g, 'symfun')) %!test %! % ... even if it has a variable in it %! syms x t %! f(x) = x; %! g = int(f, x, 0, t); %! assert (isa(g, 'sym')) %! assert (~isa(g, 'symfun')) %!test %! % ... even if the input is abstract funcion %! syms f(x) %! g = int(f, x, 0, 2); %! assert (isa(g, 'sym')) %! assert (~isa(g, 'symfun')) %!test %! % symfun in x, integrated in y gives symfun still in x %! % (SMT does this too). %! syms f(x) y %! g = int(f, y); %! assert (isa (g, 'symfun')) %! assert (isequal (argnames (g), x)) %!test %! % same as above, but concrete symfun %! syms x y %! f(x) = x^2; %! g = int(f, y); %! assert (isa (g, 'symfun')) %! assert (isequal (argnames (g), x)) %! assert (isequal (g, x^2*y)) symbolic-2.2.4/inst/@symfun/diff.m0000644000175000001440000000510112633614672015513 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{g} =} diff (@var{f}) %% @deftypefnx {Function File} {@var{g} =} diff (@var{f}, @var{x}) %% @deftypefnx {Function File} {@var{g} =} diff (@var{f}, @dots{}) %% Symbolic differentiation of symbolic functions. %% %% Mostly the same as @code{diff} for class @code{sym} (indeed it %% calls that code) but returns a @code{symfun}. %% %% The derivative is itself a symfun so you can evaluate at a point like: %% @example %% >> syms u(x) %% >> up = diff(u) % u'(x) %% @result{} up(x) = (symfun) %% d %% ──(u(x)) %% dx %% >> up(2) % u'(2) %% @result{} ans = (sym) %% ⎛d ⎞│ %% ⎜──(u(x))⎟│ %% ⎝dx ⎠│x=2 %% @end example %% %% At least on GNU Octave, a further shortcut is possible: %% @example %% >> syms u(x) %% >> diff(u)(2) %% @result{} ans = (sym) %% ⎛d ⎞│ %% ⎜──(u(x))⎟│ %% ⎝dx ⎠│x=2 %% %% >> syms f(x, y) %% >> diff(f, x, y, y)(3, 2) % a third partial eval at (3, 2) %% @result{} ans = (sym) %% ⎛⎛ 3 ⎞│ ⎞│ %% ⎜⎜ ∂ ⎟│ ⎟│ %% ⎜⎜──────(f(x, y))⎟│ ⎟│ %% ⎜⎜ 2 ⎟│ ⎟│ %% ⎝⎝∂y ∂x ⎠│x=3⎠│y=2 %% @end example %% %% @seealso{int} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, differentiation function z = diff(f, varargin) z = diff(f.sym, varargin{:}); z = symfun(z, f.vars); end %!test %! % concrete fcn %! syms x %! f(x) = x*x; %! g(x) = 2*x; %! assert (logical (diff(f) == g)) %! assert (isa (diff(f), 'symfun')) %!test %! % abstract fcn %! syms y(x) %! assert (logical (diff(y) == diff(y(x)))) %! assert (isa (diff(y), 'symfun')) symbolic-2.2.4/inst/@symfun/formula.m0000644000175000001440000000400112633614672016246 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g}} formula (@var{f}) %% Return a symbolic expression for this symfun. %% %% This returns the expression that defines the function given by %% the symfun @var{f}. Typically this is the RHS of the symfun: %% @example %% @group %% >> syms x %% >> f(x) = sin(x); %% >> formula(f) %% @result{} ans = (sym) sin(x) %% @end group %% @end example %% %% The command @ref{argname} gives the independent variables of the %% @@symfun. Basically, @code{argname} for the independent %% variables and @code{formula} for the dependent expression. %% %% If the symfun @var{f} is abstract, this returns @var{f} as a %% sym: %% @example %% @group %% >> syms f(x) %% >> formula(f) % but note it's a sym %% @result{} ans = (sym) f(x) %% @end group %% @end example %% %% @seealso{@@symfun/argnames} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function g = formula(f) g = f.sym; end %!test %! % simple %! syms x %! f(x) = sin(x); %! g = formula(f); %! assert (isequal (g, sin(x))); %!test %! % concrete: return is a sym, not a symfun %! syms x %! f(x) = sin(x); %! g = formula(f); %! assert (~isa(g, 'symfun')); %!test %! % abstract: return is a sym, not a symfun %! syms f(x) %! g = formula(f); %! assert (~isa(g, 'symfun')); symbolic-2.2.4/inst/@symfun/mrdivide.m0000644000175000001440000000222512633614672016412 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} mrdivide (@var{f}, @var{g}) %% Forward slash division of symbolic functions (/). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = mrdivide(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 / s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f/f, 'symfun')) %! assert( isa(f/x, 'symfun')) symbolic-2.2.4/inst/@symfun/subsref.m0000644000175000001440000000333112633614672016257 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{out} =} subsref (@var{f}, @var{idx}) %% Overloaded () reference for symfuns. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function out = subsref (f, idx) switch idx.type case '()' out = subs(f, f.vars, idx.subs); case '.' fld = idx.subs; if (strcmp (fld, 'vars')) out = f.vars; elseif (strcmp (fld, 'sym')) out = f.sym; else %out = sym/subsref(f, idx); %out = f.sym.fld; %warning(' is there a better way to call the superclass fcn?') out = subsref(f.sym,idx); end otherwise error ('@symfun/subsref: invalid subscript type ''%s''', idx.type); end end %!test %! syms x %! f(x) = x^2; %! v = f.vars; %! assert(iscell(v)) %! assert(length(v)==1) %! assert(isequal(v{1},x)) %!test %! %% pass through to sym properties %! syms x %! f(x) = x^2; %! y = x^2; % not a symfun %! assert(strcmp(f.flat, y.flat)) symbolic-2.2.4/inst/@symfun/mldivide.m0000644000175000001440000000221512633614672016403 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} mldivide (@var{f}, @var{g}) %% Backslash division of symbolic functions. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = mldivide(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 \ s2, vars); end %!test %! syms x %! f(x) = x^2; %! assert( isa(f\f, 'symfun')) %! assert( isa(f\x, 'symfun')) symbolic-2.2.4/inst/@symfun/mpower.m0000644000175000001440000000235012633614672016117 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} mpower (@var{f}, @var{g}) %% Symbolic function exponentiation (^). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = mpower(f, g) [vars, s1, s2] = helper_symfun_binops(f, g); h = symfun(s1 ^ s2, vars); end %!test %! syms x %! f(x) = 2*x; %! h = f^f; %! assert( isa(h, 'symfun')) %! assert( isequal(h.sym, (2*x)^(2*x))) %! h = f^sym(2); %! assert( isa(h, 'symfun')) %! assert( isequal(h.sym, 4*x^2)) symbolic-2.2.4/inst/assumptions.m0000644000175000001440000002216612633614672015561 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{A} =} assumptions () %% @deftypefnx {Function File} {@var{A} =} assumptions (@var{x}) %% @deftypefnx {Function File} {[@var{v}, @var{d}] =} assumptions (@var{x}, 'dict') %% @deftypefnx {Function File} {@var{L} =} assumptions ('possible') %% List assumptions on symbolic variables. %% %% The assumptions are returned as a cell-array of strings: %% @example %% @group %% >> syms x y positive %% >> syms n integer %% >> assumptions %% @result{} ans = %% @{ %% [1,1] = n: integer %% [1,2] = x: positive %% [1,3] = y: positive %% @} %% >> f = sin(n*x); %% >> assumptions(f) %% @result{} ans = %% @{ %% [1,1] = n: integer %% [1,2] = x: positive %% @} %% >> assumptions(n) %% @result{} ans = %% @{ %% [1,1] = n: integer %% @} %% @end group %% @end example %% %% With the optional second argument set to the string @code{'dict'}, %% return the assumption dictionaries in @var{d} corresponding %% to the variables in @var{v}. %% %% You can also get a list of possible assumptions: %% @example %% @group %% >> A = assumptions('possible'); %% >> sprintf('%s ', A@{:@}) %% @result{} ans = real positive negative integer even odd rational finite %% @end group %% @end example %% %% @seealso{sym, syms, assume, assumeAlso} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [A, B] = assumptions(F, outp) if ((nargin == 1) && ischar(F) && strcmp(F, 'possible')) A = valid_sym_assumptions(); return end if ((nargin == 0) || isempty(F)) find_all_free_symbols = true; else find_all_free_symbols = false; end if (nargin <= 1) outp = 'no'; end if (find_all_free_symbols) %% no input arguments % find all syms, check each for free symbols workspace = {}; context = 'caller'; S = evalin(context, 'whos'); evalin(context, '[];'); % clear 'ans' for i = 1:numel(S) workspace{i} = evalin(context, S(i).name); end F = findsymbols(workspace); end % Nice and easy on SymPy >= 0.7.7 % FIXME: See also, sym.m and syms.m, updates there? cmd = { 'x = _ins[0]' 'outputdict = _ins[1]' 'd = x._assumptions.generator' 'if d == {}:' ' astr = ""' 'elif all(d.values()):' % all True so list them ' astr = ", ".join([str(i) for i in d.keys()])' 'else:' % more complicated case, just the raw dict ' astr = str(d)' 'if outputdict:' ' return (astr, d)' 'else:' ' return astr,' }; % FIXME: Deprecate 0.7.6.x. But on older SymPy we do some foolishness. % Abbreviate certain assumption dicts to shorter equivalent forms. % I look forward to deleting all this. oldsympy = python_cmd('return sympy.__version__ == "0.7.5" or sympy.__version__.startswith("0.7.6"),'); if (oldsympy) cmd = { 'x = _ins[0]' 'outputdict = _ins[1]' '# saved cases to abbreviate later' 'adict_default = {"commutative":True}' 'adict_real = {"commutative":True, "complex":True, "hermitian":True, "imaginary":False, "real":True}' 'adict_pos = {"commutative":True, "complex":True, "hermitian":True, "imaginary":False, "negative":False, "nonnegative":True, "nonpositive":False, "nonzero":True, "positive":True, "real":True, "zero":False}' 'adict_neg = {"commutative":True, "complex":True, "hermitian":True, "imaginary":False, "negative":True, "nonnegative":False, "nonpositive":True, "nonzero":True, "positive":False, "prime":False, "composite":False, "real":True, "zero":False}' 'adict_odd = {"even":False, "nonzero":True, "commutative":True, "noninteger":False, "hermitian":True, "zero":False, "complex":True, "rational":True, "real":True, "integer":True, "imaginary":False, "odd":True, "irrational":False}' 'adict_even = {"real":True, "even":True, "commutative":True, "noninteger":False, "hermitian":True, "complex":True, "rational":True, "integer":True, "imaginary":False, "odd":False, "irrational":False}' 'adict_even_076 = {"real":True, "even":True, "commutative":True, "noninteger":False, "hermitian":True, "complex":True, "rational":True, "integer":True, "imaginary":False, "odd":False, "irrational":False}' 'adict_integer = {"real":True, "commutative":True, "noninteger":False, "hermitian":True, "complex":True, "rational":True, "integer":True, "imaginary":False, "irrational":False}' 'adict_rational = {"real":True, "commutative":True, "hermitian":True, "complex":True, "rational":True, "imaginary":False, "irrational":False}' 'if sympy.__version__.startswith("0.7.6"):' ' new076 = {"algebraic":True, "transcendental":False}' ' adict_integer.update(new076)' ' adict_even.update(new076)' ' adict_odd.update(new076)' ' adict_rational.update(new076)' 'adict = x.assumptions0' 'if adict == adict_default:' ' astr = ""' ' #adict={}' 'elif adict == adict_real:' ' astr = "real"' ' #adict = {"real":True}' 'elif adict == adict_pos:' ' astr = "positive"' ' #adict = {"positive":True}' 'elif adict == adict_neg:' ' astr = "negative"' ' #adict = {"negative":False}' 'elif adict == adict_integer:' ' astr = "integer"' ' #adict = {"integer":True}' 'elif adict == adict_even:' ' astr = "even"' ' #adict = {"even":True}' 'elif adict == adict_odd:' ' astr = "odd"' ' #adict = {"odd":True}' 'elif adict == adict_rational:' ' astr = "rational"' ' #adict = {"rational":True}' 'else:' ' astr = str(adict)' ' astr = astr.replace("True","1").replace("False","0").replace(": ",":")' '#astr = str(x) + ": " + astr' 'if outputdict:' ' return (astr,adict)' 'else:' ' return (astr,)' }; end c = 0; A = {}; if strcmp(outp, 'dict') B = {}; end if (isempty(F)) return end s = findsymbols(F); for i=1:length(s) x = s{i}; if strcmp(outp, 'dict') [astr, adict] = python_cmd(cmd, x, true); if ~isempty(astr) c = c + 1; A{c} = x; B{c} = adict; end else astr = python_cmd(cmd, x, false); if ~isempty(astr) c = c + 1; str = [x.flat ': ' astr]; A{c} = str; %if c == 1 % A = str; %elseif c == 2 % A = {A str}; %else % A{c} = str; %end end end end end %!test %! syms x %! assert(isempty(assumptions(x))) %!test %! x = sym('x', 'positive'); %! a = assumptions(x); %! assert(~isempty(strfind(a{1}, 'positive'))) %!test %! syms x %! assert(isempty(assumptions(x))) %!test %! clear % for matlab test script %! syms x positive %! assert(~isempty(assumptions())) %! clear %! assert(isempty(assumptions())) %!test %! A = {'real' 'positive' 'negative' 'integer' 'even' 'odd' 'rational'}; %! % FIXME: remove once SymPy 0.7.6 support deprecated %! for i = 1:length(A) %! x = sym('x', A{i}); %! a = assumptions(x); %! assert(strcmp(a{1}, ['x: ' A{i}] )) %! end %!test %! if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=761) %! disp('skipping: char(x) of assumptions suboptimal in <= 0.7.6.x') %! else %! A = assumptions('possible'); %! for i = 1:length(A) %! x = sym('x', A{i}); %! a = assumptions(x); %! assert(strcmp(a{1}, ['x: ' A{i}] )) %! s1 = char(x); %! s2 = ['Symbol(''x'', ' A{i} '=True)']; %! assert (strcmp (s1, s2)) %! end %! end %!test %! syms x positive %! syms y real %! syms z %! f = x*y*z; %! a = assumptions(f); %! assert(length(a) == 2) %! assert(~isempty(strfind(a{1}, 'positive'))) %! assert(~isempty(strfind(a{2}, 'real'))) %!test %! % dict output %! syms x positive %! syms y real %! syms z %! f = x*y*z; %! [v, d] = assumptions(f, 'dict'); %! assert(length(v) == 2) %! assert(iscell(v)) %! assert(isa(v{1}, 'sym')) %! assert(isa(v{2}, 'sym')) %! assert(length(d) == 2) %! assert(iscell(d)) %! assert(isstruct(d{1})) %! assert(isstruct(d{2})) %!test %! %% assumptions on just the vars in an expression %! clear % for matlab test script %! syms x y positive %! f = 2*x; %! assert(length(assumptions(f))==1) %! assert(length(assumptions())==2) %!test %! %% assumptions in cell/struct %! clear % for matlab test script %! syms x y z w positive %! f = {2*x [1 2 y] {1, {z}}}; %! assert(length(assumptions())==4) %! assert(length(assumptions(f))==3) %! clear x y z w %! assert(length(assumptions())==3) %! assert(length(assumptions(f))==3) symbolic-2.2.4/inst/evalpy.m0000644000175000001440000001410312633614672014464 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} evalpy (@var{cmd}) %% @deftypefnx {Function File} {} evalpy (@var{cmd}, @var{x}, @var{y}, @dots{}) %% Run Python code, automatically transferring results. %% %% Examples: %% @example %% @group %% >> x = -4; %% >> evalpy ('y = 2*x', x) %% @result{} y = -8 %% >> y %% @result{} y = -8 %% @end group %% @end example %% %% You can replace @code{x} with a new value in the Python code: %% @example %% @group %% >> syms x %% >> evalpy ('y = 3*x; x = -1.5; z = x**2', x) %% @result{} %% x = -1.5000 %% y = (sym) 3⋅x %% z = 2.2500 %% @end group %% @end example %% %% All arguments can be accessed as @code{i0}, @code{i1}, etc. %% This is useful if they don't have inputnames: %% @example %% @group %% >> x = 10; %% >> evalpy ('y = ", ".join( (str(x),str(i0),str(i1)) )', x, 5) %% @result{} y = 10.0, 10.0, 5.0 %% @end group %% @end example %% %% If you need a variable in Python but don't want it passed back %% to Octave, put an @code{_} (underscore) at the beginning or end. %% @example %% @group %% >> x = 20; %% >> evalpy ('_y = 3*x; z_ = _y/6; my = z_/2;', x) %% @result{} Variables effected: my %% >> _y %% @result{} ??? '_y' undefined near line 1 column 1 %% >> z_ %% @result{} ??? 'z_' undefined near line 1 column 1 %% @end group %% @end example %% %% The final few characters of @var{cmd} effect the verbosity: %% @itemize %% @item 2 semicolons @code{;;}, very quiet, no output. %% @item 1 semicolon @code{;}, a one-line msg about variables assigned. %% @item no semicolon, display each variable assigned. %% @end itemize %% %% Multiline code should be placed in a cell array, see the %% @code{python_cmd} documentation. %% %% Warning: evalpy is probably too smart for its own good. It is %% intended for interactive use. In your non-interactive code, you %% might want @code{python_cmd} instead. %% %% Notes: %% @itemize %% @item if you assign to @var{x} but don't change its value, %% it will not be assigned to and will not appear in the %% Variables effected:" list. %% @item using print is probably a bad idea. For now, use %% @code{dbout(x)} to print @code{x} to stderr which should %% appear in the terminal (FIXME: currently broken on windows). %% @item evalpy is a bit of a work-in-progress and subject to %% change. For example, with a proper IPC mechanism, you could %% grab the values of @var{x} etc when needed and not need to %% specify them as args. %% @end itemize %% %% @seealso{python_cmd} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: python function evalpy(cmd, varargin) %% import variables % use name of input if it has one, also i0, i1, etc s = {}; for i = 1:(nargin-1) s{end+1} = sprintf('i%d = _ins[%d]', i-1, i-1); name = inputname(i+1); if ~isempty(name) s{end+1} = sprintf('%s = _ins[%d]', name, i-1); s{end+1} = sprintf('_%s_orig = copy.copy(%s)', name, name); end end vars2py = s; %% generate code which checks if inputs have changed s = {}; for i = 1:(nargin-1) name = inputname(i+1); if ~isempty(name) s{end+1} = sprintf('if not %s == _%s_orig:', name, name); s{end+1} = sprintf(' _newvars["%s"] = %s', name, name); end end changed_vars_also_export = s; %s = ''; %e = findstr(cmd, '=') %for i = 1:length(e); % n = e(i); % cmd(n) %end %% Examine end of cmd if ~iscell(cmd) cmd = {cmd}; end % count semicolons s = cmd{end}; if strcmp(s(end-1:end),';;') verbosity = 0; cmd{end} = s(1:end-1); % ;; is syntax error in python elseif s(end) == ';' verbosity = 1; else verbosity = 2; end fullcmd = { ... vars2py{:} ... '_vars1 = locals().copy()' ... cmd{:} ... '_vars2 = locals().copy()' ... '_newvars = dictdiff(_vars2, _vars1)' ... changed_vars_also_export{:} ... '_names = []' ... 'for key in _newvars:' ... ' if not (key[0] == "_" or key[-1] == "_"):' ... ' _outs.append(_vars2[key])' ... ' _names.append(key)' ... 'return (_names,_outs,)' }; %% debugging %fprintf('\n*** ***\n') %disp(fullcmd) %fprintf('\n*** ***\n\n') [names, values] = python_cmd (fullcmd, varargin{:}); assert (length(names) == length(values)) % Make the visual display of the results deterministic. Not easy to % use OrderedDict in Python because `locals()` is a regular dict. [names, I] = sort(names); values = values(I); %fprintf('assigning to %s...\n', names{i}) for i=1:length(names) assignin('caller', names{i}, values{i}) if (verbosity >= 2) evalin('caller', names{i}) end if (i==1) varnames = names{i}; else varnames = [varnames ', ' names{i}]; end end if (verbosity == 1) if (length(names) == 0) fprintf('no variables changed\n'); else fprintf('Variables effected: %s\n', varnames); end end end %!test %! x = 6; %! evalpy('y = 2*x;;', x); %! assert( y == 12 ) %!test %! x = 6; %! evalpy('y = 2*x; x = 10; z = 3*x;;', x); %! assert( isequal( [x y z], [10 12 30] )) %% underscore variables not returned %!test %! evalpy('_y = 42; x_ = 42'); %! assert( ~exist('_y', 'var')) %! assert( ~exist('x_', 'var')) %!test %! evalpy('_y = "GNU Octave Rocks"; z = _y.split();;'); %! assert( iscell(z) ) %! assert( isequal (z, {'GNU', 'Octave','Rocks'} )) symbolic-2.2.4/inst/vpasolve.m0000644000175000001440000000677412633614672015042 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} vpasolve (@var{e}) %% @deftypefnx {Function File} {@var{y} =} vpasolve (@var{e}, @var{x}) %% @deftypefnx {Function File} {@var{y} =} vpasolve (@var{e}, @var{x}, @var{x0}) %% Numerical solution of a symbolic equation. %% %% Variable-precision numerical solution of the equation @var{e} %% for variable @var{x} using initial guess of @var{x0}. %% %% Example: %% @example %% @group %% >> syms x %% >> eqn = exp(x) == x + 2; %% >> vpasolve(eqn, x, 0.1) %% @result{} (sym) 1.1461932206205825852370610285214 %% @end group %% @end example %% %% @seealso{vpa} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = vpasolve(e, x, x0) if (nargin < 3) x0 = sym(0); end if (nargin < 2) x = symvar(e, 1); end n = digits(); % nsolve gives back mpf object: https://github.com/sympy/sympy/issues/6092 % In SymPy >= 0.7.7, mpmath is not bundled so we import mpmath. % In older versions it is usually bundled except on Fedora, hence % the try, except bit. cmd = { '(e, x, x0, n) = _ins' 'if sympy.__version__ == "0.7.5" or sympy.__version__.startswith("0.7.6"):' ' try:' ' sympy.mpmath.mp.dps = n' ' findroot = sympy.mpmath.findroot' ' except AttributeError:' ' import mpmath' ' mpmath.mp.dps = n' ' findroot = mpmath.findroot' 'else:' ' import mpmath' ' mpmath.mp.dps = n' ' findroot = mpmath.findroot' '#r = nsolve(e, x, x0)' % https://github.com/sympy/sympy/issues/8564 '#r = sympy.N(r, n)' % deal with mpf 'if isinstance(e, Equality):' ' e = e.lhs - e.rhs' 'e = e.evalf(n)' 'f = lambda meh: e.subs(x, meh)' 'r = findroot(f, x0)' 'r = sympy.N(r, n)' % deal with mpf 'return r,' }; r = python_cmd (cmd, sym(e), x, x0, n); end %!test %! syms x %! vpi = vpa(sym(pi), 64); %! e = tan(x/4) == 1; %! q = vpasolve(e, x, 3.0); %! w = q - vpi ; %! assert (double(w) < 1e-30) %!test %! syms x %! vpi = vpa(sym(pi), 64); %! e = tan(x/4) == 1; %! q = vpasolve(e, x); %! w = q - vpi; %! assert (double(w) < 1e-30) %! q = vpasolve(e); %! w = q - vpi; %! assert (double(w) < 1e-30) %!test %! % very accurate pi %! syms x %! e = tan(x/4) == 1; %! m = digits(256); %! q = vpasolve(e, x, 3); %! assert (double(abs(sin(q))) < 1e-256) %! digits(m); %!test %! % very accurate sqrt 2 %! syms x %! e = x*x == 2; %! m = digits(256); %! q = vpasolve(e, x, 1.5); %! assert (double(abs(q*q - 2)) < 1e-256) %! digits(m); %!test %! % very accurate sqrt pi %! % fails: https://github.com/sympy/sympy/issues/8564 %! syms x %! e = x*x == sym(pi); %! m = digits(256); %! q = vpasolve(e, x, 3); %! assert (double(abs(sin(q*q))) < 1e-256) %! digits(m); symbolic-2.2.4/inst/@sym/0000755000175000001440000000000012633614672013717 5ustar cbmuserssymbolic-2.2.4/inst/@sym/expm.m0000644000175000001440000000377312633614672015060 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{B} =} expm (@var{A}) %% Symbolic matrix exponential. %% %% Example: %% @example %% @group %% >> A = [sym(4) 1; sym(0) 4] %% @result{} A = (sym 2×2 matrix) %% ⎡4 1⎤ %% ⎢ ⎥ %% ⎣0 4⎦ %% >> expm(A) %% @result{} (sym 2×2 matrix) %% ⎡ 4 4⎤ %% ⎢ℯ ℯ ⎥ %% ⎢ ⎥ %% ⎢ 4⎥ %% ⎣0 ℯ ⎦ %% @end group %% @end example %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = expm(x) cmd = { 'x, = _ins' 'if not x.is_Matrix:' ' x = sp.Matrix([[x]])' 'return x.exp(),' }; z = python_cmd (cmd, x); end %!test %! % scalar %! syms x %! assert (isequal (expm(x), exp(x))) %!test %! % diagonal %! A = [sym(1) 0; 0 sym(3)]; %! B = [exp(sym(1)) 0; 0 exp(sym(3))]; %! assert (isequal (expm(A), B)) %!test %! % diagonal w/ x %! syms x positive %! A = [sym(1) 0; 0 x+2]; %! B = [exp(sym(1)) 0; 0 exp(x+2)]; %! assert (isequal (expm(A), B)) %!test %! % non-diagonal %! syms x positive %! A = [sym(1) 2; 0 x+2]; %! B = expm(A); %! C = double(subs(B, x, 4)); %! D = expm(double(subs(A, x, 4))); %! assert (max (max (abs (C - D))) <= 1e-11) symbolic-2.2.4/inst/@sym/setxor.m0000644000175000001440000000447212633614672015430 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} setxor (@var{A}, @var{B}) %% Return the symmetric difference of two sets. %% %% @seealso{union, intersect, setdiff, unique, ismember} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = setxor(A, B) % FIXME: is it worth splitting out a "private/set_helper"? cmd = { 'A, B = _ins' 'try:' ' A = iter(A)' 'except TypeError:' ' A = set([A])' 'else:' ' A = set(A)' 'try:' ' B = iter(B)' 'except TypeError:' ' B = set([B])' 'else:' ' B = set(B)' 'C = A.symmetric_difference(B)' 'C = sympy.Matrix([list(C)])' 'return C,' }; A = sym(A); B = sym(B); r = python_cmd (cmd, A, B); % reshape to column if both inputs are if (iscolumn(A) && iscolumn(B)) r = reshape(r, length(r), 1); end end %!test %! A = sym([1 2 3]); %! B = sym([1 2 4]); %! C = setxor(A, B); %! D1 = sym([3 4]); %! D2 = sym([4 3]); %! assert (isequal (C, D1) || isequal (C, D2)) %!test %! % one nonsym %! A = sym([1 2 3]); %! B = [1 2 4]; %! C = setxor(A, B); %! D1 = sym([3 4]); %! D2 = sym([4 3]); %! assert (isequal (C, D1) || isequal (C, D2)) %!test %! % empty %! A = sym([1 2 3]); %! C = setxor(A, A); %! assert (isempty (C)) %!test %! % empty input %! A = sym([1 2]); %! C = setxor(A, []); %! assert (isequal (C, A) || isequal (C, sym([2 1]))) %!test %! % scalar %! syms x %! assert (isequal (setxor([x 1], x), sym(1))) %! assert (isempty (setxor(x, x))) symbolic-2.2.4/inst/@sym/partfrac.m0000644000175000001440000000511712633614672015703 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald, Andrés Prieto %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{g} =} partfrac (@var{f}) %% @deftypefnx {Function File} {@var{g} =} partfrac (@var{f}, @var{x}) %% Compute partial fraction decomposition of a rational function. %% %% Examples: %% @example %% >> syms x %% >> f = 2/(x + 4)/(x + 1) %% @result{} f = (sym) %% 2 %% ─────────────── %% (x + 1)⋅(x + 4) %% >> partfrac(f) %% @result{} ans = (sym) %% 2 2 %% - ───────── + ───────── %% 3⋅(x + 4) 3⋅(x + 1) %% @end example %% %% Other examples: %% @example %% >> syms x y %% >> partfrac(y/(x + y)/(x + 1), x) %% @result{} ans = (sym) %% y y %% - ─────────────── + ─────────────── %% (x + y)⋅(y - 1) (x + 1)⋅(y - 1) %% >> partfrac(y/(x + y)/(x + 1), y) %% @result{} ans = (sym) %% x 1 %% - ─────────────── + ───── %% (x + 1)⋅(x + y) x + 1 %% @end example %% %% @seealso{factor} %% @end deftypefn %% Author: Colin B. Macdonald, Andrés Prieto %% Keywords: symbolic, fractions function z = partfrac(f, x) % some special cases for SMT compat. if (nargin == 1) x = symvar(f, 1); if (isempty(x)) x = sym('x'); end end cmd = 'return sp.polys.partfrac.apart(_ins[0],_ins[1]),'; z = python_cmd (cmd, sym(f), sym(x)); end %!test %! % basic %! syms x y z %! assert(logical( partfrac(y/(x + 2)/(x + 1),x) == -y/(x + 2) + y/(x + 1) )) %! assert(logical( factor(partfrac(x^2/(x^2 - y^2),y)) == factor(x/(2*(x + y)) + x/(2*(x - y)) ))) %! assert(logical( factor(partfrac(x^2/(x^2 - y^2),x)) == factor(-y/(2*(x + y)) + y/(2*(x - y)) + 1 ))) symbolic-2.2.4/inst/@sym/ifourier.m0000644000175000001440000000761612633614672015733 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% Copyright (C) 2014, 2015 Andrés Prieto, Alexander Misel, Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{f} =} ifourier (@var{FF}, @var{k}, @var{x}) %% @deftypefnx {Function File} {@var{f} =} ifourier (@var{FF}) %% @deftypefnx {Function File} {@var{f} =} ifourier (@var{FF}, @var{x}) %% Symbolic inverse Fourier transform. %% %% Example: %% @example %% @group %% >> syms k %% >> F = sqrt(sym(pi))*exp(-k^2/4); %% >> ifourier(F) %% @result{} (sym) %% 2 %% -x %% ℯ %% @end group %% @group %% >> F = 2*sym(pi)*dirac(k); %% >> ifourier(F) %% @result{} ans = (sym) 1 %% @end group %% @end example %% %% Note @code{fourier} and @code{ifourier} implement the non-unitary, %% angular frequency convention. %% %% @seealso{fourier} %% @end deftypefn %% Author: Colin B. Macdonald, Andrés Prieto %% Keywords: symbolic, integral transforms function f = ifourier(varargin) % FIXME: it only works for scalar functions % FIXME: it doesn't handle diff call (see SMT transform of diff calls) % If the frequency variable determined to be "x", then % use "t" as the spatial domain variable (analogously to SMT) if (nargin == 1) F = sym(varargin{1}); k = symvar(F, 1); if (isempty(k)) k = sym('k'); end cmd = { 'F=_ins[0]; k=_ins[1]; x=sp.Symbol("x")' 'if x==k:' ' x=sp.Symbol("t")' 'f = sp.inverse_fourier_transform(F, k, x/(2*sp.pi))/(2*sp.pi)' 'return f,'}; f = python_cmd(cmd, F, k); elseif (nargin == 2) F = sym(varargin{1}); x = sym(varargin{2}); k = symvar(F, 1); % note SMT does something different, prefers w if (isempty(k)) k = sym('k'); end cmd = { 'F=_ins[0]; k=_ins[1]; x=_ins[2]' 'f = sp.inverse_fourier_transform(F, k, x/(2*sp.pi))/(2*sp.pi)' 'return f,'}; f = python_cmd(cmd, F, k, x); elseif (nargin == 3) F = sym(varargin{1}); k = sym(varargin{2}); x = sym(varargin{3}); cmd = { 'F=_ins[0]; k=_ins[1]; x=_ins[2]' 'f = sp.inverse_fourier_transform(F, k, x/(2*sp.pi))/(2*sp.pi)' 'return f,'}; f = python_cmd(cmd, F, k, x); else print_usage (); end end %!test %! % matlab SMT compat %! syms t r u x w %! Pi=sym('pi'); %! assert(logical( ifourier(exp(-abs(w))) == 1/(Pi*(x^2 + 1)) )) %! assert(logical( ifourier(exp(-abs(x))) == 1/(Pi*(t^2 + 1)) )) %! assert(logical( ifourier(exp(-abs(r)),u) == 1/(Pi*(u^2 + 1)) )) %! assert(logical( ifourier(exp(-abs(r)),r,u) == 1/(Pi*(u^2 + 1)) )) %!test %! % basic %! syms x w %! Pi=sym('pi'); %! assert(logical( ifourier(exp(-w^2/4)) == 1/(sqrt(Pi)*exp(x^2)) )) %! assert(logical( ifourier(sqrt(Pi)/exp(w^2/4)) == exp(-x^2) )) %!xtest %! % Inverse Fourier transform cannot handle non-smooth functions %! % SymPy cannot evaluate correctly?? %! syms x w %! assert(logical( ifourier(2/(w^2 + 1)) == exp(-abs(x)) )) %! assert(logical( ifourier(2/(w^2 + 1)) == heaviside(x)/exp(x) + heaviside(-x)*exp(x) )) %! assert(logical( ifourier(-(w*4)/(w^4 + 2*w^2 + 1) )== -x*exp(-abs(x))*1i )) %! assert(logical( ifourier(-(w*4)/(w^4 + 2*w^2 + 1) )== -x*(heaviside(x)/exp(x) + heaviside(-x)*exp(x))*1i )) symbolic-2.2.4/inst/@sym/ge.m0000644000175000001440000000303012633614672014464 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} ge (@var{a}, @var{b}) %% Test/define symbolic inequality, greater than or equal to. %% %% @seealso{lt, le, gt, eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = ge(x, y) t = ineq_helper('>=', 'Ge', x, y); end %!test %! % simple %! x = sym(1); y = sym(1); e = x >= y; %! assert (logical (e)) %! x = sym(1); y = sym(2); e = x >= y; %! assert (~logical(e)) %!test %! % array -- array %! syms x %! a = sym([1 3 3 2*x]); %! b = sym([2 x 3 10]); %! e = a >= b; %! assert (isa (e, 'sym')) %! assert (~logical (e(1))) %! assert (isa (e(2), 'sym')) %! assert (isequal (e(2), 3 >= x)) %! assert (logical (e(3))) %! assert (isa (e(4), 'sym')) %! assert (isequal (e(4), 2*x >= 10)) symbolic-2.2.4/inst/@sym/horzcat.m0000644000175000001440000000662312633614672015556 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} horzcat (@var{x}, @var{y}, @dots{}) %% Horizontally concatentate symbolic arrays. %% %% @seealso{vertcat} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = horzcat(varargin) % special case for 0x0 but other empties should be checked for % compatibilty cmd = { '_proc = []' 'for i in _ins:' ' if i.is_Matrix:' ' if i.shape == (0, 0):' ' pass' ' else:' ' _proc.append(i)' ' else:' ' _proc.append(sp.Matrix([[i]]))' 'failed = False' 'M = "whatev"' 'try:' ' M = sp.Matrix.hstack(*_proc)' 'except ShapeError:' ' failed = True' 'return (failed, M)' }; varargin = sym(varargin); [flag, h] = python_cmd (cmd, varargin{:}); if (flag) error('horzcat: ShapeError: incompatible sizes concatenated') end end %!test %! % basic %! syms x %! A = [x x]; %! B = horzcat(x, x); %! C = horzcat(x, x, x); %! assert (isa (A, 'sym')) %! assert (isa (B, 'sym')) %! assert (isa (C, 'sym')) %! assert (isequal (size(A), [1 2])) %! assert (isequal (size(B), [1 2])) %! assert (isequal (size(C), [1 3])) %!test %! % basic, part 2 %! syms x %! A = [x 1]; %! B = [1 x]; %! C = [1 2 x]; %! assert (isa (A, 'sym')) %! assert (isa (B, 'sym')) %! assert (isa (C, 'sym')) %! assert (isequal (size(A), [1 2])) %! assert (isequal (size(B), [1 2])) %! assert (isequal (size(C), [1 3])) %!test %! % row vectors %! a = [sym(1) 2]; %! b = [sym(3) 4]; %! assert (isequal ( [a b] , [1 2 3 4] )) %! assert (isequal ( [a 3 4] , [1 2 3 4] )) %! assert (isequal ( [3 4 a] , [3 4 1 2] )) %! assert (isequal ( [a [3 4]] , [1 2 3 4] )) %! assert (isequal ( [a sym(3) 4] , [1 2 3 4] )) %! assert (isequal ( [a [sym(3) 4]] , [1 2 3 4] )) %!test %! % col vectors %! a = [sym(1); 2]; %! b = [sym(3); 4]; %! assert (isequal ( [a b] , [1 3; 2 4] )) %! assert (isequal ( [a b a] , [1 3 1; 2 4 2] )) %!test %! % empty vectors %! v = sym(1); %! a = [v []]; %! assert (isequal (a, v)) %! a = [[] v []]; %! assert (isequal (a, v)) %! a = [v [] []]; %! assert (isequal (a, v)) %!test %! % more empty vectors %! v = [sym(1) sym(2)]; %! q = sym(ones(1, 0)); %! assert (isequal ([v q], v)) %!error %! % FIXME: clean-up when we drop 0.7.5 support (Issue #164) %! if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=75) %! disp('skipping: test passes on sympy >= 0.7.6') %! error('ShapeError') % pass the test with correct error %! else %! v = [sym(1) sym(2)]; %! q = sym(ones(3, 0)); %! w = [v q]; %! end symbolic-2.2.4/inst/@sym/length.m0000644000175000001440000000242612633614672015362 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{n} =} length (@var{x}) %% Length of a symbolic vector. %% %% As usual, be careful with this and matrices: you may want %% @code{numel} instead. %% %% @seealso{numel,size} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function n = length(x) d = size(x); n = max(d); end %!test %! a = sym([1 2 3]); %! assert(length(a) == 3); %!test %! % 2D array %! a = sym([1 2 3; 4 5 6]); %! assert(length(a) == 3); %!test %! % empty %! a = sym([]); %! assert(length(a) == 0); symbolic-2.2.4/inst/@sym/ldivide.m0000644000175000001440000000352312633614672015520 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} ldivide (@var{x}, @var{y}) %% Elementwise backslash of sym expressions (dot backslash). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = ldivide(x, y) z = rdivide(y, x); end %!test %! % scalar %! syms x %! assert (isa (x .\ 1, 'sym')) %! assert (isa (x .\ x, 'sym')) %! assert (isequal (x .\ 1, 1/x)) %! assert (isequal (x .\ x, sym(1))) %!test %! % matrix-scalar %! D = [1 1; 2 3]; %! A = sym(D); %! assert (isequal ( A .\ 6 , D .\ 6 )) %! assert (isequal ( A .\ sym(6) , D .\ 6 )) %! assert (isequal ( D .\ sym(6) , D .\ 6 )) %!test %! % matrix-matrix %! D = [1 2; 3 4]; %! A = sym(D); %! assert (isequal ( A .\ A , D .\ D )) %! assert (isequal ( A .\ D , D .\ D )) %! assert (isequal ( D .\ A , D .\ D )) %!test %! % matrix .\ matrix with symbols %! syms x y %! A = [x y; x^2 2*y]; %! B = [y x; x y]; %! assert (isequal ( A .\ A , sym(ones(2, 2)) )) %! assert (isequal ( B .\ A , [x/y y/x; x 2] )) %!test %! % scalar .\ matrix %! D = 3*[1 2; 3 4]; %! A = sym(D); %! assert (isequal ( 3 .\ A , 3 .\ D )) symbolic-2.2.4/inst/@sym/isrow.m0000644000175000001440000000232512633614672015242 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isrow (@var{x}) %% Return true if symbolic expression is a row vector. %% %% @seealso{iscolumn, isvector, isscalar} %% @end deftypefn function r = isrow(x) % from Rik Wehbring's Octave function sz = size (x); r = (ndims (x) == 2 && (sz(1) == 1)); end %!assert (isrow (sym ([1]))) %!assert (isrow (sym ([1 2 3]))) %!assert (~isrow (sym ([]))) %!assert (~isrow (sym ([1 2 3]'))) %!assert (~isrow (sym ([1 2; 3 4]))) symbolic-2.2.4/inst/@sym/laplacian.m0000644000175000001440000000572012633614672016025 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{G} =} laplacian (@var{f}) %% @deftypefnx {Function File} {@var{G} =} laplacian (@var{f}, @var{x}) %% Symbolic laplacian of symbolic expression. %% %% @example %% @group %% >> syms x y %% >> laplacian(x^3 + 5*y^2) %% @result{} (sym) 6⋅x + 10 %% @end group %% @end example %% %% @var{x} can be a scalar, vector or cell list. If omitted, %% it is determined using @code{symvar}. %% %% Note: assumes @var{x} is a Cartesian coordinate system. %% %% @seealso{divergence, gradient, curl, jacobian, hessian} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function g = laplacian(f,x) assert (isscalar(f), 'laplacian: only scalar functions supported') if (nargin == 1) x = symvar(f); if (isempty(x)) x = sym('x'); end end if (~iscell(x) && isscalar(x)) x = {x}; end cmd = { '(f, x) = _ins' 'g = 0' 'for y in x:' ' g = g + f.diff(y, 2)' 'return g,' }; g = python_cmd (cmd, sym(f), x); end %!shared x,y,z %! syms x y z %!test %! % 1D %! f = x^2; %! g = diff(f,x,x); %! assert (isequal (laplacian(f), g)) %! assert (isequal (laplacian(f,{x}), g)) %! assert (isequal (laplacian(f,[x]), g)) %! assert (isequal (laplacian(f,x), g)) %!test %! % const %! f = sym(1); %! g = sym(0); %! assert (isequal (laplacian(f), g)) %! assert (isequal (laplacian(f,x), g)) %! f = sym('c'); %! assert (isequal (laplacian(f,x), g)) %!test %! % double const %! f = 1; %! g = sym(0); %! assert (isequal (laplacian(f,x), g)) %!test %! % 1D fcn in 2d/3d %! f = sin(2*y); %! g = -4*f; %! assert (isequal (laplacian(f), g)) %! assert (isequal (laplacian(f, {x,y}), g)) %! assert (isequal (laplacian(f, {x,y,z}), g)) %!test %! % 2d fcn in 2d/3d %! f = sin(exp(x)*y); %! g = diff(f,x,x) + diff(f,y,y); %! assert (isequal (laplacian(f), g)) %! assert (isequal (laplacian(f, {x,y}), g)) %!test %! % 2d fcn in 2d/3d %! f = sin(exp(x)*y+sinh(z)); %! gr2 = gradient(f, {x,y}); %! divgr2 = divergence(gr2, {x,y}); %! l2 = laplacian(f,{x,y}); %! gr3 = gradient(f, {x,y,z}); %! divgr3 = divergence(gr3, {x,y,z}); %! l3 = laplacian(f,{x,y,z}); %! assert (isAlways (l2 == divgr2)) %! assert (isAlways (l3 == divgr3)) symbolic-2.2.4/inst/@sym/isscalar.m0000644000175000001440000000224412633614672015700 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{b} =} isscalar (@var{x}) %% Return true if this symbolic expression is a scalar. %% %% @seealso{size, numel, isvector} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function b = isscalar(x) d = size(x); n = prod(d); b = (n == 1); end %!assert(isscalar(sym('x'))) %!test %! a = sym([1 2 3]); %! assert(~isscalar(a)) %!assert(~isscalar(sym([]))) symbolic-2.2.4/inst/@sym/axplusy.m0000644000175000001440000000276612633614672015615 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} axplusy (@var{a}, @var{x}, @var{y}) %% Helper function: scalar a times sym x plus sym y. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = axplusy(a, x, y) cmd = { '(a,x,y) = _ins' 'if x.is_Matrix and y.is_Matrix:' ' return (a*x+y,)' 'if x.is_Matrix and not y.is_Matrix:' ' return (a*x + y*sp.ones(*x.shape),)' 'if not x.is_Matrix and y.is_Matrix:' ' return (a*x*sp.ones(*y.shape) + y,)' 'else:' ' return (a*x + y,)' }; z = python_cmd (cmd, sym(a), sym(x), sym(y)); end %! % Should be tested by the functions that use it... %!assert(isequal(axplusy(sym(3),4,5), sym(3)*4+5)) symbolic-2.2.4/inst/@sym/csc.m0000644000175000001440000000253412633614672014651 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} csc (@var{x}) %% Symbolic csc function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = csc(x) y = uniop_helper (x, 'csc'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = csc(x); %! f2 = csc(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = csc(A); %! f2 = csc(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/uminus.m0000644000175000001440000000221512633614672015415 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} uminus (@var{x}) %% Symbolic unitary minus (-). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = uminus(x) z = axplusy(-1, x, 0); end %!test %! % scalar %! syms x %! assert (isa (-x, 'sym')) %! assert (isequal (-(-x), x)) %!test %! % matrix %! D = [0 1; 2 3]; %! A = sym(D); %! assert( isequal( -A, -D )) symbolic-2.2.4/inst/@sym/trace.m0000644000175000001440000000235012633614672015173 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} trace (@var{A}) %% Trace of symbolic matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = trace(x) cmd = { 'x, = _ins' 'if not x.is_Matrix:' ' x = sp.Matrix([[x]])' 'return sp.trace(x),' }; z = python_cmd (cmd, x); end %!test %! % scalar %! syms x %! assert (isequal (trace(x), x)) %!test %! syms x %! A = [x 3; 2*x 5]; %! assert (isequal (trace(A), x + 5)) symbolic-2.2.4/inst/@sym/logical.m0000644000175000001440000001305312633614672015511 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{r} =} logical (@var{eq}) %% Test if expression is "structurally" true. %% %% This should probably be used with if/else flow control. %% %% Example: %% @example %% @group %% >> syms x y %% >> logical(x*(1+y) == x*(y+1)) %% @result{} 1 %% >> logical(x == y) %% @result{} 0 %% @end group %% @end example %% %% Note this is different from @code{isAlways} which tries to %% determine mathematical truth: %% @example %% @group %% >> isAlways(x*(1+y) == x+x*y) %% @result{} 1 %% >> logical(x*(1+y) == x+x*y) %% @result{} 0 %% @end group %% @end example %% %% @code{logical} treats objects according to: %% @itemize %% @item true/false in various forms: as is. %% @item equalities (==), unequalities (~=): check for structural %% equivalence (whether lhs and rhs match without simplifying.) %% @item numbers: true if nonzero, false if zero. %% @item nan, oo, zoo: FIXME %% @item boolean expr: And, Or: FIXME %% @item other objects raise error. %% @end itemize %% %% @seealso{isAlways, isequal, eq (==)} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = logical(p) % do not simplify here cmd = { 'def scalar2tfn(p):' ' if p in (S.true, S.false):' ' return bool(p)' ' # ineq nothing to do, but Eq, Ne check structural eq' ' if isinstance(p, Eq):' ' r = p.lhs == p.rhs' % could not be true from Eq ctor ' return bool(r)' % none -> false ' if isinstance(p, Ne):' ' r = p.lhs != p.rhs' ' return bool(r)' ' if isinstance(p, (Lt, Gt, Le, Ge)):' ' return False' % didn't reduce in ctor, needs isAlways ' # for SMT compat' ' if p.is_number:' ' r = p.is_zero' % FIXME: return bool(r)? ' if r in (S.true, S.false):' ' return not bool(r)' ' return None' ' #return "cannot reliably convert sym \"%s\" to bool" % str(p))' }; cmd = vertcat(cmd, { '(x, unknown) = _ins' 'if x.is_Matrix:' ' r = [a for a in x.T]' % note transpose 'else:' ' r = [x,]' 'r = [scalar2tfn(a) for a in r]' 'r = [unknown if a is None else a for a in r]' 'flag = True' 'if r.count("error") > 0:' ' flag = False' ' r = "cannot reliably convert sym to bool"' 'return (flag, r)' }); [flag, r] = python_cmd (cmd, p, 'error'); % FIXME: oo, zoo error too in SMT % ' elif p is nan:' % ' raise TE # FIXME: check SMT' if (~flag) assert (ischar (r), 'logical: programming error?') error(['logical: ' r]) end r = cell2mat(r); r = reshape(r, size(p)); end %!test %! % basics, many others in isAlways.m %! assert (logical(true)) %! assert (~(logical(false))) %!test %! % numbers to logic? %! assert (logical(sym(1))) %! assert (logical(sym(-1))) %! assert (~logical(sym(0))) %!test %! % eqns, "structurally equivalent" %! syms x %! e = logical(x == x); %! assert ( islogical (e)) %! assert (e) %! e = logical(x == 1); %! assert ( islogical (e)) %! assert (~e) %!test %! % eqn could have solutions but are false in general %! syms x %! e = logical(x^2 == x); %! assert ( islogical (e)) %! assert (~e) %! e = logical(2*x == x); %! assert ( islogical (e)) %! assert (~e) %!test %! % FIXME: (not sure yet) T/F matrices should stay sym until logical() %! a = sym(1); %! e = a == a; %! assert (isa (e, 'sym')) %! assert (islogical (logical (e))) %! e = [a == a a == 0 a == a]; %! assert (isa (e, 'sym')) %! assert (islogical (logical (e))) %!test %! % sym vectors of T/F to logical %! a = sym(1); %! e = [a == a a == 0 a == a]; %! w = logical(e); %! assert (islogical (w)) %! assert (isequal (w, [true false true])) %! e = e'; %! w = logical(e); %! assert (islogical (w)) %! assert (isequal (w, [true; false; true])) %!test %! % sym matrix of T/F to logical %! a = sym([1 2 3; 4 5 6]); %! b = sym([1 2 0; 4 0 6]); %! e = a == b; %! w = logical(e); %! assert (islogical (w)) %! assert (isequal (w, [true true false; true false true])) %!error %! syms x %! logical(x); %!error %! logical(sym(nan)) %!test %! % but oo and zoo are non-zero so we call those true %! % (SMT errors on these) FIXME %! syms oo zoo %! assert (logical (oo)) %! % assert (logical (zoo)) %%!xtest %%! % FIXME: what about positive x? %%! syms x positive %%! w = logical(x); %%! assert (w) %!xtest %! % FIXME: bug in Octave: if should automatically use logical %! % (want "if (obj)" same as "if (logical(obj))") %! e = sym(true); %! if (e) %! assert(true); %! else %! assert(false); %! end % more above, once it passes % e2 = sym(1) == sym(1); % if (e2) % assert(true); % else % assert(false); % end % e3 = sym([1 2]) == sym([1 1]); % if (e3(1)) % assert(true); % else % assert(false); % end symbolic-2.2.4/inst/@sym/dot.m0000644000175000001440000000333512633614672014667 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{s} =} dot (@var{a}, @var{b}) %% Symbolic dot (scalar) product. %% %% Examples: %% @example %% @group %% a = [sym('a1'); sym('a2'); sym('a3')]; %% b = [sym('b1'); sym('b2'); sym('b3')]; %% dot(a, b) %% @result{} (sym) a₁⋅b₁ + a₂⋅b₂ + a₃⋅b₃ %% dot(a, a) %% @result{} (sym) %% 2 2 2 %% a₁ + a₂ + a₃ %% @end group %% @end example %% %% @example %% @group %% syms x %% a = [x; 0; 0]; %% b = [0; 0; sym(1)]; %% dot(a, b) %% @result{} ans = (sym) 0 %% @end group %% @end example %% %% @seealso{cross} %% @end deftypefn function c = dot(a, b) cmd = { 'a, b = _ins' 'return a.dot(b),' }; c = python_cmd (cmd, sym(a), sym(b)); end %!test %! a = sym([1; 1; 0]); %! b = sym([1; 2; 4]); %! c = dot(a, b); %! assert (isequal (c, sym(3))) %!test %! syms x %! a = sym([x; 0; 0]); %! b = sym([0; 1; 0]); %! c = dot(a, b); %! assert (isequal (c, sym(0))) symbolic-2.2.4/inst/@sym/subsasgn.m0000644000175000001440000001754512633614672015736 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{out} =} subsasgn (@var{val}, @var{idx}, @var{rhs}) %% Assign to entries of a symbolic array. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function out = subsasgn (val, idx, rhs) switch idx.type case '()' %% symfun constructor % f(x) = rhs % f is val % x is idx.subs{1} % This also gets called for "syms f(x)" if (isa(idx.subs{1}, 'sym')) % f(sym) = ..., define symfun if (~isa(rhs, 'sym')) % rhs is, e.g., a double, then we call the constructor rhs = sym(rhs); end out = symfun(rhs, idx.subs); else % f(double) = ..., array assignment out = mat_replace(val, idx.subs, sym(rhs)); end case '.' assert( isa(rhs, 'sym')) assert( ~isa(idx.subs, 'sym')) assert( ~isa(val, 'sym')) val.(idx.subs) = rhs; out = val; otherwise disp('FIXME: do we need to support any other forms of subscripted assignment?') idx rhs val error('broken'); end end %!shared a,b %! b = [1:4]; %! a = sym(b); %!test a(1) = 10; b(1) = 10; %! assert(isequal( a, b )) %!test I = logical([1 0 1 0]); %! a(I) = 2; b(I) = 2; %! assert(isequal( a, b )) %!test I = logical([1 0 1 0]); %! a(I) = [2 4]; b(I) = [2 4]; %! assert(isequal( a, b )) %!test I = logical([1 0 1 0]); %! a(I) = [2; 4]; b(I) = [2; 4]; %! assert(isequal( a, b )) %!shared a,b %! b = 1:4; b = [b; 2*b; 3*b]; %! a = sym(b); %!test %! rhs = [10 11; 12 13]; %! a([1:2],[1:2]) = rhs; %! b([1:2],[1:2]) = rhs; %! assert(isequal( a, b )) %! a(1:2,1:2) = rhs; %! assert(isequal( a, b )) %% slice : %!shared a,b %! b = 1:4; b = [b; 2*b]; %! a = sym(b); %!test %! rhs = [10 11; 12 13]; %! a(:,2:3) = rhs; %! b(:,2:3) = rhs; %! assert(isequal( a, b )) %% grow 2D %!shared a,b %! b = 1:4; b = [b; 2*b]; %! a = sym(b); %!test %! rhs = [10 11; 12 13]; %! a([1 end+1],end:end+1) = rhs; %! b([1 end+1],end:end+1) = rhs; %! assert(isequal( a, b )) %% linear indices of 2D %!test %! b = 1:4; b = [b; 2*b; 3*b]; %! a = sym(b); %! b(1:4) = [10 11 12 13]; %! a(1:4) = [10 11 12 13]; %! assert(isequal( a, b )) %! b(1:4) = [10 11; 12 13]; %! a(1:4) = [10 11; 12 13]; %! assert(isequal( a, b )) %% Wrong shape RHS % Matlab/Octave don't allow this on doubles, but if you do % this is the right answer (Matlab SMT 2013b gets it wrong) % I will disable it too. %test % rhs = [10 11; 12 13]; % b(1:2,1:2) = rhs; % a(1:2,1:2) = rhs(:); % assert(isequal( a, b )) %% 1D growth and 'end' %!test %! g = sym([1 2 3]); %! g(3:4) = [67 68]; %! g(end:end+1) = [12 14]; %! assert(isequal( g, [1 2 67 12 14] )) %% expanding empty and scalar %!test %! syms x %! c = sym([]); %! c(1) = x; %! assert(isequal( c, x )) %! c(2) = 2*x; %! assert(isequal( c, [x 2*x] )) %% 2d logical indexing, ref and asgn %!shared a,b,I,J %! b = 1:4; b = [b; 3*b; 5*b]; a = sym(b); %! I = logical([1 0 1]); %! J = logical([1 0 1 0]); %!assert(isequal( a(I,J), b(I,J) )) %!test %! rhs = [90 91; 92 93]; %! b(I, J) = rhs; %! a(I, J) = rhs; %! assert(isequal( a, b )) %!test %! b(I, J) = 100; %! a(I, J) = 100; %! assert(isequal( a, b )) %!shared x %! syms x %% logical with all false %!test %! y = x; %! y(false) = 6; %! assert(isequal( y, x )); %! a = [x x]; %! a([false false]) = [6 6]; %! assert(isequal( a, [x x] )); %% issue 18, scalar access %!test %! x(1) = sym(6); %! assert(isequal( x, sym(6) )); %! x(1) = 6; %! assert(isequal( x, sym(6) )); %! x(true) = 88; %! assert(isequal( x, sym(88) )); %% bug: assignment to column vector used to fail %!test %! A = sym(zeros(3,1)); %! A(1) = 5; %% symfun creation (generic function) %!test %! syms x %! g(x) = x*x; %! assert(isa(g,'symfun')) %% symfun creation (generic function) %!test %! syms x g(x) %! assert(isa(g,'symfun')) %% symfun creation when g already exists and is a sym/symfun %!test %! syms x %! g = x; %! syms g(x) %! assert(isa(g,'symfun')) %! clear g %! g(x) = x; %! g(x) = x*x; %! assert(isa(g,'symfun')) %!test %! % older expansion tests %! syms x %! f = [2*x 3*x]; %! f(2) = 4*x; %! assert (isequal (f, [2*x 4*x])) %! f(2) = 2; %! assert (isequal(f, [2*x 2])) %! g = f; %! g(1,3) = x*x; %! assert (isequal(g, [2*x 2 x^2])) %! g = f; %! g(3) = x*x; %! assert (isequal(g, [2*x 2 x^2])) %! g = f; %! g(3) = 4; %! assert (isequal(g, [2*x 2 4])) %!test %! % older slicing tests %! syms x %! f = [1 x^2 x^4]; %! f(1:2) = [x x]; %! assert (isequal( f, [x x x^4] )) %! f(1:2) = [1 2]; %! assert (isequal( f, [1 2 x^4] )) %! f(end-1:end) = [3 4]; %! assert (isequal( f, [1 3 4] )) %! f(3:4) = [10 11]; %! assert (isequal( f, [1 3 10 11] )) %! f(end:end+1) = [12 14]; %! assert (isequal( f, [1 3 10 12 14] )) %!test %! % struct.str = sym, sometimes calls subsasgn %! d = struct(); %! syms x %! d.a = x; %! assert (isa (d, 'struct')) %! assert (isequal (d.a, x)) %! d.('a') = x; %! assert (isa (d, 'struct')) %! assert (isequal (d.a, x)) %! d = setfield(d, 'a', x); %! assert (isa (d, 'struct')) %! assert (isequal (d.a, x)) %! % at least on Oct 3.8, this calls sym's subsasgn %! d = struct(); %! d = setfield(d, 'a', x); %! assert (isa (d, 'struct')) %! assert (isequal (d.a, x)) %!test %! % bool scalar assignments of true/false into sym %! a = sym([1 2 x 3]); %! b = [1 2 10 4]; %! e = a == b; %! assert (logical (e(2))) %! e(2) = false; %! assert (~logical (e(2))) %!test %! % bool vector assignments of true/false into sym %! a = sym([1 2 x 3]); %! b = [1 2 10 4]; %! e = a == b; %! e(1:2) = [true true]; %! assert (isequal (e, [sym(1)==1 sym(2)==2 x==10 sym(3)==4])) %!test %! % bool scalar promoted to vector assignments into sym %! a = sym([1 2 x 3]); %! b = [1 2 10 4]; %! e = a == b; %! e(1:2) = true; %! assert (isequal (e, [sym(1)==1 sym(2)==2 x==10 sym(3)==4])) %% 2D arrays from mat_mask_asgn %!shared a, b, I %! b = [1:4]; b = [b; 3*b; 5*b]; %! a = sym(b); %! I = rand(size(b)) > 0.5; %!test %! A = a; A(I) = 2*b(I); %! B = b; B(I) = 2*b(I); %! assert (isequal (A, B)) %!test %! % scalar RHS %! A = a; A(I) = 17; %! B = b; B(I) = 17; %! assert (isequal (A, B)) %!warning %! % strange non-vector (matrix) RHS ("rhs2"), should be warning %! I = logical([1 0 1 0; 0 1 0 1; 1 0 1 0]); %! rhs2 = reshape(2*b(I), 2, 3); % strange bit %! A = a; %! A(I) = rhs2; %!test %! % nonetheless, above strange case should give right answer %! I = logical([1 0 1 0; 0 1 0 1; 1 0 1 0]); %! rhs = 2*b(I); %! rhs2 = reshape(rhs, 2, 3); %! s = warning ('off', 'OctSymPy:subsagn:rhs_shape'); %! A0 = a; A1 = a; %! A0(I) = rhs; %! A1(I) = rhs2; %! warning (s) %! assert (isequal (A0, A1)) %% Tests from mat_rclist_asgn %!shared AA, BB %! BB = [1 2 3; 4 5 6]; %! AA = sym(BB); %!test %! A = AA; B = BB; %! B([1 6]) = [8 9]; %! A([1 6]) = [8 9]; %! assert (isequal (A, B)) %!test %! % rhs scalar %! A = AA; B = BB; %! B([1 6]) = 88; %! A([1 6]) = 88; %! assert (isequal (A, B)) %!test %! % If rhs is not a vector, make sure col-based access works %! rhs = [18 20; 19 21]; %! A = AA; B = BB; %! B([1 6]) = 88; %! A([1 6]) = 88; %! B([1 2 3 4]) = rhs; %! A([1 2 3 4]) = rhs; %! assert (isequal (A, B)) %!test %! % Growth %! A = AA; B = BB; %! A(1,5) = 10; %! B(1,5) = 10; %! assert (isequal (A, B)) %% End of mat_* tests symbolic-2.2.4/inst/@sym/not.m0000644000175000001440000000653012633614672014701 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} not (@var{x}) %% Logical not of a symbolic array. %% %% @seealso{eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = not(x) % not the same as: %y = ~logical(x); % FIXME: simpler version? don't micromanage sympy but gives ~x % ' try:' % ' return Not(p)' % ' except:' % ' raise TE' % cf., logical, isAlways cmd = { '(p,) = _ins' 'def scalar_case(p,):' ' TE = TypeError("cannot logically negate sym \"%s\"" % str(p))' ' if sympy.__version__ == "0.7.5":' % later Not(p) below ok ' if isinstance(p, Eq): return Ne(p.lhs, p.rhs)' ' elif isinstance(p, Ne): return Eq(p.lhs, p.rhs)' ' elif isinstance(p, Lt): return Ge(p.lts, p.gts)' ' elif isinstance(p, Le): return Gt(p.lts, p.gts)' ' elif isinstance(p, Gt): return Le(p.gts, p.lts)' ' elif isinstance(p, Ge): return Lt(p.gts, p.lts)' ' if p is nan:' ' raise TE' % FIXME: check SMT ' elif isinstance(p, (BooleanFunction, Relational)):' ' return Not(p)' ' elif p in (S.true, S.false):' ' return Not(p)' ' elif p.is_number:' ' return S(not bool(p))' ' else:' ' raise TE' 'try:' ' if p.is_Matrix:' ' r = p.applyfunc(lambda a: scalar_case(a))' ' else:' ' r = scalar_case(p)' ' flag = True' 'except TypeError as e:' ' r = str(e)' ' flag = False' 'return (flag, r)' }; [flag, r] = python_cmd (cmd, x); if (~flag) assert (ischar (r), ': programming error?') error([': ' r]) end end %!shared t, f %! t = sym(true); %! f = sym(false); %!test %! % simple %! assert (isequal( ~t, f)) %! assert (isequal( ~t, f)) %!test %! % array %! w = [t t f t]; %! z = [f f t f]; %! assert (isequal( ~w, z)) %!test %! % number %! assert (isequal( ~sym(5), f)) %! assert (isequal( ~sym(0), t)) %!test %! % output is sym %! syms x %! e = ~(x == 4); %! assert (isa (e, 'sym')) %! assert (strncmp(char(e), 'Unequality', 10)) %!xtest %! % output is sym even for scalar t/f %! % ₣IXME: should match other bool fcns %! assert (isa (~t, 'sym')) %!test %! % symbol ineq %! syms x %! a = [t f x == 1 x ~= 2 x < 3 x <= 4 x > 5 x >= 6]; %! b = [f t x ~= 1 x == 2 x >= 3 x > 4 x <= 5 x < 6]; %! assert (isequal( ~a, b)) %!test %! % symbol ineq %! syms x %! try %! y = ~x %! waserr = false; %! catch %! waserr = true; %! end %! assert (waserr) symbolic-2.2.4/inst/@sym/ipermute.m0000644000175000001440000000214012633614672015724 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{A} =} ipermute (@var{B}, @var{iperm}) %% Permute the indices of a symbolic array. %% %% @seealso{permute} %% @end deftypefn function A = ipermute(B, iperm) A = permute(B, iperm); end %!test %! syms x %! A = [1 x]; %! perm = [2 1]; %! B = permute(A, perm); %! C = ipermute(B, perm); %! assert (isequal(C, A)) symbolic-2.2.4/inst/@sym/ccode.m0000644000175000001440000001015012633614672015147 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{s} =} ccode (@var{f}) %% @deftypefnx {Function File} {@var{s} =} ccode (@var{f1}, @dots{}, @var{fn}) %% @deftypefnx {Function File} {} ccode (@dots{}, 'file', @var{filename}) %% @deftypefnx {Function File} {[@var{c_stuff}, @var{h_stuff}] =} ccode (@dots{}, 'file', '') %% Convert symbolic expression into C code. %% %% Example: %% @example %% @group %% >> syms x %% >> g = taylor(log(1 + x), x, 0, 'order', 5); %% >> g = horner(g) %% @result{} g = (sym) %% ⎛ ⎛ ⎛ x 1⎞ 1⎞ ⎞ %% x⋅⎜x⋅⎜x⋅⎜- ─ + ─⎟ - ─⎟ + 1⎟ %% ⎝ ⎝ ⎝ 4 3⎠ 2⎠ ⎠ %% >> ccode(g) %% @result{} x*(x*(x*(-1.0L/4.0L*x + 1.0L/3.0L) - 1.0L/2.0L) + 1) %% @end group %% @end example %% %% We can write to a file or obtain the contents directly: %% @example %% @group %% >> [C, H] = ccode(g, 'file', '', 'show_header', false); %% >> H.name %% @result{} file.h %% >> H.code %% @result{} %% #ifndef PROJECT__FILE__H %% #define PROJECT__FILE__H %% %% double myfun(double x); %% %% #endif %% >> C.name %% @result{} file.c %% >> %C.code % This would show the C code %% @end group %% @end example %% FIXME: show C code here after the following doctest bug is fixed: %% https://github.com/catch22/octave-doctest/issues/42 %% %% FIXME: This doesn't write "optimized" code like Matlab's %% Symbolic Math Toolbox; it doesn't do "Common Subexpression %% Elimination". Presumably the compiler would do that for us %% anyway. Sympy has a "cse" module that will do it. See: %% http://stackoverflow.com/questions/22665990/optimize-code-generated-by-sympy %% %% @seealso{fortran, latex, function_handle} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = ccode(varargin) [flg, meh] = codegen(varargin{:}, 'lang', 'C'); if flg == 0 varargout = {}; elseif flg == 1 varargout = meh(1); elseif flg == 2 varargout = {meh{1}, meh{2}}; else error('whut?'); end end %!shared x,y,z %! syms x y z %!test %! % basic test %! f = x*sin(y) + abs(z); %! source = ccode(f); %! expected = 'x*sin(y) + fabs(z)'; %! assert(strcmp(source, expected)) %!test %! % output test %! f = x*sin(y) + abs(z); %! [C, H] = ccode(f, 'file', '', 'show_header', false); %! expected_c_code_075 = sprintf('#include \"file.h\"\n#include \n\ndouble myfun(double x, double y, double z) {\n\n return x*sin(y) + fabs(z);\n\n}\n'); %! % change in behaviour in 0.7.5 -> 0.7.6 %! expected_c_code = sprintf('#include \"file.h\"\n#include \n\ndouble myfun(double x, double y, double z) {\n\n double myfun_result;\n myfun_result = x*sin(y) + fabs(z);\n return myfun_result;\n\n}\n'); %! expected_h_code = sprintf('\n#ifndef PROJECT__FILE__H\n#define PROJECT__FILE__H\n\ndouble myfun(double x, double y, double z);\n\n#endif\n\n'); %! assert(strcmp(C.name, 'file.c')) %! assert(strcmp(H.name, 'file.h')) %! hwin = strrep(expected_h_code, sprintf('\n'), sprintf('\r\n')); %! assert (strcmp (H.code, expected_h_code) || strcmp (H.code, hwin)) %! s1 = expected_c_code_075; %! s2 = expected_c_code; %! s3 = strrep(expected_c_code_075, sprintf('\n'), sprintf('\r\n')); %! s4 = strrep(expected_c_code, sprintf('\n'), sprintf('\r\n')); %! assert (strcmp (C.code, s1) || strcmp (C.code, s2) || strcmp(C.code, s3) || strcmp (C.code, s4)) symbolic-2.2.4/inst/@sym/coth.m0000644000175000001440000000254412633614672015037 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} coth (@var{x}) %% Symbolic coth function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = coth(x) y = uniop_helper (x, 'coth'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = coth(x); %! f2 = coth(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = coth(A); %! f2 = coth(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/erfc.m0000644000175000001440000000254412633614672015021 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} erfc (@var{x}) %% Symbolic erfc function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = erfc(x) y = uniop_helper (x, 'erfc'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = erfc(x); %! f2 = erfc(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = erfc(A); %! f2 = erfc(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/erfinv.m0000644000175000001440000000257012633614672015372 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} erfinv (@var{x}) %% Symbolic erfinv function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = erfinv(x) y = uniop_helper (x, 'erfinv'); end %!shared x, d %! d = 1/2; %! x = sym('1/2'); %!test %! f1 = erfinv(x); %! f2 = erfinv(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = erfinv(A); %! f2 = erfinv(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/orth.m0000644000175000001440000000456212633614672015060 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} orth (@var{A}) %% Orthonormal basis for column space (range) of symbolic matrix. %% %% The basis is often not unique and in general @code{double(B)} may %% not match the output of @code{orth(double(A))}. %% %% @seealso{rank, null, rref} %% @end deftypefn function B = orth(A) cmd = { 'A = _ins[0]' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'L = A.rref()' 'B = [A[:, i] for i in L[1]]' % get pivot columns in original 'B = sp.GramSchmidt(B, True)' 'B = sp.Matrix.hstack(*B)' 'return B,' }; B = python_cmd (cmd, A); end %!test %! A = [1 2; 3 6]; %! K = orth(A); %! L = orth(sym(A)); %! assert (isequal (size(L), [2 1])) %! dif1 = abs (double(L) - K); %! dif2 = abs (double(L) + K); %! assert (all (dif1 < 1e-16) || all (dif2 < 1e-16)) %!test %! A = [1; 3]; %! K = orth(A); %! L = orth(sym(A)); %! assert (isequal (size(L), [2 1])) %! dif1 = abs (double(L) - K); %! dif2 = abs (double(L) + K); %! assert (all (dif1 < 1e-16) || all (dif2 < 1e-16)) %!test %! A = sym([1 2; 3 4]); %! L = orth(sym(A)); %! assert (isequal (size(L), [2 2])) %! v = L(:, 1); %! w = L(:, 2); %! assert (isAlways (v' * v == 1)) %! assert (isAlways (w' * w == 1)) %! assert (isAlways (v' * w == 0)) %!test %! A = sym([1 1; 1 0; 1 0]); %! L = orth(sym(A)); %! assert (isequal (size(L), [3 2])) %! v = L(:, 1); %! w = L(:, 2); %! assert (isAlways (v' * v == 1)) %! assert (isAlways (w' * w == 1)) %! assert (isAlways (v' * w == 0)) %! % y and z components must be equal %! assert (isAlways (v(2) == v(3))) %! assert (isAlways (w(2) == w(3))) symbolic-2.2.4/inst/@sym/private/0000755000175000001440000000000012633614672015371 5ustar cbmuserssymbolic-2.2.4/inst/@sym/private/mat_access.m0000644000175000001440000000437012633614672017655 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mat_access (@var{A}, @var{subs}) %% Private helper routine for symbolic array access. %% %% Big piece of spaghetti code :( %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mat_access(A, subs) if ((length(subs) == 1) && (islogical(subs{1}))) %% A(logical) z = mat_mask_access(A, subs{1}); return elseif ( (length(subs) == 1) && strcmp(subs{1}, ':') ) %% A(:) z = reshape(A, numel(A), 1); return elseif (length(subs) == 1) %% linear index into a matrix/vector/scalar A i = subs{1}; if strcmp(i, '') i = []; % yes empty str ok here end if (ischar(i)) error(['invalid indexing, i="' i '"']) end [r, c] = ind2sub (size(A), i); z = mat_rclist_access(A, r(:), c(:)); % output shape, see also logic in comments in mat_mask_access.m if (~isscalar(A) && isrow(A) && isvector(i)) z = reshape(z, 1, length(i)); % i might be row or col elseif (~isscalar(A) && iscolumn(A) && isvector(i)) assert(iscolumn(z)) else % all other cases we take shape of i z = reshape(z, size(i)); end return elseif (length(subs) == 2) r = subs{1}; c = subs{2}; assert( isvector(r) || isempty(r) || strcmp(r, ':') ) assert( isvector(c) || isempty(c) || strcmp(c, ':') ) if strcmp(r, ''), r = []; end if strcmp(c, ''), c = []; end z = mat_rccross_access(A, r, c); return else error('Unknown indexing') end end symbolic-2.2.4/inst/@sym/private/numeric_array_to_sym.m0000644000175000001440000000263212633614672022004 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . function z = numeric_array_to_sym(A) %private helper for sym ctor % convert an array to syms, currently on 1D, 2D. [n, m] = size(A); if (n == 0 || m == 0) cmd = { sprintf('return sp.Matrix(%d, %d, []),', n, m) }; z = python_cmd (cmd); return end Ac = cell(n,1); for i=1:n % we want all sym creation to go through the ctor. Ac{i} = cell(m,1); for j=1:m Ac{i}{j} = sym(A(i,j)); end end %Ac = {{x 2}; {3 4}; {8 9}}; d = size(A); if (length(d) > 2) error('conversion not supported for arrays of dim > 2'); end cmd = { 'L = _ins[0]' 'M = sp.Matrix(L)' 'return M,' }; z = python_cmd (cmd, Ac); symbolic-2.2.4/inst/@sym/private/mat_rclist_access.m0000644000175000001440000000364412633614672021240 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mat_rclist_access (@var{A}, @var{r}, @var{c}) %% Private helper routine for sym array access via lists of row/col. %% %% @code{(r(i),c(i))} specify entries of the matrix @var{A}. %% Returns a column vector of these extracted from @var{A}. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mat_rclist_access(A, r, c) if ~( isvector(r) && isvector(c) && (length(r) == length(c)) ) error('this routine is for a list of rows and cols'); end cmd = { '(A, rr, cc) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'n = len(rr)' 'M = sp.Matrix.zeros(n, 1)' 'for i in range(0,n):' ' M[i,0] = A[rr[i],cc[i]]' 'return M,' }; rr = num2cell(int32(r-1)); cc = num2cell(int32(c-1)); z = python_cmd (cmd, A, rr, cc); end %% Note: tests in @sym/private/ not executed % To run these in the test suite, you could move this mfile up to @sym. % However, note these are generally tested elsewhere indirectly. %!test %! B = [1 2 3; 5 6 7]; %! A = sym(B); %! assert (isequal (mat_rclist_access(A,[1 2],[2 3]), [B(1,2); B(2,3)])) symbolic-2.2.4/inst/@sym/private/mat_rccross_access.m0000644000175000001440000000661512633614672021417 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mat_rccross_access (@var{A}, @var{r}, @var{c}) %% Private helper routine for symbolic array access. %% %% Access entries of @var{A} that are the cross product of vectors %% @var{r} and @var{c}. @var{r} and @var{c} could be strings. %% Namely @code{':'}. %% %% @var{r} and @var{c} could contain duplicates. This is one %% reason by this code doesn't easily replace %% @code{mat_rclist_access}. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mat_rccross_access(A, r, c) if (ischar(r) && ischar(c) && strcmp(r, ':') && strcmp(c, ':')) z = A; return end %if both expressible as py slices... % FIXME: Could optimize these cases [n, m] = size(A); if (isnumeric(r) && isempty(r)) % no-op elseif (isnumeric(r) && isvector(r)) assert(all(r >= 1) && all(r <= n), 'index out of range') elseif (strcmp(r, ':')) r = 1:n; elseif (islogical(r) && isvector(r) && (length(r) == n)) I = r; r = 1:n; r = r(I); else error('unknown 2d-indexing in rows') end if (isnumeric(c) && isempty(c)) % no-op elseif (isnumeric(c) && isvector(c)) assert(all(c >= 1) && all(c <= m), 'index out of range') elseif (strcmp(c,':')) c = 1:m; elseif (islogical(c) && isvector(c) && (length(c) == m)) J = c; c = 1:m; c = c(J); else error('unknown 2d-indexing in columns') end cmd = { '(A, rr, cc) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'M = sp.Matrix.zeros(len(rr), len(cc))' 'for i in range(0, len(rr)):' ' for j in range(0, len(cc)):' ' M[i,j] = A[rr[i], cc[j]]' 'return M,' }; rr = num2cell(int32(r-1)); cc = num2cell(int32(c-1)); z = python_cmd (cmd, A, rr, cc); % FIXME: here's some code could be used for slices if (1==0) cmd = { 'A = _ins[0]' ... 'r = slice(_ins[1],_ins[2])' ... 'c = slice(_ins[3],_ins[4])' ... 'M = A[r,c]' ... 'return M,' }; z = python_cmd (cmd, A, r1-1, r2, c1-1, c2); end end %% Note: tests in @sym/private/ not executed % To run these in the test suite, you could move this mfile up to @sym. % However, note these are generally tested elsewhere indirectly. %!shared A,B %! B = [1 2 3 4; 5 6 7 9; 10 11 12 13]; %! A = sym(B); %!assert (isequal (mat_rccross_access(A,[1 3],[2 3]), B([1 3], [2 3]) )) %!assert (isequal (mat_rccross_access(A,1,[2 3]), B(1,[2 3]) )) %!assert (isequal (mat_rccross_access(A,[1 2],4), B([1 2],4) )) %!assert (isequal (mat_rccross_access(A,[2 1],[4 2]), B([2 1],[4 2]) )) %!assert (isequal (mat_rccross_access(A,[],[]), B([],[]) )) symbolic-2.2.4/inst/@sym/private/ustr_length.m0000644000175000001440000000303712633614672020110 0ustar cbmusersfunction n = ustr_length(str) %USTR_LENGTH Return the length of a unicode string % Return the number of characters in a string 'str' in a way that % works on both Matlab and Octave. On Matlab this is the same as % 'length(str)' (FIXME: is that so even for high code plane % characters?). But in Octave, char objects (strings) use UTF-8 and % so non-ascii characters uses up to 4 bytes. % % Note: nothing very sophisiticated happens here: there may be % things that could not be considered characters that are % nonetheless counted towards the length. In particular: I'm not % sure of the relationship between the amount of (monospaced) space % taken by a string and the results of this function. if ~exist('octave_config_info', 'builtin') n = length(str); return end d = double(str)'; N = length(d); b = dec2bin(d, 8); % "Bit patterns 0xxxxxxx and 11xxxxxx are synchronizing words used to % mark the beginning of the next valid character." Wikipedia UTF-8. ascii = (b(:,1) == '0'); % detect 0xxxxxxx target = repmat('11', N, 1); multibyte = all(b(:,1:2) == target, 2); % detect 11xxxxxx % Debugging: %sp = repmat(' ', N, 1); %[num2str(d,'%3d') sp b sp num2str(ascii) sp num2str(multibyte)] n = nnz(ascii) + nnz(multibyte); end %!assert (isequal (ustr_length('...'), 3)) %!assert (isequal (ustr_length('€'), 1)) %!assert (isequal (ustr_length('ab€c'), 4)) %!assert (isequal (ustr_length('ab€€'), 4)) %!assert (isequal (ustr_length('我爱你 爱着你 就像老鼠爱大米'), 15)) symbolic-2.2.4/inst/@sym/private/is_same_shape.m0000644000175000001440000000034012633614672020344 0ustar cbmusersfunction t = is_same_shape(x,y) %IS_SAME_SHAPE Inputs have same shape % Note does not say same type d1 = size(x); d2 = size(y); t = ( ... (length(d1) == length(d2)) && ... (all(d1 == d2)) ... ); symbolic-2.2.4/inst/@sym/private/def_each_elem_binary.m0000644000175000001440000000120612633614672021632 0ustar cbmusersfunction s = def_each_elem_binary(x, n) %private % FIXME: Deprecated? use binop_helper s = { 'def _each_elem_binary(x, y, f):' ... ' if x.is_Matrix and y.is_Matrix:' ... ' z = x.copy()' ... ' for i in range(0, len(x)):' ... ' z[i] = f(x[i], y[i])' ... ' return z,' ... ' if x.is_Matrix and not y.is_Matrix:' ... ' return x.applyfunc(lambda a: f(a, y)),' ... ' if not x.is_Matrix and y.is_Matrix:' ... ' return n.applyfunc(lambda a: f(x, a)),' ... ' else:' ... ' return f(x, y),' }; end symbolic-2.2.4/inst/@sym/private/binop_helper.m0000644000175000001440000000352412633614672020221 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% Author: Colin B. Macdonald %% Keywords: symbolic function z = binop_helper(x, y, scalar_fcn) %binop_helper, private % % 'scalar_fcn' can either be the name of a function or a lambda. % example: 'lambda a,b: a % b'); % It can also be the defn of a function called "_op" % e.g., { 'def _op(a,b):' ' return a % b' } % % FIXME: even faster if move to python_header (load once)? if (iscell(scalar_fcn)) %assert strncmp(scalar_fcn_str, 'def ', 4) cmd = scalar_fcn; else cmd = {['_op = ' scalar_fcn]}; end cmd = { cmd{:} ... '(x, y) = _ins' ... 'if x.is_Matrix and y.is_Matrix:' ... ' assert x.shape == y.shape' ... ' A = sp.Matrix(x.shape[0], y.shape[1],' ... ' lambda i,j: _op(x[i,j], y[i,j]))' ... ' return A,' ... 'elif x.is_Matrix:' ... ' return x.applyfunc(lambda a: _op(a, y)),' ... 'elif y.is_Matrix:' ... ' return y.applyfunc(lambda a: _op(x, a)),' ... 'else:' ... ' return _op(x, y),' }; z = python_cmd (cmd, sym(x), sym(y)); end symbolic-2.2.4/inst/@sym/private/make_sym_matrix.m0000644000175000001440000000365412633614672020750 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . function A = make_sym_matrix(As, sz) % private helper function for making symbolic matrix assert (ischar (As)); assert (isequal (size(sz), [1 2])); if (isa(sz, 'sym')) cmd = { 'As, sz = _ins' 'return sympy.MatrixSymbol(As, *sz),' }; A = python_cmd (cmd, As, sz); else n = int32(sz(1)); m = int32(sz(2)); % FIXME: returning an appropriate MatrixSymbol is nice idea, % but would need more work on IPC, size(). The ideal thing % might be a string representation that looks like this % when displayed in Octave, but is represented with a % MatrixSymbol internally. cmd = { 'As, n, m = _ins' '#A = sympy.MatrixSymbol(As, n, m)' 'if n == 0 or m == 0:' ' return sympy.Matrix(n, m, []),' ' #sympy.MatrixSymbol(As, n, m),' % broken? 'if n < 10 and m < 10:' ' extra = ""' 'else:' ' extra = "_"' 'L = [[Symbol("%s%d%s%d" % (As, i+1, extra, j+1)) \' ' for j in range(0, m)] \' ' for i in range(0, n)]' 'A = sympy.Matrix(L)' 'return A,' }; A = python_cmd (cmd, As, n, m); end end symbolic-2.2.4/inst/@sym/private/mat_replace.m0000644000175000001440000000471512633614672020032 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mat_replace (@var{A}, @var{subs}, @var{rhs}) %% Private helper routine for setting symbolic array entries. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mat_replace(A, subs, b) if ( (length(subs) == 1) && (islogical(subs{1})) ) %% A(logical) = B z = mat_mask_asgn(A, subs{1}, b); return elseif (length(subs) == 1) % can use a single index to grow a vector, so we carefully deal with % vector vs linear index to matrix (not required for access) [n,m] = size(A); if (n == 0 || n == 1) c = subs{1}; r = ones(size(c)); elseif (m == 1) r = subs{1}; c = ones(size(r)); else % linear indices into 2D array [r, c] = ind2sub (size(A), subs{1}); end elseif (length(subs) == 2) r = subs{1}; c = subs{2}; [n,m] = size(A); if (isnumeric(r) && ((isvector(r) || isempty(r)))) % no-op elseif (strcmp(r,':')) r = 1:n; elseif (islogical(r) && isvector(r) && (length(r) == n)) I = r; r = 1:n; r = r(I); else error('unknown 2d-indexing in rows') end if (isnumeric(c) && ((isvector(c) || isempty(c)))) % no-op elseif (strcmp(c,':')) c = 1:m; elseif (islogical(c) && isvector(c) && (length(c) == m)) J = c; c = 1:m; c = c(J); else error('unknown 2d-indexing in columns') end [r,c] = ndgrid(r,c); if ~( isscalar(b) || is_same_shape (r, b) ) % Octave/Matlab both do this for double so we will to error('A(I,J,...) = X: dimensions mismatch') end r = r(:); c = c(:); else error('unknown indexing') end z = mat_rclist_asgn(A, r, c, b); end symbolic-2.2.4/inst/@sym/private/mat_rclist_asgn.m0000644000175000001440000000770012633614672020724 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mat_rclist_asgn (@var{A}, @var{r}, @var{c}, @var{B}) %% Private helper routine for sym array assigment using lists. %% %% @code{(R(i),C(i))} specify entries of the matrix @var{A}. %% We execute @code{A(R(i),C(i)) = B(i)}. %% %% Notes: %% @itemize %% @item @var{B} is accessed with linear indexing. %% @item @var{B} might be a scalar, used many times. %% @item @var{A} might need to get bigger, if so it will be padded %% with zeros. %% @end itemize %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mat_rclist_asgn(A, r, c, B) if ~( isvector(r) && isvector(c) && (length(r) == length(c)) ) error('this routine is for a list of rows and cols'); end if ((numel(B) == 1) && (numel(r) > 1)) % B should be a sym unless experimenting with various bool % trickery. % FIXME: Issue #71: why does this work even if B is sym w/ bools? B = B*ones(size(r)); % If sym, we probably can't use repmat (recursion?). %if isa(B, 'sym') % B = B*ones(size(r)); %else % warning('activating repmat code: a non-sym snuck in?') % assert( islogical (B)) % B = repmat(B, size(r)); %end end if (length(r) ~= numel(B)) error('not enough/too much in B') end % Note: we expand by making a new big enough matrix and calling % .copyin_matrix. Easiest as: new[0,0] = old cmd = { '(A, r, c, B) = _ins' '# B linear access fix, transpose for sympy row-based' '#if not isinstance(B, sp.MatrixBase):' 'if not B.is_Matrix:' ' B = sp.Matrix([[B]])' 'BT = B.T' '# copy of A, expanded and padded with zeros' 'if not A.is_Matrix:' ' n = max( max(r)+1, 1 )' ' m = max( max(c)+1, 1 )' 'else:' ' n = max( max(r)+1, A.rows )' ' m = max( max(c)+1, A.cols )' 'AA = sp.Matrix.zeros(n, m)' 'AA[0, 0] = A' 'for i in range(0, len(r)):' ' AA[r[i],c[i]] = BT[i]' 'return AA,' }; rr = num2cell(int32(r-1)); cc = num2cell(int32(c-1)); z = python_cmd (cmd, A, rr, cc, B); % a simpler earlier version, but only for scalar r,c %cmd = { '(A, r, c, b) = _ins' % 'if not A.is_Matrix:' % ' A = sp.Matrix([[A]])' % 'AA = sp.Matrix.zeros(max(r+1, A.rows), max(c+1, A.cols))' % 'AA[0, 0] = A' % 'AA[r, c] = b' % 'return AA,' }; end %% Note: tests in @sym/private/ not executed % To run these in the test suite, you could move this mfile up to @sym. % However, note these are generally tested elsewhere indirectly. %!shared A, B %! B = [1 2 3; 4 5 6]; %! A = sym(B); %!test %! C = B; C([1 6]) = [8 9]; %! assert (isequal (mat_rclist_asgn(A,[1 2],[1 3],sym([8 9])), C)) %!test %! % rhs scalar %! C = B; C([1 6]) = 88; %! assert (isequal (mat_rclist_asgn(A,[1 2],[1 3],sym(88)), C)) %!test %! % If rhs is not a vector, make sure col-based access works %! rhs = [18 20; 19 21]; %! C = B; C([1 2 3 4]) = rhs; %! D = mat_rclist_asgn(A,[1 2 1 2],[1 1 2 2],sym(rhs)); %! assert (isequal (D, C)) %!test %! % Growth %! C = B; C(1,5) = 10; %! D = mat_rclist_asgn(A,1,5,sym(10)); %! assert (isequal (D, C)) symbolic-2.2.4/inst/@sym/private/mat_mask_asgn.m0000644000175000001440000000602212633614672020353 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mat_mask_asgn (@var{A}, @var{I}, @var{rhs}) %% Private helper routine for symbolic array assignment via mask. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mat_mask_asgn(A, I, B) if (~islogical(I)) error('subscript indices must be either positive integers or logicals') end if (numel(A) ~= numel(I)) error('size A not compatible w/ size I in A(I)') end % issue #18 fix a(t/f)=6 if (isscalar(A)) if (I) z = B; else z = A; end return end % this messes with the later sanity checks if (nnz(I) == 0) z = A; return end if (numel(B) == 1) B = B*ones(nnz(I),1); end if (nnz(I) ~= numel(B)) error('not enough/too much in B') end if (~(is_same_shape(A,I))) % this is not an error, but quite likely reflects a user error warning('OctSymPy:subsagn:index_matrix_not_same_shape', ... 'A and I in A(I) not same shape: no problem, but did you intend this?') end if (~isvector(B)) % Here B is a matrix. B scalar is dealt with earlier. This is a bit % odd (although ok in octave) so probably a user error. assert (~isscalar(B)) warning('OctSymPy:subsagn:rhs_shape', ... 'B neither vector nor scalar in indexed A(I)=B: unusual, did you intend this?') end % I think .T makes a copy, but be careful: in general may need a % .copy() here cmd = { '(A, mask, B) = _ins' '# transpose b/c SymPy is row-based' 'AT = A.T' 'maskT = mask.T' 'BT = B.T' 'j = 0' 'for i in range(0, len(A)):' ' if maskT[i]:' ' AT[i] = BT[j]' ' j = j + 1' 'return AT.T,' }; z = python_cmd (cmd, sym(A), sym(I), sym(B)); end %% Note: tests in @sym/private/ not executed % To run these in the test suite, you could move this mfile up to @sym. % However, note these are generally tested elsewhere indirectly. %% 2D arrays %!shared a, b, I %! b = [1:4]; b = [b; 3*b; 5*b]; %! a = sym(b); %! I = rand(size(b)) > 0.5; %!test %! A = mat_mask_asgn(a,I, 2*b(I)); %! B = b; B(I) = 2*b(I); %! assert (isequal (A, B)) %!test %! % scalar RHS %! A = mat_mask_asgn(a,I, 17); %! B = b; B(I) = 17; %! assert (isequal (A, B)) symbolic-2.2.4/inst/@sym/private/assert_same_shape.m0000644000175000001440000000017712633614672021242 0ustar cbmusersfunction t = assert_same_shape(x,y) if ~(is_same_shape(x,y)) error('array inputs must have same size and shape'); end symbolic-2.2.4/inst/@sym/private/ineq_helper.m0000644000175000001440000000230512633614672020042 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% Author: Colin B. Macdonald %% Keywords: symbolic function t = ineq_helper(op, fop, lhs, rhs, nanspecial) if (nargin == 4) nanspecial = 'S.false'; end % FIXME: this will need to catch exceptions soon op = { 'def _op(lhs, rhs):' ' # workaround sympy nan behaviour, Issue #9' ' if lhs is nan or rhs is nan:' [' return ' nanspecial] [' return ' fop '(lhs, rhs)'] }; t = binop_helper(lhs, rhs, op); end symbolic-2.2.4/inst/@sym/private/cell_array_to_sym.m0000644000175000001440000000064112633614672021257 0ustar cbmusersfunction s = cell_array_to_sym (L) %private helper for sym ctor % convert a cell array to syms, recursively when nests cells found assert(iscell(L)) s = cell(size(L)); for i = 1:numel(L) %s{i} = sym(L{i}); % not strictly necessary if sym calls this but maybe neater this way: item = L{i}; if iscell(item) s{i} = cell_array_to_sym(item); else s{i} = sym(item); end end symbolic-2.2.4/inst/@sym/private/mystrjoin.m0000644000175000001440000000246012633614672017607 0ustar cbmusersfunction s = mystrjoin(A, sepchar) % replacement for strjoin until Octave 3.6 is old persistent have_strjoin if isempty(have_strjoin) % this test is slow if it does not exist (6s for 1000 calls) % (28s w/, 24 w/o) so we cache the result if (exist('strjoin') > 1) have_strjoin = true; else have_strjoin = false; end end if (have_strjoin) s = strjoin(A, sepchar); return end %% we have no strjoin, do our own n = numel(A); % The builtin strjoin in Octave and Matlab do this too (that is, need % to call with '\\n' to join with '\n'. sepchar = sprintf(sepchar); if (n == 0) s = ''; else s = A{1}; end for i = 2:n s = [s sepchar A{i}]; end end %try % s = strjoin(A, sepchar); %catch % [msg, msgid] = lasterr (); % if ~strncmp(msg, '''strjoin'' undefined', 19) % error(msgid, msg) % end %end % for loop above is 23s % 23s %L(2,:) = repmat({newl}, 1, length(L)); %fputs(f, [L{:}]); % 27s %B = cellfun(@(x) fputs(f, [x newl]), L); % 27s %B = cellfun(@(x) [x newl], L, 'UniformOutput', false); %fputs (f, [B{:}]); % 30s %B = cellfun(@(x) [x newl], L, 'UniformOutput', false); %B = cellfun(@(x) fputs(f, x), B); % 24 s %for i = 1:length(L) % fputs (f, L{i}); % fputs (f, newl); %end symbolic-2.2.4/inst/@sym/private/magic_double_str.m0000644000175000001440000000323612633614672021055 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {[@var{s}, @var{flag}] =} magic_double_str (@var{x}) %% Recognize special double values. %% %% Private helper function. %% %% Caution: there are two copies of this file for technical %% reasons: make sure you modify both of them! %% %% @seealso{sym, vpa} %% @end deftypefn function [s, flag] = magic_double_str(x) flag = 1; if (~isa(x, 'double') || ~isreal(x)) error('OctSymPy:magic_double_str:notrealdouble', ... 'Expected a real double precision number'); end % NOTE: yes, these are floating point equality checks! if (x == pi) s = 'pi'; elseif (x == -pi) s = '-pi'; elseif ((isinf(x)) && (x > 0)) s = 'inf'; elseif ((isinf(x)) && (x < 0)) s = '-inf'; elseif (isnan(x)) s = 'nan'; elseif (isreal(x) && (mod(x,1) == 0)) % is integer s = num2str(x); % better than sprintf('%d', large) else s = ''; flag = 0; end end symbolic-2.2.4/inst/@sym/private/codegen.m0000644000175000001440000001423412633614672017157 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% Author: Colin B. Macdonald %% Keywords: symbolic function [outflag,output] = codegen(varargin) [Nin, inputs, inputstr, Nout, param] = codegen_input_parser(varargin{:}); %fprintf('debug: %d inputs, %d outputs\n', Nin, Nout); %% fortran.m/ccode.m % these call us with lang if (isfield(param, 'lang')) assert(strcmpi(param.lang, 'F95') || ... strcmpi(param.lang, 'C') || ... strcmpi(param.lang, 'Octave')) else param.lang = 'Octave'; end if (strcmpi(param.lang, 'Octave')) outflag = -1; output = {Nin, inputs, inputstr, Nout, param}; return end %% Outputs if (param.codegen) %cmd = { '(expr,fcnname,fname,showhdr) = _ins' ... % 'from sympy.utilities.codegen import codegen' ... % ['out = codegen((fcnname,expr), "' param.lang ... % '", filename, header=showhdr)'] ... % 'return out,' }; %if (user_provided_vars) cmd = { '(expr,fcnname,filename,showhdr,in_vars) = _ins' ... 'from sympy.utilities.codegen import codegen' ... ['out = codegen((fcnname,expr), "' param.lang ... '", filename, header=showhdr' ... ', argument_sequence=in_vars)'] ... 'return out,' }; %end assert(Nout == 1, 'FIXME: multiple inputs? need names?'); if isempty(param.fname) fname2 = 'file'; fcnname = 'myfun'; else fname2 = param.fname; fcnname = param.fname; end % was note here about findsymbols vs symvar ordering: not relevant out = python_cmd (cmd, varargin{1}, fcnname, fname2, param.show_header, inputs); C.name = out{1}{1}; C.code = out{1}{2}; H.name = out{2}{1}; H.code = out{2}{2}; if (isempty(param.fname)) output = {C, H}; outflag = 2; else [fid,msg] = fopen(C.name, 'w'); assert(fid > -1, msg) fprintf(fid, '%s', C.code) fclose(fid); [fid,msg] = fopen(H.name, 'w'); assert(fid > -1, msg) fprintf(fid, '%s', H.code) fclose(fid); fprintf('Wrote files %s and %s.\n', C.name, H.name); output = {}; outflag = 0; end else if (strcmp(param.lang, 'C')) cmd = { '(f,) = _ins' ... 's = ccode(f)' ... 'return s,' }; elseif (strcmp(param.lang, 'F95')) cmd = { '(f,) = _ins' ... 's = fcode(f)' ... 'return s,' }; else error('only C and F95 supported'); end exprstrs = {}; for i=1:Nout expr = varargin{i}; exprstr{i} = python_cmd (cmd, expr); end if (Nout == 1) output = {exprstr{1}}; else output = exprstr; end outflag = 1; end end function [Nin, inputs, inputstr, Nout, param] = codegen_input_parser(varargin) param.codegen = false; param.user_provided_vars = false; param.show_header = true; Nout = -42; %% input processing % loop over inputs to find: (f1,f2,...,f_{Nout}, param, value) i = 0; while (i < nargin) i = i + 1; if (ischar(varargin{i})) if (Nout < 0) Nout = i-1; end if strcmpi(varargin{i}, 'vars') temp = varargin{i+1}; i = i + 1; param.user_provided_vars = true; if (isa(temp, 'sym')) inputs = temp; elseif (iscell(temp)) inputs = temp; for j=1:length(inputs) assert(isa(inputs{j},'sym') || ischar(inputs{j}), ... 'only sym/char supported in vars list'); end else error('invalid "vars" param'); end elseif strcmpi(varargin{i}, 'file') param.codegen = true; param.fname = varargin{i+1}; i = i + 1; elseif strcmpi(varargin{i}, 'show_header') param.show_header = logical(varargin{i+1}); i = i + 1; elseif strcmpi(varargin{i}, 'lang') param.lang = varargin{i+1}; i = i + 1; elseif strcmp(varargin{i}, 'outputs') warning('fixme: named "outputs" to be implemented?') outs = varargin{i+1} i = i + 1; else error('invalid option') end end end if (Nout < 0) Nout = nargin; end for i=1:Nout if ~(isa(varargin{i}, 'sym')) warning('expected output expressions to be syms'); end if (isa(varargin{i}, 'symfun')) warning('FIXME: symfun! does that need special treatment?'); end end %% get input string if (param.user_provided_vars) Nin = length(inputs); % FIXME: once Octave 3.6 is ancient history, use strjoin inputstr = mystrjoin(syms2charcells(inputs), ','); else % findsymbols works on cell input, previous comment worried % about differences with symvar, but don't think there are any % here: only for two inputs like symvar(f, 2). inputs = findsymbols(varargin(1:Nout)); Nin = length(inputs); inputs_array = cell2symarray(inputs); inputstr = findsym(inputs_array); end %fprintf('debug: %d inputs, %d outputs\n', Nin, Nout); end function A = cell2symarray(C) A = sym([]); for i=1:length(C) %A(i) = C{i}; % Issue #17 idx.type = '()'; idx.subs = {i}; A = subsasgn(A, idx, C{i}); end end function C = syms2charcells(S) C = {}; for i=1:length(S) if iscell(S) if isa(S{i}, 'sym') C{i} = S{i}.flat; else C{i} = S{i}; end else % MoFo Issue #17 %C{i} = S(i).flat idx.type = '()'; idx.subs = {i}; temp = subsref(S,idx); C{i} = temp.flat; end end end symbolic-2.2.4/inst/@sym/private/uniop_helper.m0000644000175000001440000000243412633614672020243 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% Author: Colin B. Macdonald %% Keywords: symbolic function z = uniop_helper(x, scalar_fcn) % string can either be the name of a function or the definition % of a new function. if (iscell(scalar_fcn)) %assert strncmp(scalar_fcn_str, 'def ', 4) cmd = scalar_fcn; else cmd = {['sf = ' scalar_fcn]}; end cmd = { cmd{:} ... '(x,) = _ins' ... 'if x.is_Matrix:' ... ' return x.applyfunc(lambda a: sf(a)),' ... 'else:' ... ' return sf(x),' }; z = python_cmd (cmd, sym(x)); end symbolic-2.2.4/inst/@sym/private/mat_mask_access.m0000644000175000001440000001014312633614672020663 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mat_mask_access (@var{A}, @var{I}) %% Private helper routine for symbolic array access via mask. %% %% Notes on shape, from observing Matlab/Octave behaviour on doubles: %% @itemize %% @item If A is a vector, Z always has the same orientation as A. %% @item If A is a matrix and if I is a vector than Z has the same %% orientation as I. %% @item In all other cases (?) result is a column vector. %% @end itemize %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function Z = mat_mask_access(A, I) if (~islogical(I)) error('subscript indices must be either positive integers or logicals') end if (numel(A) ~= numel(I)) error('size A not compatible w/ size I in A(I)') end if (~(is_same_shape(A,I))) % this is not an error, but quite likely reflects a user error warning('OctSymPy:subsref:index_matrix_not_same_shape', ... 'A and I in A(I) not same shape: no problem, but did you intend this?') end % issue #18 fix a(t/f)=6 if (isscalar(A)) if (I) Z = A; else Z = sym([]); end return end % careful, if you have persistence/caching, do these need .copy? cmd = { '(A, mask, n, m) = _ins' '# transpose b/c SymPy is row-based' 'AT = A.T' 'maskT = mask.T' 'M = sp.Matrix.zeros(m, n) # row-based' 'j = 0' 'for i in range(0,len(A)):' ' if maskT[i]:' ' M[j] = AT[i]' ' j = j + 1' 'return M.T,' }; % old Matlab (e.g., 2008) has no isrow/iscolumn, but we want A % and I to be sym eventually, so just do it here first. But in % (common) case where I is nonsym (logical), its faster to call % nnz on the nonsym I. A = sym(A); Is = sym(I); % output shape, see logic in comments above if (isrow(A)) n = 1; m = nnz(I); elseif (iscolumn(A)) n = nnz(I); m = 1; elseif (isrow(Is)) n = 1; m = nnz(I); elseif (iscolumn(Is)) n = nnz(I); m = 1; else n = nnz(I); m = 1; end Z = python_cmd (cmd, A, Is, n, m); end %% Note: tests in @sym/private/ not executed % To run these in the test suite, you could move this mfile up to @sym. % However, note these are generally tested elsewhere indirectly. %!test %! % 2D arrays %! b = [1:4]; b = [b; 3*b; 5*b]; %! a = sym(b); %! I = rand(size(b)) > 0.5; %! assert(isequal( mat_mask_access(a,I), b(I) )) %! I = I(:); %! s = warning ('off', 'OctSymPy:subsref:index_matrix_not_same_shape'); %! assert(isequal( mat_mask_access(a,I), b(I) )) %! I = I'; %! assert(isequal( mat_mask_access(a,I), b(I) )) %! warning (s) %! I = logical(zeros(size(b))); %! assert(isequal( mat_mask_access(a,I), b(I) )) %!warning %! % some warnings when I is wrong shape %! r = [1:6]; %! ar = sym(r); %! c = r'; %! ac = sym(c); %! Ir = rand(size(r)) > 0.5; %! Ic = rand(size(c)) > 0.5; %! temp = mat_mask_access(ar, Ic); %! temp = mat_mask_access(ac, Ir); %!test %! % 1D arrays %! r = [1:6]; %! ar = sym(r); %! c = r'; %! ac = sym(c); %! Ir = rand(size(r)) > 0.5; %! Ic = rand(size(c)) > 0.5; %! assert (isequal (mat_mask_access(ar,Ir), r(Ir))) %! assert (isequal (mat_mask_access(ac,Ic), c(Ic))) %! s = warning ('off', 'OctSymPy:subsref:index_matrix_not_same_shape'); %! assert (isequal (mat_mask_access(ar,Ic), r(Ic))) %! assert (isequal (mat_mask_access(ac,Ir), c(Ir))) %! warning (s) symbolic-2.2.4/inst/@sym/ilaplace.m0000644000175000001440000000642212633614672015653 0ustar cbmusers%% Copyright (C) 2014 Andrés Prieto %% Copyright (C) 2015 Andrés Prieto, Colin Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{f} =} ilaplace (@var{F}, @var{s}, @var{t}) %% @deftypefnx {Function File} {@var{f} =} ilaplace (@var{F}) %% @deftypefnx {Function File} {@var{f} =} ilaplace (@var{F}, @var{t}) %% Inverse Laplace transform. %% %% Example: %% @example %% @group %% >> syms s %% >> F = 1/s^2; %% >> ilaplace(F) %% @result{} (sym) t %% @end group %% @end example %% %% By default the ouput is a function of @code{t} (or @code{x} if the %% inverse transform happens to be with respect to @code{t}). This can %% be overriden by specifying @var{t}. For example: %% @example %% @group %% >> syms s t x %% >> ilaplace(1/s^2) %% @result{} (sym) t %% >> ilaplace(1/t^2) %% @result{} (sym) x %% >> ilaplace(1/s^2, x) %% @result{} (sym) x %% @end group %% @end example %% %% @seealso{laplace} %% @end deftypefn %% Author: Andrés Prieto %% Keywords: symbolic, integral transforms function f = ilaplace(varargin) % FIXME: it only works for scalar functions % If the Laplace variable in the frequency domain is equal to "t", % "x" will be the physical variable (analogously to SMT) if (nargin == 1) F = sym(varargin{1}); s = symvar(F, 1); if (isempty(s)) s = sym('s'); end cmd = { 'F=_ins[0]; s=_ins[1]; t=sp.Symbol("t")' 'if t==s:' ' t=sp.Symbol("x")' 'return sp.Subs(sp.inverse_laplace_transform(F, s, t),sp.Heaviside(t),1).doit(),'}; f = python_cmd(cmd,F,s); elseif (nargin == 2) F = sym(varargin{1}); t = sym(varargin{2}); s = symvar(F, 1); % note SMT does something different, prefers s if (isempty(s)) s = sym('s'); end cmd = { 'F=_ins[0]; s=_ins[1]; t=_ins[2]' 'return sp.Subs(sp.inverse_laplace_transform(F, s, t),sp.Heaviside(t),1).doit(),'}; f = python_cmd(cmd,F,s,t); elseif (nargin == 3) F = sym(varargin{1}); s = sym(varargin{2}); t = sym(varargin{3}); cmd = { 'F=_ins[0]; s=_ins[1]; t=_ins[2]' 'return sp.Subs(sp.inverse_laplace_transform(F, s, t),sp.Heaviside(t),1).doit(),'}; f = python_cmd(cmd,F,s,t); else print_usage (); end end %!test %! % basic %! syms t s r u x %! assert(logical( ilaplace(1/r^2,u) == u )) %! assert(logical( ilaplace(1/r^2,r,u) == u )) %! assert(logical( ilaplace(s/(s^2+9)) == cos(3*t) )) %! assert(logical( ilaplace(6/s^4) == t^3 )) %!test %! % SMT compact %! syms t s x %! assert(logical( ilaplace(1/s^2) == t )) %! assert(logical( ilaplace(1/t^2) == x )) symbolic-2.2.4/inst/@sym/symvar.m0000644000175000001440000001225612633614672015424 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{vars} =} symvar (@var{f}) %% @deftypefnx {Function File} {@var{vars} =} symvar (@var{f}, @var{n}) %% Find symbols in expression and return them as a symbolic vector. %% %% The symbols are sorted in alphabetic order with capital letters %% first. If @var{n} is specified, the @var{n} symbols closest to %% @code{x} are returned. %% %% Example: %% @example %% @group %% >> syms x y %% >> f = x^2 + 3*x*y - y^2; %% >> symvar (f) %% @result{} (sym) [x y] (1×2 matrix) %% >> symvar (f, 1) %% @result{} (sym) x %% @end group %% @end example %% %% Further examples: %% @example %% @group %% >> syms a x t %% >> f = a*x + t; %% >> symvar (f, 1) %% @result{} (sym) x %% >> symvar (f, 2) %% @result{} (sym) [x t] (1×2 matrix) %% >> symvar (f, 3) %% @result{} (sym) [x t a] (1×3 matrix) %% @end group %% @end example %% And note its ok to ask for more: %% @example %% @group %% >> symvar (f, 1000) %% @result{} (sym) [x t a] (1×3 matrix) %% @end group %% @end example %% %% %% Compatibility with other implementations: the output should %% match the order of the equivalent command in the Matlab Symbolic %% Toolbox version 2014a, as documented here: %% http://www.mathworks.co.uk/help/symbolic/symvar.html %% %% If two variables have the same symbol but different assumptions, %% they will both appear in the output. It is not well-defined %% in what order they appear. %% %% @seealso{findsym, findsymbols} %% @end deftypefn %% Author: Colin B. Macdonald, Willem J. Atsma (previous versions) %% Keywords: symbolic function vars = symvar(F, Nout) symlist = findsymbols (F); Nlist = length (symlist); if (nargin == 1) vars = sym([]); for i=1:Nlist %vars(i) = symlist{i}; idx.type = '()'; idx.subs = {i}; vars = subsasgn(vars, idx, symlist{i}); end return end % behaviour is rather different specific number of outputs requests assert(Nout >= 0, 'number of requested symbols should be positive') if (Nlist < Nout) %if (Nout == 1) % warning('Asked for one variable, but none found.'); %else % warning('Asked for %d variables, but only %d found.',Nout,Nlist); %end Nout = Nlist; end vars = sym([]); if (Nout == 0) return end symstrings = {}; for i=1:Nlist symstrings{i} = symlist{i}.flat; end %% define a map for resorting sortorder = 'xywzvutsrqponmlkjihgfedcbaXYWZVUTSRQPONMLKJIHGFEDCBA'; AZaz = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; assert(length(AZaz) == length(sortorder)) for i=1:length(sortorder) map.(sortorder(i)) = AZaz(i); end symstr_forsort = {}; for i=1:Nlist str = symstrings{i}; first = str(1); str(1) = map.(first); symstr_forsort{i} = str; end symstr_forsort; [xs,I] = sort(symstr_forsort); for i=1:Nout %vars(i) = symlist{i}; idx.type = '()'; idx.subs = {i}; vars = subsasgn(vars, idx, symlist{I(i)}); end end %!test %! %% some empty cases %! assert (isempty (symvar (sym(1)))); %! assert (isempty (symvar (sym(1),1))); %! assert (isempty (symvar (sym(1),0))); %! assert (isempty (symvar (sym('x'),0))); %!shared x,y,f %! x=sym('x'); y=sym('y'); f=x^2+3*x*y-y^2; %!assert (isequal (symvar (f), [x y])); %!assert (isequal (symvar (f, 1), x)); %!test %! %% closest to x %! syms x y a b c xx %! alpha = sym('alpha'); %! % https://www.mathworks.com/matlabcentral/newsreader/view_thread/237730 %! assert( isequal (symvar (b*xx*exp(alpha) + c*sin(a*y), 2), [xx y])) %! %% tests to match Matlab R2013b %!shared x,y,z,a,b,c,X,Y,Z %! syms x y z a b c X Y Z %!test %! %% X,Y,Z first if no 2nd argument %! s = prod([x y z a b c X Y Z]); %! assert (isequal( symvar (s), [X Y Z a b c x y z] )) %!test %! %% uppercase have *low* priority with argument? %! s = prod([x y z a b c X Y Z]); %! assert (isequal (symvar (s,4), [x, y, z, c] )) %!test %! %% closest to x %! s = prod([y z a b c Y Z]); %! assert (isequal( symvar (s,6), [ y, z, c, b, a, Y] )) %! s = prod([a b c Y Z]); %! assert (isequal( symvar (s,4), [ c, b, a, Y] )) %!test %! %% upper case letters in correct order %! s = X*Y*Z; %! assert (isequal( symvar (s,3), [X Y Z] )) %!test %! % diff. assumptions make diff. symbols %! x1 = sym('x'); %! x2 = sym('x', 'positive'); %! f = x1*x2; %! assert (length (symvar (f)) == 2) %! z = symvar (f, 1); %! assert (xor (isequal (z, x1), isequal (z, x2))) symbolic-2.2.4/inst/@sym/atanh.m0000644000175000001440000000256012633614672015173 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} atanh (@var{x}) %% Symbolic atanh function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = atanh(x) y = uniop_helper (x, 'atanh'); end %!shared x, d %! d = 1/2; %! x = sym('1/2'); %!test %! f1 = atanh(x); %! f2 = atanh(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = atanh(A); %! f2 = atanh(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/sym.m0000644000175000001440000004245312633614672014715 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{x} =} sym (@var{y}) %% @deftypefnx {Function File} {@var{x} =} sym (@var{y}, @var{assumestr}) %% @deftypefnx {Function File} {@var{x} =} sym (@var{y}, @var{assumestr1}, @var{assumestr2}, @dots{}) %% @deftypefnx {Function File} {@var{x} =} sym (@var{A}, [@var{n}, @var{m}]) %% Define symbols and numbers as symbolic expressions. %% %% @var{y} can be an integer, a string or one of several special %% double values. It can also be a double matrix or a cell %% array. %% %% Examples: %% @example %% @group %% >> x = sym ('x') %% @result{} x = (sym) x %% >> y = sym ('2') %% @result{} y = (sym) 2 %% >> y = sym (3) %% @result{} y = (sym) 3 %% >> y = sym (inf) %% @result{} y = (sym) ∞ %% >> y = sym (pi) %% @result{} y = (sym) π %% @end group %% @end example %% %% A sym of a sym is a sym (idempotence): %% @example %% @group %% >> sym (sym (pi)) %% @result{} (sym) π %% @end group %% @end example %% %% A matrix can be input: %% @example %% @group %% >> sym ([1 2; 3 4]) %% @result{} (sym 2×2 matrix) %% ⎡1 2⎤ %% ⎢ ⎥ %% ⎣3 4⎦ %% @end group %% @end example %% %% Boolean input, giving symbolic True/False: %% @example %% @group %% >> sym (true) %% @result{} (sym) True %% >> sym (false) %% @result{} (sym) False %% @end group %% @end example %% %% Some special double values are recognized but its all a %% bit heuristic/magical: %% @example %% @group %% >> y = sym(pi/100) %% @result{} warning: Using rat() heuristics for double-precision input (is this what you wanted?) %% y = (sym) %% π %% ─── %% 100 %% @end group %% @end example %% While this works fine for “small” fractions, its probably safer to do: %% @example %% @group %% >> y = sym(pi)/100 %% @result{} y = (sym) %% π %% ─── %% 100 %% @end group %% @end example %% %% %% A second (and further) arguments can provide assumptions %% or restrictions on the type of the symbol: %% @example %% @group %% >> x = sym ('x', 'positive') %% @result{} x = (sym) x %% >> x = sym ('x', 'positive', 'integer') %% @result{} x = (sym) x %% @end group %% @end example %% @xref{assumptions}, for the list of supported assumptions. %% %% Caution: it is possible to create multiple variants of the %% same symbol with different assumptions. %% @example %% @group %% >> x1 = sym('x') %% @result{} x1 = (sym) x %% >> x2 = sym('x', 'positive') %% @result{} x2 = (sym) x %% >> x1 == x2 %% @result{} (sym) x = x %% >> isAlways(x1 == x2) %% @result{} 0 %% >> logical(x1 == x2) % @result{} 0 %% @end group %% @end example %% %% The second argument can also specify the size of a matrix: %% @example %% @group %% >> A = sym('a', [2 3]) %% @result{} A = (sym 2×3 matrix) %% ⎡a₁₁ a₁₂ a₁₃⎤ %% ⎢ ⎥ %% ⎣a₂₁ a₂₂ a₂₃⎦ %% @end group %% @end example %% or even with symbolic size: %% @example %% @group %% >> syms m n positive integer %% >> B = sym('B', [m n]) %% @result{} B = (sym) B (m×n matrix expression) %% @end group %% @end example %% %% The underlying SymPy “srepr” can also be passed directly to %% @code{sym}: @pxref{char} for details. %% %% @seealso{syms, assumptions, assume, assumeAlso} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, symbols, CAS function s = sym(x, varargin) if (nargin == 0) s = sym(0); return end %% The actual class constructor % Tempting to make a 'private constructor' but we need to access % this from the python ipc stuff: outside the class. We identify % this non-user-facing usage by empty x and 6 inputs total. Note % that "sym([])" is valid but "sym([], ...)" is otherwise not. if (isempty(x) && (nargin == 6)) s.pickle = varargin{1}; s.size = varargin{2}; s.flat = varargin{3}; s.ascii = varargin{4}; s.unicode = varargin{5}; s.extra = []; s = class(s, 'sym'); return end %% User interface for defining sym % sym(1), sym('x'), etc. %if (strcmp (class (x), 'symfun') && nargin==1) % % FIXME: pass a symfun to sym() ctor; convert to pure sym % % (SMT does not do this in 2014a). bad idea? % s = x.sym; % return if (isa (x, 'sym') && nargin==1) % matches sym and subclasses s = x; return elseif (iscell (x) && nargin==1) s = cell_array_to_sym (x); return elseif (isnumeric(x) && ~isscalar (x) && nargin==1) s = numeric_array_to_sym (x); return elseif (islogical (x) && ~isscalar (x) && nargin==1) s = numeric_array_to_sym (x); return elseif (isa (x, 'double') && ~isreal (x) && nargin==1) s = sym(real(x)) + sym('I')*sym(imag(x)); return elseif (isinteger(x) && nargin==1) s = sym(num2str(x, '%ld')); return elseif (isa (x, 'double') && nargin==1) [s, flag] = magic_double_str(x); if (~flag) % Allow 1/3 and other "small" fractions. % Personally, I like a warning here so I can catch bugs. % Matlab SMT does this (w/o warning). % FIXME: could have sympy do this? Or just make symbolic floats? warning('OctSymPy:sym:rationalapprox', ... 'Using rat() heuristics for double-precision input (is this what you wanted?)'); [N1, D1] = rat(x); [N2, D2] = rat(x/pi); if (10*abs(D2) < abs(D1)) % use frac*pi if demoninator significantly shorter s = sprintf('Rational(%s, %s)*pi', num2str(N2), num2str(D2)); else s = sprintf('Rational(%s, %s)', num2str(N1), num2str(D1)); end end s = sym(s); return elseif (islogical (x) && isscalar(x) && nargin==1) if (x) cmd = 'z = sp.S.true'; else cmd = 'z = sp.S.false'; end elseif (nargin == 2 && ischar(varargin{1}) && strcmp(varargin{1},'clear')) % special case for 'clear', because of side-effects if (isa(x, 'sym')) x = x.flat; % we just want the string end s = sym(x); % --------------------------------------------- % Muck around in the caller's namespace, replacing syms % that match 'xstr' (a string) with the 'newx' sym. xstr = x; newx = s; context = 'caller'; % --------------------------------------------- S = evalin(context, 'whos'); evalin(context, '[];'); % clear 'ans' for i = 1:numel(S) obj = evalin(context, S(i).name); [newobj, flag] = symreplace(obj, xstr, newx); if flag, assignin(context, S(i).name, newobj); end end % --------------------------------------------- return elseif (isa (x, 'sym') && (nargin >= 2)) % support sym(x, assumption) for existing sym x s = sym(x.flat, varargin{:}); return elseif (isa (x, 'char')) asm = []; if (nargin == 2 && isequal(size(varargin{1}), [1 2])) s = make_sym_matrix(x, varargin{1}); return elseif (nargin >= 2) % assume the remaining inputs are assumptions asm = varargin; end doDecimalCheck = true; % preprocess if (strcmpi(x, 'inf')) || (strcmpi(x, '+inf')) x = 'oo'; elseif (strcmpi(x, '-inf')) x = '-oo'; elseif (strcmpi(x, 'i')) x = 'I'; elseif (strcmpi(x, '-i')) x = '-I'; elseif (strcmpi(x, 'nan')) x = 'nan'; elseif (strcmp(x, 'lambda')) x = 'lamda'; elseif (strcmp(x, 'Lambda')) x = 'Lamda'; end % Decide whether to pass to S() or Symbol() if (any(strcmp(x, {'pi', 'I', 'oo', 'zoo', 'nan'}))) useSymbolNotS = false; elseif (regexp(x, '^-?\d*\.?\d*(e-?\d+)?$')) % Numbers: integers and floats useSymbolNotS = false; elseif (regexp(x, '^\w+$')) % Words. Note must follow numbers case. % Use Symbol instead of S, e.g., for Issue #23: % strcmp(x, {'beta' 'gamma' 'zeta' 'Chi' 'E' 'E1' 'Ei' 'S' 'N' 'Q'}) % But we also expect sym('Eq') to work, so match all single words useSymbolNotS = true; elseif (~isempty (strfind (x, '(') )) % SymPy "srepr" or other raw python code useSymbolNotS = false; doDecimalCheck = false; else % Other non-symbols such as sym('1/3') useSymbolNotS = false; end if (~useSymbolNotS) % Use S(), as we're not forcing Symbol() assert (isempty (asm)) % sym('pi', 'integer') if (doDecimalCheck && ~isempty(strfind(x, '.'))) warning('possibly unintended decimal point in constructor string'); end % x is raw sympy, could have various quotes in it cmd = sprintf('z = sympy.S("%s")', strrep(x, '"', '\"')); else % useSymbolNotS if (isempty(asm)) cmd = sprintf('z = sympy.Symbol("%s")', x); elseif (isscalar(asm) && isscalar(asm{1}) && isstruct(asm{1})) % we have an assumptions dict cmd = sprintf('return sympy.Symbol("%s", **_ins[0]),', x); s = python_cmd (cmd, asm{1}); return elseif (iscell(asm)) valid_asm = assumptions('possible'); for n=1:length(asm) assert(ischar(asm{n}), 'sym: assumption must be a string') assert(ismember(asm{n}, valid_asm), ... 'sym: that assumption is not supported') end cmd = ['z = sympy.Symbol("' x '"' ... sprintf(', %s=True', asm{:}) ')']; else error('sym: invalid extra input, perhaps invalid assumptions?'); end end % useSymbolNotS else x class(x) nargin error('conversion to symbolic with those arguments not (yet) supported'); end s = python_cmd ({cmd 'return z,'}); end %!test %! % integers %! x = sym('2'); %! y = sym(2); %! assert (isa(x, 'sym')) %! assert (isa(y, 'sym')) %! assert (isequal(x, y)) %!test %! % infinity %! for x = {'inf', '-inf', inf, -inf, 'Inf'} %! y = sym(x{1}); %! assert (isa(y, 'sym')) %! assert (isinf(double(y))) %! assert (isinf(y)) %! end %!test %! % pi %! x = sym('pi'); %! assert (isa (x, 'sym')) %! assert (isequal (sin(x), sym(0))) %! assert (abs(double(x) - pi) < 2*eps ) %! x = sym(pi); %! assert ( isa (x, 'sym')) %! assert ( isequal (sin(x), sym(0))) %! assert ( abs(double(x) - pi) < 2*eps ) %!test %! % rationals %! x = sym(1) / 3; %! assert (isa (x, 'sym')) %! assert (isequal (3*x - 1, sym(0))) %! x = 1 / sym(3); %! assert (isa (x, 'sym')) %! assert (isequal (3*x - 1, sym(0))) %! x = sym('1/3'); %! assert (isa (x, 'sym')) %! assert (isequal (3*x - 1, sym(0))) %!test %! % passing small rationals %! x = sym('1/2'); %! assert( double(x) == 1/2 ) %! assert( isequal( 2*x, sym(1))) %!warning x = sym(1/2); %!test %! % passing small rationals w/o quotes: despite the warning, %! % it should work %! s = warning ('off', 'OctSymPy:sym:rationalapprox'); %! x = sym(1/2); %! warning (s) %! assert( double(x) == 1/2 ) %! assert( isequal( 2*x, sym(1))) %!test %! assert (isa (sym (pi), 'sym')) %! assert (isa (sym ('beta'), 'sym')) %!test %! % sym from array %! D = [0 1; 2 3]; %! A = [sym(0) 1; sym(2) 3]; %! assert (isa (sym(D), 'sym')) %! assert (isequal ( size(sym(D)) , size(D) )) %! assert (isequal ( sym(D) , A )) %!test %! % more sym from array %! syms x %! A = [x x]; %! assert (isequal ( sym(A), A )) %! A = [1 x]; %! assert (isequal ( sym(A), A )) %!test %! % Cell array lists to syms %! % (these tests are pretty weak, doens't recursively compare two %! % cells, but just running this is a good test. %! x = sym('x'); %! %! a = {1 2}; %! s = sym(a); %! assert (isequal( size(a), size(s) )) %! %! a = {1 2 {3 4}}; %! s = sym(a); %! assert (isequal( size(a), size(s) )) %! %! a = {1 2; 3 4}; %! s = sym(a); %! assert (isequal( size(a), size(s) )) %! %! a = {1 2; 3 {4}}; %! s = sym(a); %! assert (isequal( size(a), size(s) )) %! %! a = {1 [1 2] x [sym(pi) x]}; %! s = sym(a); %! assert (isequal( size(a), size(s) )) %! assert (isequal( size(a{2}), size(s{2}) )) %! assert (isequal( size(a{4}), size(s{4}) )) %! %! a = {{{[1 2; 3 4]}}}; %! s = sym(a); %! assert (isequal( size(a), size(s) )) %! assert (isequal( size(a{1}), size(s{1}) )) %! assert (isequal( size(a{1}{1}), size(s{1}{1}) )) %! assert (isequal( size(a{1}{1}{1}), size(s{1}{1}{1}) )) %!test %! %% assumptions and clearing them %! clear % for matlab test script %! x = sym('x', 'real'); %! f = {x {2*x}}; %! asm = assumptions(); %! assert ( ~isempty(asm)) %! x = sym('x', 'clear'); %! asm = assumptions(); %! assert ( isempty(asm)) %!test %! %% matlab compat, syms x clear should add x to workspace %! x = sym('x', 'real'); %! f = 2*x; %! clear x %! assert (~logical(exist('x', 'var'))) %! x = sym('x', 'clear'); %! assert (logical(exist('x', 'var'))) %!test %! %% assumptions should work if x is already a sym %! x = sym('x'); %! x = sym(x, 'real'); %! assert (~isempty(assumptions(x))) %!test %! %% likewise for clear %! x = sym('x', 'real'); %! f = 2*x; %! x = sym(x, 'clear'); %! assert (isempty(assumptions(x))) %! assert (isempty(assumptions(f))) %!test %! % bool %! t = sym(false); %! t = sym(true); %! assert (logical (t)) %!test %! % bool vec/mat %! a = sym(1); %! t = sym([true false]); %! assert (isequal (t, [a==1 a==0])) %! t = sym([true false; false true]); %! assert (isequal (t, [a==1 a==0; a==0 a==1])) %!test %! % symbolic matrix %! A = sym('A', [2 3]); %! assert (isa (A, 'sym')) %! assert (isequal (size (A), [2 3])) %! A(1, 1) = 7; %! assert (isa (A, 'sym')) %! A = A + 1; %! assert (isa (A, 'sym')) %!xtest %! % symbolic matrix, subs in for size %! % FIXME: will fail until we return non-1x1 size for MatrixSymbols %! syms n m integer %! A = sym('A', [n m]); %! B = subs(A, [n m], [5 6]); %! assert (isa (B, 'sym')) %! assert (isequal (size (B), [5 6])) %!test %! % 50 shapes of empty %! a = sym(ones(0, 3)); %! assert (isa (a, 'sym')) %! assert (isequal (size (a), [0 3])) %! a = sym(ones(2, 0)); %! assert (isequal (size (a), [2 0])) %! a = sym([]); %! assert (isequal (size (a), [0 0])) %!test %! % moar empty %! a = sym('a', [0 3]); %! assert (isa (a, 'sym')) %! assert (isequal (size (a), [0 3])) %! a = sym('a', [2 0]); %! assert (isa (a, 'sym')) %! assert (isequal (size (a), [2 0])) %!test %! % embedded sympy commands, various quotes, issue #143 %! a = sym('a'); %! a1 = sym('Symbol("a")'); %! a2 = sym('Symbol(''a'')'); %! assert (isequal (a, a1)) %! assert (isequal (a, a2)) %! % Octave only, and eval to hide from Matlab parser %! if exist('octave_config_info', 'builtin') %! eval( 'a3 = sym("Symbol(''a'')");' ); %! eval( 'a4 = sym("Symbol(\"a\")");' ); %! assert (isequal (a, a3)) %! assert (isequal (a, a4)) %! end %!test %! % doubles bigger than int32 INTMAX should not fail %! d = 4294967295; %! a = sym(d); %! assert (isequal (double(a), d)) %! d = d + 123456; %! a = sym(d); %! assert (isequal (double(a), d)) %!test %! % int32 integer types %! a = sym(100); %! b = sym(int32(100)); %! assert (isequal (a, b)) %!test %! % int32 MAXINT integers %! a = sym('2147483647'); %! b = sym(int32(2147483647)); %! assert (isequal (a, b)) %! a = sym('-2147483647'); %! b = sym(int32(-2147483647)); %! assert (isequal (a, b)) %! a = sym('4294967295'); %! b = sym(uint32(4294967295)); %! assert (isequal (a, b)) %!test %! % int64 integer types %! a = sym('123456789012345'); %! b = sym(int64(123456789012345)); %! c = sym(uint64(123456789012345)); %! assert (isequal (a, b)) %! assert (isequal (a, c)) %!test %! % integer arrays %! a = int64([1 2 100]); %! s = sym(a); %! assert (isequal (double(a), [1 2 100])) %!xtest %! % bigger int64 integer types: TODO: passes on Octave 4? %! q = int64(123456789012345); %! w = 10000*q + 123; %! a = sym('1234567890123450123'); %! b = sym(w); %! assert (isequal (a, b)) %!test %! % sym(double) heuristic %! s = warning ('off', 'OctSymPy:sym:rationalapprox'); %! x = sym(2*pi/3); %! assert (isequal (x/sym(pi), sym(2)/3)) %! x = sym(22*pi); %! assert (isequal (x/sym(pi), sym(22))) %! x = sym(pi/123); %! assert (isequal (x/sym(pi), sym(1)/123)) %! warning (s) %!test %! % symbols with special sympy names %! syms Ei Eq %! assert (regexp(char(Eq), '^Symbol')) %! assert (regexp(char(Ei), '^Symbol')) %!test %! % E can be a sym not just exp(sym(1)) %! syms E %! assert (~logical (E == exp(sym(1)))) %!error %! x = sym('x', 'positive2'); %!error %! x = sym('x', 'integer', 'positive2'); %!error %! x = sym('x', 'integer2', 'positive'); %!error %! x = sym('-pi', 'positive') %!error %! x = sym('pi', 'integer') %!xtest %! % multiple assumptions %! % FIXME: xtest for sympy <= 0.7.6.x where a is the full dict %! n = sym('n', 'negative', 'even'); %! a = assumptions(n); %! assert(strcmp(a, 'n: negative, even') || strcmp(a, 'n: even, negative')) %! % FIXME: slightly obtuse testing b/c 0.7.6 but still fails on 0.7.5 %! assert (isequal (n > 0, sym(false))) %! assert (isequal (n == -1, sym(false))) symbolic-2.2.4/inst/@sym/isAlways.m0000644000175000001440000002123612633614672015675 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{r} =} isAlways (@var{eq}) %% @deftypefnx {Function File} {@var{r} =} isAlways (@var{eq}, 'Unknown', 'false') %% @deftypefnx {Function File} {@var{r} =} isAlways (@var{eq}, 'Unknown', 'true') %% @deftypefnx {Function File} {@var{r} =} isAlways (@var{eq}, 'Unknown', 'error') %% Test if expression is mathematically true. %% %% Example: %% @example %% @group %% >> syms x y %% >> isAlways(x*(1+y) == x+x*y) %% @result{} 1 %% @end group %% @end example %% Contrast this with a test for “structural equality“: %% @example %% @group %% >> logical(x*(1+y) == x+x*y) %% @result{} 0 %% @end group %% @end example %% %% The optional keyword argument 'Unknown' specifies that happens %% for expressions that cannot simplify. By default these return %% false (that is, cannot verify it is always true). Pass the %% strings 'true', 'false' or 'error' to change the behaviour. You %% can also pass logical true/false. %% %% If @code{isAlways} is called on expressions without relationals, %% it will return true for non-zero numbers: %% @example %% @group %% >> isAlways (sym (10)) %% @result{} 1 %% @end group %% @end example %% %% It is safe to use isAlways even when the expression does not %% require simplifying: %% @example %% >> syms x %% >> isAlways (sin(x) - sin(x) == 0) %% @result{} 1 %% @end example %% In practice, @code{isAlways} might get called on a simple %% boolean variable, so OctSymPy implements @@logical/isAlways %% (which is essentially a no-op). %% %% @seealso{logical, isequal, eq (==)} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = isAlways(p, varargin) assert((nargin == 1) || (nargin == 3)) if (nargin == 3) assert(strcmpi(varargin{1}, 'unknown')) cant = varargin{2}; if islogical(cant) % SMT doesn't allow nonstring but it seems reasonable elseif strcmpi(cant, 'true') cant = true; elseif strcmpi(cant, 'false') cant = false; elseif strcmpi(cant, 'error') % no-op else error('isAlways: invalid argument for "unknown" keyword') end else cant = false; end cmd = { 'def simplify_tfn(p):' ' if p in (S.true, S.false):' ' return bool(p)' ' r = simplify(p)' ' #FIXME; Boolean, simplify more than once?' ' if r in (S.true, S.false):' ' return bool(r)' ' # FIXME: hopefully we get sympy patched for some of this' ' #ver = sympy.__version__' ' #if ver == "0.7.5" or ver.startswith("0.7.6") or ver.startswith("0.7.7"):' ' if True:' ' if isinstance(p, Equality):' ' r = Eq(sp.simplify(p.lhs - p.rhs), 0)' ' r = simplify(r)' ' if r in (S.true, S.false):' ' return bool(r)' ' if isinstance(p, Unequality):' ' r = Eq(sp.simplify(p.lhs - p.rhs), 0)' ' r = simplify(r)' ' if r in (S.true, S.false):' ' return not bool(r)' ' if isinstance(p, (Lt, Gt, Le, Ge)):' ' r = p._eval_relation(sp.simplify(p.lhs - p.rhs), 0)' ' r = simplify(r)' ' if r in (S.true, S.false):' ' return not bool(r)' ' # for SMT compat' ' if p.is_number:' ' r = p.is_zero' % FIXME: return bool(r)? ' if r in (S.true, S.false):' ' return not bool(r)' ' return None' }; % could distinguish b/w None and return a string for this last case cmd = vertcat(cmd, { '(x, unknown) = _ins' 'if x.is_Matrix:' ' r = [a for a in x.T]' % note transpose 'else:' ' r = [x,]' 'r = [simplify_tfn(a) for a in r]' 'r = [unknown if a is None else a for a in r]' 'flag = True' 'if r.count("error") > 0:' ' flag = False' ' r = "cannot reliably convert sym to bool"' 'return (flag, r)' }); [flag, r] = python_cmd (cmd, p, cant); if (~flag) assert (ischar (r), 'isAlways: programming error?') error(['isAlways: ' r]) end r = cell2mat(r); r = reshape(r, size(p)); end %!test %! % basics %! assert(isAlways(true)) %! assert(isAlways(1==1)) %! assert(isAlways(sym(1)==sym(1))) %! assert(isAlways(sym(1)==1)) %!test %! % numbers to logic? %! assert (isAlways(sym(1))) %! assert (isAlways(sym(-1))) %! assert (~isAlways(sym(0))) %!shared x %! syms x %!test %! % in this case it is boolean %! expr = x - x == 0; %! assert (logical(expr)) %! assert (isAlways(expr)) %! % and both are logical type %! assert (islogical(logical(expr))) %! assert (islogical(isAlways(expr))) %!test %! % structurally same and mathematically true %! % (here expr should be sym, non-boolean) %! expr = x == x; %! assert (logical(expr)) %! assert (isAlways(expr)) %! %assert (~islogical(expr)) % FIXME: Issue #56 %! %assert (isa(expr, 'sym)) %!test %! % structurally same and mathematically true %! % (here expr should be sym, non-boolean) %! expr = 1 + x == x + 1; %! assert (logical(expr)) %! assert (isAlways(expr)) %!test %! % non-zero numbers are true %! assert (isAlways(sym(1))) %! assert (isAlways(sym(-10))) %! assert (~isAlways(sym(0))) % FIXME: should we support implicit == 0 like sympy? SMT does oppositve, plus it ignores assumptions? SMT behaviour is probably meant to mimic matlab doubles, %expr = x - x; %c=c+1; r(c) = logical(expr); %c=c+1; r(c) = isAlways(expr); %!shared x, y %! syms x y %!test %! % structurally same and mathematically true %! % (here expr should be sym, non-boolean) %! expr = x*(1+y) == x*(y+1); %! assert (logical(expr)) %! assert (isAlways(expr)) %! assert (islogical(isAlways(expr))) %!test %! % Now for some differences %! % simplest example from SymPy FAQ %! expr = x*(1+y) == x+x*y; %! assert (~logical(expr)) %! assert (isAlways(expr)) %!test %! % more differences 1, these don't simplify in sympy 0.7.5 %! expr = (x+1)^2 == x*x + 2*x + 1; %! assert (~logical(expr)) %! assert (isAlways(expr)) %!test %! % more differences 2 %! expr = sin(2*x) == 2*sin(x)*cos(x); %! assert (~logical(expr)) %! assert (isAlways(expr)) %!test %! % more differences 3, false %! expr = x*(x+y) == x^2 + x*y + 1; %! assert (~logical(expr)) %! assert (~isAlways(expr)) %! assert (~isAlways(expr, 'unknown', 'error')) %!test %! % logically not equal, math equal %! exprn = x*(x+y) ~= x^2 + x*y; %! assert (logical(exprn)) %! assert (~isAlways(exprn)) %!test %! % logically not equal, math not equal %! exprn = x*(x+y) ~= x^2 + x*y + 1; %! assert (logical(exprn)) %! assert (isAlways(exprn)) %!test %! % equal and not equal %! e1 = sin(x)^2 + cos(x)^2 == 1; %! e2 = sin(x)^2 + cos(x)^2 == 2; %! assert (~logical(e1)) %! assert (isAlways(e1)) %! assert (~logical(e2)) %! assert (~isAlways(e2)) %! assert (~isAlways(e2, 'unknown', 'error')) %!error isAlways(x, 'unknown', 'kevin') %!error isAlways(x, 'unknown') %!error isAlways(x, 'kevin', 'true') %!error %! a = [x*(x+y)==x^2+x*y x==y]; %! b = isAlways(a, 'unknown', 'error'); %!error %! a = x==y; %! b = isAlways(a, 'unknown', 'error'); %!test %! % array, unknown keyword %! a = [x==x x==x+1 x==y x*(x+y)==x^2+x*y cos(x)^2+sin(x)^2==2]; %! b = isAlways(a, 'unknown', false); %! c = isAlways(a, 'unknown', 'false'); %! expect = [true false false true false]; %! assert (islogical(b)) %! assert (isequal (b, expect)) %! assert (isequal (c, expect)) %! b = isAlways(a, 'unknown', true); %! c = isAlways(a, 'unknown', 'true'); %! expect = [true false true true false]; %! assert (islogical(b)) %! assert (isequal (b, expect)) %! assert (isequal (c, expect)) %!test %! % ineq %! e = x*(x+y) >= x^2 + x*y + 1; %! assert (~logical(e)) %! assert (isAlways(e)) %! e = x*(x+y) <= x^2 + x*y; %! assert (~logical(e)) %! assert (isAlways(e)) %test % % FIXME; booleans % e1 = x*(x+1) == x*x+x % e2 = x*(x+1)+2 == x*x+x+2 % b = e1 & e2 % assert isAlways(b) symbolic-2.2.4/inst/@sym/triu.m0000644000175000001440000000426312633614672015065 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{U} =} triu (@var{A}) %% @deftypefnx {Function File} {@var{U} =} triu (@var{A}, @var{k}) %% Upper triangular part of a symbolic matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function U = triu(A,k) if (nargin == 1) k = 0; end if ~(isa(A, 'sym')) % k was a sym U = triu(A, double(k)); return end cmd = { '(A,k) = _ins' 'if A.is_Matrix:' ' (n,m) = A.shape' ' for c in range(0,m):' ' for r in range(max(0,1+c-k),n):' ' A[r,c] = 0' ' return A,' 'elif k == 0:' ' return A,' 'else:' ' return sp.S(0),' }; U = python_cmd (cmd, A, int32(double(k))); end %!test %! % scalar %! syms x %! assert (isequal (triu(x), x)) %! assert (isequal (triu(x,0), x)) %! assert (isequal (triu(x,1), 0)) %! assert (isequal (triu(x,-1), 0)) %!test %! % with symbols %! syms x %! A = [x 2*x; 3*x 4*x]; %! assert (isequal (triu(A), [x 2*x; 0 4*x])) %!test %! % diagonal shifts %! B = round(10*rand(3,4)); %! A = sym(B); %! assert (isequal (triu(A), triu(B))) %! assert (isequal (triu(A,0), triu(B,0))) %! assert (isequal (triu(A,1), triu(B,1))) %! assert (isequal (triu(A,-1), triu(B,-1))) %!test %! % double array pass through %! B = round(10*rand(3,4)); %! assert (isequal (triu(B,sym(1)), triu(B,1))) %! assert (isa (triu(B,sym(1)), 'double')) symbolic-2.2.4/inst/@sym/nextprime.m0000644000175000001440000000262612633614672016116 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} nextprime (@var{x}) %% Symbolic nextprime function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = nextprime(x) y = uniop_helper (x, 'nextprime'); end %!shared x, d %! d = 123; %! x = sym('123'); %!test %! f1 = nextprime(x); %! f2 = 127; %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = nextprime(A); %! f2 = 127; %! f2 = [f2 f2; f2 f2]; %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/symprod.m0000644000175000001440000001140612633614672015574 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} symprod (@var{f}, @var{n}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{y} =} symprod (@var{f}, @var{n}, [@var{a} @var{b}]) %% @deftypefnx {Function File} {@var{y} =} symprod (@var{f}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{y} =} symprod (@var{f}, [@var{a} @var{b}]) %% @deftypefnx {Function File} {@var{y} =} symprod (@var{f}, @var{n}) %% @deftypefnx {Function File} {@var{y} =} symprod (@var{f}) %% Symbolic product. %% %% The product of the expression @var{f} as variable @var{n} changes %% from @var{a} to @var{b}. When @var{n} is omitted it is determined %% using @code{symvar} and defaults to @code{x} if @var{f} is %% constant. The limits @var{a} and @var{b} default to @code{1} and %% @var{n} respectively. %% %% Examples: %% @example %% @group %% syms n m x %% symprod(sin(n*x), n, [1 3]) %% @result{} (sym) sin(x)⋅sin(2⋅x)⋅sin(3⋅x) %% symprod(n, n, 1, m) %% @result{} (sym) m! %% @end group %% @end example %% %% Unevaluated product: %% @example %% @group %% syms x m %% symprod(sin(x), x, [1 m]) %% @result{} (sym) %% m %% ┬───┬ %% │ │ sin(x) %% │ │ %% x = 1 %% @end group %% @end example %% %% @seealso{symsum, prod} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function S = symprod(f, n, a, b) idx1.type = '()'; idx1.subs = {1}; idx2.type = '()'; idx2.subs = {2}; if (nargin == 1) n = symvar(f, 1); if (isempty(n)) n = sym('x'); end a = sym(1); b = n; elseif (nargin == 2) && (length(n) == 2) f = sym(f); %a = n(1); % issue #17 %b = n(2); a = subsref(n, idx1); b = subsref(n, idx2); n = symvar(f, 1); if (isempty(n)) n = sym('x'); end elseif (nargin == 2) f = sym(f); n = sym(n); a = sym(1); b = n; elseif (nargin == 3) && (length(a) == 2) f = sym(f); n = sym(n); %b = a(2); % issue #17 %a = a(1); b = subsref(a, idx2); a = subsref(a, idx1); elseif (nargin == 3) f = sym(f); b = a; a = n; n = symvar(f, 1); if (isempty(n)) n = sym('x'); end else f = sym(f); n = sym(n); a = sym(a); b = sym(b); end cmd = { '(f, n, a, b) = _ins' 'S = sp.product(f, (n, a, b))' 'return S,' }; S = python_cmd (cmd, sym(f), sym(n), sym(a), sym(b)); end %!test %! % simple %! syms n %! assert (isequal (symprod(n, n, 1, 10), factorial(sym(10)))) %! assert (isequal (symprod(n, n, sym(1), sym(10)), factorial(10))) %!test %! % one input %! syms n %! f = symprod (n); %! g = factorial (n); %! assert (isequal (f, g)) %! f = symprod (2*n); %! g = 2^n * factorial (n); %! assert (isequal (f, g)) %!test %! % constant input %! f = symprod (sym(2)); %! syms x %! g = 2^x; %! assert (isequal (f, g)) %!test %! % two inputs %! syms n %! f = symprod (2*n, n); %! g = 2^n * factorial (n); %! assert (isequal (f, g)) %!test %! % two inputs, second is range %! syms n %! f = symprod (n, [1 6]); %! g = 720; %! assert (isequal (f, g)) %! f = symprod (n, [sym(1) 6]); %! g = 720; %! assert (isequal (f, g)) %! f = symprod (2*n, [1 6]); %! g = sym(2)^6*720; %! assert (isequal (f, g)) %!test %! % three inputs, last is range %! syms n %! f = symprod (2*n, n, [1 4]); %! g = sym(384); %! assert (isequal (f, g)) %! f = symprod (2*n, n, [sym(1) 4]); %! g = sym(384); %! assert (isequal (f, g)) %! f = symprod (2, n, [sym(1) 4]); %! g = sym(16); %! assert (isequal (f, g)) %!test %! % three inputs, no range %! syms n %! f = symprod (2*n, 1, 4); %! g = sym(384); %! assert (isequal (f, g)) %! f = symprod (5, sym(1), 3); %! g = sym(125); %! assert (isequal (f, g)) %!test %! % infinite product %! syms a n oo %! zoo = sym('zoo'); %! assert (isequal (symprod(a, n, 1, oo), a^oo)) %! assert (isequal (symprod(a, n, 1, inf), a^oo)) %%!test %%! % FIXME: commented out test... %%! % SymPy 0.7.6: nan %%! % SymPy git: interesting that 1**oo is nan but this is still 1 %%! assert (isequal (symprod(1, n, 1, oo), sym(1))) symbolic-2.2.4/inst/@sym/isconstant.m0000644000175000001440000000301012633614672016254 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} isconstant (@var{x}) %% Indicate which elements of symbolic array are constant. %% %% @seealso{isallconstant, symvar, findsymbols} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = isconstant(x) cmd = { '(x,) = _ins' 'if x.is_Matrix:' ' return x.applyfunc(lambda a: a.is_constant()),' 'else:' ' return x.is_constant(),' }; z = python_cmd (cmd, sym(x)); % Issue #27: Matrix of bools not converted to logical z = logical(z); end %!test %! syms x %! A = [x 2 3]; %! B = [false true true]; %! assert (isequal (isconstant(A), B)) %!test %! syms x %! A = [x 2; 3 x]; %! B = [false true; true false]; %! assert (isequal (isconstant(A), B)) symbolic-2.2.4/inst/@sym/ismatrix.m0000644000175000001440000000251112633614672015734 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{b} =} ismatrix (@var{x}) %% Return true if this symbolic expression is a matrix. %% %% That is, a 2D array including scalar and empty matrices. %% %% @seealso{isscalar, isvector, size} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function b = ismatrix(x) b = (length(size(x)) == 2); end %!assert(ismatrix(sym('x'))) %!assert(ismatrix(sym([1 2 3]))) %!assert(ismatrix(sym([1; 2]))) %!assert(ismatrix(sym([1 2; 3 4]))) %!assert(ismatrix(sym([]))) %!assert(ismatrix(sym(ones(1,0)))) %!assert(ismatrix(sym(ones(0,3)))) symbolic-2.2.4/inst/@sym/function_handle.m0000644000175000001440000002456612633614672017252 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{g} =} function_handle (@var{f}) %% @deftypefnx {Function File} {@var{g} =} function_handle (@var{f1}, @dots{}, @var{fn}) %% @deftypefnx {Function File} {@var{g} =} function_handle (@dots{}, @var{param}, @var{value}) %% @deftypefnx {Function File} {@var{g} =} function_handle (@dots{}, 'vars', [@var{x} @dots{} @var{z}]) %% @deftypefnx {Function File} {@dots{}} function_handle (@dots{}, 'file', @var{filename}) %% @deftypefnx {Function File} {@dots{}} function_handle (@dots{}, 'outputs', [@var{o1} @dots{} @var{on}]) %% Convert symbolic expression into a standard function. %% %% This can make anonymous functions from symbolic expressions: %% @example %% @group %% >> syms x y %% >> f = x^2 + sin(y) %% @result{} f = (sym) %% 2 %% x + sin(y) %% >> h = function_handle(f) %% @result{} h = %% @@(x, y) x .^ 2 + sin (y) %% @end group %% @end example %% %% Multiple arguments correspond to multiple outputs of the %% function. For example, the final @code{x} in this example %% specifies the third output (rather than the input): %% @example %% @group %% >> h = function_handle(x^2, 5*x, x); %% >> [a, b, c] = h(2) %% @result{} a = 4 %% @result{} b = 10 %% @result{} c = 2 %% @end group %% @end example %% %% The order and number of inputs can be specified: %% @example %% @group %% >> syms x y z %% >> h = function_handle(f, 'vars', [z y x]) %% @result{} h = %% @@(z, y, x) x .^ 2 + sin (y) %% @end group %% @end example %% %% For compatibility with the Symbolic Math Toolbox in Matlab, we %% provide a synonym: @xref{matlabFunction} %% %% OctSymPy can also generate an @code{.m} file from a symbolic %% expression by passing the keyword @code{file} with a string %% argument for @var{filename}. A handle to the function in the %% file will be returned. %% Passing an empty @var{filename} creates an anonymous function: %% @example %% @group %% >> h = function_handle(f, 'file', '') %% @result{} h = %% @@(x, y) x .^ 2 + sin (y) %% @end group %% @end example %% %% FIXME: naming outputs with @var{PARAM} as %% @code{outputs} not implemented. %% %% FIXME: does not ``optimize'' code, for example, using common %% subexpression elimination. %% %% The routine relies on code generation features added to SymPy %% 0.7.6. On earlier versions, the workaround only works for %% very simple expressions such as polynomials and trig functions. %% %% @seealso{ccode, fortran, latex, matlabFunction} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function f = function_handle(varargin) [flg, meh] = codegen(varargin{:}, 'lang', 'octave'); assert(flg == -1); [Nin, inputs, inputstr, Nout, param] = deal(meh{:}); %% Outputs if (param.codegen) && (~isempty(param.fname)) cmd = { '(expr,fcnname,filename,showhdr,in_vars) = _ins' ... 'from sympy.utilities.codegen import codegen' ... 'try:' ... [' out = codegen((fcnname,expr), "' param.lang ... '", filename, header=showhdr' ... ', argument_sequence=in_vars)'] ... 'except ValueError as e:' ... ' return (False, str(e))' ... 'return (True, out)' }; % if filename ends with .m, do not add another if strcmpi(param.fname(end-1:end), '.m') param.fname = param.fname(1:end-2); end fname2 = param.fname; fcnname = param.fname; % was old note about findsymbols vs symvar: not relevant [worked, out] = python_cmd (cmd, varargin(1:Nout), fcnname, fname2, param.show_header, inputs); if (~worked) if (strcmp(out, 'Language ''octave'' is not supported.')) error('function_handle: your SymPy has no octave codegen, cannot workaround'); else ou error('function_handle: Some other error from SymPy code gen? file a bug!'); end end M.name = out{1}{1}; M.code = out{1}{2}; [fid,msg] = fopen(M.name, 'w'); assert(fid > -1, msg) fprintf(fid, '%s', M.code) fclose(fid); fprintf('Wrote file %s.\n', M.name); f = str2func(fcnname); else % output function handle exprstrs = {}; for i=1:Nout expr = varargin{i}; cmd = { '(f,) = _ins' ... 'try:' ... ' a, b, s = octave_code(f, human=False)' ... 'except NameError as e:' ... ' return (False, str(e))' ... 'if len(b) != 0:' ... ' return (False, s)' ... 'if len(a) != 0:' ... ' return (False, "expected symbols-to-declare to be empty")' ... 'return (True, s)' }; [worked, codestr] = python_cmd (cmd, expr); %worked = false; if (worked) codestr = vectorize(codestr); else %% SymPy 0.7.5 has no octave_code command % Use a crude workaround (e.g., Abs, ceiling will fail). if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=75 ... && strcmp(codestr, 'global name ''octave_code'' is not defined')) warning('OctSymPy:function_handle:nocodegen', ... 'function_handle: your SymPy has no octave codegen: partial workaround'); codestr = expr.flat; % Matlab: ** to ^ substition. On Octave, vectorize does this codestr = strrep(codestr, '**', '^'); codestr = vectorize(codestr); else error('function_handle: python codegen failed: %s', codestr) end end exprstr{i} = codestr; end if (Nout == 1) f = eval(sprintf('@(%s) %s', inputstr, exprstr{1})); else str = [ sprintf('@(%s) deal(', inputstr) ... sprintf('%s,', exprstr{:})]; str = [str(1:end-1) ')']; f = eval(str); end end % Note: this fails in Matlab SMT too: %h = function_handle({x,y,z},'vars',{x y z}) % (could fix by moving it outside @sym) end %!shared x,y,z %! syms x y z %!test %! % basic test %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = function_handle(2*x); %! warning(s) %! assert(isa(h, 'function_handle')) %! assert(h(3)==6) %!test %! % autodetect inputs %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = function_handle(2*x*y, x+y); %! warning(s) %! [t1, t2] = h(3,5); %! assert(t1 == 30 && t2 == 8) %!test %! % specified inputs %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = function_handle(2*x*y, 'vars', [x y]); %! assert(h(3,5)==30) %! h = function_handle(2*x*y, x+y, 'vars', [x y]); %! warning(s) %! [t1, t2] = h(3,5); %! assert(t1 == 30 && t2 == 8) %!test %! % cell arrays for vars list %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = function_handle(2*x*y, x+y, 'vars', {x y}); %! [t1, t2] = h(3,5); %! assert(t1 == 30 && t2 == 8) %! h = function_handle(2*x*y, x+y, 'vars', {'x' 'y'}); %! warning(s) %! [t1, t2] = h(3,5); %! assert(t1 == 30 && t2 == 8) %!test %! % cell arrays specfies order, overriding symvar order %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = function_handle(x*y, 12/y, 'vars', {y x}); %! [t1, t2] = h(3, 6); %! assert(t1 == 18 && t2 == 4) %! h = function_handle(x*y, 12/y, 'vars', [y x]); %! warning(s) %! [t1, t2] = h(3, 6); %! assert(t1 == 18 && t2 == 4) %!test %! % cell arrays specfies order, overriding symvar order %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = function_handle(x*y, 12/y, 'vars', {y x}); %! [t1, t2] = h(3, 6); %! assert(t1 == 18 && t2 == 4) %! h = function_handle(x*y, 12/y, 'vars', [y x]); %! warning(s) %! [t1, t2] = h(3, 6); %! assert(t1 == 18 && t2 == 4) %!xtest %! % Functions with different names in Sympy. %! % (will fail unless Sympy has Octave codegen) %! f = abs(x); % becomes Abs(x) %! h = function_handle(f); %! assert(h(-10) == 10) %! f = ceil(x); %! h = function_handle(f); %! assert(h(10.1) == 11) %!test %! % 'file' with empty filename returns handle %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = function_handle(2*x*y, 'file', ''); %! assert(isa(h, 'function_handle')) %! assert(h(3,5)==30) %! h = function_handle(2*x*y, 'vars', {x y}, 'file', ''); %! warning(s) %! assert(isa(h, 'function_handle')) %! assert(h(3,5)==30) %!xtest %! % output to disk %! % (will fail unless Sympy has Octave codegen) %! f = function_handle(2*x*y, 2^x, 'vars', {x y z}, 'file', 'temp_test_output1'); %! assert( isa(f, 'function_handle')) %! [a,b] = f(10,20,30); %! assert (isnumeric (a) && isnumeric (b)) %! assert (a == 400) %! assert (b == 1024) %! delete('temp_test_output1.m') %!xtest %! % output to disk: also works with .m specified %! % (will fail unless Sympy has Octave codegen) %! f = function_handle(2*x*y, 2^x, 'vars', {x y z}, 'file', 'temp_test_output2.m'); %! assert( isa(f, 'function_handle')) %! [a,b] = f(10,20,30); %! assert (isnumeric (a) && isnumeric (b)) %! assert (a == 400) %! assert (b == 1024) %! delete('temp_test_output2.m') %!xtest %! % non-scalar outputs %! % (will fail unless Sympy has Octave codegen) %! H = [x y z]; %! M = [x y; z 16]; %! V = [x;y;z]; %! h = function_handle(H, M, V); %! [t1,t2,t3] = h(1,2,3); %! assert(isequal(t1, [1 2 3])) %! assert(isequal(t2, [1 2; 3 16])) %! assert(isequal(t3, [1;2;3])) %!xtest %! % non-scalar outputs in .m files %! % (will fail unless Sympy has Octave codegen) %! H = [x y z]; %! M = [x y; z 16]; %! V = [x;y;z]; %! h = function_handle(H, M, V, 'vars', {x y z}, 'file', 'temp_test_output3'); %! assert( isa(h, 'function_handle')) %! [t1,t2,t3] = h(1,2,3); %! assert(isequal(t1, [1 2 3])) %! assert(isequal(t2, [1 2; 3 16])) %! assert(isequal(t3, [1;2;3])) %! delete('temp_test_output3.m') %!test %! % order of outputs is lexiographic %! syms a A x y %! f = y + 10*a + 100*x + 1000*A; %! h = function_handle(f); %! assert (h(1, 2, 3, 4) == 1000 + 20 + 300 + 4) symbolic-2.2.4/inst/@sym/rref.m0000644000175000001440000000330312633614672015032 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} rref (@var{A}) %% @deftypefnx {Function File} {[@var{r, k}] =} rref (@var{A}) %% Reduced Row Echelon Form of a symbolic matrix. %% %% Optional second output gives the indices of pivots. %% %% @seealso{rank, null, orth} %% @end deftypefn function [r, k] = rref(A) cmd = { 'A = _ins[0]' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'L = A.rref()' 'K = sp.Matrix([L[1]])' 'return (L[0], K)' }; [r, k] = python_cmd (cmd, A); k = k + 1; end %!test %! A = sym([1 2; 3 4]); %! [r, k] = rref(A); %! assert (isequal (r, eye(2))) %! assert (isequal (k, [1 2])) %!assert (isequal (rref(sym([2 1])), [1 sym(1)/2])) %!assert (isequal (rref(sym([1 2; 2 4])), [1 2; 0 0])) %!assert (isequal (rref(sym([0 0; 2 4])), [1 2; 0 0])) %!test %! A = sym([1 2 3; 2 3 4]); %! [r, k] = rref(A); %! assert (isequal (r, [1 0 -1; 0 1 2])) %! assert (isequal (k, [1 2])); symbolic-2.2.4/inst/@sym/mtimes.m0000644000175000001440000000334212633614672015375 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mtimes (@var{x}, @var{y}) %% Symbolic matrix multiplication (*). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mtimes(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = mtimes(x, y); return end cmd = { '(x,y) = _ins' 'return x*y,' }; z = python_cmd (cmd, sym(x), sym(y)); end %!test %! % scalar %! syms x %! assert (isa (x*2, 'sym')) %! assert (isequal (2*sym(3), sym(6))) %! assert (isequal (sym(2)*3, sym(6))) %!test %! % matrix-scalar %! D = [0 1; 2 3]; %! A = sym(D); %! assert (isa (2*A, 'sym')) %! assert (isequal ( 2*A , 2*D )) %! assert (isequal ( A*2 , 2*D )) %!test %! % matrix-matrix %! D = [0 1; 2 3]; %! A = sym(D); %! assert (isa (A*A, 'sym')) %! assert (isequal ( A*A , D*D )) symbolic-2.2.4/inst/@sym/isempty.m0000644000175000001440000000373212633614672015574 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isempty (@var{x}) %% Return true a symbolic array is empty (one dimension is zero). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = isempty(x) d = size(x); % Octave can have n x 0 and 0 x m empty arrays % logical in case one has symbolic size % r = logical(prod(d) == 0); % safer, in case we use NaN later r = any(logical(d == 0)); end %% Tests %!shared se, a %! se = sym ([]); %! a = sym ([1 2]); %!assert (~isempty (sym (1))) %!assert (isempty (sym (se))) %!assert (isempty (se == [])) %!test % assert (isempty (a([]))) % assert (isempty (a([se]))) %% Growing an empty symfun into a scalar %!test se(1) = 10; %!test assert ( isa (se, 'sym')) %!test assert ( isequal (se, 10)) %!shared %!test %! % empty matrices %! A = sym('A', [3 0]); %! assert (isempty (A)) %! A = sym(ones(3,0)); %! assert (isempty (A)) %!test %! % non-empty symbolic-size matrices %! syms n integer %! A = sym('A', [3 n]); %! assert (~isempty (A)) %!xtest %! % empty symbolic-size matrices %! % FIXME: will fail until size stop lying by saying 1x1 %! syms n integer %! A = sym('A', [0 n]); %! assert (isempty (A)) %! A = sym('A', [n 0]); %! assert (isempty (A)) symbolic-2.2.4/inst/@sym/subs.m0000644000175000001440000001601512633614672015054 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{g} =} subs (@var{f}, @var{x}, @var{y}) %% @deftypefnx {Function File} {@var{g} =} subs (@var{f}, @var{y}) %% Replace symbols in an expression with other expressions. %% %% Example substituting a value for a variable: %% @example %% @group %% >> syms x y %% >> f = x*y; %% >> subs(f, x, 2) %% @result{} ans = (sym) 2⋅y %% @end group %% @end example %% If @var{x} is omitted, @code{symvar} is used on @var{f}. %% %% @var{x} and @var{y} can also be vectors or lists of syms to %% replace: %% @example %% @group %% >> subs(f, @{x y@}, @{sin(x) 16@}) %% @result{} ans = (sym) 16⋅sin(x) %% %% >> F = [x x*y; 2*x*y y]; %% >> subs(F, @{x y@}, [2 sym(pi)]) %% @result{} ans = (sym 2×2 matrix) %% %% ⎡ 2 2⋅π⎤ %% ⎢ ⎥ %% ⎣4⋅π π ⎦ %% %% @end group %% @end example %% %% Note: There are many possibilities that we don't support (FIXME) %% if you start mixing scalars and matrices. We support one simple %% case of subbing a matrix in for a scalar in a scalar expression: %% @example %% @group %% >> f = sin(x); %% >> g = subs(f, x, [1 2; 3 4]) %% @result{} g = (sym 2×2 matrix) %% %% ⎡sin(1) sin(2)⎤ %% ⎢ ⎥ %% ⎣sin(3) sin(4)⎦ %% %% @end group %% @end example %% If you want to extend support to more cases, a good place to %% start, as of July 2014, is the Sympy Issue #2962 %% [https://github.com/sympy/sympy/issues/2962]. %% %% @seealso{symfun} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, substitution function g = subs(f, in, out) if (nargin == 1) % FIXME: SMT will take values of x from the workspace in this case. error('subs: we do not support single-input w/ substitution from workspace') elseif (nargin == 2) out = in; in = symvar(f, 1); if (isempty(in)) in = sym('x'); end end %% special case: scalar f, scalar in, vector out % A workaround for Issue #10, also upstream Sympy Issue @2962 % (github.com/sympy/sympy/issues/2962). There are more complicated % cases that will also fail but this one must be pretty common. if (isscalar(f) && ~iscell(in) && ~iscell(out) && isscalar(in) && ~isscalar(out)) g = sym(out); % a symarray of same size-shape as out, whether % out is sym or double for i = 1:numel(out) % f$#k Issue #17 %g(i) = subs(f, in, sym(out(i))) idx.type = '()'; idx.subs = {i}; temp = subsref(out, idx); temp2 = subs(f, in, temp); g = subsasgn(g, idx, temp2); end return end %% Simple code for scalar x % The more general code would work fine, but maybe this makes some % debugging easier, e.g., without simultaneous mode? if (isscalar(in) && ~iscell(in) && ~iscell(out)) cmd = { '(f, x, y) = _ins' 'return f.subs(x, y).doit(),' }; g = python_cmd (cmd, sym(f), sym(in), sym(out)); return end %% In general % We build a list of of pairs of substitutions. in = sym(in); out = sym(out); if ( (iscell(in)) || (numel(in) >= 2) ) assert_same_shape(in,out) sublist = cell(1, numel(in)); for i = 1:numel(in) % not really Bug #17, but I doubt if I'd have done it this % way w/o that bug. if (iscell(in)), idx1.type = '{}'; else idx1.type = '()'; end if (iscell(out)), idx2.type = '{}'; else idx2.type = '()'; end idx1.subs = {i}; idx2.subs = {i}; sublist{i} = { subsref(in, idx1), subsref(out, idx2) }; end elseif (numel(in) == 1) % scalar, non-cell input assert(~iscell(out)) % out could be an array (although this doesn't work b/c of % Issue #10) sublist = { {in, out} }; else error('not a valid sort of subs input'); end % simultaneous=True is important so we can do subs(f,[x y], [y x]) cmd = { '(f, sublist) = _ins' 'g = f.subs(sublist, simultaneous=True).doit()' 'return g,' }; g = python_cmd (cmd, sym(f), sublist); end %!shared x,y,t,f %! syms x y t %! f = x*y; %!test %! assert( isequal( subs(f, x, y), y^2 )) %! assert( isequal( subs(f, y, sin(x)), x*sin(x) )) %! assert( isequal( subs(f, x, 16), 16*y )) %!test %! % multiple subs w/ cells %! assert( isequal( subs(f, {x}, {t}), y*t )) %! assert( isequal( subs(f, {x y}, {t t}), t*t )) %! assert( isequal( subs(f, {x y}, {t 16}), 16*t )) %! assert( isequal( subs(f, {x y}, {16 t}), 16*t )) %! assert( isequal( subs(f, {x y}, {2 16}), 32 )) %!test %! % multiple subs w/ vectors %! assert( isequal( subs(f, [x y], [t t]), t*t )) %! assert( isequal( subs(f, [x y], [t 16]), 16*t )) %! assert( isequal( subs(f, [x y], [2 16]), 32 )) %!test %! % anything you can think of %! assert( isequal( subs(f, [x y], {t t}), t*t )) %! assert( isequal( subs(f, {x y}, [t t]), t*t )) %! assert( isequal( subs(f, {x; y}, [t; t]), t*t )) %!test %! % sub in doubles gives sym (matches SMT 2013b) %! % FIXME: but see %! % http://www.mathworks.co.uk/help/symbolic/gradient.html %! assert( isequal( subs(f, {x y}, {2 pi}), 2*sym(pi) )) %! assert( ~isa(subs(f, {x y}, {2 pi}), 'double')) %! assert( isa(subs(f, {x y}, {2 pi}), 'sym')) %! assert( isa(subs(f, {x y}, {2 sym(pi)}), 'sym')) %! assert( isa(subs(f, {x y}, {sym(2) sym(pi)}), 'sym')) %!shared x,y,t,f,F %! syms x y t %! f = sin(x)*y; %! F = [f; 2*f]; %!test %! % need the simultaneous=True flag in SymPy (matches SMT 2013b) %! assert( isequal( subs(f, [x t], [t 6]), y*sin(t) )) %! assert( isequal( subs(F, [x t], [t 6]), [y*sin(t); 2*y*sin(t)] )) %!test %! % swap x and y (also needs simultaneous=True %! assert( isequal( subs(f, [x y], [y x]), x*sin(y) )) %!test %! % but of course both x and y to t still works %! assert( isequal( subs(f, [x y], [t t]), t*sin(t) )) %% reset the shared variables %!shared %!test %! % Issue #10, subbing matrices in for scalars %! syms y %! a = sym([1 2; 3 4]); %! f = sin(y); %! g = subs(f, y, a); %! assert (isequal (g, sin(a))) %!test %! % Issue #10, subbing matrices in for scalars %! syms y %! a = [10 20 30]; %! f = 2*y; %! g = subs(f, y, a); %! assert (isequal (g, 2*a)) %! assert (isa (g, 'sym')) %!test %! % two inputs %! syms x y %! assert (isequal (subs(sym(2)*x, 6), 12)) %! assert (isequal (subs(sym(2)*x*y^2, 6), 12*y^2)) %! assert (isequal (subs(sym(2)*y, 6), 12)) %! assert (isequal (subs(sym(2), 6), 2)) symbolic-2.2.4/inst/@sym/power.m0000644000175000001440000000567212633614672015243 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} power (@var{x}, @var{y}) %% Symbolic expression componentwise exponentiation (dot carat). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = power(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = power(x, y); return end cmd = { '(x,y) = _ins' 'if x.is_Matrix and y.is_Matrix:' ' for i in range(0, len(x)):' ' x[i] = x[i]**y[i]' ' return x,' 'if x.is_Matrix and not y.is_Matrix:' ' return x.applyfunc(lambda a: a**y),' 'if not x.is_Matrix and y.is_Matrix:' ' return y.applyfunc(lambda a: x**a),' 'else:' ' return x**y,' }; z = python_cmd (cmd, sym(x), sym(y)); end %!test %! % scalar .^ scalar %! syms x %! assert (isa (x.^2, 'sym')) %! assert (isa (2.^x, 'sym')) %! assert (isa (x.^x, 'sym')) %! assert (isequal (x.^2, x^2)) %! assert (isequal (2.^x, 2^x)) %! assert (isequal (x.^x, x^x)) %!test %! % scalar .^ matrix %! D = [0 1; 2 3]; %! A = sym(D); %! assert (isequal ( sym(2).^D , 2.^D )) %! assert (isequal ( sym(2).^A , 2.^A )) %! assert (isequal ( 2.^D , 2.^A )) %! assert (isequal ( 2.^A , 2.^A )) %!test %! % matrix .^ matrix %! syms x %! A = [x 2*x; 3*x 4*x]; %! D = [0 1; 2 3]; %! B = sym(D); %! assert (isequal ( A.^D, [1 2*x; 9*x^2 64*x^3] )) %! assert (isequal ( A.^B, [1 2*x; 9*x^2 64*x^3] )) %!test %! % matrix .^ scalar %! syms x %! A = [x 2*x]; %! assert (isequal ( A.^2, [x^2 4*x^2] )) %! assert (isequal ( A.^sym(2), [x^2 4*x^2] )) %!test %! % 1^oo %! % (sympy >= 0.7.5 gives NaN, SMT R2013b: gives 1) %! oo = sym(inf); %! assert (isnan (1^oo)) %!test %! % 1^zoo %! % (1 on sympy 0.7.4--0.7.6, but nan in git (2014-12-12, a210908d4)) %! % FIXME: xtest can be removed when 0.7.6.x support deprecated. %! zoo = sym('zoo'); %! if (str2num(strrep(python_cmd ('return sp.__version__,'), '.', ''))<=761) %! disp('skipping known failure b/c SymPy <= 0.7.6.x') %! else %! assert (isnan (1^zoo)) %! end symbolic-2.2.4/inst/@sym/lu.m0000644000175000001440000000551412633614672014522 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{L}, @var{U} =} lu (@var{A}) %% @deftypefnx {Function File} {@var{L}, @var{U}, @var{P} =} lu (@var{A}) %% @deftypefnx {Function File} {@dots{} =} lu (@var{A}, 'vector') %% Symbolic LU factorization of a matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [L, U, P] = lu(A, opt) if (nargin < 2) opt = 'matrix'; end assert (strcmp(opt, 'matrix') || strcmp(opt, 'vector')) cmd = { '(A, opt) = _ins' ... 'if not A.is_Matrix:' ... ' A = sp.Matrix([A])' ... '(L, U, p) = A.LUdecomposition()' ... '# convert list to P' ... 'n = L.shape[0]' ... 'if opt == "matrix":' ... ' P = sp.eye(n)' ... 'else:' ... ' P = sp.Matrix(range(1, n+1))' ... 'for w in p:' ... ' P.row_swap(*w)' ... 'return (L, U, P)' }; [L, U, P] = python_cmd (cmd, sym(A), opt); if (nargout == 2) L = P.' * L; end end %!test %! % scalar %! [l, u, p] = lu(sym(6)); %! assert (isequal (l, sym(1))) %! assert (isequal (u, sym(6))) %! assert (isequal (p, sym(1))) %! syms x %! [l, u, p] = lu(x); %! assert (isequal (l*u, p*x)) %! [l, u] = lu(x); %! assert (isequal (l*u, x)) %!test %! % perm %! A = sym(fliplr(2*eye(3))); %! [L, U, P] = lu(A); %! assert (isequal (L*U, P*A)) %! [L, U, P] = lu(A, 'matrix'); %! assert (isequal (L*U, P*A)) %! [L, U, p] = lu(A, 'vector'); %! assert (isequal (L*U, A(p,:))) %! [L, U] = lu(A); %! assert (isequal (L*U, A)) %!test %! % p is col vectpr %! A = sym([0 2; 3 4]); %! [L, U, p] = lu(A, 'vector'); %! assert(iscolumn(p)) %!test %! % simple matrix %! A = [1 2; 3 4]; %! B = sym(A); %! [L, U, P] = lu(B); %! assert (isequal (L*U, P*A)) %! assert (isequal (U(2,1), sym(0))) %! % needs pivot %! A = [0 2; 3 4]; %! B = sym(A); %! [L, U, P] = lu(B); %! [Ld, Ud, Pd] = lu(A); %! assert (isequal (L*U, P*A)) %! assert (isequal (U(2,1), sym(0))) %! % matches regular LU %! assert ( max(max(double(L)-Ld)) <= 10*eps) %! assert ( max(max(double(U)-Ud)) <= 10*eps) %! assert ( isequal (P, Pd)) symbolic-2.2.4/inst/@sym/expand.m0000644000175000001440000000237012633614672015356 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} expand (@var{x}) %% Combine parts of a symbolic product. %% %% @seealso{factor} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = expand(x) y = python_cmd( 'return sympy.expand(*_ins),', sym(x)); end %!test %! syms x %! assert (logical (x^2 + 6*x + 5 == expand ((x+5)*(x+1)))) %! assert (isequal (x^2 + 6*x + 5, expand ((x+5)*(x+1)))) %!test %! % array %! syms x %! assert (isequal (expand ([x (x+1)*x]), [x x^2+x])) symbolic-2.2.4/inst/@sym/asinh.m0000644000175000001440000000255412633614672015205 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} asinh (@var{x}) %% Symbolic asinh function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = asinh(x) y = uniop_helper (x, 'asinh'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = asinh(x); %! f2 = asinh(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = asinh(A); %! f2 = asinh(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/disp.m0000644000175000001440000000663012633614672015041 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} disp (@var{x}) %% @deftypefnx {Function File} {} disp (@var{x}, 'unicode') %% @deftypefnx {Function File} {} disp (@var{x}, 'ascii') %% @deftypefnx {Function File} {} disp (@var{x}, 'flat') %% @deftypefnx {Function File} {@var{s} =} disp (@var{x}) %% Display the value of a symbolic expression. %% %% Examples: %% @example %% @group %% >> syms x a c %% >> str = disp(sin(2*sym(pi)*x)) %% @result{} str = sin(2⋅π⋅x) %% %% >> A = [sin(x/2) floor(a^(x*c)); acosh(2*x/pi) ceil(sin(x/gamma(x)))]; %% >> disp(A, 'unicode') %% @result{} %% ⎡ ⎛x⎞ ⎢ c⋅x⎥ ⎤ %% ⎢ sin⎜─⎟ ⎣a ⎦ ⎥ %% ⎢ ⎝2⎠ ⎥ %% ⎢ ⎥ %% ⎢ ⎛2⋅x⎞ ⎡ ⎛ x ⎞⎤⎥ %% ⎢acosh⎜───⎟ ⎢sin⎜────⎟⎥⎥ %% ⎣ ⎝ π ⎠ ⎢ ⎝Γ(x)⎠⎥⎦ %% @end group %% %% @group %% >> disp(A, 'ascii') %% @result{} %% [ /x\ / c*x\ ] %% [ sin|-| floor\a / ] %% [ \2/ ] %% [ ] %% [ /2*x\ / / x \\] %% [acosh|---| ceiling|sin|--------||] %% [ \ pi/ \ \gamma(x)//] %% %% >> disp(A, 'flat') %% @result{} Matrix([[sin(x/2), floor(a**(c*x))], [acosh(2*x/pi), ceiling(sin(x/gamma(x)))]]) %% @end group %% @end example %% %% @seealso{pretty} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = disp(x, wh) if (nargin == 1) %% read config to see how to display x wh = sympref('display'); end switch lower(wh) case 'flat' s = x.flat; case 'ascii' s = x.ascii; case 'unicode' s = x.unicode; otherwise print_usage (); end s = make_indented(s); if (nargout == 0) disp(s) else varargout = {[s sprintf('\n')]}; % add a newline end end function s = make_indented(s, n) if (nargin == 1) n = 2; end pad = char (double (' ')*ones (1,n)); newl = sprintf('\n'); s = strrep (s, newl, [newl pad]); s = [pad s]; % first line end %!test %! syms x %! s = disp(sin(x)); %! assert(strcmp(s, sprintf(' sin(x)\n'))) %!test %! syms x %! s = disp(sin(x/2), 'flat'); %! assert(strcmp(s, sprintf(' sin(x/2)\n'))) %!test %! % Examples of 2x0 and 0x2 empty matrices: %! a = sym([1 2; 3 4]); %! b2x0 = a([true true], [false false]); %! b0x2 = a([false false], [true true]); %! assert (isequal (size (b2x0), [2 0])) %! assert (isequal (size (b0x2), [0 2])) %! s = disp(b2x0); %! assert(strcmp(s, sprintf(' []\n'))) %! s = disp(b0x2); %! assert(strcmp(s, sprintf(' []\n'))) symbolic-2.2.4/inst/@sym/cosh.m0000644000175000001440000000254412633614672015036 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} cosh (@var{x}) %% Symbolic cosh function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = cosh(x) y = uniop_helper (x, 'cosh'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = cosh(x); %! f2 = cosh(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = cosh(A); %! f2 = cosh(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/ezplot.m0000644000175000001440000001171112633614672015413 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{h} =} ezplot (@var{f}) %% @deftypefnx {Function File} {@var{h} =} ezplot (@var{f1}, @var{f2}) %% @deftypefnx {Function File} {@var{h} =} ezplot (@var{f1}, @var{n}) %% @deftypefnx {Function File} {@var{h} =} ezplot (@dots{}) %% Simple plotting of symbolic expressions. %% %% See help for the (non-symbolic) @code{ezplot}, which this %% routine calls after trying to convert sym inputs to %% anonymous functions. %% %% Using sym arguments for @var{dom} and @var{n} can lead to %% ambiguity where OctSymPy cannot tell if you are specifying @var{n} %% or @var{f2}. For example: %% @example %% @group %% >> syms t %% >> f = sin(t); %% >> N = sym(50); %% %% >> % parametric plot of f(t), N(t) %% >> ezplot(f, N) % doctest: +SKIP %% %% >> % plot f vs t using 50 pts %% >> ezplot(f, double(N)) % doctest: +SKIP %% @end group %% @end example %% %% The solution, as shown in the example, is to convert the sym to %% a double. %% %% FIXME: Sept 2014, there are differences between Matlab %% and Octave's ezplot and Matlab 2014a does not support N as %% number of points. Disabled some tests. %% %% @seealso{ezplot3, ezsurf, ezmesh, function_handle} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, plotting function varargout = ezplot(varargin) % first input is handle, shift if (ishandle(varargin{1})) fshift = 1; else fshift = 0; end firstsym = []; for i = (1+fshift):nargin if (isa(varargin{i}, 'sym')) if ( (i == 1 + fshift) || ... (i == 2 + fshift && isscalar(varargin{i})) ... ) % This is one of the fcns to plot, so convert to handle fcn % The "i == 2" issscalar cond is to supports ezplot(f, sym([0 1])) % Each is function of one var, and its the same var for all thissym = symvar(varargin{i}); assert(length(thissym) <= 1, ... 'ezplot: plotting curves: functions should have at most one input'); if (isempty(thissym)) % a number, create a constant function in a dummy variable % (0*t works around some Octave oddity on 3.8 and hg Dec 2014) thisf = inline(sprintf('%g + 0*t', double(varargin{i})), 't'); %thisf = @(t) 0*t + double(varargin{i}); % no else % check variables match (sanity check) if (isempty(firstsym)) firstsym = thissym; else assert(logical(thissym == firstsym), ... 'ezplot: all functions must be in terms of the same variables'); end thisf = function_handle(varargin{i}); end varargin{i} = thisf; else % plot ranges, etc, convert syms to doubles varargin{i} = double(varargin{i}); end end end h = ezplot(varargin{:}); if (nargout) varargout{1} = h; end end %!test %! % simple %! syms x %! f = cos(x); %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = ezplot(f); %! warning(s) %! xx = get(h, 'xdata'); %! yy = get(h, 'ydata'); %! assert (abs(yy(end) - cos(xx(end))) <= 2*eps) %! % matlab misses endpoint wtth nodisplay %! %assert (abs(xx(end) - 2*pi) <= 4*eps) %! %assert (abs(yy(end) - cos(2*pi)) <= 4*eps) %!test %! % parametric %! syms t %! x = cos(t); %! y = sin(t); %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = ezplot(x, y); %! warning(s) %! xx = get(h, 'xdata'); %! assert (abs(xx(end) - cos(2*pi)) <= 4*eps) %!error %! syms x t %! ezplot(t, x) %!error %! syms x t %! ezplot(t, t*x) %%!test %%! % contour, FIXME: broken on Matlab? Issue #108 %%! syms x y %%! f = sqrt(x*x + y*y) - 1; %%! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %%! h = ezplot(f); %%! warning(s) %%! y = get(h, 'ydata'); %%! assert (max(y) - 1 <= 4*eps) %%!test %%! % bounds etc as syms %%! % FIXME: this number-of-points option no supported on matlab %%! syms x %%! f = cos(x); %%! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %%! h = ezplot(f, [0 2*sym(pi)], sym(42)); %%! warning(s) %%! y = get(h, 'ydata'); %%! assert (length(y) == 42) %%! assert (abs(y(end) - cos(4*pi)) <= 4*eps) symbolic-2.2.4/inst/@sym/priv_disp_name.m0000644000175000001440000000243612633614672017101 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{s} =} priv_disp_name (@var{x}) %% A string appropriate for representing the name of this sym. %% %% Private method: this is not the method you are looking for. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function s = priv_disp_name(x, input_name) s = input_name; % subclasses might do something more interesting, but they should % be careful to ensure empty input_name gives empty s. end %!test %! syms x %! s = priv_disp_name(x, 'x'); %! assert (strcmp (s, 'x'))symbolic-2.2.4/inst/@sym/norm.m0000644000175000001440000000367412633614672015062 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} norm (@var{x}) %% @deftypefnx {Function File} {@var{z} =} norm (@var{x}, @var{ord}) %% Symbolic vector/matrix norm. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = norm(x, ord) if (nargin < 2) ord = 'meh'; line1 = 'x = _ins[0]; ord = None'; else line1 = '(x,ord) = _ins'; end if (ischar(ord)) if (~strcmp(ord, 'fro') && ~strcmp(ord, 'meh')) error('invalid norm') end else ord = sym(ord); end cmd = { line1 ... 'if not x.is_Matrix:' ... ' x = sympy.Matrix([x])' ... 'return x.norm(ord),' }; z = python_cmd (cmd, sym(x), ord); end %!assert (isequal (norm(sym(-6)), 6)) %!test %! syms x y real %! assert (isequal (norm([x 1; 3 y]), sqrt(x^2 + y^2 + 10))) %! assert (isequal (norm([x 1; 3 y], 'fro'), sqrt(x^2 + y^2 + 10))) %! assert (isequal (norm([x 1], 2), sqrt(x^2 + 1))) %!test %! % test sym vs double ord %! syms x %! assert (isequal (norm([x 2 1], 1), abs(x) + 3)) %! assert (isequal (norm([x 2 1], sym(1)), abs(x) + 3)) %! assert (isequal (norm([sym(-3) 2 1], inf), sym(3))) %! assert (isequal (norm([sym(-3) 2 1], sym(inf)), sym(3))) symbolic-2.2.4/inst/@sym/eig.m0000644000175000001440000000634012633614672014644 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{Lambda} =} eig (@var{A}) %% @deftypefnx {Function File} {@var{V}, @var{D} =} eig (@var{A}) %% Symbolic eigenvales/eigenvectors of a matrix. %% %% FIXME; generalized eigrnvalue problem not supported, check %% SymPy. %% %% @seealso{svd} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [V, D] = eig(A, B) if (nargin >= 2) error('eig: generalized eigenvalue problem not implemented') end if (nargout <= 1) cmd = { '(A,) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'd = A.eigenvals()' 'L = []' 'for (e, m) in d.items():' ' L.extend([e]*m)' 'L = sympy.Matrix(L)' 'return L,' }; V = python_cmd (cmd, sym(A)); else % careful, geometric vs algebraic mult, use m cmd = { '(A,) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'd = A.eigenvects()' 'V = sp.zeros(A.shape[0], 0)' % empty 'L = []' 'for (e, m, bas) in d:' ' L.extend([e]*m)' ' if len(bas) < m:' ' bas.extend([bas[0]]*(m-len(bas)))' ' for v in bas:' ' V = V.row_join(v)' 'D = diag(*L)' 'return V, D' }; [V, D] = python_cmd (cmd, sym(A)); end end %!test %! % basic %! A = [1 2; 3 4]; %! B = sym(A); %! sd = eig(A); %! s = eig(B); %! s2 = double(s); %! assert (norm(sort(s2) - sort(sd)) <= 10*eps) %!test %! % scalars %! syms x %! a = sym(-10); %! assert (isequal (eig(a), a)) %! assert (isequal (eig(x), x)) %!test %! % diag, multiplicity %! A = diag([6 6 7]); %! B = sym(A); %! e = eig(B); %! assert (isequal (size (e), [3 1])) %! assert (sum(logical(e == 6)) == 2) %! assert (sum(logical(e == 7)) == 1) %!test %! % matrix with symbols %! syms x y positive %! A = [x+9 y; sym(0) 6]; %! s = eig(A); %! s = simplify(s); %! assert (isequal (s, [x+9; 6]) || isequal (s, [6; x+9])) %!test %! % eigenvects %! e = sym([5 5 5 6 7]); %! A = diag(e); %! [V, D] = eig(A); %! assert (isequal (diag(D), e.')) %! assert (isequal (V, diag(sym([1 1 1 1 1])))) %!test %! % alg/geom mult, eigenvects %! e = sym([5 5 5 6]); %! A = diag(e); %! A(1,2) = 1; %! [V, D] = eig(A); %! assert (isequal (diag(D), e.')) %! assert (sum(logical(V(1,:) ~= 0)) == 2) %! assert (sum(logical(V(2,:) ~= 0)) == 0) %! assert (sum(logical(V(3,:) ~= 0)) == 1) %! assert (sum(logical(V(4,:) ~= 0)) == 1) symbolic-2.2.4/inst/@sym/isallconstant.m0000644000175000001440000000234712633614672016761 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} isallconstant (@var{x}) %% Whether all elements of a symbolic array are constant. %% %% @seealso{isconstant, symvar, findsymbols} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = isallconstant(x) z = isempty (findsymbols (x)); end %!assert (isallconstant([sym(1) 2 3])) %!test %! syms x %! assert (~isallconstant([sym(1) x 3])) %!test %! syms x %! assert (~isallconstant([sym(1) x; sym(2) 3])) symbolic-2.2.4/inst/@sym/floor.m0000644000175000001440000000255412633614672015224 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} floor (@var{x}) %% Symbolic floor function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = floor(x) y = uniop_helper (x, 'floor'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = floor(x); %! f2 = floor(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = floor(A); %! f2 = floor(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/potential.m0000644000175000001440000000725212633614672016102 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{p} =} potential (@var{v}) %% @deftypefnx {Function File} {@var{p} =} potential (@var{v}, @var{x}) %% @deftypefnx {Function File} {@var{p} =} potential (@var{v}, @var{x}, @var{y}) %% Symbolic potential of a vector field. %% %% Finds the potential of the vector field @var{v} with respect to %% the variables @var{x}$. The potential is defined up to an %% additive constant, unless the third argument is given; in which %% case the potential is such that @var{p} is zero at the point %% @var{y}. %% %% Example: %% @example %% @group %% syms x y z %% f = x*y*z; %% g = gradient (f) %% @result{} g = (sym 3×1 matrix) %% ⎡y⋅z⎤ %% ⎢ ⎥ %% ⎢x⋅z⎥ %% ⎢ ⎥ %% ⎣x⋅y⎦ %% potential (g) %% @result{} (sym) x⋅y⋅z %% @end group %% @end example %% %% Return symbolic @code{nan} if the field has no potential (based %% on checking if the Jacobian matrix of the field is %% nonsymmetric). For example: %% @example %% @group %% syms x y %% a = [x; x*y^2]; %% potential (a) %% @result{} (sym) nan %% @end group %% @end example %% @seealso{gradient, jacobian} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function p = potential(v, x, y) assert (isvector(v), 'potential: defined for vector fields') if (nargin == 1) x = symvar(v); end % orient same as vec field x = reshape(x, size(v)); if (nargin < 3) y = 0*x; end assert ((length(v) == length(x)) && (length(x) == length(y)), ... 'potential: num vars must match vec length') cmd = { '(v, x, y) = _ins' 'if not v.is_Matrix:' ' v = Matrix([v])' ' x = Matrix([x])' ' y = Matrix([y])' 'G = v.jacobian(x)' 'if not G.is_symmetric():' ' return S.NaN,' '_lambda = sympy.Dummy("lambda", real=True)' 'q = y + _lambda*(x - y)' 'vlx = v.subs([a for a in zip(list(x), list(q))], simultaneous=True)' 'p = integrate((x-y).dot(vlx), (_lambda, 0, 1))' 'return p.simplify(),' }; % FIXME: [a for a in zip] is a hack for python 3: why is this % necessary? SymPy bug? p = python_cmd (cmd, sym(v), x, sym(y)); end %!shared x,y,z %! syms x y z %!test %! % 1D %! f = 3*x^2; %! F = x^3; %! assert (isequal (potential(f), F)) %! assert (isequal (potential(f, x), F)) %! assert (isequal (potential(f, x, 0), F)) %! assert (isequal (potential(f, x, 2), F - 8)) %!test %! F = x*exp(y) + (z-1)^2; %! f = gradient(F); %! G = potential(f, [x;y;z], [0;1;1]); %! assert (isAlways (G == F)) %!test %! F = x*exp(y); %! f = gradient(F); %! G = potential(f); %! assert (isAlways (G == F)) %!test %! % no potential exists %! syms x y %! a = [x; x*y^2]; %! assert (isnan (potential (a))) %!shared %!xtest %! % fails b/c of sympy #8458 (piecewise expr that should simplify) %! syms x %! f = cos(x); %! assert (isequal (potential(f, x), sin(x))) symbolic-2.2.4/inst/@sym/cond.m0000644000175000001440000000261112633614672015020 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{k} =} cond (@var{a}) %% Symbolic condition number of a symbolic matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function k = cond(A) cmd = { '(A,) = _ins' ... 'if not A.is_Matrix:' ... ' A = sp.Matrix([A])' ... 'return A.condition_number(),' }; k = python_cmd (cmd, sym(A)); end %!test %! A = [1 2; 3 4]; %! B = sym(A); %! k1 = cond(A); %! k2 = cond(B); %! k3 = double(k2); %! assert (k1 - k3 <= 100*eps) %!test %! % matrix with symbols %! syms x positive %! A = [x 0; sym(0) 2*x]; %! k1 = cond(A); %! assert (isequal (k1, sym(2))) symbolic-2.2.4/inst/@sym/erfcinv.m0000644000175000001440000000266412633614672015541 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} erfcinv (@var{x}) %% Symbolic erfcinv function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = erfcinv(x) % Note: the erfcinv unit test fails on Octave < 3.8 y = uniop_helper (x, 'erfcinv'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = erfcinv(x); %! f2 = erfcinv(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = erfcinv(A); %! f2 = erfcinv(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/cot.m0000644000175000001440000000253412633614672014666 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} cot (@var{x}) %% Symbolic cot function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = cot(x) y = uniop_helper (x, 'cot'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = cot(x); %! f2 = cot(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = cot(A); %! f2 = cot(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/minus.m0000644000175000001440000000321112633614672015225 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} minus (@var{x}, @var{y}) %% Subtract one symbolic expression from another (-). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = minus(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = minus(x, y); return end % -y + x z = axplusy(-1, y, x); end %!test %! % scalar %! syms x %! assert (isa (x-1, 'sym')) %! assert (isa (x-x, 'sym')) %! assert (isequal (x-x, sym(0))) %!test %! % matrices %! D = [0 1; 2 3]; %! A = sym(D); %! DZ = D - D; %! assert (isequal ( A - D , DZ )) %! assert (isequal ( A - A , DZ )) %! assert (isequal ( D - A , DZ )) %! assert (isequal ( A - 2 , D - 2 )) %! assert (isequal ( 4 - A , 4 - D )) symbolic-2.2.4/inst/@sym/latex.m0000644000175000001440000000242012633614672015210 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{s} =} latex (@var{x}) %% Return LaTeX typesetting code for a symbolic expression. %% %% @seealso{disp, pretty} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = latex(x) cmd = { 'return sp.latex(*_ins),' }; s = python_cmd (cmd, x); if (nargout == 0) disp(s) else varargout = {s}; end end %!test %! syms x %! y = sin(x); %! assert ( strcmp( latex(y), '\sin{\left (x \right )}')) %! assert ( strcmp( latex(exp(x)), 'e^{x}')) symbolic-2.2.4/inst/@sym/colon.m0000644000175000001440000000430712633614672015213 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{x} =} colon (@var{a},@var{b}) %% @deftypefnx {Function File} {@var{x} =} colon (@var{a},@var{step},@var{b}) %% Generate a range of syms. %% %% FIXME: should this generate intervals? Check what SMT does? %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = colon(a,step,b) if (nargin == 2) b = step; step = sym(1); end a = sym(a); b = sym(b); step = sym(step); B = (b-a)/step; y = (0:double(B))*sym(step) + a; % this approach fails to make 0:sym(pi):10 %cmd = {'(a, b, step) = _ins'... % 'y = range(a, b + sign(step)*1, step)'... % 'return y,'}; %y = python_cmd (cmd, a, b, step) %y = cell2mat(y); end %!test %! a = sym(1):5; %! b = sym(1:5); %! assert(isequal(a,b)); %! a = 1:sym(5); %! b = sym(1:5); %! assert(isequal(a,b)); %!test %! a = 2:sym(2):8; %! b = sym(2:2:8); %! assert(isequal(a,b)); %!test %! a = sym(10):-2:-4; %! b = sym(10:-2:-4); %! assert(isequal(a,b)); %!test %! % symbolic intervals %! p = sym(pi); %! L = 0:p/4:p; %! assert(isa(L,'sym')); %! assert(isequal(L, [0 p/4 p/2 3*p/4 p])); %!test %! % mixed symbolic and double intervals %! p = sym(pi); %! s = warning ('off', 'OctSymPy:sym:rationalapprox'); %! L = 0.1:(sym(pi)/3):2.3; %! warning(s) %! assert(isa(L,'sym')); %! t = sym(1)/10; %! assert(isequal(L, [t p/3+t 2*p/3+t])); %! % should be an error if it doesn't convert to double %!error syms x; a = 1:x; symbolic-2.2.4/inst/@sym/qr.m0000644000175000001440000000365612633614672014531 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{q}, @var{r} =} qr (@var{a}) %% Symbolic QR factorization of a matrix. %% %% FIXME: The sympy QR routine could probably be improved. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [Q, R] = qr(A, ord) if (nargin == 2) warning('OctSymPy:NotImplemented', 'economy-size not implemented') end cmd = { 'A = _ins[0]' ... 'if not A.is_Matrix:' ... ' A = sp.Matrix([A])' ... '(Q, R) = A.QRdecomposition()' ... 'return (Q, R)' }; [Q, R] = python_cmd (cmd, sym(A)); end %!test %! % scalar %! [q, r] = qr(sym(6)); %! assert (isequal (q, sym(1))) %! assert (isequal (r, sym(6))) %! syms x %! [q, r] = qr(x); %! assert (isequal (q*r, x)) %! % could hardcode this if desired %! %assert (isequal (q, sym(1))) %! %assert (isequal (r, x)) %!test %! A = [1 2; 3 4]; %! B = sym(A); %! [Q, R] = qr(B); %! assert (isequal (Q*R, B)) %! assert (isequal (R(2,1), sym(0))) %! assert (isequal (Q(:,1)'*Q(:,2), sym(0))) %! %[QA, RA] = qr(A) %! %assert ( max(max(double(Q)-QA)) <= 10*eps) %! %assert ( max(max(double(Q)-QA)) <= 10*eps) %%!xtest %%! % non square matrix %%! assert (false) symbolic-2.2.4/inst/@sym/all.m0000644000175000001440000000376312633614672014656 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} all (@var{x}) %% @deftypefnx {Function File} {@var{y} =} all (@var{x}, @var{dim}) %% Return true if all entries of a symbolic vector are nonzero. %% %% Similar behaviour to the built-in @code{all} with regard to %% matrices and the second argument. %% %% Throws an error if any entries are non-numeric. %% %% Example: %% @example %% @group %% >> all([sym(1) pi 3]) %% @result{} ans = 1 %% @end group %% @end example %% %% @seealso{any} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = all(x, varargin) z = all (logical (x), varargin{:}); %z = double (x, false); %if (isempty (z)) % error ('indeterminable') %else % z = all (z, varargin{:}); %end end %!test %! % matrix %! a = [0 3; 1 2]; %! s = sym (a); %! assert (isequal (all (s), all (a))) %! assert (isequal (all (s,1), all (a,1))) %! assert (isequal (all (s,2), all (a,2))) %!test %! % vector %! a = [1 2 3]; %! s = sym (a); %! assert (isequal (all (s), all (a))) %! assert (isequal (all (s,1), all (a,1))) %! assert (isequal (all (s,2), all (a,2))) %!test %! % should fail on symbols %! syms x %! s = [1 2 x]; %! try %! all (s) %! waserr = false; %! catch %! waserr = true; %! end %! assert (waserr) symbolic-2.2.4/inst/@sym/cat.m0000644000175000001440000000214312633614672014644 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {} cat () %% Overloaded cat for sym class, perhaps unnecessary. %% %% FIXME: do we need this? %% %% @seealso{vertcat,horzcat} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function cat(varargin) error('cat: not implemented, unnecessary?'); end %!assert(true) % so far, everything works :) symbolic-2.2.4/inst/@sym/matlabFunction.m0000644000175000001440000000261012633614672017042 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} matlabFunction (@var{f}) %% Convert symbolic expression into a standard function. %% %% This is a synonym of @code{function_handle}. See further %% documentation: @xref{function_handle} %% %% @seealso{ccode, fortran, latex, function_handle} %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function f = matlabFunction(varargin) f = function_handle(varargin{:}); end %!test %! % autodetect inputs %! syms x y %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = matlabFunction(2*x*y, x+y); %! warning(s) %! [t1, t2] = h(3,5); %! assert(t1 == 30 && t2 == 8) symbolic-2.2.4/inst/@sym/isfinite.m0000644000175000001440000000241312633614672015707 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isfinite (@var{x}) %% Is symbolic expression finite. %% %% We have this mainly so @code{assert} works properly. %% %% @seealso{isnan} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = isfinite(x) r = ~ (isnan(x) | isinf(x)); end %!test %! syms x oo %! assert (isfinite(x)) % FIXME: why? %! assert (isfinite(sym(1))) %! assert (~isfinite(oo)) %! assert (~isfinite(sym(nan))) %! assert (isequal (isfinite (sym ([1 oo])), [true false])) symbolic-2.2.4/inst/@sym/asin.m0000644000175000001440000000254412633614672015034 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} asin (@var{x}) %% Symbolic asin function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = asin(x) y = uniop_helper (x, 'asin'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = asin(x); %! f2 = asin(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = asin(A); %! f2 = asin(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/atan2.m0000644000175000001440000000305612633614672015106 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{a} =} atan2 (@var{x}, @var{y}) %% Symbolic atan2 function, return angle from a point. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function a = atan2(y, x) a = binop_helper (y, x, 'sp.atan2'); end %!test %! % some angles %! e = sym(1); %! a = atan2(0, e); %! assert (isequal (a, sym(0))) %! a = atan2(e, 0); %! assert (isequal (a, sym(pi)/2)) %!test %! % symbols can give numerical answer %! syms x positive %! a = atan2(0, x); %! assert (isequal (a, sym(0))) %! a = atan2(x, 0); %! assert (isequal (a, sym(pi)/2)) %! a = atan2(-x, 0); %! assert (isequal (a, -sym(pi)/2)) %!test %! % matrices %! x = sym([1 -2; 0 0]); %! y = sym([0 0; 8 -3]); %! a = atan2(y, x); %! sp = sym(pi); %! aex = [0 sp; sp/2 -sp/2]; %! assert (isequal (a, aex)) symbolic-2.2.4/inst/@sym/fliplr.m0000644000175000001440000000307612633614672015373 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} fliplr (@var{A}) %% Flip a symbolic matrix horizontally. %% %% @seealso{flipud, reshape} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function B = fliplr(A) cmd = { '(A,) = _ins' ... 'if not A.is_Matrix:' ... ' A = sp.Matrix([A])' ... '_, n = A.shape' ... 'for j in range(0, int(n/2)):' ... ' A.col_swap(j, n-j-1)' ... 'return A,' }; B = python_cmd (cmd, sym(A)); end %!test %! % simple %! syms x %! A = [x 2; sym(pi) x]; %! B = [2 x; x sym(pi)]; %! assert (isequal (fliplr(A), B)) %!test %! % simple, odd # cols %! syms x %! A = [x 2 sym(pi); x 1 2]; %! B = [sym(pi) 2 x; 2 1 x]; %! assert (isequal (fliplr(A), B)) %!test %! % scalar %! syms x %! assert (isequal (fliplr(x), x)) symbolic-2.2.4/inst/@sym/mod.m0000644000175000001440000000733112633614672014660 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} mod (@var{x}, @var{n}) %% @deftypefnx {Function File} {@var{y} =} mod (@var{x}, @var{n}, false) %% Element-wise modular arithmetic on symbolic arrays and polynomials. %% %% Example: %% @example %% @group %% >> mod([10 3 1], sym(3)) %% @result{} ans = (sym) [1 0 1] (1×3 matrix) %% @end group %% @end example %% %% If any of the entries contain variables, we assume they are %% univariate polynomials and convert their coefficients to mod %% @var{n}: %% @example %% @group %% >> syms x %% >> mod(5*x + 7, 3) %% @result{} (sym) 2⋅x + 1 %% >> mod(x, 3) % (coefficient is 1 mod 3) %% @result{} (sym) x %% @end group %% @end example %% You can disable this behaviour by passing @code{false} as the %% third argument: %% @example %% @group %% >> syms x %% >> q = mod(x, 3, false) %% @result{} q = (sym) Mod(x, 3) %% >> subs(q, x, 10) %% @result{} ans = (sym) 1 %% %% >> syms n integer %% >> mod(3*n + 2, 3, false) %% @result{} (sym) 2 %% @end group %% @end example %% %% @seealso{coeffs} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mod(x, n, canpoly) if (nargin < 3) canpoly = true; end isconst = isempty (findsymbols (x)); if (~canpoly || isconst) z = binop_helper(x, n, 'lambda a,b: a % b'); %z = binop_helper(x, n, {'def _op(a, b):' ... % ' return a % b' }); else %% its not constant, assume everything is poly and mod the coefficients z = x; for i = 1:numel(x) % t = x(i) idx.type = '()'; idx.subs = {i}; t = subsref (x, idx); if (isscalar(n)) m = n; else m = subsref (n, idx); % m = n(i) end sv = symvar(t, 1); % Note: sympy Polys have a .termwise: would that be easier? [c, t] = coeffs(t, sv); c = mod(c, m, false); % force no poly here rhs = t * c.'; % recombine the new poly z = subsasgn(z, idx, rhs); %z(i) = rhs; end end end %!assert (isequal (mod (sym(5), 4), sym(1))) %!assert (isequal (mod ([sym(5) 8], 4), [1 0] )) %!assert (isequal (mod (sym(5), [2 3]), [1 2] )) %!assert (isequal (mod ([sym(5) sym(6)], [2 3]), [1 0] )) %!test %! syms x %! assert (isequal ( mod (5*x, 3), 2*x )) %!test %! syms x %! a = [7*x^2 + 3*x + 3 3*x; 13*x^4 6*x]; %! assert (isequal ( mod (a,3), [x^2 0; x^4 0] )) %!test %! % vector of polys with mix of vars: symvar on each %! syms x y %! a = [6*x 7*y]; %! b = mod(a, 4); %! c = [2*x 3*y]; %! assert (isequal (b, c)) %!xtest %! % coeff has variable (fails on 0.7.5) %! syms x %! n = sym('n', 'integer'); %! p = (3*n + 2)*x; %! q = mod(p, 3); %! assert (isequal (q, 2*x)) %!test %! % coeff has variable %! syms x a %! p = a*x; %! q = mod(p, 3); %! q = children(q); %! q = q(2); % order might be fragile! %! w = subs(q, a, 5); %! assert (isequal (w, 2)) %!test %! % different modulo %! syms x y %! q = mod([5*x + 10 5*y + 10], [2 3]); %! assert (isequal (q, [x 2*y + 1])) symbolic-2.2.4/inst/@sym/permute.m0000644000175000001440000000262712633614672015565 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} permute (@var{A}, @var{perm}) %% Permute the indices of a symbolic array. %% %% Generalizes transpose, but currently doesn't do much as we only %% support 2D symbolic arrays. %% %% @seealso{ipermute} %% @end deftypefn function B = permute(A, perm) if (isequal(perm, [1 2])) B = A; elseif (isequal(perm, [2 1])) B = A.'; else print_usage (); end end %!test %! D = round(10*rand(5,3)); %! A = sym(D); %! B = permute(A, [1 2]); %! assert (isequal(B, A)) %! B = permute(A, [2 1]); %! assert (isequal(B, A.')) %!test %! syms x %! A = [1 x]; %! B = permute(A, [2 1]); %! assert (isequal(B, [1; x])) symbolic-2.2.4/inst/@sym/times.m0000644000175000001440000000356512633614672015227 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} times (@var{x}, @var{y}) %% Return elementwise multiplication of two syms (dot star). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = times(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = times(x, y); return end cmd = { '(x,y) = _ins' 'if x.is_Matrix and y.is_Matrix:' ' return x.multiply_elementwise(y),' 'else:' ' return x*y,' }; z = python_cmd (cmd, sym(x), sym(y)); end %!test %! % scalar %! syms x %! assert (isa (x.*2, 'sym')) %! assert (isequal (x.*2, x*2)) %! assert (isequal (2.*sym(3), sym(6))) %! assert (isequal (sym(2).*3, sym(6))) %!test %! % matrix-matrix and matrix-scalar %! D = [0 1; 2 3]; %! A = sym(D); %! assert (isequal ( 2.*A , 2*D )) %! assert (isequal ( A.*2 , 2*D )) %! assert (isequal ( A.*A , D.*D )) %! assert (isequal ( A.*D , D.*D )) %! assert (isequal ( D.*A , D.*D )) symbolic-2.2.4/inst/@sym/size.m0000644000175000001440000000574412633614672015061 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{d} =} size (@var{x}) %% @deftypefnx {Function File} {[@var{n}, @var{m}] =} size (@var{x}) %% @deftypefnx {Function File} {@var{d} =} size (@var{x}, @var{dim}) %% Return the size of a symbolic array. %% %% @seealso{length, numel} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [n, m] = size(x, dim) % Note: symbolic sized matrices should return double, not sym/string. n = x.size; % FIXME: for now, we artificially force symbolic sized objects % (where one or more dimension is recorded as NaN) to be 1x1. % This effects MatrixSymbol and MatrixExpr. See Issue #159. if (any(isnan(n))) n = [1 1]; end % Alternatively: %n(isnan(n)) = 1; if (nargin == 2) && (nargout == 2) print_usage (); elseif (nargout == 2) m = n(2); n = n(1); elseif (nargin == 2) n = n(dim); end end %!test %! a = sym([1 2 3]); %! [n,m] = size(a); %! assert (n == 1 && m == 3) %!test %! a = sym([1 2 3]); %! n = size(a); %! assert (isequal (n, [1 3])) %!test %! %% size, numel, length %! a = sym([1 2 3; 4 5 6]); %! assert (isa (size(a), 'double')) %! assert (isa (numel(a), 'double')) %! assert (isa (length(a), 'double')) %! assert (isequal (size(a), [2 3])) %! assert (length(a) == 3) %! assert (numel(a) == 6) %! a = sym([1; 2; 3]); %! assert (isequal (size(a), [3 1])) %! assert (length(a) == 3) %! assert (numel(a) == 3) %!test %! %% size by dim %! a = sym([1 2 3; 4 5 6]); %! n = size(a, 1); %! assert (n == 2) %! m = size(a, 2); %! assert (m == 3) %! a = sym([1 2 3]'); %! n = size(a, 1); %! assert (n == 3) %! m = size(a, 2); %! assert (m == 1) %!xtest %! % symbolic-size matrices %! syms n m integer %! A = sym('A', [n m]); %! d = size(A); %! assert (~isa(d, 'sym')) %! assert (isnumeric(d)) %! assert (isequaln (d, [NaN NaN])) %!xtest %! % half-symbolic-size matrices %! % FIXME: will fail until size stop lying by saying 1x1 %! syms n integer %! A = sym('A', [n 3]); %! assert (isequaln (size(A), [NaN 3])) %! A = sym('A', [4 n]); %! assert (isequaln (size(A), [4 NaN])) %!xtest %! % half-symbolic-size empty matrices %! % FIXME: will fail until size stop lying by saying 1x1 %! syms n integer %! A = sym('A', [n 0]); %! assert (isequaln (size(A), [NaN 0])) symbolic-2.2.4/inst/@sym/assumeAlso.m0000644000175000001440000000735312633614672016221 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{x} =} assumeAlso (@var{x}, @var{cond}, @var{cond2}, ...) %% @deftypefnx {Function File} {} assumeAlso (@var{x}, @var{cond}) %% Add additional assumptions on a symbolic variable. %% %% Behaviour is similar to @code{assume}; however @var{cond} is combined %% with any existing assumptions of @var{x} instead of replacing them. %% %% @strong{Warning}: with no output argument, this tries to find %% and replace any @var{x} within expressions in the caller's %% workspace. See @ref{assume}. %% %% @seealso{assume, assumptions, sym, syms} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = assumeAlso(x, varargin) [tilde,ca] = assumptions(x, 'dict'); if isempty(ca) ca = []; elseif (length(ca)==1) ca = ca{1}; else ca error('expected at most one dict') end for n=2:nargin cond = varargin{n-1}; ca.(cond) = true; end xstr = x.flat; newx = sym(xstr, ca); if (nargout > 0) varargout{1} = newx; return end % --------------------------------------------- % Muck around in the caller's namespace, replacing syms % that match 'xstr' (a string) with the 'newx' sym. %xstr = %newx = context = 'caller'; % --------------------------------------------- S = evalin(context, 'whos'); evalin(context, '[];'); % clear 'ans' for i = 1:numel(S) obj = evalin(context, S(i).name); [newobj, flag] = symreplace(obj, xstr, newx); if flag, assignin(context, S(i).name, newobj); end end % --------------------------------------------- end %!test %! syms x %! x = assumeAlso(x, 'positive'); %! a = assumptions(x); %! assert(strcmp(a, 'x: positive')) %!test %! syms x positive %! x = assumeAlso(x, 'integer'); %! [tilde, a] = assumptions(x, 'dict'); %! assert(a{1}.integer) %! assert(a{1}.positive) %!test %! % multiple assumptions %! syms x positive %! x = assumeAlso(x, 'integer', 'even'); %! [tilde, a] = assumptions(x, 'dict'); %! assert(a{1}.integer) %! assert(a{1}.positive) %! assert(a{1}.even) %!xtest %! % has output so avoids workspace %! % FIXME: xtest for sympy 0.7.6.x where a is the full dict %! syms x positive %! x2 = x; %! f = sin(x); %! assumeAlso(x, 'integer'); %! a = assumptions(x); %! assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) %! a = assumptions(x2); %! assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) %! a = assumptions(f); %! assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) %!xtest %! % has no output so does workspace %! % FIXME: xtest for sympy 0.7.6 where a is the full dict %! syms x positive %! x2 = x; %! f = sin(x); %! assumeAlso(x, 'integer'); %! a = assumptions(x); %! assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) %! a = assumptions(x2); %! assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) %! a = assumptions(f); %! assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) symbolic-2.2.4/inst/@sym/xor.m0000644000175000001440000000346612633614672014716 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{z} =} xor (@var{x}, @var{y}) %% Logical xor of symbolic arrays. %% %% Example: %% @example %% @group %% >> xor(sym(true), sym(true)) %% @result{} ans = (sym) False %% @end group %% @end example %% %% @seealso{and, or, not, eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = xor(x, y) r = binop_helper(x, y, 'lambda a,b: Xor(a, b)'); end %!shared t, f %! t = sym(true); %! f = sym(false); %!test %! % simple %! assert (isequal (xor(t, f), t)) %! assert (isequal (xor(t, t), f)) %!test %! % array %! w = [t t f f]; %! z = [t f t f]; %! assert (isequal (xor(w, z), [f t t f])) %!xtest %! % output is sym even for scalar t/f %! % ₣IXME: should match other bool fcns %! assert (isa (xor(t, f), 'sym')) %!test %! % eqns %! syms x %! e = xor(x == 4, x == 5); %! assert (isequal (subs(e, x, [3 4 5 6]), [f t t f])) %!test %! % eqns, exclusive %! syms x %! e = xor(x == 3, x^2 == 9); %! assert (isequal (subs(e, x, [-3 0 3]), [t f f])) symbolic-2.2.4/inst/@sym/end.m0000644000175000001440000000317412633614672014650 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} end (@var{x}) %% Overloaded end for sym arrays. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = end (obj, index_pos, num_indices) if ~(isscalar(index_pos)) error('can this happen?') end if (num_indices == 1) r = numel(obj); elseif (num_indices == 2) d = size(obj); r = d(index_pos); else obj index_pos num_indices error('now whut?'); end end %!test %! % scalar %! syms x %! y = x(1:end); %! assert (isequal (x, y)) %!test %! % vector %! syms x %! A = [1 2 x 4]; %! y = A(end-1:end); %! assert (isequal (y, [x 4])) %!test %! % subset of matrix %! syms x %! A = [1 2 x; x 3 9; 4 x*x 6]; %! y = A(end,1:end-1); %! assert (isequal (y, [4 x*x])) %!test %! % linear index of matrix %! syms x %! A = [1 2 x; x 3 9]; %! y = A(end); %! assert (isequal (y, sym(9))) symbolic-2.2.4/inst/@sym/argnames.m0000644000175000001440000000242712633614672015677 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{vars} =} argnames (@var{f}) %% Return the independent variables in a symfun. %% %% For a @@sym, this always returns the empty sym, but %% subclasses like @@symfun do something more interesting. %% %% @seealso{@@symfun/argnames, symvar, findsym, findsymbols} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function vars = argnames(F) vars = sym([]); end %!test %! % basic tests %! syms x %! f = 2*x; %! assert (isempty (argnames(x))) %! assert (isempty (argnames(f))) symbolic-2.2.4/inst/@sym/isnan.m0000644000175000001440000000534712633614672015216 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isnan (@var{x}) %% Return true if a symbolic expression is Not-a-Number. %% %% @seealso{isinf, double} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = isnan(x) % todo: neat idea but fails for matrices %r = isnan (double (x, false)); if isscalar(x) cmd = 'return (_ins[0] == sp.nan,)'; r = python_cmd (cmd, x); if (~ islogical(r)) error('nonboolean return from python'); end else % array r = logical(zeros(size(x))); for j = 1:numel(x) % Bug #17 idx.type = '()'; idx.subs = {j}; r(j) = isnan(subsref(x, idx)); end end end %!shared x,zoo,oo,snan %! oo = sym(inf); %! zoo = sym('zoo'); %! x = sym('x'); %! snan = sym(nan); %!test %! % various ops that give nan %! assert (isnan(0*oo)) %! assert (isnan(0*zoo)) %! assert (isnan(snan)) %! assert (isnan(snan-snan)) %! assert (isnan(oo+snan)) %! assert (isnan(oo-oo)) %! assert (isnan(oo-zoo)) %! assert (isnan(oo+zoo)) %! assert (~isnan(oo)) %! assert (~isnan(zoo)) %! assert (~isnan(oo+oo)) %!test %! % more ops give nan %! assert(isnan(x+snan)) %! assert(isnan(x*snan)) %! assert(isnan(0*snan)) %! assert(isnan(x+nan)) %! assert(isnan(x*nan)) %! assert(isnan(sym(0)*nan)) %!test %! % array %! assert (isequal( isnan([oo zoo]), [0 0] )) %! assert (isequal( isnan([10 snan]), [0 1] )) %! assert (isequal( isnan([snan snan]), [1 1] )) %! assert (isequal( isnan([snan x]), [1 0] )) %!test %! % sub in to algebraic expression gives nan %! y = x - oo; %! y = subs(y, x, oo); %! assert(isnan(y)) %!test %! % Must not contain string 'symbol'; these all should make an %! % actual nan. Actually a ctor test, not isnan. %! y = sym(nan); %! assert (isempty( strfind(y.pickle, 'Symbol') )) %! y = sym('nan'); %! assert (isempty( strfind(y.pickle, 'Symbol') )) %! y = sym('NaN'); %! assert (isempty( strfind(y.pickle, 'Symbol') )) %! y = sym('NAN'); %! assert (isempty( strfind(y.pickle, 'Symbol') )) symbolic-2.2.4/inst/@sym/acot.m0000644000175000001440000000254412633614672015030 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} acot (@var{x}) %% Symbolic acot function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = acot(x) y = uniop_helper (x, 'acot'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = acot(x); %! f2 = acot(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = acot(A); %! f2 = acot(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/sin.m0000644000175000001440000000253412633614672014672 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} sin (@var{x}) %% Symbolic sin function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = sin(x) y = uniop_helper (x, 'sin'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = sin(x); %! f2 = sin(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = sin(A); %! f2 = sin(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/diag.m0000644000175000001440000000651012633614672015003 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{M} =} diag (@var{v}) %% @deftypefnx {Function File} {@var{M} =} diag (@var{v}, @var{k}) %% @deftypefnx {Function File} {@var{M} =} diag (@var{v}, @var{n}, @var{m}) %% @deftypefnx {Function File} {@var{v} =} diag (@var{A}) %% @deftypefnx {Function File} {@var{v} =} diag (@var{A}, @var{k}) %% Make diagonal matrix or extract diagonal of symbolic matrix. %% %% @seealso{repmat} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function D = diag(A, k, c) if (nargin == 3) assert(isvector(A)) elseif (nargin == 1) k = 0; end if isvector(A) if (nargin == 3) r = double(k); c = double(c); k = 0; else k = double(k); r = length(A) + abs(k); c = r; end cmd = { '(A, k, r, c) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'D = sp.zeros(r, c)' 'if k >= 0:' ' for i in range(0, min(r, c, c-k, r+k)):' ' D[i,i+k] = A[i]' 'else:' ' for i in range(0, min(r, c, c-k, r+k)):' ' D[i-k,i] = A[i]' 'return D,' }; D = python_cmd (cmd, sym(A), int32(k), int32(r), int32(c)); else cmd = { '(A, k) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'r, c = A.shape' 'if k >= 0:' ' B = sp.Matrix([A[i,i+k] for i in range(0, min(r, c, c-k, r+k))])' 'else:' ' B = sp.Matrix([A[i-k,i] for i in range(0, min(r, c, c-k, r+k))])' 'return B,' }; D = python_cmd (cmd, sym(A), int32(double(k))); end end %!test %! % scalar %! syms x %! assert (isequal (diag(x), x)) %!test %! % row,col vec input %! syms x %! r = [1 x 2]; %! c = [sym(1); x]; %! assert (isequal (diag(diag(c)), c)) %! assert (isequal (diag(c), [sym(1) 0; 0 x])) %! assert (isequal (diag(diag(r)), r.')) %! assert (isequal (diag(r), [sym(1) 0 0; 0 x 0; sym(0) 0 2])) %!test %! % create matrix, kth diag %! syms x %! r = [1 x]; %! z = sym(0); %! assert (isequal (diag (x, 0), x)) %! assert (isequal (diag (x, 1), [z x; z z])) %! assert (isequal (diag (x, -1), [z z; x z])) %! assert (isequal (diag (x, 2), [z z x; z z z; z z z])) %! assert (isequal (diag (r, 1), [z 1 z; z z x; z z z])) %!test %! % extract kth diag %! A = sym([1 2 3; 4 5 6]); %! assert (isequal (diag(A), sym([1; 5]))) %! assert (isequal (diag(A, 0), sym([1; 5]))) %! assert (isequal (diag(A, 1), sym([2; 6]))) %! assert (isequal (diag(A, 2), sym(3))) %! assert (isequal (diag(A, -1), sym(4))) %! assert (isempty (diag(A, -2))) %! assert (isempty (diag(A, 3))) symbolic-2.2.4/inst/@sym/iscolumn.m0000644000175000001440000000235312633614672015731 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} iscolumn (@var{x}) %% Return true if symbolic expression is a column vector. %% %% @seealso{isrow, isvector, isscalar} %% @end deftypefn function r = iscolumn(x) % from Rik Wehbring's Octave function: sz = size (x); r = (ndims (x) == 2 && (sz(2) == 1)); end %!assert (iscolumn (sym ([1]))) %!assert (iscolumn (sym ([1 2 3]'))) %!assert (~iscolumn (sym ([]))) %!assert (~iscolumn (sym ([1 2 3]))) %!assert (~iscolumn (sym ([1 2; 3 4]))) symbolic-2.2.4/inst/@sym/isequal.m0000644000175000001440000000421712633614672015544 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isequal (@var{f}, @var{g}) %% @deftypefnx {Function File} {@var{r} =} isequal (@var{f}, @var{g}, @dots{}) %% Test if contents of two or more arrays are equal. %% %% Here nan's are considered nonequal, see also @code{isequaln} %% where @code{nan == nan}. %% %% Note the type of the arrays is not considered, just their shape %% and values. %% %% @seealso{logical, isAlways, eq (==), isequaln} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = isequal(x, y, varargin) % isequal does not care about type, but if you wanted it to... %if ( ~ ( isa (x, 'sym') && isa (y, 'sym'))) % t = false; % return %end if (any (any (isnan (x)))) % at least on sympy 0.7.4, 0.7.5, nan == nan is true so we % detect is ourselves t = false; else t = isequaln(x, y, varargin{:}); end end %!test %! a = sym([1 2]); %! b = a; %! assert (isequal (a, b)) %! b(1) = 42; %! assert (~isequal (a, b)) %!test %! a = sym([1 2; 3 4]); %! b = a; %! assert (isequal (a, b)) %! b(1) = 42; %! assert (~isequal (a, b)) %!test %! a = sym([nan; 2]); %! b = a; %! assert (~isequal (a, b)) %!test %! % proper nan treatment %! a = sym([nan 2; 3 4]); %! b = a; %! assert (~isequal (a, b)) %!test %! % more than two arrays %! a = sym([1 2 3]); %! b = a; %! c = a; %! assert (isequal (a, b, c)) %! c(1) = 42; %! assert (~isequal (a, b, c)) symbolic-2.2.4/inst/@sym/numel.m0000644000175000001440000000234112633614672015215 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{n} =} numel (@var{x}) %% Return number of elements in symbolic array. %% %% @seealso{length,size} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function n = numel(x) %disp('numel call') d = size(x); n = prod(d); end %!test %! a = sym([1 2 3]); %! assert(numel(a) == 3); %!test %! % 2D array %! a = sym([1 2 3; 4 5 6]); %! assert(numel(a) == 6); %!test %! % empty %! a = sym([]); %! assert(numel(a) == 0); symbolic-2.2.4/inst/@sym/svd.m0000644000175000001440000000423412633614672014674 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{S} =} svd (@var{A}) %% @deftypefnx {Function File} {@var{U}, @var{S}, @var{V} =} svd (@var{A}) %% Symbolic singular value decomposition. %% %% The SVD: %% U*S*V' = A %% %% FIXME: currently only singular values, not singular vectors. %% Should add full SVD to sympy. %% %% @seealso{eig} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [S, varargout] = svd(A) if (nargin >= 2) error('svd: economy-size not supported yet') end if (nargout >= 2) error('svd: singular vectors not yet computed by sympy') end cmd = { '(A,) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'L = sp.Matrix(A.singular_values())' 'return L,' }; S = python_cmd (cmd, sym(A)); end %!test %! % basic %! A = [1 2; 3 4]; %! B = sym(A); %! sd = svd(A); %! s = svd(B); %! s2 = double(s); %! assert (norm(s2 - sd) <= 10*eps) %!test %! % scalars %! syms x %! syms y positive %! a = sym(-10); %! assert (isequal (svd(a), sym(10))) %! assert (isequal (svd(x), sqrt(x*conj(x)))) %! assert (isequal (svd(y), y)) %!test %! % matrix with symbols %! syms x positive %! A = [x+1 0; sym(0) 2*x+1]; %! s = svd(A); %! s2 = subs(s, x, 2); %! assert (isequal (s2, [sym(5); 3])) %! s = simplify(factor(s)); %! assert (isequal (s, [2*x+1; x+1])) %%!test %%! % no sing vecs %%! A = [x 0; sym(0) 2*x] %%! [u,s,v] = cond(A) %%! assert (false) symbolic-2.2.4/inst/@sym/double.m0000644000175000001440000001125612633614672015354 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} double (@var{x}) %% @deftypefnx {Function File} {@var{y} =} double (@var{x}, false) %% Convert symbolic to doubles. %% %% Example: %% @example %% @group %% >> x = sym(1) / 3 %% @result{} x = (sym) 1/3 %% >> double (x) %% @result{} ans = 0.33333 %% @end group %% @end example %% %% Despite the name, this is one way to convert a complex sym to %% floating point: %% @example %% @group %% >> z = sym(4i) - 3; %% >> double (z) %% @result{} ans = -3 + 4i %% @end group %% @end example %% %% If conversion fails, you get an error: %% @example %% @group %% >> syms x %% >> double (x) %% @result{} ??? cannot convert to double %% @end group %% @end example %% %% You can pass an optional second argument of @code{false} to %% return an empty array if conversion fails on any component. %% For example: %% @example %% @group %% >> syms x %% >> a = [1 2 x]; %% >> b = double (a, false) %% @result{} b = [](0x0) %% @end group %% @end example %% %% @seealso{sym} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = double(x, failerr) if (nargin == 1) failerr = true; end % FIXME: port to uniop? if ~(isscalar(x)) % sympy N() works fine on matrices but it gives objects like "Matrix([[1.0,2.0]])" y = zeros(size(x)); for j = 1:numel(x) % temp = x(j) (Issue #17) idx.type = '()'; idx.subs = {j}; temp = double(subsref(x,idx), failerr); if (isempty(temp)) y = []; return end y(j) = temp; end return end cmd = { '(x,) = _ins' ... '# special case for zoo, FIXME: good idea?' ... 'if x == zoo:' ... ' return (1, float(sp.oo), 0.0)' ... 'try:' ... ' z = float(x)' ... 'except TypeError:' ... ' flag = 0' ... 'else:' ... ' flag = 1;' ... ' return (flag, z, 0.0)' ... 'if flag == 0:' ... ' try:' ... ' z = complex(x)' ... ' except TypeError:' ... ' flag = 0' ... ' else:' ... ' flag = 2;' ... ' return (flag, z.real, z.imag)' ... 'return (0, 0.0, 0.0)' }; [flag, A, B] = python_cmd (cmd, x); assert(isnumeric(flag)) assert(isnumeric(A)) assert(isnumeric(B)) if (flag==0) if (failerr) error('OctSymPy:double:conversion', 'cannot convert to double'); else y = []; end elseif (flag==1) y = A; elseif (flag==2) y = A + 1i*B; else error('whut?'); end end %!test %! % numeric scalar %! a = double(sym(10)); %! assert (a == 10) %! assert (isa (a, 'double')) %!test %! % numeric vectors %! a = double(sym([10 12])); %! assert (isequal (a, [10 12])) %! assert (isa (a, 'double')) %!test %! % optional second argument to return empty on failure %! assert (isempty (double (sym('x'), false))) %! assert (isempty (double (sym([10 12 sym('x')]), false))) %!test %! % complex %! a = 3 + 4i; %! b = sym(a); %! assert (isequal (double (b), a)) %!xtest %! % unexpected, precisely same floating point %! a = 3 + 4i; %! b = sym(a); %! assert (isequal (double (b/pi), a/pi)) %!test %! % floating point %! x = sqrt(sym(2)); %! assert( abs(double(x) - sqrt(2)) < 2*eps) %! x = sym(pi); %! assert( abs(double(x) - pi) < 2*eps) %!test %! % various infinities %! oo = sym(inf); %! zoo = sym('zoo'); %! assert( double(oo) == inf ) %! assert( double(-oo) == -inf ) %! assert( double(zoo) == inf ) %! assert( double(-zoo) == inf ) %! assert( isnan(double(0*oo)) ) %! assert( isnan(double(0*zoo)) ) %!test %! % nan %! snan = sym(nan); %! assert( isnan(double(snan))) %!test %! % arrays %! a = [1 2; 3 4]; %! assert( isequal( double(sym(a)), a )) %! assert( isequal( double(sym(a)), a )) %! % should fail with error for non-double %!error syms x; double(x) %!error syms x; double([1 2 x]) symbolic-2.2.4/inst/@sym/cross.m0000644000175000001440000000344712633614672015236 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{c} =} cross (@var{a}, @var{b}) %% Symbolic cross product. %% %% Examples: %% @example %% @group %% a = [sym('a1'); sym('a2'); sym('a3')]; %% b = [sym('b1'); sym('b2'); sym('b3')]; %% cross(a, b) %% @result{} (sym 3×1 matrix) %% ⎡a₂⋅b₃ - a₃⋅b₂ ⎤ %% ⎢ ⎥ %% ⎢-a₁⋅b₃ + a₃⋅b₁⎥ %% ⎢ ⎥ %% ⎣a₁⋅b₂ - a₂⋅b₁ ⎦ %% %% cross(a, a) %% @result{} (sym 3×1 matrix) %% ⎡0⎤ %% ⎢ ⎥ %% ⎢0⎥ %% ⎢ ⎥ %% ⎣0⎦ %% @end group %% @end example %% %% @seealso{dot} %% @end deftypefn function c = cross(a, b) cmd = { 'a, b = _ins' 'return a.cross(b),' }; c = python_cmd (cmd, sym(a), sym(b)); end %!test %! a = sym([1; 0; 0]); %! b = sym([0; 1; 0]); %! c = cross(a, b); %! assert (isequal (c, sym([0; 0; 1]))) %!test %! syms x %! a = sym([x; 0; 0]); %! b = sym([0; 1; 0]); %! c = cross(a, b); %! assert (isequal (c, sym([0; 0; x]))) symbolic-2.2.4/inst/@sym/divergence.m0000644000175000001440000000520612633614672016213 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} divergence (@var{F}) %% @deftypefnx {Function File} {@var{g} =} divergence (@var{F}, @var{x}) %% Symbolic divergence of symbolic expression. %% %% Note: assumes @var{x} is a Cartesian coordinate system. %% %% @seealso{gradient, curl, laplacian, jacobian, hessian} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function g = divergence(f,x) assert (isvector(f), 'divergence: defined for vectors') if (nargin == 1) x = symvar(f); end assert (length(f) == length(x), 'divergence: num vars must match vec length') idx1.type='()'; if (iscell(x)) idx2.type='{}'; else idx2.type='()'; end g = sym(0); for i = 1:length(f) idx1.subs={i}; idx2.subs={i}; g = g + diff (subsref(f,idx1), subsref(x,idx2)); end end %!shared x,y,z %! syms x y z %!test %! % 1D %! f = x^2; %! assert (isequal (divergence(f), diff(f,x))) %! assert (isequal (divergence(f,{x}), diff(f,x))) %! assert (isequal (divergence(f,[x]), diff(f,x))) %! assert (isequal (divergence(f,x), diff(f,x))) %!test %! % const %! f = [sym(1); 2; exp(sym(3))]; %! assert (isequal (divergence(f,{x,y,z}), 0)) %! f = [sym(1); 2; exp(sym('c'))]; %! assert (isequal (divergence(f,{x,y,z}), 0)) %!test %! % double const %! f = [1 2]; %! g = sym(0); %! assert (isequal (divergence(f, [x y]), g)) %! % should fail, calls @double: divergence(f, {x y}), g)) %!test %! % 1D fcn in 2d/3d %! f = [x y z]; %! assert (isequal (divergence(f), 3)) %! assert (isequal (divergence(f, {x,y,z}), 3)) %! assert (isequal (divergence(f, [x,y,z]), 3)) %!test %! % 2d fcn in 2d/3d %! f = sin(exp(x)*y+sinh(z)); %! g2 = [diff(f,x); diff(f,y)]; %! l2 = diff(g2(1),x) + diff(g2(2),y); %! g3 = [diff(f,x); diff(f,y); diff(f,z)]; %! l3 = diff(g3(1),x) + diff(g3(2),y) + diff(g3(3),z); %! assert (isequal (divergence(g2, {x,y}), l2)) %! assert (isequal (divergence(g3, {x,y,z}), l3)) symbolic-2.2.4/inst/@sym/abs.m0000644000175000001440000000253612633614672014650 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} abs (@var{x}) %% Symbolic abs function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = abs(x) y = uniop_helper (x, 'Abs'); end %!shared x, d %! d = -1; %! x = sym('-1'); %!test %! f1 = abs(x); %! f2 = abs(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = abs(A); %! f2 = abs(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/degree.m0000644000175000001440000000441612633614672015335 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{n} =} degree (@var{p}) %% @deftypefnx {Function File} {@var{n} =} degree (@var{p}, @var{x}) %% Extract numerator and demoninator of symbolic expression. %% %% Examples: %% @example %% @group %% syms x %% degree(x^2 + 6) %% @result{} (sym) 2 %% @end group %% @end example %% %% You can specify the variable or rely on the @code{symvar} default: %% @example %% @group %% syms x y %% degree(x^2 + y*x + 1) %% @result{} (sym) 2 %% degree(x^2 + y*x + 1, x) %% @result{} (sym) 2 %% degree(x^2 + y*x + 1, y) %% @result{} (sym) 1 %% @end group %% @end example %% %% FIXME: @code{degree(x^n, x)} does not work here (nor in SMT). %% %% @seealso{sym2poly, poly2sym} %% @end deftypefn function n = degree(p, x) if (nargin == 1) x = symvar(p, 1); end if (isempty(x)) % degree will fail if p is constant and no generator given x = sym('x'); end n = python_cmd ('return sympy.degree(*_ins),', sym(p), sym(x)); end %!test %! syms x %! assert (isequal (degree(x^3), 3)) %! assert (isequal (degree(x^3 + 6), 3)) %!test %! % specify variable %! syms x y %! p = x^2 + y*x + 1; %! assert (isequal (degree(p), 2)) %! assert (isequal (degree(p, x), 2)) %! assert (isequal (degree(p, y), 1)) %!test %! syms x a oo %! assert (isequal (degree(x^3, a), 0)) %! assert (isequal (degree(sym(1), a), 0)) %! assert (isequal (degree(sym(0), a), -oo)) %!xtest %! % constant inputs %! syms oo %! assert (isequal (degree(sym(1)), 0)) %! assert (isequal (degree(sym(0)), -oo)) symbolic-2.2.4/inst/@sym/cos.m0000644000175000001440000000253412633614672014665 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} cos (@var{x}) %% Symbolic cos function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = cos(x) y = uniop_helper (x, 'cos'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = cos(x); %! f2 = cos(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = cos(A); %! f2 = cos(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/taylor.m0000644000175000001440000001132412633614672015410 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{g} =} taylor (@var{f}) %% @deftypefnx {Function File} {@var{g} =} taylor (@var{f}, @var{x}) %% @deftypefnx {Function File} {@var{g} =} taylor (@var{f}, @var{x}, @var{a}) %% @deftypefnx {Function File} {@var{g} =} taylor (@dots{}, @var{key}, @var{value}) %% Symbolic Taylor series. %% %% If omitted, @var{x} is chosen with @code{symvar} and @var{a} %% defaults to zero. %% %% Key/value pairs can be used to set the order: %% @example %% @group %% >> syms x %% >> f = exp(x); %% >> taylor(f, x, 0, 'order', 6) %% @result{} (sym) %% 5 4 3 2 %% x x x x %% ─── + ── + ── + ── + x + 1 %% 120 24 6 2 %% @end group %% @end example %% %% As an alternative to passing @var{a}), you can also set the %% expansion point using a key/value notation: %% @example %% @group %% >> taylor(f, 'expansionPoint', 1, 'order', 4) %% @result{} (sym) %% 3 2 %% ℯ⋅(x - 1) ℯ⋅(x - 1) %% ────────── + ────────── + ℯ⋅(x - 1) + ℯ %% 6 2 %% @end group %% @end example %% @seealso{diff} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, differentiation function s = taylor(f, varargin) if (nargin == 1) % taylor(f) x = symvar(f,1); a = sym(0); i = 1; elseif (nargin == 2) % taylor(f,x) x = varargin{1}; a = sym(0); i = 2; elseif (~ischar(varargin{1}) && ~ischar(varargin{2})) % taylor(f,x,a,...) x = varargin{1}; a = varargin{2}; i = 3; elseif (~ischar(varargin{1}) && ischar(varargin{2})) % taylor(f,x,'param') x = varargin{1}; a = sym(0); i = 2; else % taylor(f,'param') assert (ischar(varargin{1})) x = symvar(f,1); a = sym(0); i = 1; end n = 6; %default order while (i <= (nargin-1)) if (strcmpi(varargin{i}, 'order')) n = varargin{i+1}; i = i + 2; elseif (strcmpi(varargin{i}, 'expansionPoint')) a = varargin{i+1}; i = i + 2; else error('invalid key/value pair') end end if (isfloat(n)) n = int32(n); end if (numel(x) > 1) warning('FIXME: Issue #31 multivar Taylor expansions not implemented') end cmd = { '(f, x, a, n) = _ins' 's = f.series(x, a, n).removeO()' 'return s,' }; s = python_cmd (cmd, sym(f), sym(x), sym(a), n); end %!test %! syms x %! f = exp(x); %! expected = 1 + x + x^2/2 + x^3/6 + x^4/24 + x^5/120; %! assert (isequal (taylor(f), expected)) %! assert (isequal (taylor(f,x), expected)) %! assert (isequal (taylor(f,x,0), expected)) %!test %! syms x %! f = exp(x); %! expected = 1 + x + x^2/2 + x^3/6 + x^4/24; %! assert (isequal (taylor(f,'order',5), expected)) %! assert (isequal (taylor(f,x,'order',5), expected)) %! assert (isequal (taylor(f,x,0,'order',5), expected)) %!test %! % key/value ordering doesn't matter %! syms x %! f = exp(x); %! g1 = taylor(f, 'expansionPoint', 1, 'order', 3); %! g2 = taylor(f, 'order', 3, 'expansionPoint', 1); %! assert (isequal (g1, g2)) %!test %! syms x %! f = x^2; %! assert (isequal (taylor(f,x,0,'order',0), 0)) %! assert (isequal (taylor(f,x,0,'order',1), 0)) %! assert (isequal (taylor(f,x,0,'order',2), 0)) %! assert (isequal (taylor(f,x,0,'order',3), x^2)) %! assert (isequal (taylor(f,x,0,'order',4), x^2)) %!test %! % syms for a and order %! syms x %! f = x^2; %! assert (isequal (taylor(f,x,sym(0),'order',sym(2)), 0)) %! assert (isequal (taylor(f,x,sym(0),'order',sym(4)), x^2)) %!test %! % expansion point %! syms x a %! f = x^2; %! g = taylor(f,x,2); %! assert (isequal (simplify(g), f)) %! assert (isequal (g, 4*x+(x-2)^2-4)) %! g = taylor(f,x,a); %! assert (isequal (simplify(g), f)) %!xtest %! % wrong order-1 series with nonzero expansion pt: %! % upstream bug https://github.com/sympy/sympy/issues/9351 %! syms x %! g = x^2 + 2*x + 3; %! h = taylor (g, x, 4, 'order', 1); %! assert (isequal (h, 27)) symbolic-2.2.4/inst/@sym/lhs.m0000644000175000001440000000435512633614672014672 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{L} =} lhs (@var{f}) %% Left-hand side of symbolic expression. %% %% Gives an error if any of the symbolic objects have no left-hand side. %% %% @seealso{rhs, children} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function L = lhs(f) cmd = { 'f, = _ins' 'flag = 0' 'r = 0' 'if f.is_Matrix:' ' try:' ' r = f.applyfunc(lambda a: a.lhs)' ' except:' ' flag = 1' 'else:' ' try:' ' r = f.lhs' ' except:' ' flag = 1' 'return (flag, r)' }; [flag, L] = python_cmd (cmd, f); if (flag) error('lhs: one or more entries have no ''lhs'' attribute') end end %!test %! syms x y %! f = x + 1 == 2*y; %! assert (isequal (lhs(f), x + 1)) %! assert (isequal (rhs(f), 2*y)) %!test %! syms x y %! f = x + 1 < 2*y; %! assert (isequal (lhs(f), x + 1)) %! assert (isequal (rhs(f), 2*y)) %!test %! syms x y %! f = x + 1 >= 2*y; %! assert (isequal (lhs(f), x + 1)) %! assert (isequal (rhs(f), 2*y)) %!test %! syms x y %! A = [x == y 2*x < 2*y; 3*x > 3*y 4*x <= 4*y; 5*x >= 5*y x < 0]; %! L = [x 2*x; 3*x 4*x; 5*x x]; %! R = [y 2*y; 3*y 4*y; 5*y 0]; %! assert (isequal( lhs(A), L)) %! assert (isequal( rhs(A), R)) %!error %! syms x %! lhs(x) %!error %! syms x %! rhs(x) %!error %! lhs(sym(true)) %!error %! syms x %! A = [1 + x == 2*x sym(6)]; %! lhs(A) symbolic-2.2.4/inst/@sym/rdivide.m0000644000175000001440000000457112633614672015532 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} rdivide (@var{x}, @var{y}) %% Elementwise forward slash division of sym expressions (dot slash). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = rdivide(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = rdivide(x, y); return end cmd = { '(x,y) = _ins' 'if x.is_Matrix and y.is_Matrix:' ' return x.multiply_elementwise(y.applyfunc(lambda a: 1/a)),' 'if not x.is_Matrix and y.is_Matrix:' ' return y.applyfunc(lambda a: x/a),' 'else:' ' return x/y,' }; z = python_cmd (cmd, sym(x), sym(y)); end %!test %! % scalar %! syms x %! assert (isa (x ./ 1, 'sym')) %! assert (isa (x ./ x, 'sym')) %! assert (isequal (x ./ 1, x)) %! assert (isequal (x ./ x, sym(1))) %!test %! % matrix-scalar %! D = 2*[0 1; 2 3]; %! A = sym(D); %! assert (isequal ( A./2 , D/2 )) %! assert (isequal ( A./sym(2) , D/2 )) %! assert (isequal ( D./sym(2) , D/2 )) %!test %! % matrix ./ matrix %! D = [1 2; 3 4]; %! A = sym(D); %! assert (isequal ( A./A , D./D )) %! assert (isequal ( A./D , D./D )) %! assert (isequal ( D./A , D./D )) %!test %! % matrix ./ matrix with symbols %! syms x y %! A = [x y; x^2 2*y]; %! B = [y x; x y]; %! assert (isequal ( A./A , sym(ones(2,2)) )) %! assert (isequal ( A./B , [x/y y/x; x 2] )) %!test %! % scalar ./ matrix %! D = [1 2; 3 4]; %! A = sym(D); %! assert (isequal ( 12./A , 12./D )) symbolic-2.2.4/inst/@sym/isvector.m0000644000175000001440000000242512633614672015736 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{b} =} isvector (@var{x}) %% Return true if this symbolic expression is a vector. %% %% @seealso{size, numel, isscalar} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function b = isvector(x) d = size(x); b = any(d == 1); end %!assert(isvector(sym('x'))) %!assert(isvector(sym([1 2 3]))) %!assert(isvector(sym([1; 2]))) %!assert(~isvector(sym([1 2; 3 4]))) %!assert(~isvector(sym([]))) %!assert(isvector(sym(ones(1,0)))) %!assert(~isvector(sym(ones(0,3)))) symbolic-2.2.4/inst/@sym/ne.m0000644000175000001440000000376112633614672014506 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} ne (@var{a}, @var{b}) %% Test/define symbolic inequality, not equal to. %% %% @seealso{eq, lt, le, gt, ge, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = ne(x,y) % nanspecial is (python) 'True' here b/c nan is not equal % to everything, even itself. t = ineq_helper('[donotuse]', 'Ne', x, y, 'S.true'); end %!test %! % simple %! x = sym(1); y = sym(1); e = x ~= y; %! assert (~logical (e)) %! x = sym(1); y = sym(2); e = x ~= y; %! assert (logical(e)) %!xtest %! % array -- array %! syms x %! a = sym([1 3 3 2*x]); %! b = sym([2 x 3 10]); %! e = a ~= b; %! assert (isa (e, 'sym')) %! assert (logical (e(1))) %! assert (isa (e(2), 'sym')) %! assert (isequal (e(2), 3 ~= x)) %! assert (~logical (e(3))) %! assert (isa (e(4), 'sym')) %! assert (isequal (e(4), 2*x ~= 10)) %!test %! % oo %! syms oo x %! e = oo ~= x; %! assert (isa (e, 'sym')) %! s = strtrim (disp (e, 'flat')); %! % SymPy <= 0.7.6.x will be '!=', newer gives 'Ne', test both %! assert (strcmp (s, 'oo != x') || strcmp (s, 'Ne(oo, x)')) %!test %! % nan %! syms oo x %! snan = sym(nan); %! e = snan ~= sym(0); %! assert (logical (e)) %! e = snan ~= snan; %! assert (logical (e)) symbolic-2.2.4/inst/@sym/simplify.m0000644000175000001440000000316512633614672015736 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} simplify (@var{x}) %% Simplify an expression. %% %% Example: %% @example %% @group %% >> syms x %% >> p = x^2 + x + 1 %% @result{} p = (sym) %% 2 %% x + x + 1 %% >> q = horner (p) %% @result{} q = (sym) x⋅(x + 1) + 1 %% >> d = p - q %% @result{} d = (sym) %% 2 %% x - x⋅(x + 1) + x %% %% >> isAlways(p == q) %% @result{} 1 %% %% >> simplify(p - q) %% @result{} (sym) 0 %% @end group %% @end example %% %% FIXME: SymPy has other operations to manipulate expressions, %% should provide those too. %% %% @seealso{isAlways} %% @end deftypefn function y = simplify(x) cmd = 'return sp.simplify(*_ins),'; y = python_cmd (cmd, x); end %!shared x,p,q %! syms x %! p = x^2 + x + 1; %! q = horner (p); %!assert(~isequal( p - q, 0)) %!assert(isequal( simplify(p - q), 0)) symbolic-2.2.4/inst/@sym/ceil.m0000644000175000001440000000255312633614672015016 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} ceil (@var{x}) %% Symbolic ceil function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = ceil(x) y = uniop_helper (x, 'ceiling'); end %!shared x, d %! d = 3/2; %! x = sym('3/2'); %!test %! f1 = ceil(x); %! f2 = ceil(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = ceil(A); %! f2 = ceil(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/curl.m0000644000175000001440000000561012633614672015044 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{f} =} curl (@var{G}) %% @deftypefnx {Function File} {@var{f} =} curl (@var{G}, @var{x}) %% Symbolic curl of symbolic expression. %% %% @var{G} and @var{x} should be vectors of length three. %% If omitted, @var{x} is determined using @code{symvar}. %% %% Note: assumes @var{x} is a Cartesian coordinate system. %% %% @seealso{divergence, gradient, laplacian, jacobian, hessian} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function g = curl(v,x) assert(isvector(v) && length(v)==3, 'curl is for 3D vector fields') if (nargin == 1) x = symvar(v, 3); end assert(length(x)==3, 'coordinate system should have three components') % ugh issue 17 so do in python to avoid cmd = { '(v, x) = _ins' 'def d(u, y):' ' if u.is_constant():' % FIXME ? ' return sp.numbers.Zero()' ' return u.diff(y)' 'g = Matrix([ \' ' d(v[2], x[1]) - d(v[1], x[2]), \' ' d(v[0], x[2]) - d(v[2], x[0]), \' ' d(v[1], x[0]) - d(v[0], x[1]) ])' 'return g,' }; g = python_cmd (cmd, sym(v), x); end %!shared x,y,z %! syms x y z %!test %! % double const %! f = [1 2 3]; %! g = [sym(0); 0; 0]; %! assert (isequal (curl(f, [x y z]), g)) %! % should fail, calls @double: curl(f, {x y z}), g)) %!test %! % div curl always 0 %! v = [exp(x); x*y; sin(z)]; %! g = curl(v); %! a = divergence(g, [x y z]); %! assert (isAlways (a == sym(0))) %! assert (isa (a, 'sym')) %! g = curl(v, [x y z]); %! a = divergence(g, [x y z]); %! assert (isAlways (a == sym(0))) %! assert (isa (a, 'sym')) %!test %! % div curl always 0 %! v = [exp(x); erfc(x*y); sin(exp(x)*y+sinh(z))]; %! g = curl(v, [x y z]); %! a = divergence(g, [x y z]); %! assert (isAlways (a == sym(0))) %! assert (isa (a, 'sym')) %!test %! % curl grad is vec zero %! f = sin(exp(x)*y+sinh(z)); %! g = curl(gradient(f, [x,y,z])); %! assert (isequal (g, sym([0;0;0]))) %!test %! % 2d fcn in 2d/3d %! u = sin(exp(x)*y); %! v = x^2*y^3; %! vorticity2d = diff(v,x) - diff(u,y); %! omega = curl([u; v; 0], [x y z]); %! assert (isequal (omega, [0; 0; vorticity2d])) symbolic-2.2.4/inst/@sym/real.m0000644000175000001440000000232312633614672015020 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{x} =} real (@var{z}) %% Real part of a symbolic expression. %% %% @seealso{imag, conj, ctranspose} %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function x = real(z) x = (z + conj(z))/2; end %!assert(isequal(real(sym(4)+3i),4)) %!test %! syms x y real %! z = x + 1i*y; %! assert(isequal(real(z),x)) %!test %! syms x y real %! Z = [4 x + 1i*y; x 4+3i]; %! assert(isequal(real(Z),[4 x; x 4])) symbolic-2.2.4/inst/@sym/exp.m0000644000175000001440000000253412633614672014675 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} exp (@var{x}) %% Symbolic exp function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = exp(x) y = uniop_helper (x, 'exp'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = exp(x); %! f2 = exp(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = exp(A); %! f2 = exp(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/repmat.m0000644000175000001440000000305212633614672015365 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} repmat (@var{A}, @var{n}, @var{m}) %% Build symbolic block matrices. %% %% @seealso{vertcat, horzcat} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function B = repmat(A, n, m) cmd = { '(A,n,m) = _ins' ... 'if not A.is_Matrix:' ... ' A = sp.Matrix([A])' ... 'L = [A]*m' ... 'B = sp.Matrix.hstack(*L)' ... 'L = [B]*n' ... 'B = sp.Matrix.vstack(*L)' ... 'return B,' }; B = python_cmd (cmd, sym(A), int32(n), int32(m)); end %!test %! % simple %! syms x %! A = [x x x; x x x]; %! assert (isequal (repmat(x, 2, 3), A)) %!test %! % block cf double %! A = [1 2 3; 4 5 6]; %! B = sym(A); %! C = repmat(A, 2, 3); %! D = repmat(B, 2, 3); %! assert (isequal (C, D)) symbolic-2.2.4/inst/@sym/gt.m0000644000175000001440000000301112633614672014502 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} gt (@var{a}, @var{b}) %% Test/define symbolic inequality, greater than. %% %% @seealso{lt, le, ge, eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = gt(x, y) t = ineq_helper('>', 'Gt', x, y); end %!test %! % simple %! x = sym(1); y = sym(1); e = x > y; %! assert (~logical (e)) %! x = sym(1); y = sym(2); e = x > y; %! assert (~logical (e)) %!test %! % array -- array %! syms x %! a = sym([1 3 3 2*x]); %! b = sym([2 x 3 10]); %! e = a > b; %! assert (isa (e, 'sym')) %! assert (~logical (e(1))) %! assert (isa (e(2), 'sym')) %! assert (isequal (e(2), 3 > x)) %! assert (~logical (e(3))) %! assert (isa (e(4), 'sym')) %! assert (isequal (e(4), 2*x > 10)) symbolic-2.2.4/inst/@sym/rank.m0000644000175000001440000000262512633614672015035 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} rank (@var{A}) %% Rank of a symbolic matrix. %% %% @seealso{cond, null, orth} %% @end deftypefn function r = rank(A) cmd = { 'A = _ins[0]' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'return A.rank(),' }; r = python_cmd (cmd, A); end %!test %! A = sym([1 2; 3 4]); %! assert (rank(A) == 2); %!test %! A = sym([1 2 3; 3 4 5]); %! assert (rank(A) == 2); %!test %! A = sym([1 2; 1 2]); %! assert (rank(A) == 1); %!test %! A = sym([1 2; 3 4]); %! assert (rank(A) == 2); %!assert (rank(sym(1)) == 1); %!assert (rank(sym(0)) == 0); %!assert (rank(sym('x', 'positive')) == 1); symbolic-2.2.4/inst/@sym/heaviside.m0000644000175000001440000000261612633614672016043 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} heaviside (@var{x}) %% Symbolic heaviside function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = heaviside(x) y = uniop_helper (x, 'Heaviside'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = heaviside(x); %! f2 = 1; %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = heaviside(A); %! f2 = 1; %! f2 = [f2 f2; f2 f2]; %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/jacobian.m0000644000175000001440000000562712633614672015655 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{J} =} jacobian (@var{f}) %% @deftypefnx {Function File} {@var{J} =} jacobian (@var{f}, @var{x}) %% Symbolic Jacobian of symbolic expression. %% %% @var{x} can be a scalar, vector or cell list. If omitted, %% it is determined using @code{symvar}. %% %% @seealso{divergence, gradient, curl, laplacian, hessian} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function g = jacobian(f,x) assert (isvector(f), 'jacobian: defined for vectors expressions') if (nargin == 1) x = symvar(f); if (isempty(x)) x = sym('x'); end end if (~iscell(x) && isscalar(x)) x = {x}; end cmd = { '(f, x) = _ins' 'if not f.is_Matrix:' ' f = Matrix([f])' 'G = f.jacobian(x)' 'return G,' }; g = python_cmd (cmd, sym(f), x); end %!shared x,y,z %! syms x y z %!test %! % 1D %! f = x^2; %! assert (isequal (jacobian(f), diff(f,x))) %! assert (isequal (jacobian(f,{x}), diff(f,x))) %! assert (isequal (jacobian(f,x), diff(f,x))) %!test %! % const %! f = sym(1); %! g = sym(0); %! assert (isequal (jacobian(f), g)) %! assert (isequal (jacobian(f,x), g)) %!test %! % double const %! f = 1; %! g = sym(0); %! assert (isequal (jacobian(f,x), g)) %!test %! % diag %! f = [x y^2]; %! g = [sym(1) 0; 0 2*y]; %! assert (isequal (jacobian(f), g)) %! assert (isequal (jacobian(f, [x y]), g)) %! assert (isequal (jacobian(f, {x y}), g)) %!test %! % anti-diag %! f = [y^2 x]; %! g = [0 2*y; sym(1) 0]; %! assert (isequal (jacobian(f), g)) %! assert (isequal (jacobian(f, {x y}), g)) %!test %! % shape %! f = [x y^2]; %! assert (isequal (size(jacobian(f, {x y z})), [2 3])) %! assert (isequal (size(jacobian(f, [x y z])), [2 3])) %! assert (isequal (size(jacobian(f, [x; y; z])), [2 3])) %! assert (isequal (size(jacobian(f.', {x y z})), [2 3])) %!test %! % scalar f %! f = x*y; %! assert (isequal (size(jacobian(f, {x y})), [1 2])) %! g = gradient(f, {x y}); %! assert (isequal (jacobian(f, {x y}), g.')) %!test %! % vect f wrt 1 var %! f = [x x^2]; %! assert (isequal (size(jacobian(f, x)), [2 1])) %! f = f.'; % same shape output %! assert (isequal (size(jacobian(f, x)), [2 1])) symbolic-2.2.4/inst/@sym/acoth.m0000644000175000001440000000255412633614672015201 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} acoth (@var{x}) %% Symbolic acoth function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = acoth(x) y = uniop_helper (x, 'acoth'); end %!shared x, d %! d = 2; %! x = sym('2'); %!test %! f1 = acoth(x); %! f2 = acoth(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = acoth(A); %! f2 = acoth(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/gradient.m0000644000175000001440000000647012633614672015701 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{G} =} gradient (@var{f}) %% @deftypefnx {Function File} {@var{G} =} gradient (@var{f}, @var{x}) %% Symbolic gradient of symbolic expression. %% %% @var{x} can be a scalar, vector or cell list. If omitted, %% it is determined using @code{symvar}. %% %% Note: assumes @var{x} is a Cartesian coordinate system. %% %% @seealso{divergence, curl, laplacian, jacobian, hessian} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function g = gradient(f,x) assert (isscalar(f), 'gradient: defined for scalar functions') if (nargin == 1) x = symvar(f); if (isempty(x)) x = sym('x'); end end if (~iscell(x) && isscalar(x)) x = {x}; end cmd = { '(f, x) = _ins' 'if not f.is_Matrix:' ' f = Matrix([f])' 'G = f.jacobian(x).T' 'return G,' }; g = python_cmd (cmd, sym(f), x); end %!shared x,y,z %! syms x y z %!test %! % 1D %! f = x^2; %! assert (isequal (gradient(f), diff(f,x))) %! assert (isequal (gradient(f,{x}), diff(f,x))) %! assert (isequal (gradient(f,[x]), diff(f,x))) %! assert (isequal (gradient(f,x), diff(f,x))) %!test %! % const %! f = sym(1); %! g = sym(0); %! assert (isequal (gradient(f), g)) %! assert (isequal (gradient(f,x), g)) %!test %! % double const %! f = 1; %! g = sym(0); %! assert (isequal (gradient(f,x), g)) %!test %! % 1D fcn in 2d/3d %! f = sin(y); %! assert (isequal (gradient(f), diff(f,y))) %! assert (isequal (gradient(f, {x,y}), [sym(0); diff(f,y)])) %! assert (isequal (gradient(f, [x y]), [sym(0); diff(f,y)])) %! assert (isequal (size (gradient(f, {x,y})), [2 1])) %! assert (isequal (gradient(f, {x,y,z}), [0; diff(f,y); 0])) %! assert (isequal (gradient(f, [x y z]), [0; diff(f,y); 0])) %! assert (isequal (size (gradient(f, {x,y,z})), [3 1])) %!test %! % grad is column vector %! f = sin(y); %! assert (isequal (size (gradient(f, {x,y})), [2 1])) %! assert (isequal (size (gradient(f, {x,y,z})), [3 1])) %! assert (isequal (size (gradient(f, [x y])), [2 1])) %! assert (isequal (size (gradient(f, [x;y])), [2 1])) %!test %! % 2d fcn in 2d/3d %! f = sin(exp(x)*y); %! g2 = [diff(f,x); diff(f,y)]; %! g3 = [diff(f,x); diff(f,y); diff(f,z)]; %! assert (isequal (gradient(f), g2)) %! assert (isequal (gradient(f, {x,y}), g2)) %! assert (isequal (gradient(f, {x,y,z}), g3)) %!test %! % 2d fcn in 2d/3d %! f = sin(exp(x)*y+sinh(z)); %! g2 = [diff(f,x); diff(f,y)]; %! g3 = [diff(f,x); diff(f,y); diff(f,z)]; %! assert (isequal (gradient(f), g3)) %! assert (isequal (gradient(f, {x,y}), g2)) %! assert (isequal (gradient(f, {x,y,z}), g3)) symbolic-2.2.4/inst/@sym/sqrt.m0000644000175000001440000000254412633614672015073 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} sqrt (@var{x}) %% Symbolic sqrt function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = sqrt(x) y = uniop_helper (x, 'sqrt'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = sqrt(x); %! f2 = sqrt(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = sqrt(A); %! f2 = sqrt(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/factor.m0000644000175000001440000000563112633614672015360 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} factor (@var{f}) %% @deftypefnx {Function File} {[@var{p},@var{m}] =} factor (@var{f}) %% Factor a symbolic polynomial or integer. %% %% @seealso{expand} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function [p, m] = factor(f) % FIXME: doc: SMT does not expose vector output? Strange, given Matlab's % factor(double) command! if (isempty (findsymbols (f))) %% No syms, integer factorization if (nargout <= 1) if (~isscalar(f)) error('FIXME: check SMT, allows array input here?') end % FIXME: this is fragile, even pretty(y) causes it to expand % SMT is less fragile. Can we do something to force % evaluate=False to persist here? p = python_cmd ('return factorint(_ins[0], visual=True),', f); else if (~isscalar(f)) error('vector output factorization only for scalar integers') end cmd = { 'd = factorint(_ins[0], visual=False)' 'num = len(d.keys())' 'sk = sorted(d.keys())' 'p = sp.Matrix(1, num, sk)' 'm = sp.Matrix(1, num, lambda i,j: d[sk[j]])' 'return (p, m)' }; [p, m] = python_cmd (cmd, f); end else %% symbols, polynomial factorization % FIXME; symvar? optional 2nd argument cmd = { 'p = factor(_ins[0])' 'return p,' }; p = python_cmd (cmd, f); end end %!test %! % n = 152862; %! % [p,m] = factor(n); % only works on Octave, no Matlab as of 2014a %! n = 330; % so we use an output without repeated factors %! p = factor(n); m = ones(size(p)); %! [ps,ms] = factor(sym(n)); %! assert (isequal (p, ps)) %! assert (isequal (m, ms)) %!test %! n = sym(2)^4*13; %! [p,m] = factor(n); %! assert (isequal (p, [2 13])) %! assert (isequal (m, [4 1])) %!test syms x %! assert( logical (factor(x^2 + 6*x + 5) == (x+5)*(x+1))) %!test %! syms x %! f = [ x^4/2 + 5*x^3/12 - x^2/3 x^2 - 1 10]; %! g = [ x^2*(2*x - 1)*(3*x + 4)/12 (x+1)*(x-1) 10]; %! assert (isequal (factor(f), g)) %!test %! % "fragile form" works %! A = factor(sym(124)); %! B = strtrim(disp(A, 'flat')); %! assert (strcmp (B, '2**2*31**1')) symbolic-2.2.4/inst/@sym/pretty.m0000644000175000001440000000447412633614672015435 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} pretty (@var{x}) %% @deftypefnx {Function File} {@var{s} =} pretty (@var{x}) %% Return/display ASCII-art/unicode representation of expression. %% %% This is usually the same as @code{disp(x)}, unless you have %% @code{sympref display flat}, in which case %% @code{pretty(x)} displays ASCII-art. You can force unicode %% with @code{pretty(x, 'unicode')}. %% %% Note: pretty(x) works like disp(x) (makes output even if has a %% semicolon) %% %% @code{pretty} exists mainly for compatibility with the %% Symbolic Math Toolbox. %% %% @seealso{disp, latex} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = pretty(x, wh) if (nargin == 1) % read config to see how to display x wh = sympref('display'); end % if config says flat, pretty does ascii if (strcmp('flat', lower(wh))) wh = 'ascii'; end if (nargout == 0) disp(x, wh) else varargout{1} = disp(x, wh); end end %!test %! % simple %! syms x %! s1 = pretty(sin(x)); %! s2 = sprintf(' sin(x)\n'); %! assert (strcmp (s1, s2)) %!test %! % force ascii %! syms x %! s1 = pretty(sin(x/2), 'ascii'); %! s2 = sprintf(' /x\\\n sin|-|\n \\2/\n'); %! swin = strrep(s1, sprintf('\r\n'), sprintf('\n')); %! assert (strcmp (s1, s2) || strcmp (swin, s2)) %!test %! % force unicode %! syms x %! s1 = pretty(sin(x/2), 'unicode'); %! s2 = sprintf(' ⎛x⎞\n sin⎜─⎟\n ⎝2⎠\n'); %! swin = strrep(s1, sprintf('\r\n'), sprintf('\n')); %! assert (strcmp (s1, s2) || strcmp (swin, s2)) symbolic-2.2.4/inst/@sym/plus.m0000644000175000001440000000327612633614672015070 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} plus (@var{x}, @var{y}) %% Add two symbolic expressions together (+). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = plus(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = plus(x, y); return end z = axplusy(1, x, y); end %!test %! % basic addition %! syms x %! assert (isa (x+5, 'sym')) %! assert (isa (5+x, 'sym')) %! assert (isa (5+sym(4), 'sym')) %! assert (isequal (5+sym(4), sym(9))) %!test %! % array addition %! syms x %! D = [0 1; 2 3]; %! A = [sym(0) 1; sym(2) 3]; %! DZ = D - D; %! assert( isequal ( A + D , 2*D )) %! assert( isequal ( D + A , 2*D )) %! assert( isequal ( A + A , 2*D )) %! assert( isequal ( A + 2 , D + 2 )) %! assert( isequal ( 4 + A , 4 + D )) symbolic-2.2.4/inst/@sym/flipud.m0000644000175000001440000000310212633614672015354 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} flipud (@var{A}) %% Flip a symbolic matrix vertically. %% %% @seealso{fliplr, reshape} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function B = flipud(A) cmd = { '(A,) = _ins' ... 'if not A.is_Matrix:' ... ' A = sp.Matrix([A])' ... 'm, _ = A.shape' ... 'for i in range(0, int(m/2)):' ... ' A.row_swap(i, m-i-1)' ... 'return A,' }; B = python_cmd (cmd, sym(A)); end %!test %! % simple %! syms x %! A = [x 2; sym(pi) x]; %! B = [sym(pi) x; x 2]; %! assert (isequal (flipud(A), B)) %!test %! % simple, odd # rows %! syms x %! A = [x 2; sym(pi) x; [1 2]]; %! B = [[1 2]; sym(pi) x; x 2]; %! assert (isequal (flipud(A), B)) %!test %! % scalar %! syms x %! assert (isequal (flipud(x), x)) symbolic-2.2.4/inst/@sym/inv.m0000644000175000001440000000272112633614672014673 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} inv (@var{A}) %% Symbolic inverse of a matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = inv(x) [n,m] = size(x); if n ~= m error('matrix is not square') end cmd = { 'x, = _ins' 'if x.is_Matrix:' ' return x.inv(),' 'else:' ' return S.One/x,' }; z = python_cmd (cmd, x); end %!test %! % scalar %! syms x %! assert (isequal (inv(x), 1/x)) %!test %! % diagonal %! syms x %! A = [sym(1) 0; 0 x]; %! B = [sym(1) 0; 0 1/x]; %! assert (isequal (inv(A), B)) %!test %! % 2x2 inverse %! A = [1 2; 3 4]; %! assert (max (max (abs (double (inv (sym (A))) - inv(A)))) <= 3*eps) symbolic-2.2.4/inst/@sym/null.m0000644000175000001440000000272312633614672015053 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} null (@var{A}) %% Basis for the nullspace of a symbolic matrix. %% %% Return a matrix whose columns are a basis for the nullspace of %% the matrix. %% %% @seealso{rank, orth} %% @end deftypefn function r = null(A) cmd = { 'A = _ins[0]' 'if not A.is_Matrix:' ' A = sympy.Matrix([A])' 'ns = A.nullspace()' 'if len(ns) == 0:' ' return sympy.zeros(A.cols, 0),' 'return sympy.Matrix.hstack(*ns),' }; r = python_cmd (cmd, A); end %!test %! A = sym([1 2; 3 4]); %! assert (isempty (null (A))) %!assert (isempty (null (sym(4)))) %!test %! A = sym([1 2 3; 3 4 5]); %! assert (isequal (null(A), sym([1;-2;1]))) symbolic-2.2.4/inst/@sym/laplace.m0000644000175000001440000001056312633614672015503 0ustar cbmusers%% Copyright (C) 2014 Andrés Prieto %% Copyright (C) 2015 Andrés Prieto, Colin Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{F} =} laplace (@var{f}, @var{t}, @var{s}) %% @deftypefnx {Function File} {@var{F} =} laplace (@var{f}) %% @deftypefnx {Function File} {@var{F} =} laplace (@var{f}, @var{s}) %% Laplace transform. %% %% Example: %% @example %% @group %% >> syms t %% >> f = t^2; %% >> laplace(f) %% @result{} (sym) %% 2 %% ── %% 3 %% s %% @end group %% @end example %% %% By default the ouput is a function of @code{s} (or @code{z} if the Laplace %% transform happens to be with respect to @code{s}). This can be overriden %% by specifying @var{s}. For example: %% @example %% @group %% >> syms t s z %% >> laplace(exp(t)) %% @result{} (sym) %% 1 %% ───── %% s - 1 %% >> laplace(exp(s)) %% @result{} (sym) %% 1 %% ───── %% z - 1 %% >> laplace(exp(t), z) %% @result{} (sym) %% 1 %% ───── %% z - 1 %% @end group %% @end example %% %% @seealso{ilaplace} %% @end deftypefn %% Author: Andrés Prieto %% Keywords: symbolic, integral transforms function F = laplace(varargin) % FIXME: it only works for scalar functions % FIXME: it doesn't handle diff call (see SMT transform of diff calls) % If the physical variable of f is equal to "s", % "z" is the frequency domain variable (analogously to SMT) if (nargin == 1) f = sym(varargin{1}); t = symvar(f, 1); if (isempty(t)) t = sym('t'); end cmd = { 'f=_ins[0]; t=_ins[1]; s=sp.Symbol("s")' 'if t==s:' ' s=sp.Symbol("z")' 'F=sp.laplace_transform(f, t, s)' 'if isinstance(F, sp.LaplaceTransform):' ' return F,' 'else:' ' return F[0],'}; F = python_cmd(cmd, f, t); elseif (nargin == 2) f = sym(varargin{1}); s = sym(varargin{2}); t = symvar(f, 1); % note SMT does something different, prefers t if (isempty(t)) t = sym('t'); end cmd = { 'f=_ins[0]; t=_ins[1]; s=_ins[2]' 'F=sp.laplace_transform(f, t, s)' 'if isinstance(F, sp.LaplaceTransform):' ' return F,' 'else:' ' return F[0],'}; F = python_cmd(cmd, f, t, s); elseif (nargin == 3) f = sym(varargin{1}); t = sym(varargin{2}); s = sym(varargin{3}); cmd = { 'f=_ins[0]; t=_ins[1]; s=_ins[2]' 'F=sp.laplace_transform(f, t, s)' 'if isinstance(F, sp.LaplaceTransform):' ' return F,' 'else:' ' return F[0],'}; F = python_cmd(cmd, f, t, s); else print_usage (); end end %!test %! % basic %! syms t s u w %! assert(logical( laplace(cos(3*t)) == s/(s^2+9) )) %! assert(logical( laplace(t^3) == 6/s^4 )) %!test %! % matlab SMT compat %! syms t s u w z %! assert(logical( laplace(exp(2*t)) == 1/(s-2) )) %! assert(logical( laplace(exp(2*s)) == 1/(z-2) )) %! assert(logical( laplace(exp(2*u),w) == 1/(w-2) )) %! assert(logical( laplace(exp(2*u),u,w) == 1/(w-2) )) %!test %! syms x s t z %! % matlab SMT prefers t over x (WTF not symvar like we do?) %! assert (isequal (laplace(x*exp(t), z), exp(t)/z^2)) %! % as usual, you can just specify: %! assert (isequal (laplace(x*exp(t), t, z), x/(z - 1))) % SMT result %! assert (isequal (laplace(x*exp(t), x, z), exp(t)/z^2)) %!test %! % constant, issue #250 %! syms s %! f = laplace(2, s); %! assert (isequal (f, 2/s)) %!xtest %! % Differential operator to algebraic %! % SymPy cannot evaluate? (Issue #170) %! syms s f(t) %! assert(logical( laplace(diff(f(t),t),t,s) == s*laplace(f(t),t,s)-f(0) )) symbolic-2.2.4/inst/@sym/nchoosek.m0000644000175000001440000000314212633614672015706 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{C} =} nchoosek (@var{n}, @var{k}) %% Symbolic binomial coefficient. %% %% @end deftypefn function C = nchoosek(n, k) if (~isscalar(n)) error('nchoosek: set input for n not implemented'); end assert (isscalar(k), 'nchoosek: k must be scalar'); C = python_cmd ('return sp.binomial(*_ins),', sym(n), sym(k)); end %!assert (isequal (nchoosek(sym(5), sym(2)), sym(10))) %!assert (isequal (nchoosek(sym(5), 2), sym(10))) %!assert (isequal (nchoosek(5, sym(2)), sym(10))) %!assert (isequal (nchoosek(sym(10), 0), 1)) %!assert (isequal (nchoosek(sym(10), -1), 0)) %!test %! n = sym('n', 'integer'); %! q = nchoosek(n, 2); %! w = subs(q, n, 5); %! assert (isequal (w, 10)) %!test %! n = sym('n', 'integer'); %! k = sym('k', 'integer'); %! q = nchoosek(n, k); %! w = subs(q, {n k}, {5 2}); %! assert (isequal (w, 10)) symbolic-2.2.4/inst/@sym/sinh.m0000644000175000001440000000254412633614672015043 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} sinh (@var{x}) %% Symbolic sinh function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = sinh(x) y = uniop_helper (x, 'sinh'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = sinh(x); %! f2 = sinh(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = sinh(A); %! f2 = sinh(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/dsolve.m0000644000175000001440000002041112633614672015367 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald, Andrés Prieto %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{sol} =} dsolve (@var{ode}) %% @deftypefnx {Function File} {@var{sol} =} dsolve (@var{ode}, @var{ics}) %% Solve ordinary differentual equations (ODEs) symbolically. %% %% Many types of ODEs can be solved, including initial-value %% problems and boundary-value problem. Some systems can be %% solved, including initial-value problems involving linear systems %% of first order ODEs with constant coefficients. %% %% *WARNING*: As of SymPy 0.7.6 (May 2015), there are many problems %% with systems, even very simple ones. Use these at your own risk, %% or even better: help us fix SymPy. %% %% FIXME: SMT supports strings like 'Dy + y = 0': we are unlikely %% to support this. %% %% @seealso{int} %% @end deftypefn %% Author: Colin B. Macdonald, Andrés Prieto %% Keywords: symbolic function [soln,classify] = dsolve(ode,varargin) % Usually we cast to sym in the _cmd call, but want to be % careful here b/c of symfuns if (any(~isa(ode, 'sym'))) error('Inputs must be sym or symfun') end % FIXME: might be nice to expose SymPy's "sp.ode.classify_sysode" and % "sp.ode.classify_ode" with their own commands if (isscalar(ode) && nargout==2) classify = python_cmd ('return sp.ode.classify_ode(_ins[0])[0],', ode); elseif(~isscalar(ode) && nargout==2) disp('Classification of systems of ODEs is currently not supported') classify=''; end % FIXME: the initial/boundary conditions admit parameters % but only on their values (not at the evaluation point) % FIXME: it is not currently supported a list of boundary/initial conditions if (isscalar(ode) && nargin>=2) cmd = { 'ode=_ins[0]; ics=_ins[1:]' 'sol=sp.dsolve(ode)' 'x=list(ode.free_symbols)[0]' 'ic_eqs=[]' 'for ic in ics:' ' funcarg=ic.lhs' ' if isinstance(funcarg, sp.Subs):' ' x0=funcarg.point[0]' ' dorder=sp.ode_order(funcarg.expr, x)' ' dsol_eq=sp.Eq(sp.diff(sol.lhs,x,dorder),sp.diff(sol.rhs,x,dorder))' ' dy_at_x0=funcarg.expr.subs(x,x0)' ' ic_eqs.append(dsol_eq.subs(x,x0).subs(dy_at_x0,ic.rhs))' ' elif isinstance(funcarg, sp.function.AppliedUndef):' ' x0=funcarg.args[0]' ' ic_eqs.append(sol.subs(x,x0).subs(funcarg,ic.rhs))' 'sol_C=sp.solve(ic_eqs)' 'if type(sol_C)==dict:' ' sol_final=sol.subs(sol_C)' 'elif type(sol_C)==list:' ' sol_final=[]' ' for c in sol_C:' ' sol_final.append(sol.subs(c))' 'return sol_final,'}; soln = python_cmd (cmd, ode, varargin{:}); % FIXME: only solve initial-value problems involving linear systems % of first order ODEs with constant coefficients (a unique % solution is expected) elseif(~isscalar(ode) && nargin>=2) cmd = { 'ode=_ins[0]; ics=_ins[1:]' 'sol=sp.dsolve(ode)' 'x=list(ode[0].free_symbols)[0]' 'ic_eqs=[]' 'for solu in sol:' ' ic_eqs.append(solu)' ' for ic in ics:' ' funcarg=ic.lhs' ' if isinstance(funcarg, sp.function.AppliedUndef):' ' x0=funcarg.args[0]' ' ic_eqs[-1]=ic_eqs[-1].subs(x,x0).subs(funcarg,ic.rhs)' 'sol_C=sp.solve(ic_eqs)' 'sol_final=[]' 'for y in sol:' ' sol_final.append(y.subs(sol_C))' 'return sol_final,'}; soln = python_cmd (cmd, ode, varargin{:}); elseif(nargin==1) soln = python_cmd ('return sp.dsolve(*_ins),', ode); end end %!test %! syms y(x) %! de = diff(y, 2) - 4*y == 0; %! f = dsolve(de); %! syms C1 C2 %! g1 = C1*exp(-2*x) + C2*exp(2*x); %! g2 = C2*exp(-2*x) + C1*exp(2*x); %! assert (isequal (rhs(f), g1) || isequal (rhs(f), g2)) %!test %! % Not enough initial conditions %! syms y(x) C1 %! de = diff(y, 2) + 4*y == 0; %! f = dsolve(de, y(0) == 3); %! g = 3*cos(2*x) + C1*sin(2*x); %! assert (isequal (rhs(f), g)) %!test %! % Solution in implicit form %! syms y(x) C1 %! sol=dsolve((2*x*y(x)-exp(-2*y(x)))*diff(y(x),x)+y(x)==0); %! eq=x*exp(2*y(x))-log(y(x))==C1; %! assert (isequal (rhs(sol), rhs(eq)) && isequal (lhs(sol), lhs(eq)) ) %!test %! % Compute solution and classification %! syms y(x) C1 %! [sol,classy]=dsolve((2*x*y(x)-exp(-2*y(x)))*diff(y(x),x)+y(x)==0); %! eq=x*exp(2*y(x))-log(y(x))==C1; %! assert (isequal (rhs(sol), rhs(eq)) && isequal (lhs(sol), lhs(eq))) %! assert (strcmp (classy, '1st_exact')) %!test %! % initial conditions (first order ode) %! syms y(x) %! de = diff(y, x) + 4*y == 0; %! f = dsolve(de, y(0) == 3); %! g = 3*exp(-4*x); %! assert (isequal (rhs(f), g)) %!test %! % initial conditions (second order ode) %! syms y(x) %! de = diff(y, 2) + 4*y == 0; %! f = dsolve(de, y(0) == 3, subs(diff(y,x),x,0)==0); %! g = 3*cos(2*x); %! assert (isequal (rhs(f), g)) %!test %! % Dirichlet boundary conditions (second order ode) %! syms y(x) %! de = diff(y, 2) + 4*y == 0; %! f = dsolve(de, y(0) == 2, y(1) == 0); %! g = -2*sin(2*x)/tan(sym('2'))+2*cos(2*x); %! assert (isequal (rhs(f), g)) %!test %! % Neumann boundary conditions (second order ode) %! syms y(x) %! de = diff(y, 2) + 4*y == 0; %! f = dsolve(de, subs(diff(y,x),x,0)==1, subs(diff(y,x),x,1)==0); %! g = sin(2*x)/2+cos(2*x)/(2*tan(sym('2'))); %! assert (isequal (rhs(f), g)) %!test %! % Dirichlet-Neumann boundary conditions (second order ode) %! syms y(x) %! de = diff(y, 2) + 4*y == 0; %! f = dsolve(de, y(0) == 3, subs(diff(y,x),x,1)==0); %! g = 3*sin(2*x)*tan(sym('2'))+3*cos(2*x); %! assert (isequal (rhs(f), g)) %!test %! % System of ODEs %! if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=75) %! disp('skipping: Solution of ODE systems needs sympy >= 0.7.6, issue #169') %! else %! syms x(t) y(t) C1 C2 %! ode_1=diff(x(t),t) == 2*y(t); %! ode_2=diff(y(t),t) == 2*x(t)-3*t; %! sol_sodes=dsolve([ode_1,ode_2]); %! g=[2*C1*exp(-2*t)+2*C2*exp(2*t),-2*C1*exp(-2*t)+2*C2*exp(2*t)]; %! assert (isequal ([rhs(sol_sodes{1}),rhs(sol_sodes{2})], g)) %! end %!test %! % System of ODEs (initial-value problem) %! if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=75) %! disp('skipping: Solution of ODE systems needs sympy >= 0.7.6, issue #169') %! else %! syms x(t) y(t) %! ode_1=diff(x(t),t) == 2*y(t); %! ode_2=diff(y(t),t) == 2*x(t)-3*t; %! sol_ivp=dsolve([ode_1,ode_2],x(0)==1,y(0)==0); %! g_ivp=[exp(-2*t)/2+exp(2*t)/2,-exp(-2*t)/2+exp(2*t)/2]; %! assert (isequal ([rhs(sol_ivp{1}),rhs(sol_ivp{2})], g_ivp)) %! end %!test %! syms y(x) %! de = diff(y, 2) + 4*y == 0; %! f = dsolve(de, y(0) == 0, y(sym(pi)/4) == 1); %! g = sin(2*x); %! assert (isequal (rhs(f), g)) %!test %! % Nonlinear example %! syms y(x) C1 %! e = diff(y, x) == y^2; %! g = -1 / (C1 + x); %! soln = dsolve(e); %! assert (isequal (rhs(soln), g)) %!test %! % Nonlinear example with initial condition %! syms y(x) %! e = diff(y, x) == y^2; %! g = -1 / (x - 1); %! soln = dsolve(e, y(0) == 1); %! assert (isequal (rhs(soln), g)) %!xtest %! % forcing, Issue #183 %! if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=75) %! disp('skipping: Solution of ODE systems needs sympy >= 0.7.6, issue #169') %! else %! syms x(t) y(t) %! ode1 = diff(x) == x + sin(t) + 2; %! ode2 = diff(y) == y - t - 3; %! soln = dsolve([ode1 ode2], x(0) == 1, y(0) == 2); %! X = rhs(soln{1}); %! Y = rhs(soln{2}); %! assert (isequal (diff(X) - (X + sin(t) + 2), 0)) %! assert (isequal (diff(Y) - (Y - t - 3), 0)) %! end symbolic-2.2.4/inst/@sym/isequaln.m0000644000175000001440000000455512633614672015727 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isequaln (@var{f}, @var{g}) %% @deftypefnx {Function File} {@var{r} =} isequaln (@var{f}, @var{g}, @dots{}) %% Test if contents of arrays are equal, even with nan. %% %% Here @code{nan == nan} is considered true, see also %% @code{isequal} where as usual @code{nan ~= nan}. %% %% @seealso{logical, isAlways, eq (==), isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = isequaln(x, y, varargin) % isequal does not care about type, but if you wanted it to... %if ( ~ ( isa (x, 'sym') && isa (y, 'sym'))) % t = false; % return %end %% some special cases if ~(is_same_shape(x, y)) t = false; return end % In symy, nan == nan is true by structural (not mathematical) % equivalence, so we don't need to detect it ourselves. % Sympy's == returns a scalar for arrays, no special case. cmd = 'return (_ins[0] == _ins[1],)'; t = python_cmd (cmd, sym(x), sym(y)); if (~ islogical(t)) error('nonboolean return from python'); end if (nargin >= 3) t = t && isequaln(x, varargin{:}); end end %!test %! a = sym([1 2]); %! b = a; %! assert (isequaln (a, b)) %! b(1) = 42; %! assert (~isequaln (a, b)) %!test %! a = sym([1 2; 3 4]); %! b = a; %! assert (isequaln (a, b)) %! b(1) = 42; %! assert (~isequaln (a, b)) %!test %! a = sym([nan; 2]); %! b = a; %! assert (isequaln (a, b)) %!test %! a = sym([nan 2; 3 4]); %! b = a; %! assert (isequaln (a, b)) %!test %! % more than two arrays %! a = sym([nan 2 3]); %! b = a; %! c = a; %! assert (isequaln (a, b, c)) %! c(1) = 42; %! assert (~isequaln (a, b, c)) symbolic-2.2.4/inst/@sym/children.m0000644000175000001440000000715712633614672015677 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{r} =} children (@var{f}) %% Return "children" (terms, lhs/rhs, etc) of symbolic expression. %% %% For a scalar expression, return a row vector of sym expressions: %% @example %% @group %% >> syms x y %% >> f = 2*x*y + sin(x); %% >> C = children(f) %% @result{} C = (sym) [2⋅x⋅y sin(x)] (1×2 matrix) %% %% >> children(C(1)) %% @result{} ans = (sym) [2 x y] (1×3 matrix) %% >> children(C(2)) %% @result{} ans = (sym) x %% @end group %% @end example %% %% %% For matrices/vectors, return a cell array where each entry is %% a row vector. The cell array is the same shape as the input. %% @example %% @group %% >> A = [x*y 2; 3 x] %% @result{} A = (sym 2×2 matrix) %% ⎡x⋅y 2⎤ %% ⎢ ⎥ %% ⎣ 3 x⎦ %% >> children(A) %% @result{} ans = %% @{ %% (sym) [x y] (1×2 matrix) %% (sym) 3 %% (sym) 2 %% (sym) x %% @} %% >> size(children(A)) %% @result{} ans = %% 2 2 %% @end group %% @end example %% %% A symbol/number/boolean has itself as children. %% %% @seealso{lhs, rhs} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = children(f) cmd = { 'f, = _ins' 'f = sympify(f)' % mutable -> immutable 'def scalarfcn(a):' ' if len(a.args) == 0:' ' return sympy.Matrix([a])' % children(x) is [x] ' return sympy.Matrix([a.args])' 'if f.is_Matrix:' ' r = [scalarfcn(a) for a in f.T]' % note transpose 'else:' ' r = scalarfcn(f)' 'return r,' }; r = python_cmd (cmd, f); if (~isscalar(f)) r = reshape(r, size(f)); end end %!test %! % basics, sum %! syms x y %! f = 2*x + x*x + sin(y); %! assert (isempty (setxor (children(f), [2*x x*x sin(y)]))) %!test %! % basics, product %! syms x y %! f = 2*x*sin(y); %! assert (isempty (setxor (children(f), [2 x sin(y)]))) %!test %! % basics, product and powers %! syms x y %! f = 2*x^2*y^3; %! assert (isempty (setxor (children(f), [2 x^2 y^3]))) %!test %! % eqn, ineq %! syms x y %! lhs = 2*x^2; rhs = y^3 + 7; %! assert (isequal (children(lhs == rhs), [lhs rhs])) %! assert (isequal (children(lhs < rhs), [lhs rhs])) %! assert (isequal (children(lhs >= rhs), [lhs rhs])) %!test %! % matrix %! syms x y %! f = [4 + y 1 + x; 2 + x 3 + x]; %! c = children(f); %! ec = {[4 y], [1 x]; [2 x], [3 x]}; %! assert (isequal (size(c), size(ec))) %! for i=1:length(c) %! assert (isempty (setxor (c{i}, ec{i}))) %! end %!test %! % matrix, sum/prod %! syms x y %! f = [x + y; x*sin(y); sin(x)]; %! ec = {[x y]; [x sin(y)]; [x]}; %! c = children(f); %! assert (isequal (size(c), size(ec))) %! for i=1:length(c) %! assert (isempty (setxor (c{i}, ec{i}))) %! end %!test %! % scalar symbol %! syms x %! assert (isequal (children(x), x)) %!test %! % scalar number %! x = sym(6); %! assert (isequal (children(x), x)) symbolic-2.2.4/inst/@sym/toeplitz.m0000644000175000001440000000571612633614672015760 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{A} =} toeplitz (@var{c}, @var{r}) %% @deftypefnx {Function File} {@var{A} =} toeplitz (@var{r}) %% Construct a symbolic Toeplitz matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function A = toeplitz(C,R) if (nargin == 1) [C,R] = deal(C',C); end if ~(isa(R, 'sym')) R = sym(R); end if ~(isa(C, 'sym')) C = sym(C); end assert(isvector(R)); assert(isvector(C)); % Diagonal conflict idx.type = '()'; idx.subs = {1}; if (nargin == 2) && ~(isequal(subsref(R,idx), subsref(C,idx))); warning('OctSymPy:toeplitz:diagconflict', ... 'toeplitz: column wins diagonal conflict') R = subsasgn(R, idx, subsref(C, idx)); end % (if just one input (R) then we want it to get the diag) cmd = { '(C, R) = _ins' ... 'if not R.is_Matrix:' ... ' return (R[0],)' ... '(n, m) = (len(C), len(R))' ... 'A = sp.zeros(n, m)' ... 'for i in range(0, n):' ... ' for j in range(0, m):' ... ' if i - j > 0:' ... ' A[i, j] = C[i-j]' ... ' else:' ... ' A[i, j] = R[j-i]' ... 'return (A,)' }; A = python_cmd (cmd, C, R); end %!test %! % rect %! R = [10 20 40]; C = [10 30]; %! A = sym(toeplitz(R,C)); %! B = toeplitz(sym(R),sym(C)); %! assert (isequal (A, B)) %! R = [10 20]; C = [10 30 50]; %! A = sym(toeplitz(R,C)); %! B = toeplitz(sym(R),sym(C)); %! assert (isequal (A, B)) %!test %! % symbols %! syms x y %! R = [10 20 40]; C = [10 30]; %! Rs = [10 x 40]; Cs = [10 y]; %! A = toeplitz(R,C); %! B = toeplitz(Rs,Cs); %! assert (isequal (A, subs(B,[x,y],[20 30]))) %!test %! % hermitian %! syms a b c %! A = [a b c; conj(b) a b; conj(c) conj(b) a]; %! B = toeplitz([a,b,c]); %! assert (isequal( A, B)) %!warning %! % mismatch %! syms x %! B = toeplitz([10 x], [1 3 x]); %!test %! % mismatch %! syms x y %! fprintf('\n*** One warning expected ***\n') % how to quiet this one? %! A = toeplitz([10 2], [1 3 5]); %! s = warning ('off', 'OctSymPy:toeplitz:diagconflict'); %! B = toeplitz([10 x], [1 3 y]); %! warning(s) %! assert (isequal (A, subs(B, [x,y], [2 5]))) symbolic-2.2.4/inst/@sym/erfi.m0000644000175000001440000000256012633614672015025 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} erfi (@var{x}) %% Symbolic erfi function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = erfi(x) y = uniop_helper (x, 'erfi'); end %!shared x, d %! d = 0; %! x = sym('0'); %!test %! f1 = erfi(x); %! f2 = 0; %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = erfi(A); %! f2 = 0; %! f2 = [f2 f2; f2 f2]; %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/ezplot3.m0000644000175000001440000000670512633614672015505 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{h} =} ezplot3 (@var{f1}, @var{f2},@var{f3}) %% @deftypefnx {Function File} {@var{h} =} ezplot3 (@dots{}) %% Simple 3D parametric plotting of symbolic expressions. %% %% See help for the (non-symbolic) @code{ezplot3}, which this %% routine calls after trying to convert sym inputs to %% anonymous functions. %% %% @seealso{ezplot, ezsurf, ezmesh, function_handle} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, plotting function varargout = ezplot3(varargin) % first input is handle, shift if (ishandle(varargin{1})) firstpotsym = 2; else firstpotsym = 1; end maxnumsym = 3; firstsym = []; for i = firstpotsym:nargin if (isa(varargin{i}, 'sym')) if (i < firstpotsym + maxnumsym) % one of the fcns to plot, covert to handle fcn % Each is function of one var, and its the same var for all thissym = symvar(varargin{i}); assert(length(thissym) <= 1, ... 'ezplot3: plotting curves: functions should have at most one input'); if (isempty(thissym)) % a number, create a constant function in a dummy variable % (0*t works around some Octave oddity on 3.8 and hg Dec 2014) thisf = inline(sprintf('%g + 0*t', double(varargin{i})), 't'); %thisf = @(t) 0*t + double(varargin{i}); % no else % check variables match (sanity check) if (isempty(firstsym)) firstsym = thissym; else assert(logical(thissym == firstsym), ... 'ezplot3: all functions must be in terms of the same variables'); end thisf = function_handle(varargin{i}); end varargin{i} = thisf; else % plot ranges, etc, convert syms to doubles varargin{i} = double(varargin{i}); end end end h = ezplot3(varargin{:}); if (nargout) varargout{1} = h; end end %!test %! % parametric %! syms t %! f1 = cos(t); %! f2 = sin(t); %! f3 = t; %! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %! h = ezplot3(f1, f2, f3); %! warning(s) %! zz = get(h, 'zdata'); %! assert (abs(zz(end) - 2*pi) <= 4*eps) %!error %! syms x t %! ezplot3(t, x, t) %!error %! syms x t %! ezplot3(t, t*x, t) %%!test %%! % bounds etc as syms %%! % FIXME: disabled for matlab, see ezplot.m too %%! syms t %%! f1 = cos(t); %%! f2 = sin(t); %%! f3 = t; %%! s = warning('off', 'OctSymPy:function_handle:nocodegen'); %%! h = ezplot3(f1, f2, f3, [sym(0) sym(pi)], sym(42)); %%! warning(s) %%! zz = get(h, 'zdata'); %%! assert (length(zz) == 42) %%! assert (abs(zz(end) - pi) <= 4*eps) symbolic-2.2.4/inst/@sym/int.m0000644000175000001440000001060212633614672014666 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{g} =} int (@var{f}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{x}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{x}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{x}, [@var{a}, @var{b}]) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{g} =} int (@var{f}, [@var{a}, @var{b}]) %% Symbolic integration. %% %% Definite integral: %% @example %% @group %% >> syms x %% >> f = x^2; %% >> F = int(f, x, 1, 2) %% @result{} F = (sym) 7/3 %% @end group %% @end example %% or alternatively %% @example %% @group %% >> F = int(f, x, [1 2]) %% @result{} F = (sym) 7/3 %% @end group %% @end example %% %% Indefinite integral: %% @example %% @group %% >> F = int(f, x) %% @result{} F = (sym) %% 3 %% x %% ── %% 3 %% >> F = int(f) %% @result{} F = (sym) %% 3 %% x %% ── %% 3 %% @end group %% @end example %% %% @seealso{diff} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, integration function F = int(f, x, a, b) if (nargin == 4) % int(f, x, a, b) assert(numel(a)==1) assert(numel(b)==1) definite = true; elseif (nargin == 2) && (numel(x) == 1) % int(f, x) definite = false; elseif (nargin == 1) % int(f) definite = false; x = symvar(f,1); if isempty(x) x = sym('x'); end elseif (nargin == 2) && (numel(x) == 2) % int(f, [a b]) idx.type = '()'; idx.subs = {2}; definite = true; b = subsref(x, idx); idx.subs = {1}; a = subsref(x, idx); x = symvar(f,1); if isempty(x) x = sym('x'); end elseif (nargin == 3) && (numel(a) == 2) % int(f, x, [a b]) definite = true; idx.type = '()'; idx.subs = {2}; b = subsref(a, idx); idx.subs = {1}; a = subsref(a, idx); elseif (nargin == 3) && (numel(a) == 1) % int(f, a, b) definite = true; b = a; a = x; x = symvar(f,1); if isempty(x) x = sym('x'); end else print_usage (); end %% now do the definite or indefinite integral if (definite) cmd = { '(f, x, a, b) = _ins' 'F = sp.integrate(f, (x, a, b))' 'return F,' }; F = python_cmd (cmd, sym(f), sym(x), sym(a), sym(b)); else cmd = { '(f,x) = _ins' 'd = sp.integrate(f, x)' 'return d,' }; F = python_cmd (cmd, sym(f), sym(x)); end end %!shared x,y,a %! syms x y a %!assert(logical(int(cos(x)) - sin(x) == 0)) %!assert(logical(int(cos(x),x) - sin(x) == 0)) %!assert(logical(int(cos(x),x,0,1) - sin(sym(1)) == 0)) %!test %! %% limits might be syms %! assert( isequal (int(cos(x),x,sym(0),sym(1)), sin(sym(1)))) %! assert( isequal (int(cos(x),x,0,a), sin(a))) %!test %! %% other variables present %! assert( isequal (int(y*cos(x),x), y*sin(x))) %!test %! %% limits as array %! assert( isequal (int(cos(x),x,[0 1]), sin(sym(1)))) %! assert( isequal (int(cos(x),x,sym([0 1])), sin(sym(1)))) %! assert( isequal (int(cos(x),x,[0 a]), sin(a))) %!test %! %% no x given %! assert( isequal (int(cos(x),[0 1]), sin(sym(1)))) %! assert( isequal (int(cos(x),sym([0 1])), sin(sym(1)))) %! assert( isequal (int(cos(x),[0 a]), sin(a))) %! assert( isequal (int(cos(x),0,a), sin(a))) %!test %! %% integration of const %! assert( isequal (int(sym(2),y), 2*y)) %! assert( isequal (int(sym(2)), 2*x)) %! assert( isequal (int(sym(2),[0 a]), 2*a)) %! assert( isequal (int(sym(2),0,a), 2*a)) %!test %! % componentwise int of array %! A = [x x*x]; %! assert (isequal (int(A, x), [x^2/2 x^3/3])) symbolic-2.2.4/inst/@sym/imag.m0000644000175000001440000000233412633614672015014 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} imag (@var{z}) %% Imaginary part of a symbolic expression. %% %% @seealso{real, conj, ctranspose} %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = imag(z) y = (z - conj(z))/2i; end %!assert(isequal(imag(sym(4)+3i),3)) %!test %! syms x y real %! z = x + 1i*y; %! assert(isequal(imag(z),y)) %!test %! syms x y real %! Z = [4 x + 1i*y; 1i*y 4+3i]; %! assert(isequal(imag(Z),[0 y; y 3])) symbolic-2.2.4/inst/@sym/char.m0000644000175000001440000000320212633614672015007 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{s} =} char (@var{x}) %% Return underlying string representation of a symbolic expression. %% %% Although not intended for general use, the underlying SymPy string %% representation (“srepr”) can be recovered with this command: %% @example %% @group %% >> syms x positive %% >> srepr = char (x) %% @result{} srepr = Symbol('x', positive=True) %% @end group %% @end example %% %% It can then be passed directly to sym: %% @example %% @group %% >> x2 = sym (srepr) %% @result{} x2 = (sym) x %% >> x2 == x %% @result{} (sym) True %% @end group %% @end example %% %% @seealso{disp, pretty, sym} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function s = char(x) s = x.pickle; end %!test %! % issue #91: expose as string %! syms x %! s = char(x); %! assert (strcmp (s, 'Symbol(''x'')')) symbolic-2.2.4/inst/@sym/lt.m0000644000175000001440000000744712633614672014530 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} lt (@var{a}, @var{b}) %% Test/define symbolic inequality, less than. %% %% @seealso{le, gt, ge, eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = lt(x, y) t = ineq_helper('<', 'Lt', x, y); end %% Note: % in general, put tests in lt unless they are specific to % another inequality. %!test %! % simple %! x = sym(1); y = sym(1); e = x < y; %! assert (~logical (e)) %! x = sym(1); y = sym(2); e = x < y; %! assert (logical (e)) %!test %! % mix sym and double %! x = sym(1); y = 1; e = x < y; %! assert (~logical (e)) %! x = sym(1); y = 2; e = x < y; %! assert (logical (e)) %! x = 1; y = sym(1); e = x < y; %! assert (~logical (e)) %! x = 1; y = sym(2); e = x < y; %! assert (logical (e)) %!test %! % Type of the output is sym or logical? %! % FIXME: in current version, they are sym %! x = sym(1); y = sym(1); e1 = x < y; %! x = sym(1); y = sym(2); e2 = x < y; %! %assert (islogical (e1)) %! %assert (islogical (e2)) %! assert (isa (e1, 'sym')) %! assert (isa (e2, 'sym')) %!test %! % ineq w/ symbols %! syms x y %! e = x < y; %! assert (~islogical (e)) %! assert (isa (e, 'sym')) %!test %! % array -- array %! syms x %! a = sym([1 3 3 2*x]); %! b = sym([2 x 3 10]); %! e = a < b; %! assert (isa (e, 'sym')) %! assert (logical (e(1))) %! assert (isa (e(2), 'sym')) %! assert (isequal (e(2), 3 < x)) %! assert (~logical (e(3))) %! assert (isa (e(4), 'sym')) %! assert (isequal (e(4), 2*x < 10)) %!test %! % array -- scalar %! syms x oo %! a = sym([1 x oo]); %! b = sym(3); %! e = a < b; %! assert (isa (e, 'sym')) %! assert (logical (e(1))) %! assert (isa (e(2), 'sym')) %! assert (isequal (e(2), x < 3)) %! assert (~logical (e(3))) %!test %! % scalar -- array %! syms x oo %! a = sym(1); %! b = sym([2 x -oo]); %! e = a < b; %! assert (isa (e, 'sym')) %! assert (logical (e(1))) %! assert (isa (e(2), 'sym')) %! assert (isequal (e(2), 1 < x)) %! assert (~logical (e(3))) %!test %! % ineq w/ nan %! syms x %! snan = sym(nan); %! e = x < snan; %! assert (~logical (e)) %! e = snan < x; %! assert (~logical (e)) %! b = [sym(0) x]; %! e = b < snan; %! assert (isequal (e, [false false])) %!test %! % oo %! syms oo x %! e = oo < x; %! assert (isa (e, 'sym')) %! assert (strcmp (strtrim (disp (e, 'flat')), 'oo < x')) %!test %! % sympy true matrix %! a = sym([1 3 3]); %! b = sym([2 4 1]); %! e = a < b; %! %assert (~isa (e, 'sym')) %! %assert (islogical (e)) %! assert (isequal (e, [true true false])) %!test %! % oo, finite real variables %! syms oo %! syms z real %! assumeAlso(z, 'finite') %! e = -oo < z; %! assert (isequal (e, sym(true))) %! e = z < oo; %! assert (isequal (e, sym(true))) %!xtest %! % -oo, positive var (known failure w/ sympy 0.7.6.x) %! syms oo %! syms z positive %! e = -oo < z; %! assert (logical (e)) %! assert (isequal (e, sym(true))) %!xtest %! % positive (known failure w/ sympy 0.7.5) %! syms z positive %! e = -1 < z; %! assert (isequal (e, sym(true))) %!test %! syms oo %! z = sym('z', 'negative'); %! e = z < oo; %! assert (isequal (e, sym(true))) symbolic-2.2.4/inst/@sym/tan.m0000644000175000001440000000253412633614672014663 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} tan (@var{x}) %% Symbolic tan function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = tan(x) y = uniop_helper (x, 'tan'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = tan(x); %! f2 = tan(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = tan(A); %! f2 = tan(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/sign.m0000644000175000001440000000254412633614672015042 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} sign (@var{x}) %% Symbolic sign function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = sign(x) y = uniop_helper (x, 'sign'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = sign(x); %! f2 = sign(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = sign(A); %! f2 = sign(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/reshape.m0000644000175000001440000000500712633614672015526 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} reshape (@var{x}, @var{n}, @var{m}) %% @deftypefnx {Function File} {@var{y} =} reshape (@var{x}, [@var{n}, @var{m}]) %% Change the shape of a symbolic array. %% %% @seealso{size} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = reshape(a, n, m) % reshaping a double array with sym sizes if ~(isa(a, 'sym')) if (nargin == 2) z = reshape(a, double(n)); else z = reshape(a, double(n), double(m)); end return end if (nargin == 2) m = n(2); n = n(1); end cmd = { '(A, n, m) = _ins' ... 'if A.is_Matrix:' ... ' #sympy is row-based' ... ' return A.T.reshape(m,n).T,' ... 'else:' ... ' return A,' }; z = python_cmd (cmd, sym(a), int32(n), int32(m)); end %!test %! d = [2 4 6; 8 10 12]; %! a = sym(d); %! assert (isequal (reshape(a, [1 6]), reshape(d, [1 6]))) %! assert (isequal (reshape(a, 1, 6), reshape(d, 1, 6))) %! assert (isequal (reshape(a, 2, 3), reshape(d, 2, 3))) %! assert (isequal (reshape(a, 3, 2), reshape(d, 3, 2))) %! assert (isequal (reshape(a, 6, 1), reshape(d, 6, 1))) %!shared x, a, d %! syms x %! a = [1 x^2 x^4; x x^3 x^5]; %! d = [0 2 4; 1 3 5]; %! %!test %! b = reshape(a, [1 6]); %! assert (isequal (size(b), [1 6])) %! assert (isequal (b, x.^reshape(d,1,6))) %! %!test %! b = reshape(a, [6 1]); %! assert (isequal (size(b), [6 1])) %! assert (isequal (b, x.^reshape(d,6,1))) %! b = reshape(b, size(a)); %! assert (isequal (size(b), [2 3])) %! assert (isequal (b, a)) %! %!test %! b = a(:); %! assert( isequal (size(b), [6 1])) %! assert( isequal (b, x.^(d(:)))) %! %!test %! % reshape scalar %! assert (logical( reshape(x, 1, 1) == x )) %! assert (logical( reshape(x, [1 1]) == x )) symbolic-2.2.4/inst/@sym/diff.m0000644000175000001440000001073612633614672015014 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{g} =} diff (@var{f}) %% @deftypefnx {Function File} {@var{g} =} diff (@var{f}, @var{x}) %% @deftypefnx {Function File} {@var{g} =} diff (@var{f}, @dots{}) %% Symbolic differentiation. %% %% Examples: %% @example %% @group %% >> syms x %% >> f = sin (cos (x)); %% >> diff (f) %% @result{} (sym) -sin(x)⋅cos(cos(x)) %% >> diff (f, x) %% @result{} (sym) -sin(x)⋅cos(cos(x)) %% >> simplify (diff (f, x, x)) %% @result{} (sym) %% 2 %% - sin (x)⋅sin(cos(x)) - cos(x)⋅cos(cos(x)) %% @end group %% @end example %% %% Partial differentiation: %% @example %% @group %% >> syms x y %% >> f = cos(2*x + 3*y); %% >> diff(f, x, y, x) %% @result{} (sym) 12⋅sin(2⋅x + 3⋅y) %% >> diff(f, x, 2, y, 3) %% @result{} (sym) -108⋅sin(2⋅x + 3⋅y) %% @end group %% @end example %% %% Other examples: %% @example %% @group %% >> diff(sym(1)) %% @result{} (sym) 0 %% @end group %% @end example %% %% @seealso{int} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, differentiation function z = diff(f, varargin) % simpler version, but gives error on differentiating a constant %cmd = 'return sp.diff(*_ins),'; %% some special cases for SMT compat. % FIXME: with a sympy symvar, could move this to python? if (nargin == 1) % diff(f) -> symvar x = symvar(f, 1); if (isempty(x)) x = sym('x'); % e.g., diff(sym(6)) end z = diff(f, x); return elseif (nargin >= 2) q = varargin{1}; % Note: pickle: to avoid double() overhead for common diff(f,x) isnum2 = isnumeric(q) || (isa(q, 'sym') && strncmpi(q.pickle, 'Integer', 7)); if ((nargin == 2) && isnum2) % diff(f,2) -> symvar x = symvar(f, 1); if (isempty(x)) x = sym('x'); % e.g., diff(sym(6), 2) end z = diff(f, x, varargin{1}); return end if ((nargin == 3) && isnum2) % diff(f,2,x) -> diff(f,x,2) z = diff(f, varargin{2}, varargin{1}); return end end cmd = { 'f = _ins[0]' 'args = _ins[1:]' 'return f.diff(*args),' }; varargin = sym(varargin); z = python_cmd (cmd, sym(f), varargin{:}); end %!shared x,y,z %! syms x y z %!test %! % basic %! assert(logical( diff(sin(x)) - cos(x) == 0 )) %! assert(logical( diff(sin(x),x) - cos(x) == 0 )) %! assert(logical( diff(sin(x),x,x) + sin(x) == 0 )) %!test %! % these fail when doubles are not converted to sym %! assert(logical( diff(sin(x),x,2) + sin(x) == 0 )) %! assert(logical( diff(sym(1),x) == 0 )) %! assert(logical( diff(1,x) == 0 )) %! assert(logical( diff(pi,x) == 0 )) %!test %! % symbolic diff of const (w/o variable) fails in sympy, but we work around %! assert (isequal (diff(sym(1)), sym(0))) %!test %! % nth symbolic diff of const %! assert (isequal (diff(sym(1), 2), sym(0))) %! assert (isequal (diff(sym(1), sym(1)), sym(0))) %!test %! % octave's vector difference still works %! assert(isempty(diff(1))) %! assert((diff([2 6]) == 4)) %!test %! % other forms %! f = sin(x); %! g = diff(f,x,2); %! assert (isequal (diff(f,2), g)) %! assert (isequal (diff(f,2,x), g)) %! assert (isequal (diff(f,sym(2)), g)) %! assert (isequal (diff(f,sym(2),x), g)) %! g = diff(f,x); %! assert (isequal (diff(f), g)) %! assert (isequal (diff(f,1), g)) %! assert (isequal (diff(f,1,x), g)) %!test %! % matrix %! A = [x sin(x); x*y 10]; %! B = [1 cos(x); y 0]; %! assert(isequal(diff(A,x),B)) %!test %! % bug: use symvar %! a = x*y; %! b = diff(a); %! assert (isequal (b, y)) %!test %! % bug: symvar should be used on the matrix, not comp-by-comp %! a = [x y x*x]; %! b = diff(a); %! assert (~isequal (b(2), 1)) %! assert (isequal (b, [1 0 2*x])) %! b = diff(a,1); %! assert (~isequal (b(2), 1)) %! assert (isequal (b, [1 0 2*x])) symbolic-2.2.4/inst/@sym/log2.m0000644000175000001440000000221312633614672014736 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} log2 (@var{x}) %% Symbolic log base 2 function. %% %% @seealso{log,log10} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = log2(x) sf = 'lambda x: sp.log(x, 2)'; z = uniop_helper (x, sf); end %!assert (isequal (log2 (sym (1024)), sym (10))) %!assert (isequal (log2 (sym ([2 16; 32 1])), sym ([1 4; 5 0]))) symbolic-2.2.4/inst/@sym/uplus.m0000644000175000001440000000214312633614672015245 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} uplus (@var{x}) %% Symbolic unitary minus (+). %% %% A no-op. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function x = uplus(x) x = x; end %!test %! syms x %! assert (isa (+x, 'sym')) %! assert (isequal (+x, x)) %!test %! A = sym([0 -1 inf]); %! assert( isequal ( +A, A)) symbolic-2.2.4/inst/@sym/rows.m0000644000175000001440000000220212633614672015063 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{n} =} rows (@var{x}) %% Return the number of rows in a symbolic array. %% %% @seealso{columns, size, length, numel} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function n = rows(x) n = size(x, 1); end %!test %! a = sym([1 2 3]); %! assert (rows(a) == 1) %!test %! a = sym([1 2 3; 4 5 6]); %! assert (rows(a) == 2) symbolic-2.2.4/inst/@sym/horner.m0000644000175000001440000000460012633614672015372 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{q} =} horner (@var{p}) %% @deftypefnx {Function File} {@var{q} =} horner (@var{p}, @var{x}) %% Convert a symbolic polynomial to Horner form. %% %% The Horner form minimizes the number of arthimetic operators to %% evaluate the polynomial. %% %% Example: %% @example %% @group %% >> syms x %% >> p = poly2sym ([2 4 6 8], x) %% @result{} p = (sym) %% 3 2 %% 2⋅x + 4⋅x + 6⋅x + 8 %% >> horner (p) %% @result{} ans = (sym) x⋅(x⋅(2⋅x + 4) + 6) + 8 %% @end group %% @end example %% %% You can specify the variable as a second input: %% @example %% @group %% >> syms x a %% >> p = expand((a+2)*(2*a+x)*(3*a+7)); %% >> horner(p, a) %% @result{} ans = (sym) a⋅(a⋅(6⋅a + 3⋅x + 26) + 13⋅x + 28) + 14⋅x %% @end group %% @end example %% %% @seealso{poly2sym} %% @end deftypefn function y = horner(p, x) if (nargin == 1) x = symvar(p, 1); end if (isempty(x)) y = python_cmd ('return sp.horner(*_ins),', sym(p)); else y = python_cmd ('return sp.horner(*_ins),', sym(p), sym(x)); end end %!assert (isAlways (horner(sym(1)) == 1)) %!test %! syms x %! assert (isAlways (horner(x) == x)) %!test %! syms x a %! p = a^2 + a*x + 2*a + 2*x; %! assert (isequal (horner (p, a), a*(a+x+2) + 2*x)) %! q = a^2 + 2*a + x*(a + 2); %! assert (isequal (horner (p, x), q)) %! assert (isequal (horner (p), q)) %!test %! syms x %! p = poly2sym ([2 4 6 8], x); %! q = horner (p); %! assert (isAlways (p == q)) %! assert (isAlways (horner(2*x^3 + 4*x^2 + 6*x + 8) == q)) %!test %! % non-sym input %! syms x %! assert (isequal (horner(6, x), sym(6))) symbolic-2.2.4/inst/@sym/sec.m0000644000175000001440000000253412633614672014653 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} sec (@var{x}) %% Symbolic sec function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = sec(x) y = uniop_helper (x, 'sec'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = sec(x); %! f2 = sec(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = sec(A); %! f2 = sec(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/tril.m0000644000175000001440000000333312633614672015051 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{L} =} tril (@var{A}) %% @deftypefnx {Function File} {@var{L} =} tril (@var{A}, @var{k}) %% Lower triangular part of a symbolic matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function L = tril(A,k) if (nargin == 1) k = 0; end if ~(isa(A, 'sym')) % k was a sym L = tril(A, double(k)); return end L = triu(A.', -k); L = L.'; end %!test %! syms x %! assert (isequal (tril(x), x)) %!test %! % with symbols %! syms x %! A = [x 2*x; 3*x 4*x]; %! assert (isequal (tril(A), [x 0; 3*x 4*x])) %!test %! % diagonal shifts %! B = round(10*rand(3,4)); %! A = sym(B); %! assert (isequal (tril(A), tril(B))) %! assert (isequal (tril(A,0), tril(B,0))) %! assert (isequal (tril(A,1), tril(B,1))) %! assert (isequal (tril(A,-1), tril(B,-1))) %!test %! % double array pass through %! B = round(10*rand(3,4)); %! assert (isequal (tril(B,sym(1)), tril(B,1))) %! assert (isa (tril(B,sym(1)), 'double')) symbolic-2.2.4/inst/@sym/formula.m0000644000175000001440000000233512633614672015545 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g}} formula (@var{f}) %% Return a symbolic expression for this object. %% %% For a @@sym, this simply returns the sym itself. Subclasses %% such as @@symfun may do more interesting things. %% %% @seealso{@@symfun/formula, argnames} %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function g = formula(f) g = f; end %!test %! syms x %! assert (isequal (formula(x), x)) %! assert (isequal (formula(2*x), 2*x)) symbolic-2.2.4/inst/@sym/findsym.m0000644000175000001440000000420512633614672015547 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{S} =} findsym (@var{expr}) %% @deftypefnx {Function File} {@var{S} =} findsym (@var{expr}, @var{n}) %% Find symbols in expression, return them as comma-separated string. %% %% See @code{symvar}, this just concatenates its output into a %% string. %% %% Example: %% @example %% @group %% syms y a b %% f = a*y + b; %% v = findsym (f) %% @result{} v = a,b,y %% v = findsym (f, 1) %% @result{} v = y %% @end group %% @end example %% %% @seealso{symvar, findsymbols} %% @end deftypefn function s = findsym(varargin) A = symvar(varargin{:}); % FIXME: once Octave 3.6 is ancient history, use strjoin s = mystrjoin(syms2charcells(A), ','); end function C = syms2charcells(S) C = {}; for i=1:length(S) if iscell(S) C{i} = S{i}.flat; else % MoFo Issue #17 %C{i} = S(i).flat idx.type = '()'; idx.subs = {i}; temp = subsref(S, idx); C{i} = temp.flat; end end end %!assert (strcmp (findsym (sym(2)), '')); %!shared x,y,f %! x=sym('x'); y=sym('y'); f=x^2+3*x*y-y^2; %!assert (strcmp (findsym (f), 'x,y')); %!assert (strcmp (findsym (f,1), 'x')); %!test %! % test order of returned vars %! syms x y a b c xx %! % https://www.mathworks.com/matlabcentral/newsreader/view_thread/237730 %! alpha = sym('alpha'); %! assert (strcmp (findsym(b*xx*exp(alpha) + c*sin(a*y), 2), 'xx,y')) symbolic-2.2.4/inst/@sym/isna.m0000644000175000001440000000243112633614672015027 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isna (@var{x}) %% Symbolic expressions cannot be the Octave/R missing data NA. %% %% We have this mainly so @code{assert} works properly. %% %% @seealso{isnan} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = isna(x) r = logical(zeros(size(x))); end %!test %! % no sym should be NA %! syms x oo %! assert (~isna(sym(1))) %! assert (~isna(x)) %! assert (~isna(oo)) %! assert (~isna(sym(nan))) %! assert (isequal (isna (sym ([1 nan])), [false false])) symbolic-2.2.4/inst/@sym/factorial.m0000644000175000001440000000261412633614672016044 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} factorial (@var{x}) %% Symbolic factorial function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = factorial(x) y = uniop_helper (x, 'factorial'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = factorial(x); %! f2 = factorial(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = factorial(A); %! f2 = factorial(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/any.m0000644000175000001440000000376412633614672014676 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} any (@var{x}) %% @deftypefnx {Function File} {@var{y} =} any (@var{x}, @var{dim}) %% Return true if any entries of a symbolic vector are nonzero. %% %% Similar behaviour to the built-in @code{any} with regard to %% matrices and the second argument. %% %% Throws an error if any entries are non-numeric. %% %% Example: %% @example %% @group %% >> any([0; sym(pi); 0]) %% @result{} ans = 1 %% @end group %% @end example %% %% @seealso{all} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = any(x, varargin) z = any (logical (x), varargin{:}); % z = double (x, false); %if (isempty (z)) % error('indeterminable') %else % z = any (z, varargin{:}); %end end %!test %! % matrix %! a = [0 0; 1 0]; %! s = sym(a); %! assert (isequal (any (s), any (a))) %! assert (isequal (any (s,1), any (a,1))) %! assert (isequal (any (s,2), any (a,2))) %!test %! % vector %! a = [0 1 0]; %! s = sym(a); %! assert (isequal (any (s), any (a))) %! assert (isequal (any (s,1), any (a,1))) %! assert (isequal (any (s,2), any (a,2))) %!test %! % should fail on symbols %! syms x %! s = [0 1 x]; %! try %! any (s) %! waserr = false; %! catch %! waserr = true; %! end %! assert (waserr) symbolic-2.2.4/inst/@sym/numden.m0000644000175000001440000000332212633614672015363 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{n}, @var{d} =} numden (@var{x}) %% Extract numerator and demoninator of symbolic expression. %% %% Examples: %% @example %% @group %% >> [n, d] = numden(sym(4)/5) %% @result{} %% n = (sym) 4 %% d = (sym) 5 %% @end group %% @end example %% %% @example %% @group %% >> syms x y %% >> [n, d] = numden((x+y)/sin(x)) %% @result{} %% n = (sym) x + y %% d = (sym) sin(x) %% @end group %% @end example %% %% @seealso{coeffs, children, lhs, rhs} %% @end deftypefn function [n, d] = numden(x) [n, d] = python_cmd ('return (sympy.numer(*_ins), sympy.denom(*_ins))', sym(x)); end %!test %! [n, d] = numden(sym(2)); %! assert (isequal (n, 2)); %! assert (isequal (d, 1)); %!test %! syms x y %! [n, d] = numden((x + pi)/(y + 6)); %! assert (isequal (n, x + pi)); %! assert (isequal (d, y + 6)); %!test %! syms x y %! [n, d] = numden((x^2 + y^2)/(x*y)); %! assert (isequal (n, x^2 + y^2)); %! assert (isequal (d, x*y)); symbolic-2.2.4/inst/@sym/tanh.m0000644000175000001440000000254412633614672015034 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} tanh (@var{x}) %% Symbolic tanh function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = tanh(x) y = uniop_helper (x, 'tanh'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = tanh(x); %! f2 = tanh(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = tanh(A); %! f2 = tanh(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/atan.m0000644000175000001440000000254412633614672015025 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} atan (@var{x}) %% Symbolic atan function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = atan(x) y = uniop_helper (x, 'atan'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = atan(x); %! f2 = atan(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = atan(A); %! f2 = atan(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/solve.m0000644000175000001440000001545512633614672015237 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald, Andrés Prieto %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{sol} =} solve (@var{eq, var}) %% @deftypefnx {Function File} {@var{sol} =} solve (@var{eq1, eq2}) %% @deftypefnx {Function File} {@var{sol} =} solve (@var{eq1, @dots{}, eqn, v1, @dots{}, vm}) %% @deftypefnx {Function File} {[@var{s1, @dots{}, sn}] =} solve (@var{eq1, @dots{}, eqm, v1, @dots{}, vn}) %% Symbolic solutions of equations and systems. %% %% Examples %% @example %% @group %% >> syms x %% >> solve(x == 2*x + 6, x) %% @result{} ans = (sym) -6 %% >> solve(x^2 + 6 == 5*x, x) %% @result{} ans = (sym 2×1 matrix) %% ⎡2⎤ %% ⎢ ⎥ %% ⎣3⎦ %% @end group %% @end example %% %% You can specify a variable or even an expression to solve for: %% @example %% @group %% >> syms x y %% >> e = 10*x == 20*y; %% >> d = solve(e, x) % gives 2*y %% @result{} d = (sym) 2⋅y %% >> d = solve(e, y) % gives x/2 %% @result{} d = (sym) %% x %% ─ %% 2 %% >> d = solve(e, 2*x) % gives 4*y %% @result{} d = (sym) 4⋅y %% @end group %% @end example %% %% In general, the output will be a list of dictionaries. Each %% entry of the list is one a solution, and the variables that make %% up that solutions are keys of the dictionary (fieldnames of the %% struct). %% @example %% @group %% >> syms x y %% >> d = solve(x^2 == 4, x + y == 1); %% %% >> % the first solution %% >> d@{1@}.x %% @result{} (sym) -2 %% >> d@{1@}.y %% @result{} (sym) 3 %% %% >> % the second solution %% >> d@{2@}.x %% @result{} (sym) 2 %% >> d@{2@}.y %% @result{} (sym) -1 %% @end group %% @end example %% %% But there are various special cases for the output (single %% versus multiple variables, single versus multiple solutions, %% etc). %% FIXME: provide a 'raw_output' argument or something to %% always give the general output. %% %% Alternatively: %% @example %% @group %% >> [X, Y] = solve(x^2 == 4, x + y == 1, x, y) %% @result{} X = (sym 2×1 matrix) %% ⎡-2⎤ %% ⎢ ⎥ %% ⎣2 ⎦ %% Y = (sym 2×1 matrix) %% ⎡3 ⎤ %% ⎢ ⎥ %% ⎣-1⎦ %% @end group %% @end example %% %% @seealso{dsolve} %% @end deftypefn %% Author: Colin B. Macdonald, Andrés Prieto %% Keywords: symbolic function varargout = solve(varargin) varargin = sym(varargin); if (nargout == 0 || nargout == 1) cmd = { 'eqs = list(); symbols = list()' 'for arg in _ins:' ' if arg.is_Relational:' ' eqs.append(arg)' ' else:' ' symbols.append(arg)' '#' 'if len(symbols) > 0:' ' d = sp.solve(eqs, symbols, dict=True)' 'else:' ' d = sp.solve(eqs, dict=True)' '#' 'if len(d) >= 1 and len(d[0].keys()) == 1:' % one variable... ' if len(d) == 1:' % one variable, single solution ' return d[0].popitem()[1],' ' else:' % one variable, multiple solutions ' return sp.Matrix([r.popitem()[1] for r in d]),' '#' 'if len(d) == 1:' ' d = d[0]' 'return d,' }; out = python_cmd (cmd, varargin{:}); varargout = {out}; else % multiple outputs cmd = { 'eqs = list(); symbols = list()' 'for arg in _ins:' ' if arg.is_Relational:' ' eqs.append(arg)' ' else:' ' symbols.append(arg)' '#' 'if len(symbols) > 0:' ' (vars, solns) = sp.solve(eqs, symbols, set=True)' 'else:' ' (vars, solns) = sp.solve(eqs, set=True)' '#' 'd = []' 'for (i, var) in enumerate(vars):' ' d.append(sp.Matrix([t[i] for t in solns]))' 'return d,' }; out = python_cmd (cmd, varargin{:}); varargout = out; if (length(out) ~= nargout) warning('solve: number of outputs did not match solution vars'); end end end %!test %! % Simple, single variable, single solution %! syms x %! d = solve(10*x == 50); %! assert (isequal (d, 5)) %!test %! % Single variable, multiple solutions %! syms x %! d = solve(x^2 == 4); %! assert (length(d) == 2); %! assert (isequal (d, [2; -2]) || isequal (d, [-2; 2])) %!shared x,y,e %! syms x y %! e = 10*x == 20*y; %!test %! d = solve(e, x); %! assert (isequal (d, 2*y)) %!test %! d = solve(e, y); %! assert (isequal (d, x/2)) %!test %! d = solve(e); %! assert (isequal (d, 2*y)) %!test %! % now this works because we don't return a dict, see next comments %! d = solve(e, 2*x); %! assert (isequal (d, 4*y)) %%!test %%! % solve for 2*x (won't work on Matlab/Octave 3.6) %%! % FIXME: design a test with both x and y? Should we support this? %%! if exist('octave_config_info', 'builtin') %%! if (compare_versions (OCTAVE_VERSION (), '3.8.0', '>=')) %%! d = solve(e, 2*x); %%! s = d.('2*x'); %%! assert (isequal (s, 4*y)) %%! end %%! end %!test %! d = solve(2*x - 3*y == 0, x + y == 1); %! assert (isequal (d.x, sym(3)/5) && isequal(d.y, sym(2)/5)) %!test %! d = solve(2*x-3*y==0,x+y==1,x,y); %! assert (isequal (d.x, sym(3)/5) && isequal(d.y, sym(2)/5)) %!test %! % Multiple solutions, multiple variables %! d = solve(x^2 == 4, x + y == 1); %! assert (length(d) == 2); %! % FIXME: SMT has d.x gives vector and d.y giving vector, what is %! % more intuitive? %! for i = 1:2 %! assert (isequal (d{i}.x + d{i}.y, 1)) %! assert (isequal ((d{i}.x)^2, 4)) %! end %!test %! % No solutions %! syms x y z %! d = solve(x == y, z); %! assert (isempty (d)); %!test %! % Multiple outputs with single solution %! syms x y %! [X, Y] = solve(2*x + y == 5, x + y == 3); %! assert (isequal (X, 2)) %! assert (isequal (Y, 1)) %!test %! % Multiple outputs with multiple solns %! syms x y %! [X, Y] = solve(x*x == 4, x == 2*y); %! assert (isequal (X, [2; -2])) %! assert (isequal (Y, [1; -1])) %!test %! % Multiple outputs with multiple solns, specify vars %! syms x y %! [X, Y] = solve(x*x == 4, x == 2*y, x, y); %! assert (isequal (X, [2; -2])) %! assert (isequal (Y, [1; -1])) symbolic-2.2.4/inst/@sym/log.m0000644000175000001440000000253412633614672014662 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} log (@var{x}) %% Symbolic log function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = log(x) y = uniop_helper (x, 'log'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = log(x); %! f2 = log(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = log(A); %! f2 = log(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/log10.m0000644000175000001440000000220612633614672015017 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} log10 (@var{x}) %% Symbolic log base 10 function. %% %% @seealso{log,log2} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = log10(x) sf = 'lambda x: sp.log(x, 10)'; z = uniop_helper (x, sf); end %!assert (isequal (log10 (sym (1000)), sym (3))) %!assert (isequal (log10 (sym ([10 100])), sym ([1 2]))) symbolic-2.2.4/inst/@sym/nnz.m0000644000175000001440000000337312633614672014710 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{n} =} nnz (@var{A}) %% Number of non-zero elements in the symbolic array. %% %% @seealso{numel} %% @end deftypefn function n = nnz(A) % some future-proofing here for supporting symbolic sparse matrices % but what is SparseMatrix has bools in it? cmd = { 'def scalar2tf(a):' ' if a in (S.true, S.false):' ' return bool(a)' %' if a is S.NaN:' %' return True' ' return a != 0' 'A = _ins[0]' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'try:' ' n = A.nnz()' 'except AttributeError:' ' n = sum([scalar2tf(a) for a in A])' 'return n,' }; n = python_cmd (cmd, A); end %!assert (nnz (sym ([1])) == 1) %!assert (nnz (sym ([0])) == 0) %!assert (nnz (sym ([])) == 0) %!assert (nnz (sym ([1 0; 0 3])) == 2) %!test %! syms x %! assert (nnz ([x 0]) == 1) %!assert (nnz (sym (true)) == 1) %!assert (nnz (sym (false)) == 0) %!assert (nnz (sym (inf)) == 1) %!assert (nnz (sym (nan)) == 1) symbolic-2.2.4/inst/@sym/coeffs.m0000644000175000001440000001333312633614672015345 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of Octave-Symbolic-SymPy %% %% Octave-Symbolic-SymPy is free software; you can redistribute %% it and/or modify it under the terms of the GNU General Public %% License as published by the Free Software Foundation; %% either version 3 of the License, or (at your option) any %% later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{c} =} coeffs (@var{p}, @var{x}) %% @deftypefnx {Function File} {@var{c} =} coeffs (@var{p}) %% @deftypefnx {Function File} {[@var{c}, @var{t}] =} coeffs (@var{p}, @var{x}) %% @deftypefnx {Function File} {[@var{c}, @var{t}] =} coeffs (@var{p}) %% Return non-zero coefficients of symbolic polynomial. %% %% @var{c} contains the coefficients and @var{t} the corresponding %% terms. %% %% Example: %% @example %% @group %% >> syms x %% >> [c, t] = coeffs (x^6 + 3*x - 4) %% @result{} c = (sym) [1 3 -4] (1×3 matrix) %% t = (sym 1×3 matrix) %% ⎡ 6 ⎤ %% ⎣x x 1⎦ %% @end group %% @end example %% %% The polynomial can be multivariate: %% @example %% @group %% >> syms x y %% >> [c, t] = coeffs (x^2 + y*x) %% @result{} c = (sym) [1 1] (1×2 matrix) %% t = (sym 1×2 matrix) %% ⎡ 2 ⎤ %% ⎣x x⋅y⎦ %% %% @end group %% @group %% >> [c, t] = coeffs (x^2 + y*x, [x y]) % same %% @result{} c = (sym) [1 1] (1×2 matrix) %% t = (sym 1×2 matrix) %% ⎡ 2 ⎤ %% ⎣x x⋅y⎦ %% %% >> [c, t] = coeffs (x^2 + y*x, @{x y@}) % same %% @result{} c = (sym) [1 1] (1×2 matrix) %% t = (sym 1×2 matrix) %% ⎡ 2 ⎤ %% ⎣x x⋅y⎦ %% @end group %% @end example %% %% You can use the second argument to specify a vector or list of %% variables: %% @example %% @group %% >> [c, t] = coeffs (x^2 + y*x, x) %% @result{} c = (sym) [1 y] (1×2 matrix) %% t = (sym 1×2 matrix) %% ⎡ 2 ⎤ %% ⎣x x⎦ %% @end group %% @end example %% %% Omitting the second output gives only the coefficients: %% @example %% @group %% >> c = coeffs (x^6 + 3*x - 4) %% @result{} c = (sym) [1 3 -4] (1×3 matrix) %% @end group %% @end example %% WARNING: Matlab's Symbolic Math Toolbox returns c = [-4 3 1] %% here (as of version 2014a). I suspect they have a bug as its %% inconsistent with the rest of Matlab's polynomial routines. We %% do not copy this bug. %% %% @seealso{sym2poly} %% @end deftypefn function [c, t] = coeffs(p, x) if ~(isscalar(p)) error('coeffs: works for scalar input only'); end cmd = { 'f = _ins[0]' 'xx = _ins[1]' 'if xx == [] and f.is_constant():' % special case ' xx = sympy.S("x")' 'try:' ' xx = list(xx)' 'except TypeError:' ' xx = [xx]' 'p = Poly.from_expr(f, *xx)' 'terms = p.terms()' 'cc = [q[1] for q in terms]' 'tt = [1]*len(terms)' 'for i, x in enumerate(p.gens):' ' tt = [t*x**q[0][i] for (t, q) in zip(tt, terms)]' 'return (Matrix([cc]), Matrix([tt]))' }; % don't use symvar: if input has x, y we want both if (nargin == 1) [c, t] = python_cmd (cmd, sym(p), {}); else [c, t] = python_cmd (cmd, sym(p), sym(x)); end %% matlab SMT bug? % they seem to reverse the order if t is not output. %if (nargout == 1) % c = fliplr(c); %end % if nargout == 1, here is a simplier implementation: %cmd = { 'f = _ins[0]' % 'xx = _ins[1]' % 'try:' % ' xx = list(xx)' % 'except TypeError:' % ' xx = [xx]' % 'p = Poly.from_expr(f, *xx)' % 'c = p.coeffs()' % 'return Matrix([c]),' }; end %!test %! % simple %! syms x %! [c, t] = coeffs(6*x*x + 27); %! assert (isequal (c, [6 27])) %! assert (isequal (t, [x*x 1])) %!test %! % specify a variable %! syms x %! [c, t] = coeffs(6*x*x + 27, x); %! assert (isequal (c, [6 27])) %! assert (isequal (t, [x*x 1])) %!test %! % specify another variable %! syms x y %! [c, t] = coeffs(6*x + 27, y); %! assert (isequal (c, 6*x + 27)) %! assert (isequal (t, 1)) %%!test %%! % weird SMT order %%! syms x %%! a1 = [27 6]; %%! a2 = [6 27]; %%! c = coeffs(6*x*x + 27); %%! assert (isequal (c, a1)) %%! [c, t] = coeffs(6*x*x + 27); %%! assert (isequal (c, a2)) %!test %! % multivariable array %! syms x y %! [c, t] = coeffs(6*x*x + 27*y*x + 36, [x y]); %! a = [6 27 36]; %! s = [x^2 x*y 1]; %! assert (isequal (c, a)) %! assert (isequal (t, s)) %! % with list %! [c, t] = coeffs(6*x*x + 27*y*x + 36, {x y}); %! assert (isequal (c, a)) %! assert (isequal (t, s)) %!test %! % other symbols treated as part of coeffs %! syms x y %! [c, t] = coeffs(6*x*x + 27*y*x + 36, x); %! a = [6 27*y 36]; %! s = [x^2 x 1]; %! assert (isequal (c, a)) %! assert (isequal (t, s)) %!test %! % empty same as no specifying %! syms x y %! [c, t] = coeffs(6*x*x + 27*y*x + 36, {}); %! a = [6 27 36]; %! assert (isequal (c, a)) %! [c, t] = coeffs(6*x*x + 27*y*x + 36); %! assert (isequal (c, a)) %!test %! % no input defaults to all symbols (not symvar to get x) %! syms x y %! [c, t] = coeffs(6*x*x + 27*y*x + 36); %! assert (isequal (c, [6 27 36])) %!test %! % non sym input %! syms x %! assert (isequal (coeffs(6, x), sym(6))) %!test %! % constant input without x %! assert (isequal (coeffs(sym(6)), sym(6))) symbolic-2.2.4/inst/@sym/erf.m0000644000175000001440000000253412633614672014655 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} erf (@var{x}) %% Symbolic erf function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = erf(x) y = uniop_helper (x, 'erf'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = erf(x); %! f2 = erf(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = erf(A); %! f2 = erf(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/pinv.m0000644000175000001440000000244112633614672015052 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{B} =} pinv (@var{A}) %% Symbolic Moore-Penrose pseudoinverse of a matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = pinv(x) cmd = { 'x, = _ins' 'if not x.is_Matrix:' ' x = sp.Matrix([[x]])' 'return x.pinv(),' }; z = python_cmd (cmd, x); end %!test %! % scalar %! syms x %! assert (isequal (pinv(x), 1/x)) %!test %! % 2x3 %! A = [1 2 3; 4 5 6]; %! assert (max (max (abs (double (pinv (sym (A))) - pinv(A)))) <= 10*eps) symbolic-2.2.4/inst/@sym/resize.m0000644000175000001440000000210712633614672015376 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {} resize () %% Overloaded resize for sym class, perhaps unnecessary. %% %% FIXME: do we need this? %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = resize(a, n, m) error('resize: not implemented'); end %!assert(true) % so far, everything works :) symbolic-2.2.4/inst/@sym/eq.m0000644000175000001440000000767212633614672014516 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} eq (@var{a}, @var{b}) %% Test for symbolic equality, and/or define equation. %% %% @code{a == b} tries to convert both @code{a} and @code{b} to %% numbers and compare them as doubles. If this fails, it defines %% a symbolic expression for @code{a == b}. When each happens is a %% potential source of bugs! %% %% FIXME: Notes from SMT: %% @itemize %% @item If any varibles appear in the matrix, then you get a matrix %% of equalities: syms x; a = sym([1 2; 3 x]); a == 1 %% @item @code{x==x} is an equality, rather than @code{true}. %% We currently satisfy neither of these (FIXME). %% @end itemize %% %% FIXME: from reading SymPy's @code{Eq??}, the following would %% seem to work: %% @code{>>> e = relational.Relational.__new__(relational.Eq, x, x)} %% (but passing this to solve() is still different from SMT). %% %% FIXME: array case is hardcoded only to check for equality (see logical()). %% to get the SMT, could do two passes through the array. %% %% @seealso{logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = eq(x,y) t = ineq_helper('[donotuse]', 'Eq', x, y); end %!test %! % simple tests with scalar numbers %! assert (logical (sym(1) == sym(1))) %! assert (logical (sym(1) == 1)) %! assert (~logical (sym(1) == 0)) %! assert (isequal (sym(1) == sym(1), sym(true))) %! assert (isequal (sym(1) == 1, sym(true))) %! assert (isequal (sym(1) == 0, sym(false))) %!test %! % Type of the output is sym or logical? %! % FIXME: in current version, they are sym %! e = sym(1) == sym(1); %! %assert (islogical (e)) %! assert (isa (e, 'sym')) %!test %! % things involving a variable are usually not bool but sym. %! % (SMT behaviour says always, FIXME: currently we differ.) %! syms x %! e = x == 0; %! assert (~islogical (e)) %! assert (isa (e, 'sym')) %!test %! % ... except of course via cancelation %! syms x %! e = x - x == 0; %! assert (logical (e)) %! assert (isequal (e, sym(true))) %!test %! % array == array %! a = sym([1 2; 3 4]); %! y = a == a; %! assert (isequal( size(y), [2 2])) %! assert (isequal (y, sym([true true; true true]))) %! assert (all(all(y))) %! y = a == 1; %! assert (isequal( size(y), [2 2])) %! assert (isequal (y, sym([true false; false false]))) %! assert (any(any(y))) %! y = a == 42; %! assert (isequal( size(y), [2 2])) %! assert (isequal (y, sym([false false; false false]))) %!test %! % more array == array %! D = [0 1; 2 3]; %! A = [sym(0) 1; sym(2) 3]; %! DZ = D - D; %! assert (isequal (logical(A == A), [true true; true true])) %! assert (isequal (logical(A == D), [true true; true true])) %! assert (isequal (logical(A - D == DZ), [true true; true true])) %! assert (all (all ( A == A ))) %! assert (all (all ( A == D ))) %! assert (all (all ( A - D == DZ ))) %!test %! % logical output, right shape, etc %! t = true; f = false; %! a = sym([0 1 2; 3 4 5]); %! b = sym([0 1 1; 3 5 5]); %! e = a == b; %! eexp = sym(logical([1 1 0; 1 0 1])); %! assert (isequal (e, eexp)) %! a = sym([0 1 2]); %! b = sym([0 1 1]); %! e = a == b; %! eexp = sym(logical([1 1 0])); %! assert (isequal (e, eexp)) %! e = a' == b'; %! eexp = eexp.'; % is/was bug here with ' %! assert (isequal (e, eexp)) symbolic-2.2.4/inst/@sym/columns.m0000644000175000001440000000221112633614672015551 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{n} =} columns (@var{x}) %% Return the number of columns in a symbolic array. %% %% @seealso{columns, size, length, numel} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function n = columns(x) n = size(x, 2); end %!test %! a = sym([1 2 3]); %! assert (columns(a) == 3) %!test %! a = sym([1; 2]); %! assert (columns(a) == 1) symbolic-2.2.4/inst/@sym/dirac.m0000644000175000001440000000257312633614672015166 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} dirac (@var{x}) %% Symbolic dirac function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = dirac(x) y = uniop_helper (x, 'DiracDelta'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = dirac(x); %! f2 = 0; %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = dirac(A); %! f2 = 0; %! f2 = [f2 f2; f2 f2]; %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/fourier.m0000644000175000001440000000743212633614672015556 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% Copyright (C) 2014, 2015 Andrés Prieto, Alexander Misel, Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{FF} =} fourier (@var{f}, @var{x}, @var{k}) %% @deftypefnx {Function File} {@var{FF} =} fourier (@var{f}) %% @deftypefnx {Function File} {@var{FF} =} fourier (@var{f}, @var{k}) %% Symbolic Fourier transform. %% %% Example: %% @example %% @group %% >> syms x %% >> f = exp(-abs(x)); %% >> fourier(f) %% @result{} (sym) %% 2 %% ────── %% 2 %% w + 1 %% @end group %% @end example %% %% Note @code{fourier} and @code{ifourier} implement the non-unitary, %% angular frequency convention. %% %% *WARNING*: As of SymPy 0.7.6 (June 2015), there are many problems %% with fourier transforms, even very simple ones. Use at your own risk, %% or even better: help us fix SymPy. %% %% @seealso{ifourier} %% @end deftypefn %% Author: Colin B. Macdonald, Andrés Prieto %% Keywords: symbolic, integral transforms function F = fourier(varargin) % FIXME: it only works for scalar functions % FIXME: it doesn't handle diff call (see SMT transform of diff calls) % If the physical variable of f is equal to "w", % "v" is the frequency domain variable (analogously to SMT) if (nargin == 1) f = sym(varargin{1}); x = symvar(f, 1); if (isempty(x)) x = sym('x'); end cmd = { 'f=_ins[0]; x=_ins[1]; k=sp.Symbol("w")' 'if x==k:' ' k=sp.Symbol("v")' 'F = sp.fourier_transform(f, x, k/(2*sp.pi))' 'return F,'}; F = python_cmd(cmd, f, x); elseif (nargin == 2) f = sym(varargin{1}); k = sym(varargin{2}); x = symvar(f, 1); if (isempty(x)) x = sym('x'); % FIXME: should be dummy variable in case k was x end cmd = { 'f=_ins[0]; x=_ins[1]; k=_ins[2]' 'F = sp.fourier_transform(f, x, k/(2*sp.pi))' 'return F,'}; F = python_cmd(cmd, f, x, k); elseif (nargin == 3) f = sym(varargin{1}); x = sym(varargin{2}); k = sym(varargin{3}); cmd = { 'f=_ins[0]; x=_ins[1]; k=_ins[2]' 'F = sp.fourier_transform(f, x, k/(2*sp.pi))' 'return F,'}; F = python_cmd(cmd, f, x, k); else print_usage (); end end %!test %! % matlab SMT compatibiliy for arguments %! syms r x u w v %! assert(logical( fourier(exp(-abs(x))) == 2/(w^2 + 1) )) %! assert(logical( fourier(exp(-abs(w))) == 2/(v^2 + 1) )) %! assert(logical( fourier(exp(-abs(r)),u) == 2/(u^2 + 1) )) %! assert(logical( fourier(exp(-abs(r)),r,u) == 2/(u^2 + 1) )) %!test %! % basic tests %! syms x w %! Pi=sym('pi'); assert(logical( fourier(exp(-x^2)) == sqrt(Pi)/exp(w^2/4) )) %! assert(logical( fourier(x*exp(-abs(x))) == -(w*4*1i)/(w^4 + 2*w^2 + 1) )) %!xtest %! % Issue #251, upstream failure? TODO: upstream issue? %! syms x w %! f = fourier(sym(2), x, w); %! assert (isequal (f, 4*sym(pi)*dirac(w))) %!xtest %! % Differential operator to algebraic %! % SymPy cannot evaluate? (Issue #170) %! syms x w f(x) %! assert(logical( fourier(diff(f(x),x),x,w) == -1i*w*fourier(f(x),x,w) )) symbolic-2.2.4/inst/@sym/acosh.m0000644000175000001440000000255412633614672015200 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} acosh (@var{x}) %% Symbolic acosh function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = acosh(x) y = uniop_helper (x, 'acosh'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = acosh(x); %! f2 = acosh(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = acosh(A); %! f2 = acosh(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/rhs.m0000644000175000001440000000306512633614672014675 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{L} =} rhs (@var{f}) %% Right-hand side of symbolic expression. %% %% Gives an error if any of the symbolic objects have no right-hand side. %% %% @seealso{lhs, children} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function R = rhs(f) cmd = { 'f, = _ins' 'flag = 0' 'r = 0' 'if f.is_Matrix:' ' try:' ' r = f.applyfunc(lambda a: a.rhs)' ' except:' ' flag = 1' 'else:' ' try:' ' r = f.rhs' ' except:' ' flag = 1' 'return (flag, r)' }; [flag, R] = python_cmd (cmd, f); if (flag) error('rhs: one or more entries have no ''rhs'' attribute') end end %% most tests are in lhs %!test %! syms x %! f = x + 1 == 2*x; %! assert (isequal (rhs(f), 2*x)) symbolic-2.2.4/inst/@sym/transpose.m0000644000175000001440000000426012633614672016115 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} transpose (@var{x}) %% Structural transpose (not conjugate) of a symbolic array. %% %% Example: %% @example %% @group %% >> syms z %% >> syms x real %% >> A = [1 x z; sym(4) 5 6+7i] %% @result{} A = (sym 2×3 matrix) %% ⎡1 x z ⎤ %% ⎢ ⎥ %% ⎣4 5 6 + 7⋅ⅈ⎦ %% >> transpose(A) %% @result{} (sym 3×2 matrix) %% ⎡1 4 ⎤ %% ⎢ ⎥ %% ⎢x 5 ⎥ %% ⎢ ⎥ %% ⎣z 6 + 7⋅ⅈ⎦ %% @end group %% @end example %% %% This can be abbreviated to: %% @example %% @group %% >> A.' %% @result{} (sym 3×2 matrix) %% ⎡1 4 ⎤ %% ⎢ ⎥ %% ⎢x 5 ⎥ %% ⎢ ⎥ %% ⎣z 6 + 7⋅ⅈ⎦ %% @end group %% @end example %% %% @seealso{ctranspose} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = transpose(x) cmd = { 'x = _ins[0]' ... 'if x.is_Matrix:' ... ' return x.T,' ... 'else:' ... ' return x,' }; z = python_cmd (cmd, x); end %!test %! x = sym(1); %! assert (isequal (x.', x)) %!assert (isempty (sym([]).')) %!test %! syms x; %! assert (isequal (x.', x)) %!test %! A = [1 2; 3 4]; %! assert(isequal( sym(A).' , sym(A.') )) %!test %! A = [1 2] + 1i; %! assert(isequal( sym(A).' , sym(A.') )) symbolic-2.2.4/inst/@sym/sum.m0000644000175000001440000000512212633614672014701 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} sum (@var{x}) %% @deftypefnx {Function File} {@var{y} =} sum (@var{x}, @var{n}) %% Sum of symbolic expressions. %% %% Sum over the rows or columns of an expression. By default, sum %% over the rows. Can specify row or column sums using @var{n}. %% To perform symbolic summations, see @xref{symsum}. %% %% Examples: %% @example %% @group %% >> syms x y z %% >> sum([x y z]) %% @result{} (sym) x + y + z %% %% >> sum([x y; x z], 1) %% @result{} (sym) [2⋅x y + z] (1×2 matrix) %% %% >> sum([x y; x z], 2) %% @result{} (sym 2×1 matrix) %% ⎡x + y⎤ %% ⎢ ⎥ %% ⎣x + z⎦ %% %% @end group %% @end example %% @seealso{prod, symsum} %% @end deftypefn function y = sum(x, n) x = sym(x); if (isscalar(x)) y = x; return end if (nargin == 1) if (isrow(x)) n = 2; elseif (iscolumn(x)) n = 1; else n = 1; end else n = double(n); end %y = python_cmd ({'return sp.prod(_ins[0]),'}, x); cmd = { 'A = _ins[0]' 'B = sp.Matrix.zeros(A.rows, 1)' 'for i in range(0, A.rows):' ' B[i] = sum(A.row(i))' 'return B,' }; if (n == 1) y = python_cmd (cmd, transpose(x)); y = transpose(y); elseif (n == 2) y = python_cmd (cmd, x); else print_usage (); end end %!shared x,y,z %! syms x y z %!assert (isequal (sum (x), x)) %!assert (isequal (sum ([x y z]), x+y+z)) %!assert (isequal (sum ([x; y; z]), x+y+z)) %!assert (isequal (sum ([x y z], 1), [x y z])) %!assert (isequal (sum ([x y z], 2), x+y+z)) %!shared a,b %! b = [1 2; 3 4]; a = sym(b); %!assert (isequal (sum(a), sum(b))) %!assert (isequal (sum(a,1), sum(b,1))) %!assert (isequal (sum(a,2), sum(b,2))) %!test %! % weird inputs %! a = sum('xx', sym(1)); %! assert (isequal (a, sym('xx'))) symbolic-2.2.4/inst/@sym/vertcat.m0000644000175000001440000000737612633614672015562 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} vertcat (@var{x}, @var{y}, @dots{}) %% Vertically concatentate symbolic arrays. %% %% @seealso{horzcat} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function h = vertcat(varargin) % special case for 0x0 but other empties should be checked for % compatibilty cmd = { '_proc = []' 'for i in _ins:' ' if i.is_Matrix:' ' if i.shape == (0, 0):' ' pass' ' else:' ' _proc.append(i)' ' else:' ' _proc.append(sp.Matrix([[i]]))' 'failed = False' 'M = "whatev"' 'try:' ' M = sp.Matrix.vstack(*_proc)' 'except ShapeError:' ' failed = True' 'return (failed, M)' }; varargin = sym(varargin); [flag, h] = python_cmd (cmd, varargin{:}); if (flag) error('vertcat: ShapeError: incompatible sizes concatenated') end end %!test %! % basic %! syms x %! A = [x; x]; %! B = vertcat(x, x); %! C = vertcat(x, x, x); %! assert (isa (A, 'sym')) %! assert (isa (B, 'sym')) %! assert (isa (C, 'sym')) %! assert (isequal (size(A), [2 1])) %! assert (isequal (size(B), [2 1])) %! assert (isequal (size(C), [3 1])) %!test %! % basic, part 2 %! syms x %! A = [x; 1]; %! B = [1; x]; %! C = [1; 2; x]; %! assert (isa (A, 'sym')) %! assert (isa (B, 'sym')) %! assert (isa (C, 'sym')) %! assert (isequal (size(A), [2 1])) %! assert (isequal (size(B), [2 1])) %! assert (isequal (size(C), [3 1])) %!test %! % column vectors %! a = [sym(1); 2]; %! b = [sym(3); 4]; %! assert (isequal ( [a;b] , [1; 2; 3; 4] )) %! assert (isequal ( [a;b;a] , [1; 2; 3; 4; 1; 2] )) %!test %! % row vectors %! a = [sym(1) 2]; %! b = [sym(3) 4]; %! assert (isequal ( [a;b] , [1 2; 3 4] )) %! assert (isequal ( [a;b;a] , [1 2; 3 4; 1 2] )) %!test %! % row vector, other row %! a = [sym(1) 2]; %! assert (isequal ( [a; [sym(3) 4]] , [1 2; 3 4] )) %!test %! % empty vectors %! v = [sym(1) sym(2)]; %! a = [v; []]; %! assert (isequal (a, v)) %! a = [[]; v; []]; %! assert (isequal (a, v)) %! a = [v; []; []]; %! assert (isequal (a, v)) %!xtest %! % FIXME: is this Octave bug? worth worrying about %! syms x %! a = [x; [] []]; %! assert (isequal (a, x)) %!test %! % more empty vectors %! v = [sym(1) sym(2)]; %! q = sym(ones(0, 2)); %! assert (isequal ([v; q], v)) %!error %! % FIXME: clean-up when we drop 0.7.5 support (Issue #164) %! if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=75) %! disp('skipping: test passes on sympy >= 0.7.6') %! error('ShapeError') % pass the test with correct error %! else %! v = [sym(1) sym(2)]; %! q = sym(ones(0, 3)); %! w = [v; q]; %! end %!test %! % Octave 3.6 bug: should pass on 3.8.1 and matlab %! a = [sym(1) 2]; %! assert (isequal ( [a; [3 4]] , [1 2; 3 4] )) %! assert (isequal ( [a; sym(3) 4] , [1 2; 3 4] )) %! % more examples %! syms x %! [x [x x]; x x x]; %! [[x x] x; x x x]; %! [[x x] x; [x x] x]; %! [x x x; [x x] x]; symbolic-2.2.4/inst/@sym/mrdivide.m0000644000175000001440000000374412633614672015710 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mrdivide (@var{x}, @var{y}) %% Forward slash division of symbolic expressions (/). %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mrdivide(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = mrdivide(x, y); return end if isscalar(x) && isscalar(y) z = rdivide(x, y); elseif isscalar(x) && ~isscalar(y) error('FIXME: scalar/array not implemented yet'); elseif ~isscalar(x) && isscalar(y) z = rdivide(x, y); else % two array's case error('FIXME: array/array not implemented yet'); end end %!test %! % scalar %! syms x %! assert (isa( x/x, 'sym')) %! assert (isequal( x/x, sym(1))) %! assert (isa( 2/x, 'sym')) %! assert (isa( x/2, 'sym')) %!test %! % matrix / scalar %! D = 2*[0 1; 2 3]; %! A = sym(D); %! assert (isequal ( A/2 , D/2 )) %! assert (isequal ( A/sym(2) , D/2 )) %!error %! A = [1 2; 3 4]; %! B = sym(1) / A; %!error %! A = [1 2; 3 4]; %! B = sym(A); %! C = A / B; symbolic-2.2.4/inst/@sym/acos.m0000644000175000001440000000254412633614672015027 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} acos (@var{x}) %% Symbolic acos function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = acos(x) y = uniop_helper (x, 'acos'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = acos(x); %! f2 = acos(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = acos(A); %! f2 = acos(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/display.m0000644000175000001440000001400612633614672015543 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} display (@var{x}) %% Display, on command line, the contents of a symbolic expression. %% %% Examples: %% @example %% @group %% >> x = sym('x') %% @result{} x = (sym) x %% %% >> display(x) %% @result{} x = (sym) x %% %% >> display([x 2 pi]) %% @result{} (sym) [x 2 π] (1×3 matrix) %% @end group %% @end example %% %% Other examples: %% @example %% @group %% >> A = sym([1 2; 3 4]) %% @result{} A = (sym 2×2 matrix) %% ⎡1 2⎤ %% ⎢ ⎥ %% ⎣3 4⎦ %% %% >> syms n %% >> B = A^n %% @result{} B = (sym 2×2 matrix expression) %% n %% ⎛⎡1 2⎤⎞ %% ⎜⎢ ⎥⎟ %% ⎝⎣3 4⎦⎠ %% @end group %% %% @group %% >> A = sym(ones(0, 3)) %% @result{} A = (sym) [] (empty 0×3 matrix) %% %% >> B = 3*A^n %% @result{} B = (sym empty 0×3 matrix expression) %% n %% 3⋅([]) %% @end group %% @end example %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function display(x) %% Settings wh = sympref('display'); if (strcmp(wh, 'unicode')) unicode_dec = true; else unicode_dec = false; end display_snippet = sympref('snippet'); if (exist('OCTAVE_VERSION', 'builtin') && ... compare_versions (OCTAVE_VERSION (), '4.0.0', '>=')) % Octave 4.1 dropped (temporarily?) the get(0,...) approach loose = eval('! __compactformat__ ()'); else % Matlab and Octave < 4 loose = strcmp(get(0, 'FormatSpacing'), 'loose'); end %% Get terminal width, mainly for snippets % works in matlab gui & -nodesktop but not the most up-to-date % approach [term_width] = get(0, 'CommandWindowSize'); if (isequal(term_width, [0 0])) % octave gives [0 0], at least as of August 2014. [term_width] = terminal_size(); % octave has [height width] term_width = term_width(2); else % matlab has [width height] term_width = term_width(1); end % weird hack to support "ans(x) = " output for @symfun name = priv_disp_name(x, inputname (1)); dispstr = disp (x); dispstrtrim = strtrim (dispstr); hasnewlines = ~isempty (strfind (dispstrtrim, sprintf('\n'))); [desc_start, desc_end] = sym_describe (x, unicode_dec); if display_snippet toobig = true; else toobig = hasnewlines; %toobig = hasnewlines || ~(isempty(x) || isscalar(x)); end s1 = ''; if (~isempty(name)) s1 = sprintf ('%s = ', name); end if (toobig) if (isempty(desc_end)) s2 = sprintf('(%s)', desc_start); else s2 = sprintf('(%s %s)', desc_start, desc_end); end else if (isempty(desc_end)) s2 = sprintf('(%s) %s', desc_start, dispstrtrim); else s2 = sprintf('(%s) %s (%s)', desc_start, dispstrtrim, desc_end); end end s = [s1 s2]; n = ustr_length (s); %fputs (1, s); % only in octave, not matlab fprintf (s) if (display_snippet) % again, fputs safer, but not in matlab fprintf (snippet_of_sympy (x, 7, term_width - n, unicode_dec)) end fprintf ('\n'); if (toobig) if (loose), fprintf ('\n'); end % don't use printf b/c ascii-art might have slashes disp (dispstr(1:end-1)); % remove existing newline, disp adds one if (loose), fprintf ('\n'); end end end function [s1 s2] = sym_describe(x, unicode_dec) if (unicode_dec) timesstr = '×'; else timesstr = 'x'; end s1 = class (x); srepr = char (x); d = size (x); % sort of isinstance(x, MatrixExpr) but cheaper is_matrix_symbol = false; matexprlist = {'MatrixSymbol' 'MatMul' 'MatAdd' 'MatPow'}; for i=1:length(matexprlist) if (strncmp(srepr, matexprlist{i}, length(matexprlist{i}))) is_matrix_symbol = true; end end if (isscalar (x)) && (~is_matrix_symbol) s2 = ''; elseif (is_matrix_symbol) %if (any(isnan(d))) % may not tell the truth if (any(isnan(x.size))) [nn, mm] = python_cmd('return (_ins[0].rows, _ins[0].cols)', x); numrstr = strtrim(disp(nn, 'flat')); numcstr = strtrim(disp(mm, 'flat')); else nn = d(1); mm = d(2); numrstr = num2str(d(1), '%g'); numcstr = num2str(d(2), '%g'); end if (logical(nn == 0) || logical(mm == 0)) estr = 'empty '; else estr = ''; end s2 = sprintf ('%s%s%s%s matrix expression', estr, numrstr, timesstr, numcstr); elseif (length (d) == 2) if (isempty (x)) estr = 'empty '; else estr = ''; end s2 = sprintf ('%s%g%s%g matrix', estr, d(1), timesstr, d(2)); else s2 = sprintf ('%d-dim array', length (d)) end end function snip = snippet_of_sympy(x, padw, width, unicode) if (unicode) ell = '…'; lquot = '“'; rquot = '”'; else ell = '...'; lquot = '"'; rquot = lquot; end rightpad = 1; pad = repmat(' ', 1, padw); % trim newlines (if there are any) s = regexprep (char (x), '\n', '\\n'); snip = [pad lquot s rquot]; if (ustr_length (snip) > width) n = width - rightpad - padw - ustr_length ([lquot rquot ell]); if (n < 8) snip = ''; else snip = sprintf ([pad lquot '%s' ell rquot], s(1:n)); end end end % FIXME: Could quietly test with "evalc", but [missing in % Octave](https://savannah.gnu.org/patch/?8033). For now, a dummy % test. Doctests will cover this anyway. %!test %! assert(true) symbolic-2.2.4/inst/@sym/subsref.m0000644000175000001440000001477512633614672015564 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{out} =} subsref (@var{f}, @var{idx}) %% Access entries of a symbolic array. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function out = subsref (f, idx) %disp('call to @sym/subsref') switch idx.type case '()' % sym(sym) indexing in Matlab gets here (on Octave, subsindex % does it) for i=1:length(idx.subs) if (isa(idx.subs{i}, 'sym')) idx.subs{i} = subsindex(idx.subs{i})+1; end end out = mat_access(f, idx.subs); case '.' fld = idx.subs; if (strcmp (fld, 'pickle')) out = f.pickle; elseif (strcmp (fld, 'flat')) out = f.flat; elseif (strcmp (fld, 'ascii')) out = f.ascii; elseif (strcmp (fld, 'unicode')) out = f.unicode; elseif (strcmp (fld, 'extra')) out = f.extra; % not part of the interface %elseif (strcmp (fld, 'size')) % out = f.size; else error ('@sym/subsref: invalid or nonpublic property ''%s''', fld); end otherwise error ('@sym/subsref: invalid subscript type ''%s''', idx.type); end end %!shared a,b %! b = [1:4]; %! a = sym(b); %!assert(isequal( a(1), b(1) )) %!assert(isequal( a(2), b(2) )) %!assert(isequal( a(4), b(4) )) %!assert(isempty( a([]) )) %!shared a,b %! b = [1:4]; b = [b; 3*b; 5*b]; %! a = sym(b); %!assert(isequal( a(1), b(1) )) %!assert(isequal( a(2), b(2) )) %!assert(isequal( a(4), b(4) )) %!assert(isequal( a(:,:), a )) %!assert(isequal( a(1:2,1:3), a(1:2,1:3) )) %!assert(isequal( a(1:2:3,[1 2 4]), b(1:2:3,[1 2 4]) )) %!assert(isequal( a(1:2:3,[4 2 3 1]), b(1:2:3,[4 2 3 1]) )) % repeats %!assert(isequal( a(1:2:3,[4 1 1 1]), b(1:2:3,[4 1 1 1]) )) %!assert(isequal( a([],:), b([],:) )) %!assert(isequal( size(a([],:)), [0 4] )) %!assert(isequal( a(1:2,[]), b(1:2,[]) )) %!assert(isequal( size(a(1:2,[])), [2 0] )) %!assert(isempty( a(1:2,[]) )) %!assert(isempty( a([],[]) )) %!assert(isequal( a([],[]), sym([]) )) %!assert(~isequal( a(1:2,[]), sym([]) )) %!shared e %! e = sym([1 3 5; 2 4 6]); %!assert(isequal( e(:), sym((1:6)') )) %!assert(isequal( e([1 2 3]), sym([1 2 3]) )) %!assert(isequal( e([1; 3; 4]), sym([1; 3; 4]) )) %!assert(isempty( e([]) )) %!assert(isequal( e([]), sym([]) )) %!shared a,b %! b = 1:5; a = sym(b); %!assert(isequal( a([1 2 5]), b([1 2 5]) )) %!assert(isequal( a([1; 2; 5]), b([1; 2; 5]) )) %!shared x %! syms x %% logical with empty result %!test %! assert(isempty( x(false) )) %! a = [x x]; %! assert(isempty( a([false false]) )) %% issue 18, scalar access %!test %! assert(isequal( x(1), x )) %! assert(isequal( x(true), x )) %!test %! % older access tests %! syms x %! f = [x 2; 3 4*x]; %! % element access %! assert (logical( f(1,1) == x )) %! assert (logical( f(1,2) == 2 )) %! % linear access of 2d array %! assert (logical( f(1) == x )) %! assert (logical( f(2) == 3 )) % column based %! assert (logical( f(3) == 2 )) %!shared a,b %! % effectively a random matrix %! a = reshape( round(50*(sin(1:20)+1)), 5,4); %! b = sym(a); %!test %! % older array refs test %! assert (logical(b(1,1) == a(1,1))) %! assert (logical(b(3,1) == a(3,1))) %! assert (logical(b(1,3) == a(1,3))) %! assert (logical(b(4,4) == a(4,4))) %!test %! % older array refs test: linear indices %! assert (logical(b(1) == a(1))) %! assert (logical(b(3) == a(3))) %! assert (logical(b(13) == a(13))) %!test %! % older array refs test: end %! assert (all(all(logical( b(end,1) == a(end,1) )))) %! assert (all(all(logical( b(2,end) == a(2,end) )))) %! assert (all(all(logical( b(end,end) == a(end,end) )))) %! assert (all(all(logical( b(end-1,1) == a(end-1,1) )))) %! assert (all(all(logical( b(2,end-1) == a(2,end-1) )))) %! assert (all(all(logical( b(end-1,end-1) == a(end-1,end-1) )))) %!test %! % older slicing tests %! syms x %! a = [1 2 3 4 5 6]; a = [a; 3*a; 5*a; 2*a; 4*a]; %! b = sym(a); %! assert (isequal( b(:,1), a(:,1) )) %! assert (isequal( b(:,2), a(:,2) )) %! assert (isequal( b(1,:), a(1,:) )) %! assert (isequal( b(2,:), a(2,:) )) %! assert (isequal( b(:,:), a(:,:) )) %! assert (isequal( b(1:3,2), a(1:3,2) )) %! assert (isequal( b(1:4,:), a(1:4,:) )) %! assert (isequal( b(1:2:5,:), a(1:2:5,:) )) %! assert (isequal( b(1:2:4,:), a(1:2:4,:) )) %! assert (isequal( b(2:2:4,3), a(2:2:4,3) )) %! assert (isequal( b(2:2:4,3), a(2:2:4,3) )) %!test %! % 2D arrays %! b = [1:4]; b = [b; 3*b; 5*b]; %! a = sym(b); %! I = rand(size(b)) > 0.5; %! assert (isequal (a(I), b(I))) %! I = I(:); %! s = warning ('off', 'OctSymPy:subsref:index_matrix_not_same_shape'); %! assert (isequal (a(I), b(I))) %! I = I'; %! assert (isequal (a(I), b(I))) %! warning (s) %! I = logical(zeros(size(b))); %! assert (isequal (a(I), b(I))) %!warning %! % some warnings when I is wrong shape %! r = [1:6]; %! ar = sym(r); %! c = r'; %! ac = sym(c); %! Ir = rand(size(r)) > 0.5; %! temp = ac(Ir); %!warning %! % some warnings when I is wrong shape %! r = [1:6]; %! ar = sym(r); %! c = r'; %! ac = sym(c); %! Ic = rand(size(c)) > 0.5; %! temp = ar(Ic); %!test %! % 1D arrays, does right with despite warning %! r = [1:6]; %! ar = sym(r); %! c = r'; %! ac = sym(c); %! Ir = rand(size(r)) > 0.5; %! Ic = rand(size(c)) > 0.5; %! assert (isequal (ar(Ir), r(Ir))) %! assert (isequal (ac(Ic), c(Ic))) %! s = warning ('off', 'OctSymPy:subsref:index_matrix_not_same_shape'); %! assert (isequal (ar(Ic), r(Ic))) %! assert (isequal (ac(Ir), c(Ir))) %! warning (s) %!test %! % rccross tests %! B = [1 2 3 4; 5 6 7 9; 10 11 12 13]; %! A = sym(B); %! assert (isequal (A([1 3],[2 3]), B([1 3], [2 3]) )) %! assert (isequal (A(1,[2 3]), B(1,[2 3]) )) %! assert (isequal (A([1 2],4), B([1 2],4) )) %! assert (isequal (A([2 1],[4 2]), B([2 1],[4 2]) )) %! assert (isequal (A([],[]), B([],[]) )) symbolic-2.2.4/inst/@sym/det.m0000644000175000001440000000244712633614672014660 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} det (@var{x}) %% Symbolic determinant of a matrix. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = det(x) cmd = { '(A,) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'return A.det(),' }; z = python_cmd (cmd, x); end %!assert (isequal (det(sym([])), 1)) %!test %! syms x y real %! assert (isequal (det([x 5; 7 y]), x*y-35)) %!test %! syms x %! assert (isequal (det(x), x)) %! assert (isequal (det(sym(-6)), sym(-6))) symbolic-2.2.4/inst/@sym/subsindex.m0000644000175000001440000000532312633614672016104 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{i} =} subsindex (@var{x}) %% Used to implement indexing by sym. %% %% Note returns zero-based index. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function b = subsindex(x) % check if all bool or all integer cmd = { '(A,) = _ins' 'if not A.is_Matrix:' ' A = sp.Matrix([A])' 'if all([x.is_Integer for x in A]):' ' return 1,' 'elif all([x in (S.true, S.false) for x in A]):' ' return 2,' 'else:' ' return 0,' }; flag = python_cmd (cmd, x); assert(isnumeric(flag)) if (flag == 0) error('OctSymPy:subsindex:values', 'subscript indices must be integers or boolean'); elseif (flag == 1) % integer b = double(x) - 1; % zero-based elseif (flag == 2) % boolean b = find(logical(x)) - 1; % zero-based else error('subsindex: programming error'); end end %!test %! i = sym(1); %! a = 7; %! assert(a(i)==a); %! i = sym(2); %! a = 2:2:10; %! assert(a(i)==4); %!test %! i = sym([1 3 5]); %! a = 1:10; %! assert( isequal (a(i), [1 3 5])) %!test %! i = sym([1 3 5]); %! a = sym(1:10); %! assert( isequal (a(i), sym([1 3 5]))); %!test %! % should be an error if it doesn't convert to double %! syms x %! a = 1:10; %! try %! a(x) %! waserr = false; %! catch %! waserr = true; %! end %! assert(waserr) %!test %! syms x %! assert (isequal (x(sym (true)), x)) %! assert (isequal (x(sym (false)), sym ([]))) %!test %! x = 6; %! assert (isequal (x(sym (true)), 6)) %! assert (isequal (x(sym (false)), [])) %!test %! a = sym([10 12 14]); %! assert (isequal (a(sym ([true false true])), a([1 3]))) %! assert (isequal (a(sym ([false false false])), sym (ones(1,0)))) %!test %! a = [10 11; 12 13]; %! p = [true false; true true]; %! assert (isequal (a(sym (p)), a(p))) %! p = [false false false]; %! assert (isequal (a(sym (p)), a(p))) %!error %! a = [10 12]; %! I = [sym(true) 2]; %! b = a(I); symbolic-2.2.4/inst/@sym/limit.m0000644000175000001440000000730112633614672015214 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} limit (@var{expr}, @var{x}, @var{a}, @var{dir}) %% @deftypefnx {Function File} {@var{y} =} limit (@var{expr}, @var{x}, @var{a}) %% @deftypefnx {Function File} {@var{y} =} limit (@var{expr}, @var{a}) %% @deftypefnx {Function File} {@var{y} =} limit (@var{expr}) %% Evaluate symbolic limits. %% %% The limit of @var{expr} as @var{x} tends to @var{a} from %% @var{dir}. @var{dir} can be @code{left} or @code{right}. %% %% Examples: %% @example %% @group %% >> syms x %% >> L = limit(sin(x)/x, x, 0) %% @result{} L = (sym) 1 %% >> L = limit(1/x, x, sym(inf)) %% @result{} L = (sym) 0 %% >> L = limit(1/x, x, 0, 'left') %% @result{} L = (sym) -∞ %% >> L = limit(1/x, x, 0, 'right') %% @result{} L = (sym) ∞ %% @end group %% @end example %% %% If @var{x} is omitted, @code{symvar} is used to determine the %% variable. If @var{a} is omitted, it defaults to 0. %% %% @var{dir} defaults to @code{right}. Note this is different from %% Matlab's Symbolic Math Toolbox which returns @code{NaN} for %% @code{limit(1/x, x, 0)} %% (and @code{+/-inf} if you specify @code{left/right}). I'm not %% sure how to get this nicer behaviour from SymPy. %% FIXME: this is https://github.com/cbm755/octsympy/issues/74 %% %% @seealso{diff} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function L = limit(f, x, a, dir) if (nargin > 4 || nargin < 1) print_usage (); end if (nargin < 4) dir= 'right'; end if (nargin == 2) a = x; x = symvar(f, 1); end if (nargin == 1) x = symvar(f, 1); a = 0; end switch (lower (dir)) case {'left' '-'} pdir = '-'; case {'right' '+'} pdir = '+'; otherwise print_usage (); end cmd = { '(f, x, a, pdir) = _ins' 'if f.is_Matrix:' ' g = f.applyfunc(lambda b: b.limit(x, a, dir=pdir))' 'else:' ' g = f.limit(x, a, dir=pdir)' 'return g,' }; L = python_cmd (cmd, sym(f), sym(x), sym(a), pdir); end %!shared x, oo %! syms x %! oo = sym(inf); %!assert (isa (limit(x, x, pi), 'sym')) %!assert (isequal (limit(x, x, pi), sym(pi))) %!assert (isequal (limit(sin(x)/x, x, 0), 1)) %!test %! % left/right-hand limit %! assert (isequal (limit(1/x, x, 0, 'right'), oo)) %! assert (isequal (limit(1/x, x, 0), oo)) %! assert (isequal (limit(1/x, x, 0, 'left'), -oo)) %! assert (isequal (limit(1/x, x, oo), 0)) %! assert (isequal (limit(sign(x), x, 0, 'left'), -1)) %! assert (isequal (limit(sign(x), x, 0, 'right'), 1)) %! assert (isequal (limit(sign(x), x, 0, '-'), -1)) %! assert (isequal (limit(sign(x), x, 0, '+'), 1)) %!test %! % matrix %! syms y %! A = [x 1/x x*y]; %! B = sym([3 sym(1)/3 3*y]); %! assert (isequal (limit(A, x, 3), B)) %!test %! % omitting arguments %! syms a %! assert (isequal (limit(a*x+a+2), a+2)) %! assert (isequal (limit(a*x+a+2, 6), 7*a+2)) %! assert (isequal (limit(sym(6)), 6)) %! assert (isequal (limit(sym(6), 7), 6)) symbolic-2.2.4/inst/@sym/lambertw.m0000644000175000001440000000462712633614672015723 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} lambertw (@var{x}) %% @deftypefnx {Function File} {@var{y} =} lambertw (@var{k}, @var{x}) %% Symbolic Lambert W function. %% %% The Lambert W function is the inverse of @code{W*exp(W)}. The %% branch @var{k} defaults to zero if omitted. %% %% Examples: %% @example %% @group %% >> syms x %% >> lambertw(x) %% @result{} (sym) LambertW(x) %% >> lambertw(2, x) %% @result{} (sym) LambertW(x, 2) %% @end group %% @end example %% (@strong{Note} that the branch @var{k} must come first in the %% input but it comes last in the output.) %% %% Also supports vector/matrix input: %% @example %% @group %% >> syms x y %% >> lambertw([0 1], [x y]) %% @result{} (sym) [LambertW(x) LambertW(y, 1)] (1×2 matrix) %% @end group %% @end example %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function W = lambertw(k, x) if (nargin == 1) x = sym(k); W = uniop_helper (x, 'LambertW'); else x = sym(x); k = sym(k); W = binop_helper (x, k, 'LambertW'); end end %!test %! % W(x)*exp(W(x)) == x %! syms x %! T = lambertw(x)*exp(lambertw(x)); %! T = double (subs (T, x, 10)); %! assert (isequal (T, 10)); %!test %! % k, x not x, k to match SMT %! if (str2num(strrep(python_cmd ('return sp.__version__,'),'.',''))<=75) %! disp('skipping: SymPy 0.7.5 is too old') % clean up in Issue #164 %! else %! syms x %! T = lambertw(2, x)*exp(lambertw(2, x)); %! T = double (subs (T, x, 10)); %! assert (abs(T - 10) < 1e-15) %! end %!xtest %! % W(x)*exp(W(x)) == x; FIXME: a failure in SymPy? %! syms x %! T = simplify(lambertw(x)*exp(lambertw(x))); %! assert (isequal (T, x)) symbolic-2.2.4/inst/@sym/setdiff.m0000644000175000001440000000430412633614672015522 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} setdiff (@var{A}, @var{B}) %% Set subtraction. %% %% @seealso{union, intersect, setxor, unique, ismember} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = setdiff(A, B) % FIXME: is it worth splitting out a "private/set_helper"? cmd = { 'A, B = _ins' 'try:' ' A = iter(A)' 'except TypeError:' ' A = set([A])' 'else:' ' A = set(A)' 'try:' ' B = iter(B)' 'except TypeError:' ' B = set([B])' 'else:' ' B = set(B)' 'C = A.difference(B)' 'C = sympy.Matrix([list(C)])' 'return C,' }; A = sym(A); B = sym(B); r = python_cmd (cmd, A, B); % reshape to column if both inputs are if (iscolumn(A) && iscolumn(B)) r = reshape(r, length(r), 1); end end %!test %! A = sym([1 2 3]); %! B = sym([1 2 4]); %! C = setdiff(A, B); %! D = sym([3]); %! assert (isequal (C, D)) %!test %! % one nonsym %! A = sym([1 2 3]); %! B = [1 2 4]; %! C = setdiff(A, B); %! D = sym([3]); %! assert (isequal (C, D)) %!test %! % empty %! A = sym([1 2 3]); %! C = setdiff(A, A); %! assert (isempty (C)) %!test %! % empty input %! A = sym([1 2]); %! C = setdiff(A, []); %! assert (isequal (C, A) || isequal (C, sym([2 1]))) %!test %! % scalar %! syms x %! assert (isequal (setdiff([x 1], x), sym(1))) %! assert (isempty (setdiff(x, x))) symbolic-2.2.4/inst/@sym/hessian.m0000644000175000001440000000503712633614672015534 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{H} =} hessian (@var{f}) %% @deftypefnx {Function File} {@var{H} =} hessian (@var{f}, @var{x}) %% Symbolic Hessian matrix of symbolic scalar expression. %% %% @var{x} can be a scalar, vector or cell list. If omitted, %% it is determined using @code{symvar}. %% %% @seealso{jacobian, divergence, gradient, curl, laplacian} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function H = hessian(f,x) assert (isscalar(f), 'hessian: defined for scalar functions') if (nargin == 1) x = symvar(f); if (isempty(x)) x = sym('x'); end end if (~iscell(x) && isscalar(x)) x = {x}; end cmd = { '(f,x,) = _ins' '#if not f.is_Matrix:' 'f = Matrix([f])' 'grad = f.jacobian(x).T' 'H = grad.jacobian(x)' 'return H,' }; H = python_cmd (cmd, sym(f), x); end %!shared x,y,z %! syms x y z %!test %! % 1D %! f = x^2; %! assert (isequal (hessian(f), diff(f,x,x))) %! assert (isequal (hessian(f,{x}), diff(f,x,x))) %! assert (isequal (hessian(f,x), diff(f,x,x))) %!test %! % const %! f = sym(1); %! g = sym(0); %! assert (isequal (hessian(f), g)) %! assert (isequal (hessian(f,x), g)) %!test %! % double const %! f = 1; %! g = sym(0); %! assert (isequal (hessian(f,x), g)) %!test %! % linear %! f = 42*x; %! g = sym(0); %! assert (isequal (hessian(f), g)) %! assert (isequal (hessian(f,x), g)) %!test %! % linear %! f = 42*x - sym('a')*y; %! g = [0 0; 0 0]; %! assert (isequal (hessian(f, {x y}), g)) %!test %! % 2d %! f = x*cos(y); %! g = [0 -sin(y); -sin(y) -f]; %! assert (isequal (hessian(f), g)) %! assert (isequal (hessian(f, {x y}), g)) %!test %! % 3d %! f = x*cos(z); %! Hexp = [0 0 -sin(z); sym(0) 0 0; -sin(z) 0 -f]; %! H = hessian(f, {x y z}); %! assert (isequal (H, Hexp)) symbolic-2.2.4/inst/@sym/or.m0000644000175000001440000000311312633614672014513 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{z} =} or (@var{x}, @var{y}) %% Logical or of symbolic arrays. %% %% @seealso{and, not, xor, eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = or(x, y) r = binop_helper(x, y, 'lambda a,b: Or(a, b)'); end %!shared t, f %! t = sym(true); %! f = sym(false); %!test %! % simple %! assert (isequal (t | f, t)) %! assert (isequal (t | t, t)) %! assert (isequal (f | f, f)) %!test %! % array %! w = [t t f f]; %! z = [t f t f]; %! assert (isequal (w | z, [t t t f])) %!xtest %! % output is sym even for scalar t/f %! % ₣IXME: should match other bool fcns %! assert (isa (t | f, 'sym')) %!test %! % eqns %! syms x %! e = or(x == 4, x == 5); %! assert (isequal (subs(e, x, [3 4 5 6]), [f t t f])) symbolic-2.2.4/inst/@sym/isinf.m0000644000175000001440000000704612633614672015214 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isinf (@var{x}) %% Return true if a symbolic expression is infinite. %% %% FIXME: Sympy returns "none" for isinf(x + oo), perhaps we should %% say "I don't know" in some cases too. SMT seems to always decide... %% %% @seealso{isnan, double} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = isinf(x) % FIXME: port to uniop_helper, how to return bools then? if isscalar(x) cmd = { 'd = _ins[0]' 'if sympy.__version__ == "0.7.5":' ' d = d.is_unbounded' 'else:' ' d = d.is_infinite' 'if d == True:' ' return True,' 'elif d == False:' ' return False,' 'else:' ' return False,' }; r = python_cmd (cmd, x); if (~ islogical(r)) error('nonboolean return from python'); end else % array r = logical(zeros(size(x))); for j = 1:numel(x) % Bug #17 idx.type = '()'; idx.subs = {j}; r(j) = isinf(subsref(x, idx)); end end end %!shared x,zoo,oo,snan %! oo = sym(inf); %! zoo = sym('zoo'); %! x = sym('x'); %! snan = sym(nan); %!test %! % various ops that give inf and nan %! assert (isinf(oo)) %! assert (isinf(zoo)) %! assert (isinf(oo+oo)) %! assert (~isinf(oo+zoo)) %! assert (~isinf(0*oo)) %! assert (~isinf(0*zoo)) %! assert (~isinf(snan)) %! assert (~isinf(oo-oo)) %! assert (~isinf(oo-zoo)) %!test %! % arrays %! assert (isequal( isinf([oo zoo]), [1 1] )) %! assert (isequal( isinf([oo 1]), [1 0] )) %! assert (isequal( isinf([10 zoo]), [0 1] )) %! assert (isequal( isinf([x oo x]), [0 1 0] )) %!test %! % Must not contain string 'symbol'; these all should make an %! % actual infinity. Actually a ctor test, not isinf. %! % IIRC, SMT in Matlab 2013b fails. %! oo = sym(inf); %! assert (isempty( strfind(oo.pickle, 'Symbol') )) %! oo = sym(-inf); %! assert (isempty( strfind(oo.pickle, 'Symbol') )) %! oo = sym('inf'); %! assert (isempty( strfind(oo.pickle, 'Symbol') )) %! oo = sym('-inf'); %! assert (isempty( strfind(oo.pickle, 'Symbol') )) %! oo = sym('Inf'); %! assert (isempty( strfind(oo.pickle, 'Symbol') )) %! oo = sym('INF'); %! assert (isempty( strfind(oo.pickle, 'Symbol') )) %!test %! % ops with infinity shouldn't collapse %! syms x oo zoo %! y = x + oo; %! assert(~isempty( strfind(lower(y.pickle), 'add') )) %! y = x - oo; %! assert(~isempty( strfind(lower(y.pickle), 'add') )) %! y = x - zoo; %! assert(~isempty( strfind(lower(y.pickle), 'add') )) %! y = x*oo; %! assert(~isempty( strfind(lower(y.pickle), 'mul') )) %!test %! % ops with infinity are not necessarily infinite %! syms x oo zoo %! y = x + oo; %! assert(~isinf(y)) % SMT 2014a says "true", I disagree %! y = x - zoo; %! assert(~isinf(y)) %! y = x*oo; %! assert(~isinf(y)) symbolic-2.2.4/inst/@sym/isprime.m0000644000175000001440000000451412633614672015551 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} isprime (@var{n}) %% Return true if a symbolic number is prime. %% %% @seealso{nextprime} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = isprime(x) %sf = { 'def sf(x):' ' return x.is_prime' }; % could just call uniop_helper but this way we can catch the errors sf = { 'def sf(x):' ' if not x.is_integer or not x.is_nonnegative:' ' raise NameError("isprime: input must be nonnegative integer")' ' r = x.is_prime' ' if r is None:' ' raise NameError("isprime: cannot determine if input is prime")' ' return r' }; cmd = { sf{:} ... '(x,) = _ins' ... 'try:' ... ' if x.is_Matrix:' ... ' return (True, x.applyfunc(lambda a: sf(a)))' ... ' else:' ... ' return (True, sf(x))' ... 'except NameError as e:' ... ' return (False, str(e))' ... }; [r, z] = python_cmd (cmd, x); if (~r) error(z) end z = logical(z); end %!assert (isprime (sym(5))) %!assert (~isprime (sym(4))) %!assert (~isprime (sym(0))) %!assert (~isprime (sym(1))) %!test %! a = [5 7 6; 1 2 337]; %! assert (isequal (isprime (a), [true true false; false true true])) %!error isprime(sym(-4)) %!error isprime(sym(4i)) %!error isprime(sym(3)/5) %!error isprime(sym('x')) %!error %! syms x positive %! x = assumeAlso(x, 'integer'); %! isprime(x) symbolic-2.2.4/inst/@sym/ctranspose.m0000644000175000001440000000617612633614672016270 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} ctranspose (@var{x}) %% Conjugate (Hermitian) transpose of a symbolic array. %% %% Example: %% @example %% @group %% >> syms z %% >> syms x real %% >> A = [1 x z; sym(4) 5 6+7i] %% @result{} A = (sym 2×3 matrix) %% ⎡1 x z ⎤ %% ⎢ ⎥ %% ⎣4 5 6 + 7⋅ⅈ⎦ %% >> ctranspose(A) %% @result{} (sym 3×2 matrix) %% ⎡1 4 ⎤ %% ⎢ ⎥ %% ⎢x 5 ⎥ %% ⎢ ⎥ %% ⎢_ ⎥ %% ⎣z 6 - 7⋅ⅈ⎦ %% @end group %% @end example %% %% This can be abbreviated to: %% @example %% @group %% >> A' %% @result{} (sym 3×2 matrix) %% ⎡1 4 ⎤ %% ⎢ ⎥ %% ⎢x 5 ⎥ %% ⎢ ⎥ %% ⎢_ ⎥ %% ⎣z 6 - 7⋅ⅈ⎦ %% @end group %% @end example %% %% @seealso{transpose, conj} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = ctranspose(x) cmd = { 'x = _ins[0]' ... '# special case for Boolean terms' ... 'if x.has(S.true) or x.has(S.false):' ... ' def sf(x):' ... ' if x in (S.true, S.false):' ... ' return x' ... ' return x.conjugate()' ... ' if x.is_Matrix:' ... ' z = x.T' ... ' return z.applyfunc(lambda a: sf(a)),' ... ' else:' ... ' return sf(x),' ... 'if x.is_Matrix:' ... ' return x.H,' ... 'else:' ... ' return x.conjugate(),' }; z = python_cmd (cmd, x); end %!test %! x = sym(1); %! assert (isequal (x', x)) %!assert (isempty (sym([])')) %!test %! % conjugate does nothing to real x %! syms x real %! assert (isequal (x', x)) %!test %! % complex %! syms x %! assert (isequal (x', conj(x))) %!test %! % complex array %! syms x %! A = [x 2*x]; %! B = [conj(x); 2*conj(x)]; %! assert(isequal(A', B)) %!test %! A = [1 2; 3 4]; %! assert(isequal( sym(A)' , sym(A') )) %!test %! A = [1 2] + 1i; %! assert(isequal( sym(A)' , sym(A') )) %!test %! % true/false %! t = sym(true); %! f = sym(false); %! assert (isequal ( t', t)) %! assert (isequal ( f', f)) %!test %! % more true/false %! syms x %! A = [x true 1i]; %! B = [conj(x); true; -sym(1i)]; %! assert (isequal ( A', B)) symbolic-2.2.4/inst/@sym/fortran.m0000644000175000001440000000764612633614672015565 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{s} =} fortran (@var{g}) %% @deftypefnx {Function File} {@var{s} =} fortran (@var{g1}, @dots{}, @var{gn}) %% @deftypefnx {Function File} {} fortran (@dots{}, 'file', @var{filename}) %% @deftypefnx {Function File} {[@var{F}, @var{H}] =} fortran (@dots{}, 'file', '') %% Convert symbolic expression into C code. %% %% Example: %% @example %% @group %% >> syms x %% >> g = taylor(log(1 + x), x, 0, 'order', 5); %% >> g = horner(g) %% @result{} g = (sym) %% ⎛ ⎛ ⎛ x 1⎞ 1⎞ ⎞ %% x⋅⎜x⋅⎜x⋅⎜- ─ + ─⎟ - ─⎟ + 1⎟ %% ⎝ ⎝ ⎝ 4 3⎠ 2⎠ ⎠ %% >> fortran(g) %% @result{} x*(x*(x*(-1.0d0/4.0d0*x + 1.0d0/3.0d0) - 1.0d0/2.0d0) + 1) %% @end group %% @end example %% %% We can write to a file or obtain the contents directly: %% @example %% @group %% >> [f90, h] = fortran(g, 'file', '', 'show_header', false); %% >> f90.name %% @result{} file.f90 %% >> h.name %% @result{} file.h %% >> f90.code %% @result{} %% REAL*8 function myfun(x) %% implicit none %% REAL*8, intent(in) :: x %% %% myfun = x*(x*(x*(-1.0d0/4.0d0*x + 1.0d0/3.0d0) - 1.0d0/2.0d0) + 1) %% %% end function %% %% >> h.code %% @result{} %% interface %% REAL*8 function myfun(x) %% implicit none %% REAL*8, intent(in) :: x %% end function %% end interface %% @end group %% @end example %% %% FIXME: This doesn't write "optimized" code like Matlab's %% Symbolic Math Toolbox; it doesn't do "Common Subexpression %% Elimination". Presumably the compiler would do that for us %% anyway. Sympy has a "cse" module that will do it. See: %% http://stackoverflow.com/questions/22665990/optimize-code-generated-by-sympy %% %% @seealso{ccode, latex, function_handle} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = fortran(varargin) [flg, meh] = codegen(varargin{:}, 'lang', 'F95'); if flg == 0 varargout = {}; elseif flg == 1 varargout = meh(1); elseif flg == 2 varargout = {meh{1}, meh{2}}; else error('whut?'); end end %!shared x,y,z %! syms x y z %!test %! % basic test %! f = x*sin(y) + abs(z); %! source = fortran(f); %! expected = ' x*sin(y) + Abs(z)'; %! assert(strcmp(source, expected)) %!test %! % output test %! f = x*sin(y) + abs(z); %! [F,H] = fortran(f, 'file', '', 'show_header', false); %! expected_h_code = sprintf('\ninterface\nREAL*8 function myfun(x, y, z)\nimplicit none\nREAL*8, intent(in) :: x\nREAL*8, intent(in) :: y\nREAL*8, intent(in) :: z\nend function\nend interface\n\n'); %! expected_f_code = sprintf('\nREAL*8 function myfun(x, y, z)\nimplicit none\nREAL*8, intent(in) :: x\nREAL*8, intent(in) :: y\nREAL*8, intent(in) :: z\n\nmyfun = x*sin(y) + Abs(z)\n\nend function\n'); %! assert(strcmp(F.name, 'file.f90')) %! assert(strcmp(H.name, 'file.h')) %! %disp(expected_f_code); disp(F.code) %! s1 = strrep(expected_f_code, sprintf('\n'), sprintf('\r\n')); %! s2 = strrep(expected_h_code, sprintf('\n'), sprintf('\r\n')); %! assert (strcmp (F.code, expected_f_code) || strcmp (F.code, s1)) %! assert (strcmp (H.code, expected_h_code) || strcmp (H.code, s2)) symbolic-2.2.4/inst/@sym/symreplace.m0000644000175000001440000001750412633614672016250 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} symreplace (@var{newx}) %% @deftypefnx {Function File} {} symreplace (@var{x}, @var{newx}) %% @deftypefnx {Function File} {} symreplace (@var{x}, @var{newx}, @var{context}) %% @deftypefnx {Function File} {} symreplace (@var{xstr}, @var{newx}) %% @deftypefnx {Function File} {} symreplace (@var{xstr}, @var{newx}, @var{context}) %% @deftypefnx {Function File} {[@var{f}, @var{flag}] =} symreplace (@var{f}, @var{xstr}, @var{newx}) %% Replace symbols in caller's workspace or in syms/struct/cells. %% %% @strong{WARNING}: you probably do not need this for normal %% usage; @pxref{subs} instead. %% %% One mode of operation is similar to @code{subs()}: %% @example %% @group %% >> syms x y %% >> f = @{x; 2*x; sin(x)@}; %% >> g = symreplace(f, x, y) %% @result{} g = %% @{ %% (sym) y %% (sym) 2⋅y %% (sym) sin(y) %% @} %% >> g = symreplace(f, 'x', y); % alternative %% @end group %% @end example %% However, unlike @code{subs()}, here @code{f} can be a cell array %% or struct, which we recursively traverse down into. %% %% @var{flag} is true if the output @var{f} was changed from %% the input @var{f}: %% @example %% @group %% >> syms x y %% >> f = sin(y); %% >> [g, flag] = symreplace(f, x, y) %% @result{} g = (sym) sin(y) %% flag = 0 %% @end group %% @end example %% %% The alternative form using @var{xstr} is used internally by %% OctSymPy for assumptions (@pxref{assume}, @pxref{assumeAlso}), %% to replace one @code{x} with another @code{x} with possibly %% different assumptions. For example: %% @example %% @group %% >> syms x positive %% >> f = x^2; %% >> assumptions(f)@{:@} %% @result{} x: positive %% >> x = sym('x', 'real'); %% >> f = symreplace(f, 'x', x); %% >> assumptions(f)@{:@} %% @result{} x: real %% @end group %% @end example %% %% The other mode of operation is also used by OctSymPy for %% supporting assumptions. It has no output but plenty of %% side-effects! Not scared off yet? Here's what it does: %% @example %% @group %% >> syms x real %% >> f = abs(x); %% >> syms x positive %% >> f %% @result{} f = (sym) │x│ %% >> symreplace ('x', x) %% >> f %% @result{} f = (sym) x %% @end group %% @end example %% %% Here is the scary part: this works by searching expressions in %% the @strong{callers workspace} for variables with same name as %% @var{x}/@var{xstr}. We then substitute @var{newx}. If @var{x} %% is omitted, the string of @var{newx} is used instead. This is %% precisely what happens when using @code{assume}: %% @example %% @group %% >> syms x %% >> f = abs(x); %% >> assume(x, 'positive') %% >> f %% @result{} f = (sym) x %% @end group %% @end example %% %% Note: operates on the caller's workspace via evalin/assignin. %% So if you call this from other functions, it will operate in %% your function's workspace (not the @code{base} workspace). %% You can pass @code{'base'} to @var{context} to operate in %% the base context instead. %% %% Note for developers: if you want to call this from your function %% but have it work on the 'caller' context %% @strong{of your function}, that unfortunately does not seem to %% be possible. Copy-paste the highlighted bits of this code into %% your function instead (see @code{assume} for example). %% %% @seealso{assume, assumeAlso, assumptions, sym, syms} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = symreplace(varargin) %% This is the first ("benign") form if ((nargout >= 1) || (nargin == 3 && ~ischar(varargin{3}))) [varargout{1:2}] = symreplace_helper(varargin{:}); return end %% otherwise, no output: this is the scary one if (nargin == 1) newx = varargin{1}; xstr = newx.flat; context = 'caller'; elseif (nargin == 2) xstr = varargin{1}; newx = varargin{2}; context = 'caller'; elseif (nargin == 3) xstr = varargin{1}; newx = varargin{2}; context = varargin{3}; else print_usage (); end assert(ischar(context) && ... (strcmp(context, 'caller') || strcmp(context, 'base'))) % we just want the string if (isa(xstr, 'sym')) xstr = xstr.flat; end %% Here's the piece with side-effects % This is the part that you might want to copy into your function % --------------------------------------------- % Muck around in the caller's namespace, replacing syms % that match 'xstr' (a string) with the 'newx' sym. %xstr = %newx = %context = 'caller'; S = evalin(context, 'whos'); evalin(context, '[];'); % clear 'ans' for i = 1:numel(S) obj = evalin(context, S(i).name); [newobj, flag] = symreplace(obj, xstr, newx); if flag, assignin(context, S(i).name, newobj); end end % --------------------------------------------- %% end of side-effects bit end function [newobj, flag] = symreplace_helper(obj, xstr, newx) % If you need to add other things other than struct/cell/sym, this is % place to do it. if (isa (xstr, 'sym')) xstr = xstr.flat; end assert (ischar (xstr)) flag = false; if isa(obj, 'sym') % check if contains any symbols with the same string as x. symlist = findsymbols(obj); for c = 1:length(symlist) if strcmp(xstr, symlist{c}.flat) flag = true; break end end % If so, subs in the new x and replace that variable. if (flag) newobj = subs(obj, symlist{c}, newx); end if isa(obj, 'symfun') warning('FIXME: need to do anything special for symfun vars?') end elseif iscell(obj) %fprintf('Recursing into a cell array of numel=%d\n', numel(obj)) newobj = obj; flag = false; for i=1:numel(obj) [temp, flg] = symreplace_helper(obj{i}, xstr, newx); if (flg) newobj{i} = temp; flag = true; end end elseif isstruct(obj) %fprintf('Recursing into a struct array of numel=%d\n', numel(obj)) newobj = obj; fields = fieldnames(obj); for i=1:numel(obj) for j=1:length(fields) thisobj = getfield(obj, {i}, fields{j}); [temp, flg] = symreplace_helper(thisobj, xstr, newx); if (flg) % This requires work on octave but not on matlab! Instead, gratuitous % use of eval()... %newobj = setfield(newobj, {i}, fields{j}, temp); eval(sprintf('newobj(%d).%s = temp;', i, fields{j})); flag = true; end end end end if ~(flag) newobj = obj; end end %!test %! % start with assumptions on x then remove them %! syms x positive %! f = x*10; %! symreplace(x, sym('x')) %! assert(isempty(assumptions(x))) %!test %! % replace x with y %! syms x %! f = x*10; %! symreplace(x, sym('y')) %! assert( isequal (f, 10*sym('y'))) %!test %! % gets inside cells %! syms x %! f = {x 1 2 {3 4*x}}; %! symreplace(x, sym('y')) %! syms y %! assert( isequal (f{1}, y)) %! assert( isequal (f{4}{2}, 4*y)) %!test %! % gets inside structs/cells %! syms x %! my.foo = {x 1 2 {3 4*x}}; %! my.bar = x; %! g = {'ride' my 'motor' 'sicle'}; %! symreplace(x, sym('y')) %! syms y %! f = g{2}; %! assert( isequal (f.foo{1}, y)) %! assert( isequal (f.foo{4}{2}, 4*y)) %! assert( isequal (f.bar, y)) symbolic-2.2.4/inst/@sym/gamma.m0000644000175000001440000000255412633614672015165 0ustar cbmusers%% Copyright (C) 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} gamma (@var{x}) %% Symbolic gamma function. %% %% Note: this file is autogenerated: if you want to edit it, you might %% want to make changes to 'generate_functions.py' instead. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function y = gamma(x) y = uniop_helper (x, 'gamma'); end %!shared x, d %! d = 1; %! x = sym('1'); %!test %! f1 = gamma(x); %! f2 = gamma(d); %! assert( abs(double(f1) - f2) < 1e-15 ) %!test %! D = [d d; d d]; %! A = [x x; x x]; %! f1 = gamma(A); %! f2 = gamma(D); %! assert( all(all( abs(double(f1) - f2) < 1e-15 ))) symbolic-2.2.4/inst/@sym/sym2poly.m0000644000175000001440000001053112633614672015673 0ustar cbmusers%% Copyright (C) 2003 Willem J. Atsma %% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This program is free software; you can redistribute it and/or %% modify it under the terms of the GNU General Public %% License as published by the Free Software Foundation; %% either version 3, or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR %% PURPOSE. See the GNU General Public License for more %% details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. If not, %% see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{c} =} sym2poly (@var{p}) %% @deftypefnx {Function File} {@var{c} =} sym2poly (@var{p}, @var{x}) %% Return vector of coefficients of a symbolic polynomial. %% %% In the two-input form, the second argument @var{x} specifies the free %% variable; in this case this function returns a row vector @var{c} of %% symbolic expressions. The coefficients correspond to decreasing exponent %% of the free variable. Example: %% @example %% @group %% syms x y %% sym2poly(2*x^2 + 3*x - pi, x) %% @result{} (sym) [2 3 -π] (1×3 matrix) %% sym2poly(x^2 + y*x, x) %% @result{} (sym) [1 y 0] (1×3 matrix) %% @end group %% @end example %% %% @strong{Warning}: Using the single-argument form, the coefficient vector %% @var{c} is a plain numeric vector (double). This is for compatibility %% with the Matlab Symbolic Math Toolbox, and could change in future versions %% of OctSymPy. We thus recommend using @code{double} explicitly as in: %% @example %% @group %% syms x %% double(sym2poly(pi*x^2 + 3*x/2 + exp(sym(1)))) %% @result{} 3.1416 1.5000 2.7183 %% @end group %% @end example %% %% If @var{p} is not a polynomial the result has no warranty. SymPy can %% certainly deal with more general concepts of polynomial but we do not %% yet expose all of that here. %% %% @seealso{poly2sym, polyval, roots} %% @end deftypefn %% Created: 18 April 2003 %% Changed: 25 April 2003 %% Removed the use of differentiate to get to coefficients - round-off %% errors cause problems. Now using newly created sumterms(). %% Changed: 6 May 2003 %% Removed the attempt to use ldegree(), degree() and coeff() - results %% with these are inconsistent. %% Changed: 16 April 2014 %% Used the comment header and tests in OctSymPy, but rewrote %% the body (by Colin Macdonald). function c = sym2poly(p, x) if ~(isscalar(p)) error('works for scalar input only'); end if (nargin == 1) ss = findsymbols(p); if (length(ss) >= 2) error('Input has more than one symbol: not clear what you want me to do') end x = ss{1}; convert_to_double = true; else convert_to_double = false; end cmd = { 'f = _ins[0]' 'x = _ins[1]' 'p = Poly.from_expr(f,x)' 'return p.all_coeffs(),' }; c2 = python_cmd (cmd, sym(p), sym(x)); if (isempty(c2)) error('Empty python output, can this happen? A bug.') end % FIXME: should be able to convert c2 to array faster than array % expansion! Particularly in the case where we just convert to % double anyway! c = sym([]); for j = 1:numel(c2) % Bug #17 %c(j) = c2{j}; idx.type = '()'; idx.subs = {j}; c = subsasgn(c, idx, c2{j}); end if (convert_to_double) c = double(c); end end %!shared x,y,a,b,c %! syms x y a b c %!assert (isequal (sym2poly (x^2 + 3*x - 4), [1 3 -4])) %!assert (isequal (sym2poly (x^6 - x^3), [1 0 0 -1 0 0 0])) %!assert (isequal (sym2poly (x^2 + 3*x - 4, x), [1 3 -4])) %!assert (norm (sym2poly (pi*x^2 + exp(sym(1))) - [pi 0 exp(1)]) < 10*eps) %% types %!assert (isa (sym2poly (x^2 + 3*x - 4), 'double')) %!assert (isa (sym2poly (x^2 + 3*x - 4, x), 'sym')) %% tests with other vars %!assert (isequal (sym2poly (x^2+y*x, x), [sym(1) y sym(0)])) %!assert (isequal (sym2poly (x^2+y*x, y), [x x^2])) %% inverse relationship %!assert (isequal (sym2poly (poly2sym ([a b c], x), x), [a b c])) %!assert (isequal (poly2sym (sym2poly(a*x^2 + c, x), x), a*x^2 + c)) %!assert (isequal (sym2poly (poly2sym ([1 2 3])), [1 2 3])) %!error %! % too many symbols for single-input %! p = a*x^2 + 2; %! c = sym2poly (p); symbolic-2.2.4/inst/@sym/assume.m0000644000175000001440000001142412633614672015374 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{x} =} assume (@var{x}, @var{cond}, @var{cond2}, @dots{}) %% @deftypefnx {Function File} {} assume (@var{x}, @var{cond}) %% New assumptions on a symbolic variable (replace old if any). %% %% This function has two different behaviours depending on whether %% it has an output argument or not. The first form is simpler; %% it returns a new sym with assumptions given by @var{cond}, for %% example: %% @example %% @group %% >> syms x %% >> x1 = x; %% >> x = assume(x, 'positive'); %% >> assumptions(x) %% @result{} ans = %% @{ %% [1,1] = x: positive %% @} %% >> assumptions(x1) % empty, x1 still has the original x %% @result{} ans = @{@}(0x0) %% @end group %% @end example %% %% Another example to help clarify: %% @example %% @group %% >> x1 = sym('x', 'positive'); %% >> x2 = assume(x1, 'negative'); %% >> assumptions(x1) %% @result{} ans = %% @{ %% [1,1] = x: positive %% @} %% >> assumptions(x2) %% @result{} ans = %% @{ %% [1,1] = x: negative %% @} %% @end group %% @end example %% %% %% The second form---with no output argument---is different; it %% attempts to find @strong{all} instances of symbols with the same name %% as @var{x} and replace them with the new version (with @var{cond} %% assumptions). For example: %% @example %% @group %% >> syms x %% >> x1 = x; %% >> f = sin(x); %% >> assume(x, 'positive'); %% >> assumptions(x) %% @result{} ans = %% @{ %% [1,1] = x: positive %% @} %% >> assumptions(x1) %% @result{} ans = %% @{ %% [1,1] = x: positive %% @} %% >> assumptions(f) %% @result{} ans = %% @{ %% [1,1] = x: positive %% @} %% @end group %% @end example %% %% @strong{Warning}: this second form operates on the caller's %% workspace via evalin/assignin. So if you call this from other %% functions, it will operate in your function's workspace (and not %% the @code{base} workspace). This behaviour is for compatibility %% with other symbolic toolboxes. %% %% FIXME: idea of rewriting all sym vars is a bit of a hack, not %% well tested (for example, with global vars.) %% %% @seealso{assumeAlso, assumptions, sym, syms} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function varargout = assume(x, varargin) for n=2:nargin cond = varargin{n-1}; ca.(cond) = true; end xstr = x.flat; newx = sym(xstr, ca); if (nargout > 0) varargout{1} = newx; return end % --------------------------------------------- % Muck around in the caller's namespace, replacing syms % that match 'xstr' (a string) with the 'newx' sym. %xstr = %newx = context = 'caller'; % --------------------------------------------- S = evalin(context, 'whos'); evalin(context, '[];'); % clear 'ans' for i = 1:numel(S) obj = evalin(context, S(i).name); [newobj, flag] = symreplace(obj, xstr, newx); if flag, assignin(context, S(i).name, newobj); end end % --------------------------------------------- end %!test %! syms x %! x = assume(x, 'positive'); %! a = assumptions(x); %! assert(strcmp(a, 'x: positive')) %! x = assume(x, 'even'); %! a = assumptions(x); %! assert(strcmp(a, 'x: even')) %! x = assume(x, 'odd'); %! a = assumptions(x); %! assert(strcmp(a, 'x: odd')) %!test %! % multiple assumptions %! syms x %! x = assume(x, 'positive', 'integer'); %! [tilde, a] = assumptions(x, 'dict'); %! assert(a{1}.integer) %! assert(a{1}.positive) %!test %! % has output so avoids workspace %! syms x positive %! x2 = x; %! f = sin(x); %! x = assume(x, 'negative'); %! a = assumptions(x); %! assert(strcmp(a, 'x: negative')) %! a = assumptions(x2); %! assert(strcmp(a, 'x: positive')) %! a = assumptions(f); %! assert(strcmp(a, 'x: positive')) %!test %! % has no output so does workspace %! syms x positive %! x2 = x; %! f = sin(x); %! assume(x, 'negative'); %! a = assumptions(x); %! assert(strcmp(a, 'x: negative')) %! a = assumptions(x2); %! assert(strcmp(a, 'x: negative')) %! a = assumptions(f); %! assert(strcmp(a, 'x: negative')) symbolic-2.2.4/inst/@sym/mldivide.m0000644000175000001440000000634712633614672015704 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{x} =} mldivide (@var{A}, @var{b}) %% Symbolic backslash: solve linear systems. %% %% Over- and under-determined aystem are supported. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function x = mldivide(A, b) % Dear hacker from the distant future... maybe you can delete this? if (isa(A, 'symfun') || isa(b, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') x = mldivide(A, b); return end % not for singular %'ans = A.LUsolve(b)' if (isscalar(A)) x = b / A; return end cmd = { '(A, B) = _ins' 'flag = 0' 'if not A.is_Matrix:' ' A = sympy.Matrix([A])' 'if not B.is_Matrix:' ' B = sympy.Matrix([B])' 'if any([y.is_Float for y in A]) or any([y.is_Float for y in B]):' ' flag = 1' 'M = A.cols' 'Z = sympy.zeros(M, B.cols)' 'for k in range(0, B.cols):' ' b = B.col(k)' ' x = [Symbol("c%d" % (j + k*M)) for j in range(0, M)]' ' AA = A.hstack(A, b)' ' d = solve_linear_system(AA, *x)' ' if d is None:' ' Z[:, k] = sympy.Matrix([S.NaN]*M)' ' else:' ' # apply dict' ' Z[:, k] = sympy.Matrix([d.get(c, c) for c in x])' 'return (flag, Z)' }; [flag, x] = python_cmd (cmd, sym(A), sym(b)); if (flag ~= 0) warning('octsympy:backslash:vpa', ... 'vpa backslash may not match double backslash') end end % [5 2] \ 10 %!test %! % scalar %! syms x %! assert (isa( x\x, 'sym')) %! assert (isequal( x\x, sym(1))) %! assert (isa( 2\x, 'sym')) %! assert (isa( x\2, 'sym')) %!test %! % scalar \ matrix: easy, no system %! D = 2*[0 1; 2 3]; %! A = sym(D); %! assert (isequal ( 2 \ A , D/2 )) %! assert (isequal ( sym(2) \ A , D/2 )) %!test %! % singular matrix %! A = sym([1 2; 2 4]); %! b = sym([5; 10]); %! x = A \ b; %! syms c1 %! y = [-2*c1 + 5; c1]; %! assert (isequal (x, y)) %!test %! % singular matrix, mult RHS %! A = sym([1 2; 2 4]); %! B = sym([[5; 10] [0; 2] [0; 0]]); %! x = A \ B; %! syms c1 c5 %! y = [-2*c1 + 5 nan -2*c5; c1 nan c5]; %! assert (isequaln (x, y)) %!warning %! % vpa, nearly singular matrix %! A = sym([1 2; 2 4]); %! A(1,1) = vpa('1.001'); %! b = sym([1; 2]); %! x = A \ b; %! y = [sym(0); vpa('0.5')]; %! assert (isequal (x, y)) %!warning %! % vpa, singular rhs %! A = sym([1 2; 2 4]); %! b = [vpa('1.01'); vpa('2')]; %! x = A \ b; %! assert (all(isnan(x))) symbolic-2.2.4/inst/@sym/le.m0000644000175000001440000000302412633614672014474 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{g} =} le (@var{a}, @var{b}) %% Test/define symbolic inequality, less than or equal to. %% %% @seealso{lt, gt, ge, eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function t = le(x, y) t = ineq_helper('<=', 'Le', x, y); end %!test %! % simple %! x = sym(1); y = sym(1); e = x <= y; %! assert (logical (e)) %! x = sym(1); y = sym(2); e = x <= y; %! assert (logical (e)) %!test %! % array -- array %! syms x %! a = sym([1 3 3 2*x]); %! b = sym([2 x 3 10]); %! e = a <= b; %! assert (isa (e, 'sym')) %! assert (logical (e(1))) %! assert (isa (e(2), 'sym')) %! assert (isequal (e(2), 3 <= x)) %! assert (logical (e(3))) %! assert (isa (e(4), 'sym')) %! assert (isequal (e(4), 2*x <= 10)) symbolic-2.2.4/inst/@sym/conj.m0000644000175000001440000000330412633614672015026 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} conj (@var{x}) %% Symbolic conj function. %% %% @seealso{ctranspose, real, imag} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = conj(x) % can just use .conjugate on matrix but avoids S.true err sf = { 'def sf(x):' ' if x in (S.true, S.false):' ' return x' ' return x.conjugate()' }; z = uniop_helper (x, sf); end %!test %! a = sym(6); %! b = sym(5i); %! assert (isequal (conj(a), a)) %! assert (isequal (conj(b), -b)) %! assert (isequal (conj(a+b), a-b)) %!test %! syms x %! assert (isequal (conj(conj(x)), x)) %!test %! syms x real %! assert (isequal (conj(x), x)) %!test %! % array %! syms x %! A = [x 6+1i; sym(1) x+2i]; %! B = [conj(x) 6-1i; sym(1) conj(x)-2i]; %! assert (isequal (conj(A), B)) %!test %! % true/false %! t = sym(true); %! f = sym(false); %! assert (isequal ( conj(t), t)) %! assert (isequal ( conj(f), f)) symbolic-2.2.4/inst/@sym/mpower.m0000644000175000001440000000727612633614672015422 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{z} =} mpower (@var{x}, @var{y}) %% Symbolic expression matrix exponentiation (^). %% %% We implement scalar ^ scalar and matrix ^ scalar. %% %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function z = mpower(x, y) % Dear hacker from the distant future... maybe you can delete this? if (isa(x, 'symfun') || isa(y, 'symfun')) warning('OctSymPy:sym:arithmetic:workaround42735', ... 'worked around octave bug #42735') z = mpower(x, y); return end if isscalar(x) && isscalar(y) cmd = 'return _ins[0]**_ins[1],'; z = python_cmd (cmd, sym(x), sym(y)); elseif isscalar(x) && ~isscalar(y) error('scalar^array not implemented'); elseif ~isscalar(x) && isscalar(y) % FIXME: sympy can do int and rat, could use MatPow otherwise, % rather than error. SMT just leaves them unevaluted. % FIXME: sin(MatrixExpr) also fails, any easy way in SymPy to express % component-wise operations on a MatrixExpr? cmd = { 'x, y = _ins' 'try:' ' if not y.is_number:' ' z = sympy.MatPow(x, y)' ' else:' ' z = x**y' ' r = True' 'except NotImplementedError as e:' ' z = str(e)' ' r = False' 'return (r, z)' }; [r, z] = python_cmd (cmd, sym(x), sym(y)); if ~r error('mpower: not implemented; sympy says: %s', z) end else % two array's case error('array^array not implemented'); end end %!test %! syms x %! assert(isequal(x^(sym(4)/5), x.^(sym(4)/5))) %!test %! % integer powers of scalars %! syms x %! assert (isequal (x^2, x*x)) %! assert (isequal (x^sym(3), x*x*x)) %!test %! % array ^ integer %! syms x y %! A = [x 2; y 4]; %! assert (isequal (A^2, A*A)) %! assert (isequal (simplify(A^3 - A*A*A), [0 0; 0 0])) %!test %! % array ^ rational %! Ad = [1 2; 0 3]; %! A = sym(Ad); %! B = A^(sym(1)/3); %! Bd = Ad^(1/3); %! assert (max(max(abs(double(B) - Bd))) < 1e-14) %!error %! A = sym([1 2; 0 3]); %! B = A^sym(pi); %!test %! % matpow %! if (str2num(strrep(python_cmd ('return sympy.__version__,'),'.',''))<=75) %! disp('skipping: fails on SymPy 0.7.5') %! else %! syms n %! A = sym([1 2; 3 4]); %! B = A^n; %! C = 10 + B + B^2; %! D = subs(C, n, 1); %! E = 10 + A + A^2; %! assert (isequal (D, E)) %! end %!test %! % matpow, sub in zero gives identity %! if (str2num(strrep(python_cmd ('return sympy.__version__,'),'.',''))<=75) %! disp('skipping: fails on SymPy 0.7.5') %! else %! A = sym([1 2; 0 3]); %! syms n; %! B = A^n; %! C = subs(B, n, 1); %! assert (isequal (C, A)) %! C = subs(B, n, 0); %! assert (isequal (C, sym(eye(2)))) %! end %!error %! % scalar^array not implemented %! syms x %! A = [1 2; 3 4]; %! B = x^A; %!error %! % array^array not implemented %! A = sym([1 2; 3 4]); %! B = A^A; symbolic-2.2.4/inst/@sym/symsum.m0000644000175000001440000001204712633614672015436 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} symsum (@var{f}, @var{n}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{y} =} symsum (@var{f}, @var{n}, [@var{a} @var{b}]) %% @deftypefnx {Function File} {@var{y} =} symsum (@var{f}, @var{a}, @var{b}) %% @deftypefnx {Function File} {@var{y} =} symsum (@var{f}, [@var{a} @var{b}]) %% @deftypefnx {Function File} {@var{y} =} symsum (@var{f}, @var{n}) %% @deftypefnx {Function File} {@var{y} =} symsum (@var{f}) %% Symbolic summation. %% %% The sum of the expression @var{f} for @var{n} from @var{a} to %% @var{b}. When @var{n} is omitted it is determined using %% @code{symvar} and defaults to @code{x} if @var{f} is constant. The %% limits @var{a} and @var{b} default to 0 and @var{n} - 1 %% respectively. %% %% @example %% @group %% >> syms n m %% >> symsum(1/n^2, n, 1, m) %% @result{} (sym) harmonic(m, 2) %% %% >> symsum(exp(2*n)/sin(n), n, 2*m, 6*m) %% @result{} (sym) %% 6⋅m %% ____ %% ╲ %% ╲ 2⋅n %% ╲ ℯ %% ╱ ────── %% ╱ sin(n) %% ╱ %% ‾‾‾‾ %% n = 2⋅m %% @end group %% @end example %% %% @seealso{symprod, sum} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function S = symsum(f, n, a, b) idx1.type = '()'; idx1.subs = {1}; idx2.type = '()'; idx2.subs = {2}; if (nargin == 1) n = symvar(f, 1); if (isempty(n)) n = sym('x'); end a = sym(0); b = n - 1; elseif (nargin == 2) && (length(n) == 2) f = sym(f); %a = n(1); % issue #17 %b = n(2); a = subsref(n, idx1); b = subsref(n, idx2); n = symvar(f, 1); if (isempty(n)) n = sym('x'); end elseif (nargin == 2) f = sym(f); n = sym(n); a = sym(0); b = n - 1; elseif (nargin == 3) && (length(a) == 2) f = sym(f); n = sym(n); %b = a(2); % issue #17 %a = a(1); b = subsref(a, idx2); a = subsref(a, idx1); elseif (nargin == 3) f = sym(f); b = a; a = n; n = symvar(f, 1); if (isempty(n)) n = sym('x'); end else f = sym(f); n = sym(n); a = sym(a); b = sym(b); end cmd = { '(f, n, a, b) = _ins' 'S = sp.summation(f, (n, a, b))' 'return S,' }; S = python_cmd (cmd, sym(f), sym(n), sym(a), sym(b)); end %!test %! % finite sums %! syms n %! assert (isequal (symsum(n,n,1,10), 55)) %! assert(isa(symsum(n,n,1,10), 'sym')) %! assert (isequal (symsum(n,n,sym(1),sym(10)), 55)) %! assert (isequal (symsum(n,n,sym(1),sym(10)), 55)) %! assert (isequal (symsum(1/n,n,1,10), sym(7381)/2520)) %!test %! % negative limits %! syms n %! assert (isequal (symsum(n,n,-3,3), sym(0))) %! assert (isequal (symsum(n,n,-3,0), sym(-6))) %! assert (isequal (symsum(n,n,-3,-1), sym(-6))) %!test %! % one input %! syms n %! f = symsum (n); %! g = n^2/2 - n/2; %! assert (isequal (f, g)) %! f = symsum (2*n); %! g = n^2 - n; %! assert (isequal (f, g)) %!test %! % constant input %! f = symsum (sym(2)); %! syms x %! g = 2*x; %! assert (isequal (f, g)) %!test %! % two inputs %! syms n %! f = symsum (2*n, n); %! g = n^2 - n; %! assert (isequal (f, g)) %!test %! % two inputs, second is range %! syms n %! f = symsum (n, [1 6]); %! g = 21; %! assert (isequal (f, g)) %! f = symsum (n, [sym(1) 6]); %! g = 21; %! assert (isequal (f, g)) %! f = symsum (2*n, [1 6]); %! g = 2*21; %! assert (isequal (f, g)) %!test %! % three inputs, last is range %! syms n %! f = symsum (2*n, n, [1 4]); %! g = sym(20); %! assert (isequal (f, g)) %! f = symsum (2*n, n, [sym(1) 4]); %! g = sym(20); %! assert (isequal (f, g)) %! f = symsum (2, n, [sym(1) 4]); %! g = sym(8); %! assert (isequal (f, g)) %!test %! % three inputs, no range %! syms n %! f = symsum (2*n, 1, 4); %! g = sym(20); %! assert (isequal (f, g)) %! f = symsum (5, sym(1), 3); %! g = sym(15); %! assert (isequal (f, g)) %!test %! % ok to use double's for arguments in infinite series %! syms n oo %! assert(isequal(symsum(1/n^2,n,1,oo), sym(pi)^2/6)) %! assert(isequal(symsum(1/n^2,n,1,inf), sym(pi)^2/6)) %!test %! % should be oo because 1 is real but seems to be %! % zoo/oo depending on sympy version %! syms n oo %! zoo = sym('zoo'); %! assert (isequal (symsum(1/n,n,1,oo), oo) || ... %! isequal (symsum(1/n,n,1,oo), zoo)) symbolic-2.2.4/inst/@sym/and.m0000644000175000001440000000356612633614672014651 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{z} =} and (@var{x}, @var{y}) %% Logical and of symbolic arrays. %% %% @seealso{or, not, xor, eq, ne, logical, isAlways, isequal} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = and(x, y) r = binop_helper(x, y, 'lambda a,b: And(a, b)'); end %!shared t, f %! t = sym(true); %! f = sym(false); %!test %! % simple %! assert (isequal (t & f, f)) %! assert (isequal (t & t, t)) %!test %! % mix wih nonsym %! assert (isequal (t & false, f)) %! assert (isequal (t & true, t)) %! assert (isequal (t & 0, f)) %! assert (isequal (t & 6, t)) %! assert (isa (t & false, 'sym')) %! assert (isa (t & 6, 'sym')) %!test %! % array %! w = [t t f f]; %! z = [t f t f]; %! assert (isequal (w & z, [t f f f])) %!test %! % number %! assert (isequal( sym(5) & t, t)) %! assert (isequal( sym(0) & t, f)) %!xtest %! % output is sym even for scalar t/f %! % ₣IXME: should match other bool fcns %! assert (isa (t & f, 'sym')) %!test %! % eqns, exclusive %! syms x %! e = (x == 3) & (x^2 == 9); %! assert (isequal (subs(e, x, [-3 0 3]), [f f t])) symbolic-2.2.4/inst/@sym/prod.m0000644000175000001440000000510512633614672015042 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} prod (@var{x}) %% @deftypefnx {Function File} {@var{y} =} prod (@var{x}, @var{n}) %% Product of symbolic expressions. %% %% Example: %% @example %% @group %% >> syms x y z %% >> prod([x y z]) %% @result{} ans = (sym) x⋅y⋅z %% @end group %% @end example %% %% Can specify row or column sums using @var{n}: %% @example %% @group %% >> f = prod([x y; x z], 1) %% @result{} f = (sym 1×2 matrix) %% %% ⎡ 2 ⎤ %% ⎣x y⋅z⎦ %% %% >> f = prod([x y; x z], 2) %% @result{} f = (sym 2×1 matrix) %% %% ⎡x⋅y⎤ %% ⎢ ⎥ %% ⎣x⋅z⎦ %% %% @end group %% @end example %% %% @seealso{sum, symprod} %% @end deftypefn function y = prod(x, n) x = sym(x); if (isscalar(x)) y = x; return end if (nargin == 1) if (isrow(x)) n = 2; elseif (iscolumn(x)) n = 1; else n = 1; end else n = double(n); end %y = python_cmd ({'return sp.prod(_ins[0]),'}, x); cmd = { 'A = _ins[0]' 'B = sp.Matrix.zeros(A.rows, 1)' 'for i in range(0, A.rows):' ' B[i] = prod(A.row(i))' 'return B,' }; if (n == 1) y = python_cmd (cmd, transpose(x)); y = transpose(y); elseif (n == 2) y = python_cmd (cmd, x); else print_usage (); end end %!shared x,y,z %! syms x y z %!assert (isequal (prod (x), x)) %!assert (isequal (prod ([x y z]), x*y*z)) %!assert (isequal (prod ([x; y; z]), x*y*z)) %!assert (isequal (prod ([x y z], 1), [x y z])) %!assert (isequal (prod ([x y z], 2), x*y*z)) %!shared a,b %! b = [1 2; 3 4]; a = sym(b); %!assert (isequal (prod(a), prod(b))) %!assert (isequal (prod(a,1), prod(b,1))) %!assert (isequal (prod(a,2), prod(b,2))) %!test %! % weird inputs %! a = prod('xx', sym(1)); %! assert (isequal (a, sym('xx'))) symbolic-2.2.4/inst/test_bugs.tst0000644000175000001440000001072012633614672015542 0ustar cbmusers%% Tests % tests listed here are for current or fixed bugs. Could move % these to appropriate functions later if desired. %!test %! % Issue #5, scalar expansion %! a = sym(1); %! a(2) = 2; %! assert (isequal(a, [1 2])) %! a = sym([]); %! a([1 2]) = [1 2]; %! assert (isa(a, 'sym')) %! assert (isequal(a, [1 2])) %! a = sym([]); %! a([1 2]) = sym([1 2]); %! assert (isa(a, 'sym')) %! assert (isequal(a, [1 2])) %!test %! % "any, all" not implemented %! D = [0 1; 2 3]; %! A = sym(D); %! assert (isequal( size(any(A-D)), [1 2] )) %! assert (isequal( size(all(A-D,2)), [2 1] )) %!test %! % double wasn't implemented correctly for arrays %! D = [0 1; 2 3]; %! A = sym(D); %! assert (isequal( size(double(A)), size(A) )) %! assert (isequal( double(A), D )) %!test %! % in the past, inf/nan in array ctor made wrong matrix %! a = sym([nan 1 2]); %! assert (isequaln (a, [nan 1 2])) %! a = sym([1 inf]); %! assert( isequaln (a, [1 inf])) %% Bugs still active % Change these from xtest to test and move them up as fixed. %%!test %%! % FIXME: in SMT, x - true goes to x - 1 %%! syms x %%! y = x - (1==1) %%! assert( isequal (y, x - 1)) %!xtest %! % Issue #8: array construction when row is only doubles %! % fails on: Octave 3.6.4, 3.8.1, hg tip July 2014. %! % works on: Matlab %! try %! A = [sym(0) 1; 2 3]; %! failed = false; %! catch %! failed = true; %! end %! assert (~failed) %! assert (isequal(A, [1 2; 3 4])) %!test %! % boolean not converted to sym (part of Issue #58) %! y = sym(1==1); %! assert( isa (y, 'sym')) %! y = sym(1==0); %! assert( isa (y, 'sym')) %!test %! % Issue #9, nan == 1 should be bool false not "nan == 1" sym %! snan = sym(0)/0; %! y = snan == 1; %! assert (~logical(y)) %!test %! % Issue #9, for arrays, passes currently, probably for wrong reason %! snan = sym(nan); %! A = [snan snan 1] == [10 12 1]; %! assert (isequal (A, sym([false false true]))) %!test %! % these seem to work %! e = sym(inf) == 1; %! assert (~logical(e)) %!test %! % known failure, issue #55; an upstream issue %! snan = sym(nan); %! assert (~logical(snan == snan)) %% x == x tests % Probably should move to eq.m when fixed %!test %! % in SMT x == x is a sym (not "true") and isAlways returns true %! syms x %! assert (isAlways( x == x )) %!xtest %! % fails to match SMT (although true here is certainly reasonable) %! syms x %! e = x == x; %! assert (strcmp (strtrim(disp(e, 'flat')), 'x == x')) %%!xtest %%! % this is more serious! %%! % FIXME: is it? currently goes to false which is reasonable %%! syms x %%! e = x - 5 == x - 3; %%! assert (isa(e, 'sym')) %%! assert (~isa(e, 'logical')) %%!test %%! % using eq for == and "same obj" is strange, part 1 %%! % this case passes %%! syms x %%! e = (x == 4) == (x == 4); %%! assert (isAlways( e )) %%! assert (logical( e )) %%!test %%! % using eq for == and "same obj" is strange, part 2 %%! syms x %%! e = (x-5 == x-3) == (x == 4); %%! assert (~logical( e )) %%! % assert (~isAlways( e )) %%!xtest %%! % using eq for == and "same obj" is strange, part 3 %%! % this fails too, but should be true, although perhaps %%! % only with a call to simplify (i.e., isAlways should %%! % get it right). %%! syms x %%! e = (2*x-5 == x-1) == (x == 4); %%! assert (isAlways( e )) %%! assert (islogical( e )) %%! assert (isa(e, 'logical')) %%! assert (e) %!xtest %! % SMT behaviour for arrays: if any x's it should not be logical %! % output but instead syms for the equality objects %! syms x %! assert (isequal ( [x x] == sym([1 2]), [x==1 x==2] )) %! assert (isequal ( [x x] == [1 2], [x==1 x==2] )) %! % FIXME: new bool means these don't test the right thing %! %assert (~islogical( [x 1] == 1 )) %! %assert (~islogical( [x 1] == x )) %! %assert (~islogical( [x x] == x )) % not so clear %!xtest %! % FIXME: symbolic matrix size, Issue #159 %! syms n m integer %! A = sym('A', [n m]); %! assert (isequal (size (A), [n m])) %!xtest %! % symbolic matrix, subs in for size, Issue #160 %! syms n m integer %! A = sym('A', [n m]); %! B = subs(A, [n m], [5 6]); %! assert (isa (B, 'sym')) %! assert (isequal (size (B), [5 6])) %! % FIXME: not same as an freshly created 5 x 6. %! C = sym('B', [5 6]); %! assert (isequal(B, C)) %! % FIXME: e.g., cannot add to it %! B = B + 1 %! assert (isa (B, 'sym')) %!xtest %! % previous leave things so broken, takes a couple ops to clear up (yuck!) %! syms x %!xtest %! % previous leave things so broken, takes a couple ops to clear up (yuck!) %! syms x %!test %! % previous leave things so broken, takes a couple ops to clear up (yuck!) %! syms x symbolic-2.2.4/inst/fibonacci.m0000644000175000001440000000353512633614672015110 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{f} =} fibonacci (@var{n}) %% @deftypefnx {Function File} {@var{p} =} fibonacci (@var{n}, @var{x}) %% Return Fibonacci numbers and polynomials. %% %% Examples: %% @example %% @group %% >> fibonacci(15) %% @result{} (sym) 610 %% >> syms n %% >> fibonacci(n) %% @result{} (sym) fibonacci(n) %% @end group %% @end example %% %% Polynomial example: %% @example %% @group %% >> syms x %% >> fibonacci(10, x) %% @result{} (sym) %% 9 7 5 3 %% x + 8⋅x + 21⋅x + 20⋅x + 5⋅x %% @end group %% @end example %% %% @seealso{euler, bernouilli} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = fibonacci(n, x) if (nargin == 1) r = python_cmd ('return sp.fibonacci(*_ins),', sym(n)); else r = python_cmd ('return sp.fibonacci(*_ins),', sym(n), sym(x)); end end %!assert (isequal ( fibonacci (sym(0)), 0)) %!assert (isequal ( fibonacci (sym(14)), sym(377))) %!assert (isequal ( fibonacci (14), 377)) %!test syms x %! assert (isequal (fibonacci (5,x), x^4 + 3*x^2 + 1)) symbolic-2.2.4/inst/eulergamma.m0000644000175000001440000000236212633614672015307 0ustar cbmusers%% Copyright (C) 2015 Carnë Draug %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} eulergamma () %% Return Euler-Mascheroni constant. %% %% @example %% vpa (eulergamma ()) %% @result{} (sym) 0.57721566490153286060651209008240 %% @end example %% %% @seealso{catalan} %% @end deftypefn %% Author: Carnë Draug %% Keywords: symbolic, constants function g = eulergamma () g = python_cmd ('return sympy.S.EulerGamma,'); end %!assert (double (eulergamma ()) > 0.577215664901) %!assert (double (eulergamma ()) < 0.577215664902) symbolic-2.2.4/inst/bernoulli.m0000644000175000001440000000336512633614672015167 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{b} =} bernoulli (@var{n}) %% @deftypefnx {Function File} {@var{p} =} bernoulli (@var{n}, @var{x}) %% Return Bernoulli numbers and polynomials. %% %% Examples: %% @example %% @group %% >> bernoulli(6) %% @result{} (sym) 1/42 %% >> bernoulli(7) %% @result{} (sym) 0 %% @end group %% @end example %% %% Polynomial example: %% @example %% @group %% >> syms x %% >> bernoulli(2, x) %% @result{} (sym) %% 2 1 %% x - x + ─ %% 6 %% @end group %% @end example %% @seealso{euler} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = bernoulli(n, x) if (nargin == 1) r = python_cmd ('return sp.bernoulli(*_ins),', sym(n)); else r = python_cmd ('return sp.bernoulli(*_ins),', sym(n), sym(x)); end end %!assert (isequal (bernoulli (8), -sym(1)/30)) %!assert (isequal (bernoulli (9), 0)) %!test syms x %! assert (isequal (bernoulli(3,x), x^3 - 3*x^2/2 + x/2)) symbolic-2.2.4/inst/octsympy_tests.m0000644000175000001440000001660712633614672016310 0ustar cbmusers%% Copyright (C) 2014 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{r} =} octsympy_tests () %% Run the OctSymPy tests, log results, and return true if passing. %% %% I threw this together by modifying "__run_test_suite__.m" which %% is Copyright (C) 2005-2013 David Bateman and part of GNU Octave, %% GPL v3. %% %% FIXME: once we no longer try to support Octave 3.6, drop most of %% this and call "__run_test_suite(@{'@@sym', '@@symfun'@}, @{@})" %% instead. See https://savannah.gnu.org/bugs/?41215 %% %% @end deftypefn %% Author: Colin B. Macdonald, David Bateman %% Keywords: tests function anyfail = octsympy_tests () fcndirs = { '.' '@logical' '@sym' '@symfun' }; mycwd = pwd (); mydir = fileparts (mfilename ('fullpath')); chdir (mydir); % I had trouble with global vars, so just return them files_with_no_tests = {}; files_with_tests = {}; pso = page_screen_output (); warn_state = warning ("query", "quiet"); warning ("on", "quiet"); % time it all totaltime = clock(); totalcputime = cputime(); % get the octsympy startup text out of way before we start syms x try page_screen_output (false); warning ("off", "Octave:deprecated-function"); fid = fopen ("octsympy_tests.log", "wt"); if (fid < 0) error ("could not open octsympy_tests.log for writing"); endif test ("", "explain", fid); dp = dn = dxf = dsk = 0; puts ("\nIntegrated test scripts:\n\n"); for i = 1:length (fcndirs) [p, n, xf, sk, FWT, FWNT] = run_test_script (fid, fcndirs{i}); dp += p; dn += n; dxf += xf; dsk += sk; files_with_tests = {files_with_tests{:} FWT{:}}; files_with_no_tests = {files_with_no_tests{:} FWNT{:}}; endfor fclose (fid); puts ("\nSummary:\n\n"); nfail = dn - dp - dxf; printf (" PASS %6d\n", dp); printf (" FAIL %6d\n", nfail); if (dxf > 0) printf (" XFAIL %6d\n", dxf); endif if (dsk > 0) printf (" SKIPPED %6d\n", dsk); endif totaltime = etime(clock(), totaltime); totalcputime = cputime() - totalcputime; fprintf (' TIME %8.0fs (%.0fs CPU)\n', totaltime, totalcputime); puts ("\n"); puts ("See the file octsympy_tests.log for additional details.\n"); if (dxf > 0) puts ("\n"); puts ("Expected failures (listed as XFAIL above) are usually known bugs.\n"); puts ("Help is always appreciated.\n"); endif if (dsk > 0) puts ("\n"); puts ("Tests are most often skipped because the features they require\n"); puts ("have been disabled.\n"); endif ## Weed out deprecated and private functions #weed_idx = cellfun (@isempty, regexp (files_with_tests, '\|\', 'once')); #files_with_tests = files_with_tests(weed_idx); #weed_idx = cellfun (@isempty, regexp (files_with_no_tests, '\|\', 'once')); #files_with_no_tests = files_with_no_tests(weed_idx); report_files_with_no_tests (files_with_tests, files_with_no_tests, ".m"); printf("\n"); printf (list_in_columns (files_with_no_tests, 80)); anyfail = nfail > 0; page_screen_output (pso); warning (warn_state.state, "quiet"); catch page_screen_output (pso); warning (warn_state.state, "quiet"); disp (lasterr ()); end_try_catch chdir (mycwd); endfunction function print_test_file_name (nm) filler = repmat (".", 1, 48-length (nm)); printf (" %s %s", nm, filler); endfunction function print_pass_fail (p, n, xf, sk) if ((n + sk) > 0) printf (" PASS %3d/%-3d", p, n); nfail = n - p - xf; if (nfail > 0) printf (" \033[1;40;31m%s %d\033[m", "FAIL", nfail); endif if (sk > 0) printf (" \033[1;40;33m%s %d\033[m", "SKIP", sk); endif if (xf > 0) printf (" \033[1;40;33m%s %d\033[m", "XFAIL", xf); endif endif puts ("\n"); endfunction function retval = has_functions (f) n = length (f); if (n > 3 && strcmpi (f((end-2):end), ".cc")) fid = fopen (f); if (fid >= 0) str = fread (fid, "*char")'; fclose (fid); retval = ! isempty (regexp (str,'^(DEFUN|DEFUN_DLD)\>', 'lineanchors', 'once')); else error ("fopen failed: %s", f); endif elseif (n > 2 && strcmpi (f((end-1):end), ".m")) retval = true; else retval = false; endif endfunction function retval = has_tests (f) fid = fopen (f); if (fid >= 0) str = fread (fid, "*char")'; fclose (fid); retval = ! isempty (regexp (str, '^%!(assert|error|fail|test|xtest|warning)', 'lineanchors', 'once')); else error ("fopen failed: %s", f); endif endfunction function [dp, dn, dxf, dsk, FWT, FWNT] = run_test_script (fid, d); FWT = {}; FWNT = {}; lst = dir (d); dp = dn = dxf = dsk = 0; for i = 1:length (lst) nm = lst(i).name; ## # recurve into subdirs ## if (lst(i).isdir && nm(1) != ".") ## [p, n, xf, sk, myFWT, myFWNT] = run_test_script (fid, [d, filesep, nm]); ## dp += p; ## dn += n; ## dxf += xf; ## dsk += sk; ## FWT = {FWT{:} myFWT{:}}; ## FWNT = {FWNT{:} myFWNT{:}}; ## endif endfor for i = 1:length (lst) nm = lst(i).name; ## Ignore hidden files if (nm(1) == '.') continue endif f = fullfile (d, nm); if ((length (nm) > 2 && strcmpi (nm((end-1):end), ".m")) || (length (nm) > 4 && ( strcmpi (nm((end-3):end), "-tst") || strcmpi (nm((end-3):end), ".tst")))) p = n = xf = 0; ## Only run if it contains %!test, %!assert, %!error, %!fail, or %!warning if (has_tests (f)) tmp = f; print_test_file_name (tmp); [p, n, xf, sk] = test (f, "quiet", fid); if (compare_versions (OCTAVE_VERSION (), '3.9', '<')) p -= xf; end print_pass_fail (p, n, xf, sk); dp += p; dn += n; dxf += xf; dsk += sk; FWT{end+1} = f; else ## To reduce the list length, only mark .cc files that contain ## DEFUN definitions. FWNT{end+1} = f; endif endif endfor #printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); endfunction function n = num_elts_matching_pattern (lst, pat) n = sum (! cellfun ("isempty", regexp (lst, pat, 'once'))); endfunction function report_files_with_no_tests (with, without, typ) pat = ['\' typ "$"]; n_with = num_elts_matching_pattern (with, pat); n_without = num_elts_matching_pattern (without, pat); n_tot = n_with + n_without; printf ("\n%d (of %d) %s files have no tests:\n", n_without, n_tot, typ); endfunction % muhaha, no one is watching the watchers %!assert(true) symbolic-2.2.4/inst/catalan.m0000644000175000001440000000233212633614672014570 0ustar cbmusers%% Copyright (C) 2015 Carnë Draug %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} catalan () %% Return Catalan constant. %% %% @example %% vpa (catalan ()) %% @result{} (sym) 0.91596559417721901505460351493238 %% @end example %% %% @seealso{eulergamma} %% @end deftypefn %% Author: Carnë Draug %% Keywords: symbolic, constants function g = catalan () g = python_cmd ('return sympy.S.Catalan,'); end %!assert (double (catalan ()) > 0.915965594177) %!assert (double (catalan ()) < 0.915965594178) symbolic-2.2.4/inst/poly2sym.m0000644000175000001440000000632312633614672014767 0ustar cbmusers%% Copyright (C) 2003 Willem J. Atsma %% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This program is free software; you can redistribute it and/or %% modify it under the terms of the GNU General Public %% License as published by the Free Software Foundation; %% either version 3, or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR %% PURPOSE. See the GNU General Public License for more %% details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. If not, %% see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{p} =} poly2sym (@var{c}) %% @deftypefnx {Function File} {@var{p} =} poly2sym (@var{c}, @var{x}) %% Create a symbolic polynomial expression from coefficients. %% %% If @var{x} is not specified, the free variable is set to @code{x}. @var{c} %% may be a vector of doubles or syms. It can also be a cell array vector. %% @var{x} may be a symbolic expression or something that converts to one. %% The coefficients correspond to decreasing exponent of the free variable. %% %% Example: %% @example %% @group %% x = sym ('x'); %% y = sym ('y'); %% poly2sym ([2 5]) %% @result{} (sym) 2⋅x + 5 %% poly2sym (@{2*y 5 -3@}, x) %% @result{} (sym) %% 2 %% 2⋅x ⋅y + 5⋅x - 3 %% @end group %% @end example %% %% @seealso{sym2poly, polyval, roots} %% @end deftypefn function p = poly2sym(c,x) if (nargin == 1) x = sym('x'); else x = sym(x); end N = length(c); if (~iscell(c)) tmp = c; c = {}; for i=1:N % Bug #17 %c{i} = tmp(i) idx.type = '()'; idx.subs = {i}; c{i} = subsref(tmp, idx); end end p = sym(0); for i=1:N % horner form %p = p*x+c{i}; % monomial form (this is what matlab SMT does) p = p + c{i} * x^(N-i); end end %!shared x,y,a,b,c,p %! syms x y a b c %! p = x^3 + 2*x^2 + 3*x + 4; %!assert(isAlways( poly2sym([1 2 3 4]) == p )) %!assert(isAlways( poly2sym([1 2 3 4],x) == p )) %!assert(isAlways( poly2sym([1 2 3 4],y) == subs(p,x,y) )) %!assert(isAlways( poly2sym([1 2 3 4],5) == subs(p,x,5) )) %!assert(isequal( poly2sym ([1]), 1 )) %!assert(isequal( poly2sym ([]), 0 )) %% symbolic coefficents %!assert(isAlways( poly2sym(sym([1 2 3 4]),x) == p )) %!assert(isAlways( poly2sym([a b c],x) == a*x^2 + b*x + c )) %!assert(isAlways( poly2sym([a b c]) == a*x^2 + b*x + c )) %!assert(isequal( poly2sym(sym([])), 0 )) %% cell arrays %!assert(isAlways( poly2sym({sym(1) sym(2)}, x) == x + 2 )) %!assert(isequal( poly2sym ({1}), 1 )) %!assert(isequal( poly2sym ({}), 0 )) %!assert(isequal( poly2sym ({1}, x), 1 )) %!assert(isequal( poly2sym ({}, x), 0 )) %% weird cases (matlab SMT does this too, I think it should be an error) %!assert(isAlways( poly2sym([x x], x) == x^2 + x )) %!test %! % mixed cell array with doubles and syms %! assert (isequal (poly2sym ({2.0 sym(3) int64(4)}), 2*x^2 + 3*x + 4)) %!test %! % string for x %! p = poly2sym ([1 2], 's'); %! syms s %! assert (isequal (p, s + 2)) symbolic-2.2.4/inst/misc.tst0000644000175000001440000000361612633614672014504 0ustar cbmusers%% some new tests, may want to put elsewhere... %!shared x %! syms x %!assert (isequal (x(1), x)); %!assert (isequal (x(end), x)); %!error x(0) %!error x(-1) %!error x(end+1) %!error x(42, 42) %!error x(1, 42) %!error x(42, 1) %!assert (isequal (x(1, 1), x)); %!assert (isequal (x(:, :), x)); %!assert (isequal (x(:), x)); %!error x('::') %!error x(1, '::') %!shared a %! syms x %! a = [1 2 x]; %!error a(42, 42) %!error a(0, 1) %!error a(1, 0) %!shared x %! syms x %!error x([1 2; 1 1]) %!error x([1 2]) %!test %! % matrix index into matrix %! m = [1 x; 3 6*x]; %! assert (isequal (m([4 1; 3 3]), [6*x 1; x x])) %!test %! % vector index into matrix, orientation, prompted by issue #114 %! m = [0 x; 2*x 3]; %! assert (isequal (m([2; 1; 3]), [2*x; 0; x])) %! assert (isequal (m([2 1 3]), [2*x 0 x])) %!test %! % matrix index into vector (scalar), issue #113 %! assert (isequal (x([1 1; 1 1]), [x x; x x])) %! assert (isequal (x([1 1]), [x x])) %! assert (isequal (x([1; 1]), [x; x])) %!test %! % matrix index into vector (scalar), issue #113 %! a = [1 x 3]; %! assert (isequal (a([1 2; 2 3]), [1 x; x 3])) %! % but vec into vec takes orientation from a %! assert (isequal (a([2 3]), [x 3])) %! assert (isequal (a([2; 2]), [x x])) %!test %! % matrix index into vector %! a = [10 20 x]; %! assert (isequal (a([3 1; 3 2]), [x 10; x 20])) %!test %! % empty indexing %! assert (isempty (x([]))) %! assert (isequal (size(x([])), [0 0])) %! m = [0 x 1; 2*x 3 0]; %! assert (isequal (size(m([])), [0 0])) %! assert (isequal (size(m([],[])), [0 0])) %! assert (isequal (size(m(:,[])), [2 0])) %! assert (isequal (size(m([],:)), [0 3])) symbolic-2.2.4/inst/digits.m0000644000175000001440000000352212633614672014452 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{n} =} digits () %% @deftypefnx {Function File} {} digits (@var{n}) %% @deftypefnx {Function File} {@var{oldn} =} digits (@var{n}) %% Get/set number of digits used in variable precision arith. %% %% Examples: %% @example %% @group %% >> n_orig = digits(7); %% >> vpa('pi') %% @result{} (sym) 3.141593 %% %% >> digits(42) %% >> vpa('pi') %% @result{} (sym) 3.14159265358979323846264338327950288419717 %% %% >> digits(n_orig) # reset digits to saved value %% @end group %% @end example %% @seealso{sym, vpa, vpasolve} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function m = digits(n) if (nargin == 0) || (nargout == 1) m = sympref('digits'); end if (nargin == 1) sympref('digits', n); end end %!test %! orig = digits(32); % to reset later %! m = digits(64); %! p = vpa(sym(pi)); %! assert (abs (double (sin(p))) < 1e-64) %! n = digits(m); %! assert (n == 64) %! p = vpa(sym(pi)); %! assert (abs (double (sin(p))) < 1e-32) %! assert (abs (double (sin(p))) > 1e-40) %! digits(orig) symbolic-2.2.4/inst/vpa.m0000644000175000001440000001326512633614672013762 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {@var{y} =} vpa (@var{x}) %% @deftypefnx {Function File} {@var{y} =} vpa (@var{x}, @var{n}) %% Create a variable-precision floating point number. %% %% @var{x} can be a string, a sym or a double. Example: %% @example %% @group %% >> x = vpa('1/3', 32) %% @result{} x = (sym) 0.33333333333333333333333333333333 %% >> a = sym(1)/3; %% >> x = vpa(a, 32) %% @result{} x = (sym) 0.33333333333333333333333333333333 %% @end group %% @end example %% %% Be careful when creating a high-precision float from a %% double as you will generally only get 15 digits: %% @example %% @group %% >> vpa(1/3, 32) %% @result{} (sym) 0.33333333333333331482961625624739 %% @end group %% @end example %% %% If @var{n} is omitted it defaults to the current value of %% @code{digits()}. %% %% @seealso{sym, vpasolve, digits} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic function r = vpa(x, n) if (nargin == 1) n = digits(); end if (isa(x, 'sym')) cmd = { 'x, n = _ins' 'return sympy.N(x, n),' }; r = python_cmd (cmd, x, n); elseif (ischar(x)) x = magic_str_str(x); % Want Float if its '2.3' but N if its 'pi' cmd = { 'x, n = _ins' 'try:' ' return sympy.Float(x, n),' 'except ValueError:' ' pass' 'return sympy.N(x, n),' }; r = python_cmd (cmd, x, n); elseif (isfloat(x) && ~isreal (x)) r = vpa(real(x), n) + sym('I')*vpa(imag(x), n); elseif (isfloat(x) && isscalar(x) == 1) [s, flag] = magic_double_str(x); if (flag) r = vpa(s, n); else cmd = { 'x, n = _ins' 'return sympy.Float(x, n),' }; r = python_cmd (cmd, x, n); end elseif (isinteger(x) && isscalar(x) == 1) cmd = { 'x, n = _ins' 'return sympy.N(x, n),' }; r = python_cmd (cmd, x, n); elseif (~isscalar(x)) cmd = { sprintf('return sympy.ZeroMatrix(%d, %d).as_mutable(),', size(x)) }; r = python_cmd (cmd); for i=1:numel(x) r(i) = vpa(x(i), n); end else x class(x) error('conversion to vpa with those arguments not (yet) supported'); end end %!test %! a = vpa(0, 4); %! b = double(a); %! assert(b == 0) %!test %! a = vpa(pi, 4); %! b = sin(a); %! assert(abs(double(b)) < 1e-4) %!test %! % vpa from double is ok, doesn't warn (c.f., sym(2.3)) %! a = vpa(2.3); %! assert(true) %!test %! % vpa from double not more than 16 digits %! a = vpa(sqrt(pi), 32); %! b = sin(a^2); %! assert(abs(double(b)) > 1e-20) %! assert(abs(double(b)) < 1e-15) %!test %! a = vpa(sym(pi), 32); %! b = sin(a); %! assert(abs(double(b)) < 1e-30) %!test %! a = vpa(sym(pi), 256); %! b = sin(a); %! assert(abs(double(b)) < 1e-256) %!test %! % pi str %! a = vpa('pi', 32); %! b = sin(a); %! assert(abs(double(b)) < 1e-32) %!test %! % pi str %! a = vpa('pi', 32); %! b = vpa(sym('pi'), 32); %! assert (double (a - b) == 0) %!test %! spi = sym(pi); %! a = vpa(spi, 10); %! b = double(a); %! assert(~isAlways(spi == a)) %!test %! % matrix of sym %! a = [sym(pi) 0; sym(1)/2 1]; %! b = [pi 0; 0.5 1]; %! c = vpa(a, 6); %! assert(max(max(abs(double(c)-b))) < 1e-6) %!test %! % matrix of double %! b = [pi 0; 0.5 1]; %! c = vpa(b, 6); %! assert(max(max(abs(double(c)-b))) < 1e-6) %!test %! % integer type %! a = vpa(int32(6), 64); %! b = vpa(6, 64); %! assert (isequal (a, b)) %!test %! % matrix of int %! b = int32([pi 0; 6.25 1]); %! c = vpa(b, 6); %! assert (isequal (double(c), [3 0; 6 1])) %!test %! % can pass pi directly to vpa %! a = vpa(sym(pi), 128); %! b = vpa(pi, 128); %! assert (isequal (a, b)) %!test %! % can pass pi directly to vpa, even in array %! a = vpa(sym([2 pi]), 128); %! b = vpa([2 pi], 128); %! assert (isequal (a, b)) %!test %! % can pass i directly to vpa %! a = vpa(sym(i)); %! b = vpa(i); %! c = vpa('i'); %! d = vpa('I'); %! assert (isequal (a, b)) %! assert (isequal (a, c)) %! assert (isequal (a, d)) %!test %! % inf/-inf do not become symbol('inf') %! S = {'oo', '-oo', 'inf', 'Inf', '-inf', '+inf'}; %! for j = 1:length(S) %! a = vpa(S{j}); %! b = vpa(sym(S{j})); %! assert (isequal (a, b)) %! end %!test %! a = vpa('2.3', 20); %! s = strtrim(disp(a, 'flat')); %! assert (strcmp (s, '2.3000000000000000000')) %!test %! % these should *not* be the same %! a = vpa(2.3, 40); %! b = vpa('2.3', 40); %! sa = char(a); %! sb = char(b); %! assert (~isequal (a, b)) %! assert (abs(double(a - b)) > 1e-20) %! assert (abs(double(a - b)) < 1e-15) %! assert (~strcmp(sa, sb)) %!test %! % these should *not* be the same %! x = vpa('1/3', 32); %! y = vpa(sym(1)/3, 32); %! z = vpa(1/3, 32); %! assert (isequal (x, y)) %! assert (~isequal (x, z)) %!test %! % big integers %! a = int64(12345678); %! a = a*a; %! b = vpa(a); %! c = vpa('152415765279684'); %! assert (isequal (b, c)) %!xtest %! % big integers (workaround poor num2str, works in 4.0?) %! a = int64(1234567891); a = a*a; %! b = vpa(a); %! c = vpa('1524157877488187881'); %! assert (isequal (b, c)) symbolic-2.2.4/inst/syms.m0000644000175000001440000001515312633614672014165 0ustar cbmusers%% Copyright (C) 2014, 2015 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This software is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See %% the GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see . %% -*- texinfo -*- %% @documentencoding UTF-8 %% @deftypefn {Function File} {} syms @var{x} %% @deftypefnx {Function File} {} syms @var{x} @var{y} @dots{} %% @deftypefnx {Function File} {} syms @var{f(x)} %% @deftypefnx {Function File} {} syms @var{x} @var{asm} %% @deftypefnx {Function File} {} syms @var{x} @var{asm} @var{asm2} @dots{} %% @deftypefnx {Function File} {} syms %% Create symbolic variables and symbolic functions. %% %% This is a convenience function. For example: %% @example %% >> syms x y z %% @end example %% instead of: %% @example %% >> x = sym('x'); %% >> y = sym('y'); %% >> z = sym('z'); %% @end example %% %% The last arguments can provide one or more assumptions (type or %% restriction) on the variable (@pxref{sym}). %% @example %% >> syms x y z positive %% >> syms n positive even %% @end example %% %% Symfuns represent abstract or concrete functions. Abstract %% symfuns can be created with @code{syms}: %% @example %% >> syms f(x) %% @end example %% If @code{x} does not exist in the callers workspace, it %% is created as a @strong{side effect} in that workspace. %% %% Called without arguments, @code{syms} displays a list of %% all symbolic functions defined in the current workspace. %% %% Caution: On Matlab, you may not want to use @code{syms} within %% functions. %% In particular, if you shadow a function name, you may get %% hard-to-track-down bugs. For example, instead of writing %% @code{syms alpha} use @code{alpha = sym('alpha')} in functions. %% [https://www.mathworks.com/matlabcentral/newsreader/view_thread/237730] %% %% @seealso{sym} %% @end deftypefn %% Author: Colin B. Macdonald %% Keywords: symbolic, symbols, CAS function syms(varargin) %% No inputs %output names of symbolic vars if (nargin == 0) S = evalin('caller', 'whos'); disp('Symbolic variables in current scope:') for i=1:numel(S) %S(i) if strcmp(S(i).class, 'sym') disp([' ' S(i).name]) elseif strcmp(S(i).class, 'symfun') % FIXME improve display of symfun disp([' ' S(i).name ' (symfun)']) end end return end %% Find assumptions valid_asm = assumptions('possible'); last = -1; doclear = false; for n=1:nargin assert(ischar(varargin{n}), 'syms: expected string inputs') if (ismember(varargin{n}, valid_asm)) if (last < 0) last = n - 1; end elseif (strcmp(varargin{n}, 'clear')) doclear = true; if (last < 0) last = n - 1; else warning('syms: should not combine "clear" with other assumptions') end if (n ~= nargin) error('syms: "clear" should be the final argument') end elseif (last > 0) error('syms: cannot have symbols after assumptions') end end if (last < 0) asm = {}; exprs = varargin; elseif (last == 0) error('syms: cannot have only assumptions w/o symbols') else asm = varargin((last+1):end); exprs = varargin(1:last); end % loop over each input for i = 1:length(exprs) expr = exprs{i}; % look for parenthesis: check if we're making a symfun if (isempty (strfind (expr, '(') )) % no assert(isvarname(expr)); % help prevent malicious strings if (doclear) % We do this here instead of calling sym() because sym() % would modify this workspace instead of the caller's. newx = sym(expr); assignin('caller', expr, newx); xstr = newx.flat; % --------------------------------------------- % Muck around in the caller's namespace, replacing syms % that match 'xstr' (a string) with the 'newx' sym. %xstr = x; %newx = s; context = 'caller'; % --------------------------------------------- S = evalin(context, 'whos'); evalin(context, '[];'); % clear 'ans' for i = 1:numel(S) obj = evalin(context, S(i).name); [newobj, flag] = symreplace(obj, xstr, newx); if flag, assignin(context, S(i).name, newobj); end end % --------------------------------------------- else assignin('caller', expr, sym(expr, asm{:})) end else % yes, this is a symfun assert(isempty(asm), 'mixing symfuns and assumptions not supported') % regex matches: abc(x,y), f(var), f(x, y, z), f(r2d2), f( x, y ) % should not match: Rational(2, 3), f(2br02b) assert(~isempty(regexp(expr, '^\w+\(\s*[A-z]\w*(,\s*[A-z]\w*)*\s*\)$')), ... 'invalid symfun expression') s = sym(expr); %vars = symvar(s) % might re-order the inputs, instead: cmd = { 'f = _ins[0]' 'return (f.func.__name__, f.args)' }; [name, vars] = python_cmd (cmd, s); sf = symfun(s, vars); assignin('caller', name, sf); for i = 1:length(vars) v = vars{i}; assignin('caller', v.flat, v); end end end end %!test %! %% assumptions %! syms x real %! x2 = sym('x', 'real'); %! assert (isequal (x, x2)) %!test %! %% assumptions and clearing them %! syms x real %! f = {x {2*x}}; %! A = assumptions(); %! assert ( ~isempty(A)) %! syms x clear %! A = assumptions(); %! assert ( isempty(A)) %!test %! %% matlab compat, syms x clear should add x to workspace %! syms x real %! f = 2*x; %! clear x %! assert (~logical(exist('x', 'var'))) %! syms x clear %! assert (logical(exist('x', 'var'))) %!error %! syms x positive y %!error %! % this sometimes catches typos or errors in assumption names %! % (if you need careful checking, use sym not syms) %! syms x positive evne %!warning %! syms x positive clear %!error %! syms x clear y %!error %! syms positive integer %!test %! % does not create a variable called positive %! syms x positive integer %! assert (logical(exist('x', 'var'))) %! assert (~logical(exist('positive', 'var'))) symbolic-2.2.4/TODO.md0000644000175000001440000000556112633614672013130 0ustar cbmusers# TODO List, mostly historial now ## assumptions http://docs.sympy.org/dev/modules/assumptions/assume.html You can define integers at creation: >>> x, y, z, t = symbols('x y z t') >>> k, m, n = symbols('k m n', integer=True) >>> f, g, h = symbols('f g h', cls=Function) >>> x = Symbol('x', real=True, positive=True) In Matlab's SMT, assumptions effect expressions already defined. This seems a bit at odds with Sympy (also c.f., global_assumptions). The easier approach is to put them in Symbol() ## Global assumptions don't apply "automatically"? from sympy.assumptions.assume import global_assumptions from sympy import Q GA = global_assumptions x = sp.Symbol('x') In [23]: sp.sqrt(x**2) Out[23]: sqrt(x**2) GA.add(Q.positive(x)) In [29]: sp.sqrt(x**2) Out[29]: sqrt(x**2) In [31]: sp.refine(sp.sqrt(x**2)) Out[31]: x ## Assumptions on variables in the constructor This works well. But how to map this onto the assume() and alsoAssume() commands? Proposal: set assume to generate help text and a warning. And extend the constructor instead to work like sympy... ## equality MST: ==, define equations, equality test only when both sides become double SymPy: relationalequality, eq() MST: logical(), "structural" equivalence SymPy: == MST: isAlways(), "mathematical" equivalence SymPy: bool(LHS.expand() == RHS.expand()) > If .expand() does not help, try simplify(), trigsimp(), etc, which > attempt more advanced transformations. For example, [https://github.com/sympy/sympy/wiki/Faq] ## matrices Fundamental choice: (1) make a matrix array of sym objects; or (2) use sp.Matrix in sympy. (1+) seems easy to start with (1-) but then sin(x) for example will need to call sin for each entry (2-) requires some effort for functions: A.applyfunc(sp.sin) (2+) renders nicely already essential issue is that scalars are not (1,1) matrices in sympy. Could do that but, e.g., diff might not work... well we could just generate the code to make it work. ## IPC Currently we have two approaches implemented: * Using system() * Using popen2() There are quite a few options out there: * http://code.google.com/p/python-matlab-wormholes/ * http://algoholic.eu/matpy/ * Jython: very promising as there is already a rsympy: sympy in R using this. * http://stackoverflow.com/questions/1707780/call-python-function-from-matlab?rq=1 ## Limitations of system() We used to create a temporary file and execute it with system(). But its nicer to pass the command itself on the command line with "python -c". IIRC, I couldn't make this work with multiline pickles (i.e., most of them). * http://stackoverflow.com/questions/11392033/passing-python-array-to-bash-script-and-passing-bash-variable-to-python-functio * http://stackoverflow.com/questions/2043453/executing-python-multi-line-statements-in-the-one-line-command-line * http://superuser.com/questions/607367/raw-multiline-string-in-bash symbolic-2.2.4/NEWS0000644000175000001440000002371612633614672012542 0ustar cbmusersoctsympy 2.2.4 (2015-12-14) =========================== * Fix display on Octave 3.8. * Support for SymPy 0.7.6.1. octsympy 2.2.3 (2015-11-25) =========================== * New commands: cross dot * sym('var') is more robust in case var happens to be a special value in SymPy. Now sym('E') is just a symbol rather than exp(sym(1)). Also sym('E1') and sym('Eq') no longer give errors. * Fix bug in assigning to column vectors, thanks to Grzegorz Dudziuk. * During install, test for PATH problems on Windows (issue #236). * Fix for Octave 4.1+ development versions, thanks to Mike Miller. octsympy 2.2.2 (2015-07-03) =========================== * Fix for configure script using Python 3 (thanks Vadim Gribanov). * Fourier transform fixes (thanks Alexander Misel, Andrés Prieto). They now follow the non-unitary angular frequency convention. * Support for SymPy 0.7.7.dev version. * Add some warnings to the documentation about unreliable results for "dsolve" on systems and from Fourier transforms. * Start using "print_usage" for invalid inputs as is common practice in Octave. * Bug fixes and update doctests. octsympy 2.2.1 (2015-04-22) =========================== * Fix an ascii pretty printing regression (issue #234). * Other minor fixes for doctests, sympref and symreplace. octsympy 2.2.0 (2015-04-20) =========================== * New commands: catalan eulergamma lambertw * Installing symbolic package now check for Python and minimum version of SymPy (thanks Carnë Draug for autoconf). * Installations from Octave-Forge ("pkg install -forge symbolic") should now work on Windows (thanks vassbu). You will need the Python and SymPy dependencies. Or you can use the [bundled package](https://github.com/cbm755/octsympy/releases) * Added support for Python 3 (still works with Python 2 as well). * Documentation improvements especially to assumptions. Examples within documentation can now be tested with doctests, see the `octsympy_doctests.m` function. * Fix a warning on Octave 4.0.0-rc1 and make tests work properly. * Other bug fixes: assumptions; symvar and symbolic matrix powers; various display issues. octsympy 2.1.0 (2015-03-06) =========================== * New commands: columns degree formula ismatrix numden rows * Additional ways of calling symsum, symprod, and subs for better compatibility with other symbolic toolboxes. * Bug fixes in poly2sym, sym2poly, symfun (thanks @rocketsound), prod, horner, coeffs. * Documentation improvements. * Improvements to "argnames" and "formula" for the dependent variables and dependent expression of a symfun. These are now implemented for basic sym objects as well. * Improvements to assumptions. E.g., `x = assume(x, 'positive')` no longer mucks around in the workspace for other instances of x (it still does this with no output argument, for compatibility with other symbolic toolboxes). You can use multiple assumptions with sym and syms, e.g., `syms n m positive even`. * Improve symbolic sized matrices such as `A = sym('a', [n m])`. These are still experimental; they correspond to MatixSymbols in SymPy and may need a recent SymPy development version. For now, the `size(A)` returns "1x1" although internally `NaN` is used for symbolic-sized dimensions. Enabling `size(A)` to return "NaNx3" may occur later. * Drop python_cmd_string, which has been deprecated since v0.1.1. octsympy 2.0.0 (2015-02-04) =========================== * Octsympy is now the "symbolic" package for Octave Forge. There was a previous "symbolic" package (based on GiNaC) which reached version 1.1.0. To prevent confusion, we are now at version 2.0.0. Additionally, the history of the two projects has been merged (thanks Carnë Draug). * New commands: coeffs ipermute isallconstant isconstant nchoosek permute * Fixes for development version of SymPy. * Fixes for vpa and vpasolve: high precision should be more reliable. * Improve handling `sym(pi/3)` and other small fractions of pi. It works but you'll still get a warning and 2*sym(pi)/3 is really the preferred approach! `sym(-pi)` now works. * On Windows, default to ascii rendering for now (until unicode is fixed in Octave on that platform). * No longer needs to autogenerate a bunch of functions at install time: hopefully making it easier than ever to get involved! octsympy 0.1.3 (2015-01-06) =========================== * New commands: argnames partfrac digits orth ilaplace rank laplace rref ldivide sum mldivide vpa null vpasolve * Symbolic backslash support. * variable-precision arithmetic support: see vpa, digits, vpasolve. * Much-improved dsolve thanks to Andrés Prieto. * Laplace and inverse Laplace transforms (Andrés Prieto). * Partial fractions (Andrés Prieto). * Improvements to solve (Andrés Prieto). * Preliminary support for matrix expressions, e.g., matrix to a symbolic power. * Should work properly with Stand-alone Python (thanks to David Manthey). octsympy 0.1.2 (2014-12-01) =========================== * New commands: children rhs expm setdiff lhs setxor pinv trace potential * Support new SymPy 0.7.6. This adds Octave code generation which means that OctSymPy's `matlabFunction` is supported. * For now, SymPy 0.7.5 should still work, but upgrading to SymPy 0.7.6 is recommended. octsympy 0.1.1 (2014-10-20) Rose Garden ======================================== Major Changes ------------- * Fix sym(double) approx by rationals (issue #121, thanks HuiZhong LU). * Improvements to sym() command: you can now pass the underlying "srepr" SymPy presentation to create an object. * Bug fixes: improvements to indexing, findsymbols and assumptions, isscalar/isvector failures on recent Octave, output formatting fixes, * New commands: and isscalar char isvector diag nnz eig or iscolumn uplus isrow xor Minor Changes ------------- * Improvements to logical and isAlways commands. * IPC system() should work on windows. * Better test system, easier to see "real" failures rather than expected (known) failures. * Improved handling of symfuns. * Improvements to internal string handling/escaping especially newlines. - Enter a multiline command using a cell array of lines e.g., `python_cmd({'a = 10' 'return (a, 2*a)'}) or `python_cmd({'a = 10'; 'return (a, 2*a)'}) - The same applies to `evalpy`. If you need the old deprecated behaviour, it is still available as `python_cmd_string`. octsympy 0.1.0 (2014-08-27) Pacific Coffee =========================================== Major Changes ------------- * `sympref` replaces `octsympy_config`. You can change the Python interpreter with `sympref python /path/to/python`. * Unicode pretty-printed output by default. - If you see `?` or other broken characters, try `sympref display ascii`. Then help me get this working on your system! - Or `sympref display flat` to disable pretty-printing. (You can still use the `pretty` command selectively). * Experimental Windows package with Python and SymPy included (look Ma, no deps!) Uses [David Manthey's single file py.exe Python] [1]. [1]: http://www.orbitals.com/programs/pyexe.html * Lots of new commands: atan2 fliplr isfinite norm ccode flipud isna not cond fortran jacobian qr conj ge laplacian real curl gradient le repmat det gt lt svd divergence hessian lu toeplitz ezplot3 imag matlabFunction tril ezplot inv ne triu * Preliminary code generation (`ccode`, `fortran` and `matlabFunction` functions). However, `matlabFunction` mostly depends on patches not yet in upstream SymPy. * Inequality support. * Assumptions now behave more like the Matlab Symbolic Math Toolbox. Minor or internal changes ------------------------- * Arithmetic operations on symfuns return symfuns instead of syms. * More robust XML-like IPC transport. * Move to proper Octave-style `%!` tests. * Debugging IPC modes: `systmpfile` (same as `system` but outputs a temp file for inspection) and `sysoneline` (work-in-progress). octsympy 0.0.4 (2014-05-26) Lovever Coffee =========================================== * Basic assumptions support. * Matlab packages, only slow system() ipc for now. * Improvements on passing variables between Octave and Python. octsympy 0.0.3 (2014-04-29) Wu Ke Song ======================================= * Many new commands. * `system()` communication no longer makes temporary files. To change the communication mechanism, use "octsympy_config ipc system". See also "help octsympy_config". * Added new tool "evalpy", this is fun and good for debugging... * Bugs fixed, docs updated * Start documenting differences with the Matlab Symbolic Math Toolbox. octsympy 0.0.2 (2014-04-20) =========================== * A preview release, test it out report issues. Documentation is a mess, various things are work-in-progress. But it works and I think has potential. symbolic-2.2.4/README.md0000644000175000001440000000647112633614672013321 0ustar cbmusersOctSymPy ======== An implementation of a symbolic toolbox using SymPy. [https://github.com/cbm755/octsympy] Goals ----- Feature parity with the other symbolic toolboxes. ![Screenshot 1](/screenshot.png) ![Screenshot 2](/screenshot-install.png) Status ------ "Beta" quality at best! Contributions welcome. How to Install -------------- 1. The only dependencies are Python and SymPy. Consult the SymPy website (e.g., `yum install sympy` on Fedora). 2. Download the latest release, e.g., `octsympy-0.1.2.tar.gz`. 3. Run Octave and change to the folder containing the downloaded file. 4. At Octave prompt, type `pkg install octsympy-0.1.2.tar.gz`. 5. At Octave prompt, type `pkg load octsympy`. 6. At Octave prompt, type `syms x`, then `f = (sin(x/2))^3`, `diff(f,x)`, etc. How to Install on Windows ------------------------- 1. Get [Octave](http://www.octave.org) for Windows. 2. Try the octsympy-windows-0.1.2.zip package. Follow the last three steps above using this file instead. The `octsympy-windows` package should have no dependencies other than Octave itself (it includes SymPy and a Python interpreter.) Alternatively, you can install Python and SymPy yourself and use the standard `octsympy-0.1.2.zip` package. If you encounter any difficulties (even minor ones) please read and if possible help us improve the [wiki page on Windows Installation](https://github.com/cbm755/octsympy/wiki/Notes-on-Windows-installation). How to Install on Matlab ------------------------ Although OctSymPy is designed for GNU Octave, it will work with Matlab. Currently only the slower system()-based communication is available. 1. Download the latest release, e.g., `octsympy-matlab-0.1.2.tar.gz`. 2. Unzip is somewhere and add it to your Matlab Path. The .m files for Matlab have been reformatted for Matlab comment conventions, but are otherwise the same as the Octave source. How to Help ----------- We have a list of things to work on tagged [help wanted](https://github.com/cbm755/octsympy/issues?q=is:open+is:issue+label:"help+wanted"). Some of these should be quite easy to fix and would be a great way to get involved. Come join us! How to hack on the code: 1. Clone the repo with git (preferred, but you can use the "Download ZIP" instead of you want). 2. Go to octsympy/src/ and type "make". (You only need to do this again if you change the inst/private/python_header.py or various autogeneration scripts in src/.) 3. Run Octave (or Matlab) in octsympy/inst/. Implementation -------------- Python code is generated to do the actual work. Each sym objects keep a text field for display purposes and a string (a SymPy `srepr`). The objects are communicated between Python and Octave by passing the srepr's back-and-forth. Currently pure m-file (and Python) implementation, no code to be compiled. Communication ------------- We have two IPC mechanisms between Octave and Python. One option is calling "system()". The other uses "popen2()". Others could be implemented. Related Projects ---------------- * There was a previous "symbolic" package in Octave Forge based on GiNaC. Its history has now been merged into octsympy. * ["SymPy CAS" by Jonathan Lister](http://www.mathworks.com/matlabcentral/fileexchange/42787-sympy-cas-in-matlab). Calls SymPy commands using system(). symbolic-2.2.4/extract_tests_for_matlab.m0000644000175000001440000000576612633614672017310 0ustar cbmusersfunction extract_tests_for_matlab() dirs = {'.', '@sym', '@symfun'}; dirstr = {'', 'sym', 'symfun'}; outdir = 'tests_matlab'; for j=1:length(dirs) files = dir(dirs{j}); for i=1:length(files) mfile = files(i).name; if ( (~files(i).isdir) && strcmp(mfile(end-1:end), '.m') ) %str = mfile(1:end-2); fprintf('>>> Looking for tests in: %s', mfile); tf = proc_file(dirs{j}, dirstr{j}, mfile, outdir); if tf fprintf('\t[done]\n'); else fprintf('\t[no tests]\n'); end end end end endfunction function r = proc_file(base, basestr, nm, outdir) %nm = 'symfun.m'; %base = '@symfun'; name_no_m = nm(1:end-2); in_name = [base '/' nm]; body = __extract_test_code(in_name); r = true; if isempty(body) r = false; return end %% process it a bit % Chop it up into blocks for evaluation. %__lineidx = find (__body == "\n"); %__blockidx = __lineidx(find (! isspace (__body(__lineidx+1))))+1; nl = sprintf('\n'); % add an extra newline to ensure final line has one body = [body nl]; ddot = 'fprintf(''.'')'; dskip = 'fprintf(''s'')'; body = regexprep(body, '^test\n', [nl ddot nl '%test' nl], 'lineanchors'); body = regexprep(body, '^test ', [nl ddot nl '%test' nl], 'lineanchors'); body = regexprep(body, '^(shared.*)\n', ['%$1' nl], 'lineanchors', 'dotexceptnewline'); % FIXME: better to put these inside appropriate try catch end" body = regexprep(body, '^xtest\n( [^\n]*\n)*', [nl dskip nl '%xtest' ... ' (**TEST EXPECTED TO FAIL: REMOVE**)' nl], 'lineanchors'); body = regexprep(body, '^error [^\n]+\n( [^\n]*\n)*', [nl dskip nl '%error' ... ' (**ERROR TEST: NOT SUPPORTED, REMOVED**)' nl], 'lineanchors'); body = regexprep(body, '^warning [^\n]+\n( [^\n]*\n)*', [nl dskip nl '%warning' ... ' (**WARNING TEST: NOT SUPPORTED, REMOVED**)' nl], 'lineanchors'); % output it out_name = ['tests_' basestr '_' name_no_m]; full_out_name = [outdir '/' out_name '.m']; fid = fopen (full_out_name, 'w'); fprintf(fid, 'function %s()\n', out_name); fprintf(fid, '%%%% Auto extracted tests from %s\n', in_name); fprintf(fid, '%% This file autogenerated from the inline Octave tests\n'); fprintf(fid, '%% in the above file. Don''t modify directly.\n'); % FIXME: fprintf better than this schar thing? its for utf8 fwrite(fid, body, "schar"); fprintf(fid, '\n\n\n%%%% End of tests\n'); fprintf(fid, 'disp('' Passed'')\n'); fclose(fid); endfunction % This code from Octave source: /scripts/testfun/test.m % Copyright (C) 2005-2013 Paul Kienzle % GPL function body = __extract_test_code (nm) fid = fopen (nm, "rt"); body = ''; if (fid >= 0) while (! feof (fid)) ln = fgetl (fid); if (length (ln) >= 2 && strcmp (ln(1:2), "%!")) body = [body, "\n"]; if (length (ln) > 2) body = [body, ln(3:end)]; endif endif endwhile fclose (fid); endif endfunction symbolic-2.2.4/testing/0000755000175000001440000000000012633614672013507 5ustar cbmuserssymbolic-2.2.4/testing/echo_bug.bat0000644000175000001440000000104312633614672015750 0ustar cbmusers@echo OFF REM Info: REM "ping" is "sleep" on this lame excuse of an OS REM ("timeout" won't work if input/output redirected) echo hello 1, sleeping PING 1.1.1.1 -n 1 -w 500 > NUL echo hello 2, sleeping PING 1.1.1.1 -n 1 -w 500 > NUL echo hello 3, sleeping PING 1.1.1.1 -n 1 -w 500 > NUL echo NOW WE TALK TO STDERR... echo hello stderr 1>&2 echo Betcha won't see this! echo hello 4, sleeping PING 1.1.1.1 -n 1 -w 500 > NUL echo hello 5, sleeping PING 1.1.1.1 -n 1 -w 500 > NUL echo hello 6, sleeping PING 1.1.1.1 -n 1 -w 500 > NUL echo goodbye symbolic-2.2.4/testing/test_python_prog_as_string.m0000644000175000001440000000437212633614672021353 0ustar cbmusers%% Test python -c with newlines in the command if (ispc () && ! isunix ()) pyexec = 'py.exe'; %pyexec = 'n:\win32\octsympy.git\testing\py.exe' else pyexec = 'python'; end %% Baseline % works on GNU/Linux and Windows bigs1 = 'import sys; print(42)' %% real embedded newlines % works on GNU/Linux, fails on windows % todo: experiment with \r\n, no reason it should work as sprintf % will do that anyway...? bigs2 = 'import sys\nprint(42)' bigs2 = sprintf(bigs2) [st1,out1] = system([pyexec ' -c "' bigs1 '"']) [st2,out2] = system([pyexec ' -c "' bigs2 '"']) disp('----------------------------------------') %% escaped newlines % fails on GNU/Linux, not expected to work bigs3 = 'import sys\nprint(42)' [st3,out3] = system([pyexec ' -c "' bigs3 '"']) disp('----------------------------------------') %% idea: use exec() # triple slash quote s4 = 'exec(\"def p(x):\n print(x)\np(42)\np(\\\"p\\\")\")' # with single quote: escaped just for entry into octave s5 = 'exec(\"def p(x):\n print(x)\np(42)\np(\\\"p\\\''qr\\\")\np(''jk'')\")' # newlines inside inside string s6 = 'exec(\"def p(x):\n print(x)\np(42)\np(\\\"hello\\\nbye\\\")\np(42)\")' # newlines, single quotes and double quotes inside string: #s7 = 'exec(\"def p(x):\n print(x)\np(42)\np(\\\"hello\\\n''nihao''\\\n\\\\\\\"bye\\\\\\\"\\\")\np(42)\")' s7 = ['exec(\"' ... 'def p(x):\n print(x)\n' ... 'p(42)\np(\\\"hello\\\\n''ni\\\\\\\\\\\\\\\\tao''\\\n\\\\\\\"bye\\\\\\\"\\\")\n' ... 'p(42)\np(''hello\\\\n\\\\''nihao\\\''\\\n\\\\\\\"bye\\\\\\\"'')\n' ... 'p(42)\")'] % a python str w/ newl, dblquote, tab, \. and \t %p("ab\nab\"ab\tab\\ab\\tab") %\n -> \\\\n [\\n \n newl] %\" -> \\\\\\\" 7 not 8 [\\\" \" "] %\" -> \\\\" then replace " with \\\" %\" -> \\\\\\\\" [\\\\" \\" \"] %\t -> \\\\t [\\t \t tab] good %\\ -> 8\ %\\\\ -> 16\ [st4,out4] = system([pyexec ' -c "' s4 '"']) [st5,out5] = system([pyexec ' -c "' s5 '"']) [st6,out6] = system([pyexec ' -c "' s6 '"']) [st7,out7] = system([pyexec ' -c "' s7 '"']) disp('----------------------------------------') %% test, can we use single quotes instead to avoid so much escaping? # single quote in -c, fails on Windows sa1 = 'exec("def p(x):\n print(x)\np(42)\np(\"a\\n\\\"b\\\"\\n\\\"c\")")' [sta1,outa1] = system([pyexec ' -c ''' sa1 '''']) symbolic-2.2.4/testing/test_pipe_py2.m0000644000175000001440000000474312633614672016463 0ustar cbmusersmore off EAGAIN = errno ('EAGAIN') EINVAL = errno ('EINVAL') disp('** calling popen2') %[in, out, pid] = popen2 ('python', '-i') %[in, out, pid] = popen2 ('n:\win32\py275.exe') %[in, out, pid] = popen2 ('py.exe', {'-S'}) % ok %[in, out, pid] = popen2 ('py.exe', {'-S'}) %[in, out, pid] = popen2 ('py.exe', {'-i' '--help'}) %[in, out, pid] = popen2 ('busybox.exe', {'cat'}) %[in, out, pid] = popen2 ('myecho.bat') [in, out, pid] = popen2 ('winwrapy.bat') %[in, out, pid] = popen2 ('C:\Windows\system32\sort.exe', '/R') %[in, out, pid] = popen2 ('sort', '/R') %[in, out, pid] = popen2 ('cat') assert(pid > 0) if (ispc() && ~isunix()) %newl = sprintf('\r\n'); newl = sprintf('\n'); else newl = sprintf('\n'); end r = fputs (in, ['a = 42; print((a,a,a))' newl newl]); assert(r == 0) r = fputs (in, ['a = "colin"; print(a)' newl newl]); assert(r == 0) r = fputs (in, ['a = 43; print((a,a,a))' newl newl]); assert(r == 0) % works %r = fputs (in, sprintf('a = "macdonald"; print(a)\n\n')) r = fputs (in, 'a = "macdonald"; print(a)'); assert(r == 0) r = fputs (in, [newl newl]); assert(r == 0) r = fputs (in, ['import time' newl newl]); assert(r == 0) r = fputs (in, ['time.sleep(1.5)' newl newl]); assert(r == 0) r = fputs (in, ['import sys' newl newl]); assert(r == 0) r = fputs (in, ['print(sys.version_info)' newl newl]); assert(r == 0) sleep(1) r = fputs (in, ['a = 44; print((a,a,a))' newl newl]); assert(r == 0) %r = fputs (in, '\n\n') r = fflush(in); assert(r == 0) %r = fputs (in, ["zese" newl "are" newl "some" newl "strings" newl]) %assert(r == 0) r = fflush(in); assert(r == 0) fclear (in); %r = fclose (in); assert(r == 0) sleep (0.1); disp('** reading it back') done = false; num_again = 0; do %errno(0); % see syscall.cc test on windows s = fgets (out); if (ischar (s)) fputs (stdout, s); elseif (errno () == EINVAL) disp(sprintf('waiting (win32), s=%d, errno=%d', s, errno())) errno(0); fclear (out); %fclear (in); %fputs (in, newl); sleep (0.2); num_again++; if (num_again > 30) disp('no many waits, breaking out') break end elseif (errno () == EAGAIN) errno fclear (out); sleep (0.2); disp('waiting (on posix)') else disp(sprintf('waiting (somewhere), s=%d, errno=%d', s, errno())) sleep (0.2); num_again++; if (num_again > 12) disp('no many waits, breaking out') break end %done = true; end until (done) r = fclose (in); assert(r == 0) fclose (out); waitpid (pid); symbolic-2.2.4/testing/test_pipe_python.m0000644000175000001440000000716512633614672017273 0ustar cbmusers%% basic python with popen2 test % more off EAGAIN = errno ('EAGAIN') EINVAL = errno ('EINVAL') disp('** calling popen2') %[in, out, pid] = popen2 ('python', '-i') %[in, out, pid] = popen2 ('n:\win32\py.exe', '-i') %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\winwrapy.bat') %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\busybox.exe', 'cat') %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe', '-i -c "a=42;print(a);print(a,a)"') % works on win32: %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\busybox.exe', 'cat') %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\busybox.exe', {'cat'}) %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe') % (but needs to fclose first!) %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe', '-V') % does not work: %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\busybox.exe cat') % should work but does not: %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe', '-i') %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe', '-c print(42)') %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe', '-c print(42)') % testing %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe', '-i') %[in, out, pid] = popen2 ('n:\win32\octsympy.git\testing\py.exe', '-c print(42)') %args = {'-c' 'print(42)'}; Targs = {'-c' '"print(66);a=66;print((a,a,a,a))"'}; %args = {'-i' '-u' '--help'}; args = {'-u'}; [in, out, pid] = popen2 ('py.exe', args) assert(pid > 0) close_first = true sleep(0.1) fprintf('\n') % this will make the correct newline on win and unix newl = sprintf('\n'); newl2 = "\r\n"; r = fputs (in, ['a = 42; print((a,a,a))' newl2 newl2]); assert(r == 0) %% test loading modules %r = fputs (in, ['import sympy' newl newl]); %assert(r == 0) r = fputs (in, ['a = "test"; print(a)' newl newl]); assert(r == 0) %% other things that work r = fputs (in, sprintf('a = "weee"; print(a)\n\n')); fprintf (in, 'a = "weee"; print(a)\n\n') r = fputs (in, [newl newl]); assert(r == 0) fprintf (in, 'print("** LAST input **")\n\n') fprintf (in, 'print("** LAST input **")\n\n') r = fputs (in, [newl newl]); %% Flush input % necessary (tested on GNU/Linux) if last input is fprintf, rather % than fputs. sleep (0.1); r = fflush(in); assert(r == 0) sleep (0.1); r = fflush(in); assert(r == 0) %% Issue whether we close before reading from the pipe % need to close it later for proper interactivity. if (close_first) disp('closing "in" before reading back') r = fclose (in); assert(r == 0); end fprintf('\n**** Starting to read from pipe ****\n') done = false; num_again = 0; errno(0); fclear(out); while(1) if (ispc() && ~isunix()) %% reset errno before the syscall, harmful on Linux? % what about Mac OS X? %errno(0); % see octave syscall.cc test on windows end s = fgets (out); if (ischar (s)) disp('') fputs (stdout, s); disp('') elseif (errno() == EINVAL) fclear (out); errno(0); % reset errno, is this sufficient for win32? sleep (0.15); disp('waiting (on win32)') num_again++; assert (ispc() && ~isunix()) elseif (errno() == EAGAIN) fclear(out); errno(0); % not required on posix but harmless? sleep(0.15); disp('waiting (on posix)') num_again++; %assert (~ispc() && isunix()) else warning(sprintf('fgets returned non-string, unexpected errno: s=%d, errno=%d', s, errno())) sleep(0.1); num_again++; end if (num_again > 25) disp('25 waits, breaking out') break end end if (~close_first) r = fclose (in); assert(r == 0) end r = fclose (out); assert(r == 0) [pid,st,msg] = waitpid (pid) symbolic-2.2.4/testing/README.md0000644000175000001440000000252712633614672014774 0ustar cbmusersNotes on Octave-Python IPC ========================== This directory contains some testing codes. We currently have three mechanisms. 1. creating a temp file and calling it with system('python temp.py') 2. system() with passing program on command line via 'python -c'. 3. popen2(). The faster approach, should be default. IPC on GNU/Linux ---------------- Developement environment, all three mechanisms work. IPC experiments on Windows -------------------------- 1) temp file works on windows w/ py.exe and python.org win install 2) system doesn't work on either, perhaps cmd.exe multiline todo write test for this, even just with sort? 3) popen2 works in principle on windows a. python install works w/ some tests (but not full octsympy yet?). No even all tests work :( b. py.exe has bug with pipes, reported, wait for 2.7.8 release. cat | py.exe -i | cat and it does not work without the -i with -i it is interactive, so py.exe works in principle --> must be Octave problem (but I cannot get -i passed using popen2) Using -i I get nothing, no EINVAL at all With or w/o -S I can get back output but only if I close the input before reading (!) perhaps it would work if I could pass -i? hypothesis: octave cannot handle things writing to stderr, py.exe does with -i so it get's grumpy IPC on Mac OS X --------------- Not tested. symbolic-2.2.4/testing/mydbpy.bat0000755000175000001440000000065212633614672015511 0ustar cbmusers@echo OFF REM Octave for windows cannot tolerate stderr from a popen2 subprocess REM This bat file discards stderr from py.exe REM redir stderr to stdout REM py -i 2>&1 REM drop stderr py -i 2> NUL REM log stderr REM py -i 2> stderrlog.txt REM Fancier logging with busybox/tee REM del /Q inlog.txt REM del /Q outlog.txt REM del /Q stderrlog.txt REM busybox tee inlog.txt | py -i 2> stderrlog.txt | busybox tee outlog.txt symbolic-2.2.4/HOWTO-release.md0000644000175000001440000000426412633614672014700 0ustar cbmusersHow to do a release =================== We use x.y.z. Bump y for minor changes or z for "micro" changes (bug fixes etc). OctaveForge process: http://octave.sourceforge.net/developers.html TODO: read this during next release, and update below. Checklist --------- * Update sympref.m: - update version number (remove "-dev", check if bump needed). - Make sure snippet defaults to false. * Update DESCRIPTION file (version number and date). * Update NEWS file (date, version number, reformat). * Update version in src/configure.ac. Test the bootstrap script (note the scripts below will run bootstrap for the packages). * Packages: need to run the following two scripts. I recommend testing them first without using the tag. Then test the packages by running the test suite. - make_release_packages.sh, use "day-to-day testing" mode instead of tag. - make_windows_package.sh, use "day-to-day testing" mode. * Test regenerating the html documentation. Needs version >= 0.1.7. - pkg load generate_html - options = get_html_options ("octave-forge"); - generate_package_html ("symbolic", "html", options) * If packages seem ok, then tag the repo with: `git tag -a v2.0.0 -m "Version 2.0.0"` * `git push --tags origin master`. If messed up and want to change anything after this, need to bump version number (tag is public). * Push and push tags to sourceforge. * Then redo the packages using the "tag" mode. - compute the md5sums, upload the packages to github release page, and copy-paste the md5sums. - regenerating the html documentation. - create ticket for binaries and doc tarball on sourceforge. AFTER release ============= * Bump version to the next anticipated version and append "-dev" in in sympref.m. See [PEP 440](https://www.python.org/dev/peps/pep-0440). * Update the version in src/configure.ac: -dev seems ok there. * Optionally, update the make_*releases* scripts. * Leave old version in DESCRIPTION ("-dev" not supported here). We will bump it at the next release. FIXME: this is unfortunate. * Snippets could default to true in sympref.m symbolic-2.2.4/.travis.yml0000644000175000001440000000227412633614672014150 0ustar cbmuserslanguage: python # well its really octave, but that is not supported matrix: include: - python: "2.7" env: SYMPY_VER=0.7.5 DOCTEST=no - python: "2.7" env: SYMPY_VER=0.7.6 DOCTEST=yes - python: "3.4" env: SYMPY_VER=0.7.6.1 DOCTEST=yes # need octave devel pkgs for doctest (has compiled code as of July 2015) # TODO: once doctest is in OF, change to "install -forge" below install: - sudo apt-add-repository --yes ppa:octave/stable - sudo apt-get update - sudo apt-get install octave liboctave-dev - "pip install sympy==$SYMPY_VER" - wget https://github.com/catch22/octave-doctest/releases/download/v0.4.0/doctest-0.4.0.tar.gz - octave --eval "pkg install doctest-0.4.0.tar.gz" # all commands here must have exit code 0 for the build to be called "passing" # debugging: octave --eval "syms x; A = [x sin(x) x^3]; A; exit(0)" script: - octave --eval "ver; pwd; exit(0)" - pushd src; make; popd - pushd inst - octave --eval "r = octsympy_tests; exit(r)" - cat octsympy_tests.log - if [ "x$DOCTEST" = "xyes" ]; then octave --eval "pkg load doctest; syms x; r = doctest('.'); exit(~r)"; fi - popd #after_script: # - echo ${TRAVIS_TEST_RESULT} symbolic-2.2.4/make_windows_package.sh0000755000175000001440000000336312633614672016540 0ustar cbmusers#!/bin/sh # download py.exe from http://www.orbitals.com/programs/pyexe.html PYEXE=py27910.exe PYEXEREADME=py27910.readme.txt # from the src package # download sympy release, unpack in the directory with this script SYMPY=sympy-0.7.6.1 # for day-to-day testing VER=2.2.4-dev # for release #VER=2.2.4 #TAG=v${VER} ################################### WINPKG=symbolic-win-py-bundle-$VER WINDIR=$WINPKG WINDIRTMP=${WINDIR}-TMP echo "Making packages for octsympy-$VER." read -p "Press [Enter] to git clone and make packages..." # checkout a clean copy rm -rf octsympy git clone https://github.com/cbm755/octsympy.git pushd octsympy if [ -z $TAG]; then git checkout master else git checkout tags/${TAG} fi popd # clean up rm -rf ${WINDIR} rm -rf ${WINDIRTMP} cp -r octsympy ${WINDIRTMP} pushd ${WINDIRTMP}/src/ make distclean ./bootstrap ./configure make popd # copy things to the package mkdir ${WINDIR} cp -ra ${WINDIRTMP}/inst ${WINDIR}/ cp -ra ${WINDIRTMP}/bin ${WINDIR}/ cp -ra ${WINDIRTMP}/NEWS ${WINDIR}/ cp -ra ${WINDIRTMP}/CONTRIBUTORS ${WINDIR}/ cp -ra ${WINDIRTMP}/DESCRIPTION ${WINDIR}/ cp -ra ${WINDIRTMP}/COPYING ${WINDIR}/ cp -ra ${WINDIRTMP}/README.bundled.md ${WINDIR}/ cp -ra ${WINDIRTMP}/matlab_smt_differences.md ${WINDIR}/ # py.exe cp ${PYEXE} ${WINDIR}/bin/py.exe cp ${PYEXEREADME} ${WINDIR}/README.pyexe.txt # change default python to py.exe echo "making default python py.exe" sed -i "s/pyexec = 'python'/pyexec = 'py.exe'/" ${WINDIR}/inst/private/python_ipc_sysoneline.m sed -i "s/pyexec = 'python'/pyexec = 'py.exe'/" ${WINDIR}/inst/private/python_ipc_system.m # sympy cp -ra ${SYMPY}/sympy ${WINDIR}/bin/ || exit -6 cp -ra ${SYMPY}/README.rst ${WINDIR}/README.sympy.rst || exit -6 zip -r ${WINPKG}.zip ${WINDIR} md5sum ${WINPKG}.zip symbolic-2.2.4/matlab_smt_differences.md0000644000175000001440000001023712633614672017037 0ustar cbmusersDifferences between OctSymPy and the Symbolic Math Toolbox ========================================================== The Symbolic Math Toolbox (SMT) is proprietary software sold by The Mathworks. We want some minimal compatibility. This document notes the differences. Functions SMT has that OctSymPy does not have --------------------------------------------- > "Uh, all of them, I think." > --John Conner, 1995 That is, your help is needed here. Functions that OctSymPy has which SMT does not have --------------------------------------------------- These should be updated to match SMT if/when they are added. * fibonacci * isprime * nextprime * lhs/rhs * isconstant/isallconstant Differences ----------- * bernoulli in octsympy gives explicit polynomials whereas SMT treats e.g., diff() using identities. * SMT's sym() constructor allows big string expressions: we don't really support that (and its not the way modern SMT is used either). Build your expressions like sym('x')/2 rather than sym('x/2'). (If you do want to pass long strings, they should be valid Python SymPy `srepr` syntax---i.e., you probably don't want to do this!) * OctSymPy has [p,m] = factor(a) which returns an array of the prime factors and their multiplicities. Pure Matlab 'factor' has this but strangely SMT 'factor' does not. * Assumptions are quite different, although we fake quite a bit for compatibility, see section below. * SMT has isinf(x + oo) and isinf(x*oo) true. SymPy says false. * SMT logical(sym('x')), logical(sym(pi)) are errors. OctSymPy has true (b/c nonzero). FIXME: double-check later * SMT char(expr) outputs MuPAD code string; OctSymPy outputs SymPy string. * Suppose we have a symfun `g(s,t) = x`. Both SMT and OctSymPy agree that `symvar(g, 1)` is `s` (i.e., preference for the independent variables). However, `symvar(g)` gives `[s t x]` in OctSymPy and `x` in SMT. I suspect this is an SMT bug. At any rate, its probably better to use `argnames` and `symvar(formula)` if these sorts of subtlies are important to you. * SMT and OctSymPy differ in how the return solutions to systems of equation has multiple solutions. For example: `d = solve(x*x == 4, x == 2*y)` In OctSymPy, the two solutions are `d{1}` and `d{2}`. Components are accessed as `d{1}.x` (the x component of the first solution). In SMT, its the opposite: `d.x` gives the x component of both solutions as a column vector. I prefer our way (but this could be changed fairly easily.) `[X, Y] = solve(x*x == 4, x == 2*y)` does the same on both, returning column vectors for X and Y. * SMT sym2poly converts to a double array. We *currently* copy this behaviour but might change in the future. We recommend `double(sym2poly(x^2 + 3))` for clarity and compatibility. Our sym2poly also takes an optional extra argument to specify `x` which returns a symbolic row vector. * SMT fourier/ifourier/laplace/ilaplace have strange rules for determining a transform with respect to what variable. We just use symvar (that is, a preference for `x` over other variables like `t`). Differences in assumptions -------------------------- In OctSymPy, if you create a symbol with assumptions, those stay with any expressions and are not "updated" if you introduce a new symbol with the same expression. For example: ```` syms x positive x2 = sym('x', 'real') isequal(x,x2) % false ```` or ```` x = sym('x', 'positive') eqn = x^2 == 4 solve(eqn) % 2 x = sym('x') solve(eqn) % still 2, eqn has the old symbol solve(eqn,x) % empty: the variable in x is not the same as that in eqn. ```` Other notes: * SMT assumptions seem to be stored centrally: FIXME: double check that SMT functions do have their own assumptions workspace. * assume(), assumeAlso(), sym('x', 'clear'), "syms x clear". All of these muck around in the caller's workspace, traversing sym, struct and cell arrays to replace x with the new x. * in both OctSymPy and SMT, you can add assumptions when creating a sym as in sym('x', 'real') and sym('x', 'positive'). OctSymPy also supports others including 'integer', 'even', 'odd'. symbolic-2.2.4/bin/0000755000175000001440000000000012633614672012602 5ustar cbmuserssymbolic-2.2.4/bin/winwrapy.bat0000755000175000001440000000256112633614672015161 0ustar cbmusers@echo OFF REM This bat file discards stderr from python.exe. REM This is needed as Octave for Windows cannot tolerate stderr from a popen2 REM subprocess: see [this bug report](https://savannah.gnu.org/bugs/?43036). REM We look for python.exe and use that if found. Otherwise we try py.exe. REM You'll need to edit this script if your python is called something else. REM This batch file uses the "where" command, which is present only for REM Windows Server 2003 and later versions. So, for older windows systems (such REM as Windows XP) only lines 17 or 20 should be kept in the next code block. REM returns 0 if python.exe is found where /Q python.exe IF ERRORLEVEL 1 GOTO else python.exe -i 2> NUL goto endif :else py.exe -i 2> NUL :endif REM If python is not installed in your system, "py.exe" will be used. REM It is [available online](http://www.orbitals.com/programs/pyexe.html) REM You may need to include its folder (e.g., REM C:\Octave\Octave-3.8.2\share\octave\package\octsympy-2.1.1\bin) REM in the windows environment variable %PATH REM Other options for the stderr: REM redir stderr to stdout REM py -i 2>&1 REM drop stderr REM py -i 2> NUL REM log stderr REM py -i 2> stderrlog.txt REM Fancier logging with busybox/tee REM del /Q inlog.txt REM del /Q outlog.txt REM del /Q stderrlog.txt REM busybox tee inlog.txt | py -i 2> stderrlog.txt | busybox tee outlog.txt symbolic-2.2.4/convert_comments.m0000644000175000001440000001372112633614672015601 0ustar cbmusersfunction convert_comments (basedir, subdir, dirout) % this slightly strange way of doing things (basedir, subdir) is % b/c I must "chdir" into base, but get_first_help_sentence() must % not be in the class dir... disp(char('_' * ones(1,78))) disp('') fprintf('****** OCTAVE PROCESSING DIRECTORY %s\n', [basedir subdir]) %basedir, subdir, dirout files = dir([basedir subdir]); chdir(basedir) for i=1:length(files) if (~files(i).isdir) [dir, name, ext] = fileparts(files(i).name); if (strcmp(ext, '.m')) if isempty(subdir) octname = [name ext]; else octname = [subdir '/' name ext]; end fprintf('**** Processing %s ****\n', octname) r = convert_oct_2_ml (octname, [dirout octname]); if ~r [status, msg, msgid] = copyfile (octname, [dirout octname], 'f'); if (status ~= 1) error(msg) end %disp([' ' char('*' * ones(1,72))]) fprintf('******* COPYING %s UNMODIFIED ****\n', octname) %disp([' ' char('*' * ones(1,72))]) end end end end disp(char('_' * ones(1,78))) end function success = convert_oct_2_ml (fname, foutname) [dir, fcn, ext] = fileparts(fname); newl = sprintf('\n'); [fi,msg] = fopen(fname, 'r'); if (fi < 0) error(msg) end ins = {}; i = 0; while (1) temp = fgets(fi); if ~ischar(temp) && temp == -1 break end i = i + 1; ins{i} = temp; % todo, possible strip newl end fclose(fi); % trim newlines ins = deblank(ins); %% find the actual function [] = ... line Nfcn = []; for i = 1:length(ins) I = strfind (ins{i}, 'function'); if ~isempty(I) && I(1) == 1 %disp ('found function header') Nfcn = i; break end end if isempty(Nfcn) disp('AFAICT, this is a script, not a function') success = false; return end %% copyright block [cr,N] = findblock(ins, 1); if (Nfcn < N) warning('function header in first block (where copyright block should be), not converting') success = false; return end cr = ltrim(cr, 3); % cut 2nd line if empty if isempty(cr{2}) cr2 = cell(1,length(cr)-1); cr2(1) = cr(1); cr2(2:end) = cr(3:end); cr = cr2; end cr = prepend_each_line(cr, '%', ' '); cr{1} = ['%' cr{1}]; copyright_summary = 'This is free software under the GPL, see .m file for full details.'; %% use block % we don't parse this, just call get_help_text temp = ins{N}; if ~strcmp(temp, '%% -*- texinfo -*-') error('can''t find the texinfo line, aborting') %success = false; %return end %% the "lookfor" line lookforstr = get_first_help_sentence (fname); if (~isempty(strfind(lookforstr, newl))) lookforstr error('lookfor string contains newline: missing period? too long? some other issue?') %success = false; %return end if (length(lookforstr) > 76) error(sprintf('lookfor string of length %d deemed too long', length(lookforstr))) end %% actual help, then format [text, form] = get_help_text(fname); if ~strcmp(form, 'texinfo') text form error('formatted incorrectly, help text not texinfo') end usestr = __makeinfo__(text, 'plain text'); %% remove the lookforstr from the text I = strfind(usestr, lookforstr); if length(I) ~= 1 I lookforstr usestr error('too many lookfor lines?') end len = length(lookforstr); J = I + len; % if usestr has only a lookfor line then no need to see what's next if (J < length(usestr)) % find next non-empty char %while isspace(usestr(J)) % J = J + 1; %end % let's be more conservative trim newline in usual case: if ~isspace(usestr(J)) error('no space or newline after lookfor line?'); end J = J + 1; end usestr = usestr([1:(I-1) J:end]); use = strsplit(usestr, newl, 'CollapseDelimiters', false); %% remove this string % and make sure these lines have the correct function name remstr = '-- Function File: '; for i=1:length(use) if strfind(use{i}, remstr); if isempty(strfind(use{i}, [' ' fcn])) error('function @deftypefn line doesn''t include function name') end end use{i} = strrep(use{i}, remstr, ' '); end %usestr = strrep(usestr, lookforstr, ''); use = ltrim(use, 2); while isempty(use{end}) use = use(1:end-1); end %% the rest N = Nfcn; fcn_line = ins{N}; % sanity checks I = strfind(ins{N+1}, '%'); if ~isempty(I) && I(1) == 1 ins{N} ins{N+1} error('possible duplicate comment header following function') end therest = ins(N+1:end); %% Output f = fopen(foutname, 'w'); fdisp(f, fcn_line) fprintf(f, '%%%s %s\n', upper(fcn), lookforstr) for i=1:length(use) fprintf(f, '%%%s\n', use{i}); end fdisp(f, '%'); fprintf(f, '%% %s\n', copyright_summary); %fdisp(f, '%'); %fdisp(f, '% [Genereated from a GNU Octave .m file, edit that instead.]'); %fprintf(f,(s) fdisp(f, ''); fdisp(f, '%% Note for developers'); fdisp(f, '% This file is autogenerated from a GNU Octave .m file.'); fdisp(f, '% If you want to edit, please make changes to the original instead'); fdisp(f, ''); for i=1:length(cr) fprintf(f, '%s\n', cr{i}); end fdisp(f, ''); for i=1:length(therest) fprintf(f, '%s\n', therest{i}); end fclose(f); success = true; end function [block,endl] = findblock(f, j) block = {}; c = 0; %newl = sprintf('\n'); for i = j:length(f) temp = f{i}; %if (strcmp(temp, newl)) if (isempty(temp)) endl = i + 1; break end c = c + 1; block{c} = temp; end end function g = ltrim(f, n) g = {}; for i = 1:length(f) temp = f{i}; if length(temp) < n g{i} = ''; else g{i} = substr(temp, n+1); end end end function g = prepend_each_line(f, pre, pad) g = {}; for i = 1:length(f) temp = f{i}; if isempty(temp) g{i} = pre; else g{i} = [pre pad temp]; end end end symbolic-2.2.4/README.matlab.md0000644000175000001440000000066712633614672014561 0ustar cbmusersOctSymPy for Matlab =================== README.md is the main document. Here we list any Matlab-specific notes. Formatting: Matlab uses a different formatting for comment headers. Most of the .m files have been autoconverted from the GNU Octave versions. Tests: Many .m files have tests built-in using using Octave's test framework. These have been autoextracted for Matlab (which unfortunately doesn't use the same test framework).