symbolic/0000755000175000017500000000000011647530220013677 5ustar carandraugcarandraugsymbolic/doc/0000755000175000017500000000000011647530220014444 5ustar carandraugcarandraugsymbolic/doc/INSTALL0000644000175000017500000000237410473517121015504 0ustar carandraugcarandraug Prerequisites ------------- You will need GiNaC installed before you can install this package. Go to the GiNaC web site http://www.ginac.de and follow the download instructions. It will tell you how to get cln and also how to build GiNaC once you have built cln. You will also need a version of Octave that was compiled without the -fno-rtti or -fno-exceptions. Versions below octave-2.1.33 have these options by default. These options are typically loacated in the Makeconf file in the top level directory. After configure and before compile you can remove these options if you want to use an older version of octave. Compiling ---------- Make sure that the correct version of mkoctfile is in your path. Then just type gmake(or whatever you call you version of GNU Make) in the top level directory. Installing ---------- Just type "gmake INSTALL_PATH=/your/path install" and it will install all the .oct files and .m files in /your/path. Add /your/path to your octave path. Once you have it installed you will need to type symbols at the octave command prompt each session to initialize the toolbox. Then you can use all of the commands in the toolbox. Command completion will not work on the commands until after yopu have used them once. symbolic/doc/symbolic.html0000644000175000017500000001721510764762165017177 0ustar carandraugcarandraug Octave Symbolic Manipulation Toolbox

The Octave Symbolic Manipulation Toolbox is based upon  GiNaC .   The goal is to simply provide the capabilities of GiNaC in the easy to use environment provided by Octave.

Limitations/Features
Currently there is no support for symbolic matrices. I think it would require a few changes to the parser to do it nicely: for example:  sym_matrix = [x+1, x+5; x^2+4,x^2+2*x+1];  I could make a function like sym_matrix(the_rows,the_columns,x+1, ... )  that returned a symbolic matrix but this would be a bit of a kludge.

In order to do exact arithmetic you need to deal with strings and the vpa command.  For example:  vpa("1")/vpa("7") is represented internally as exactly 1/7.   However,  vpa("1")/7 or 1/vpa("7")  is an approximation to 1/7 that is accurate to roughly the accuracy of the current value of digits.

GiNaC throws exceptions when there are problems with computations.   I handle some of them at this time, but I do not handle all of them.   This can cause octave to terminate prematurely.   For example, try vpa("1")/vpa("0").   This will eventually be fixed.

Download and install

You will need to install cln-1.0.1, GiNaC-0.8.0 and octave-2.1.33 or later to use this package.  You may be able to get by with an earlier version of octave if you compiled without the "-fno-rtti -fno-exceptions" options.   This package uses both exceptions and run-time type identification.    There is an INSTALL file in the package which will tell you how to install the package.

Functions
Below I provide a list of function that I have implemented or have plans to implement as of the latest release .  If the function name is green then the function is implemented and to the best of my knowledge there are no problems with it.  If the function is red then it has not been implemented yet.  If the function is blue then it has been implemented but is known not to work correctly.  Blues will appear only very rarely.

symbolic/inst/0000755000175000017500000000000011647530254014663 5ustar carandraugcarandraugsymbolic/inst/symfsolve.m0000644000175000017500000001220611647265117017074 0ustar carandraugcarandraug## Copyright (C) 2003 Willem J. Atsma ## ## 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 2 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{x}, @var{inf}, @var{msg}] =} symfsolve (@dots{}) ## Solve a set of symbolic equations using @command{fsolve}. There are a number of ## ways in which this function can be called. ## ## This solves for all free variables, initial values set to 0: ## ## @example ## symbols ## x=sym("x"); y=sym("y"); ## f=x^2+3*x-1; g=x*y-y^2+3; ## a = symfsolve(f,g); ## @end example ## ## This solves for x and y and sets the initial values to 1 and 5 respectively: ## ## @example ## a = symfsolve(f,g,x,1,y,5); ## a = symfsolve(f,g,@{x==1,y==5@}); ## a = symfsolve(f,g,[1 5]); ## @end example ## ## In all the previous examples vector a holds the results: x=a(1), y=a(2). ## If initial conditions are specified with variables, the latter determine ## output order: ## ## @example ## a = symfsolve(f,g,@{y==1,x==2@}); # here y=a(1), x=a(2) ## @end example ## ## The system of equations to solve for can be given as separate arguments or ## as a single cell-array: ## ## @example ## a = symfsolve(@{f,g@},@{y==1,x==2@}); # here y=a(1), x=a(2) ## @end example ## ## If the variables are not specified explicitly with the initial conditions, ## they are placed in alphabetic order. The system of equations can be comma- ## separated or given in a cell-array. The return-values are those of ## fsolve; @var{x} holds the found roots. ## @end deftypefn ## @seealso{fsolve} function [ x,inf,msg ] = symfsolve (varargin) ## separate variables and equations eqns = cell(); vars = cell(); if iscell(varargin{1}) if !strcmp(typeinfo(varargin{1}{1}),"ex") error("First argument must be (a cell-array of) symbolic expressions.") endif eqns = varargin{1}; arg_count = 1; else arg_count = 0; for i=1:nargin tmp = disp(varargin{i}); if( iscell(varargin{i}) || ... all(isalnum(tmp) || tmp=="_" || tmp==",") || ... !strcmp(typeinfo(varargin{i}),"ex") ) break; endif eqns{end+1} = varargin{i}; arg_count = arg_count+1; endfor endif neqns = length(eqns); if neqns==0 error("No equations specified.") endif ## make a list with all variables from equations tmp=eqns{1}; for i=2:neqns tmp = tmp+eqns{i}; endfor evars = findsymbols(tmp); nevars=length(evars); ## After the equations may follow initial values. The formats are: ## [0 0.3 -3 ...] ## x,0,y,0.3,z,-3,... ## {x==0, y==0.3, z==-3 ...} ## none - default of al zero initial values if arg_count==nargin vars = evars; nvars = nevars; X0 = zeros(nvars,1); elseif (nargin-arg_count)>1 if mod(nargin-arg_count,2) error("Initial value symbol-value pairs don't match up.") endif for i=(arg_count+1):2:nargin tmp = disp(varargin{i}); if all(isalnum(tmp) | tmp=="_" | tmp==",") vars{end+1} = varargin{i}; X0((i-arg_count+1)/2)=varargin{i+1}; else error("Error in symbol-value pair arguments.") endif endfor nvars = length(vars); else nvars = length(varargin{arg_count+1}); if nvars!=nevars error("The number of initial conditions does not match the number of free variables.") endif if iscell(varargin{arg_count+1}) ## cell-array of relations - this should work for a list of strings ("x==3") too. for i=1:nvars tmp = disp(varargin{arg_count+1}{i}); vars{end+1} = {sym(strtok(tmp,"=="))}; X0(i) = str2num(tmp((findstr(tmp,"==")+2):length(tmp))); endfor else ## straight numbers, match up with symbols in alphabetic order vars = evars; X0 = varargin{arg_count+1}; endif endif ## X0 is now a vector, vars a list of variables. ## create temporary function: symfn = sprintf("function Y=symfn(X) "); for i=1:nvars symfn = [symfn sprintf("%s=X(%d); ",disp(vars{i}),i)]; endfor for i=1:neqns symfn = [symfn sprintf("Y(%d)=%s; ",i,disp(eqns{i}))]; endfor symfn = [symfn sprintf("endfunction")]; eval(symfn); [x,inf,msg] = fsolve("symfn",X0); endfunction %!shared % x = sym ("x"); % y = sym ("y"); % f = x ^ 2 + 3 * x - 1; % g = x * y - y ^ 2 + 3; %!test % assert (symfsolve (f, g), [0.30278; -1.58727]', 1e-5); %!test % assert (symfsolve (f, g, x, 1, y, 5), [0.30278; 1.89004]', 1e-5); %!test % assert (symfsolve (f, g, {x==1,y==5}), [0.30278; 1.89004]', 1e-5); %!test % assert (symfsolve (f, g, [1 5]), [0.30278; 1.89004]', 1e-5); %!test % assert (symfsolve ({f, g}, {y==1,x==2}), [1.89004; 0.30278]', 1e-5); symbolic/inst/sym2poly.m0000644000175000017500000001073411647265117016647 0ustar carandraugcarandraug## Copyright (C) 2003 Willem J. Atsma ## ## 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 2, 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} =} sym2poly (@var{p}, @var{x}) ## Returns the coefficients of the symbolic polynomial expression @var{p} ## as a vector. If there is only one free variable in @var{p} the ## coefficient vector @var{c} is a plain numeric vector. If there is more ## than one free variable in @var{p}, a second argument @var{x} specifies the ## free variable and the function returns a cell vector of symbolic expressions. ## The coefficients correspond to decreasing exponent of the free variable. ## ## Example: ## @example ## symbols ## x = sym("x"); ## y = sym("y"); ## c = sym2poly (x^2+3*x-4); # c = [1,3,-4] ## c = sym2poly (x^2+y*x,x); # c = @{2,y,0@} ## @end example ## ## If @var{p} is not a polynomial the result has no warranty. ## ## @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. function c = sym2poly(p,x) BADPOLY_COEFF_LIMIT = 500; if is_vpa(p) ## polynomial is one vpa number c = to_double(p); if length(c)!=1 error("Argument is not a polynomial."); endif return endif if !is_ex(p) error("Argument has to be a symbolic expression.") endif pvars = findsymbols(p); if isempty(pvars) ## It is possible that we get an expression without any symbols. c = to_double(p); return; endif nvars = length(pvars); if nvars>1 && exist("x")!=1 error("Symbolic expression has more than 1 free variable; no variable specified.") elseif exist("x")!=1 x = pvars{1}; endif p = expand(p); ## GiNaC has commands to access coefficients directly, but in octave this often ## does not work, because for example x^2 typed in octave results in a ## non-integer power in GiNaC: x^2.0 . [num,den] = numden(p); tmp = findsymbols(den); for i=1:length(tmp) if tmp{i}==x error("Symbolic expression is a ratio of polynomials.") endif endfor p = expand(p); p_terms = sumterms(p); ## if this is well behaved, I can find the coefficients by dividing with x c_ex = cell; for i=1:length(p_terms) tmp = p_terms{i}; for j=1:BADPOLY_COEFF_LIMIT if disp(differentiate(tmp,x))=="0" break; endif tmp = tmp/x; endfor if j==BADPOLY_COEFF_LIMIT printf("Please examine your code or adjust this function.\n"); printf("This error may occur because the passed expression is not a polynomial.\n"); error("Reached the set limit (%d) for the number of coefficients.",BADPOLY_COEFF_LIMIT) endif if (length(c_ex) ## ## 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 2, 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} =} findsym (@var{f}, @var{n}) ## Find symbols in expression @var{f} and return them comma-separated in ## string @var{vars}. The symbols are sorted in alphabetic order. If @var{n} ## is specified, the @var{n} symbols closest to "x" are returned. ## ## Example: ## @example ## symbols ## x = sym ("x"); ## y = sym ("y"); ## f = x^2+3*x*y-y^2; ## vars = findsym (f); ## vars2 = findsym (f,1); ## @end example ## ## This is intended for m****b compatibility, calls findsymbols(). ## @seealso{findsymbols} ## @end deftypefn function VARS = findsym(F,Nout) symlist = findsymbols(F); Nlist = length(symlist); if Nlist==0 warning("No symbols were found.") VARS = ""; return endif if exist("Nout")!=1 VARS = disp(symlist{1}); for i=2:Nlist VARS = [VARS "," disp(symlist{i})]; endfor return else ## If Nout is specified, sort anew from x. symstrings = disp(symlist{1}); for i=2:Nlist symstrings = [symstrings ; disp(symlist{i})]; endfor symasc = toascii(symstrings); if Nlist ## ## 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 2, 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{p} =} poly2sym (@var{c}, @var{x}) ## Creates a symbolic polynomial expression @var{p} with coefficients @var{c}. ## If @var{p} is not specified, the free variable is set to sym("x"). @var{c} ## may be a vector or a cell-array of symbols. @var{x} may be a symbolic ## expression or a string. ## The coefficients correspond to decreasing exponent of the free variable. ## ## Example: ## @example ## symbols ## x = sym("x"); ## y = sym("y"); ## p = poly2sym ([2,5,-3]); # p = 2*x^2+5*x-3 ## c = poly2sym (@{2*y,5,-3@},x); # p = 2*y*x^2+5*x-3 ## @end example ## ## @seealso{sym2poly,polyval,roots} ## @end deftypefn function p = poly2sym(c,x) if exist("x")!=1 x = sym("x"); endif N = length(c); if !iscell(c) tmp = c; c = cell; for i=1:N c(i) = tmp(i); endfor endif p = vpa(0); for i=1:N if isnumeric(c{i}) p = p*x+vpa(c{i}); else p = p*x+c{i}; endif endfor endfunction symbolic/inst/splot.m0000644000175000017500000000215211647265117016205 0ustar carandraugcarandraug## Copyright (C) 2002 Ben Sapp ## ## 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 2 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 . ## -*- texinfo -*- ## @deftypefn {Function File} splot(@var{f},@var{x},@var{range}) ## Plot a symbolic function f(x) over range. ## @end deftypefn function splot(expression,symbol,range) ## we should be a little smarter about this t = linspace(min(range),max(range),400); x = zeros(size(t)); j = 1; for i = t x(j) = to_double(subs(expression,symbol,vpa(t(j)))); j++; endfor plot(t,x); endfunction symbolic/INDEX0000644000175000017500000000110010764762536014501 0ustar carandraugcarandraugsymbolic >> Symbolic algebra Symbols symbols sym ex_matrix Pi Extended precision arithmetic digits vpa to_double Properties is_ex is_ex_matrix is_sym is_vpa syminfo Expression manipulation subs collect expand lcoeff numden findsymbols findsym Special Functions Abs Cos Cosh Exp Gcd Log Sin Sinh Tan Tanh aCos aCosh aSin aSinh aTan aTanh Sqrt Polynomials tcoeff coeff degree ldegree sym2poly poly2sym sumterms Calculus differentiate Solving Equations symlsolve symfsolve Number theory probably_prime quotient remainder premainder Plot splot Conversion to_char symbolic/src/0000755000175000017500000000000011647530250014471 5ustar carandraugcarandraugsymbolic/src/numden.cc0000644000175000017500000000303011647271140016262 0ustar carandraugcarandraug/* Copyright (C) 2003 Willem J. Atsma 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 2 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 . */ #include #include #include "ov-vpa.h" #include "ov-ex.h" #include "symbols.h" DEFUN_DLD(numden,args,nargout, "-*- texinfo -*-\n\ @deftypefn Loadable Function {[@var{num}, @var{den}] =} numden(@var{f})\n\ \n\ Return the numerator and denominator of symbolic expression @var{f}.\n\ @end deftypefn") { GiNaC::ex expression, numden_list; octave_value_list retval; int nargin = args.length(); if (nargin != 1) { print_usage (); return retval; } try { if (!get_expression (args(0), expression)) { error("Argument must be a symbolic expression."); return retval; } numden_list = expression.numer_denom(); retval.append(new octave_ex(numden_list[0])); retval.append(new octave_ex(numden_list[1])); } catch(std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } symbolic/src/configure.base0000644000175000017500000000050011014631227017273 0ustar carandraugcarandraugdnl autoconf 2.13 certainly doesn't work! What is the minimum requirement? AC_PREREQ(2.2) AC_INIT(configure.base) dnl Checking for ginac library PKG_CHECK_MODULES(GINAC, ginac, , [AC_MSG_ERROR([GINAC not found])]) dnl Check for gmp library dnl AC_CHECK_LIB(gmp, __gmpz_init, , [AC_MSG_ERROR([GNU MP not found])]) symbolic/src/symbols.h0000644000175000017500000000707411647271140016342 0ustar carandraugcarandraugbool get_expression(const octave_value arg, GiNaC::ex& expression); bool get_symbol(const octave_value arg, GiNaC::ex& sym); bool get_numeric(const octave_value arg, GiNaC::numeric& number); bool get_relation(const octave_value arg, GiNaC::relational& rel); #define DEFUN_DLD_EX_GINAC_FUNCTION(oct_name,ginac_name,description) \ DEFUN_DLD(oct_name, args, , \ "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{r} =}" # oct_name "(@var{x})\n\ Return the " description " of a symbolic expression.\n\ @end deftypefn\n\ ") \ { \ int nargin = args.length (); \ octave_value retval; \ octave_ex *r = NULL; \ GiNaC::ex expression; \ \ if (nargin != 1) \ { \ print_usage(); \ return retval; \ } \ \ try \ { \ if(!get_expression(args(0), expression)) \ { \ print_usage(); \ return retval; \ } \ \ r = new octave_ex(GiNaC::ginac_name (expression)); \ retval = octave_value (r); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ retval = octave_value (); \ } \ \ return retval; \ } #define DEFUN_DLD_EX_SYM_GINAC_FUNCTION(oct_name,ginac_name,description) \ DEFUN_DLD(oct_name, args, , \ "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{r} =}" # oct_name "(@var{a}, @var{x})\n\ Return the " description " of a symbolic expression.\n\ @end deftypefn\n\ ") \ { \ int nargin = args.length (); \ octave_value retval; \ octave_ex *r = NULL; \ GiNaC::ex expression; \ GiNaC::ex sym; \ \ if (nargin != 2) \ { \ error("need exactly two arguments"); \ return retval; \ } \ \ try \ { \ if(!get_expression(args(0), expression)) \ { \ print_usage(); \ return retval; \ } \ \ if (!get_symbol(args(1), sym)) \ { \ print_usage(); \ return retval; \ } \ \ r = new octave_ex(expression.ginac_name \ (GiNaC::ex_to(sym))); \ \ } \ catch (std::exception &e) \ { \ octave_value_list empty; \ error (e.what ()); \ return empty; \ } \ \ return octave_value(r); \ } #define DEFUN_DLD_EX_EX_SYM_GINAC_FUNCTION(oct_name,ginac_name,description) \ DEFUN_DLD(oct_name, args, , \ "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{r} =}" # oct_name "(@var{a}, @var{x})\n\ Return the " description " of a symbolic expression.\n\ @end deftypefn\n\ ") \ { \ int nargin = args.length (); \ octave_value retval; \ octave_ex *r = NULL; \ GiNaC::ex expression0; \ GiNaC::ex expression1; \ GiNaC::ex sym; \ \ if (nargin != 3) \ { \ error("need exactly three arguments"); \ return retval; \ } \ \ try \ { \ if(!get_expression(args(0), expression0)) \ { \ gripe_wrong_type_arg(# oct_name, args(0)); \ print_usage(); \ return retval; \ } \ \ if(!get_expression(args(1), expression1)) \ { \ gripe_wrong_type_arg(# oct_name, args(1)); \ print_usage(); \ return retval; \ } \ \ if (!get_symbol(args(2), sym)) \ { \ gripe_wrong_type_arg(# oct_name, args(2)); \ print_usage(); \ return retval; \ } \ \ r = new octave_ex(ginac_name (expression0, \ expression1, \ GiNaC::ex_to(sym) )); \ \ } \ catch (std::exception &e) \ { \ octave_value_list empty; \ error (e.what ()); \ return empty; \ }\ \ return octave_value(r); \ } /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/ov-vpa.h0000644000175000017500000000505411647271140016056 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #if !defined (octave_vpa_h) #define octave_vpa_h 1 // GiNaC #include #include #include #include // vpa values. class octave_vpa : public octave_base_value { public: octave_vpa (void); octave_vpa (int i); octave_vpa (const octave_vpa& s); octave_vpa (const GiNaC::numeric& s); octave_vpa( const GiNaC::ex& x); ~octave_vpa (void) { } OV_REP_TYPE *clone (void) const { return new octave_vpa (*this); } #if 0 void *operator new (size_t size); void operator delete (void *p, size_t size); #endif dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } int rows (void) const { return 1; } int columns (void) const { return 1; } bool is_constant (void) const { return true; } bool is_defined (void) const { return true; } bool is_real_scalar (void) const { return true; } octave_value all (void) const { return (double) (scalar != 0); } octave_value any (void) const { return (double) (scalar != 0); } bool is_real_type (void) const { return true; } bool is_scalar_type (void) const { return true; } bool is_vpa_type (void) const { return true; } bool valid_as_scalar_index (void) const { return scalar == 1; } bool valid_as_zero_index (void) const { return scalar == 0; } bool is_true (void) const { return (scalar != 0); } double double_value (bool = false) const { return scalar.to_double(); } GiNaC::numeric vpa_value (bool = false) const { return scalar; } octave_value hermitian (void) const { return new octave_vpa (scalar); } void increment (void) { ++scalar; } void decrement (void) { --scalar; } void print (std::ostream& os, bool pr_as_read_syntax = false) const; private: GiNaC::numeric scalar; DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; #endif /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/ov-ex.h0000644000175000017500000000460011647271140015700 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #if !defined (octave_ex_h) #define octave_ex_h 1 #include #include #include #include #include "ov-vpa.h" class octave_complex; class octave_scalar; class octave_ex : public octave_base_value { public: octave_ex(void):octave_base_value() {} octave_ex(octave_ex &ox); octave_ex(GiNaC::ex expression); octave_ex(GiNaC::symbol sym); octave_ex(octave_complex &cmplx); octave_ex(Complex z); octave_ex(octave_scalar &s); octave_ex(double d); ~octave_ex(); octave_ex& operator=(const octave_ex&); GiNaC::ex ex_value(bool = false) const { return x; } OV_REP_TYPE *clone (void) { return new octave_ex (*this); } dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } int rows (void) const { return 1; } int columns (void) const { return 1; } bool is_constant (void) const { return true; } bool is_defined (void) const { return true; } bool valid_as_scalar_index(void) const {return false;} bool is_true(void) const { return true; } octave_value uminus (void) const { return new octave_ex(-x); } void increment (void) { x = x+1;} void decrement (void) { x = x-1;} void print(std::ostream& os,bool pr_as_read_syntax) const; private: GiNaC::ex x; void assign_symbol_to_list(GiNaC::symbol &sym); class symbol_list_item { public: symbol_list_item() {} symbol_list_item(GiNaC::symbol s, int c) {sym=s; refcount=c;} GiNaC::symbol sym; int refcount; }; static std::vector symbol_list; DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; #endif /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/sumterms.cc0000644000175000017500000000337411647271140016666 0ustar carandraugcarandraug/* Copyright (C) 2003 Willem J. Atsma 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 2 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 . */ #include #include #include #include "ov-ex.h" #include "symbols.h" DEFUN_DLD(sumterms,args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{terms} =} sumterms(@var{f})\n\ \n\ Returns a list of terms that are summed in expression @var{f}.\n\ @end deftypefn") { GiNaC::ex expression; octave_value retval; octave_value_list termlist; int nargin = args.length(); if (nargin != 1) { error("Need one argument."); return retval; } try { if (!get_expression (args(0), expression)) { error("Argument must be a symbolic expression."); return retval; } if(GiNaC::is_a(expression)) { int i, n = expression.nops(); for(i=0;i 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 2 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 . */ #include #include #include "ov-ex.h" #include "ov-relational.h" #include "ov-struct.h" #include "ov-bool.h" #include "symbols.h" inline static void add_info_field(Octave_map& info,const GiNaC::ex& exp,std::string field,int info_flag) { bool flag = exp.info(info_flag); info.assign(field,octave_value(flag)); } static void get_info(Octave_map& oct_info, const GiNaC::ex& gobj) { add_info_field(oct_info,gobj,"numeric",GiNaC::info_flags::numeric); add_info_field(oct_info,gobj,"real",GiNaC::info_flags::real); add_info_field(oct_info,gobj,"rational",GiNaC::info_flags::rational); add_info_field(oct_info,gobj,"integer",GiNaC::info_flags::integer); add_info_field(oct_info,gobj,"crational",GiNaC::info_flags::crational); add_info_field(oct_info,gobj,"cinteger",GiNaC::info_flags::cinteger); add_info_field(oct_info,gobj,"relation",GiNaC::info_flags::relation); add_info_field(oct_info,gobj,"symbol",GiNaC::info_flags::symbol); add_info_field(oct_info,gobj,"list",GiNaC::info_flags::list); add_info_field(oct_info,gobj,"exprseq",GiNaC::info_flags::exprseq); add_info_field(oct_info,gobj,"polynomial",GiNaC::info_flags::polynomial); add_info_field(oct_info,gobj,"integer_polynomial",GiNaC::info_flags::integer_polynomial); add_info_field(oct_info,gobj,"cinteger_polynomial",GiNaC::info_flags::cinteger_polynomial); add_info_field(oct_info,gobj,"rational_polynomial",GiNaC::info_flags::rational_polynomial); add_info_field(oct_info,gobj,"crational_polynomial",GiNaC::info_flags::crational_polynomial); add_info_field(oct_info,gobj,"rational_function",GiNaC::info_flags::rational_function); add_info_field(oct_info,gobj,"algebraic",GiNaC::info_flags::algebraic); add_info_field(oct_info,gobj,"indexed",GiNaC::info_flags::indexed); add_info_field(oct_info,gobj,"has_indices",GiNaC::info_flags::has_indices); add_info_field(oct_info,gobj,"idx",GiNaC::info_flags::idx); } DEFUN_DLD(syminfo,args,nargout, "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{info} =} syminfo(@var{eqn})\n\ \n\ Returns information regarding the nature of symbolic expression @var{eqn} in\n\ a structure. Uses the @command{GiNaC::info()} function.\n\ @end deftypefn") { Octave_map oct_info; octave_value retval; int nargin = args.length(); if (nargin != 1) { error("Wrong number of arguments."); return retval = oct_info; } try { GiNaC::ex expression; if(!get_expression(args(0),expression)) { GiNaC::numeric num; if(get_numeric(args(0),num)) expression = GiNaC::ex(num); else { GiNaC::relational relation; if(get_relation(args(0),relation)) { expression = GiNaC::ex(relation); std::cout << expression << std::endl; } else { if(!get_symbol(args(0),expression)) { error("Expected a symbolic object as parameter."); return retval = oct_info; } } } } get_info(oct_info,expression); retval = oct_info; } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } symbolic/src/ov-relational.h0000644000175000017500000000467611647271140017433 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #if !defined (octave_relational_h) #define octave_relational_h 1 // GiNaC #include #include #include "ov-ex.h" // relational values. class octave_relational : public octave_base_value { public: octave_relational (void):octave_base_value() {} octave_relational (GiNaC::relational & orel) : octave_base_value () { rel = orel;} octave_relational (const GiNaC::ex & lhs, const GiNaC::ex & rhs, GiNaC::relational::operators op); octave_relational (const octave_ex & lhs, const octave_ex & rhs, GiNaC::relational::operators op); octave_relational (const octave_ex & lhs, const GiNaC::ex & rhs, GiNaC::relational::operators op); octave_relational (const GiNaC::ex & lhs, const octave_ex & rhs, GiNaC::relational::operators op); ~octave_relational (void) { } OV_REP_TYPE *clone (void) { return new octave_relational (*this); } dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } int rows (void) const { return 1; } int columns (void) const { return 1; } bool is_constant (void) const { return true; } bool is_defined (void) const { return true; } octave_value all (void) const { return (double) bool(rel); } octave_value any (void) const { return (double) bool(rel); } bool is_true (void) const { return bool(rel); } GiNaC::relational relational_value (bool = false) const { return rel; } void print (std::ostream& os, bool pr_as_read_syntax = false) const; private: GiNaC::relational rel; DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; #endif /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/symlsolve.cc0000644000175000017500000000571711647271140017047 0ustar carandraugcarandraug/* Copyright (C) 2003 Willem J. Atsma 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 2 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 . Based on differentiate.cc by Ben Sapp (2002) */ #include #include #include "ov-ex.h" #include "ov-relational.h" #include "symbols.h" DEFUN_DLD(symlsolve,args,nargout, "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{sols} =} symlsolve(@var{eqns},@var{vars})\n\ \n\ Apply the GiNaC @command{lsolve()} method to the given linear system of equations and\n\ variables. @var{eqns} and @var{vars} must be single symbolic expressions or\n\ lists/cell-arrays of these. The return value @var{sols} is a list of\n\ symbolic solutions corresponding in order to @var{vars}.\n\ @end deftypefn") { GiNaC::lst eqns, vars; GiNaC::relational relation; GiNaC::ex expression, sols; octave_value_list oct_sols; octave_value retval; int i, nargin = args.length(); if (nargin != 2) { error("Need 2 arguments."); return retval; } try { if(args(0).is_cell()) { octave_value_list oct_eqn_list(args(0).list_value()); for(i=0;i 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 2 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 . */ #include #include #include #include #include #include #include "sym-ops.h" #include "ov-relational.h" #include "ov-vpa.h" #include "ov-ex.h" #include "ov-ex-mat.h" /* definitions for when vpa is first */ DEFINE_EX_MATRIX_OPS(vpa, ex_matrix) DEFINE_EX_MATRIX_OPS(vpa, matrix) DEFINE_EX_MATRIX_OPS(vpa, complex_matrix) DEFINE_EX_EX_OPS(vpa, scalar) DEFINE_EX_EX_OPS(vpa, complex) DEFINE_EX_EX_OPS(vpa, vpa) DEFINE_EX_EX_OPS(vpa, ex) /* extra operators need for octave builtin types */ DEFINE_MATRIX_EX_OPS(complex_matrix, vpa) DEFINE_MATRIX_EX_OPS(matrix, vpa) DEFINE_EX_EX_OPS(scalar, vpa) DEFINE_EX_EX_OPS(complex, vpa) void install_vpa_ops() { // INSTALL_UNOP (op_not, octave_vpa, not); /* INSTALL_UNOP (op_uminus, octave_vpa, uminus); INSTALL_UNOP (op_transpose, octave_vpa, transpose); INSTALL_UNOP (op_hermitian, octave_vpa, hermitian); INSTALL_NCUNOP (op_incr, octave_vpa, incr); INSTALL_NCUNOP (op_decr, octave_vpa, decr); */ /* for when the vpa is first */ INSTALL_EX_MATRIX_OPS(vpa, ex_matrix); INSTALL_EX_MATRIX_OPS(vpa, matrix); INSTALL_EX_MATRIX_OPS(vpa, complex_matrix); INSTALL_EX_EX_OPS(vpa, scalar); INSTALL_EX_EX_OPS(vpa, complex); INSTALL_EX_EX_OPS(vpa, vpa); INSTALL_EX_EX_OPS(vpa, ex); /* extra operators need for octave builtin types */ INSTALL_MATRIX_EX_OPS(complex_matrix, vpa); INSTALL_MATRIX_EX_OPS(matrix, vpa); INSTALL_EX_EX_OPS(scalar, vpa); INSTALL_EX_EX_OPS(complex, vpa); /* INSTALL_BINOP (op_lt, octave_vpa, octave_vpa, lt); INSTALL_BINOP (op_le, octave_vpa, octave_vpa, le); INSTALL_BINOP (op_eq, octave_vpa, octave_vpa, eq); INSTALL_BINOP (op_ge, octave_vpa, octave_vpa, ge); INSTALL_BINOP (op_gt, octave_vpa, octave_vpa, gt); INSTALL_BINOP (op_ne, octave_vpa, octave_vpa, ne); */ } symbolic/src/ov-ex.cc0000644000175000017500000001007311647271140016037 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp Copyright (C) 2003 Willem Atsma 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 2 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 . */ // 2003-05-1 Willem Atsma // * Modified the constructors and the destructor and added a symbol list // and symbol reference count. New members are: // void assign_symbol_to_list(GiNaC::symbol &sym); // class symbol_list_item; // static std::vector symbol_list; // This is a work-around for the fact that GiNaC can have different symbols // with the same string name, while in octave you want a symbol that // appears the same to actually be the same. It works great as long as // symbols are declared in octave. It is still possible to have same-name // symbols that are different to GiNaC, if a symbol goes out of scope in // octave without it being defined in octave's workspace. This could be fixed // by also keeping reference counts for symbols in expressions. #include #include #include "ov-ex.h" #include "ov-vpa.h" std::vector octave_ex::symbol_list; // A list of symbols is maintained to ensure all symbols that look the // same in octave are in fact the same to GiNaC. The destructor removes // items if the reference count goes to zero. void octave_ex::assign_symbol_to_list(GiNaC::symbol &sym) { unsigned int i; std::string name = sym.get_name(); // check if new symbol already exists for(i=0;i(ox.x)) { GiNaC::symbol sym = GiNaC::ex_to(ox.x); assign_symbol_to_list(sym); x = sym; } else x = ox.x; } octave_ex::octave_ex(GiNaC::ex expression) { if(GiNaC::is_a(expression)) { GiNaC::symbol sym = GiNaC::ex_to(expression); assign_symbol_to_list(sym); x = sym; } else x = expression; } octave_ex::octave_ex(GiNaC::symbol sym) { assign_symbol_to_list(sym); x = sym; } octave_ex::octave_ex(octave_complex &cmplx) { Complex z = cmplx.complex_value (); x = z.real () + GiNaC::I*z.imag (); } octave_ex::octave_ex(Complex z) { x = z.real () + GiNaC::I*z.imag (); } octave_ex::octave_ex(octave_scalar &s) { double d = s.double_value (); x = d; } octave_ex::octave_ex(double d) { x = d; } // If this is a symbol, remove list entry if it exists. octave_ex::~octave_ex() { if((GiNaC::is_a(x)) && (!symbol_list.empty())) { GiNaC::symbol sym = GiNaC::ex_to(x); std::vector::iterator iter_symlist; for(iter_symlist=symbol_list.begin();iter_symlistsym)) { iter_symlist->refcount --; if(iter_symlist->refcount==0) { iter_symlist = symbol_list.erase(iter_symlist); continue; } } iter_symlist++; } } } void octave_ex::print(std::ostream& os,bool pr_as_read_syntax) const { os << x; } octave_ex& octave_ex::operator=(const octave_ex& a) { return (*(new octave_ex(a.x))); } DEFINE_OCTAVE_ALLOCATOR (octave_ex); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_ex, "ex", "sym"); /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/autogen.sh0000755000175000017500000000133510747712404016477 0ustar carandraugcarandraug#! /bin/sh ## Generate ./configure rm -f configure.in echo "dnl --- DO NOT EDIT --- Automatically generated by autogen.sh" > configure.in cat configure.base >> configure.in cat <> configure.in AC_OUTPUT(\$CONFIGURE_OUTPUTS) dnl XXX FIXME XXX chmod is not in autoconf's list of portable functions echo " " echo " \"\\\$prefix\" is \$prefix" echo " \"\\\$exec_prefix\" is \$exec_prefix" AC_MSG_RESULT([\$STATUS_MSG find . -name NOINSTALL -print # shows which toolboxes won't be installed ]) EOF aclocal && autoconf configure.in > configure.tmp if [ diff configure.tmp configure > /dev/null 2>&1 ]; then rm -f configure.tmp; else mv -f configure.tmp configure chmod 0755 configure fi rm -f configure.in symbolic/src/findsymbols.cc0000644000175000017500000000555611647271140017344 0ustar carandraugcarandraug/* Copyright (C) 2003 Willem J. Atsma 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 2 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 . */ #include #include #include #include "ov-vpa.h" #include "ov-ex.h" #include "symbols.h" /* Travel down the hierarchical expression and insert new symbols in the list so the endresult is sorted. */ static void append_symbols(octave_value_list& symlist,const GiNaC::ex& expression) { int i, j, n = expression.nops(); for(i=0;i(expression.op(i))) { bool unique = true; int insert_here = symlist.length(); GiNaC::ex ex_sym; GiNaC::symbol sym, sym_new = GiNaC::ex_to(expression.op(i)); std::string sym_name,sym_name_new = sym_new.get_name(); for(j=0;j(ex_sym); if(GiNaC::operator == (sym,sym_new)) { unique = false; break; } else { if(sym.get_name()>sym_name_new) { insert_here = j; break; } } } if(unique) { octave_value_list tmp = symlist; symlist.resize(symlist.length()+1); symlist(insert_here) = octave_value(new octave_ex(expression.op(i))); for(j=insert_here;j 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 2 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 . */ #include #include #include #include #include #include #include "sym-ops.h" #include "ov-vpa.h" #include "ov-ex.h" #include "ov-ex-mat.h" /* definitions for when ex_matrix is first */ DEFINE_MATRIX_MATRIX_OPS(ex_matrix, ex_matrix) DEFINE_MATRIX_MATRIX_OPS(ex_matrix, matrix) DEFINE_MATRIX_MATRIX_OPS(ex_matrix, complex_matrix) DEFINE_MATRIX_EX_OPS(ex_matrix, scalar) DEFINE_MATRIX_EX_OPS(ex_matrix, complex) DEFINE_MATRIX_EX_OPS(ex_matrix, vpa) DEFINE_MATRIX_EX_OPS(ex_matrix, ex) /* extra operators need for octave builtin types */ DEFINE_MATRIX_MATRIX_OPS(complex_matrix, ex_matrix) DEFINE_MATRIX_MATRIX_OPS(matrix, ex_matrix) DEFINE_EX_MATRIX_OPS(complex, ex_matrix) DEFINE_EX_MATRIX_OPS(scalar, ex_matrix) void install_ex_matrix_ops() { INSTALL_MATRIX_MATRIX_OPS(ex_matrix, ex_matrix); INSTALL_MATRIX_MATRIX_OPS(ex_matrix, matrix); INSTALL_MATRIX_MATRIX_OPS(ex_matrix, complex_matrix); INSTALL_MATRIX_EX_OPS(ex_matrix, scalar); INSTALL_MATRIX_EX_OPS(ex_matrix, complex); INSTALL_MATRIX_EX_OPS(ex_matrix, vpa); INSTALL_MATRIX_EX_OPS(ex_matrix, ex); /* extra operators need for octave builtin types */ INSTALL_MATRIX_MATRIX_OPS(complex_matrix, ex_matrix); INSTALL_MATRIX_MATRIX_OPS(matrix, ex_matrix); INSTALL_EX_MATRIX_OPS(complex, ex_matrix); INSTALL_EX_MATRIX_OPS(scalar, ex_matrix); #if 0 INSTALL_UNOP(op_uminus, octave_ex, uminus); // -x INSTALL_NCUNOP(op_incr, octave_ex, incr); // x++ INSTALL_NCUNOP(op_decr, octave_ex, decr); // x-- #endif } symbolic/src/Makefile0000644000175000017500000000163611014631227016131 0ustar carandraugcarandraug sinclude Makeconf # assumptions to make if not using ./configure script ifndef OCTAVE_FORGE MKOCTFILE=mkoctfile HAVE_GINAC=1 endif #SRC=symbols.cc probably_prime.cc differentiate.cc \ # sym-bool.cc sym-create.cc \ # ov-ex.cc ov-sym.cc ov-vpa.cc ov-ex-mat.cc ov-relational.cc \ # op-ex-mat.cc op-ex.cc op-sym.cc op-vpa.cc SRC=symbols.cc probably_prime.cc differentiate.cc \ findsymbols.cc numden.cc syminfo.cc symlsolve.cc sumterms.cc\ sym-bool.cc sym-create.cc \ ov-ex.cc ov-vpa.cc ov-ex-mat.cc ov-relational.cc \ op-ex-mat.cc op-ex.cc op-vpa.cc OBJ=$(SRC:.cc=.o) %.o: %.cc ; $(MKOCTFILE) -v $(GINAC_CFLAGS) $(HAVE_ND_ARRAYS) $(TYPEID_HAS_CLASS) -c $< ifdef HAVE_GINAC PROGS=symbols.oct all: $(PROGS) else all: @echo "Ginac library or headers not found" false endif $(PROGS): Makefile symbols.oct: $(OBJ) $(MKOCTFILE) -v -o $@ $(OBJ) `pkg-config --libs ginac` clean: ; $(RM) *.o core octave-core *.oct *~ symbolic/src/sym-create.cc0000644000175000017500000000717611647271140017064 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #include #include #include #include #include #include "ov-vpa.h" #include "ov-ex.h" #include "ov-ex-mat.h" #include "symbols.h" DEFUN_DLD (vpa, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{n} =} vpa(@var{s})\n\ \n\ Creates a variable precision arithmetic variable from @var{s}.\n\ @var{s} can be a scalar, vpa value, string or a ex value that \n\ is a number.\n\ @end deftypefn\n\ ") { mlock (); octave_value retval; GiNaC::numeric d; int nargin = args.length(); try { if (nargin == 1) { if (!get_numeric (args(0), d)) { gripe_wrong_type_arg ("vpa", args(0)); return retval; } } else { print_usage (); return retval; } retval = octave_value(new octave_vpa(d)); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } DEFUN_DLD (sym,args, , "-*- texinfo -*-\n\ Create an object of type symbol\n") { mlock (); octave_value retval; int nargin = args.length (); if (nargin != 1) { error("one argument expected\n"); return octave_value (); } try { GiNaC::symbol xtmp(args(0).string_value()); octave_ex x(xtmp); retval = octave_value(new octave_ex(x)); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } // an ex DLD function might be nice DEFUN_DLD (ex_matrix, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{n} =} ex_matrix(@var{rows}, @var{cols}, @dots{})\n\ \n\ Creates a variable precision arithmetic variable from @var{s}.\n\ @var{s} can be a scalar, vpa value, string or a ex value that \n\ is a number.\n\ @end deftypefn\n\ ") { mlock (); octave_value retval; GiNaC::ex expression; int nargin = args.length(); int rows, cols,k; if (nargin < 2) { print_usage (); return retval; } if(args(0).is_real_scalar()) { rows = int(args(0).double_value()); } else { error("You must supply a scalar for the first argument."); return retval; } if(args(1).is_real_scalar()) { cols = int(args(1).double_value()); } else { error("You must supply a scalar for the first argument."); return retval; } try { GiNaC::matrix a = GiNaC::matrix(rows,cols); k = 2; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++, k++) { if (k < nargin) { if (!get_expression(args(k),expression)) { error("unable to turn an argument into a symbolic expression"); return retval; } a(i,j) = expression; } else break; } } retval = octave_value(new octave_ex_matrix(a)); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } symbolic/src/probably_prime.cc0000644000175000017500000000264411647530163020017 0ustar carandraugcarandraug// Copyright (C) 2001 Paul Kienzle // // 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 2 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 . #include #include #include "symbols.h" DEFUN_DLD(probably_prime, args, , "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{r} =} is_prime(@var{x})\n\ Return true if the variable precision number is probably prime,\n\ with error 1 in 2^100.\n\ @end deftypefn\n\ ") { int nargin = args.length (); octave_value_list retval; GiNaC::numeric value; if (nargin != 1) { print_usage (); return retval; } try { if(!get_numeric(args(0), value)) { print_usage (); return retval; } retval(0) = GiNaC::is_prime(value); } catch (std::exception &e) { error (e.what ()); return retval; } return retval; } symbolic/src/differentiate.cc0000644000175000017500000000423611647271140017616 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #include #include #include #include #include "ov-vpa.h" #include "ov-ex.h" #include "symbols.h" DEFUN_DLD(differentiate,args,, "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{da_dx} =} differentiate(@var{a},@var{x} [, @var{n}])\n\ \n\ Return the @var{n}th derivative of @var{a} with respect to @var{x}. If @var{n} is not\n\ supplied then a default value of 1 is used.\n\ @end deftypefn") { GiNaC::ex expression; GiNaC::ex variable; GiNaC::numeric num; int order; octave_value retval; int nargin = args.length(); if ((nargin < 2) || (nargin > 3)) { print_usage (); return retval; } try { if (!get_expression (args(0), expression)) { print_usage (); return retval; } if (!get_symbol (args(1), variable)) { print_usage (); return retval; } if (nargin == 3) { if (!get_numeric (args(2), num)) { print_usage (); return retval; } order = int(num.to_double ()); if (order < 0) { error("must supply an integer greater than zero\n"); return retval; } } else order = 1; retval = octave_value(new octave_ex (expression.diff (GiNaC::ex_to(variable),order))); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } symbolic/src/symbols.cc0000644000175000017500000003311611647271140016474 0ustar carandraugcarandraug/* Copyright (C) 2001 Paul Kienzle Copyright (C) 2002 Ben Sapp Copyright (C) 2003 Willem Atsma Copyright (C) 2008 Nils Bluethgen 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 2 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 . */ // 2001-09-18 Paul Kienzle // * use GiNaC::is_a(x) rather than is_ex_of_type(x, blah) // * use GiNaC::ex_to(x) rather than ex_to_blah(x) // 2003-04-19 Willem Atsma // * added get_relational() // 2008-03-09 Nils Bluethgen // * added get_char() and to_char() #include #include #include #include #include #include #include #include #include #include "ov-vpa.h" #include "ov-ex.h" #include "ov-ex-mat.h" #include "ov-relational.h" #include "sym-ops.h" #include "symbols.h" #include #include bool get_expression(const octave_value arg, GiNaC::ex& expression) { const OV_REP_TYPE& rep = (arg).get_rep(); if (arg.type_id () == octave_vpa::static_type_id ()) { GiNaC::numeric x = ((octave_vpa& ) rep).vpa_value(); expression = x+0; } else if (arg.type_id () == octave_ex::static_type_id ()) { GiNaC::ex x = ((octave_ex& ) rep).ex_value(); expression = x; } else if (arg.is_real_scalar ()) { GiNaC::numeric x(arg.double_value ()); expression = x+0; } else { return false; } return true; } bool get_char(const octave_value arg, std::string& str) { GiNaC::ex ex; if (!get_expression(arg, ex)) return false; std::stringstream strstr; strstr << GiNaC::dflt << ex; str = strstr.str(); return true; } bool get_symbol(const octave_value arg, GiNaC::ex& sym) { const OV_REP_TYPE& rep = arg.get_rep (); GiNaC::ex x; if (arg.type_id () == octave_ex::static_type_id ()) x = ((octave_ex& ) rep).ex_value(); else return false; if (GiNaC::is_a(x)) sym = x; else return false; return true; } bool get_numeric(const octave_value arg, GiNaC::numeric& number) { const OV_REP_TYPE& rep = arg.get_rep (); if (arg.type_id () == octave_ex::static_type_id ()) { GiNaC::ex x = ((octave_ex& ) rep).ex_value(); if(GiNaC::is_a(x)) number = GiNaC::ex_to(x); else return false; } else if (arg.type_id () == octave_vpa::static_type_id ()) number = ((const octave_vpa &) rep).vpa_value (); else if (arg.is_real_scalar ()) number = GiNaC::numeric (arg.double_value ()); else if (arg.is_string ()) number = GiNaC::numeric (arg.string_value ().c_str ()); else return false; return true; } bool get_relation(const octave_value arg, GiNaC::relational& relation) { const OV_REP_TYPE& rep = arg.get_rep(); if (arg.type_id () == octave_relational::static_type_id ()) { GiNaC::relational x = ((octave_relational& ) rep).relational_value(); relation = x; } else return false; return true; } static bool symbolic_type_loaded = false; void load_symbolic_type (void) { if (! symbolic_type_loaded) { octave_vpa::register_type (); octave_ex::register_type (); octave_ex_matrix::register_type (); octave_relational::register_type (); install_ex_matrix_ops(); install_ex_ops(); install_vpa_ops(); symbolic_type_loaded = true; } } DEFUN_DLD(symbols,args,,"Initialize symbolic manipulation") { octave_value retval; load_symbolic_type (); return retval; } DEFUN_DLD(to_char,args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{d} =} to_char(@var{n})\n\ \n\ Convert a vpa, string, ex type to a string.\n\ \n\ @end deftypefn\n\ ") { octave_value retval; int nargin = args.length(); std::string str; if (nargin != 1) { print_usage (); return retval; } try { if (!get_char (args(0), str)) { print_usage (); return retval; } retval = octave_value(str); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } DEFUN_DLD(to_double,args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{d} =} to_double(@var{n})\n\ \n\ Convert a vpa, string, ex or string type to a double.\n\ \n\ @end deftypefn\n\ ") { octave_value retval; int nargin = args.length(); GiNaC::numeric num; if (nargin != 1) { print_usage (); return retval; } try { if (!get_numeric (args(0), num)) { print_usage (); return retval; } retval = octave_value(num.to_double ()); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } DEFUN_DLD(digits, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{dgts} =} digits([@var{num}])\n\ Change the precision for the vpa type\n\ @end deftypefn\n\ ") { octave_value retval; int nargin = args.length(); if ((nargin != 1) && (nargin != 0)) { error("you must supply 0 or 1 arguments\n"); return(retval); } try { if(nargin == 1) { if(args(0).is_real_scalar()) { GiNaC::Digits = int(args(0).double_value()); } else { print_usage (); } } double dig = double(GiNaC::Digits); retval = octave_value(dig); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return(retval); } DEFUN_DLD(Pi,args, , "-*- texinfo -*-\n\ Pi evaluated to the current value of Digits\n\ \n\ @seealso{digits}") { octave_value retval; try { retval = octave_value(new octave_vpa(GiNaC::ex_to(GiNaC::Pi.evalf()))); } catch (std::exception &e) { error (e.what ()); retval = octave_value (); } return retval; } DEFUN_DLD_EX_GINAC_FUNCTION(Sqrt,sqrt,"square root"); DEFUN_DLD_EX_GINAC_FUNCTION(Cos,cos,"cosine"); DEFUN_DLD_EX_GINAC_FUNCTION(Sin,sin,"sine"); DEFUN_DLD_EX_GINAC_FUNCTION(Tan,tan,"tangent"); DEFUN_DLD_EX_GINAC_FUNCTION(aCos,acos,"inverse cosine"); DEFUN_DLD_EX_GINAC_FUNCTION(aSin,asin,"inverse sine"); DEFUN_DLD_EX_GINAC_FUNCTION(aTan,atan,"inverse tangent"); DEFUN_DLD_EX_GINAC_FUNCTION(Cosh,cosh,"hyperbolic cosine"); DEFUN_DLD_EX_GINAC_FUNCTION(Sinh,sinh,"hyperbolic sine"); DEFUN_DLD_EX_GINAC_FUNCTION(Tanh,tanh,"hyperbolic tangent"); DEFUN_DLD_EX_GINAC_FUNCTION(aCosh,acosh,"inverse hyperbolic cosine"); DEFUN_DLD_EX_GINAC_FUNCTION(aSinh,asinh,"inverse hyperbolic sine"); DEFUN_DLD_EX_GINAC_FUNCTION(aTanh,atanh,"inverse hyperbolic tangent"); DEFUN_DLD_EX_GINAC_FUNCTION(Exp,exp,"exponential"); DEFUN_DLD_EX_GINAC_FUNCTION(Log,log,"logarithm"); DEFUN_DLD_EX_GINAC_FUNCTION(Abs,abs,"absolute value"); DEFUN_DLD_EX_SYM_GINAC_FUNCTION(degree, degree,"degree"); DEFUN_DLD_EX_SYM_GINAC_FUNCTION(ldegree, ldegree,"low degree"); DEFUN_DLD_EX_SYM_GINAC_FUNCTION(tcoeff, tcoeff, "trailing coeffiecient"); DEFUN_DLD_EX_SYM_GINAC_FUNCTION(lcoeff, lcoeff, "leading coefficient"); DEFUN_DLD_EX_EX_SYM_GINAC_FUNCTION(quotient,quo,"quotient"); DEFUN_DLD_EX_EX_SYM_GINAC_FUNCTION(remainder,rem,"remainder"); DEFUN_DLD_EX_EX_SYM_GINAC_FUNCTION(premainder,prem,"pseudo-remainder"); DEFUN_DLD(subs,args,, "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{b} =} subs(@var{a},@var{x},@var{n})\n\ \n\ Substitute variables in an expression.\n\ @table @var\n\ @item a\n\ The expresion in which the substition will occur.\n\ @item x\n\ The variables that will be substituted.\n\ @item n\n\ The expressions, vpa values or scalars that will replace @var{x}.\n\ @end table\n\ \n\ Multiple substitutions can be made by using lists or cell-arrays for\n\ @var{x} and @var{n}.\n\ \n\ Examples:\n\ @example\n\ symbols\n\ x=sym(\"x\"); y=sym(\"y\"); f=x^2+3*x*y-y^2;\n\ v = subs (f,x,1)\n\ w = subs (f,@{x,y@},@{1,vpa(1/3)@})\n\ @end example\n\ \n\ @end deftypefn\n\ ") { GiNaC::ex expression; GiNaC::ex the_sym; GiNaC::ex ex_sub; GiNaC::ex tmp; int nargin = args.length (); octave_value retval; if (nargin != 3) { error("need three arguments\n"); return retval; } try { if (!get_expression (args(0), expression)) { gripe_wrong_type_arg ("subs",args(0)); return retval; } //if (!(args(1).is_list() || args(1).is_cell())) { if (!(args(1).is_cell())) { if (!get_symbol (args(1), the_sym)) { gripe_wrong_type_arg("subs",args(1)); return retval; } if (!get_expression (args(2), ex_sub)) { gripe_wrong_type_arg ("subs",args(2)); return retval; } tmp = expression.subs(the_sym == ex_sub); } else { octave_value_list symlist, sublist; int i; symlist = args(1).list_value(); sublist = args(2).list_value(); if(symlist.length()!=sublist.length()) { error("Number of expressions and substitutes must be the same."); return retval; } tmp = expression; for(i=0;i(the_sym))); return retval; } symbolic/src/ov-ex-mat.cc0000644000175000017500000000472011647271140016620 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #include #include #include #include #include #include #include "ov-ex.h" #include "ov-ex-mat.h" #include "ov-vpa.h" octave_ex_matrix::octave_ex_matrix(octave_ex_matrix &ox) { x = ox.x; } octave_ex_matrix::octave_ex_matrix(octave_ex &ox) { x = GiNaC::matrix(1,1); x(0,0) = ox.ex_value (); } octave_ex_matrix::octave_ex_matrix(GiNaC::symbol sym) { x = GiNaC::matrix(1,1); x(0,0) = GiNaC::ex(sym); } octave_ex_matrix::octave_ex_matrix(GiNaC::matrix ex_mat) { x = ex_mat; } octave_ex_matrix::octave_ex_matrix(GiNaC::ex expression) { x = GiNaC::matrix(1,1); x(0,0) = expression; } octave_ex_matrix::octave_ex_matrix(int rows, int columns) { x = GiNaC::matrix(rows,columns); } octave_ex_matrix::octave_ex_matrix(octave_matrix ov) { Matrix mat = ov.matrix_value (); int rows = mat.rows (); int cols = mat.cols (); x = GiNaC::matrix(rows, cols); for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) x(i,j) = GiNaC::ex(mat(i,j)); } octave_ex_matrix::octave_ex_matrix(octave_complex_matrix ov) { ComplexMatrix mat = ov.complex_matrix_value (); int rows = mat.rows (); int cols = mat.cols (); x = GiNaC::matrix(rows, cols); for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) x(i,j) = GiNaC::ex(mat(i,j).real ()) + GiNaC::I*GiNaC::ex(mat(i,j).imag ()); } void octave_ex_matrix::print(std::ostream& os,bool pr_as_read_syntax) const { os << x; } octave_ex_matrix& octave_ex_matrix::operator=(const octave_ex_matrix& a) { return (*(new octave_ex_matrix(a.x))); } DEFINE_OCTAVE_ALLOCATOR (octave_ex_matrix); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_ex_matrix, "symbolic matrix","sym"); symbolic/src/ov-relational.cc0000644000175000017500000000416611647271140017563 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #include #include "ov-relational.h" octave_relational::octave_relational (const GiNaC::ex & lhs, const GiNaC::ex & rhs, GiNaC::relational::operators op=GiNaC::relational::equal) { rel = GiNaC::relational(lhs, rhs, op); } octave_relational::octave_relational (const octave_ex & lhs, const octave_ex & rhs, GiNaC::relational::operators op=GiNaC::relational::equal) { rel = GiNaC::relational(lhs.ex_value (), rhs.ex_value (), op); } octave_relational::octave_relational (const octave_ex & lhs, const GiNaC::ex & rhs, GiNaC::relational::operators op=GiNaC::relational::equal) { rel = GiNaC::relational(lhs.ex_value (), rhs, op); } octave_relational::octave_relational (const GiNaC::ex & lhs, const octave_ex & rhs, GiNaC::relational::operators op=GiNaC::relational::equal) { rel = GiNaC::relational(lhs, rhs.ex_value (), op); } void octave_relational::print (std::ostream& os, bool pr_as_read_syntax) const { GiNaC::print_context pr(os); rel.print(pr); } DEFINE_OCTAVE_ALLOCATOR (octave_relational); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_relational, "relational", "sym"); /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/ov-vpa.cc0000644000175000017500000000267611647271140016223 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #include #include "ov-vpa.h" // class ostream; octave_vpa::octave_vpa(void):octave_base_value() { scalar = GiNaC::numeric(0); } octave_vpa::octave_vpa (int i):octave_base_value() { scalar = GiNaC::numeric(0); } octave_vpa::octave_vpa (const octave_vpa& s):octave_base_value() { scalar = s.scalar; } octave_vpa::octave_vpa (const GiNaC::numeric& s):octave_base_value() { scalar = s; } octave_vpa::octave_vpa( const GiNaC::ex& x):octave_base_value() { scalar = GiNaC::ex_to(x); } void octave_vpa::print (std::ostream& os, bool pr_as_read_syntax) const { os << scalar; } DEFINE_OCTAVE_ALLOCATOR (octave_vpa); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_vpa, "vpa", "sym"); /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/ov-ex-mat.h0000644000175000017500000000436011647271140016462 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #if !defined (octave_ex_matrix_h) #define octave_ex_matrix_h 1 #include class octave_matrix; class octave_complex_matrix; class octave_ex_matrix : public octave_base_value { public: octave_ex_matrix(void):octave_base_value() {} octave_ex_matrix(octave_ex_matrix &ox); octave_ex_matrix(octave_ex &ox); octave_ex_matrix(GiNaC::symbol sym); octave_ex_matrix(GiNaC::matrix ex_mat); octave_ex_matrix(GiNaC::ex expression); octave_ex_matrix(int rows, int columns); octave_ex_matrix(octave_matrix ov); octave_ex_matrix(octave_complex_matrix ov); ~octave_ex_matrix() {} octave_ex_matrix& operator=(const octave_ex_matrix&); GiNaC::matrix ex_matrix_value(bool = false) const { return x; } GiNaC::ex ex_value(bool = false) const { return GiNaC::ex(x); } OV_REP_TYPE *clone (void) { return new octave_ex_matrix (*this); } dim_vector dims (void) const {dim_vector dv (x.rows(), x.cols()); return dv; } int rows (void) const { return x.rows (); } int columns (void) const { return x.cols (); } bool is_constant (void) const { return true; } bool is_defined (void) const { return true; } bool valid_as_scalar_index(void) const {return false;} bool is_true(void) const { return true; } octave_value uminus (void) const { return new octave_ex_matrix(-x); } void print(std::ostream& os,bool pr_as_read_syntax) const; private: GiNaC::matrix x; DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; #endif /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/src/sym-bool.cc0000644000175000017500000000375711647271140016555 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #include #include #include #include "ov-vpa.h" #include "ov-ex.h" #include "ov-ex-mat.h" DEFUN_DLD(is_vpa, args, , "Return true if an object is of type vpa, false otherwise.\n") { bool retval; retval = (args(0).type_id() == octave_vpa::static_type_id()); return octave_value(retval); } DEFUN_DLD(is_sym,args, ,"Return true if an object is of type sym false otherwise.\n") { bool retval; const OV_REP_TYPE& rep = args(0).get_rep(); retval = args(0).type_id () == octave_ex::static_type_id () && GiNaC::is_a(((octave_ex& ) rep).ex_value ()); return octave_value(retval); } DEFUN_DLD(is_ex,args,, "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{bool} =} is_ex(@var{a})\n\ \n\ Return true if an object is a symbolic expression.\n\ @seealso{is_vpa, is_sym, is_ex_matrix}\n\ @end deftypefn") { bool retval; retval = (args(0).type_id() == octave_ex::static_type_id()); return octave_value(retval); } DEFUN_DLD(is_ex_matrix,args,, "-*- texinfo -*-\n\ @deftypefn Loadable Function {@var{bool} =} is_ex_matrix(@var{a})\n\ \n\ Return true if an object is a symbolic matrix.\n\ @seealso{is_vpa, is_sym, is_ex}\n\ @end deftypefn") { bool retval; retval = (args(0).type_id() == octave_ex_matrix::static_type_id()); return octave_value(retval); } symbolic/src/op-ex.cc0000644000175000017500000000406611647271140016036 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #include #include #include #include #include #include #include "sym-ops.h" #include "ov-relational.h" #include "ov-vpa.h" #include "ov-ex.h" #include "ov-ex-mat.h" /* definitions for when ex is first */ DEFINE_EX_MATRIX_OPS(ex, ex_matrix) DEFINE_EX_MATRIX_OPS(ex, matrix) DEFINE_EX_MATRIX_OPS(ex, complex_matrix) DEFINE_EX_EX_OPS(ex, scalar) DEFINE_EX_EX_OPS(ex, complex) DEFINE_EX_EX_OPS(ex, vpa) DEFINE_EX_EX_OPS(ex, ex) /* extra operators need for octave builtin types */ DEFINE_MATRIX_EX_OPS(complex_matrix, ex) DEFINE_MATRIX_EX_OPS(matrix, ex) DEFINE_EX_EX_OPS(scalar, ex) DEFINE_EX_EX_OPS(complex, ex) void install_ex_ops() { INSTALL_EX_MATRIX_OPS(ex, ex_matrix); INSTALL_EX_MATRIX_OPS(ex, matrix); INSTALL_EX_MATRIX_OPS(ex, complex_matrix); INSTALL_EX_EX_OPS(ex, scalar); INSTALL_EX_EX_OPS(ex, complex); INSTALL_EX_EX_OPS(ex, vpa); INSTALL_EX_EX_OPS(ex, ex); /* extra operators need for octave builtin types */ INSTALL_MATRIX_EX_OPS(complex_matrix, ex); INSTALL_MATRIX_EX_OPS(matrix, ex); INSTALL_EX_EX_OPS(scalar, ex); INSTALL_EX_EX_OPS(complex, ex); #if 0 INSTALL_UNOP(op_uminus, octave_ex, uminus); // -x INSTALL_NCUNOP(op_incr, octave_ex, incr); // x++ INSTALL_NCUNOP(op_decr, octave_ex, decr); // x-- #endif } symbolic/src/Makeconf.in0000644000175000017500000000016111014631227016534 0ustar carandraugcarandraugMKOCTFILE = mkoctfile LIBS = -lginac -lcln %.o: %.cc ; $(MKOCTFILE) -c $< %.oct: %.cc ; $(MKOCTFILE) $(LIBS) $< symbolic/src/sym-ops.h0000644000175000017500000002635111647271140016260 0ustar carandraugcarandraug/* Copyright (C) 2002 Ben Sapp 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 2 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 . */ #if !defined (sym_ops_h) #define sym_ops_h 1 #include #include /* This file defines macros used in the op-X.cc files to define functions */ void install_ex_ops(void); void install_vpa_ops(void); void install_ex_matrix_ops(void); #define DEFBINOP_MATRIX_MATRIX_OP(name, t1, t2, op) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::matrix r1 = octave_ex_matrix(v1.t1 ## _value ()).ex_matrix_value (); \ GiNaC::matrix r2 = octave_ex_matrix(v2.t2 ## _value ()).ex_matrix_value (); \ if ( (r1.rows () != r2.rows ()) || (r1.cols () != r2.cols ()) ) \ { \ error("nonconformant arguments\n"); \ return octave_value (); \ } \ return octave_value \ (new octave_ex_matrix (r1.op (r2))); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFBINOP_MATRIX_MATRIX_DIV(name, t1, t2) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::matrix r1 = octave_ex_matrix(v1.t1 ## _value ()).ex_matrix_value (); \ GiNaC::matrix r2 = octave_ex_matrix(v2.t2 ## _value ()).ex_matrix_value (); \ if ( (r1.rows () != r2.rows ()) || (r1.cols () != r2.cols ()) ) \ { \ error("nonconformant arguments\n"); \ return octave_value (); \ } \ return octave_value \ (new octave_ex_matrix (r2.transpose ().inverse ().mul (r1).transpose ())); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFBINOP_EX_MATRIX_OP(name, t1, t2, op) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::matrix r1 = octave_ex_matrix(v2.t2 ## _value ()).ex_matrix_value (); \ GiNaC::ex r2 = octave_ex(v1.t1 ## _value ()).ex_value (); \ int rows = int(r1.rows ()); \ int cols = int(r1.cols ()); \ GiNaC::matrix result(rows, cols); \ for (int i = 0; i < rows; i++) \ for (int j = 0; j < cols; j++) \ result(i,j) = r1(i,j) op r2; \ return octave_value \ (new octave_ex_matrix (result)); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFBINOP_MATRIX_EX_OP(name, t1, t2, op) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::matrix r1 = octave_ex_matrix(v1.t1 ## _value ()).ex_matrix_value (); \ GiNaC::ex r2 = octave_ex(v2.t2 ## _value ()).ex_value (); \ int rows = int(r1.rows ()); \ int cols = int(r1.cols ()); \ GiNaC::matrix result(rows, cols); \ for (int i = 0; i < rows; i++) \ for (int j = 0; j < cols; j++) \ result(i,j) = r1(i,j) op r2; \ return octave_value \ (new octave_ex_matrix (result)); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFBINOP_MATRIX_EX_POW(name, t1, t2) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::matrix r1 = octave_ex_matrix(v1.t1 ## _value ()).ex_matrix_value (); \ GiNaC::ex r2 = octave_ex(v2.t2 ## _value ()).ex_value (); \ int rows = int(r1.rows ()); \ int cols = int(r1.cols ()); \ GiNaC::matrix result(rows, cols); \ for (int i = 0; i < rows; i++) \ for (int j = 0; j < cols; j++) \ result(i,j) = GiNaC::pow(r1(i,j), r2); \ return octave_value \ (new octave_ex_matrix (result)); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFBINOP_EX_EX_OP(name, t1, t2, op) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::ex r1 = octave_ex(v1.t1 ## _value ()).ex_value (); \ GiNaC::ex r2 = octave_ex(v2.t2 ## _value ()).ex_value (); \ GiNaC::ex result = r1 op r2; \ return octave_value \ (new octave_ex (result)); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFBINOP_EX_EX_POW(name, t1, t2) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::ex r1 = octave_ex(v1.t1 ## _value ()).ex_value (); \ GiNaC::ex r2 = octave_ex(v2.t2 ## _value ()).ex_value (); \ GiNaC::ex result = pow(r1,r2); \ return octave_value \ (new octave_ex (result)); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFBINOP_EX_EX_BOOL_OP(name, t1, t2, op) \ BINOPDECL (name, a1, a2) \ { \ try \ { \ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ GiNaC::ex r1 = octave_ex(v1.t1 ## _value ()).ex_value (); \ GiNaC::ex r2 = octave_ex(v2.t2 ## _value ()).ex_value (); \ if (GiNaC::is_exactly_a(r1) && \ GiNaC::is_exactly_a(r2)) \ { \ bool tmp_bool = GiNaC::relational(r1, r2, op); \ return octave_value(tmp_bool); \ } \ return octave_value \ (new octave_relational (r1, r2, op)); \ } \ catch (std::exception &e) \ { \ error (e.what ()); \ return octave_value (); \ } \ } #define DEFINE_MATRIX_EX_OPS(TYPE1, TYPE2) \ DEFBINOP_MATRIX_EX_OP (TYPE1 ## _ ## TYPE2 ## _add, TYPE1, TYPE2, +) \ DEFBINOP_MATRIX_EX_OP (TYPE1 ## _ ## TYPE2 ## _sub, TYPE1, TYPE2, -) \ DEFBINOP_MATRIX_EX_OP (TYPE1 ## _ ## TYPE2 ## _mul, TYPE1, TYPE2, *) \ DEFBINOP_MATRIX_EX_OP (TYPE1 ## _ ## TYPE2 ## _div, TYPE1, TYPE2, /) \ DEFBINOP_MATRIX_EX_POW (TYPE1 ## _ ## TYPE2 ## _pow, TYPE1, TYPE2) #define INSTALL_MATRIX_EX_OPS(TYPE1, TYPE2) \ INSTALL_BINOP(op_add, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _add) \ INSTALL_BINOP(op_sub, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _sub) \ INSTALL_BINOP(op_mul, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _mul) \ INSTALL_BINOP(op_div, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _div) \ INSTALL_BINOP(op_pow, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _pow) #define DEFINE_EX_MATRIX_OPS(TYPE1, TYPE2) \ DEFBINOP_EX_MATRIX_OP (TYPE1 ## _ ## TYPE2 ## _add, TYPE1, TYPE2, +) \ DEFBINOP_EX_MATRIX_OP (TYPE1 ## _ ## TYPE2 ## _sub, TYPE1, TYPE2, -) \ DEFBINOP_EX_MATRIX_OP (TYPE1 ## _ ## TYPE2 ## _mul, TYPE1, TYPE2, *) \ DEFBINOP_EX_MATRIX_OP (TYPE1 ## _ ## TYPE2 ## _div, TYPE1, TYPE2, /) // DEFBINOP_EX_MATRIX_POW (TYPE1 ## _ ## TYPE2 ## _pow, TYPE1, TYPE2) #define INSTALL_EX_MATRIX_OPS(TYPE1, TYPE2) \ INSTALL_BINOP(op_add, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _add) \ INSTALL_BINOP(op_sub, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _sub) \ INSTALL_BINOP(op_mul, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _mul) \ INSTALL_BINOP(op_div, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _div) // INSTALL_BINOP(op_pow, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _pow) #define DEFINE_EX_EX_OPS(TYPE1, TYPE2) \ DEFBINOP_EX_EX_OP (TYPE1 ## _ ## TYPE2 ## _add, TYPE1, TYPE2, +) \ DEFBINOP_EX_EX_OP (TYPE1 ## _ ## TYPE2 ## _sub, TYPE1, TYPE2, -) \ DEFBINOP_EX_EX_OP (TYPE1 ## _ ## TYPE2 ## _mul, TYPE1, TYPE2, *) \ DEFBINOP_EX_EX_OP (TYPE1 ## _ ## TYPE2 ## _div, TYPE1, TYPE2, /) \ DEFBINOP_EX_EX_POW (TYPE1 ## _ ## TYPE2 ## _pow, TYPE1, TYPE2) \ DEFBINOP_EX_EX_BOOL_OP(TYPE1 ## _ ## TYPE2 ## _equal, TYPE1, TYPE2, GiNaC::relational::equal) \ DEFBINOP_EX_EX_BOOL_OP(TYPE1 ## _ ## TYPE2 ## _not_equal, TYPE1, TYPE2, GiNaC::relational::not_equal) \ DEFBINOP_EX_EX_BOOL_OP(TYPE1 ## _ ## TYPE2 ## _less, TYPE1, TYPE2, GiNaC::relational::less) \ DEFBINOP_EX_EX_BOOL_OP(TYPE1 ## _ ## TYPE2 ## _less_or_equal, TYPE1, TYPE2, GiNaC::relational::less_or_equal) \ DEFBINOP_EX_EX_BOOL_OP(TYPE1 ## _ ## TYPE2 ## _greater, TYPE1, TYPE2, GiNaC::relational::greater) \ DEFBINOP_EX_EX_BOOL_OP(TYPE1 ## _ ## TYPE2 ## _greater_or_equal, TYPE1, TYPE2, GiNaC::relational::greater_or_equal) #define INSTALL_EX_EX_OPS(TYPE1, TYPE2) \ INSTALL_BINOP(op_add, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _add) \ INSTALL_BINOP(op_sub, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _sub) \ INSTALL_BINOP(op_mul, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _mul) \ INSTALL_BINOP(op_div, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _div) \ INSTALL_BINOP(op_pow, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _pow) \ INSTALL_BINOP(op_eq, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _equal) \ INSTALL_BINOP(op_ne, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _not_equal) \ INSTALL_BINOP(op_lt, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _less) \ INSTALL_BINOP(op_le, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _less_or_equal) \ INSTALL_BINOP(op_gt, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _greater) \ INSTALL_BINOP(op_ge, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _greater_or_equal); #define DEFINE_MATRIX_MATRIX_OPS(TYPE1, TYPE2) \ DEFBINOP_MATRIX_MATRIX_OP (TYPE1 ## _ ## TYPE2 ## _add, TYPE1, TYPE2, add) \ DEFBINOP_MATRIX_MATRIX_OP (TYPE1 ## _ ## TYPE2 ## _sub, TYPE1, TYPE2, sub) \ DEFBINOP_MATRIX_MATRIX_OP (TYPE1 ## _ ## TYPE2 ## _mul, TYPE1, TYPE2, mul) \ DEFBINOP_MATRIX_MATRIX_DIV (TYPE1 ## _ ## TYPE2 ## _div, TYPE1, TYPE2) #define INSTALL_MATRIX_MATRIX_OPS(TYPE1, TYPE2) \ INSTALL_BINOP(op_add, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _add) \ INSTALL_BINOP(op_sub, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _sub) \ INSTALL_BINOP(op_mul, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _mul) \ INSTALL_BINOP(op_div, octave_ ## TYPE1, octave_ ## TYPE2, TYPE1 ## _ ## TYPE2 ## _div) #endif /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */ symbolic/DESCRIPTION0000644000175000017500000000047311647271210015412 0ustar carandraugcarandraugName: Symbolic Version: 1.1.0 Date: 2011-10-18 Author: Various Authors Maintainer: The Octave Community Title: Symbolic Computations. Description: Symbolic toolbox based on GiNaC and CLN. BuildRequires: ginac-devel Depends: octave (>= 3.1.55) Autoload: yes License: GPL version 2 or later Url: http://octave.sf.net symbolic/PKG_ADD0000644000175000017500000000677311262437661014740 0ustar carandraugcarandraugautoload ("vpa", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("sym", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("is_vpa", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("is_sym", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("is_ex", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("to_char", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("to_double", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("digits", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Cos", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Sin", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Tan", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("aCos", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("aSin", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("aTan", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Cosh", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Sinh", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Tanh", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("aCosh", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("aSinh", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("aTanh", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Exp", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Log", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Sqrt", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("subs", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("differentiate", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("expand", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("collect", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("coeff", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("lcoeff", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("tcoeff", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("degree", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("ldegree", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("quotient", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("remainder", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("premainder", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("Pi", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("ex_matrix", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("probably_prime", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("findsymbols", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("numden", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("syminfo", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("symlsolve", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); autoload ("sumterms", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct")); symbols (); symbolic/COPYING0000644000175000017500000004307710751613601014745 0ustar carandraugcarandraug GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 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 licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) 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 this service 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 make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. 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. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), 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 distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the 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 a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 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. 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 convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 2 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 is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision 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, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This 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 Library General Public License instead of this License.