├── doc └── introsymb.pdf ├── headers ├── symbolicc++.h ├── symbolic │ └── constants.h ├── matnorm.h ├── identity.h └── vecnorm.h ├── othercas ├── spin.m ├── picard.mpd ├── energy.map └── tensor.red ├── examples ├── mersenne.cpp ├── sderive1.cpp ├── sgoedel2.cpp ├── sderive2.cpp ├── gat.cpp ├── coeff3.cpp ├── coeff1.cpp ├── invariant.cpp ├── firstintegral.cpp ├── integration.cpp ├── backlund.cpp ├── deter.cpp ├── division.cpp ├── matrix.cpp ├── conser.cpp ├── derivatv.cpp ├── expand.cpp ├── vproduct.cpp ├── hamiltoneq.cpp ├── inverse.cpp ├── aresize.cpp ├── lagrange.cpp ├── asslegendre.cpp ├── trace.cpp ├── lie1.cpp ├── nambu.cpp ├── metrics.cpp ├── first1.cpp ├── kronecker.cpp ├── pexample.cpp ├── pexample3.cpp ├── ghost.cpp ├── hilbert.cpp ├── setvalue.cpp ├── coeff2.cpp ├── isprime.cpp ├── hamiltonvar.cpp ├── bose.cpp ├── put.cpp ├── mandel.cpp ├── rtti2.cpp ├── logistic.cpp ├── sgoedel1.cpp ├── first2.cpp ├── elliptic.cpp ├── squater.cpp ├── commute.cpp ├── transformation.cpp ├── legendre.cpp ├── spicard.cpp ├── vnorm.cpp ├── convertbinary.cpp ├── taylor2.cpp ├── grass.cpp ├── newton.cpp ├── taylor1.cpp ├── spheric.cpp ├── picard.cpp ├── stringexpr.cpp ├── hamiltonin.cpp ├── coher.cpp ├── comm.cpp ├── tokenizer.cpp ├── sprime.cpp ├── kill.cpp ├── lie.cpp ├── lie2.cpp ├── jacobi.cpp ├── ruelle.cpp ├── asslegendre.h ├── transf.cpp ├── var.cpp ├── lag.cpp ├── legendre.h ├── pade.cpp ├── lax.cpp ├── mycomplex.cpp ├── contract.cpp ├── chebyshev.cpp ├── cumu.cpp ├── mystring.cpp ├── cantor.cpp ├── hermite.cpp ├── laguerre.cpp └── lorenzfix.cpp ├── lisp ├── listset.lisp ├── lambda │ ├── examples │ │ ├── mapcar.lambda │ │ ├── combinator.lambda │ │ ├── cond.lambda │ │ ├── logic.lambda │ │ ├── list.lambda │ │ ├── list2.lambda │ │ ├── mapcar2.lambda │ │ └── church.lambda │ ├── builtin_io.h │ └── builtin_math.h ├── countsub.lisp ├── poly_eg.lisp ├── simp2_eg.lisp ├── differ_eg.lisp ├── poly.lisp ├── simp3_eg.lisp ├── simp1.lisp ├── simp1_eg.lisp ├── differ.lisp └── simp2.lisp └── ChangeLog /doc/introsymb.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/certik/SymbolicCpp/HEAD/doc/introsymb.pdf -------------------------------------------------------------------------------- /headers/symbolicc++.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This library is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | #ifndef SYMBOLIC_CPLUSPLUS_REDIRECT 22 | #define SYMBOLIC_CPLUSPLUS_REDIRECT 23 | 24 | #include "symbolic/symbolicc++.h" 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /othercas/spin.m: -------------------------------------------------------------------------------- 1 | (* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | *) 20 | 21 | 22 | (* spin.m *) 23 | 24 | sp = {{ 0, Sqrt[2]*hb, 0}, {0, 0, Sqrt[2]*hb}, {0, 0, 0}} 25 | sm = {{0, 0, 0}, {Sqrt[2]*hb, 0, 0}, {0, Sqrt[2]*hb, 0}} 26 | comm = sp . sm - sm . sp 27 | Eigenvalues[comm] 28 | -------------------------------------------------------------------------------- /examples/mersenne.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // mersenne.cpp 23 | 24 | #include 25 | #include "verylong.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Verylong p, one("1"), two("2"), mersenne("11213"); 31 | p = pow(two,mersenne) - one; 32 | cout << p << endl; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /lisp/listset.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; listset.lisp 23 | 24 | (defun list_set (lis) 25 | (cond 26 | ( (not (consp lis)) nil ) 27 | ( (member (car lis) (cdr lis)) (list_set (cdr lis)) ) 28 | ( t (cons (car lis) (list_set (cdr lis))) ) ) ) 29 | 30 | (list_set '(a b x a c d 1 3 c 3)) ; (b x a d 1 c 3) 31 | -------------------------------------------------------------------------------- /lisp/lambda/examples/mapcar.lambda: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; mapcar.lambda 23 | 24 | (import logic.lambda) 25 | 26 | (define mapcar 27 | (lambda (function l) 28 | (if (empty? l) (list) 29 | (cons (function (car l)) (mapcar function (cdr l))) ) ) ) 30 | 31 | (mapcar (lambda (x) (+ x 1)) (list 1 2 3)) ; ( 2 3 4 ) 32 | -------------------------------------------------------------------------------- /examples/sderive1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // sderive1.cpp 23 | 24 | #include 25 | #include "derive.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Derive x; 31 | x.set(2); 32 | Derive y = 2*x*x*x + 5*x + 1; 33 | cout << "The derivative of y at x = " << x << " is " << df(y)<< endl; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /othercas/picard.mpd: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | /* picard.mpd */ 23 | 24 | x0:=0: /*initial x*/ 25 | y0:=1: /*initial y*/ 26 | y:=y0: 27 | y1:=subs(y,x=s): 28 | f:=(x,y)->(x+y): /*declare function f(x,y)=x+y*/ 29 | 30 | for i from 1 to 5 do 31 | y:=(y0+subs(int(f(s,y1),s),s=x)-subs(int(f(s,y1),s),s=x0)): 32 | y1:=subs(y,x=s): 33 | end_for: 34 | 35 | print(y); 36 | -------------------------------------------------------------------------------- /examples/sgoedel2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // sgoedel2.cpp 23 | 24 | #include 25 | #include 26 | #include "goedel.h" 27 | using namespace std; 28 | 29 | int main(void) 30 | { 31 | string s; 32 | Goedel g; 33 | for(int i=1;i<=20;i++) 34 | { 35 | s = s + 'a'; 36 | g.rename(s); 37 | cout << i << " " << g.word() << " => " << g.number() << endl; 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /lisp/countsub.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; countsub.lisp 23 | 24 | (defun countsublists (lis) 25 | (cond 26 | ( (null lis) 0 ) 27 | ( (atom lis) 0 ) 28 | ( (atom (car lis)) (countsublists (cdr lis)) ) 29 | ( t (+ 1 30 | (countsublists (car lis)) 31 | (countsublists (cdr lis)) ) ) ) ) 32 | 33 | (countsublists '(a (1 2) (r s) (a b 23) z)) ; 3 34 | (countsublists '()) ; 0 35 | -------------------------------------------------------------------------------- /examples/sderive2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // sderive2.cpp 23 | 24 | #include 25 | #include "derive.h" 26 | #include "rational.h" 27 | using namespace std; 28 | 29 | int main(void) 30 | { 31 | Derive > x; 32 | x.set(Rational(37,29)); 33 | Derive > c(3); 34 | Derive > y = x*x + c/x; 35 | cout << "The derivative of y at x = " << x << " is " << df(y) << endl; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /examples/gat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // gat.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic u("u"), v("v"), x1("x1"), x2("x2"), ep("ep"); 31 | Symbolic A, B, C; 32 | 33 | u = u[x1, x2]; 34 | v = v[x1, x2]; 35 | 36 | A = df(u, x2, 2) + u*df(u, x1) + (u^2); 37 | B = A[u == u + ep*v]; 38 | C = df(B, ep); 39 | C = C[ep == 0]; 40 | 41 | cout << C << endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /lisp/lambda/examples/combinator.lambda: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; combinator.lambda: 23 | ; Implementation of various combinators in lambda calculus 24 | 25 | ; Y combinator for anonymous recursion 26 | 27 | ; comment as an anonymous function 28 | (define Y (lambda (f) ((lambda (x) (f (x x))) 29 | (lambda (x) (f (x x))) ) ) ) 30 | 31 | ; comment as a recursive operator / equation form 32 | (define Y (lambda (f) (f (Y f)))) 33 | -------------------------------------------------------------------------------- /lisp/lambda/examples/cond.lambda: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; cond.lambda 23 | 24 | (import ../libraries/logic.lambda ../libraries/list.lambda) 25 | 26 | (define tri 27 | (lambda (x) 28 | (cond ( list (> x 0) positive ) 29 | ( list (= x 0) neutral ) 30 | ( list (< x 0) negative ) ) ) ) 31 | 32 | (display (tri -5)) (newline) 33 | (display (tri 0)) (newline) 34 | (display (tri +5)) (newline) 35 | (display (map tri (list -5 0 +5))) (newline) 36 | -------------------------------------------------------------------------------- /examples/coeff3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // coeff3.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | int i; 31 | Symbolic x("x"), p("p"); 32 | Symbolic w = 0; 33 | 34 | for(i=-5;i<=5;i++) w += (6+i)*(p^(5-i))*(x^i)/(6-i); 35 | 36 | cout << "w = " << w << endl; cout << endl; 37 | 38 | cout << "The coefficients are" << endl; 39 | for(i=-5;i<=5;i++) cout << w.coeff(x,i) << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /examples/coeff1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // coeff1.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic a("a"), b("b"), c("c"); 31 | 32 | cout << (2*a-3*b*a-2+c).coeff(a) << endl; 33 | cout << (2*a-3*b*a-2+c).coeff(b*a) << endl; 34 | cout << (2*a-3*b*a-2+c).coeff(b) << endl; 35 | cout << endl; 36 | 37 | cout << (b*b+c-3).coeff(a,0) << endl; 38 | cout << (-b).coeff(a,0) << endl; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /examples/invariant.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | // invariant.cpp 22 | 23 | #include 24 | #include "symbolicc++.h" 25 | using namespace std; 26 | 27 | int main(void) 28 | { 29 | Symbolic x("x"), x1("x1"), x2("x2"), d("d"); 30 | Symbolic f = 2*(x^2) - 1; 31 | Symbolic g = x2 - 2*(x1^2) + 2*(x2^2) + d*(1 + x2 - 2*(x1^2)); 32 | 33 | cout << f[ x == f ] << endl; 34 | cout << g[ x1 == x, x2 == f ] << endl; 35 | 36 | if( f[ x == f ] == g[ x1 == x, x2 == f ] ) 37 | cout << "Invariant." << endl; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /examples/firstintegral.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // firstintegral.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic u1("u1"), u2("u2"), t("t"); 31 | Symbolic f, r; 32 | 33 | f = ln(u1[t]) + ln(u2[t]) - u1[t] - u2[t]; 34 | r = df(f,t); 35 | cout << "r = " << r << endl; 36 | r = r.subst(df(u1[t],t),u1[t]-u1[t]*u2[t]); 37 | r = r.subst(df(u2[t],t),-u2[t]+u1[t]*u2[t]); 38 | cout << "r = " << r << endl; 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/integration.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // integration.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic x("x"), c("c"), z("z"), y; 31 | 32 | z = z[x]; 33 | y = (1-x)*(1-x)+cos(x)+x*exp(x)+c+z; 34 | 35 | cout << "y = " << y << endl; 36 | 37 | for(int i=0;i<3;i++) 38 | { 39 | y = integrate(y,x); 40 | y = y[integrate(x*exp(x),x) == x*exp(x) - exp(x)]; 41 | cout << "y = " << y << endl; 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /examples/backlund.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // backlund.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic ut("ut"), xt("xt"), x("x"), u("u"), lambda("lambda"); 31 | Symbolic res1, res2, i = sqrt(Number(-1)); 32 | 33 | xt = xt[x]; 34 | ut = ut[xt]; 35 | u = u[x]; 36 | 37 | res1 = df(u, x) - i*df(ut, xt) - 2*exp(i*lambda)*sin((u+i*ut)/2); 38 | res2 = df(res1, x); 39 | 40 | res2 = res2[ df(xt, x) == 1 ]; 41 | 42 | cout << res2 << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /headers/symbolic/constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This library is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // constants.h 23 | 24 | #ifndef SYMBOLIC_CPLUSPLUS_CONSTANTS 25 | 26 | #ifdef SYMBOLIC_DECLARE 27 | #ifndef SYMBOLIC_CPLUSPLUS_CONSTANTS_DECLARE 28 | #define SYMBOLIC_CPLUSPLUS_CONSTANTS_DECLARE 29 | 30 | namespace SymbolicConstant 31 | { 32 | static const Symbolic i = Symbolic(Power(Symbolic(-1), 33 | Power(Symbolic(2), Symbolic(-1)))); 34 | static const Symbolic i_symbol("i"); 35 | static const Symbolic e ("e"); 36 | static const Symbolic pi ("pi"); 37 | } 38 | 39 | #endif 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /examples/deter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // deter.cpp 23 | 24 | #include 25 | #include "matrix.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Matrix A(2,2); 31 | A[0][0] = 1; A[0][1] = 2; 32 | A[1][0] = 3; A[1][1] = 4; 33 | cout << A; 34 | cout << "Determinant of the matrix is " << A.determinant() << endl; 35 | cout << endl; 36 | 37 | for(int i=3;i<5;i++) 38 | { 39 | A.resize(i,i,i); 40 | cout << A; 41 | cout << "Determinant of the matrix is " << A.determinant() << endl; 42 | cout << endl; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /examples/division.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // division.cpp 23 | 24 | #include 25 | #include "verylong.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Verylong P("999"), Q("111"), D("105"); 31 | 32 | P = pow(P,D); // 999^105 = 9.00277e+314 (exceeded double limit) 33 | Q = pow(Q,D); // 111^105 = 5.74001e+214 34 | 35 | cout << div(P,Q) << endl; // 1.56842e+100 - OK 36 | cout << div(Q,P) << endl; // 6.37583e-101 - OK 37 | cout << double(P)/double(Q) << endl; // NaN 38 | cout << double(Q)/double(P) << endl; // NaN 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /examples/matrix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | #include 23 | #include "symbolicc++.h" 24 | using namespace std; 25 | 26 | int main(void) 27 | { 28 | Symbolic alpha("alpha"); 29 | Symbolic X, XI, dX, result; 30 | 31 | X = ( ( cos(alpha), sin(alpha) ), 32 | (-sin(alpha), cos(alpha) ) ); 33 | 34 | cout << X << endl; 35 | 36 | XI = X[alpha == -alpha]; cout << XI << endl; 37 | dX = df(X, alpha); cout << dX << endl; 38 | 39 | result = XI * dX; cout << result << endl; 40 | result = result[(cos(alpha)^2) == 1 - (sin(alpha)^2)]; 41 | cout << result << endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /examples/conser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // conser.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic u("u"), x1("x1"), x2("x2"); 31 | 32 | u = u[x1, x2]; 33 | 34 | Symbolic S = df(u, x2); 35 | Symbolic X = df(u, x1); 36 | 37 | Symbolic A = S[ u == (df(u,x1)^2)/2, df(df(u,x1),x2) == sin(u) ]; 38 | Symbolic B = X[ u == cos(u), df(df(u,x1),x2) == sin(u)]; 39 | 40 | cout << "A = " << A << endl; 41 | cout << "B = " << B << endl; 42 | 43 | Symbolic CL = A + B; 44 | 45 | cout << "CL = " << CL << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /lisp/poly_eg.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; poly_eg.lisp 23 | 24 | (load "poly.lisp") 25 | 26 | (defun show1 (a) 27 | `(format t "~A~% => ~A~%" (quote ,a) ,a)) 28 | 29 | (defmacro show (&rest a) 30 | `(progn ,@(mapcar #'show1 a))) 31 | 32 | (show 33 | (add '((2 . 3) (1 . 7) (0 . 1)) '((2 . 4) (0 . 2))) 34 | (add '((0 . 0)) '((3 . 4) (1 . 2) (0 . 7))) 35 | (negate '((2 . 4) (0 . 2))) 36 | (subtract '((2 . 3) (1 . 7) (0 . 1)) '((2 . 4) (0 . 2))) 37 | (multiply '((3 . 3) (0 . 2)) '((2 . 4) (1 . 1))) 38 | (multiply '((3 . 3) (0 . 2)) '()) 39 | (degree '((5 . 3) (2 . 2) (0 . -1))) 40 | ) 41 | -------------------------------------------------------------------------------- /examples/derivatv.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // derivatv.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | int i; 31 | Symbolic x("x"), y, z("z"); 32 | 33 | y = 1/(1-x) + 2*(x^3) - z; 34 | cout << "y = " << y << endl; 35 | 36 | for(i=0;i<8;i++) 37 | { y = df(y,x); cout << "y = " << y << endl; } 38 | cout << endl; 39 | 40 | Symbolic u, v("v"); 41 | 42 | u = (v^(Symbolic(3)/5))/3 - 2*(v^(Symbolic(1)/5))/7 + Symbolic(1)/6; 43 | cout << "u = " << u << endl; 44 | 45 | for(i=0;i<8;i++) 46 | { u = df(u,v); cout << "u = " << u << endl; } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /examples/expand.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // expand.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic a("a"), b("b"), c("c"), y, z; 31 | 32 | y = (Symbolic(7)^3); cout << " y = " << y << endl; 33 | y = (a^0); cout << " y = " << y << endl; 34 | y = (a^3); cout << " y = " << y << endl; 35 | cout << endl; 36 | 37 | y = ((a+b-c)^3); cout << " y = " << y << endl; 38 | cout << endl; 39 | 40 | y = (a+b)*(a-c); cout << " y = " << y << endl; 41 | cout << endl; 42 | 43 | y = a+b; 44 | z = (y^4); cout << " z = " << z << endl; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /examples/vproduct.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // vproduct.cpp 23 | 24 | #include 25 | #include "vector.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Vector A(3), B(3), C(3), D(3); 31 | A[0] = 1.2; A[1] = 1.3; A[2] = 3.4; 32 | B[0] = 4.3; B[1] = 4.3; B[2] = 5.5; 33 | C[0] = 6.5; C[1] = 2.6; C[2] = 9.3; 34 | D[0] = 1.1; D[1] = 7.6; D[2] = 1.8; 35 | cout << A%(B%C) + B%(C%A) + C%(A%B) << endl; 36 | cout << (A%B)%(C%D) << endl; 37 | cout << B*(A|C%D)-A*(B|C%D) << endl; 38 | cout << C*(A|B%D)-D*(A|B%C) << endl; 39 | // precedence of | is lower than << 40 | cout << (A|B%C) - (A%B|C) << endl; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /examples/hamiltoneq.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // hamiltoneq.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic h("h"), q1("q1"), q2("q2"), p1("p1"), p2("p2"), pt1, pt2, qt1, qt2; 31 | 32 | // Hamilton function 33 | h = (p1*p1+p2*p2+q1*q1+q2*q2)/2+q1*q1*q2-q2*q2*q2/3; 34 | // Hamilton equations of motion 35 | pt1 = -df(h,q1); pt2 = -df(h,q2); 36 | qt1 = df(h,p1); qt2 = df(h,p2); 37 | 38 | cout << "dp1/dt = " << pt1 <> f; 45 | 46 | InverseMap(f,m,n); 47 | 48 | cout << "The corresponding m is " << m << " and n is " << n << endl; 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /examples/aresize.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // aresize.cpp 23 | 24 | #include 25 | #include "array.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Array M; 31 | M.resize(3); 32 | M[0] = 5.0; M[1] = 8.0; M[2] = 4.0; 33 | cout << "M = \n" << M << endl; cout << endl; 34 | 35 | Array A; 36 | A.resize(2,3); 37 | A[0][0] = 1.0; A[0][1] = 3.0; A[0][2] = 2.0; 38 | A[1][0] = 4.0; A[1][1] = 5.0; A[1][2] = 6.0; 39 | 40 | A.resize(dimensions<2>(3,4),2); 41 | cout << "A = \n" << A << endl; 42 | A.resize(2,2); 43 | cout << "A = \n" << A << endl; 44 | A.resize(dimensions<2>(4,4),9); 45 | cout << "A = \n" << A << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /examples/lagrange.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // lagrange.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic x("x"), y("y"), dx("dx"), dy("dy"); 31 | Symbolic f = 2*x*x+y*y; 32 | Symbolic g = x+y-1; 33 | 34 | // noncommutative 35 | dx = ~dx; dy = ~dy; 36 | 37 | cout << "f = " << f << endl; 38 | cout << "g = " << g << endl; 39 | Symbolic d_f = df(f,x)*dx+df(f,y)*dy; 40 | Symbolic d_g = df(g,x)*dx+df(g,y)*dy; 41 | cout << "d_f = " << d_f << endl; 42 | cout << "d_g = " << d_g << endl; 43 | Symbolic wedge = (d_f*d_g).subst_all((dx*dx==0,dy*dy==0,dy*dx==-dx*dy)); 44 | cout << (wedge.coeff(dx*dy)==0) << endl; 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /examples/asslegendre.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // asslegendre.cpp 23 | // Associate Legendre Polynomial 24 | // P_l^|m|(w) = (1-w^2)^(|m|/2) (d/dw)^|m| P_l(w) 25 | // Recursion formula (n+1)P_{n+1}(x) = (2n+1)xP_n(x)-nP_{n-1}(x) 26 | 27 | #include 28 | #include "symbolicc++.h" 29 | #include "asslegendre.h" 30 | using namespace std; 31 | 32 | int main(void) 33 | { 34 | int n=5; 35 | Symbolic x("x") ,Y; 36 | AssLegendre P(x); 37 | 38 | for(int i=0;i A(3,3), B(3,3,-1); 31 | 32 | A[0][0] = 2; A[0][1] = -1; A[0][2] = 1; 33 | A[1][0] = 1; A[1][1] = -2; A[1][2] = -1; 34 | A[2][0] = 3; A[2][1] = 2; A[2][2] = 2; 35 | 36 | cout << "A =\n" << A << endl; 37 | cout << "B =\n" << B << endl; 38 | cout << "tr(A) = " << A.trace() << endl; 39 | cout << "tr(B) = " << B.trace() << endl; 40 | cout << "tr(AB) = " << (A*B).trace() << endl; 41 | cout << "tr(BA) = " << (B*A).trace() << endl; 42 | cout << "tr(A)tr(B) = " << A.trace() * B.trace() << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /examples/lie1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // lie1.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | Symbolic Z(const Symbolic &V, const Symbolic &x, const Symbolic &P) 29 | { return V * df(P, x); } 30 | 31 | int main(void) 32 | { 33 | int n = 4; 34 | Symbolic Q("Q"), V("V"), x("x"), ep("ep"); 35 | 36 | Q = Q[x]; 37 | V = V[x]; 38 | 39 | Symbolic SD = ep * Z(V, x, Q); 40 | Symbolic RES = Q + ep * Z(V, x, Q); 41 | 42 | for(int j=1;j<=n;j++) 43 | { 44 | SD = ep * Z(V, x, SD) / (j + 1); 45 | RES = RES + SD; 46 | } 47 | 48 | cout << "RES = " << RES << endl << endl; 49 | 50 | Symbolic F = RES[V == x - (x^2)]; 51 | 52 | cout << "F = " << F[Q == x] << endl; 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /examples/nambu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // nambu.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | void nambu(const Symbolic &I,const Symbolic &u,int n) 29 | { 30 | int i, j; 31 | Symbolic J("J",n,n); 32 | 33 | for(i=0;i 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic du("du"), dv("dv"); 31 | Symbolic u("u"), v("v"); 32 | 33 | // du and dv are not commutative 34 | du = ~du; dv = ~dv; 35 | 36 | Symbolic x1 = cos(u)*sin(v); 37 | Symbolic x2 = sin(u)*sin(v); 38 | Symbolic x3 = cos(v); 39 | 40 | Symbolic dx1 = df(x1,u)*du + df(x1,v)*dv; 41 | Symbolic dx2 = df(x2,u)*du + df(x2,v)*dv; 42 | Symbolic dx3 = df(x3,u)*du + df(x3,v)*dv; 43 | 44 | Symbolic GT = dx1*dx1 + dx2*dx2 + dx3*dx3; 45 | 46 | GT = GT[ (cos(u)^2) == 1 - (sin(u)^2), (cos(v)^2) == 1 - (sin(v)^2) ]; 47 | 48 | cout << GT << endl; 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /lisp/simp2_eg.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; simp2_eg.lisp 23 | 24 | (load "simp2.lisp") 25 | 26 | (defun show1 (a) 27 | `(format t "~A~% => ~A~%" (quote ,a) ,a)) 28 | 29 | (defmacro show (&rest a) 30 | `(progn ,@(mapcar #'show1 a))) 31 | 32 | 33 | ; Applications of the simplification 34 | (show 35 | (simp 'x) 36 | (simp '(x)) 37 | 38 | (simp '(+ x)) 39 | (simp '(+ (+ x))) 40 | (simp '(+ (- x))) 41 | (simp '(+ (- 0))) 42 | (simp '(- (+ x))) 43 | 44 | (simp '(- (sin 0))) 45 | (simp '(+ (exp 0))) 46 | (simp '(- (exp 0))) 47 | (simp '(+ (log 1))) 48 | (simp '(+ (cosh 0))) 49 | (simp '(exp (sin 0))) 50 | (simp '(log (exp (sin 0)))) 51 | 52 | (simp '(- (- x))) 53 | (simp '(+ x y)) 54 | ) 55 | -------------------------------------------------------------------------------- /examples/first1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // first1.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | int N=3; 31 | Symbolic term, sum=0, u("u",N), v("",N), I("",N); 32 | 33 | v(0) = u(1)*u(2); v(1) = u(0)*u(2); v(2) = u(0)*u(1); 34 | I(0) = u(0)*u(0)-u(1)*u(1); 35 | I(1) = u(2)*u(2)-u(0)*u(0); 36 | I(2) = u(1)*u(1)-u(2)*u(2); 37 | 38 | for(int i=0;i A(2,3), B(3,2), C(3,1), D(2,2); 31 | 32 | A[0][0] = 2; A[0][1] = -4; A[0][2] = -3; 33 | A[1][0] = 4; A[1][1] = -1; A[1][2] = -2; 34 | B[0][0] = 2; B[0][1] = -4; 35 | B[1][0] = 2; B[1][1] = -3; 36 | B[2][0] = 3; B[2][1] = -1; 37 | C[0][0] = 2; 38 | C[1][0] = 1; 39 | C[2][0] = -2; 40 | D[0][0] = 2; D[0][1] = 1; 41 | D[1][0] = 3; D[1][1] = -1; 42 | 43 | cout << kron(A,B) << endl; 44 | cout << kron(B,A) << endl; 45 | cout << kron(A,B)*kron(C,D) - kron(A*C,B*D) << endl; 46 | cout << dsum(A,B) << endl; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /examples/pexample.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // pexample.cpp 23 | 24 | #include 25 | #include "polynomial.h" 26 | #include "rational.h" 27 | using namespace std; 28 | 29 | int main(void) 30 | { 31 | Polynomial x("x"); 32 | Polynomial p1 = (x^3)+2.0*(x^2)+7.0; 33 | cout << "p1(x) = " << p1 << endl; 34 | Polynomial p2 = (x^2) - x - 1.0; 35 | cout << "p2(x) = " << p2 << endl; 36 | Polynomial p3 = p1 + 2.0*p2; 37 | cout << "p3(x) = " << p3 << endl; 38 | Polynomial p4 = 3.0*p1*p2 + 2.0; 39 | cout << "p4(x) = " << p4 << endl; 40 | Polynomial p5 = (x^2)-1.0; 41 | Polynomial p6 = x-1.0; 42 | Polynomial p7 = p5/p6; 43 | cout << "p7(x) = " << p7 << endl; 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /examples/pexample3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // pexample3.cpp 23 | 24 | #include 25 | #include "multinomial.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Multinomial x("x"); 31 | Multinomial y("y"); 32 | 33 | Multinomial p=(x^3)+2.0*(x^2)+7.0; 34 | 35 | cout << "p(x) = " << p < h("1/10"); // time-mesh length 31 | const Rational x0("99/100"); // initial value 32 | 33 | int main(void) 34 | { 35 | Rational u, v, u1, twoh, t, 36 | zero("0"), one("1"), two("2"), fifty("50"); 37 | ofstream sout("ghosts.dat"); // contain the rational number values 38 | 39 | // initial values 40 | u = x0; v = u + h*u*(one-u); 41 | t = zero; twoh = two*h; 42 | 43 | while(t <= fifty) 44 | { 45 | u1 = u; u = v; 46 | v = u1 + twoh*u*(one-u); 47 | t += h; 48 | sout << t << " " << v << endl; 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /examples/hilbert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // hilbert.cpp 23 | 24 | #include 25 | #include "matrix.h" 26 | #include "matnorm.h" 27 | #include "symbolicc++.h" 28 | using namespace std; 29 | 30 | int main(void) 31 | { 32 | int n = 2; 33 | Symbolic a("a"), b("b"), y1; 34 | Matrix A(n,n); 35 | A[0][0] = a; A[0][1] = b; 36 | A[1][0] = b; A[1][1] = a; 37 | 38 | cout << "The " << n << "x" << n << " matrix A is \n" << A << endl; 39 | 40 | y1 = normH(A); 41 | cout << "The Hilbert-Schmidt norm of matrix A is " << y1 << endl; 42 | cout << endl; 43 | 44 | //a = 2.0; b = 3.0; 45 | cout << "Put a = " << 2.0 << " and b = " << 3.0 << endl; 46 | cout << "The Hilbert-Schmidt norm of matrix A is " 47 | << y1[a==2,b==3] << " or " 48 | << y1[a==2.0,b==3.0] << endl; 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /othercas/energy.map: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ## 5 | ## Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ## 7 | ## This program is free software; you can redistribute it and/or modify 8 | ## it under the terms of the GNU General Public License as published by 9 | ## the Free Software Foundation; either version 2 of the License, or 10 | ## (at your option) any later version. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ## GNU General Public License for more details. 16 | ## 17 | ## You should have received a copy of the GNU General Public License along 18 | ## with this program; if not, write to the Free Software Foundation, Inc., 19 | ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | # energy.map 23 | 24 | # potential 25 | V := c*x; 26 | # trial ansatz 27 | u := x*exp(-a*x); 28 | # eigenvalue equation 29 | Hu := -hb^2/(2*m)*diff(u,x,x) + V*u; 30 | 31 | # integrating for finding expectation value 32 | # not normalized yet 33 | res1 := int(u*Hu,x); 34 | 35 | # collect the exponential functions 36 | res2 := collect(res1,exp); 37 | 38 | # substitution of the boundary 39 | res3 := 0 - subs(x=0,res2); 40 | 41 | # finding the norm of u to normalize 42 | res4 := int(u*u,x); 43 | res5 := -subs(x=0,res4); 44 | 45 | # normalized expectation value 46 | expe := res3/res5; 47 | 48 | # finding the minimum with respect to a 49 | minim := diff(expe,a); 50 | res6 := solve(minim=0,a); 51 | a := res6[1]; 52 | 53 | # approximate ground state energy 54 | appgse = subs(a=0,expe); 55 | -------------------------------------------------------------------------------- /examples/setvalue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // setvalue.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic x("x"), y("y"), z("z"); 31 | double c1 = 0.5, c2 = 1.2; 32 | 33 | y = x*x+z/2.0; 34 | cout << "y = " << y << endl; 35 | 36 | cout << "Put x = " << c1 << ", z = " << c2 << endl; 37 | cout << "The value of y = " << y 38 | << " is " << double(y[x==c1,z==c2]) << endl; 39 | cout << endl; 40 | 41 | y = x*x*z + 0.7*z - x*z; 42 | cout << "y = " << y << endl; 43 | 44 | cout << "Put x = " << c1 << endl; 45 | cout << "The value of y is " << y[x==c1] << endl; 46 | cout << endl; 47 | 48 | cout << "Put z = " << c2 << endl; 49 | cout << "The value of y is " 50 | << double(y[x==c1, z==c2]) << endl; 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /lisp/lambda/examples/logic.lambda: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; logic.lambda : 23 | ; Basic logic operations implemented in the lambda calculus 24 | 25 | (define true (lambda (x y) x)) 26 | (define false (lambda (x y) y)) 27 | (define if (lambda (test consequent1 consequent2) 28 | (test consequent1 consequent2) ) ) 29 | 30 | (define not (lambda (x) (if x false true))) 31 | 32 | (define or (lambda x 33 | (if (empty? x) false 34 | (if (car x) true (apply or (cdr x))) ) ) ) 35 | (define and (lambda x 36 | (if (empty? x) true 37 | (if (car x) (apply and (cdr x)) false)) ) ) 38 | 39 | (define cond (lambda x 40 | (if (empty? x) false 41 | (if (caar x) (cadar x) (apply cond (cdr x))) ) ) ) 42 | -------------------------------------------------------------------------------- /examples/coeff2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // coeff2.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic a("a"), b("b"), c("c"), d("d"); 31 | Symbolic y, z; 32 | 33 | y = -a*5*a*b*b*c+4*a-2*a*b*c*c+6-2*a*b+3*a*b*c-8*c*c*b*a+4*c*c*c*a*b-3*b*c; 34 | cout << "y = " << y << endl; cout << endl; 35 | 36 | z = a; cout << y.coeff(z) << endl; 37 | z = b; cout << y.coeff(z) << endl; 38 | z = c; cout << y.coeff(z) << endl; 39 | z = a*a; cout << y.coeff(z) << endl; 40 | z = a*b; cout << y.coeff(z) << endl; 41 | z = d; cout << y.coeff(z) << endl; 42 | cout << endl; 43 | 44 | // find coefficients of the constant term 45 | z = a; cout << y.coeff(z,0) << endl; 46 | cout << y.coeff(1) << endl; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /examples/isprime.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // isprime.cpp 23 | 24 | #include 25 | #include "verylong.h" 26 | using namespace std; 27 | 28 | template int is_prime(T p) 29 | { 30 | T j(2), zero(0), one(1), two(2), four(4); 31 | T limit = T(sqrt(p)) + one; 32 | 33 | if(j < limit && p%j == zero) return 0; 34 | j++; 35 | 36 | if(j < limit && p%j == zero) return 0; 37 | j += two; 38 | while(j < limit) 39 | { 40 | if(p%j == zero) return 0; 41 | j += two; 42 | if(p%j == zero) return 0; 43 | j += four; 44 | } 45 | return 1; 46 | } 47 | 48 | int main(void) 49 | { 50 | Verylong x; 51 | cout << "Please enter a positive integer number : "; 52 | cin >> x; 53 | if(is_prime(x)) cout << "The number " << x << " is prime " << endl; 54 | else cout << "The number " << x << " is not prime " << endl; 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /lisp/differ_eg.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; differ_eg.lisp 23 | 24 | (load "differ.lisp") 25 | (load "simp3.lisp") 26 | 27 | (defun show1 (a) 28 | `(format t "~A~% => ~A~%" (quote ,a) ,a)) 29 | 30 | (defmacro show (&rest a) 31 | `(progn ,@(mapcar #'show1 a))) 32 | 33 | ; Applications 34 | (show 35 | ;simple-examples 36 | (diff 'x 'x) 37 | (diff '2 'x) 38 | (diff 2 'x) 39 | (diff 'x 'u) 40 | 41 | ;sum-rule 42 | (diff '(+ x x) 'x) 43 | 44 | ;product-rule 45 | (diff '(* x x) 'x) 46 | (simp (diff '(* x x) 'x)) 47 | 48 | ;more-examples 49 | (diff '(* (+ 3 x) (- a x)) 'x) 50 | (simp (diff '(* (+ 3 x) (- a x)) 'x)) 51 | (diff '(* (* x x) x) 'x) 52 | (simp (diff '(* (* x x) x) 'x)) 53 | 54 | ;chain-rule 55 | (simp (diff '(cos (exp x)) 'x)) 56 | (simp (diff '(/ (sin x) (cos x)) 'x)) 57 | (simp (diff '(f (* (cos x) (exp x))) 'x)) 58 | ) 59 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2010-09-15 2 | Fixed rational.h to include 3 | 4 | 2010-08 5 | Added pattern matching for Equation 6 | Added elementary solve routines 7 | 8 | 2009-10-27 9 | Corrected the handling of powers of products in Product::subst, 10 | i.e. when expanding (a*b)^2 a and b must be inserted directly into 11 | the list of factors. 12 | 13 | 2009-10-20 14 | Corrected a bug in comparing non-commutative products. 15 | 16 | 2009-10-19 17 | Pattern matching for non-commutative products added. 18 | Added solve.h and integration.h. 19 | Initial support for equation solving: linear, quadratic, cubic. 20 | Initial support for integration using a few apptern matches. 21 | 22 | 2009-10-15 23 | Completed pattern matching (commutative products only). 24 | Added substitution with pattern matching (BindingEquation). 25 | 26 | 2009-10-02: 27 | Added a^(b+c) = a^b*a^c in Product::expand. This helps 28 | to simplify some expressions. 29 | Fix Derivative::subst to check whether the function changed 30 | and if not avoid re-computing the derivatives. This fixes 31 | a problem when differentiating f[x, y[x]] in some cases. 32 | Fix Product::subst to ignore substitutions of constants, which always 33 | work. 34 | 35 | 2009-05-22: 36 | Some parts were incorrectly marked as part of the library 37 | or part of the headers for the GNU autoconf version. 38 | 39 | 2009-05-20: 40 | Changed Cloning and CloningPtr classes to simplify 41 | and hopefully improve readability. 42 | 43 | 2009-04-14: 44 | Made the vacuum state and its dual non-commutative in 45 | examples/fermi.cpp and added some simplifying rules. 46 | 47 | 2009-03-31: 48 | Fixed the symbolic cross product. 49 | 50 | 2009-01-20: 51 | Provide GNU configure build and install 52 | Added headers/symbolicc++.h 53 | for use instead of headers/symbolic/symbolicc++.h 54 | -------------------------------------------------------------------------------- /examples/hamiltonvar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // hamiltonvar.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic h("h"), q("q",2), p("p",2), u("u",2), v("v",2), 31 | qt("",2), pt("",2), ut("",2), vt("",2); 32 | 33 | // Hamilton function 34 | h = (p(0)*p(0)+p(1)*p(1)+q(0)*q(0)+q(1)*q(1))/2 35 | + q(0)*q(0)*q(1)-q(1)*q(1)*q(1)/3; 36 | for(int j=0;j<2;j++) 37 | { 38 | pt(j) = -df(h,q(j)); qt(j) = df(h,p(j)); 39 | cout << "dp" << j << "/dt = " << pt(j) < (caar P) (caar Q)) (cons (car P) (add (cdr P) Q))) 29 | ((> (caar Q) (caar P)) (cons (car Q) (add P (cdr Q)))) 30 | ((zerop (+ (cdar P) (cdar Q))) (add (cdr P) (cdr Q))) 31 | (t (cons (cons (caar P) (+ (cdar P) (cdar Q))) 32 | (add (cdr P) (cdr Q)))))) 33 | 34 | (defun negate (P) 35 | (mapcar #'(lambda (x) (cons (car x) (- (cdr x)))) P)) 36 | 37 | (defun subtract (P Q) 38 | (add P (negate Q))) 39 | 40 | (defun multiply (P Q) 41 | (cond 42 | ((or (null P) (null Q)) nil) 43 | (t (cons (cons (+ (caar P) (caar Q)) (* (cdar P) (cdar Q))) 44 | (add (multiply (list (car P)) (cdr Q)) 45 | (multiply (cdr P) Q)))))) 46 | 47 | (defun degree (P) 48 | (if (null P) 0 (caar P))) 49 | -------------------------------------------------------------------------------- /examples/bose.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // bose.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int C(int n, int r) 29 | { 30 | int num = 1, den = 1; 31 | for(int i=n;i>r;i--) num *= i; 32 | for(int j=2;j<=(n-r);j++) den *= j; 33 | return num/den; 34 | } 35 | 36 | int main(void) 37 | { 38 | Symbolic b("b"), bd("b'"); 39 | b = ~b; bd = ~bd; 40 | 41 | for(int m=0; m<5; m++) 42 | { 43 | int fac = 1, j; 44 | Symbolic comm = (b^m)*(bd^m)-(bd^m)*(b^m); 45 | Symbolic res, res2; 46 | cout << m << ": " << comm << " = " 47 | << comm.subst_all(b*bd==1+bd*b) << endl; 48 | 49 | for(j=1; j<=m; j++) 50 | { 51 | fac *= j; 52 | res += df(bd^m,bd,j)*df(b^m,b,j)/fac; 53 | res2 += fac*C(m,j)*C(m,j)*(bd^(m-j))*(b^(m-j)); 54 | } 55 | cout << " " << comm << " = " << res << endl; 56 | cout << " " << comm << " = " << res2 << endl; 57 | } 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /examples/put.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // put.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic a("a"), b("b"), c("c"), w, y; 31 | 32 | // Test (1) 33 | y = (a+b)*(a+sin(cos(a)^2))*b; 34 | cout << "y = " << y << endl; 35 | 36 | y = y[b==c+c]; cout << "y = " << y << endl; 37 | 38 | y = y[cos(a)*cos(a)==1-sin(a)*sin(a)]; 39 | cout << "y = " << y << endl; cout << endl; 40 | 41 | // Test (2) 42 | y = sin(cos(a)^2) + b; cout << "y = " << y << endl; 43 | 44 | y = y[cos(a)*cos(a)==1-sin(a)*sin(a)]; 45 | cout << "y = " << y << endl; cout << endl; 46 | 47 | // Test (3) 48 | a = a[c]; b = b[c]; 49 | y = 2*a*df(b*a*a,c)+a*b*c; cout << "y = " << y << endl; 50 | 51 | y = y[a==cos(c)]; cout << "y = " << y << endl; 52 | 53 | w = df(b,c); y = y[w==exp(a)]; cout << "y = " << y << endl; 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /lisp/simp3_eg.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; simp3_eg.lisp 23 | 24 | (load "simp3.lisp") 25 | 26 | (defun show1 (a) 27 | `(format t "~A~% => ~A~%" (quote ,a) ,a)) 28 | 29 | (defmacro show (&rest a) 30 | `(progn ,@(mapcar #'show1 a))) 31 | 32 | 33 | ; Applications of the simplification 34 | 35 | (show 36 | (simp '(+ (+ x))) 37 | (simp '(+ (- x))) 38 | (simp '(- (- x))) ; not simplified ! 39 | 40 | (simp '(+ (sin 0))) 41 | (simp '(+ (exp 0))) 42 | (simp '(+ (log 1))) 43 | (simp '(- (cosh 0))) 44 | (simp '(- (sin 0))) 45 | (simp '(- (arctan 0))) 46 | 47 | (simp '(+ x 0)) 48 | (simp '(+ 0 x)) 49 | (simp '(- x 0)) 50 | (simp '(* x 0)) 51 | (simp '(/ x 0)) 52 | (simp '(/ 0 x)) 53 | (simp '(- (/ x 0))) 54 | (simp '(power x 0)) 55 | 56 | (simp '(+ x y)) 57 | (simp '(+ (* x 0) (* x 1))) 58 | (simp '(- (+ 0 x) (* 1 x))) 59 | 60 | (simp '(- (+ x y) (- y x))) ; not simplified ! 61 | ) 62 | -------------------------------------------------------------------------------- /examples/mandel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // mandel.cpp 23 | 24 | #include 25 | #include 26 | #include "rational.h" 27 | #include "verylong.h" 28 | using namespace std; 29 | 30 | int main(void) 31 | { 32 | complex > c(Rational(1,8),Rational(1,3)), 33 | z0(Rational(0,1),Rational(0,1)); 34 | 35 | cout << "Using data type Rational" << endl; 36 | for(int i=1;i<=3;i++) 37 | { 38 | z0 = z0*z0 + c; 39 | cout << "z[" << i << "] = " << z0 << endl; 40 | } 41 | cout << endl; 42 | 43 | complex > 44 | d(Rational(1,8),Rational(1,3)), 45 | w0(Rational(0,1),Rational(0,1)); 46 | 47 | cout << "Using data type Rational" << endl; 48 | for(int j=1;j<=5;j++) 49 | { 50 | w0 = w0*w0 + d; 51 | cout << "w[" << j << "] = " << w0 << endl; 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /examples/rtti2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // rtti2.cpp 23 | 24 | #include 25 | #include 26 | #include 27 | using namespace std; 28 | 29 | class base1 30 | { 31 | public: string whatami(void) { return typeid(*this).name(); } 32 | }; 33 | class derived11: public base1 {}; 34 | class derived12: public base1 {}; 35 | 36 | class base2 37 | { 38 | public: virtual string whatami(void) { return typeid(*this).name(); } 39 | virtual ~base2() {} 40 | }; 41 | class derived21: public base2 {}; 42 | class derived22: public base2 {}; 43 | 44 | int main(void) 45 | { 46 | derived11 d11; 47 | derived12 d12; 48 | base1* b1; 49 | derived21 d21; 50 | derived22 d22; 51 | base2* b2; 52 | b1 = &d11; 53 | cout << b1->whatami() << endl; 54 | b1 = &d12; 55 | cout << b1->whatami() << endl; 56 | b2 = &d21; 57 | cout << b2->whatami() << endl; 58 | b2 = &d22; 59 | cout << b2->whatami() << endl; 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /examples/logistic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // logistic.cpp 23 | 24 | #include "rational.h" 25 | #include "verylong.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Rational a(4,1), b(1,1), x0(1,3); // initial value x0 = 1/3 31 | int i; 32 | 33 | cout << "x[0] = " << x0 << " or " << double(x0) << endl; 34 | 35 | for(i=1;i<=4;i++) // cannot use higher values than 4 36 | { // out of range for data type int 37 | x0 = a*x0*(b - x0); 38 | cout << "x[" << i << "] = " << x0 << " or " << double(x0) << endl; 39 | } 40 | cout << endl; 41 | 42 | Rational c1("1"), c2("4/1"), 43 | y0("1/3"); // initial value y0 = 1/3 44 | 45 | cout << "y[0] = " << y0 << " or " << double(y0) << endl; 46 | 47 | for(i=1;i<=6;i++) 48 | { 49 | y0 = c2*y0*(c1 - y0); 50 | cout << "y[" << i << "] = " << y0 << " or " << double(y0) << endl; 51 | } 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /examples/sgoedel1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // sgoedel1.cpp 23 | 24 | #include 25 | #include "goedel.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Goedel g("acbc"); 31 | 32 | cout << "The word is " << g.word(); 33 | cout << " and its corresponding Goedel number is " 34 | << g.number() << endl; 35 | 36 | g.rename("aabb"); 37 | 38 | cout << "The word is " << g.word(); 39 | cout << " and its corresponding Goedel number is " 40 | << g.number() << endl; 41 | 42 | g.rename("abcbc"); 43 | 44 | cout << "The word is " << g.word(); 45 | cout << " and its corresponding Goedel number is " 46 | << g.number() << endl; 47 | cout << endl; 48 | 49 | Goedel h; 50 | 51 | // List all the Goedel Numbers below 1500 52 | for(int i=0;i<1500;i++) 53 | { 54 | h.resize(i); 55 | if(h.is_goedel()) 56 | cout << i << " => " << h.word() 57 | << " is a Goedel number" << endl; 58 | } 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /headers/matnorm.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This library is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // matnorm.h 23 | // Norms of Matrices 24 | 25 | #ifndef MATNORM_H 26 | #define MATNORM_H 27 | 28 | #include 29 | #include 30 | #include "vector.h" 31 | #include "vecnorm.h" 32 | #include "matrix.h" 33 | #include "identity.h" 34 | using namespace std; 35 | 36 | template T norm1(const Matrix &m) 37 | { 38 | T maxItem(0), temp; 39 | int i,j; 40 | for(i=0;i maxItem) maxItem = temp; 46 | } 47 | return maxItem; 48 | } 49 | 50 | template T normI(const Matrix &m) 51 | { 52 | T maxItem(norm1(m[0])); 53 | for(int i=1;i maxItem) maxItem = norm1(m[i]); 55 | return maxItem; 56 | } 57 | 58 | template T normH(const Matrix &m) 59 | { return sqrt((m*(m.transpose())).trace()); } 60 | #endif 61 | -------------------------------------------------------------------------------- /examples/first2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // first2.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic u("u",3), v("v",4); 31 | Symbolic term, sum, I, R1, R2; 32 | Symbolic t("t"), s("s"), b("b"), r("r"); 33 | 34 | // Lorenz Model 35 | v(0) = s*u(1)-s*u(0); 36 | v(1) = -u(1)-u(0)*u(2)+r*u(0); 37 | v(2) = u(0)*u(1)-b*u(2); 38 | v(3) = 1; 39 | 40 | // The ansatz 41 | I = (u(1)*u(1)+u(2)*u(2))*exp(2*t); 42 | sum = 0; 43 | 44 | for(int i=0;i<3;i++) sum += v(i)*df(I,u(i)); 45 | 46 | sum += v(3)*df(I,t); 47 | cout << "sum = " << sum << endl; cout << endl; 48 | R1 = sum.coeff(u(2),2); 49 | R1 = R1/(exp(2*t)); 50 | cout << "R1 = " << R1 << endl; 51 | 52 | R2 = sum.coeff(u(0),1); R2 = R2.coeff(u(1),1); 53 | R2 = R2/(exp(2*t)); 54 | cout << "R2 = " << R2 << endl; 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/elliptic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // elliptic.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic cn("cn"), sn("sn"), dn("dn"), k("k"), x("x"), x0("x0"), a("a"), 31 | lambda("lambda"), i = ("i"); 32 | 33 | a = a[x]; 34 | 35 | Symbolic u = i*lambda*cn[a,k]; 36 | 37 | Symbolic res1 = df(u, x, 2); 38 | 39 | res1 = res1.subst_all( 40 | ( df(sn[a,k], a) == cn[a,k] * dn[a,k], 41 | df(cn[a,k], a) == -sn[a,k] * dn[a,k], 42 | df(dn[a,k], a) == -(k^2) * sn[a,k] * cn[a,k] ) ); 43 | 44 | cout << res1 << endl; 45 | 46 | Symbolic res2 = res1 - (u^3); 47 | 48 | Symbolic res3 = res2.subst_all( 49 | (cn[a,k]^2) == (-1 + 2*(k^2) - (k^2)*(sn[a,k]^2) + (dn[a,k]^2))/(2*k*k) ); 50 | 51 | Symbolic res4 = res3[ a == lambda*(x-x0), 52 | k == 1/sqrt(Symbolic(2)), 53 | (i^3) == -i ]; 54 | cout << res4 << endl; 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/squater.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // squater.cpp 23 | 24 | #include 25 | #include "quatern.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Quaternion Q1(3,4,5,6), 31 | Q2 = Q1.conjugate(), 32 | Q3 = Q1.inverse(); 33 | double Mag = Q1.magnitude(), 34 | Magz = (~Q1).magnitude(); 35 | 36 | cout << "Q1 = " << Q1 << endl; 37 | cout << "Q2 = Conjugate of Q1 = " << Q2 << endl; 38 | cout << "Q3 = Inverse of Q1 = " << Q3 << endl; 39 | cout << "Mag = Magnitude of Q1 = " << Mag << endl; 40 | cout << "Magz = Magnitude of normalized Q1 = " << Magz << endl; 41 | cout << endl; 42 | 43 | cout << "Q1 * Q2 = " << Q1 * Q2 << endl; 44 | cout << "Q2 * Q1 = " << Q2 * Q1 << endl; 45 | cout << "Mag^2 = Square of magnitude = " << Mag * Mag << endl; 46 | cout << endl; 47 | 48 | cout << "Q1 * Q3 = " << Q1 * Q3 << endl; 49 | cout << "Q3 * Q1 = " << Q3 * Q1 << endl; 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /examples/commute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // commute.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic a("a"), b("b"), y; 31 | 32 | cout << "Commutative Algebra" << endl; 33 | cout << "===================" << endl; 34 | 35 | // The system is commutative by default 36 | y = a*b*a; cout << " y = " << y << endl; 37 | y = a*b-b*a; cout << " y = " << y << endl; 38 | 39 | y = ((a-b)^2); cout << " y = " << y << endl; 40 | cout << endl; 41 | 42 | cout << "Non Commutative Algebra" << endl; 43 | cout << "=======================" << endl; 44 | a = ~a; b = ~b; 45 | 46 | y = a*b*a; cout << " y = " << y << endl; 47 | y = a*b-b*a; cout << " y = " << y << endl; 48 | 49 | y = ((a-b)^2); cout << " y = " << y << endl; 50 | cout << endl; 51 | 52 | cout << "Commutative Algebra" << endl; 53 | cout << "===================" << endl; 54 | cout << " y = " << y[a == ~a, b == ~b] << endl; 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /examples/transformation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // transformation.cpp 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | using namespace std; 30 | 31 | double cube(double x) { return x*x*x; } 32 | 33 | string concat(string s) { return s + "x"; } 34 | 35 | char lowercase(char c) { return char(tolower(int(c))); } 36 | 37 | int main(void) 38 | { 39 | vector v; 40 | v.push_back(0.5); 41 | v.push_back(1.0); 42 | v.push_back(1.5); 43 | transform(v.begin(),v.end(),v.begin(),cube); 44 | for(int i=0;i 25 | #include "vector.h" 26 | #include "vecnorm.h" 27 | using namespace std; 28 | 29 | int main(void) 30 | { 31 | Vector v; 32 | v.resize(5,2); 33 | cout << "The size of vector v is " << v.size() << endl; 34 | cout << endl; 35 | 36 | Vector a(4,-3.1), b; 37 | b.resize(4); 38 | b[0] = 2.3; b[1] = -3.6; b[2] = -1.2; b[3] = -5.5; 39 | 40 | // Different vector norms 41 | cout << "norm1() of a = " << norm1(a) << endl; 42 | cout << "norm2() of a = " << norm2(a) << endl; 43 | cout << "normI() of a = " << normI(a) << endl; 44 | cout << endl; 45 | 46 | cout << "norm1() of b = " << norm1(b) << endl; 47 | cout << "norm2() of b = " << norm2(b) << endl; 48 | cout << "normI() of b = " << normI(b) << endl; 49 | cout << endl; 50 | 51 | // The norm2() of normalized vectors a and b is 1 52 | cout << "norm2() of normalized a = " << norm2(normalize(a)) << endl; 53 | cout << "norm2() of normalized b = " << norm2(normalize(b)) << endl; 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/convertbinary.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // convertbinary.cpp 23 | 24 | #include 25 | #include 26 | #include 27 | using namespace std; 28 | 29 | unsigned long N(string s) 30 | { 31 | unsigned long sum = 0, p2=1; 32 | for(int i=s.length()-1;i>=0;i--,p2*=2) sum += (s[i]-'0')*p2; 33 | return sum; 34 | } 35 | 36 | string Ninv(unsigned long x) 37 | { 38 | string s = ""; // empty string 39 | for(;x>0;x/=2) s = char((x%2)+'0')+s; 40 | return s; 41 | } 42 | 43 | unsigned long map(string s) 44 | { 45 | unsigned long n = N(s); 46 | if(s.length()>1) n += (1 << s.length())-2; 47 | return n; 48 | } 49 | 50 | string mapinv(unsigned long x) 51 | { 52 | unsigned long n = (unsigned long)floor(log(x+2.0)/log(2.0)); 53 | string b; 54 | if(n == 1) b = Ninv(x); 55 | else b = Ninv(x-(1< " << s << endl; 67 | } 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /examples/taylor2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // taylor2.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int factorial(int N) 29 | { 30 | int result=1; 31 | for(int i=2;i<=N;i++) result *= i; 32 | return result; 33 | } 34 | 35 | int main(void) 36 | { 37 | int i, j, n=4; 38 | Symbolic x("x"), u("u"), result; 39 | Symbolic u0("",n), w("",n); 40 | u = u[x]; 41 | u0(0) = x*x + x*u - u*u; 42 | for(i=1;i0;j--) u0(i) = u0(i)[w(j)==u0(j-1)]; 54 | cout << u0 << endl; 55 | 56 | for(i=0;ij, set e(i)*e(j) to -e(j)*e(i) 56 | for(i=0;i T f(T x) // f(x) 30 | { return 4*x-cos(x); } 31 | 32 | int main(void) 33 | { 34 | int N=7; 35 | double y, u0 = -1.0; 36 | Symbolic x("x"), ff, ff1, ff2, C; 37 | Equation value = (x==u0); 38 | ff = f(x); ff1 = df(ff,x); ff2 = df(ff1,x); 39 | 40 | // Set numerical precision to 10 decimal places 41 | cout << setprecision(10); 42 | cout << "f(x) = " << ff << endl; 43 | cout << "f'(x) = " << ff1 << endl; 44 | cout << "f''(x) = " << ff2 << endl; 45 | cout << endl; 46 | 47 | // ======= Condition for convergence ======= 48 | C = ff*ff2/ff1; 49 | cout << "C = " << C << endl; 50 | cout << "|C(x=u0)| = " << fabs(double(C[x==u0])) << endl; 51 | cout << endl; 52 | 53 | // ======= Symbolic computation ========= 54 | for(int i=0;i0;j--) u0(i) = u0(i)[y(j)==u0(j-1)]; 55 | cout << u0 << endl; 56 | 57 | for(i=0;i0 && m%2) a = -a; 45 | b = sqrt((2*l+1)*factorial(l-absm)/(4*factorial(l+absm)*PI)); 46 | result = a*b*exp(I*m*phi); 47 | return result; 48 | } 49 | 50 | int main(void) 51 | { 52 | int n=3; 53 | Symbolic phi("phi"), w("w"), result; 54 | 55 | for(int i=0;i<=n;i++) 56 | { 57 | for(int j=-i;j<=i;j++) 58 | { 59 | result = Y(i,j,phi,w); 60 | result = result[cos(w)*cos(w) == 1-sin(w)*sin(w)]; 61 | cout << "Y(" << i << "," << j << ") = " << result << endl; 62 | } 63 | cout << endl; 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /lisp/lambda/builtin_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // builtin_io.h 23 | 24 | #ifndef BUILTIN_IO_H 25 | #define BUILTIN_IO_H 26 | 27 | expression builtin_display(expression &e,environment &env) 28 | { 29 | int space = 0; 30 | vector::iterator i; 31 | for(i=e.tokens.begin()+1;i!=e.tokens.end();i++) 32 | { 33 | if(space) cout << " "; 34 | cout << evaluate(*i, env); 35 | space = 1; 36 | } 37 | return expression("#display"); 38 | } 39 | 40 | expression builtin_import(expression &e,environment &env) 41 | { 42 | vector::iterator i; 43 | for(i=e.tokens.begin()+1;i!=e.tokens.end();i++) 44 | { 45 | expression e1 = evaluate(*i, env); 46 | if(e1.type==FREE_VARIABLE) 47 | { 48 | ifstream f(e1.identifier.c_str()); 49 | if(f.fail()) 50 | cerr << "Error: (import " << e1 << ") failed to open file\n"; 51 | else interpreter(f,env); 52 | f.close(); 53 | } 54 | else 55 | cerr << "Error: (import " << e1 << ") is not a filename\n"; 56 | } 57 | return expression("#import"); 58 | } 59 | 60 | expression builtin_newline(expression &e,environment &env) 61 | {cout << endl; return expression("#newline");} 62 | #endif 63 | -------------------------------------------------------------------------------- /examples/picard.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // picard.cpp 23 | 24 | #include 25 | #include 26 | #include "polynomial.h" 27 | #include "rational.h" 28 | using namespace std; 29 | 30 | int main(void) 31 | { 32 | Polynomial > x("x"); 33 | Polynomial > pic(x); 34 | Rational zero(string("0")), one(string("1")), two(string("2")); 35 | int i; 36 | 37 | cout << endl << "x+y up to fifth approximation :" << endl; 38 | pic = one; 39 | cout << pic << endl; 40 | for(i=1;i<=5;i++) 41 | { 42 | //integrate and evaluate at the boundaries x and zero 43 | pic = one + Int(x+pic,"x") - (Int(x+pic,"x"))(zero); 44 | cout << pic << endl; 45 | } 46 | cout << "The approximation at x=2 gives " << pic(two) << endl; 47 | 48 | cout << endl << "x+y^2 up to fourth approximation :" << endl; 49 | pic = one; 50 | cout << pic << endl; 51 | for(i=1;i<=4;i++) 52 | { 53 | //integrate and evaluate at the boundaries x and zero 54 | pic = one + Int(x+(pic^2),"x") - (Int(x+(pic^2),"x"))(zero); 55 | cout << pic << endl; 56 | } 57 | cout << "The approximation at x=2 gives " << pic(two) << endl; 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /lisp/simp1.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; simp1.lisp 23 | 24 | (defun simp-unary (f) 25 | (let* ( (op (car f)) 26 | (opd (cadr f)) 27 | (z? (and (numberp opd) (zerop opd))) ; zero 28 | (o? (equal 1 opd)) ; one 29 | (p? (equal 'pi opd)) ) ; pi 30 | (cond 31 | ((eq op '+) opd) ; + x => x 32 | ((and (eq op '-) z?) 0) ; - 0 => 0 33 | ((and (eq op 'exp) z?) 1) ; exp(0) => 1 34 | ((and (eq op 'log) o?) 0) ; log(1) => 0 35 | ((and (eq op 'sin) z?) 0) ; sin(0) => 0 36 | ((and (eq op 'cos) z?) 1) ; cos(0) => 1 37 | ((and (eq op 'sin) p?) 0) ; sin(pi) => 0 38 | ((and (eq op 'cos) p?) -1) ; cos(pi) =>-1 39 | ((and (eq op 'arcsin) z?) 0) ; arcsin(0) => 0 40 | ((and (eq op 'arctan) z?) 0) ; arctan(0) => 0 41 | ((and (eq op 'sinh) z?) 0) ; sinh(0) => 0 42 | ((and (eq op 'cosh) z?) 1) ; cosh(0) => 1 43 | (t (list op opd))))) 44 | -------------------------------------------------------------------------------- /examples/stringexpr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // stringexpr.cpp 23 | 24 | #include 25 | #include 26 | #include 27 | using namespace std; 28 | 29 | int main(void) 30 | { 31 | map simplify; 32 | map::iterator i; 33 | int count = 1; 34 | 35 | simplify["sin(0)"] = "0"; 36 | simplify["cos(0)"] = "1"; 37 | simplify["1*"] = ""; 38 | simplify["*1"] = ""; 39 | simplify["+0+"] = "+"; 40 | 41 | string exp = "a*b*cos(0)+sin(0)*c-d+cos(0)*sin(0)+2*d*1"; 42 | cout << "exp = " << exp << endl; 43 | 44 | while(count) 45 | for(count=0,i=simplify.begin();i!=simplify.end();i++) 46 | { 47 | string::size_type pos = exp.find(i->first,0); 48 | while(pos < exp.npos) 49 | { 50 | count++; 51 | exp.replace(pos,i->first.length(),i->second); 52 | pos = exp.find(i->first,0); 53 | cout.setf(ios_base::left,ios_base::adjustfield); 54 | cout.width(50); 55 | cout << "exp = " + exp; 56 | if(i->second == "") 57 | cout << "(delete " + i->first + ")" << endl; 58 | else 59 | cout << "(" + i->first + " -> " + i->second + ")" << endl; 60 | } 61 | } 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /examples/hamiltonin.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // hamiltonin.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic h("h"), q("q",3), p("p",3), pt("pt",3), qt("qt",3), 31 | I1, R1, I2, R2; 32 | 33 | int j; 34 | 35 | // Hamilton function 36 | h = (p(0)*p(0)+p(1)*p(1)+p(2)*p(2))/2 37 | +exp(q(0)-q(1))+exp(q(1)-q(2))+exp(q(2)-q(0)); 38 | 39 | for(j=0;j<3;j++) 40 | { 41 | pt(j) = -df(h,q(j)); qt(j) = df(h,p(j)); 42 | cout << "dp" << j << "/dt = " << pt(j) << endl; 43 | cout << "dq" << j << "/dt = " << qt(j) << endl; 44 | } 45 | 46 | I1 = p(0)+p(1)+p(2); 47 | R1 = 0; 48 | for(j=0;j<3;j++) R1 += pt(j)*df(I1,p(j))+qt(j)*df(I1,q(j)); 49 | if(R1 == 0) cout << "I1 is a first integral." < ~A~%" (quote ,a) ,a)) 28 | 29 | (defmacro show (&rest a) 30 | `(progn ,@(mapcar #'show1 a))) 31 | 32 | 33 | ; Applications of the simplification 34 | 35 | (show 36 | (simp-unary '(+ x)) 37 | (simp-unary '(exp 0)) 38 | (simp-unary '(log 1)) 39 | (simp-unary '(cosh 0)) 40 | (simp-unary '(exp 1)) 41 | (simp-unary '(cos pi)) 42 | (simp-unary '(- x)) 43 | (simp-unary '(- 0)) 44 | 45 | ; the following expressions are not simplified 46 | (simp-unary '(+ (+ x))) 47 | (simp-unary '(- (+ x))) 48 | (simp-unary '(+ (exp 0))) 49 | (simp-unary '(exp (sin 0))) 50 | (simp-unary '(log (exp (sin 0)))) 51 | 52 | ; the last expression simplifies incorrectly 53 | (simp-unary '(+ x y)) ; <--- WRONG ! 54 | 55 | ; the following expressions generate errors 56 | (simp-unary 'x)) ; An attempt was made to do car on `x', 57 | ; which is not a pair <--- ERROR ! 58 | 59 | (simp-unary '(x)) ; An attempt was made to do car on `nil', 60 | ; which is not a pair <--- ERROR ! 61 | ) 62 | -------------------------------------------------------------------------------- /lisp/lambda/examples/mapcar2.lambda: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; mapcar2.lambda 23 | 24 | (import logic.lambda) 25 | 26 | (define first (lambda (x y) x)) 27 | (define second (lambda (x y) y)) 28 | (define cons (lambda (x y w) (w x y))) 29 | (define car (lambda (x) (x first))) 30 | (define cdr (lambda (x) (x second))) 31 | (define cadr (lambda (x) (car (cdr x)))) 32 | (define caddr (lambda (x) (car (cdr (cdr x))))) 33 | (define nil (lambda (x) (x true true true true))) 34 | (define null (lambda (x) (x (lambda (a b) false)))) 35 | 36 | (define p (cons a b)) 37 | (display p) (newline) ; ( lambda ( w ) ( w a b ) ) 38 | (display (car p)) (newline) ; a 39 | (display (cdr p)) (newline) ; b 40 | (display (if (null nil) yes no)) ; yes 41 | (newline) 42 | (display (if (null p) yes no)) ; no 43 | (newline) 44 | 45 | (define mapcar 46 | (lambda (function l) 47 | (if (null l) nil 48 | (cons (function (car l)) (mapcar function (cdr l))) ) ) ) 49 | 50 | (define ml (mapcar (lambda (x) (+ x 1)) 51 | (cons 1 (cons 2 (cons 3 nil))) ) ) 52 | 53 | (display (car ml)) (newline) ; 2 54 | (display (cadr ml)) (newline) ; 3 55 | (display (caddr ml)) (newline) ; 4 56 | -------------------------------------------------------------------------------- /lisp/lambda/examples/church.lambda: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; church.lambda : 23 | ; Implement whole numbers via Church numerals in the lambda calculus 24 | 25 | (import logic.lambda list.lambda) 26 | 27 | ; numbers are represented by repeated application 28 | (define zero false) 29 | (define zero? (lambda (x) (x (lambda (x) false) true))) 30 | (define successor (lambda (n x y) (x (n x y)))) 31 | 32 | ; To find the predecessor we construct all Church numerals 33 | ; with their successors using the repeated application 34 | ; from the given church numeral. 35 | 36 | (define predecessor 37 | (lambda (n) (first 38 | (n (lambda (x) (pair (second x) (successor (second x)))) 39 | (pair zero zero) ) ) ) ) 40 | 41 | 42 | ; Addition and multiplication are achieved by adding to the 43 | ; repeated application and repeated application of 44 | ; repeated application. 45 | 46 | (define add (lambda (a b x y) (a x (b x y)))) 47 | (define multiply (lambda (a b) (a (lambda (x) (add b x)) zero))) 48 | 49 | ; Convert a Church numeral to a number that can be displayed 50 | ; using the built in increment (++) operator. ) 51 | 52 | (define church->integer (lambda (n) (n ++ 0))) 53 | 54 | -------------------------------------------------------------------------------- /examples/coher.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // coher.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic b("b"), bd("bd"), cs("cs"), ds("ds"), 31 | z("z"), w("w"), conj("conj"); 32 | 33 | // non-commutative symbols 34 | b = ~b; bd = ~bd; cs = ~cs; ds = ~ds; 35 | 36 | Equations rules = ( b*cs[z] == z*cs[z], 37 | b*cs[w] == w*cs[w], 38 | ds[z]*bd == ds[z]*conj[z], 39 | ds[w]*bd == ds[w]*conj[w], 40 | ds[z]*cs[z] == 1, 41 | ds[w]*cs[w] == 1, 42 | ds[w]*cs[z] == exp(-(z*conj[z]+w*conj[w]-2*conj[w]*z)/2), 43 | ds[z]*cs[w] == exp(-(z*conj[z]+w*conj[w]-2*conj[z]*w)/2)); 44 | 45 | // Example 1 46 | Symbolic r1 = b*(b*cs[z]); 47 | r1 = r1.subst_all(rules); 48 | cout << r1 << endl; 49 | r1 = r1[z == 1]; 50 | cout << r1 << endl; 51 | 52 | // Example 2 53 | cout << (ds[z]*cs[z]).subst_all(rules) << endl; 54 | 55 | // Example 3 56 | Symbolic r2 = b*cs[z]; 57 | Symbolic r3 = ds[w]*r2; 58 | 59 | cout << r2.subst_all(rules) << endl; 60 | cout << r3.subst_all(rules) << endl; 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /examples/comm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // comm.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | const int n = 3; 29 | 30 | Symbolic x("x",n); 31 | 32 | Symbolic commutator(const Symbolic &V,const Symbolic &W) 33 | { 34 | Symbolic U(Symbolic(0),V.rows()); 35 | 36 | for(int k=0;k 25 | #include 26 | #include 27 | using namespace std; 28 | 29 | vector* split(string s,char sep) 30 | { 31 | // dynamically allocate the result vector 32 | // so that the returning pointer will be valid 33 | vector* results = new vector; 34 | string t = ""; 35 | int c, slength; 36 | slength = s.size(); 37 | // iterate through string s character by character 38 | for(c=0;c push_back(t); 43 | t = ""; // start new token 44 | } 45 | else { t += s[c]; } // add char to token 46 | if(t != "") results -> push_back(t); // get last token 47 | return results; // return pointer to result vector 48 | } // end split function 49 | 50 | int main(void) 51 | { 52 | // pointer to a vector of strings 53 | vector* sp; 54 | sp = split("a+b;c*d;d/f",';'); 55 | int vsize = sp -> size(); 56 | cout << "number of terms: " << vsize << endl; 57 | // display each substring token one by one 58 | for(int i=0;i at(i) << endl; 59 | delete sp; 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /examples/sprime.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // sprime.cpp 23 | 24 | #include 25 | #include "prime.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | const size_t max0 = 1000000; 31 | unsigned int i, j, count = 0; 32 | 33 | Prime p; // specifies the upper limit of the sequence 34 | p.run(); // generates the prime number sequence 35 | 36 | // for all odd numbers greater than 3, check if they are prime 37 | for(i=3,j=100;i<=max0;i+=2) 38 | { 39 | if(p.is_prime(i)) count++; 40 | 41 | // sum the number of primes below 100, 1000, ..., 1000000 42 | if(i==j-1) 43 | { 44 | j *= 10; 45 | cout << "There are " << count + 1 46 | << " primes below " << i+1 << endl; 47 | } 48 | } 49 | cout << endl; 50 | 51 | // print the first 20 primes 52 | for(i=0;i<20;i++) cout << p(i) << " "; 53 | cout << endl << endl; 54 | 55 | // randomly pick some primes 56 | cout << "The 100th prime is " << p(99) << endl; 57 | cout << "The 200th prime is " << p(199) << endl; 58 | cout << "The 3000th prime is " << p(2999) << endl; 59 | cout << "The 10000th prime is " << p(9999) << endl; 60 | cout << "The 12500th prime is " << p(12499) << endl; 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /examples/kill.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // kill.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | int N=4; 31 | Symbolic g("g",N,N), Lg("Lg",N,N), V("V",N), x("x",N); 32 | 33 | // The Goedel metric 34 | g(0,0) = 1; g(0,1) = 0; g(0,2) = 0; g(0,3) = 0; 35 | g(1,0) = 0; g(1,1) = -exp(2*x(0))/2; g(1,2) = 0; g(1,3) = -exp(x(0)); 36 | g(2,0) = 0; g(2,1) = 0; g(2,2) = 1; g(2,3) = 0; 37 | g(3,0) = 0; g(3,1) = -exp(x(0)); g(3,2) = 0; g(3,3) = -1; 38 | 39 | // The Killing vector field of the Goedel metric 40 | V(0) = x(1); V(1) = exp(-2*x(0)) - x(1)*x(1)/2; 41 | V(2) = 0; V(3) = -2*exp(-x(0)); 42 | 43 | // The Lie derivative 44 | for(int j=0;j 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | const int N = 3; 29 | 30 | Symbolic u("u",N), ut("ut",N); 31 | 32 | // The vector field V 33 | template T V(const T& ss) 34 | { 35 | T sum(0); 36 | for(int i=0;i 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | Symbolic Z(const Symbolic &V1, const Symbolic &V2, 29 | const Symbolic &x1, const Symbolic &x2, const Symbolic &P) 30 | { return V1 * df(P, x1) + V2 * df(P, x2); } 31 | 32 | int main(void) 33 | { 34 | int n = 4; 35 | Symbolic Q1("Q1"), Q2("Q2"), V1("V1"), V2("V2"), x1("x1"), x2("x2"), ep("ep"); 36 | 37 | Q1 = Q1[x1,x2]; 38 | Q2 = Q2[x1,x2]; 39 | V1 = V1[x1,x2]; 40 | V2 = V2[x1,x2]; 41 | 42 | Symbolic SD1= ep * Z(V1, V2, x1, x2, Q1); 43 | Symbolic SD2= ep * Z(V1, V2, x1, x2, Q2); 44 | Symbolic RES1 = Q1 + ep * Z(V1, V2, x1, x2, Q2); 45 | Symbolic RES2 = Q1 + ep * Z(V1, V2, x1, x2, Q2); 46 | 47 | for(int j=1;j<=n;j++) 48 | { 49 | SD1 = ep * Z(V1, V2, x1, x2, SD1) / (j + 1); 50 | SD2 = ep * Z(V1, V2, x1, x2, SD2) / (j + 1); 51 | RES1 = RES1 + SD1; 52 | RES2 = RES2 + SD2; 53 | } 54 | 55 | cout << "RES1 = " << RES1 << endl << endl; 56 | cout << "RES2 = " << RES2 << endl << endl; 57 | 58 | Symbolic F1 = RES1[V1 == x1 - x1*x2, V2 == -x2 + x1*x2]; 59 | Symbolic F2 = RES2[V1 == x1 - x1*x2, V2 == -x2 + x1*x2]; 60 | 61 | cout << "F1 = " << F1[Q1 == x1, Q2 == x2] << endl << endl; 62 | cout << "F2 = " << F2[Q1 == x1, Q2 == x2] << endl; 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /examples/jacobi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // jacobi.cpp 23 | 24 | #include 25 | #include 26 | using namespace std; 27 | 28 | // forward declaration 29 | void scdn(double,double,double,double&,double&,double&); 30 | 31 | int main(void) 32 | { 33 | double x = 3.14159, k, k2, eps = 0.01, res1, res2, res3; 34 | 35 | //sin,cos,1 of x 36 | k = 0.0; 37 | k2 = k*k; 38 | scdn(x,k2,eps,res1,res2,res3); 39 | cout << "sin(x) = " << res1 << endl; 40 | cout << "cos(x) = " << res2 << endl; 41 | cout << "1(x) = " << res3 << endl; 42 | 43 | //tanh,sech,sech of x 44 | k = 1.0; 45 | k2 = k*k; 46 | scdn(x,k2,eps,res1,res2,res3); 47 | cout << "tanh(x) = " << res1 << endl; 48 | cout << "sech(x) = " << res2 << endl; 49 | cout << "sech(x) = " << res3 << endl; 50 | } 51 | 52 | void scdn(double x,double k2,double eps,double &s,double &c,double &d) 53 | { 54 | if(fabs(x) < eps) 55 | { 56 | double x2 = x*x/2.0; 57 | s = x*(1.0 - (1.0 + k2)*x2/3.0); 58 | c = 1.0 - x2; 59 | d = 1.0 - k2*x2; 60 | } 61 | else 62 | { 63 | double sh,ch,dh; 64 | 65 | scdn(x/2.0,k2,eps,sh,ch,dh); // recursive call 66 | 67 | double sh2 = sh*sh; 68 | double sh4 = k2*sh2*sh2; 69 | double denom = 1.0 - sh4; 70 | 71 | s = 2.0*sh*ch*dh/denom; 72 | c = (1.0 - 2.0*sh2+sh4)/denom; 73 | d = (1.0 - 2.0*k2*sh2+sh4)/denom; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /examples/ruelle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // ruelle.cpp 23 | 24 | #include 25 | #include 26 | #include "symbolicc++.h" 27 | using namespace std; 28 | 29 | template T f(T x,T y,T r) 30 | { return r*(T(3)*y+T(1))*x*(T(1)-x); } 31 | 32 | template T g(T x,T y,T r) 33 | { return r*(T(3)*x+T(1))*y*(T(1)-y); } 34 | 35 | int main(void) 36 | { 37 | int T = 1000; // number of iterations 38 | double x2, y2, u2, v2; 39 | Symbolic x("x"), x1("x1"), y("y"), y1("y1"), r("r"), 40 | u("u"), u1("u1"), v("v"), v1("v1"); 41 | x1 = f(x,y,r); y1 = g(x,y,r); 42 | cout << "x1 = " << x1 << endl; 43 | cout << "y1 = " << y1 << endl; 44 | u1 = df(x1,x)*u + df(x1,y)*v; // variational equation 45 | v1 = df(y1,y)*v + df(y1,x)*u; // variational equation 46 | cout << "u1 = " << u1 << endl; 47 | cout << "v1 = " << v1 << endl; cout << endl; 48 | 49 | // initial values 50 | Equations values = (x == 0.3, y == 0.4, r == 1.0834, u == 0.5, v == 0.6); 51 | for(int t=1;t 28 | #include "symbolicc++.h" 29 | #include "legendre.h" 30 | using namespace std; 31 | 32 | class AssLegendre 33 | { 34 | private: 35 | Symbolic P; 36 | const Symbolic &x; 37 | 38 | public: 39 | AssLegendre(const Symbolic &); 40 | AssLegendre(int,int,const Symbolic &); 41 | 42 | void redefine(int,int); 43 | Symbolic current() const; 44 | 45 | friend ostream &operator << (ostream &,const AssLegendre &); 46 | }; 47 | 48 | AssLegendre::AssLegendre(const Symbolic &kernal) : x(kernal) {} 49 | 50 | AssLegendre::AssLegendre(int l,int m,const Symbolic &kernal) : x(kernal) 51 | { 52 | int i, absm = abs(m); 53 | Legendre L(l,x); 54 | P = L(l); 55 | for(i=0;i 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | // group SO(1,1) 31 | Symbolic A("A",2,2); 32 | Symbolic x("x"), x1("x1"), x2("x2"), 33 | alpha("alpha"), beta("beta"), gamma("gamma"), nu("nu"); 34 | Symbolic result; 35 | 36 | A(0,0) = cosh(x); A(0,1) = sinh(x); 37 | A(1,0) = sinh(x); A(1,1) = cosh(x); 38 | 39 | Symbolic v("v",2); 40 | v(0) = x1; v(1) = x2; 41 | 42 | Symbolic w = A * v; 43 | 44 | result = (w(0)^2) + (w(1)^2); 45 | result = result.subst(cosh(x)*cosh(x), 1 + sinh(x)*sinh(x)); 46 | cout << result << endl; 47 | 48 | // group SO(2) 49 | Symbolic B("B",2,2); 50 | Symbolic i = sqrt(Number(-1)); 51 | 52 | B(0,0) = cos(x); B(0,1) = -sin(x); 53 | B(1,0) = sin(x); B(1,1) = cos(x); 54 | 55 | Symbolic s = B * v; 56 | 57 | result = (s(0)^2) + (s(1)^2); 58 | result = result.subst(cos(x)*cos(x), 1 - sin(x)*sin(x)); 59 | cout << result << endl; 60 | 61 | // group U(2), calculating the determinant 62 | Symbolic U("U",2,2); 63 | U(0,0) = exp(i*alpha)*cos(nu); 64 | U(0,1) = exp(i*gamma)*sin(nu); 65 | U(1,0) = -exp(i*(beta-gamma))*sin(nu); 66 | U(1,1) = exp(i*(beta-alpha))*cos(nu); 67 | 68 | result = det(U); 69 | result = result.subst(cos(nu)*cos(nu), 1 - sin(nu)*sin(nu)); 70 | cout << result << endl; 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /examples/var.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // var.cpp 23 | 24 | #include 25 | #include 26 | #include "symbolicc++.h" 27 | using namespace std; 28 | 29 | Symbolic f(Symbolic &x,Symbolic &y,Symbolic &r) 30 | { return r*(3.0*y+1.0)*x*(1.0-x); } 31 | 32 | Symbolic g(Symbolic &x,Symbolic &y,Symbolic &r) 33 | { return r*(3.0*x+1.0)*y*(1.0-y); } 34 | 35 | int main(void) 36 | { 37 | int T, N = 1000; 38 | double x2, y2, u2, v2; 39 | Symbolic x("x"), x1("x1"), y("y"), y1("y1"), r("r"), 40 | u("u"), u1("u1"), v("v"), v1("v1"); 41 | 42 | x1 = f(x,y,r); 43 | y1 = g(x,y,r); 44 | 45 | cout << "x1 = " << x1 << endl; 46 | cout << "y1 = " << y1 << endl; 47 | 48 | // Variational Equation 49 | u1 = df(x1,x)*u + df(x1,y)*v; 50 | v1 = df(y1,y)*v + df(y1,x)*u; 51 | 52 | cout << "u1 = " << u1 << endl; 53 | cout << "v1 = " << v1 << endl; 54 | cout << endl; 55 | 56 | // Calculation of the Ljapunov exponent by iterating the four equations. 57 | 58 | // Initial values 59 | Equations values = (x==0.3,y==0.4,r==1.0834,u==0.5,v==0.6); 60 | 61 | for(T=1;T 26 | #include "symbolicc++.h" 27 | using namespace std; 28 | 29 | int main(void) 30 | { 31 | Symbolic om("om"), ts("ts"), u1("u1"), u2("u2"), u1d("u1d"), u2d("u2d"), 32 | u1dd("u1dd"), u2dd("u2dd"); 33 | 34 | Symbolic L = ((u1d^2) + (u2d^2))/2 35 | + om*(u1*u2d - u1d*u2) 36 | + om*(u1*u1d + u2*u2d)*tan(om*ts) 37 | + (om^2)*((u1^2) + (u2^2))*(sec(om*ts)^2)/2; 38 | 39 | Symbolic LUD1 = df(L, u1d); 40 | Symbolic res1 = df(LUD1, ts) 41 | + u1d*df(LUD1, u1) 42 | + u1dd*df(LUD1, u1d) - df(L, u1); 43 | 44 | Symbolic LUD2 = df(L, u2d); 45 | Symbolic res2 = df(LUD2, ts) 46 | + u2d*df(LUD2, u2) 47 | + u2dd*df(LUD2, u2d) - df(L, u2); 48 | 49 | res1 = res1[(sec(om*ts)^2) == 1 + (tan(om*ts)^2)]; 50 | res2 = res2[(sec(om*ts)^2) == 1 + (tan(om*ts)^2)]; 51 | res1 = res1[(sin(om*ts)^2) == 1 - (cos(om*ts)^2)]; 52 | res2 = res2[(sin(om*ts)^2) == 1 - (cos(om*ts)^2)]; 53 | 54 | cout << "res1 = " << res1 << endl; 55 | cout << "res2 = " << res2 << endl; 56 | 57 | Symbolic v1("v1"), v2("v2"); 58 | 59 | Symbolic eq1 = res1[ u1dd == df(v1[ts], ts, 2), u2d == df(v2[ts], ts) ]; 60 | Symbolic eq2 = res2[ u2dd == df(v2[ts], ts, 2), u1d == df(v1[ts], ts) ]; 61 | 62 | cout << "eq1 = " << eq1 << endl; 63 | cout << "eq2 = " << eq2 << endl; 64 | 65 | return 0; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /examples/legendre.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // legendre.h 23 | // Recursion formula (n+1)P_{n+1}(x) = (2n+1)xP_n(x)-nP_{n-1}(x) 24 | 25 | #include 26 | #include 27 | #include "symbolicc++.h" 28 | using namespace std; 29 | 30 | class Legendre 31 | { 32 | private: 33 | int maxTerm, currentStep; 34 | Symbolic P, Q; 35 | const Symbolic &x; 36 | 37 | public: 38 | Legendre(int,const Symbolic&); 39 | int step(); 40 | void run(); 41 | void reset(); 42 | Symbolic current() const; 43 | Symbolic operator () (int); 44 | friend ostream & operator << (ostream &,const Legendre&); 45 | }; 46 | 47 | Legendre::Legendre(int n, const Symbolic &kernal) 48 | : maxTerm(n), currentStep(0), P(1), x(kernal) {} 49 | 50 | int Legendre::step() 51 | { 52 | int prev = currentStep; 53 | Symbolic R, one(1); 54 | ++currentStep; 55 | if(currentStep==1) { Q = one; P = x; return 1; } 56 | if(currentStep <= maxTerm) 57 | { 58 | R = (prev+currentStep)*x*P/currentStep-prev*Q/currentStep; 59 | Q = P; P = R; 60 | return 1; 61 | } 62 | return 0; 63 | } 64 | 65 | void Legendre::run() { while(step()); } 66 | 67 | void Legendre::reset() { currentStep = 0; P = 1; } 68 | 69 | Symbolic Legendre::current() const { return P; } 70 | 71 | Symbolic Legendre::operator () (int m) 72 | { 73 | assert(m <= maxTerm); 74 | reset(); 75 | for(int i=0;i= 0) P(i,j) = Q(i,j) = a(k); 56 | else P(i,j) = Q(i,j) = 0; 57 | } 58 | 59 | for(i=0;i= 0) P(N,i) += a(k)*(x^j); 65 | } 66 | Q(N,i) = x^(N-i); 67 | } 68 | y = det(P); z = det(Q); 69 | return y/z; 70 | } 71 | 72 | int main(void) 73 | { 74 | Symbolic x("x"), f; 75 | f = sin(x); 76 | cout << Pade(f,x,1,1) << endl; // => x 77 | cout << Pade(f,x,2,2) << endl; // => -1/6*x*(-1/6-1/36*x^2)^(-1) 78 | cout << Pade(f,x,3,3) << endl; 79 | // => (-7/2160*x+1589885/3306816*x^3)*(-7/2160-7/43200*x^2)^(-1) 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /lisp/lambda/builtin_math.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // builtin_math.h 23 | 24 | #ifndef BUILTIN_MATH_H 25 | #define BUILTIN_MATH_H 26 | 27 | expression builtin_sin(expression &e,environment &env) 28 | { 29 | if(e.tokens.size()!=2) 30 | { 31 | cerr << "Error: incorrect number of arguments to sin\n"; 32 | return expression("#error"); 33 | } 34 | return expression(sin(e.tokens[1].numeric(env))); 35 | } 36 | 37 | expression builtin_cos(expression &e,environment &env) 38 | { 39 | if(e.tokens.size()!=2) 40 | { 41 | cerr << "Error: incorrect number of arguments to cos\n"; 42 | return expression("#error"); 43 | } 44 | return expression(cos(e.tokens[1].numeric(env))); 45 | } 46 | 47 | expression builtin_exp(expression &e,environment &env) 48 | { 49 | if(e.tokens.size()!=2) 50 | { 51 | cerr << "Error: incorrect number of arguments to exp\n"; 52 | return expression("#error"); 53 | } 54 | return expression(exp(e.tokens[1].numeric(env))); 55 | } 56 | 57 | expression builtin_log(expression &e,environment &env) 58 | { 59 | if(e.tokens.size()!=2) 60 | { 61 | cerr << "Error: incorrect number of arguments to log\n"; 62 | return expression("#error"); 63 | } 64 | return expression(log(e.tokens[1].numeric(env))); 65 | } 66 | 67 | expression builtin_sqrt(expression &e,environment &env) 68 | { 69 | if(e.tokens.size()!=2) 70 | { 71 | cerr << "Error: incorrect number of arguments to sqrt\n"; 72 | return expression("#error"); 73 | } 74 | return expression(sqrt(e.tokens[1].numeric(env))); 75 | } 76 | #endif 77 | -------------------------------------------------------------------------------- /lisp/differ.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; differ.lisp 23 | 24 | (defun diff (ex v) ; d(ex)/dv 25 | (cond 26 | ((atom ex) 27 | (cond ((eq ex v) 1) (t 0))) ; d(v)/dv = 1, d(constant)/dv = 0 28 | 29 | ((eq (car ex) '+) ; d(a+b)/dv = da/dv + db/dv 30 | (list '+ (diff (cadr ex) v) (diff (caddr ex) v))) 31 | 32 | ((eq (car ex) '*) ; d(a*b)/dv = da/dv * b + a * db/dv 33 | (list '+ 34 | (list '* (diff (cadr ex) v) (caddr ex)) 35 | (list '* (cadr ex) (diff (caddr ex) v)))) 36 | 37 | ((eq (car ex) '/) ; d(a/b)/dv = (da/dv)/b - (a/b*b)*db/dv 38 | (list '- 39 | (list '/ (diff (cadr ex) v) (caddr ex)) 40 | (list '* `(/ ,(cadr ex) (* ,(caddr ex) ,(caddr ex))) 41 | (diff (caddr ex) v)))) 42 | 43 | ((eq (car ex) '-) ; d(a-b)/dv = da/dv - db/dv 44 | (list '- (diff (cadr ex) v) (diff (caddr ex) v))) 45 | 46 | ((atom (car ex)) ; d/dv f(a) = f'(a) da/dv 47 | (let ( (form (assoc (car ex) '( (exp (exp x)) 48 | (sin (cos x)) 49 | (cos (- (sin x))) 50 | (ln (/ 1 x)) ))) ) 51 | (list '* (if form (subst (cadr ex) 'x (cadr form)) 52 | `(diff ,(car ex) ,v)) 53 | (diff (cadr ex) v)))))) 54 | -------------------------------------------------------------------------------- /lisp/simp2.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;; SymbolicC++ : An object oriented computer algebra system written in C++ 4 | ;; 5 | ;; Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 6 | ;; 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation; either version 2 of the License, or 10 | ;; (at your option) any later version. 11 | ;; 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | ;; 17 | ;; You should have received a copy of the GNU General Public License along 18 | ;; with this program; if not, write to the Free Software Foundation, Inc., 19 | ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | ; simp2.lisp 23 | 24 | (defun simp (f) 25 | (cond 26 | ((atom f) f) ; f is an atom 27 | ((null (cdr f)) (simp (car f))) ; f has only one element 28 | ((null (cddr f)) (simp-unary f)) ; f has two elements 29 | (t (quote cannot_simplify)) )) ; f has more than two elements 30 | 31 | (defun simp-unary (f) 32 | (let* ( (op (car f)) 33 | (opd (simp (cadr f))) ; local variables : op, opd, zp 34 | (z? (and (numberp opd) (zerop opd))) ; zero 35 | (o? (equal 1 opd)) ; one 36 | (p? (equal 'pi opd)) ) ; pi 37 | (cond 38 | ((eq op '+) opd) ; + x => x 39 | ((and (eq op '-) z?) 0) ; - 0 => 0 40 | ((and (eq op 'exp) z?) 1) ; exp(0) => 1 41 | ((and (eq op 'log) o?) 0) ; log(1) => 0 42 | ((and (eq op 'sin) z?) 0) ; sin(0) => 0 43 | ((and (eq op 'cos) z?) 1) ; cos(0) => 1 44 | ((and (eq op 'sin) p?) 0) ; sin(pi) => 0 45 | ((and (eq op 'cos) p?) -1) ; cos(pi) =>-1 46 | ((and (eq op 'arcsin) z?) 0) ; arcsin(0) => 0 47 | ((and (eq op 'arctan) z?) 0) ; arctan(0) => 0 48 | ((and (eq op 'sinh) z?) 0) ; sinh(0) => 0 49 | ((and (eq op 'cosh) z?) 1) ; cosh(0) => 1 50 | (t (list op opd))))) 51 | -------------------------------------------------------------------------------- /examples/lax.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // lax.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | Symbolic L("L",3,3), A("A",3,3), Lt("Lt",3,3); // Lt=dL/dt 31 | Symbolic a1("a1"), a2("a2"), b1("b1"), b2("b2"), b3("b3"), 32 | a1t, a2t, b1t, b2t, b3t; 33 | 34 | L(0,0) = b1; L(0,1) = a1; L(0,2) = 0; 35 | L(1,0) = a1; L(1,1) = b2; L(1,2) = a2; 36 | L(2,0) = 0; L(2,1) = a2; L(2,2) = b3; 37 | A(0,0) = 0; A(0,1) = -a1; A(0,2) = 0; 38 | A(1,0) = a1; A(1,1) = 0; A(1,2) = -a2; 39 | A(2,0) = 0; A(2,1) = a2; A(2,2) = 0; 40 | 41 | Lt = A*L - L*A; 42 | cout << "Lt =\n" << Lt << endl; 43 | 44 | b1t = Lt(0,0); b2t = Lt(1,1); b3t = Lt(2,2); 45 | a1t = Lt(0,1); a2t = Lt(1,2); 46 | cout << "b1t = " << b1t << ", b2t = " << b2t 47 | << ", b3t = " << b3t << endl; 48 | cout << "a1t = " << a1t << ", a2t = " << a2t << endl; 49 | cout << endl; 50 | 51 | // Show that I(0),I(1),I(2) are first integrals 52 | int n = 3; 53 | Symbolic result; 54 | Symbolic I("I",n); 55 | 56 | I(0) = L.trace(); cout << "I(0) = " << I(0) << endl; 57 | I(1) = (L*L).trace(); cout << "I(1) = " << I(1) << endl; 58 | I(2) = L.determinant(); cout << "I(2) = " << I(2) << endl; 59 | cout << endl; 60 | 61 | for(int i=0;i z1(1.0,-2.0); 33 | complex z2(3.0,4.0); 34 | complex v; 35 | complex w; 36 | v = z1 + z2; 37 | cout << "v = " << v << endl; 38 | w = z1*z2; 39 | cout << "w = " << w << endl; 40 | 41 | complex pi(3.141592653589793235360287); 42 | complex i(0,1); 43 | cout << exp(pi*i) - 1.0 << endl; 44 | 45 | Verylong two("2"); 46 | Verylong three("3"); 47 | Verylong four("4"); 48 | Verylong five("5"); 49 | complex u1(two,three); 50 | complex u2(four,five); 51 | complex u3; 52 | u3 = u1 + u2; 53 | cout << "u3 = " << u3 << endl; 54 | 55 | complex a(2.0,3.0); 56 | complex b(1.0,-4.0); 57 | complex > c(a,b); 58 | cout << "c = " << c << endl; 59 | complex d(-3.5,7.0); 60 | complex e(2.5,-5.5); 61 | complex > f(d,e); 62 | complex > h; 63 | h = c + f; 64 | cout << "h = " << h << endl; 65 | 66 | double rparta = a.real(); 67 | cout << "rparta = " << rparta << endl; 68 | double iparta = a.imag(); 69 | cout << "iparta = " << iparta << endl; 70 | 71 | complex sz = sin(a); 72 | cout << "sz = " << sz << endl; 73 | 74 | // principle branch 75 | cout << "log(i) = " << log(i) << endl; 76 | cout << "i^i = " << pow(i,i) << endl; 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /examples/contract.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // contract.cpp 23 | 24 | #include 25 | #include "rational.h" 26 | #include "verylong.h" 27 | using namespace std; 28 | 29 | class Map 30 | { 31 | private: 32 | Rational (*function)(Rational); 33 | Rational value; // current iterated value 34 | 35 | public: 36 | Map(Rational (*f)(Rational), Rational); 37 | void operator ++ (); // next iteration 38 | void Is_FP(); // Is there a fixed point? 39 | }; 40 | 41 | Map::Map(Rational (*f)(Rational), 42 | Rational x0) : function(f), value(x0) {} 43 | 44 | void Map::operator ++ () { value = (*function)(value); } 45 | 46 | // Is there a fixed point? 47 | void Map::Is_FP() 48 | { 49 | Rational temp, // the value in previous step 50 | dist; // the relative difference 51 | // between previous and current step 52 | do 53 | { 54 | temp = value; 55 | ++(*this); 56 | dist = abs((value-temp)/temp); // the relative difference 57 | cout << "Value : " << value << " or " << double(value) << endl; 58 | cout << endl; 59 | } while(double(dist) > 1e-5); 60 | } 61 | 62 | // f(x) = 5/2 x(1-x) 63 | Rational mapping(Rational x) 64 | { 65 | return (Rational("5/2")*x*(Rational("1")-x)); 66 | } 67 | 68 | int main(void) 69 | { 70 | // initial value = 9/10 71 | Map M(mapping, Rational(Verylong("9"),Verylong("10"))); 72 | M.Is_FP(); 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /examples/chebyshev.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // chebyshev.cpp 23 | // Recursion formula T_{n+1}(x) = 2xT_n(x)-T_{n-1}(x) 24 | 25 | #include 26 | #include "symbolicc++.h" 27 | using namespace std; 28 | 29 | class Chebyshev 30 | { 31 | private: 32 | int maxTerm, currentStep; 33 | Symbolic P, Q; 34 | const Symbolic &x; 35 | public: 36 | Chebyshev(int,const Symbolic&); 37 | int step(); 38 | void run(); 39 | Symbolic current() const; 40 | friend ostream & operator << (ostream&,const Chebyshev&); 41 | }; 42 | 43 | Chebyshev::Chebyshev(int n,const Symbolic &kernal) 44 | : maxTerm(n), currentStep(0), P(1), x(kernal) {} 45 | 46 | int Chebyshev::step() 47 | { 48 | Symbolic R; 49 | ++currentStep; 50 | 51 | if(currentStep==1) { Q = 1; P = x; return 1; } 52 | 53 | if(currentStep <= maxTerm) 54 | { 55 | R = 2*x*P-Q; Q = P; P = R; return 1; 56 | } 57 | return 0; 58 | } 59 | 60 | void Chebyshev::run() { while(step()); } 61 | 62 | Symbolic Chebyshev::current() const { return P; } 63 | 64 | ostream & operator << (ostream &s,const Chebyshev &T) 65 | { return s << T.P; } 66 | 67 | int main(void) 68 | { 69 | int n=4; 70 | Symbolic x("x"); 71 | Chebyshev T(n,x); 72 | 73 | // Calculate the first few Chebyshev polynomials 74 | cout << "T(0) = " << T << endl; 75 | for(int i=1;i<=n;i++) 76 | { 77 | T.step(); 78 | cout << "T("<< i << ") = " << T << endl; 79 | } 80 | cout << endl; 81 | 82 | // Show that the Chebyshev differential equation is satisfiedi for n=4. 83 | Symbolic result; 84 | 85 | result = (1-x*x)*df(T.current(),x,2)-x*df(T.current(),x)+n*n*T.current(); 86 | cout << result << endl; 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /examples/cumu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // cumu.cpp 23 | 24 | #include 25 | #include "symbolicc++.h" 26 | using namespace std; 27 | 28 | Symbolic Taylor(Symbolic u,const Symbolic &x,int n) 29 | { 30 | Symbolic series = u[x==0]; 31 | int fac = 1; 32 | 33 | for(int j=1;j<=n;j++) 34 | { 35 | u = df(u,x); fac = fac * j; 36 | series += (u[x==0]*(x^j)/fac); 37 | } 38 | return series; 39 | } 40 | 41 | int main(void) 42 | { 43 | int fac, n=5; 44 | Symbolic x("x"), a("a",5), b("b",5); 45 | Symbolic y, P, Q; 46 | 47 | fac = 1; P = a(0); Q = 0; 48 | for(int i=1;i " << y.coeff(x,1) << endl; 65 | cout << " P => " << P.coeff(x,1) << endl; 66 | cout << endl; 67 | 68 | cout << "Coefficient of x^2 :"<< endl; 69 | cout << "exp(Q) => " << y.coeff(x,2) << endl; 70 | cout << " P => " << P.coeff(x,2) << endl; 71 | cout << endl; 72 | 73 | cout << "Coefficient of x^3 :"<< endl; 74 | cout << "exp(Q) => " << y.coeff(x,3) << endl; 75 | cout << " P => " << P.coeff(x,3) << endl; 76 | cout << endl; 77 | 78 | cout << "Coefficient of x^4 :"<< endl; 79 | cout << "exp(Q) => " << y.coeff(x,4) << endl; 80 | cout << " P => " << P.coeff(x,4) << endl; 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /examples/mystring.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // mystring.cpp 23 | 24 | #include 25 | #include 26 | using namespace std; 27 | 28 | int main(void) 29 | { 30 | string str1("The string class provides C++"); 31 | string str2(" with string handling."); 32 | string str3; 33 | 34 | // assignment 35 | str3 = str1; 36 | cout << str3 << endl; // => The string class provides C++ 37 | 38 | // comparison 39 | int result = (str1 != str2); 40 | cout << "result = " << result << endl; // => 1 (true) 41 | 42 | // concatenate two strings using overloaded + 43 | str3 = str1 + str2; 44 | cout << str3 << endl; 45 | 46 | // length of string 47 | unsigned long a = str3.length(); 48 | cout << "length of string str3 = " << a << endl; // => 51 49 | cout << "length of string str3 = " << str3.size() << endl; // => 51 50 | 51 | bool b = str1.empty(); 52 | cout << "b = " << b << endl; // => 0 (false) 53 | 54 | string str4("Good Morning Egoli"); 55 | string str5("XYZ1234"); 56 | 57 | cout << "Initial string:\n"; 58 | cout << "str4: " << str4 << endl; 59 | cout << "str5: " << str5 << endl; 60 | 61 | // method insert 62 | cout << "insert str5 into str4:\n"; 63 | str4.insert(5,str5); 64 | cout << str4 << "\n"; // => Good XYZ1234Morning Egoli 65 | 66 | // method erase 67 | cout << "remove 7 characters from str4:\n"; 68 | str4.erase(5,7); 69 | cout << str4 << "\n"; // => Good Morning Egoli 70 | 71 | // method replace 72 | cout << "replace 2 characters in str4 with str5:\n"; 73 | str4.replace(5,2,str5); 74 | cout << str4 << endl; // => Good XYZ1234rning Egoli 75 | 76 | // substring 77 | cout << "substring = " << str4.substr(2,5); // => od XY 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /examples/cantor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // cantor.cpp 23 | 24 | #include 25 | #include "rational.h" 26 | #include "verylong.h" 27 | #include "vector.h" 28 | using namespace std; 29 | 30 | const Rational a = Rational("0"); // lower limit 31 | const Rational b = Rational("1"); // upper limit 32 | 33 | class Cantor 34 | { 35 | private: 36 | Vector > CS; 37 | int currentSize; 38 | public: 39 | Cantor(int); 40 | Cantor(const Cantor&); // copy constructor 41 | int step(); 42 | void run(); 43 | friend ostream& operator << (ostream&,const Cantor&); 44 | }; 45 | 46 | Cantor::Cantor(int numStep) : CS((int)pow(2.0,numStep+1)), currentSize(2) 47 | { CS[0] = a; CS[1] = b; } 48 | 49 | Cantor::Cantor(const Cantor& s) 50 | : CS(s.CS), currentSize(s.currentSize) { } 51 | 52 | int Cantor::step() 53 | { 54 | int i, newSize; 55 | static Rational three(3), tt(2,3); 56 | static int maxSize = CS.size(); 57 | 58 | if(currentSize < maxSize) 59 | { 60 | for(i=0;i 26 | #include "symbolicc++.h" 27 | using namespace std; 28 | 29 | class Hermite 30 | { 31 | private: 32 | int maxTerm, currentStep; 33 | Symbolic P, Q; 34 | const Symbolic &x; 35 | public: 36 | Hermite(int,const Symbolic&); 37 | int step(); 38 | void run(); 39 | Symbolic current() const; 40 | friend ostream & operator << (ostream&,const Hermite&); 41 | }; 42 | 43 | Hermite::Hermite(int n,const Symbolic &kernal) 44 | : maxTerm(n), currentStep(0), P(1), x(kernal) {} 45 | 46 | int Hermite::step() 47 | { 48 | int prev = currentStep; 49 | Symbolic R; 50 | ++currentStep; 51 | 52 | if(currentStep==1) 53 | { Q = 1; P = 2*x; return 1; } 54 | 55 | if(currentStep <= maxTerm) 56 | { 57 | R = 2*x*P-2*prev*Q; 58 | Q = P; 59 | P = R; 60 | return 1; 61 | } 62 | return 0; 63 | } 64 | 65 | void Hermite::run() { while(step()); } 66 | 67 | Symbolic Hermite::current() const { return P; } 68 | 69 | ostream & operator << (ostream &s,const Hermite &H) 70 | { return s << H.P; } 71 | 72 | int main(void) 73 | { 74 | int n=4; 75 | Symbolic x("x"); 76 | Hermite H(n,x); 77 | 78 | // Calculate the first few Hermite polynomials 79 | cout << "H(0) = " << H << endl; 80 | for(int i=1;i<=n;i++) 81 | { 82 | H.step(); 83 | cout << "H("<< i << ") = " << H << endl; 84 | } 85 | cout << endl; 86 | 87 | // Show that the Hermite differential equation is satisfied for n=4. 88 | Symbolic result; 89 | 90 | result = df(H.current(),x,2)-2*x*df(H.current(),x)+2*n*H.current(); 91 | 92 | cout << result << endl; 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /headers/identity.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This library is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | #ifndef IDENTITY_H 23 | #define IDENTITY_H 24 | 25 | #include 26 | #include 27 | #include 28 | using namespace std; 29 | 30 | template T zero(T) { static const T z = T() - T(); return z; } 31 | 32 | template T one(T) 33 | { 34 | static T z(zero(T())); 35 | static const T o = ++z; 36 | return o; 37 | } 38 | 39 | template <> char zero(char); 40 | template <> char one(char); 41 | template <> short zero(short); 42 | template <> short one(short); 43 | template <> int zero(int); 44 | template <> int one(int); 45 | template <> long zero(long); 46 | template <> long one(long); 47 | template <> float zero(float); 48 | template <> float one(float); 49 | template <> double zero(double); 50 | template <> double one(double); 51 | 52 | #define LIBSYMBOLICCPLUSPLUS 53 | 54 | template <> char zero(char) { return (char) 0; } 55 | template <> char one(char) { return (char) 1; } 56 | 57 | template <> short zero(short) { return (short) 0; } 58 | template <> short one(short) { return (short) 1; } 59 | 60 | template <> int zero(int) { return (int) 0; } 61 | template <> int one(int) { return (int) 1; } 62 | 63 | template <> long zero(long) { return (long) 0; } 64 | template <> long one(long) { return (long) 1; } 65 | 66 | template <> float zero(float) { return (float) 0.0; } 67 | template <> float one(float) { return (float) 1.0; } 68 | 69 | template <> double zero(double) { return (double) 0.0; } 70 | template <> double one(double) { return (double) 1.0; } 71 | 72 | #undef LIBSYMBOLICCPLUSPLUS 73 | 74 | template 75 | complex zero(complex) { return complex(zero(T())); } 76 | 77 | template 78 | complex one(complex) { return complex(one(T())); } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /examples/laguerre.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // laguerre.cpp 23 | // Recursion formula L_{n+1}(x) = (2n+1-x)L_n(x)-n^2L_{n-1}(x) 24 | 25 | #include 26 | #include "symbolicc++.h" 27 | using namespace std; 28 | 29 | class Laguerre 30 | { 31 | private: 32 | int maxTerm, currentStep; 33 | Symbolic P, Q; 34 | const Symbolic &x; 35 | 36 | public: 37 | Laguerre(int,const Symbolic&); 38 | 39 | int step(); 40 | void run(); 41 | Symbolic current() const; 42 | friend ostream & operator << (ostream&,const Laguerre&); 43 | }; 44 | 45 | Laguerre::Laguerre(int n,const Symbolic &kernal) 46 | : maxTerm(n), currentStep(0), P(1), x(kernal) {} 47 | 48 | int Laguerre::step() 49 | { 50 | int prev = currentStep; 51 | Symbolic R; 52 | ++currentStep; 53 | if(currentStep==1) { Q = 1; P = 1-x; return 1; } 54 | if(currentStep <= maxTerm) 55 | { 56 | R = (2*prev+1-x)*P-prev*prev*Q; 57 | Q = P; P = R; 58 | return 1; 59 | } 60 | return 0; 61 | } 62 | 63 | void Laguerre::run() { while(step()) ; } 64 | 65 | Symbolic Laguerre::current() const { return P; } 66 | 67 | ostream & operator << (ostream & s, const Laguerre & L) 68 | { return s << L.P; } 69 | 70 | int main(void) 71 | { 72 | int n=4; 73 | Symbolic x("x"); 74 | Laguerre L(n,x); 75 | 76 | // Calculate the first few Laguerre polynomials 77 | cout << "L(0) = " << L << endl; 78 | 79 | for(int i=1;i<=n;i++) 80 | { 81 | L.step(); 82 | cout << "L("<< i << ") = " << L << endl; 83 | } 84 | cout << endl; 85 | 86 | // Show that the Laguerre differential equation is satisfied for n = 4. 87 | Symbolic result; 88 | result = x*df(L.current(),x,2) + (1-x)*df(L.current(),x)+n*L.current(); 89 | cout << result << endl; 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /examples/lorenzfix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // lorenzfix.cpp 23 | 24 | #include 25 | #include 26 | #include "symbolicc++.h" 27 | using namespace std; 28 | 29 | int main(void) 30 | { 31 | int i, j; 32 | Symbolic u("u",3), V("V",3), A("A",3,3), s("s"), b("b"), r("r"); 33 | 34 | V(0) = s*(u(1) - u(0)); // Lorenz model 35 | V(1) = -u(0)*u(2) + r*u(0) - u(1); // Lorenz model 36 | V(2) = u(0)*u(1) - b*u(2); // Lorenz model 37 | 38 | for(i=0;i<3;i++) 39 | for(j=0;j<3;j++) 40 | A(i,j) = df(V(i),u(j)); 41 | 42 | Symbolic lambda("lambda"); 43 | Symbolic chareq; 44 | 45 | // characteristic equation 46 | chareq = det(lambda*A.identity() - A); 47 | 48 | // coefficients 49 | Symbolic c0 = chareq.coeff(lambda,0); 50 | Symbolic c1 = chareq.coeff(lambda,1); 51 | Symbolic c2 = chareq.coeff(lambda,2); 52 | 53 | Symbolic Q = (3*c1 - c2*c2)/9; 54 | Symbolic R = (9*c2*c1 - 27*c0 - 2*c2*c2*c2)/54; 55 | Symbolic D = Q*Q*Q + R*R; 56 | 57 | // parameter values 58 | Equations values = (s == 16.0, b == 4.0, r == 40.0); 59 | 60 | // fixed point (0,0,0) 61 | values = (values, u(0) == 0.0, u(1) == 0.0, u(2) == 0.0); 62 | 63 | double q = Q[values]; 64 | double rR = R[values]; 65 | double d = D[values]; 66 | double nc2 = c2[values]; 67 | 68 | if(rR != 0 && q < 0 && d <= 0.0) 69 | { 70 | double theta = acos(rR/sqrt(-q*q*q)); 71 | double PI = 3.14159; 72 | double lamb1 = 2.0*sqrt(-q)*cos(theta/3.0) - nc2/3.0; 73 | double lamb2 = 2.0*sqrt(-q)*cos((theta+2.0*PI)/3.0)-nc2/3.0; 74 | double lamb3 = 2.0*sqrt(-q)*cos((theta+4.0+PI)/3.0)-nc2/3.0; 75 | 76 | cout << "lamb1 = " << lamb1 << endl; 77 | cout << "lamb2 = " << lamb2 << endl; 78 | cout << "lamb3 = " << lamb3 << endl; 79 | } 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /headers/vecnorm.h: -------------------------------------------------------------------------------- 1 | /* 2 | SymbolicC++ : An object oriented computer algebra system written in C++ 3 | 4 | Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb 5 | 6 | This library is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | 22 | // vecnorm.h 23 | // Norms of Vectors 24 | 25 | #ifndef MVECNORM_H 26 | #define MVECNORM_H 27 | 28 | #include 29 | #include 30 | #include "vector.h" 31 | using namespace std; 32 | 33 | template T norm1(const Vector &v) 34 | { 35 | T result(0); 36 | for(int i=0;i &v); 41 | 42 | #define LIBSYMBOLICCPLUSPLUS 43 | double norm1(const Vector &v) 44 | { 45 | double result(0); 46 | for(int i=0;i double norm2(const Vector &v) 52 | { 53 | T result(0); 54 | for(int i=0;i T normI(const Vector &v) 59 | { 60 | T maxItem(abs(v[0])), temp; 61 | for(int i=1;i maxItem) maxItem = temp; 65 | } 66 | return maxItem; 67 | } 68 | 69 | double normI(const Vector &v); 70 | 71 | #define LIBSYMBOLICCPLUSPLUS 72 | double normI(const Vector &v) 73 | { 74 | double maxItem(fabs(v[0])), temp; 75 | for(int i=1;i maxItem) maxItem = temp; 79 | } 80 | return maxItem; 81 | } 82 | #undef LIBSYMBOLICCPLUSPLUS 83 | 84 | template Vector normalize(const Vector &v) 85 | { 86 | Vector result(v.size()); 87 | double length = norm2(v); 88 | for(int i=0;i