Diff of the two buildlogs: -- --- b1/build.log 2023-06-08 22:17:54.536578102 +0000 +++ b2/build.log 2023-06-08 23:13:21.679054784 +0000 @@ -1,6 +1,6 @@ I: pbuilder: network access will be disabled during build -I: Current time: Thu Jun 8 08:51:16 -12 2023 -I: pbuilder-time-stamp: 1686257476 +I: Current time: Fri Jun 9 12:18:13 +14 2023 +I: pbuilder-time-stamp: 1686262693 I: Building the build Environment I: extracting base tarball [/var/cache/pbuilder/bookworm-reproducible-base.tgz] I: copying local configuration @@ -16,7 +16,7 @@ I: copying [./octave-symbolic_3.0.1.orig.tar.gz] I: copying [./octave-symbolic_3.0.1-2.debian.tar.xz] I: Extracting source -gpgv: Signature made Mon Dec 5 05:22:03 2022 -12 +gpgv: Signature made Tue Dec 6 07:22:03 2022 +14 gpgv: using RSA key 3F464391498FE874BDB5D98F2124AA1983785C90 gpgv: issuer "rafael@debian.org" gpgv: Can't check signature: No public key @@ -26,135 +26,167 @@ dpkg-source: info: unpacking octave-symbolic_3.0.1-2.debian.tar.xz I: Not using root during the build. I: Installing the build-deps -I: user script /srv/workspace/pbuilder/16123/tmp/hooks/D02_print_environment starting +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/D01_modify_environment starting +debug: Running on virt64a. +I: Changing host+domainname to test build reproducibility +I: Adding a custom variable just for the fun of it... +I: Changing /bin/sh to bash +'/bin/sh' -> '/bin/bash' +lrwxrwxrwx 1 root root 9 Jun 9 12:18 /bin/sh -> /bin/bash +I: Setting pbuilder2's login shell to /bin/bash +I: Setting pbuilder2's GECOS to second user,second room,second work-phone,second home-phone,second other +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/D01_modify_environment finished +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/D02_print_environment starting I: set - BUILDDIR='/build' - BUILDUSERGECOS='first user,first room,first work-phone,first home-phone,first other' - BUILDUSERNAME='pbuilder1' - BUILD_ARCH='armhf' - DEBIAN_FRONTEND='noninteractive' - DEB_BUILD_OPTIONS='buildinfo=+all reproducible=+all parallel=3 ' - DISTRIBUTION='bookworm' - HOME='/root' - HOST_ARCH='armhf' + BASH=/bin/sh + BASHOPTS=checkwinsize:cmdhist:complete_fullquote:extquote:force_fignore:globasciiranges:globskipdots:hostcomplete:interactive_comments:patsub_replacement:progcomp:promptvars:sourcepath + BASH_ALIASES=() + BASH_ARGC=() + BASH_ARGV=() + BASH_CMDS=() + BASH_LINENO=([0]="12" [1]="0") + BASH_LOADABLES_PATH=/usr/local/lib/bash:/usr/lib/bash:/opt/local/lib/bash:/usr/pkg/lib/bash:/opt/pkg/lib/bash:. + BASH_SOURCE=([0]="/tmp/hooks/D02_print_environment" [1]="/tmp/hooks/D02_print_environment") + BASH_VERSINFO=([0]="5" [1]="2" [2]="15" [3]="1" [4]="release" [5]="arm-unknown-linux-gnueabihf") + BASH_VERSION='5.2.15(1)-release' + BUILDDIR=/build + BUILDUSERGECOS='second user,second room,second work-phone,second home-phone,second other' + BUILDUSERNAME=pbuilder2 + BUILD_ARCH=armhf + DEBIAN_FRONTEND=noninteractive + DEB_BUILD_OPTIONS='buildinfo=+all reproducible=+all parallel=4 ' + DIRSTACK=() + DISTRIBUTION=bookworm + EUID=0 + FUNCNAME=([0]="Echo" [1]="main") + GROUPS=() + HOME=/root + HOSTNAME=i-capture-the-hostname + HOSTTYPE=arm + HOST_ARCH=armhf IFS=' ' - INVOCATION_ID='1bf43bee4de44acaad348ef773f04cf9' - LANG='C' - LANGUAGE='en_US:en' - LC_ALL='C' - MAIL='/var/mail/root' - OPTIND='1' - PATH='/usr/sbin:/usr/bin:/sbin:/bin:/usr/games' - PBCURRENTCOMMANDLINEOPERATION='build' - PBUILDER_OPERATION='build' - PBUILDER_PKGDATADIR='/usr/share/pbuilder' - PBUILDER_PKGLIBDIR='/usr/lib/pbuilder' - PBUILDER_SYSCONFDIR='/etc' - PPID='16123' - PS1='# ' - PS2='> ' + INVOCATION_ID=ab6a1ef4fdf5411986a20e88ffa1e410 + LANG=C + LANGUAGE=it_CH:it + LC_ALL=C + MACHTYPE=arm-unknown-linux-gnueabihf + MAIL=/var/mail/root + OPTERR=1 + OPTIND=1 + OSTYPE=linux-gnueabihf + PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/i/capture/the/path + PBCURRENTCOMMANDLINEOPERATION=build + PBUILDER_OPERATION=build + PBUILDER_PKGDATADIR=/usr/share/pbuilder + PBUILDER_PKGLIBDIR=/usr/lib/pbuilder + PBUILDER_SYSCONFDIR=/etc + PIPESTATUS=([0]="0") + POSIXLY_CORRECT=y + PPID=11944 PS4='+ ' - PWD='/' - SHELL='/bin/bash' - SHLVL='2' - SUDO_COMMAND='/usr/bin/timeout -k 18.1h 18h /usr/bin/ionice -c 3 /usr/bin/nice /usr/sbin/pbuilder --build --configfile /srv/reproducible-results/rbuild-debian/r-b-build.QmivwliN/pbuilderrc_7dLz --distribution bookworm --hookdir /etc/pbuilder/first-build-hooks --debbuildopts -b --basetgz /var/cache/pbuilder/bookworm-reproducible-base.tgz --buildresult /srv/reproducible-results/rbuild-debian/r-b-build.QmivwliN/b1 --logfile b1/build.log octave-symbolic_3.0.1-2.dsc' - SUDO_GID='113' - SUDO_UID='107' - SUDO_USER='jenkins' - TERM='unknown' - TZ='/usr/share/zoneinfo/Etc/GMT+12' - USER='root' - _='/usr/bin/systemd-run' - http_proxy='http://10.0.0.15:3142/' + PWD=/ + SHELL=/bin/bash + SHELLOPTS=braceexpand:errexit:hashall:interactive-comments:posix + SHLVL=3 + SUDO_COMMAND='/usr/bin/timeout -k 24.1h 24h /usr/bin/ionice -c 3 /usr/bin/nice -n 11 /usr/bin/unshare --uts -- /usr/sbin/pbuilder --build --configfile /srv/reproducible-results/rbuild-debian/r-b-build.QmivwliN/pbuilderrc_xNSn --distribution bookworm --hookdir /etc/pbuilder/rebuild-hooks --debbuildopts -b --basetgz /var/cache/pbuilder/bookworm-reproducible-base.tgz --buildresult /srv/reproducible-results/rbuild-debian/r-b-build.QmivwliN/b2 --logfile b2/build.log --extrapackages usrmerge octave-symbolic_3.0.1-2.dsc' + SUDO_GID=114 + SUDO_UID=108 + SUDO_USER=jenkins + TERM=unknown + TZ=/usr/share/zoneinfo/Etc/GMT-14 + UID=0 + USER=root + _='I: set' + http_proxy=http://10.0.0.15:3142/ I: uname -a - Linux virt32c 5.10.0-23-armmp-lpae #1 SMP Debian 5.10.179-1 (2023-05-12) armv7l GNU/Linux + Linux i-capture-the-hostname 5.10.0-23-arm64 #1 SMP Debian 5.10.179-1 (2023-05-12) aarch64 GNU/Linux I: ls -l /bin - total 5072 - -rwxr-xr-x 1 root root 838488 Apr 23 09:24 bash - -rwxr-xr-x 3 root root 67144 Sep 18 2022 bunzip2 - -rwxr-xr-x 3 root root 67144 Sep 18 2022 bzcat - lrwxrwxrwx 1 root root 6 Sep 18 2022 bzcmp -> bzdiff - -rwxr-xr-x 1 root root 2225 Sep 18 2022 bzdiff - lrwxrwxrwx 1 root root 6 Sep 18 2022 bzegrep -> bzgrep - -rwxr-xr-x 1 root root 4893 Nov 27 2021 bzexe - lrwxrwxrwx 1 root root 6 Sep 18 2022 bzfgrep -> bzgrep - -rwxr-xr-x 1 root root 3775 Sep 18 2022 bzgrep - -rwxr-xr-x 3 root root 67144 Sep 18 2022 bzip2 - -rwxr-xr-x 1 root root 67112 Sep 18 2022 bzip2recover - lrwxrwxrwx 1 root root 6 Sep 18 2022 bzless -> bzmore - -rwxr-xr-x 1 root root 1297 Sep 18 2022 bzmore - -rwxr-xr-x 1 root root 67632 Sep 20 2022 cat - -rwxr-xr-x 1 root root 67676 Sep 20 2022 chgrp - -rwxr-xr-x 1 root root 67644 Sep 20 2022 chmod - -rwxr-xr-x 1 root root 67684 Sep 20 2022 chown - -rwxr-xr-x 1 root root 133532 Sep 20 2022 cp - -rwxr-xr-x 1 root root 132868 Jan 5 01:20 dash - -rwxr-xr-x 1 root root 133220 Sep 20 2022 date - -rwxr-xr-x 1 root root 67732 Sep 20 2022 dd - -rwxr-xr-x 1 root root 68104 Sep 20 2022 df - -rwxr-xr-x 1 root root 133632 Sep 20 2022 dir - -rwxr-xr-x 1 root root 59128 Mar 22 21:02 dmesg - lrwxrwxrwx 1 root root 8 Dec 19 01:33 dnsdomainname -> hostname - lrwxrwxrwx 1 root root 8 Dec 19 01:33 domainname -> hostname - -rwxr-xr-x 1 root root 67560 Sep 20 2022 echo - -rwxr-xr-x 1 root root 41 Jan 24 02:43 egrep - -rwxr-xr-x 1 root root 67548 Sep 20 2022 false - -rwxr-xr-x 1 root root 41 Jan 24 02:43 fgrep - -rwxr-xr-x 1 root root 55748 Mar 22 21:02 findmnt - -rwsr-xr-x 1 root root 26208 Mar 22 20:15 fusermount - -rwxr-xr-x 1 root root 128608 Jan 24 02:43 grep - -rwxr-xr-x 2 root root 2346 Apr 9 2022 gunzip - -rwxr-xr-x 1 root root 6447 Apr 9 2022 gzexe - -rwxr-xr-x 1 root root 64220 Apr 9 2022 gzip - -rwxr-xr-x 1 root root 67032 Dec 19 01:33 hostname - -rwxr-xr-x 1 root root 67720 Sep 20 2022 ln - -rwxr-xr-x 1 root root 35132 Mar 22 21:51 login - -rwxr-xr-x 1 root root 133632 Sep 20 2022 ls - -rwxr-xr-x 1 root root 136808 Mar 22 21:02 lsblk - -rwxr-xr-x 1 root root 67800 Sep 20 2022 mkdir - -rwxr-xr-x 1 root root 67764 Sep 20 2022 mknod - -rwxr-xr-x 1 root root 67596 Sep 20 2022 mktemp - -rwxr-xr-x 1 root root 38504 Mar 22 21:02 more - -rwsr-xr-x 1 root root 38496 Mar 22 21:02 mount - -rwxr-xr-x 1 root root 9824 Mar 22 21:02 mountpoint - -rwxr-xr-x 1 root root 133532 Sep 20 2022 mv - lrwxrwxrwx 1 root root 8 Dec 19 01:33 nisdomainname -> hostname - lrwxrwxrwx 1 root root 14 Apr 2 18:25 pidof -> /sbin/killall5 - -rwxr-xr-x 1 root root 67608 Sep 20 2022 pwd - lrwxrwxrwx 1 root root 4 Apr 23 09:24 rbash -> bash - -rwxr-xr-x 1 root root 67600 Sep 20 2022 readlink - -rwxr-xr-x 1 root root 67672 Sep 20 2022 rm - -rwxr-xr-x 1 root root 67600 Sep 20 2022 rmdir - -rwxr-xr-x 1 root root 67400 Nov 2 2022 run-parts - -rwxr-xr-x 1 root root 133372 Jan 5 07:55 sed - lrwxrwxrwx 1 root root 4 Jan 5 01:20 sh -> dash - -rwxr-xr-x 1 root root 67584 Sep 20 2022 sleep - -rwxr-xr-x 1 root root 67644 Sep 20 2022 stty - -rwsr-xr-x 1 root root 50800 Mar 22 21:02 su - -rwxr-xr-x 1 root root 67584 Sep 20 2022 sync - -rwxr-xr-x 1 root root 336764 Apr 6 02:25 tar - -rwxr-xr-x 1 root root 67144 Nov 2 2022 tempfile - -rwxr-xr-x 1 root root 133224 Sep 20 2022 touch - -rwxr-xr-x 1 root root 67548 Sep 20 2022 true - -rwxr-xr-x 1 root root 9768 Mar 22 20:15 ulockmgr_server - -rwsr-xr-x 1 root root 22108 Mar 22 21:02 umount - -rwxr-xr-x 1 root root 67572 Sep 20 2022 uname - -rwxr-xr-x 2 root root 2346 Apr 9 2022 uncompress - -rwxr-xr-x 1 root root 133632 Sep 20 2022 vdir - -rwxr-xr-x 1 root root 42608 Mar 22 21:02 wdctl - lrwxrwxrwx 1 root root 8 Dec 19 01:33 ypdomainname -> hostname - -rwxr-xr-x 1 root root 1984 Apr 9 2022 zcat - -rwxr-xr-x 1 root root 1678 Apr 9 2022 zcmp - -rwxr-xr-x 1 root root 6460 Apr 9 2022 zdiff - -rwxr-xr-x 1 root root 29 Apr 9 2022 zegrep - -rwxr-xr-x 1 root root 29 Apr 9 2022 zfgrep - -rwxr-xr-x 1 root root 2081 Apr 9 2022 zforce - -rwxr-xr-x 1 root root 8103 Apr 9 2022 zgrep - -rwxr-xr-x 1 root root 2206 Apr 9 2022 zless - -rwxr-xr-x 1 root root 1842 Apr 9 2022 zmore - -rwxr-xr-x 1 root root 4577 Apr 9 2022 znew -I: user script /srv/workspace/pbuilder/16123/tmp/hooks/D02_print_environment finished + total 5088 + -rwxr-xr-x 1 root root 838488 Apr 24 11:24 bash + -rwxr-xr-x 3 root root 67144 Sep 19 2022 bunzip2 + -rwxr-xr-x 3 root root 67144 Sep 19 2022 bzcat + lrwxrwxrwx 1 root root 6 Sep 19 2022 bzcmp -> bzdiff + -rwxr-xr-x 1 root root 2225 Sep 19 2022 bzdiff + lrwxrwxrwx 1 root root 6 Sep 19 2022 bzegrep -> bzgrep + -rwxr-xr-x 1 root root 4893 Nov 28 2021 bzexe + lrwxrwxrwx 1 root root 6 Sep 19 2022 bzfgrep -> bzgrep + -rwxr-xr-x 1 root root 3775 Sep 19 2022 bzgrep + -rwxr-xr-x 3 root root 67144 Sep 19 2022 bzip2 + -rwxr-xr-x 1 root root 67112 Sep 19 2022 bzip2recover + lrwxrwxrwx 1 root root 6 Sep 19 2022 bzless -> bzmore + -rwxr-xr-x 1 root root 1297 Sep 19 2022 bzmore + -rwxr-xr-x 1 root root 67632 Sep 21 2022 cat + -rwxr-xr-x 1 root root 67676 Sep 21 2022 chgrp + -rwxr-xr-x 1 root root 67644 Sep 21 2022 chmod + -rwxr-xr-x 1 root root 67684 Sep 21 2022 chown + -rwxr-xr-x 1 root root 133532 Sep 21 2022 cp + -rwxr-xr-x 1 root root 132868 Jan 6 03:20 dash + -rwxr-xr-x 1 root root 133220 Sep 21 2022 date + -rwxr-xr-x 1 root root 67732 Sep 21 2022 dd + -rwxr-xr-x 1 root root 68104 Sep 21 2022 df + -rwxr-xr-x 1 root root 133632 Sep 21 2022 dir + -rwxr-xr-x 1 root root 59128 Mar 23 23:02 dmesg + lrwxrwxrwx 1 root root 8 Dec 20 03:33 dnsdomainname -> hostname + lrwxrwxrwx 1 root root 8 Dec 20 03:33 domainname -> hostname + -rwxr-xr-x 1 root root 67560 Sep 21 2022 echo + -rwxr-xr-x 1 root root 41 Jan 25 04:43 egrep + -rwxr-xr-x 1 root root 67548 Sep 21 2022 false + -rwxr-xr-x 1 root root 41 Jan 25 04:43 fgrep + -rwxr-xr-x 1 root root 55748 Mar 23 23:02 findmnt + -rwsr-xr-x 1 root root 26208 Mar 23 22:15 fusermount + -rwxr-xr-x 1 root root 128608 Jan 25 04:43 grep + -rwxr-xr-x 2 root root 2346 Apr 10 2022 gunzip + -rwxr-xr-x 1 root root 6447 Apr 10 2022 gzexe + -rwxr-xr-x 1 root root 64220 Apr 10 2022 gzip + -rwxr-xr-x 1 root root 67032 Dec 20 03:33 hostname + -rwxr-xr-x 1 root root 67720 Sep 21 2022 ln + -rwxr-xr-x 1 root root 35132 Mar 23 23:51 login + -rwxr-xr-x 1 root root 133632 Sep 21 2022 ls + -rwxr-xr-x 1 root root 136808 Mar 23 23:02 lsblk + -rwxr-xr-x 1 root root 67800 Sep 21 2022 mkdir + -rwxr-xr-x 1 root root 67764 Sep 21 2022 mknod + -rwxr-xr-x 1 root root 67596 Sep 21 2022 mktemp + -rwxr-xr-x 1 root root 38504 Mar 23 23:02 more + -rwsr-xr-x 1 root root 38496 Mar 23 23:02 mount + -rwxr-xr-x 1 root root 9824 Mar 23 23:02 mountpoint + -rwxr-xr-x 1 root root 133532 Sep 21 2022 mv + lrwxrwxrwx 1 root root 8 Dec 20 03:33 nisdomainname -> hostname + lrwxrwxrwx 1 root root 14 Apr 3 20:25 pidof -> /sbin/killall5 + -rwxr-xr-x 1 root root 67608 Sep 21 2022 pwd + lrwxrwxrwx 1 root root 4 Apr 24 11:24 rbash -> bash + -rwxr-xr-x 1 root root 67600 Sep 21 2022 readlink + -rwxr-xr-x 1 root root 67672 Sep 21 2022 rm + -rwxr-xr-x 1 root root 67600 Sep 21 2022 rmdir + -rwxr-xr-x 1 root root 67400 Nov 3 2022 run-parts + -rwxr-xr-x 1 root root 133372 Jan 6 09:55 sed + lrwxrwxrwx 1 root root 9 Jun 9 12:18 sh -> /bin/bash + -rwxr-xr-x 1 root root 67584 Sep 21 2022 sleep + -rwxr-xr-x 1 root root 67644 Sep 21 2022 stty + -rwsr-xr-x 1 root root 50800 Mar 23 23:02 su + -rwxr-xr-x 1 root root 67584 Sep 21 2022 sync + -rwxr-xr-x 1 root root 336764 Apr 7 04:25 tar + -rwxr-xr-x 1 root root 67144 Nov 3 2022 tempfile + -rwxr-xr-x 1 root root 133224 Sep 21 2022 touch + -rwxr-xr-x 1 root root 67548 Sep 21 2022 true + -rwxr-xr-x 1 root root 9768 Mar 23 22:15 ulockmgr_server + -rwsr-xr-x 1 root root 22108 Mar 23 23:02 umount + -rwxr-xr-x 1 root root 67572 Sep 21 2022 uname + -rwxr-xr-x 2 root root 2346 Apr 10 2022 uncompress + -rwxr-xr-x 1 root root 133632 Sep 21 2022 vdir + -rwxr-xr-x 1 root root 42608 Mar 23 23:02 wdctl + lrwxrwxrwx 1 root root 8 Dec 20 03:33 ypdomainname -> hostname + -rwxr-xr-x 1 root root 1984 Apr 10 2022 zcat + -rwxr-xr-x 1 root root 1678 Apr 10 2022 zcmp + -rwxr-xr-x 1 root root 6460 Apr 10 2022 zdiff + -rwxr-xr-x 1 root root 29 Apr 10 2022 zegrep + -rwxr-xr-x 1 root root 29 Apr 10 2022 zfgrep + -rwxr-xr-x 1 root root 2081 Apr 10 2022 zforce + -rwxr-xr-x 1 root root 8103 Apr 10 2022 zgrep + -rwxr-xr-x 1 root root 2206 Apr 10 2022 zless + -rwxr-xr-x 1 root root 1842 Apr 10 2022 zmore + -rwxr-xr-x 1 root root 4577 Apr 10 2022 znew +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/D02_print_environment finished -> Attempting to satisfy build-dependencies -> Creating pbuilder-satisfydepends-dummy package Package: pbuilder-satisfydepends-dummy @@ -714,7 +746,7 @@ Get: 514 http://deb.debian.org/debian bookworm/main armhf python3-mpmath all 1.2.1-2 [418 kB] Get: 515 http://deb.debian.org/debian bookworm/main armhf python3-six all 1.16.0-4 [17.5 kB] Get: 516 http://deb.debian.org/debian bookworm/main armhf python3-sympy all 1.11.1-1 [4358 kB] -Fetched 180 MB in 13s (14.2 MB/s) +Fetched 180 MB in 21s (8681 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package libpython3.11-minimal:armhf. (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading database ... 20% (Reading database ... 25% (Reading database ... 30% (Reading database ... 35% (Reading database ... 40% (Reading database ... 45% (Reading database ... 50% (Reading database ... 55% (Reading database ... 60% (Reading database ... 65% (Reading database ... 70% (Reading database ... 75% (Reading database ... 80% (Reading database ... 85% (Reading database ... 90% (Reading database ... 95% (Reading database ... 100% (Reading database ... 19324 files and directories currently installed.) @@ -2831,8 +2863,19 @@ Writing extended state information... Building tag database... -> Finished parsing the build-deps +Reading package lists... +Building dependency tree... +Reading state information... +usrmerge is already the newest version (35). +0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. I: Building the package -I: Running cd /build/octave-symbolic-3.0.1/ && env PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" HOME="/nonexistent/first-build" dpkg-buildpackage -us -uc -b && env PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" HOME="/nonexistent/first-build" dpkg-genchanges -S > ../octave-symbolic_3.0.1-2_source.changes +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/A99_set_merged_usr starting +Re-configuring usrmerge... +removed '/etc/unsupported-skip-usrmerge-conversion' +The system has been successfully converted. +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/A99_set_merged_usr finished +hostname: Name or service not known +I: Running cd /build/octave-symbolic-3.0.1/ && env PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/i/capture/the/path" HOME="/nonexistent/second-build" dpkg-buildpackage -us -uc -b && env PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/i/capture/the/path" HOME="/nonexistent/second-build" dpkg-genchanges -S > ../octave-symbolic_3.0.1-2_source.changes dpkg-buildpackage: info: source package octave-symbolic dpkg-buildpackage: info: source version 3.0.1-2 dpkg-buildpackage: info: source distribution unstable @@ -2864,1701 +2907,1635 @@ dh_octave_check -O--buildsystem=octave Checking package... Checking m files ... -[inst/pycall_sympy__.m] ->>>>> /build/octave-symbolic-3.0.1/inst/pycall_sympy__.m -***** test - % general test - x = 10; y = 6; - cmd = '(x,y) = _ins; return (x+y,x-y)'; - [a,b] = pycall_sympy__ (cmd, x, y); - assert (a == x + y && b == x - y) +[inst/poly2sym.m] +>>>>> /build/octave-symbolic-3.0.1/inst/poly2sym.m +***** shared x,y,a,b,c,p + syms x y a b c + p = x^3 + 2*x^2 + 3*x + 4; Symbolic pkg v3.0.1: Python communication link active, SymPy v1.11.1. +***** assert(isAlways( poly2sym([1 2 3 4]) == p )) +***** assert(isAlways( poly2sym([1 2 3 4],x) == p )) +***** assert(isAlways( poly2sym([1 2 3 4],y) == subs(p,x,y) )) +***** assert(isAlways( poly2sym([1 2 3 4],5) == subs(p,x,5) )) +***** assert(isequal( poly2sym ([1]), 1 )) +***** assert(isequal( poly2sym ([]), 0 )) +***** assert(isAlways( poly2sym(sym([1 2 3 4]),x) == p )) +***** assert(isAlways( poly2sym([a b c],x) == a*x^2 + b*x + c )) +***** assert(isAlways( poly2sym([a b c]) == a*x^2 + b*x + c )) +***** assert(isequal( poly2sym(sym([])), 0 )) +***** assert(isAlways( poly2sym({sym(1) sym(2)}, x) == x + 2 )) +***** assert(isequal( poly2sym ({1}), 1 )) +***** assert(isequal( poly2sym ({}), 0 )) +***** assert(isequal( poly2sym ({1}, x), 1 )) +***** assert(isequal( poly2sym ({}, x), 0 )) +***** assert(isAlways( poly2sym([x x], x) == x^2 + x )) ***** test - % bool - assert (pycall_sympy__ ('return True,')) - assert (~pycall_sympy__ ('return False,')) -***** test - % float - assert (abs(pycall_sympy__ ('return 1.0/3,') - 1/3) < 1e-15) -***** test - % int - r = pycall_sympy__ ('return 123456'); - assert (r == 123456) - assert (isinteger (r)) -***** test - % string - x = 'octave'; - cmd = 's = _ins[0]; return s.capitalize(),'; - y = pycall_sympy__ (cmd, x); - assert (strcmp(y, 'Octave')) -***** test - % string with escaped newlines, comes back as escaped newlines - x = 'a string\nbroke off\nmy guitar\n'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) -***** test - % string with actual newlines, comes back as actual newlines - x = sprintf('a string\nbroke off\nmy guitar\n'); - y = pycall_sympy__ ('return _ins', x); - y2 = strrep(y, sprintf('\n'), sprintf('\r\n')); % windows - assert (strcmp(x, y) || strcmp(x, y2)) + % mixed cell array with doubles and syms + assert (isequal (poly2sym ({2.0 sym(3) int64(4)}), 2*x^2 + 3*x + 4)) ***** test - % cmd string with newlines, works with cell - y = pycall_sympy__ ('return "string\nbroke",'); - y2 = sprintf('string\nbroke'); - y3 = strrep(y2, sprintf('\n'), sprintf('\r\n')); % windows - assert (strcmp(y, y2) || strcmp(y, y3)) + % string for x + p = poly2sym ([1 2], 's'); + syms s + assert (isequal (p, s + 2)) +warning: test: file /build/octave-symbolic-3.0.1/inst/poly2sym.m leaked file descriptors +18 tests, 18 passed, 0 known failure, 0 skipped +[inst/digits.m] +>>>>> /build/octave-symbolic-3.0.1/inst/digits.m ***** test - % string with XML escapes - x = '<> >< <<>>'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) - x = '&'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) + orig = digits(32); % to reset later + m = digits(64); + p = vpa(sym(pi)); + assert (abs (double (sin(p))) < 1e-64) + n = digits(m); + assert (n == 64) + p = vpa(sym(pi)); + assert (abs (double (sin(p))) < 1e-32) + assert (abs (double (sin(p))) > 1e-40) + digits(orig) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/laguerreL.m] +>>>>> /build/octave-symbolic-3.0.1/inst/laguerreL.m +***** error laguerreL (1) +***** error laguerreL (1, 2, 3) +***** assert (isequal (laguerreL (0, rand), 1)) ***** test - % strings with double quotes - x = 'a\"b\"c'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) - x = '\"'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) + x = rand; + assert (isequal (laguerreL (1, x), 1 - x)) ***** test - % cmd has double quotes, these must be escaped by user - % (of course: she is writing python code) - expy = 'a"b"c'; - y = pycall_sympy__ ('return "a\"b\"c",'); - assert (strcmp(y, expy)) + x=rand; + y1=laguerreL(2, x); + p2=[.5 -2 1]; + y2=polyval(p2,x); + assert(y1 - y2, 0, 10*eps); ***** test - % strings with quotes - x = 'a''b'; % this is a single quote - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) + x=rand; + y1=laguerreL(3, x); + p3=[-1/6 9/6 -18/6 1]; + y2=polyval(p3,x); + assert(y1 - y2, 0, 20*eps); ***** test - % strings with quotes - x = '\"a''b\"c''\"d'; - y = pycall_sympy__ ('return _ins[0]', x); - assert (strcmp(y, x)) + x=rand; + y1=laguerreL(4, x); + p4=[1/24 -16/24 72/24 -96/24 1]; + y2=polyval(p4,x); + assert(y1 - y2, 0, 30*eps) +***** error laguerreL(1.5, 10) +***** error laguerreL([0 1], [1 2 3]) +***** error laguerreL([0 1], [1; 2]) ***** test - % strings with quotes - expy = '"a''b"c''"d'; - y = pycall_sympy__ ('s = "\"a''b\"c''\"d"; return s'); - assert (strcmp(y, expy)) + % numerically stable implementation (in n) + L = laguerreL (10, 10); + Lex = 1763/63; + assert (L, Lex, -eps) + L = laguerreL (20, 10); + Lex = -177616901779/14849255421; % e.g., laguerreL(sym(20),10) + assert (L, Lex, -eps) ***** test - % strings with printf escapes - x = '% %% %%% %%%% %s %g %%s'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) + % vectorized x + L = laguerreL (2, [5 6 7]); + Lex = [3.5 7 11.5]; + assert (L, Lex, eps) ***** test - % cmd with printf escapes - x = '% %% %%% %%%% %s %g %%s'; - y = pycall_sympy__ (['return "' x '",']); - assert (strcmp(y, x)) + L = laguerreL (0, [4 5]); + assert (L, [1 1], eps) ***** test - % cmd w/ backslash and \n must be escaped by user - expy = 'a\b\\c\nd\'; - y = pycall_sympy__ ('return "a\\b\\\\c\\nd\\",'); - assert (strcmp(y, expy)) + % vector n + L = laguerreL ([0 1 2 3], [4 5 6 9]); + assert (L, [1 -4 7 -26], eps) ***** test - % slashes - x = '/\\ // \\\\ \\/\\/\\'; - z = '/\ // \\ \/\/\'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) + % vector n, scalar x + L = laguerreL ([0 1 2 3], 6); + assert (L, [1 -5 7 1], eps) +***** assert (isa (laguerreL (0, single (1)), 'single')) +***** assert (isa (laguerreL (1, single ([1 2])), 'single')) +***** assert (isa (laguerreL ([1 2], single ([1 2])), 'single')) +18 tests, 18 passed, 0 known failure, 0 skipped +[inst/assume.m] +>>>>> /build/octave-symbolic-3.0.1/inst/assume.m +***** error + a = assume('a', 'real') +***** error + assume positive integer +***** error + assume x y +***** error + assume x clear real +***** error + assume a>0 +***** error + assume 'x/pi' integer ***** test - % slashes - z = '/\ // \\ \/\/\'; - y = pycall_sympy__ ('return "/\\ // \\\\ \\/\\/\\"'); - assert (strcmp(y, z)) + syms x + assume x positive + a = assumptions(x); + assert(strcmp(a, 'x: positive')) + assume x even + a = assumptions(x); + assert(strcmp(a, 'x: even')) ***** test - % strings with special chars - x = '!@#$^&* you!'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) - x = '~-_=+[{]}|;:,.?'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) -***** xtest - % string with backtick trouble for system -c (sysoneline) - x = '`'; - y = pycall_sympy__ ('return _ins', x); - assert (strcmp(y, x)) + % multiple assumptions + syms x + assume x positive integer + [tilde, a] = assumptions(x, 'dict'); + assert(a{1}.integer) + assert(a{1}.positive) ***** test - % unicode - s1 = '我爱你'; - cmd = 'return u"\u6211\u7231\u4f60",'; - s2 = pycall_sympy__ (cmd); - assert (strcmp (s1, s2)) + % does workspace + syms x positive + x2 = x; + f = sin(x); + assume x negative + a = assumptions(x); + assert(strcmp(a, 'x: negative')) + a = assumptions(x2); + assert(strcmp(a, 'x: negative')) + a = assumptions(f); + assert(strcmp(a, 'x: negative')) +***** error + % does not create new variable x + clear x + assume x real +***** error + % no explicit variable named x + clear x + f = 2*sym('x'); + assume x real ***** test - % unicode with \x - s1 = '我'; - cmd = 'return b"\xe6\x88\x91".decode("utf-8")'; - s2 = pycall_sympy__ (cmd); - assert (strcmp (s1, s2)) + % clear does workspace + syms x positive + f = 2*x; + assume x clear + assert (isempty (assumptions (f))); + assert (isempty (assumptions ())); ***** test - % unicode with \x and some escaped backslashes - s1 = '\我\'; - cmd = 'return b"\\\xe6\x88\x91\\".decode("utf-8")'; - s2 = pycall_sympy__ (cmd); - assert (strcmp (s1, s2)) -***** xtest - % unicode passthru - s = '我爱你'; - s2 = pycall_sympy__ ('return _ins', s); - assert (strcmp (s, s2)) - s = '我爱你<>\&//\#%% %\我'; - s2 = pycall_sympy__ ('return _ins', s); - assert (strcmp (s, s2)) -***** xtest - % unicode w/ slashes, escapes - s = '我<>\&//\#%% %\我'; - s2 = pycall_sympy__ ('return "我<>\\&//\\#%% %\\我"'); - assert (strcmp (s, s2)) + syms x y + f = sin (2*x); + assume x y real + assert (strcmp (assumptions (x), 'x: real')) + assert (strcmp (assumptions (y), 'y: real')) + assert (strcmp (assumptions (f), 'x: real')) ***** test - % list, tuple - assert (isequal (pycall_sympy__ ('return [1,2,3],'), {1, 2, 3})) - assert (isequal (pycall_sympy__ ('return (4,5),'), {4, 5})) - assert (isequal (pycall_sympy__ ('return (6,),'), {6,})) - assert (isequal (pycall_sympy__ ('return [],'), {})) + syms x y + f = sin (2*x); + assume x y positive even + assert (strcmp (assumptions (x), 'x: positive, even') || strcmp (assumptions (x), 'x: even, positive')) + assert (strcmp (assumptions (y), 'y: positive, even') || strcmp (assumptions (y), 'y: even, positive')) + assert (strcmp (assumptions (f), 'x: positive, even') || strcmp (assumptions (f), 'x: even, positive')) ***** test - % dict - cmd = 'd = dict(); d["a"] = 6; d["b"] = 10; return d,'; - d = pycall_sympy__ (cmd); - assert (d.a == 6 && d.b == 10) + % works from variable names not symbols + syms x y + a = [x y]; + assume a real + assert (strcmp (assumptions (x), 'x: real')) + assert (strcmp (assumptions (y), 'y: real')) ***** test - r = pycall_sympy__ ('return 6'); - assert (isequal (r, 6)) + % works from variable names not symbols + y = sym('x'); + f = 2*y; + assume y real + assert (strcmp (assumptions (f), 'x: real')) ***** test - r = pycall_sympy__ ('return "Hi"'); - assert (strcmp (r, 'Hi')) + % matrix of symbols + syms a b c d + A = [a b; c d]; + assume A real + assert (strcmp (assumptions (a), 'a: real')) + assert (strcmp (assumptions (b), 'b: real')) + assert (strcmp (assumptions (c), 'c: real')) + assert (strcmp (assumptions (d), 'd: real')) ***** test - % blank lines, lines with spaces - a = pycall_sympy__ ({ '', '', ' ', 'return 6', ' ', ''}); - assert (isequal (a, 6)) + % assume after symfun + clear x + syms f(x) + assume x real + assert (~ isempty (assumptions (formula (f)))) + assert (~ isempty (assumptions (argnames (f)))) +18 tests, 18 passed, 0 known failure, 0 skipped +[inst/heaviside.m] +>>>>> /build/octave-symbolic-3.0.1/inst/heaviside.m +***** assert (heaviside (0) == 0.5) +***** assert (isnan (heaviside (nan))) +***** assert (isequal (heaviside ([-inf -eps 0 eps inf]), [0 0 0.5 1 1])) +***** assert (isequaln (heaviside ([-1 1 nan]), [0 1 nan])) +***** assert (heaviside (0, 1) == 1) +***** error heaviside (1i) +***** assert (isa (heaviside (single (0)), 'single')) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/numden.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/numden.m +***** error numden (sym(1), 2) ***** test - % blank lines, strange comment lines - cmd = {'a = 1', '', '#', '', '# ', ' #', 'a = a + 2', ' #', 'return a'}; - a = pycall_sympy__ (cmd); - assert (isequal (a, 3)) + syms x + [n, d] = numden (1/x); + assert (isequal (n, sym(1)) && isequal (d, x)) ***** test - % return empty string (was https://bugs.python.org/issue25270) - assert (isempty (pycall_sympy__ ('return ""'))) + syms x y + n1 = [sym(1); x]; + d1 = [x; y]; + [n, d] = numden (n1 ./ d1); + assert (isequal (n, n1) && isequal (d, d1)) ***** test - % return nothing (via an empty list) - % note distinct from 'return [],' - pycall_sympy__ ('return []') + [n, d] = numden (sym(2)); + assert (isequal (n, 2)); + assert (isequal (d, 1)); ***** test - % return nothing (because no return command) - pycall_sympy__ ('dummy = 1') + syms x y + [n, d] = numden ((x + pi)/(y + 6)); + assert (isequal (n, x + pi)); + assert (isequal (d, y + 6)); ***** test - % return nothing (because no command) - pycall_sympy__ ('') + syms x y + [n, d] = numden ((x^2 + y^2)/(x*y)); + assert (isequal (n, x^2 + y^2)); + assert (isequal (d, x*y)); +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/reshape.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/reshape.m ***** test - % return nothing (because no command) - pycall_sympy__ ({}) -***** error - % python exception while passing variables to python - % This tests the "INTERNAL_PYTHON_ERROR" path. - % FIXME: this is a very specialized test, relies on internal octsympy - % implementation details, and may need to be adjusted for changes. - disp('') - disp('**********************************************************************') - disp('') - disp(' Some deliberate AttributeError and ValueError may appear next') - disp('') - disp('v v v v v v v v v v v v v v v v v v v v v v v v') - b = sym([], 'S.This_is_supposed_to_make_an_exception', [1 1], 'Test', 'Test', 'Test'); - c = b + 1; - -********************************************************************** - - Some deliberate AttributeError and ValueError may appear next + d = [2 4 6; 8 10 12]; + a = sym(d); + assert (isequal (reshape(a, [1 6]), reshape(d, [1 6]))) + assert (isequal (reshape(a, 1, 6), reshape(d, 1, 6))) + assert (isequal (reshape(a, 2, 3), reshape(d, 2, 3))) + assert (isequal (reshape(a, 3, 2), reshape(d, 3, 2))) + assert (isequal (reshape(a, 6, 1), reshape(d, 6, 1))) +***** shared x, a, d + syms x + a = [1 x^2 x^4; x x^3 x^5]; + d = [0 2 4; 1 3 5]; -v v v v v v v v v v v v v v v v v v v v v v v v -Traceback (most recent call last): - File "", line 4, in - File "/usr/lib/python3/dist-packages/sympy/core/singleton.py", line 119, in __getattr__ - raise AttributeError( -AttributeError: Attribute 'This_is_supposed_to_make_an_exception' was not installed on SymPy registry S -***** test - % ...and after the above test, the pipe should still work - a = pycall_sympy__ ('return _ins[0]*2', 3); - assert (isequal (a, 6)) -***** test - % This command does not fail with native interface and '@pyobject' - s = warning ('off', 'OctSymPy:pythonic_no_convert'); - try - q = pycall_sympy__ ({'return type(int)'}); - catch - msg = lasterror.message; - assert (~ isempty (regexp (msg, '.*does not know how to.*'))) - end - warning (s) - disp('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^') - disp(' End of deliberate errors!') - disp(' You should see "46/46" or "Passes 46 out of 46 tests" below') - disp('**********************************************************************') - % ...and after the above test, the pipe should still work - a = pycall_sympy__ ('return _ins[0]*2', 3); - assert (isequal (a, 6)) -Traceback (most recent call last): - File "", line 2, in - File "", line 12, in octoutput_drv - File "", line 96, in octoutput -ValueError: octoutput does not know how to export type -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - End of deliberate errors! - You should see "46/46" or "Passes 46 out of 46 tests" below -********************************************************************** -***** test - % complex input - [A, B] = pycall_sympy__ ('z = 2*_ins[0]; return (z.real,z.imag)', 3+4i); - assert (A, 6) - assert (B, 8) ***** test - % complex output - z = pycall_sympy__ ('return 3+2j'); - assert (z, 3+2i) -***** error - s = char ('abc', 'defgh', '12345'); - r = pycall_sympy__ ('return _ins[0]', s); + b = reshape(a, [1 6]); + assert (isequal (size(b), [1 6])) + assert (isequal (b, x.^reshape(d,1,6))) + ***** test - r = pycall_sympy__ ('return len(_ins[0])', ''); - assert (r == 0) + b = reshape(a, [6 1]); + assert (isequal (size(b), [6 1])) + assert (isequal (b, x.^reshape(d,6,1))) + b = reshape(b, size(a)); + assert (isequal (size(b), [2 3])) + assert (isequal (b, a)) + ***** test - % ensure the 0x0 matrix in octave gets mapped to the empty list in python - % @sym/subsasgn currently replies on this behaviour - assert (pycall_sympy__ ('return _ins[0] == []', [])); + b = a(:); + assert( isequal (size(b), [6 1])) + assert( isequal (b, x.^(d(:)))) + ***** test - % ensure the empty string gets mapped to the empty string in python - assert (pycall_sympy__ ('return _ins[0] == ""', '')); -warning: test: file /build/octave-symbolic-3.0.1/inst/pycall_sympy__.m leaked file descriptors -46 tests, 46 passed, 0 known failure, 0 skipped -[inst/vpa.m] ->>>>> /build/octave-symbolic-3.0.1/inst/vpa.m + % reshape scalar + assert (logical( reshape(x, 1, 1) == x )) + assert (logical( reshape(x, [1 1]) == x )) +***** shared a + syms a +***** error reshape(a, 2, 1) +***** error reshape(a, 1, 2) +***** error reshape(a, 1, 1, 1) +***** error reshape(a, [1, 1, 1]) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/isvector.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isvector.m +***** assert(isvector(sym('x'))) +***** assert(isvector(sym([1 2 3]))) +***** assert(isvector(sym([1; 2]))) +***** assert(~isvector(sym([1 2; 3 4]))) +***** assert(~isvector(sym([]))) +***** assert(isvector(sym(ones(1,0)))) +***** assert(~isvector(sym(ones(0,3)))) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/uplus.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/uplus.m ***** test - a = vpa(0, 4); - b = double(a); - assert(b == 0) + syms x + assert (isa (+x, 'sym')) + assert (isequal (+x, x)) ***** test - a = vpa(pi, 4); - b = sin(a); - assert(abs(double(b)) < 1e-4) + A = sym([0 -1 inf]); + assert( isequal ( +A, A)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/any.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/any.m ***** test - % vpa from double is ok, doesn't warn (c.f., sym(2.3)) - a = vpa(2.3); - assert(true) + % matrix + a = [0 0; 1 0]; + s = sym(a); + assert (isequal (any (s), any (a))) + assert (isequal (any (s,1), any (a,1))) + assert (isequal (any (s,2), any (a,2))) ***** test - % vpa from double not more than 16 digits - a = vpa(sqrt(pi), 32); - b = sin(a^2); - assert(abs(double(b)) > 1e-20) - assert(abs(double(b)) < 1e-15) + % vector + a = [0 1 0]; + s = sym(a); + assert (isequal (any (s), any (a))) + assert (isequal (any (s,1), any (a,1))) + assert (isequal (any (s,2), any (a,2))) ***** test - a = vpa(sym(pi), 32); - b = sin(a); - assert(abs(double(b)) < 1e-30) + % should fail on symbols + syms x + s = [0 1 x]; + try + any (s) + waserr = false; + catch + waserr = true; + end + assert (waserr) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/sinc.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinc.m +***** error sinc (sym(1), 2) +***** assert (isequaln (sinc (sym(nan)), sym(nan))) +***** assert (isequal (sinc (sym(0)), sym(1))) +***** assert (isequal (sinc (sym(1)), sym(0))) +***** assert (isequal (sinc (-sym(1)), sym(0))) +***** assert (double (sinc (sym(pi))), sinc (pi), -10*eps) ***** test - a = vpa(sym(pi), 256); - b = sin(a); - assert(abs(double(b)) < 1e-256) + A = [-sym(1)/2 sym(1)/2 pi; -sym(7)/2 sym(71)/2 sym(101)/3]; + D = double (A); + assert (sinc (D), double (sinc (A)), -200*eps) ***** test - % pi str - a = vpa('pi', 32); - b = sin(a); - assert(abs(double(b)) < 1e-32) + A = [sym(51)/2 sym(1001)/3 sym(10001)/3 sym(100001)/3]; + D = double (A); + assert (sinc (D), double (sinc (A)), 1e-10) ***** test - % pi str - a = vpa('pi', 32); - b = vpa(sym('pi'), 32); - assert (double (a - b) == 0) + % round trip + syms x + A = sinc (1); + f = sinc (x); + h = function_handle (f); + B = h (1); + assert (A, B, -eps) ***** test - spi = sym(pi); - a = vpa(spi, 10); - b = double(a); - assert(~isAlways(spi == a)) + % round trip + syms x + f = sinc (x); + h = function_handle (f); + A = sinc (1.5); + B = h (1.5); + assert (A, B, -eps) ***** test - % matrix of sym - a = [sym(pi) 0; sym(1)/2 1]; - b = [pi 0; 0.5 1]; - c = vpa(a, 6); - assert(max(max(abs(double(c)-b))) < 1e-6) + syms x + h = function_handle (sinc (x)); + A = double (sinc (sym (12)/10)); + B = h (1.2); + C = sinc (1.2); + assert (A, B, -eps) + assert (A, C, -eps) +11 tests, 11 passed, 0 known failure, 0 skipped +[inst/@sym/besselyn.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselyn.m ***** test - % matrix of double - b = [pi 0; 0.5 1]; - c = vpa(b, 6); - assert(max(max(abs(double(c)-b))) < 1e-6) + % roundtrip + syms x + A = double(besselyn(sym(2), sym(10))); + q = besselyn(sym(2), x); + h = function_handle(q); + B = h(10); + assert (abs (A - B) <= eps) +***** error yn(sym('x')) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/isempty.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isempty.m +***** shared se, a + se = sym ([]); + a = sym ([1 2]); +***** assert (~isempty (sym (1))) +***** assert (isempty (sym (se))) +***** assert (isempty (se == [])) ***** test - % integer type - a = vpa(int32(6), 64); - b = vpa(6, 64); - assert (isequal (a, b)) +***** test se(1) = 10; +***** test assert ( isa (se, 'sym')) +***** test assert ( isequal (se, 10)) +***** shared ***** test - % matrix of int - b = int32([pi 0; 6.25 1]); - c = vpa(b, 6); - assert (isequal (double(c), [3 0; 6 1])) + % empty matrices + A = sym('A', [3 0]); + assert (isempty (A)) + A = sym(ones(3,0)); + assert (isempty (A)) ***** test - % can pass pi directly to vpa - a = vpa(sym(pi), 128); - b = vpa(pi, 128); - assert (isequal (a, b)) + % non-empty symbolic-size matrices + syms n integer + A = sym('A', [3 n]); + assert (~isempty (A)) +***** xtest + % empty symbolic-size matrices + % FIXME: will fail until size stop lying by saying 1x1 + syms n integer + A = sym('A', [0 n]); + assert (isempty (A)) + A = sym('A', [n 0]); + assert (isempty (A)) +!!!!! known failure +assert (isempty (A)) failed +10 tests, 9 passed, 1 known failure, 0 skipped +[inst/@sym/lgamma.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/lgamma.m ***** test - % if sym does sth special for e so should vpa - a = vpa(sym(exp(1)), 64); - b = vpa(exp(1), 64); - assert (isequal (a, b)) + % tested by gammaln + assert (isequal (lgamma (sym ('x')), gammaln (sym ('x')))) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/charpoly.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/charpoly.m +***** error charpoly (sym (1), 1, 2) +***** error charpoly (sym ([1 2])) ***** test - % can pass pi directly to vpa, even in array - a = vpa(sym([2 pi]), 128); - b = vpa([2 pi], 128); - assert (isequal (a, b)) + syms x + A = sym([1 2; 3 4]); + assert (isequal (charpoly(A, x), x^2 - 5*x -2)) ***** test - % can pass i directly to vpa - a = vpa(sym(i)); - b = vpa(i); + syms x + A = sym([1 2; 3 4]); + B = sym([1 -5 -2]); + assert (isequal (charpoly(A), B)) ***** test - % 'i' and 'I' just make vars - a = vpa(sym(1i)); - b = vpa('i'); - c = vpa('I'); - assert (~isequal (a, b)) - assert (~isequal (a, c)) + syms x + A = sym([x x; x x]); + B = sym([1 -2*x 0]); + assert (isequal (charpoly(A), B)) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/euler.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/euler.m +***** error euler (sym(1), 2, 3) +***** assert (isequal (euler (sym(0)), sym(1))) ***** test - % '1i' and '1j' strings - a = vpa(sym(1i)); - b = vpa('1i'); - c = vpa('1j'); - assert (isequal (a, b)) - assert (isequal (a, c)) + m = sym([0 1 2; 8 10 888889]); + A = euler (m); + B = sym([1 0 -1; 1385 -50521 0]); + assert (isequal (A, B)) ***** test - % Issue #868, precision loss on '0.33j' - a = vpa('0.33j', 40); - b = vpa('0.33i', 40); - assert (double (abs (imag (a)*100/33) - 1) < 1e-39) - assert (isequal (a, b)) + syms x + assert (isequal (euler(6, x), x^6 - 3*x^5 + 5*x^3 - 3*x)) +***** assert (isnan (euler (3, sym(nan)))) ***** test - % inf/-inf do not become symbol('inf') - S = {'oo', '-oo', 'inf', 'Inf', '-inf', '+inf'}; - for j = 1:length(S) - a = vpa(S{j}); - b = vpa(sym(S{j})); - assert (isequal (a, b)) - end + syms m x + em = euler (m, x); + A = subs(em, [m x], [2 sym(pi)]); + assert (isequal (A, sym(pi)^2 - sym(pi))) ***** test - a = vpa('2.3', 20); - s = strtrim(disp(a, 'flat')); - assert (strcmp (s, '2.3000000000000000000')) + % vectorized + syms x y + A = euler([1; 2], [x; y]); + B = [x - sym(1)/2; y^2 - y]; + assert (isequal (A, B)) ***** test - % these should *not* be the same - a = vpa(2.3, 40); - b = vpa('2.3', 40); - sa = sympy (a); - sb = sympy (b); - assert (~isequal (a, b)) - assert (abs(double(a - b)) > 1e-20) - assert (abs(double(a - b)) < 1e-15) - assert (~strcmp(sa, sb)) + % round trip + syms m z + f = euler (m, z); + h = function_handle (f, 'vars', [m z]); + A = h (2, 2.2); + B = euler (2, 2.2); + assert (A, B) ***** test - % these should *not* be the same - x = vpa('1/3', 32); - y = vpa(sym(1)/3, 32); - z = vpa(1/3, 32); - assert (isequal (x, y)) - assert (~isequal (x, z)) + % compare vpa to maple: Digits:=34; evalf(euler(13, exp(1)+Pi*I/13)); + A = vpa('1623.14184180556920918624604530515') + ... + vpa('4270.98066989140286451493108809574')*1i; + z = vpa (exp(1), 32) + vpa(pi, 32)/13*1i; + B = euler (13, z); + relerr = double(abs((B - A)/A)); + assert (abs(relerr) < 2e-31); +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/rref.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/rref.m ***** test - % big integers - a = int64(12345678); - a = a*a; - b = vpa(a); - c = vpa('152415765279684'); - assert (isequal (b, c)) + A = sym([1 2; 3 4]); + [r, k] = rref(A); + assert (isequal (r, eye(2))) + assert (isequal (k, [1 2])) +***** assert (isequal (rref(sym([2 1])), [1 sym(1)/2])) +***** assert (isequal (rref(sym([1 2; 2 4])), [1 2; 0 0])) +***** assert (isequal (rref(sym([0 0; 2 4])), [1 2; 0 0])) ***** test - % big integers (workaround poor num2str, works in 4.0?) - a = int64(1234567891); a = a*a; - b = vpa(a); - c = vpa('1524157877488187881'); - assert (isequal (b, c)) -***** warning vpa ('sqrt(2.0)'); -***** warning - if (pycall_sympy__ ('return Version(spver) > Version("1.4")')) - a = vpa('2**0.5'); - b = vpa(sqrt(sym(2))); - assert (isequal (a, b)) - else - warning('dangerous') % fake it until we drop 1.4 - end + A = sym([1 2 3; 2 3 4]); + [r, k] = rref(A); + assert (isequal (r, [1 0 -1; 0 1 2])) + assert (isequal (k, [1 2])); +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/sin.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sin.m +***** error sin (sym(1), 2) +***** assert (isequaln (sin (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - a = vpa('2.3e1'); - b = vpa(' 2.3e+1 '); - assert (isequal (a, b)) - a = vpa('21e-1'); - b = vpa('2.1'); - assert (isequal (a, b)) + f1 = sin(x); + f2 = sin(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % Issue #859, operations on immutable matrices - x = vpa (sym ([1 2])); - % If vpa no longer makes an ImmutableDenseMatrix, - % may need to adjust or remove this test. - assert (~ isempty (strfind (sympy (x), 'Immutable'))) - y = sin(x); - y2 = [sin(vpa(sym(1))) sin(vpa(sym(2)))]; - assert (isequal (y, y2)) -30 tests, 30 passed, 0 known failure, 0 skipped -[inst/findsymbols.m] ->>>>> /build/octave-symbolic-3.0.1/inst/findsymbols.m + D = [d d; d d]; + A = [x x; x x]; + f1 = sin(A); + f2 = sin(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - syms x b y n a arlo - z = a*x + b*pi*sin (n) + exp (y) + exp (sym (1)) + arlo; - s = findsymbols (z); - assert (isequal ([s{:}], [a,arlo,b,n,x,y])) + % round trip + y = sym('y'); + A = sin (d); + f = sin (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/ldivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ldivide.m ***** test + % scalar syms x - s = findsymbols (x); - assert (isequal (s{1}, x)) -***** test - syms z x y a - s = findsymbols ([x y; 1 a]); - assert (isequal ([s{:}], [a x y])) -***** assert (isempty (findsymbols (sym (1)))) -***** assert (isempty (findsymbols (sym ([1 2])))) -***** assert (isempty (findsymbols (sym (nan)))) -***** assert (isempty (findsymbols (sym (inf)))) -***** assert (isempty (findsymbols (exp (sym (2))))) + assert (isa (x .\ 1, 'sym')) + assert (isa (x .\ x, 'sym')) + assert (isequal (x .\ 1, 1/x)) + assert (isequal (x .\ x, sym(1))) ***** test - % empty sym for findsymbols, findsym, and symvar - assert (isempty (findsymbols (sym([])))) - assert (isempty (findsym (sym([])))) - assert (isempty (symvar (sym([])))) + % matrix-scalar + D = [1 1; 2 3]; + A = sym(D); + assert (isequal ( A .\ 6 , D .\ 6 )) + assert (isequal ( A .\ sym(6) , D .\ 6 )) + assert (isequal ( D .\ sym(6) , D .\ 6 )) ***** test - % diff. assumptions make diff. symbols - x1 = sym('x'); - x2 = sym('x', 'positive'); - f = x1*x2; - assert (length (findsymbols (f)) == 2) + % matrix-matrix + D = [1 2; 3 4]; + A = sym(D); + assert (isequal ( A .\ A , D .\ D )) + assert (isequal ( A .\ D , D .\ D )) + assert (isequal ( D .\ A , D .\ D )) ***** test - % symfun or sym - syms x f(y) - a = f*x; - b = f(y)*x; - assert (isequal (findsymbols(a), {x y})) - assert (isequal (findsymbols(b), {x y})) + % matrix .\ matrix with symbols + syms x y + A = [x y; x^2 2*y]; + B = [y x; x y]; + assert (isequal ( A .\ A , sym(ones(2, 2)) )) + assert (isequal ( B .\ A , [x/y y/x; x 2] )) ***** test - % findsymbols on symfun does not find the argnames (unless they - % are on the RHS of course, this matches SMT 2014a). - syms a x y - f(x, y) = a; % const symfun - assert (isequal (findsymbols(f), {a})) - syms a x y - f(x, y) = a*y; - assert (isequal (findsymbols(f), {a y})) + % scalar .\ matrix + D = 3*[1 2; 3 4]; + A = sym(D); + assert (isequal ( 3 .\ A , 3 .\ D )) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/cosd.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cosd.m +***** error cosd (sym(1), 2) +***** assert (isequaln (cosd (sym(nan)), sym(nan))) ***** test - % sorts lexigraphically, same as symvar *with single input* - % (note symvar does something different with 2 inputs). - syms A B a b x y X Y - f = A*a*B*b*y*X*Y*x; - assert (isequal (findsymbols(f), {A B X Y a b x y})) - assert (isequal (symvar(f), [A B X Y a b x y])) + f1 = cosd (sym(1)); + f2 = cosd (1); + assert (double (f1), f2, -eps) ***** test - % symbols in matpow - syms x y - syms n - A = [sin(x) 2; y 1]; - B = A^n; - L = findsymbols(B); - assert (isequal (L, {n x y})) -Waiting........... + D = [10 30; 110 -45]; + A = sym(D); + f1 = cosd (A); + f2 = cosd (D); + assert (double (f1), f2, -4*eps) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/permute.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/permute.m +***** error permute (sym(1)) +***** error permute (sym(1), 2, 3) ***** test - % array of eq - syms x y - assert (isequal (findsymbols (2 == [2 x y]), {x y})) -:22: SymPyDeprecationWarning: - -non-Expr objects in a Matrix is deprecated. Matrix represents -a mathematical matrix. To represent a container of non-numeric -entities, Use a list of lists, TableForm, NumPy array, or some -other data structure instead. - -See https://docs.sympy.org/latest/explanation/active-deprecations.html#deprecated-non-expr-in-matrix -for details. - -This has been deprecated since SymPy version 1.9. It -will be removed in a future version of SymPy. - + D = round(10*rand(5,3)); + A = sym(D); + B = permute(A, [1 2]); + assert (isequal(B, A)) + B = permute(A, [2 1]); + assert (isequal(B, A.')) ***** test - % array of ineq - syms x y - A = [x < 1 2*x < y x >= 2 3 <= x x != y]; - assert (isequal (findsymbols (A), {x y})) -16 tests, 16 passed, 0 known failure, 0 skipped -[inst/fibonacci.m] ->>>>> /build/octave-symbolic-3.0.1/inst/fibonacci.m -***** assert (isequal ( fibonacci (sym(0)), 0)) -***** assert (isequal ( fibonacci (sym(14)), sym(377))) -***** assert (isequal ( fibonacci (14), 377)) -***** test syms x - assert (isequal (fibonacci (5,x), x^4 + 3*x^2 + 1)) + syms x + A = [1 x]; + B = permute(A, [2 1]); + assert (isequal(B, [1; x])) 4 tests, 4 passed, 0 known failure, 0 skipped -[inst/heaviside.m] ->>>>> /build/octave-symbolic-3.0.1/inst/heaviside.m -***** assert (heaviside (0) == 0.5) -***** assert (isnan (heaviside (nan))) -***** assert (isequal (heaviside ([-inf -eps 0 eps inf]), [0 0 0.5 1 1])) -***** assert (isequaln (heaviside ([-1 1 nan]), [0 1 nan])) -***** assert (heaviside (0, 1) == 1) -***** error heaviside (1i) -***** assert (isa (heaviside (single (0)), 'single')) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/horzcat.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/horzcat.m +[inst/@sym/tril.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/tril.m ***** test - % basic syms x - A = [x x]; - B = horzcat(x, x); - C = horzcat(x, x, x); - assert (isa (A, 'sym')) - assert (isa (B, 'sym')) - assert (isa (C, 'sym')) - assert (isequal (size(A), [1 2])) - assert (isequal (size(B), [1 2])) - assert (isequal (size(C), [1 3])) + assert (isequal (tril(x), x)) ***** test - % basic, part 2 + % with symbols syms x - A = [x 1]; - B = [1 x]; - C = [1 2 x]; - assert (isa (A, 'sym')) - assert (isa (B, 'sym')) - assert (isa (C, 'sym')) - assert (isequal (size(A), [1 2])) - assert (isequal (size(B), [1 2])) - assert (isequal (size(C), [1 3])) -***** test - % row vectors - a = [sym(1) 2]; - b = [sym(3) 4]; - assert (isequal ( [a b] , [1 2 3 4] )) - assert (isequal ( [a 3 4] , [1 2 3 4] )) - assert (isequal ( [3 4 a] , [3 4 1 2] )) - assert (isequal ( [a [3 4]] , [1 2 3 4] )) - assert (isequal ( [a sym(3) 4] , [1 2 3 4] )) - assert (isequal ( [a [sym(3) 4]] , [1 2 3 4] )) -***** test - % col vectors - a = [sym(1); 2]; - b = [sym(3); 4]; - assert (isequal ( [a b] , [1 3; 2 4] )) - assert (isequal ( [a b a] , [1 3 1; 2 4 2] )) -***** test - % empty vectors - v = sym(1); - a = [v []]; - assert (isequal (a, v)) - a = [[] v []]; - assert (isequal (a, v)) - a = [v [] []]; - assert (isequal (a, v)) + A = [x 2*x; 3*x 4*x]; + assert (isequal (tril(A), [x 0; 3*x 4*x])) ***** test - % more empty vectors - v = [sym(1) sym(2)]; - q = sym(ones(1, 0)); - assert (isequal ([v q], v)) -***** error - v = [sym(1) sym(2)]; - q = sym(ones(3, 0)); - w = horzcat(v, q); + % diagonal shifts + B = round(10*rand(3,4)); + A = sym(B); + assert (isequal (tril(A), tril(B))) + assert (isequal (tril(A,0), tril(B,0))) + assert (isequal (tril(A,1), tril(B,1))) + assert (isequal (tril(A,-1), tril(B,-1))) ***** test - % issue #700 - A = sym ([1 2]); - B = simplify (A); - assert (isequal ([B A], [A B])) -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/fliplr.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/fliplr.m + % double array pass through + B = round(10*rand(3,4)); + assert (isequal (tril(B,sym(1)), tril(B,1))) + assert (isa (tril(B,sym(1)), 'double')) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/tand.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/tand.m +***** error tand (sym(1), 2) +***** assert (isequaln (tand (sym(nan)), sym(nan))) ***** test - % simple - syms x - A = [x 2; sym(pi) x]; - B = [2 x; x sym(pi)]; - assert (isequal (fliplr(A), B)) + f1 = tand (sym(1)); + f2 = tand (1); + assert (double (f1), f2, -eps) ***** test - % simple, odd # cols - syms x - A = [x 2 sym(pi); x 1 2]; - B = [sym(pi) 2 x; 2 1 x]; - assert (isequal (fliplr(A), B)) + D = [10 30; 110 -45]; + A = sym(D); + f1 = tand (A); + f2 = tand (D); + assert (double (f1), f2, -eps) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/acosd.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/acosd.m +***** error acosd (sym(1), 2) +***** assert (isequaln (acosd (sym(nan)), sym(nan))) ***** test - % scalar - syms x - assert (isequal (fliplr(x), x)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/and.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/and.m -***** shared t, f - t = sym(true); - f = sym(false); + f1 = acosd (sym(1)/2); + f2 = acosd (1/2); + assert (double (f1), f2, -eps) ***** test - % simple - assert (isequal (t & f, f)) - assert (isequal (t & t, t)) + D = [1 2; 3 4]/4; + A = sym([1 2; 3 4])/4; + f1 = acosd (A); + f2 = acosd (D); + assert (double (f1), f2, -eps) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/diff.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/diff.m +***** shared x,y,z + syms x y z ***** test - % mix wih nonsym - assert (isequal (t & false, f)) - assert (isequal (t & true, t)) - assert (isequal (t & 0, f)) - assert (isequal (t & 1, t)) - assert (isa (t & false, 'sym')) - assert (isa (t & 1, 'sym')) + % basic + assert(logical( diff(sin(x)) - cos(x) == 0 )) + assert(logical( diff(sin(x),x) - cos(x) == 0 )) + assert(logical( diff(sin(x),x,x) + sin(x) == 0 )) ***** test - % array - w = [t t f f]; - z = [t f t f]; - assert (isequal (w & z, [t f f f])) + % these fail when doubles are not converted to sym + assert(logical( diff(sin(x),x,2) + sin(x) == 0 )) + assert(logical( diff(sym(1),x) == 0 )) + assert(logical( diff(1,x) == 0 )) + assert(logical( diff(pi,x) == 0 )) ***** test - % number - assert (isequal( sym(1) & t, t)) - assert (isequal( sym(0) & t, f)) + % symbolic diff of const (w/o variable) fails in sympy, but we work around + assert (isequal (diff(sym(1)), sym(0))) ***** test - % output is sym even for scalar t/f - assert (isa (t & f, 'sym')) + % nth symbolic diff of const + assert (isequal (diff(sym(1), 2), sym(0))) + assert (isequal (diff(sym(1), sym(1)), sym(0))) ***** test - % eqns, exclusive - syms x - e = (x == 3) & (x^2 == 9); - assert (isequal (subs(e, x, [-3 0 3]), [f f t])) -***** error and (sym('x'), 2, 3) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/ztrans.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ztrans.m + % octave's vector difference still works + assert(isempty(diff(1))) + assert((diff([2 6]) == 4)) ***** test - % basic Z-transform table checks - % X1, ..., X4 must have inner radius of convergence 1 - syms n z - % trick to extract the closed form formula using the fact that inner roc = 1 - closed_form = @(X) subs (X, abs (1 / z), 1 / sym (2)); - % check if ztrans(f) == X - check_ztrans = @(f, X) logical (simplify (closed_form (ztrans (f)) == X)); - f1 = sym (1); - X1 = 1 / (1 - 1 / z); - assert (check_ztrans (f1, X1)); - f2 = n; - X2 = (1 / z) / (1 - 1 / z)^2; - assert (check_ztrans (f2, X2)); - f3 = n^2; - X3 = (1 / z) * (1 + 1 / z) / (1 - 1 / z)^3; - assert (check_ztrans (f3, X3)); - f4 = n^3; - X4 = (1 / z) * (1 + 4 / z + 1 / z^2) / (1 - 1 / z)^4; - assert (check_ztrans (f4, X4)); - % basic matrix checks - A1 = ztrans ([f1 f2; f3 f4]); - B1 = [ztrans(f1) ztrans(f2); ztrans(f3) ztrans(f4)]; - assert (isequal (A1, B1)); - A2 = ztrans ([f1 f2; f3 f4], z); - B2 = [ztrans(f1, z) ztrans(f2, z); ztrans(f3, z) ztrans(f4, z)]; - assert (isequal (A2, B2)); - A3 = ztrans ([f1 f2; f3 f4], n, z); - B3 = [ztrans(f1, n, z) ztrans(f2, n, z); ztrans(f3, n, z) ztrans(f4, n, z)]; - assert (isequal (A3, B3)); + % other forms + f = sin(x); + g = diff(f,x,2); + assert (isequal (diff(f,2), g)) + assert (isequal (diff(f,sym(2)), g)) + g = diff(f,x); + assert (isequal (diff(f), g)) + assert (isequal (diff(f,1), g)) ***** test - % additional Z-transform table checks - % X1, ..., X4 must have inner radius of convergence a - syms n nonnegative integer - syms m positive integer - syms a - syms z - % trick to extract the closed form formula using the fact that inner roc = a - closed_form = @(X) subs (X, abs (a / z), 1 / sym (2)); - % check if ztrans(f) == X - check_ztrans = @(f, X) logical (simplify (closed_form (ztrans (f)) == X)); - f1 = a^n; - X1 = 1 / (1 - a / z); - assert (check_ztrans (f1, X1)); - f2 = n * a^n; - X2 = (a / z) / (1 - a / z)^2; - assert (check_ztrans (f2, X2)); - f3 = n^2 * a^n; - X3 = (a / z) * (1 + a / z) / (1 - a / z)^3; - assert (check_ztrans (f3, X3)); - f4 = nchoosek(n + m - 1, m - 1) * a^n; - X4 = 1 / (1 - a / z)^m; - assert (check_ztrans (f4, X4)); - % additional matrix checks - A1 = ztrans (f1, [n m; m n], [z a; a z]); - B1 = [ztrans(f1, n, z) ztrans(f1, m, a); ztrans(f1, m, a) ztrans(f1, n, z)]; - assert (isequal (A1, B1)); - A2 = ztrans (f1, m, [z a; a z]); - B2 = [ztrans(f1, m, z) ztrans(f1, m, a); ztrans(f1, m, a) ztrans(f1, m, z)]; - assert (isequal (A2, B2)); - A3 = ztrans (f1, [n m; m n], a); - B3 = [ztrans(f1, n, a) ztrans(f1, m, a); ztrans(f1, m, a) ztrans(f1, n, a)]; - assert (isequal (A3, B3)); + % old SMT supported (still does?) the 'n' before the 'x' + % we might remove this someday, no longer seems documented in SMT + f = sin(x); + g = diff(f,x,2); + assert (isequal (diff(f,2,x), g)) + assert (isequal (diff(f,sym(2),x), g)) + g = diff(f,x); + assert (isequal (diff(f,1,x), g)) ***** test - % Kronecker delta checks - syms n n0 nonnegative integer - syms z - assert (isequal (ztrans (kroneckerDelta (n)), 1)); - assert (isequal (ztrans (kroneckerDelta (n - n0)), 1 / z^n0)); + % matrix + A = [x sin(x); x*y 10]; + B = [1 cos(x); y 0]; + assert(isequal(diff(A,x),B)) ***** test - % basic var selection checks - syms n m z w - assert (isequal (ztrans (1 / factorial (n)), exp (1 / z))); - assert (isequal (ztrans (1 / factorial (z)), exp (1 / w))); - assert (isequal (ztrans (1 / factorial (m), w), exp (1 / w))); - assert (isequal (ztrans (1 / factorial (m), m, w), exp (1 / w))); + % bug: use symvar + a = x*y; + b = diff(a); + assert (isequal (b, y)) ***** test - % additional var selection checks - syms n m z - f = kroneckerDelta(m) / factorial (n); - assert (isequal (ztrans (f, z), exp (1 / z) * kroneckerDelta (m))); - assert (isequal (ztrans (f, n, z), exp (1 / z) * kroneckerDelta (m))); - assert (isequal (ztrans (f, m, z), 1 / factorial (n))); + % bug: symvar should be used on the matrix, not comp-by-comp + a = [x y x*x]; + b = diff(a); + assert (~isequal (b(2), 1)) + assert (isequal (b, [1 0 2*x])) + b = diff(a,1); + assert (~isequal (b(2), 1)) + assert (isequal (b, [1 0 2*x])) +10 tests, 10 passed, 0 known failure, 0 skipped +[inst/@sym/size.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/size.m ***** test - % if no t, use symvar: take x before a - syms a x z - assert (isequal (ztrans (a / factorial (x)), a * exp (1 / z))); -***** error ztrans (sym ('n')^sym ('n', 'nonnegative', 'integer')) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/igamma.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/igamma.m + a = sym([1 2 3]); + [n,m] = size(a); + assert (n == 1 && m == 3) ***** test - % mostly tested in @sym/gammainc - syms x - assert (isequal (igamma (2, x), gammainc(x, 2, 'upper'))) + a = sym([1 2 3]); + n = size(a); + assert (isequal (n, [1 3])) ***** test - % unregularized - B = double (igamma (sym(3), 1)); - A = gammainc (1, 3, 'upper')*gamma (3); - assert (A, B, -2*eps) + %% size, numel, length + a = sym([1 2 3; 4 5 6]); + assert (isa (size(a), 'double')) + assert (isa (numel(a), 'double')) + assert (isa (length(a), 'double')) + assert (isequal (size(a), [2 3])) + assert (length(a) == 3) + assert (numel(a) == 6) + a = sym([1; 2; 3]); + assert (isequal (size(a), [3 1])) + assert (length(a) == 3) + assert (numel(a) == 3) ***** test - % something like a round trip: no igamma() - syms x a - f = igamma (a, x); - h = function_handle (f, 'vars', [a x]); - A = h (1.1, 2.2); - B = double (igamma (sym(11)/10, sym(22)/10)); - C = gammainc (2.2, 1.1, 'upper')*gamma(1.1); - assert (A, B, -10*eps) - assert (A, C, -10*eps) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/csc.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/csc.m -***** error csc (sym(1), 2) -***** assert (isequaln (csc (sym(nan)), sym(nan))) + %% size by dim + a = sym([1 2 3; 4 5 6]); + n = size(a, 1); + assert (n == 2) + m = size(a, 2); + assert (m == 3) + a = sym([1 2 3]'); + n = size(a, 1); + assert (n == 3) + m = size(a, 2); + assert (m == 1) +***** xtest + % symbolic-size matrices + syms n m integer + A = sym('A', [n m]); + d = size(A); + assert (~isa(d, 'sym')) + assert (isnumeric(d)) + assert (isequaln (d, [NaN NaN])) +!!!!! known failure +assert (isequaln (d, [NaN, NaN])) failed +***** xtest + % half-symbolic-size matrices + % FIXME: will fail until size stop lying by saying 1x1 + syms n integer + A = sym('A', [n 3]); + assert (isequaln (size(A), [NaN 3])) + A = sym('A', [4 n]); + assert (isequaln (size(A), [4 NaN])) +!!!!! known failure +assert (isequaln (size (A), [NaN, 3])) failed +***** xtest + % half-symbolic-size empty matrices + % FIXME: will fail until size stop lying by saying 1x1 + syms n integer + A = sym('A', [n 0]); + assert (isequaln (size(A), [NaN 0])) +!!!!! known failure +assert (isequaln (size (A), [NaN, 0])) failed +7 tests, 4 passed, 3 known failures, 0 skipped +[inst/@sym/acos.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/acos.m +***** error acos (sym(1), 2) +***** assert (isequaln (acos (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = csc(x); - f2 = csc(d); + f1 = acos(x); + f2 = acos(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = csc(A); - f2 = csc(D); + f1 = acos(A); + f2 = acos(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = csc (d); - f = csc (y); + A = acos (d); + f = acos (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/trace.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/trace.m -***** test - % scalar - syms x - assert (isequal (trace(x), x)) -***** test - syms x - A = [x 3; 2*x 5]; - assert (isequal (trace(A), x + 5)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/isna.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isna.m +[inst/@sym/dawson.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/dawson.m ***** test - % no sym should be NA - syms x oo - assert (~isna(sym(1))) - assert (~isna(x)) - assert (~isna(oo)) - assert (~isna(sym(nan))) - assert (isequal (isna (sym ([1 nan])), [false false])) + if (exist ('OCTAVE_VERSION', 'builtin')) + % dawson missing on Matlab, Issue #742 + A = dawson([1 2]); + B = double(dawson(sym([1 2]))); + assert(A, B, -eps) + end 1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/transpose.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/transpose.m -***** test - x = sym(1); - assert (isequal (x.', x)) -***** assert (isempty (sym([]).')) -***** test - syms x; - assert (isequal (x.', x)) -***** test - A = [1 2; 3 4]; - assert(isequal( sym(A).' , sym(A.') )) +[inst/@sym/sympy.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sympy.m +***** assert (strcmp (sympy (sym(pi)), 'pi')) +***** assert (strcmp (sympy (sym(1)), 'Integer(1)')) +***** assert (strcmp (sympy (sym(2)/3), 'Rational(2, 3)')) +***** assert (strcmp (sympy (sym('x')), 'Symbol(''x'')')) ***** test - A = [1 2] + 1i; - assert(isequal( sym(A).' , sym(A.') )) + x = sym('x'); + assert (isequal (sym(sympy(x)), x)) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/symsum.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/symsum.m -***** error symsum (sym(1), 2, 3, 4, 5) -***** test - % finite sums - syms n - assert (isequal (symsum(n,n,1,10), 55)) - assert(isa(symsum(n,n,1,10), 'sym')) - assert (isequal (symsum(n,n,sym(1),sym(10)), 55)) - assert (isequal (symsum(n,n,sym(1),sym(10)), 55)) - assert (isequal (symsum(1/n,n,1,10), sym(7381)/2520)) -***** test - % negative limits - syms n - assert (isequal (symsum(n,n,-3,3), sym(0))) - assert (isequal (symsum(n,n,-3,0), sym(-6))) - assert (isequal (symsum(n,n,-3,-1), sym(-6))) +[inst/@sym/bessely.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/bessely.m ***** test - % one input - syms n - f = symsum (n); - g = n^2/2 - n/2; - assert (isequal (f, g)) - f = symsum (2*n); - g = n^2 - n; - assert (isequal (f, g)) + X = [1 2 3; 4 5 6]; + ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; + n = double(ns); + A = double(bessely(ns, X)); + B = bessely(n, X); + assert (all (all (abs (A - B) < 50*eps*abs(A)))) ***** test - % constant input - f = symsum (sym(2)); + % roundtrip syms x - g = 2*x; - assert (isequal (f, g)) -***** test - % two inputs - syms n - f = symsum (2*n, n); - g = n^2 - n; - assert (isequal (f, g)) -***** test - % two inputs, second is range - syms n - f = symsum (n, [1 6]); - g = 21; - assert (isequal (f, g)) - f = symsum (n, [sym(1) 6]); - g = 21; - assert (isequal (f, g)) - f = symsum (2*n, [1 6]); - g = 2*21; - assert (isequal (f, g)) + A = bessely(2, 10); + q = bessely(2, x); + h = function_handle(q); + B = h(10); + assert (abs (A - B) <= eps*abs(A)) +***** error bessely(sym('x')) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/laplacian.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/laplacian.m +***** shared x,y,z + syms x y z ***** test - % three inputs, last is range - syms n - f = symsum (2*n, n, [1 4]); - g = sym(20); - assert (isequal (f, g)) - f = symsum (2*n, n, [sym(1) 4]); - g = sym(20); - assert (isequal (f, g)) - f = symsum (2, n, [sym(1) 4]); - g = sym(8); - assert (isequal (f, g)) + % 1D + f = x^2; + g = diff(f,x,x); + assert (isequal (laplacian(f), g)) + assert (isequal (laplacian(f,{x}), g)) + assert (isequal (laplacian(f,[x]), g)) + assert (isequal (laplacian(f,x), g)) ***** test - % three inputs, no range - syms n - f = symsum (2*n, 1, 4); - g = sym(20); - assert (isequal (f, g)) - f = symsum (5, sym(1), 3); - g = sym(15); - assert (isequal (f, g)) + % const + f = sym(1); + g = sym(0); + assert (isequal (laplacian(f), g)) + assert (isequal (laplacian(f,x), g)) + f = sym('c'); + assert (isequal (laplacian(f,x), g)) ***** test - % ok to use double's for arguments in infinite series - syms n oo - assert(isequal(symsum(1/n^2,n,1,oo), sym(pi)^2/6)) - assert(isequal(symsum(1/n^2,n,1,inf), sym(pi)^2/6)) + % double const + f = 1; + g = sym(0); + assert (isequal (laplacian(f,x), g)) ***** test - % should be oo because 1 is real but seems to be - % zoo/oo depending on sympy version - syms n oo - zoo = sym('zoo'); - assert (isequal (symsum(1/n,n,1,oo), oo) || ... - isequal (symsum(1/n,n,1,oo), zoo)) -11 tests, 11 passed, 0 known failure, 0 skipped -[inst/@sym/besseljn.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/besseljn.m + % 1D fcn in 2d/3d + f = sin(2*y); + g = -4*f; + assert (isequal (laplacian(f), g)) + assert (isequal (laplacian(f, {x,y}), g)) + assert (isequal (laplacian(f, {x,y,z}), g)) ***** test - % roundtrip - syms x - A = double(besseljn(sym(2), sym(9))); - q = besseljn(sym(2), x); - h = function_handle(q); - B = h(9); - assert (abs (A - B) <= eps) -***** error jn(sym('x')) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/isempty.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isempty.m -***** shared se, a - se = sym ([]); - a = sym ([1 2]); -***** assert (~isempty (sym (1))) -***** assert (isempty (sym (se))) -***** assert (isempty (se == [])) + % 2d fcn in 2d/3d + f = sin(exp(x)*y); + g = diff(f,x,x) + diff(f,y,y); + assert (isequal (laplacian(f), g)) + assert (isequal (laplacian(f, {x,y}), g)) ***** test -***** test se(1) = 10; -***** test assert ( isa (se, 'sym')) -***** test assert ( isequal (se, 10)) -***** shared + % 2d fcn in 2d/3d + f = sin(exp(x)*y+sinh(z)); + gr2 = gradient(f, {x,y}); + divgr2 = divergence(gr2, {x,y}); + l2 = laplacian(f,{x,y}); + gr3 = gradient(f, {x,y,z}); + divgr3 = divergence(gr3, {x,y,z}); + l3 = laplacian(f,{x,y,z}); + assert (isAlways (l2 == divgr2)) + assert (isAlways (l3 == divgr3)) +Waiting........... +***** error laplacian(sym('x'), sym('x'), 42) +***** error laplacian([sym('x'), sym('x')]) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/jacobian.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/jacobian.m +***** error jacobian (sym(1), 2, 3) +***** error jacobian ([sym(1) 2; sym(3) 4]) +***** shared x,y,z + syms x y z ***** test - % empty matrices - A = sym('A', [3 0]); - assert (isempty (A)) - A = sym(ones(3,0)); - assert (isempty (A)) + % 1D + f = x^2; + assert (isequal (jacobian(f), diff(f,x))) + assert (isequal (jacobian(f,{x}), diff(f,x))) + assert (isequal (jacobian(f,x), diff(f,x))) ***** test - % non-empty symbolic-size matrices - syms n integer - A = sym('A', [3 n]); - assert (~isempty (A)) -***** xtest - % empty symbolic-size matrices - % FIXME: will fail until size stop lying by saying 1x1 - syms n integer - A = sym('A', [0 n]); - assert (isempty (A)) - A = sym('A', [n 0]); - assert (isempty (A)) -!!!!! known failure -assert (isempty (A)) failed -10 tests, 9 passed, 1 known failure, 0 skipped -[inst/@sym/setxor.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/setxor.m + % const + f = sym(1); + g = sym(0); + assert (isequal (jacobian(f), g)) + assert (isequal (jacobian(f,x), g)) ***** test - A = sym([1 2 3]); - B = sym([1 2 4]); - C = setxor(A, B); - D1 = sym([3 4]); - D2 = sym([4 3]); - assert (isequal (C, D1) || isequal (C, D2)) + % double const + f = 1; + g = sym(0); + assert (isequal (jacobian(f,x), g)) ***** test - % one nonsym - A = sym([1 2 3]); - B = [1 2 4]; - C = setxor(A, B); - D1 = sym([3 4]); - D2 = sym([4 3]); - assert (isequal (C, D1) || isequal (C, D2)) + % diag + f = [x y^2]; + g = [sym(1) 0; 0 2*y]; + assert (isequal (jacobian(f), g)) + assert (isequal (jacobian(f, [x y]), g)) + assert (isequal (jacobian(f, {x y}), g)) ***** test - % empty - A = sym([1 2 3]); - C = setxor(A, A); - assert (isempty (C)) + % anti-diag + f = [y^2 x]; + g = [0 2*y; sym(1) 0]; + assert (isequal (jacobian(f), g)) + assert (isequal (jacobian(f, {x y}), g)) ***** test - % empty input - A = sym([1 2]); - C = setxor(A, []); - assert (isequal (C, A) || isequal (C, sym([2 1]))) + % shape + f = [x y^2]; + assert (isequal (size(jacobian(f, {x y z})), [2 3])) + assert (isequal (size(jacobian(f, [x y z])), [2 3])) + assert (isequal (size(jacobian(f, [x; y; z])), [2 3])) + assert (isequal (size(jacobian(f.', {x y z})), [2 3])) ***** test - % scalar - syms x - assert (isequal (setxor([x 1], x), sym(1))) - assert (isempty (setxor(x, x))) + % scalar f + f = x*y; + assert (isequal (size(jacobian(f, {x y})), [1 2])) + g = gradient(f, {x y}); + assert (isequal (jacobian(f, {x y}), g.')) ***** test - A = interval(sym(1), 3); - B = interval(sym(2), 5); - C = setxor(A, B); - D = union (interval (sym(1), 2, false, true), interval (sym(3), 5, true, false)); - assert( isequal( C, D)) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/acot.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/acot.m -***** error acot (sym(1), 2) -***** assert (isequaln (acot (sym(nan)), sym(nan))) + % vect f wrt 1 var + f = [x x^2]; + assert (isequal (size(jacobian(f, x)), [2 1])) + f = f.'; % same shape output + assert (isequal (size(jacobian(f, x)), [2 1])) +10 tests, 10 passed, 0 known failure, 0 skipped +[inst/@sym/csc.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/csc.m +***** error csc (sym(1), 2) +***** assert (isequaln (csc (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = acot(x); - f2 = acot(d); + f1 = csc(x); + f2 = csc(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = acot(A); - f2 = acot(D); + f1 = csc(A); + f2 = csc(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = acot (d); - f = acot (y); + A = csc (d); + f = csc (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/all.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/all.m +[inst/@sym/zeros.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/zeros.m ***** test - % matrix - a = [0 3; 1 2]; - s = sym (a); - assert (isequal (all (s), all (a))) - assert (isequal (all (s,1), all (a,1))) - assert (isequal (all (s,2), all (a,2))) + y = zeros(sym(2)); + x = [0 0; 0 0]; + assert( isequal( y, sym(x))) ***** test - % vector - a = [1 2 3]; - s = sym (a); - assert (isequal (all (s), all (a))) - assert (isequal (all (s,1), all (a,1))) - assert (isequal (all (s,2), all (a,2))) + y = zeros(sym(2), 1); + x = [0; 0]; + assert( isequal( y, sym(x))) ***** test - % should fail on symbols - syms x - s = [1 2 x]; - try - all (s) - waserr = false; - catch - waserr = true; - end - assert (waserr) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/cond.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cond.m + y = zeros(sym(1), 2); + x = [0 0]; + assert( isequal( y, sym(x))) ***** test - A = [1 2; 3 4]; - B = sym(A); - k1 = cond(A); - k2 = cond(B); - k3 = double(k2); - assert (k1 - k3 <= 100*eps) + y = zeros (sym([2 3])); + x = sym (zeros ([2 3])); + assert (isequal (y, x)) +***** assert( isa( zeros(sym(2), 'double'), 'double')) +***** assert( isa( zeros(3, sym(3), 'single') , 'single')) +***** assert( isa( zeros(3, sym(3)), 'sym')) +***** assert( isa( zeros(3, sym(3), 'sym'), 'sym')) +***** xtest + % Issue #13 + assert( isa( zeros(3, 3, 'sym'), 'sym')) +!!!!! known failure +invalid data type specified +9 tests, 8 passed, 1 known failure, 0 skipped +[inst/@sym/subsasgn.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/subsasgn.m +***** shared a,b + b = [1:4]; + a = sym(b); +***** test a(1) = 10; b(1) = 10; + assert(isequal( a, b )) +***** test I = logical([1 0 1 0]); + a(I) = 2; b(I) = 2; + assert(isequal( a, b )) +***** test I = logical([1 0 1 0]); + a(I) = [2 4]; b(I) = [2 4]; + assert(isequal( a, b )) +***** test I = logical([1 0 1 0]); + a(I) = [2; 4]; b(I) = [2; 4]; + assert(isequal( a, b )) +***** shared ***** test - % matrix with symbols - syms x positive - A = [x 0; sym(0) 2*x]; - k1 = cond(A); - assert (isequal (k1, sym(2))) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/max.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/max.m + b = 1:4; b = [b; 2*b; 3*b]; + a = sym(b); + rhs = [10 11; 12 13]; + a([1:2],[1:2]) = rhs; + b([1:2],[1:2]) = rhs; + assert(isequal( a, b )) + a(1:2,1:2) = rhs; + assert(isequal( a, b )) ***** test - % simple - assert (isequal (max([sym(10) sym(11)]), sym(11))) + % slice : + b = 1:4; b = [b; 2*b]; + a = sym(b); + rhs = [10 11; 12 13]; + a(:,2:3) = rhs; + b(:,2:3) = rhs; + assert(isequal( a, b )) ***** test - syms x y - assert (isequal (children (max (x, y)), [x y])) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/power.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/power.m + % grow 2D + b = 1:4; b = [b; 2*b]; + a = sym(b); + rhs = [10 11; 12 13]; + a([1 end+1],end:end+1) = rhs; + b([1 end+1],end:end+1) = rhs; + assert(isequal( a, b )) ***** test - % scalar .^ scalar - syms x - assert (isa (x.^2, 'sym')) - assert (isa (2.^x, 'sym')) - assert (isa (x.^x, 'sym')) - assert (isequal (x.^2, x^2)) - assert (isequal (2.^x, 2^x)) - assert (isequal (x.^x, x^x)) + % grow from nothing + clear a + a(3) = sym (1); + b = sym ([0 0 1]); + assert (isequal (a, b)) ***** test - % scalar .^ matrix - D = [0 1; 2 3]; - A = sym(D); - assert (isequal ( sym(2).^D , 2.^D )) - assert (isequal ( sym(2).^A , 2.^A )) - assert (isequal ( 2.^D , 2.^A )) - assert (isequal ( 2.^A , 2.^A )) + % grow from nothing, 2D + clear a + a(2, 3) = sym (1); + b = sym ([0 0 0; 0 0 1;]); + assert (isequal (a, b)) ***** test - % matrix .^ matrix - syms x - A = [x 2*x; 3*x 4*x]; - D = [0 1; 2 3]; - B = sym(D); - assert (isequal ( A.^D, [1 2*x; 9*x^2 64*x^3] )) - assert (isequal ( A.^B, [1 2*x; 9*x^2 64*x^3] )) + % linear indices of 2D + b = 1:4; b = [b; 2*b; 3*b]; + a = sym(b); + b(1:4) = [10 11 12 13]; + a(1:4) = [10 11 12 13]; + assert(isequal( a, b )) + b(1:4) = [10 11; 12 13]; + a(1:4) = [10 11; 12 13]; + assert(isequal( a, b )) +***** error + % Wrong shape matrix RHS: Matlab/Octave don't allow this on doubles. + % Matlab SMT 2013b gets it wrong. We throw an error. + rhs = [10 11; 12 13]; + a = sym (magic (3)); + a(1:2,1:2) = rhs(:); ***** test - % matrix .^ scalar - syms x - A = [x 2*x]; - assert (isequal ( A.^2, [x^2 4*x^2] )) - assert (isequal ( A.^sym(2), [x^2 4*x^2] )) + % Issue #963: vector RHS with diff orientation from 2D indexing + b = 1:4; b = [b; 2*b; 3*b]; + a = sym(b); + b(1:2:3, 1) = 11:2:13; + a(1:2:3, 1) = sym(11:2:13); + assert (isequal (a, b)) + b(1:2:3, 1) = 1:2:3; + a(1:2:3, 1) = 1:2:3; + assert (isequal (a, b)) ***** test - % 1^oo - % (sympy >= 0.7.5 gives NaN, SMT R2013b: gives 1) - oo = sym(inf); - assert (isnan (1^oo)) + % Issue #963: vector RHS with diff orientation from 2D indexing + a = sym (magic (3)); + b = a; + a(1:2:3, 2) = [14 15]; + b(1:2:3, 2) = [14; 15]; + assert (isequal (a, b)) + a(2, 1:2:3) = [24 25]; + b(2, 1:2:3) = [24; 25]; + assert (isequal (a, b)) ***** test - % 1^zoo - % (1 on sympy 0.7.4--0.7.6, but nan in git (2014-12-12, a210908d4)) - zoo = sym('zoo'); - assert (isnan (1^zoo)) + % 1D growth and 'end' + g = sym([1 2 3]); + g(3:4) = [67 68]; + g(end:end+1) = [12 14]; + assert(isequal( g, [1 2 67 12 14] )) ***** test - % immutable test - A = sym([1 2]); - B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)]])'); - assert (isequal (A.^A, B.^B)) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/eq.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/eq.m + % expanding empty and scalar + syms x + c = sym([]); + c(1) = x; + assert(isequal( c, x )) + c(2) = 2*x; + assert(isequal( c, [x 2*x] )) +***** shared a,b,I,J + b = 1:4; b = [b; 3*b; 5*b]; a = sym(b); + I = logical([1 0 1]); + J = logical([1 0 1 0]); +***** assert(isequal( a(I,J), b(I,J) )) ***** test - % simple tests with scalar numbers - assert (logical (sym(1) == sym(1))) - assert (logical (sym(1) == 1)) - assert (~logical (sym(1) == 0)) - assert (isequal (sym(1) == sym(1), sym(true))) - assert (isequal (sym(1) == 1, sym(true))) - assert (isequal (sym(1) == 0, sym(false))) + rhs = [90 91; 92 93]; + b(I, J) = rhs; + a(I, J) = rhs; + assert(isequal( a, b )) ***** test - % Type of the output is sym or logical? - % FIXME: in current version, they are sym - e = sym(1) == sym(1); - %assert (islogical (e)) - assert (isa (e, 'sym')) + b(I, J) = 100; + a(I, J) = 100; + assert(isequal( a, b )) +***** shared ***** test - % things involving a variable are usually not bool but sym. - % (SMT behaviour says always, FIXME: currently we differ.) + % logical with all false syms x - e = x == 0; - assert (~islogical (e)) - assert (isa (e, 'sym')) + y = x; + y(false) = 6; + assert(isequal( y, x )); + a = [x x]; + a([false false]) = [6 6]; + assert(isequal( a, [x x] )); ***** test - % ... except of course via cancelation + % issue #18, scalar access syms x - e = x - x == 0; - assert (logical (e)) - assert (isequal (e, sym(true))) -***** test - % array == array - a = sym([1 2; 3 4]); - y = a == a; - assert (isequal( size(y), [2 2])) - assert (isequal (y, sym([true true; true true]))) - assert (all(all(y))) - y = a == 1; - assert (isequal( size(y), [2 2])) - assert (isequal (y, sym([true false; false false]))) - assert (any(any(y))) - y = a == 42; - assert (isequal( size(y), [2 2])) - assert (isequal (y, sym([false false; false false]))) + x(1) = sym(6); + assert(isequal( x, sym(6) )); + x(1) = 6; + assert(isequal( x, sym(6) )); + x(true) = 88; + assert(isequal( x, sym(88) )); ***** test - % more array == array - D = [0 1; 2 3]; - A = [sym(0) 1; sym(2) 3]; - DZ = D - D; - assert (isequal (logical(A == A), [true true; true true])) - assert (isequal (logical(A == D), [true true; true true])) - assert (isequal (logical(A - D == DZ), [true true; true true])) - assert (all (all ( A == A ))) - assert (all (all ( A == D ))) - assert (all (all ( A - D == DZ ))) + % bug: assignment to column vector used to fail + A = sym(zeros(3,1)); + A(1) = 5; ***** test - % logical output, right shape, etc - t = true; f = false; - a = sym([0 1 2; 3 4 5]); - b = sym([0 1 1; 3 5 5]); - e = a == b; - eexp = sym(logical([1 1 0; 1 0 1])); - assert (isequal (e, eexp)) - a = sym([0 1 2]); - b = sym([0 1 1]); - e = a == b; - eexp = sym(logical([1 1 0])); - assert (isequal (e, eexp)) - e = a' == b'; - eexp = eexp.'; % is/was bug here with ' - assert (isequal (e, eexp)) + % symfun creation (generic function) + syms x + g(x) = x*x; + assert(isa(g,'symfun')) ***** test - % empty matrices compare to correct empty size - a = zeros (sym(3), 0); - assert (size (a == a), [3, 0]) - a = zeros (sym(0), 2); - assert (size (a == a), [0, 2]) -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/rdivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/rdivide.m + % symfun creation (generic function) + syms x g(x) + assert(isa(g,'symfun')) ***** test - % scalar + % symfun creation when g already exists and is a sym/symfun syms x - assert (isa (x ./ 1, 'sym')) - assert (isa (x ./ x, 'sym')) - assert (isequal (x ./ 1, x)) - assert (isequal (x ./ x, sym(1))) + g = x; + syms g(x) + assert(isa(g,'symfun')) + clear g + g(x) = x; + g(x) = x*x; + assert(isa(g,'symfun')) ***** test - % matrix-scalar - D = 2*[0 1; 2 3]; - A = sym(D); - assert (isequal ( A./2 , D/2 )) - assert (isequal ( A./sym(2) , D/2 )) - assert (isequal ( D./sym(2) , D/2 )) + % Issue #443: assignment with sym indices + A = sym([10 11]); + A(sym(1)) = 12; + assert (isequal (A, sym([12 11]))) ***** test - % matrix ./ matrix - D = [1 2; 3 4]; - A = sym(D); - assert (isequal ( A./A , D./D )) - assert (isequal ( A./D , D./D )) - assert (isequal ( D./A , D./D )) + % Issue #443: assignment with sym indices + A = sym([10 11]); + A(sym(1), 1) = 12; + assert (isequal (A, sym([12 11]))) + A(sym(1), sym(1)) = 13; + assert (isequal (A, sym([13 11]))) ***** test - % matrix ./ matrix with symbols - syms x y - A = [x y; x^2 2*y]; - B = [y x; x y]; - assert (isequal ( A./A , sym(ones(2,2)) )) - assert (isequal ( A./B , [x/y y/x; x 2] )) + % Issue #443: assignment with sym indices, increase size + A = sym([10 11]); + A(sym(2), 1) = 12; + assert (isequal (A, sym([10 11; 12 0]))) +***** error + % Issue #443 + A = sym([10 11]); + A(2, sym('x')) = sym(12); +***** error + % Issue #443 + A = sym([10 11]); + A(sym(2), sym('x')) = sym(12); +***** error + % issue #445 + A = sym([10 11]); + A(1.1) = 13 +***** error + % issue #445 + A = sym([10 11]); + A(sym(pi)) = 13 +***** error + % issue #445 + A = sym([1 2; 3 4]); + A(1.3, 1.2) = 13 ***** test - % scalar ./ matrix - D = [1 2; 3 4]; - A = sym(D); - assert (isequal ( 12./A , 12./D )) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/int.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/int.m -***** shared x,y,a - syms x y a -***** assert(logical(int(cos(x)) - sin(x) == 0)) -***** assert(logical(int(cos(x),x) - sin(x) == 0)) -***** assert(logical(int(cos(x),x,0,1) - sin(sym(1)) == 0)) + % older expansion tests + syms x + f = [2*x 3*x]; + f(2) = 4*x; + assert (isequal (f, [2*x 4*x])) + f(2) = 2; + assert (isequal(f, [2*x 2])) + g = f; + g(1,3) = x*x; + assert (isequal(g, [2*x 2 x^2])) + g = f; + g(3) = x*x; + assert (isequal(g, [2*x 2 x^2])) + g = f; + g(3) = 4; + assert (isequal(g, [2*x 2 4])) ***** test - %% limits might be syms - assert( isequal (int(cos(x),x,sym(0),sym(1)), sin(sym(1)))) - assert( isequal (int(cos(x),x,0,a), sin(a))) + % older slicing tests + syms x + f = [1 x^2 x^4]; + f(1:2) = [x x]; + assert (isequal( f, [x x x^4] )) + f(1:2) = [1 2]; + assert (isequal( f, [1 2 x^4] )) + f(end-1:end) = [3 4]; + assert (isequal( f, [1 3 4] )) + f(3:4) = [10 11]; + assert (isequal( f, [1 3 10 11] )) + f(end:end+1) = [12 14]; + assert (isequal( f, [1 3 10 12 14] )) ***** test - %% other variables present - assert( isequal (int(y*cos(x),x), y*sin(x))) + % struct.str = sym, sometimes calls subsasgn + d = struct(); + syms x + d.a = x; + assert (isa (d, 'struct')) + assert (isequal (d.a, x)) + d.('a') = x; + assert (isa (d, 'struct')) + assert (isequal (d.a, x)) + d = setfield(d, 'a', x); + assert (isa (d, 'struct')) + assert (isequal (d.a, x)) + % at least on Oct 3.8, this calls sym's subsasgn + d = struct(); + d = setfield(d, 'a', x); + assert (isa (d, 'struct')) + assert (isequal (d.a, x)) ***** test - %% limits as array - assert( isequal (int(cos(x),x,[0 1]), sin(sym(1)))) - assert( isequal (int(cos(x),x,sym([0 1])), sin(sym(1)))) - assert( isequal (int(cos(x),x,[0 a]), sin(a))) + % bool scalar assignments of true/false into sym + syms x + a = sym([1 2 x 3]); + b = [1 2 10 4]; + e = a == b; + assert (logical (e(2))) + e(2) = false; + assert (~logical (e(2))) +:22: SymPyDeprecationWarning: + +non-Expr objects in a Matrix is deprecated. Matrix represents +a mathematical matrix. To represent a container of non-numeric +entities, Use a list of lists, TableForm, NumPy array, or some +other data structure instead. + +See https://docs.sympy.org/latest/explanation/active-deprecations.html#deprecated-non-expr-in-matrix +for details. + +This has been deprecated since SymPy version 1.9. It +will be removed in a future version of SymPy. + ***** test - %% no x given - assert( isequal (int(cos(x),[0 1]), sin(sym(1)))) - assert( isequal (int(cos(x),sym([0 1])), sin(sym(1)))) - assert( isequal (int(cos(x),[0 a]), sin(a))) - assert( isequal (int(cos(x),0,a), sin(a))) + % bool vector assignments of true/false into sym + syms x + a = sym([1 2 x 3]); + b = [1 2 10 4]; + e = a == b; + e(1:2) = [true true]; + assert (isequal (e, [sym(1)==1 sym(2)==2 x==10 sym(3)==4])) ***** test - %% integration of const - assert( isequal (int(sym(2),y), 2*y)) - assert( isequal (int(sym(2)), 2*x)) - assert( isequal (int(sym(2),[0 a]), 2*a)) - assert( isequal (int(sym(2),0,a), 2*a)) + % bool scalar promoted to vector assignments into sym + syms x + a = sym([1 2 x 3]); + b = [1 2 10 4]; + e = a == b; + e(1:2) = true; + assert (isequal (e, [sym(1)==1 sym(2)==2 x==10 sym(3)==4])) ***** test - % componentwise int of array - A = [x x*x]; - assert (isequal (int(A, x), [x^2/2 x^3/3])) + % grow scalar equality expression into a matrix of equalities + syms a b c d + e = a == b; + e(2) = c == d; + assert (isequal (e, [a==b c==d])) +***** shared a, b, I + b = [1:4]; b = [b; 3*b; 5*b]; + a = sym(b); + I = mod (b, 5) > 1; ***** test - % NonElementaryIntegral bug - % https://savannah.gnu.org/bugs/index.php?46831 - f = int(exp(exp(x))); - f = f + 2; - g = diff(f); - assert (isequal (g, exp(exp(x)))) -10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@sym/conj.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/conj.m + A = a; A(I) = 2*b(I); + B = b; B(I) = 2*b(I); + assert (isequal (A, B)) ***** test - a = sym(6); - b = sym(5i); - assert (isequal (conj(a), a)) - assert (isequal (conj(b), -b)) - assert (isequal (conj(a+b), a-b)) + % scalar RHS + A = a; A(I) = 17; + B = b; B(I) = 17; + assert (isequal (A, B)) ***** test - syms x - assert (isequal (conj(conj(x)), x)) + % nonetheless, above strange case should give right answer + I = logical([1 0 1 0; 0 1 0 1; 1 0 1 0]); + rhs = 2*b(I); + rhs2 = reshape(rhs, 2, 3); + A0 = a; A1 = a; + A0(I) = rhs; + A1(I) = rhs2; + assert (isequal (A0, A1)) +***** shared AA, BB + BB = [1 2 3; 4 5 6]; + AA = sym(BB); ***** test - syms x real - assert (isequal (conj(x), x)) + A = AA; B = BB; + B([1 6]) = [8 9]; + A([1 6]) = [8 9]; + assert (isequal (A, B)) ***** test - % array - syms x - A = [x 6+1i; sym(1) x+2i]; - B = [conj(x) 6-1i; sym(1) conj(x)-2i]; - assert (isequal (conj(A), B)) + % rhs scalar + A = AA; B = BB; + B([1 6]) = 88; + A([1 6]) = 88; + assert (isequal (A, B)) ***** test - % true/false - t = sym(true); - f = sym(false); - assert (isequal ( conj(t), t)) - assert (isequal ( conj(f), f)) + % If rhs is not a vector, make sure col-based access works + rhs = [18 20; 19 21]; + A = AA; B = BB; + B([1 6]) = 88; + A([1 6]) = 88; + B([1 2 3 4]) = rhs; + A([1 2 3 4]) = rhs; + assert (isequal (A, B)) ***** test - % round trip - syms x - d = 3 - 5i; - f = conj (x); - A = conj (d); - h = function_handle (f); - B = h (d); - assert (A, B) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/gammaln.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/gammaln.m -***** assert (isequal (gammaln (sym (3)), log (sym (2)))) -***** assert (isequal (gammaln (sym (10)), log (gamma (sym (10))))) + % Growth + A = AA; B = BB; + A(1,5) = 10; + B(1,5) = 10; + assert (isequal (A, B)) +***** shared ***** test - % compare to Maple: evalf(lnGAMMA(Pi)); - maple = vpa ('0.827694592323437101529578558452359951153502', 40); - us = vpa (gammaln (sym(pi)), 40); - assert (abs(double(maple-us)) < 1e-39) + % Check row deletion 1D + a = sym([1; 3; 5]); + b = sym([3; 5]); + a(1) = []; + assert( isequal( a, b)) ***** test - % compare to Maple: evalf(lnGAMMA(3+2*I)); - maple = vpa ('-0.0316390593739611898037677296008797172022603', 40) + ... - vpa ('2.02219319750132712401643376238334982100512j', 40); - us = vpa (gammaln (sym(3) + 2i), 40); - assert (abs(double(maple-us)) < 1e-39) + % Check column deletion 1D + a = sym([1, 4, 8]); + b = sym([4, 8]); + a(1) = []; + assert( isequal( a, b)) ***** test - % compare to Maple: evalf(lnGAMMA(-1.5)); - % notably, @double/gammaln has zero imag part - maple = vpa ('0.8600470153764810145109326816703567873271571', 40) - ... - vpa ('6.2831853071795864769252867665590057683943388j', 40); - us = vpa (gammaln (-sym(3)/2), 40); - assert (abs(double(maple-us)) < 1e-39) -***** assert (gammaln (pi), double (gammaln (sym (pi))), -3*eps) -***** assert (gammaln (100), double (gammaln (sym (100))), -3*eps) -***** assert (gammaln (1e-3), double (gammaln (1/sym (1e3))), -100*eps) + % Check row deletion 2D + a = sym([1, 2; 3, 4]); + b = sym([3, 4]); + a(1, :) = []; + assert( isequal( a, b)) ***** test - % round trip - syms x - f = gammaln (x); - h = function_handle (f); - A = h (1.1); - B = gammaln (1.1); - assert (A, B) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/uminus.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/uminus.m + % Check column deletion 2D + a = sym([1, 2; 3, 4]); + b = sym([2; 4]); + a(:, 1) = []; + assert( isequal( a, b)) ***** test - % scalar - syms x - assert (isa (-x, 'sym')) - assert (isequal (-(-x), x)) + % General assign + a = sym([1, 2; 3, 4]); + b = sym([5, 5; 5, 5]); + a(:) = 5; + assert( isequal( a, b)) ***** test - % matrix - D = [0 1; 2 3]; - A = sym(D); - assert( isequal( -A, -D )) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/erfi.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfi.m -***** error erfi (sym(1), 2) -***** assert (isequaln (erfi (sym(nan)), sym(nan))) -***** shared x, d - d = 0; - x = sym('0'); + % Empty matrix + a = sym([1, 2; 3, 4]); + a(:) = []; + assert( isequal( a, sym([]))) ***** test - f1 = erfi(x); - f2 = 0; - assert( abs(double(f1) - f2) < 1e-15 ) + % Disassemble matrix + a = sym([1 2; 3 4; 5 6]); + b = sym([3 5 2 4 6]); + a(1) = []; + assert (isequal (a, b)); +***** error + a = sym([1, 2; 3, 4]); + a(1, 2) = []; ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = erfi(A); - f2 = 0; - f2 = [f2 f2; f2 f2]; - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % Issue #964 + a = sym(10); + a(1) = []; + assert (isempty (a)) + assert (isequal (a, zeros(1, 0))) ***** test - % round trip - y = sym('y'); - A = erfi (d); - f = erfi (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/factor.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/factor.m + % Issue #963: scalar asgn to empty part of matrix + A = sym (magic (3)); + B = A; + A(1, []) = 42; + assert (isequal (A, B)) + A([], 2) = 42; + assert (isequal (A, B)) + A([]) = 42; + assert (isequal (A, B)) + A([], []) = 42; + assert (isequal (A, B)) + A(2:3, []) = 42; + assert (isequal (A, B)) + A([], 2:3) = 42; + assert (isequal (A, B)) + A(:, []) = 42; + assert (isequal (A, B)) + A([], :) = 42; + assert (isequal (A, B)) ***** test - % n = 152862; - % [p,m] = factor(n); % only works on Octave, no Matlab as of 2014a - n = 330; % so we use an output without repeated factors - p = factor(n); m = ones(size(p)); - [ps,ms] = factor(sym(n)); - assert (isequal (p, ps)) - assert (isequal (m, ms)) + % Issue #1026 + a = sym(1:5); + a(1:3) = []; + assert (isequal (a, sym([4 5]))) ***** test - n = sym(2)^4*13; - [p,m] = factor(n); - assert (isequal (p, [2 13])) - assert (isequal (m, [4 1])) -***** test syms x - assert( logical (factor(x^2 + 6*x + 5) == (x+5)*(x+1))) + % Issue #1026 + B = eye(4); + A = sym(B); + A(1:2, :) = []; + B(1:2, :) = []; + assert (isequal (A, B)) +***** error + % TODO: do we care what error? + A = sym (magic (3)); + A(2:3, []) = [66; 66]; +***** error + A = sym (magic (3)); + A([]) = [66; 66]; +***** error + A = sym (magic (3)); + A([], 1) = [66; 66]; ***** test - syms x - f = [ x^4/2 + 5*x^3/12 - x^2/3 x^2 - 1 10]; - g = [ x^2*(2*x - 1)*(3*x + 4)/12 (x+1)*(x-1) 10]; - assert (isequal (factor(f), g)) + % Issue #966: empty indexing, empty RHS, A unchanged + B = magic(3); + A = sym(B); + A(1, []) = []; + assert (isequal (A, B)) + A([], 2) = []; + assert (isequal (A, B)) + A([], []) = []; + assert (isequal (A, B)) + A(2:3, []) = []; + assert (isequal (A, B)) + A([], 2:3) = []; + assert (isequal (A, B)) + A(:, []) = []; + assert (isequal (A, B)) + A([], :) = []; + assert (isequal (A, B)) ***** test - % "fragile form" works - A = factor(sym(124)); - B = strtrim(disp(A, 'flat')); - assert (strcmp (B, '2**2*31**1')) -***** error [p, m] = factor(sym('x')); -***** error [p, m] = factor(sym(42), sym('x')); + % Issue 967 + B = [1 2; 3 4]; + A = sym(B); + A([]) = []; + assert (isequal (A, B)) ***** test - % if polynomial happens to be a constant, don't attempt integer - % factorization if a variable is specified - f = sym(42); - q = factor(f, sym('x')); - assert (isequal (f, q)); -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/adjoint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/adjoint.m + % Issue #965 + a = sym(7); + a([]) = []; + assert (isequal (a, sym(7))) ***** test - syms x - A = [x x^2; x^3 x^4]; - B = [x^4 -x^2; -x^3 x]; - assert( isequal( adjoint(A), B )) -***** test syms x - assert( isequal( adjoint(x), 1)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/prod.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/prod.m -***** error prod (sym(1), 2, 3) -***** error prod (sym(1), 42) -***** shared x,y,z - syms x y z -***** assert (isequal (prod (x), x)) -***** assert (isequal (prod ([x y z]), x*y*z)) -***** assert (isequal (prod ([x; y; z]), x*y*z)) -***** assert (isequal (prod ([x y z], 1), [x y z])) -***** assert (isequal (prod ([x y z], 2), x*y*z)) -***** shared a,b - b = [1 2; 3 4]; a = sym(b); -***** assert (isequal (prod(a), prod(b))) -***** assert (isequal (prod(a,1), prod(b,1))) -***** assert (isequal (prod(a,2), prod(b,2))) + % Issue #965 + a = sym(7); + a([]) = 42; + assert (isequal (a, sym(7))) +***** error + % Issue #965 + a = sym(7); + a([]) = [42 42] ***** test - % weird inputs - a = prod('xx', sym(1)); - assert (isequal (a, sym('xx'))) -11 tests, 11 passed, 0 known failure, 0 skipped -[inst/@sym/expint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/expint.m -***** error expint (sym(1), 2, 3) + b = eye (3); + a = sym (b); + I = [2 3; 4 5]; + a(I) = -2*I; + b(I) = -2*I; + assert (isequal (a, sym (b))); + assert (size (a), [3 3]); ***** test - f1 = expint(sym(1)); - f2 = expint(1); - assert( abs(double(f1) - f2) < 1e-15 ) + % 2D indexing with length in one dimension more than 2 + a = sym ([1 2; 3 4; 5 6]); + indices = [1 4; 2 5; 3 6]; + b = [10 11; 12 13; 14 15]; + a(indices) = b; + assert (isequal (a, sym (b))); ***** test - f1 = expint(sym(1i)); - f2 = expint(1i); - assert( abs(double(f1) - f2) < 1e-15 ) + A = sym ([0 0 0]); + indices = [false true false]; + A(indices) = 1; + assert (isequal (A, sym ([0 1 0]))); + A(indices) = []; + assert (isequal (A, sym ([0 0]))); + indices = [false false]; + A(indices) = []; + assert (isequal (A, sym ([0 0]))); +***** shared a, b + a = [1 2 3 5; 4 5 6 9; 7 5 3 2]; + b = sym (a); ***** test - D = [1 2; 3 4]; - A = sym(D); - f1 = expint(A); - f2 = expint(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + A = a; B = b; + A(true) = 0; + B(true) = 0; + assert (isequal (A, B)) ***** test - syms x - A = expint(x); - B = expint(1, x); + A = a; B = b; + A(false) = 0; + B(false) = 0; assert (isequal (A, B)) ***** test - syms x - A = exp(-x)/x; - B = expint(0, x); + c = [false true]; + A = a; B = b; + A(c) = 0; B(c) = 0; + assert (isequal (A, B)) + d = c | true; + A(d) = 1; B(d) = 1; + assert (isequal (A, B)) + d = c & false; + A(d) = 2; B(d) = 2; assert (isequal (A, B)) ***** test - % round trip - syms x - A = expint (3); - f = expint (x); - h = function_handle (f); - B = h (3); - assert (A, B, -eps) -***** error - % round trip - syms n x - f = expint (n, x); - h = function_handle (f); -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/cbrt.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cbrt.m -***** error cbrt (sym(1), 2) -***** assert (isequaln (cbrt (sym(nan)), sym(nan))) -***** shared x, d - d = 2; - x = sym('2'); + c = [false true false true; true false true false; false true false true]; + A = a; B = b; + A(c) = 0; B(c) = 0; + assert (isequal (A, B)) + d = c | true; + A(d) = 1; B(d) = 1; + assert (isequal (A, B)) + d = c & false; + A(d) = 2; B(d) = 2; + assert (isequal (A, B)) ***** test - f1 = cbrt(x); - f2 = 1.2599210498948731647; - assert( abs(double(f1) - f2) < 1e-15 ) + c = [false true false true false]; + A = a; B = b; + A(c) = 0; B(c) = 0; + assert (isequal (A, B)) + d = c | true; + A(d) = 1; B(d) = 1; + assert (isequal (A, B)) + d = c & false; + A(d) = 2; B(d) = 2; + assert (isequal (A, B)) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = cbrt(A); - f2 = 1.2599210498948731647; - f2 = [f2 f2; f2 f2]; - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + c = [false; true; false; true; false]; + A = a; B = b; + A(c) = 0; B(c) = 0; + assert (isequal (A, B)) + d = c | true; + A(d) = 1; B(d) = 1; + assert (isequal (A, B)) + d = c & false; + A(d) = 2; B(d) = 2; + assert (isequal (A, B)) ***** test - % round trip - y = sym('y'); - if (exist ('OCTAVE_VERSION', 'builtin')) - A = cbrt (d); - else - % Issue #742 - A = d^(1/3); - end - f = cbrt (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ellipticE.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticE.m -***** error ellipticE (sym(1), 2, 3) -***** assert (double (ellipticE (sym (-105)/10)), 3.70961391, 10e-9) -***** assert (double (ellipticE (sym (-pi)/4)), 1.844349247, 10e-10) -***** assert (double (ellipticE (sym (0))), 1.570796327, 10e-10) -***** assert (double (ellipticE (sym (1))), 1, 10e-1) + c = [false true; false true; true false]; + A = a; B = b; + A(c) = 0; B(c) = 0; + assert (isequal (A, B)) + d = c | true; + A(d) = 1; B(d) = 1; + assert (isequal (A, B)) + d = c & false; + A(d) = 2; B(d) = 2; + assert (isequal (A, B)) +76 tests, 76 passed, 0 known failure, 0 skipped +[inst/@sym/flipud.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/flipud.m ***** test - % compare to Maple - us = vpa (ellipticE (sym(7)/6, sym(13)/7), 40); - % > evalf(EllipticE(sin(7/6), sqrt(13/7)), 40); - maple = vpa ('0.6263078268598504591831743625971763209496', 40) + ... - vpa ('0.1775496232203171126975790989055865596501j', 40); - assert (abs (double (maple - us)), 0, 2e-39) + % simple + syms x + A = [x 2; sym(pi) x]; + B = [sym(pi) x; x 2]; + assert (isequal (flipud(A), B)) ***** test - % compare to Maple - us = vpa (ellipticE (sym(8)/7), 40); - % > evalf(EllipticE(sqrt(8/7)), 40); - maple = vpa ('0.8717182992576322508542205614105802333270', 40) + ... - vpa ('0.1066754320328976949531350910798010526685j', 40); - assert (abs (double (maple - us)), 0, 2e-39) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/diag.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/diag.m + % simple, odd # rows + syms x + A = [x 2; sym(pi) x; [1 2]]; + B = [[1 2]; sym(pi) x; x 2]; + assert (isequal (flipud(A), B)) ***** test % scalar syms x - assert (isequal (diag(x), x)) + assert (isequal (flipud(x), x)) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/ezmesh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ezmesh.m +***** error + syms u v t + ezmesh(u*v, 2*u*v, 3*v*t) +***** error + syms u v t + ezmesh(u*v, 2*u*v, u*v*t) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/trace.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/trace.m ***** test - % row,col vec input + % scalar syms x - r = [1 x 2]; - c = [sym(1); x]; - assert (isequal (diag(diag(c)), c)) - assert (isequal (diag(c), [sym(1) 0; 0 x])) - assert (isequal (diag(diag(r)), r.')) - assert (isequal (diag(r), [sym(1) 0 0; 0 x 0; sym(0) 0 2])) + assert (isequal (trace(x), x)) ***** test - % create matrix, kth diag syms x - r = [1 x]; - z = sym(0); - assert (isequal (diag (x, 0), x)) - assert (isequal (diag (x, 1), [z x; z z])) - assert (isequal (diag (x, -1), [z z; x z])) - assert (isequal (diag (x, 2), [z z x; z z z; z z z])) - assert (isequal (diag (r, 1), [z 1 z; z z x; z z z])) -***** test - % extract kth diag - A = sym([1 2 3; 4 5 6]); - assert (isequal (diag(A), sym([1; 5]))) - assert (isequal (diag(A, 0), sym([1; 5]))) - assert (isequal (diag(A, 1), sym([2; 6]))) - assert (isequal (diag(A, 2), sym(3))) - assert (isequal (diag(A, -1), sym(4))) - assert (isempty (diag(A, -2))) - assert (isempty (diag(A, 3))) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/cumprod.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cumprod.m -***** shared x, y - x = sym ('x'); - y = sym ('y'); -***** error cumprod (x, 1, 2) -***** assert (isequal (cumprod ([-x; -2*x; -3*x]), [-x; 2*x^2; -6*x^3])) -***** assert (isequal (expand (cumprod ([x + i, x - i])), [x + i, x^2 + 1])) -***** assert (isequal (cumprod ([1, x; y, 2], 1), [1, x; y, 2*x] )) -***** assert (isequal (cumprod ([1, x; y, 2], 2), [1, x; y, 2*y] )) -***** test cumprod ([x, x], [2, 1]); # ensure behaves like builtin cumprod -***** test cumprod ([x, x], [1, -2]); # ensure behaves like builtin cumprod -***** error cumprod (x, []) -***** error cumprod (x, {1}) -***** error cumprod (x, struct('a', 1)) -***** error cumprod (x, x) -***** error cumprod (x, 0) -***** error cumprod (x, -1) -13 tests, 13 passed, 0 known failure, 0 skipped -[inst/@sym/coth.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/coth.m -***** error coth (sym(1), 2) -***** assert (isequaln (coth (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); -***** test - f1 = coth(x); - f2 = coth(d); - assert( abs(double(f1) - f2) < 1e-15 ) -***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = coth(A); - f2 = coth(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + A = [x 3; 2*x 5]; + assert (isequal (trace(A), x + 5)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/formula.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/formula.m ***** test - % round trip - y = sym('y'); - A = coth (d); - f = coth (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/pochhammer.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/pochhammer.m -***** error pochhammer (sym(1)) -***** error pochhammer (sym(1), 2, 3) -***** assert (isequal (pochhammer (sym(3), 4), sym(360))) -***** assert (isequal (pochhammer (sym([2 3]), 3), sym([24 60]))) + syms x + assert (isequal (formula(x), x)) + assert (isequal (formula(2*x), 2*x)) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/partfrac.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/partfrac.m ***** test - % round trip - syms n z - f = pochhammer (z, n); - h = function_handle (f, 'vars', [z n]); - A = h (1.1, 2.2); - B = pochhammer (1.1, 2.2); - assert (A, B) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ezcontour.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ezcontour.m -***** error + % basic syms x y z - ezcontour (x*y*z) + assert(logical( partfrac(y/(x + 2)/(x + 1),x) == -y/(x + 2) + y/(x + 1) )) + assert(logical( factor(partfrac(x^2/(x^2 - y^2),y)) == factor(x/(2*(x + y)) + x/(2*(x - y)) ))) + assert(logical( factor(partfrac(x^2/(x^2 - y^2),x)) == factor(-y/(2*(x + y)) + y/(2*(x - y)) + 1 ))) 1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/fix.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/fix.m -***** test - d = 3/2; - x = sym('3/2'); - f1 = fix(x); - f2 = fix(d); - assert (isequal (f1, f2)) -***** test - D = [1.1 4.6; -3.4 -8.9]; - A = [sym(11)/10 sym(46)/10; sym(-34)/10 sym(-89)/10]; - f1 = fix(A); - f2 = fix(D); - assert( isequal (f1, f2)) -***** test - d = sym(-11)/10; - c = -1; - assert (isequal (fix (d), c)) -***** test - d = sym(-19)/10; - c = -1; - assert (isequal (fix (d), c)) -4 tests, 4 passed, 0 known failure, 0 skipped [inst/@sym/sym.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/sym.m ***** test @@ -5014,231 +4991,122 @@ s2 = 'FallingFactorial(Symbol(''x''), Symbol(''y''))'; assert (strcmp (s1, s2)) 82 tests, 82 passed, 0 known failure, 0 skipped -[inst/@sym/mod.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/mod.m -***** error mod (sym(1), 2, 3 ,4) -***** assert (isequal (mod (sym(5), 4), sym(1))) -***** assert (isequal (mod ([sym(5) 8], 4), [1 0] )) -***** assert (isequal (mod (sym(5), [2 3]), [1 2] )) -***** assert (isequal (mod ([sym(5) sym(6)], [2 3]), [1 0] )) -***** test - syms x - assert (isequal ( mod (5*x, 3), 2*x )) -***** test - syms x - a = [7*x^2 + 3*x + 3 3*x; 13*x^4 6*x]; - assert (isequal ( mod (a,3), [x^2 0; x^4 0] )) -***** test - % vector of polys with mix of vars: symvar on each - syms x y - a = [6*x 7*y]; - b = mod(a, 4); - c = [2*x 3*y]; - assert (isequal (b, c)) -***** test - % coeff has variable - syms x - n = sym('n', 'integer'); - p = (3*n + 2)*x; - q = mod(p, 3); - assert (isequal (q, 2*x)) -***** test - % coeff has variable - syms x a - p = a*x; - q = mod(p, 3); - q = children(q); - q = q(2); % order might be fragile! - w = subs(q, a, 5); - assert (isequal (w, 2)) -***** test - % different modulo - syms x y - q = mod([5*x + 10 5*y + 10], [2 3]); - assert (isequal (q, [x 2*y + 1])) -11 tests, 11 passed, 0 known failure, 0 skipped -[inst/@sym/floor.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/floor.m -***** error floor (sym(1), 2) -***** assert (isequaln (floor (sym(nan)), sym(nan))) +[inst/@sym/asin.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/asin.m +***** error asin (sym(1), 2) +***** assert (isequaln (asin (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = floor(x); - f2 = floor(d); + f1 = asin(x); + f2 = asin(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = floor(A); - f2 = floor(D); + f1 = asin(A); + f2 = asin(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = floor (d); - f = floor (y); + A = asin (d); + f = asin (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/log.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/log.m -***** error log (sym(1), 2) -***** assert (isequaln (log (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); -***** test - f1 = log(x); - f2 = log(d); - assert( abs(double(f1) - f2) < 1e-15 ) +[inst/@sym/symprod.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/symprod.m +***** error symprod (sym(1), 2, 3, 4, 5) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = log(A); - f2 = log(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % simple + syms n + assert (isequal (symprod(n, n, 1, 10), factorial(sym(10)))) + assert (isequal (symprod(n, n, sym(1), sym(10)), factorial(10))) ***** test - % round trip - y = sym('y'); - A = log (d); - f = log (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/mldivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/mldivide.m + % one input + syms n + f = symprod (n); + g = factorial (n); + assert (isequal (f, g)) + f = symprod (2*n); + g = 2^n * factorial (n); + assert (isequal (f, g)) ***** test - % scalar + % constant input + f = symprod (sym(2)); syms x - assert (isa( x\x, 'sym')) - assert (isequal( x\x, sym(1))) - assert (isa( 2\x, 'sym')) - assert (isa( x\2, 'sym')) -***** test - % scalar \ matrix: easy, no system - D = 2*[0 1; 2 3]; - A = sym(D); - assert (isequal ( 2 \ A , D/2 )) - assert (isequal ( sym(2) \ A , D/2 )) -***** test - % singular matrix - A = sym([1 2; 2 4]); - b = sym([5; 10]); - x = A \ b; - syms c1 - y = [-2*c1 + 5; c1]; - assert (isequal (x, y)) -***** test - % singular matrix, mult RHS - A = sym([1 2; 2 4]); - B = sym([[5; 10] [0; 2] [0; 0]]); - x = A \ B; - syms c1 c5 - y = [-2*c1 + 5 nan -2*c5; c1 nan c5]; - assert (isequaln (x, y)) -***** warning - % vpa, nearly singular matrix - A = sym([1 2; 2 4]); - A(1,1) = vpa('1.001'); - b = sym([1; 2]); - x = A \ b; - y = [sym(0); vpa('0.5')]; - assert (isequal (x, y)) -***** warning - % vpa, singular rhs - A = sym([1 2; 2 4]); - b = [vpa('1.01'); vpa('2')]; - x = A \ b; - assert (all(isnan(x))) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/gamma.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/gamma.m -***** error gamma (sym(1), 2) -***** assert (isequaln (gamma (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); -***** test - f1 = gamma(x); - f2 = gamma(d); - assert( abs(double(f1) - f2) < 1e-15 ) -***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = gamma(A); - f2 = gamma(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) -***** test - % round trip - y = sym('y'); - A = gamma (d); - f = gamma (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/sind.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sind.m -***** error sind (sym(1), 2) -***** assert (isequaln (sind (sym(nan)), sym(nan))) + g = 2^x; + assert (isequal (f, g)) ***** test - f1 = sind (sym(1)); - f2 = sind (1); - assert (double (f1), f2, -eps) + % two inputs + syms n + f = symprod (2*n, n); + g = 2^n * factorial (n); + assert (isequal (f, g)) ***** test - D = [10 30; 110 -45]; - A = sym(D); - f1 = sind (A); - f2 = sind (D); - assert (double (f1), f2, -eps) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/horner.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/horner.m -***** error horner (sym(1), 2, 3) -***** assert (isAlways (horner(sym(1)) == 1)) + % two inputs, second is range + syms n + f = symprod (n, [1 6]); + g = 720; + assert (isequal (f, g)) + f = symprod (n, [sym(1) 6]); + g = 720; + assert (isequal (f, g)) + f = symprod (2*n, [1 6]); + g = sym(2)^6*720; + assert (isequal (f, g)) ***** test - syms x - assert (isAlways (horner(x) == x)) + % three inputs, last is range + syms n + f = symprod (2*n, n, [1 4]); + g = sym(384); + assert (isequal (f, g)) + f = symprod (2*n, n, [sym(1) 4]); + g = sym(384); + assert (isequal (f, g)) + f = symprod (2, n, [sym(1) 4]); + g = sym(16); + assert (isequal (f, g)) ***** test - syms x a - p = a^2 + a*x + 2*a + 2*x; - assert (isequal (horner (p, a), a*(a+x+2) + 2*x)) - q = a^2 + 2*a + x*(a + 2); - assert (isequal (horner (p, x), q)) - assert (isequal (horner (p), q)) + % three inputs, no range + syms n + f = symprod (2*n, 1, 4); + g = sym(384); + assert (isequal (f, g)) + f = symprod (5, sym(1), 3); + g = sym(125); + assert (isequal (f, g)) ***** test - syms x - p = poly2sym ([2 4 6 8], x); - q = horner (p); - assert (isAlways (p == q)) - assert (isAlways (horner(2*x^3 + 4*x^2 + 6*x + 8) == q)) + % infinite product + syms a n oo + zoo = sym('zoo'); + assert (isequal (symprod(a, n, 1, oo), a^oo)) + assert (isequal (symprod(a, n, 1, inf), a^oo)) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/ge.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ge.m ***** test - % non-sym input - syms x - assert (isequal (horner(6, x), sym(6))) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/minus.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/minus.m + % simple + x = sym(1); y = sym(1); e = x >= y; + assert (logical (e)) + x = sym(1); y = sym(2); e = x >= y; + assert (~logical(e)) ***** test - % scalar + % array -- array syms x - assert (isa (x-1, 'sym')) - assert (isa (x-x, 'sym')) - assert (isequal (x-x, sym(0))) -***** test - % matrices - D = [0 1; 2 3]; - A = sym(D); - DZ = D - D; - assert (isequal ( A - D , DZ )) - assert (isequal ( A - A , DZ )) - assert (isequal ( D - A , DZ )) - assert (isequal ( A - 2 , D - 2 )) - assert (isequal ( 4 - A , 4 - D )) + a = sym([1 3 3 2*x]); + b = sym([2 x 3 10]); + e = a >= b; + assert (isa (e, 'sym')) + assert (~logical (e(1))) + assert (isa (e(2), 'sym')) + assert (isequal (e(2), 3 >= x)) + assert (logical (e(3))) + assert (isa (e(4), 'sym')) + assert (isequal (e(4), 2*x >= 10)) 2 tests, 2 passed, 0 known failure, 0 skipped [inst/@sym/not.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/not.m @@ -5280,330 +5148,530 @@ assert (strcmp (strtrim (s), '~x') || strcmpi (strtrim (s), 'Not(x)')) ***** error not (sym(1), 2) 8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/heaviside.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/heaviside.m -***** error heaviside (sym(1), 2, 3) -***** assert (isequal (heaviside (sym(1)), sym(1))) -***** assert (isequal (heaviside (-sym(1)), sym(0))) -***** assert (double (heaviside (1)), heaviside (1)) +[inst/@sym/laguerreL.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/laguerreL.m +***** shared x + syms x +***** assert (isequal (laguerreL(0, x), sym(1))) +***** assert (isequal (laguerreL(1, x), 1-x)) +***** assert (isequal (laguerreL(2, x), x^2/2 - 2*x + 1)) +***** error laguerreL(x) +***** error laguerreL(1, 2, x, 3) +***** shared ***** test - D = [1 -1; -10 20]; - A = sym(D); - assert (double (heaviside (A)), heaviside (D)) + if (pycall_sympy__ ('return Version(spver) > Version("1.4")')) + syms x + assert (isequal (laguerreL (-3, x), exp(x)*(x^2/2 + 2*x + 1))) + end ***** test - H0 = sym([1 -2 0; 3 0 pi]); - A = heaviside (sym(0), H0); - assert (isequal (A, H0)) + syms x n + L = laguerreL([2 n], x); + expected = [laguerreL(2, x) laguerreL(n, x)]; + assert (isequal (L, expected)) ***** test - A = heaviside ([-1 0 1], sym(1)/2); - assert (isequal (A, [0 sym(1)/2 1])) + syms x y + L = laguerreL([1; 2], [x; y]); + expected = [laguerreL(1, x); laguerreL(2, y)]; + assert (isequal (L, expected)) ***** test - A = heaviside ([-1 0 1], sym(1)/2); - assert (isequal (A, [0 sym(1)/2 1])) -***** assert (isequaln (heaviside (sym(nan)), sym(nan))) + syms x n + assert (isequal (laguerreL(n, 0, x), laguerreL(n, x))) +***** shared x, y, n + syms x y n +***** assert (isequal (laguerreL([1 n], 0, x), laguerreL([1 n], x))) ***** test - assert (isequaln (heaviside (sym(nan), sym(nan)), sym(nan))) - assert (isequaln (heaviside (0, sym(nan)), sym(nan))) - assert (isequaln (heaviside (2, sym(nan)), sym(1))) - assert (isequaln (heaviside (-2, sym(nan)), sym(0))) + L = laguerreL([1; n], [pi; 0], [x; y]); + expected = [laguerreL(1, pi, x); laguerreL(n, 0, y)]; + assert (isequal (L, expected)) +***** test + L = laguerreL([1 n], [pi 0], x); + expected = [laguerreL(1, pi, x) laguerreL(n, 0, x)]; + assert (isequal (L, expected)) +***** test + L = laguerreL([1 n], pi, [x y]); + expected = [laguerreL(1, pi, x) laguerreL(n, pi, y)]; + assert (isequal (L, expected)) +***** test + L = laguerreL(1, [pi 0], [x y]); + expected = [laguerreL(1, pi, x) laguerreL(1, 0, y)]; + assert (isequal (L, expected)) +***** test + L = laguerreL([1 n], pi, x); + expected = [laguerreL(1, pi, x) laguerreL(n, pi, x)]; + assert (isequal (L, expected)) +***** test + L = laguerreL(1, [pi 0], x); + expected = [laguerreL(1, pi, x) laguerreL(1, 0, x)]; + assert (isequal (L, expected)) +***** test + L = laguerreL(1, pi, [x y]); + expected = [laguerreL(1, pi, x) laguerreL(1, pi, y)]; + assert (isequal (L, expected)) ***** test % round trip - syms x - A = heaviside (1); - f = heaviside (x); + f = laguerreL (n, x); h = function_handle (f); - B = h (1); - assert (A, B, -eps) -***** test + A = h (1, 3.2); + B = laguerreL (1, 3.2); + assert (A, B) + A = h ([1 2], [3.3 4.4]); + B = laguerreL ([1 2], [3.3 4.4]); + assert (A, B) +***** error % round trip - syms x h0 - f = heaviside (x, h0); - h = function_handle (f, 'vars', {x h0}); - A = heaviside (1, 1/2); - B = h (1, 1/2); - assert (A, B, -eps) - A = heaviside (0, 1/2); - B = h (0, 1/2); - assert (A, B, -eps) -12 tests, 12 passed, 0 known failure, 0 skipped -[inst/@sym/children.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/children.m + f = laguerreL (n, y, x); + h = function_handle (f); +19 tests, 19 passed, 0 known failure, 0 skipped +[inst/@sym/expm.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/expm.m ***** test - % basics, sum - syms x y - f = 2*x + x*x + sin(y); - assert (isempty (setxor (children(f), [2*x x*x sin(y)]))) + % scalar + syms x + assert (isequal (expm(x), exp(x))) ***** test - % basics, product - syms x y - f = 2*x*sin(y); - assert (isempty (setxor (children(f), [2 x sin(y)]))) + % diagonal + A = [sym(1) 0; 0 sym(3)]; + B = [exp(sym(1)) 0; 0 exp(sym(3))]; + assert (isequal (expm(A), B)) ***** test - % basics, product and powers - syms x y - f = 2*x^2*y^3; - assert (isempty (setxor (children(f), [2 x^2 y^3]))) + % diagonal w/ x + syms x positive + A = [sym(1) 0; 0 x+2]; + B = [exp(sym(1)) 0; 0 exp(x+2)]; + assert (isequal (expm(A), B)) ***** test - % eqn, ineq + % non-diagonal + syms x positive + A = [sym(1) 2; 0 x+2]; + B = expm(A); + C = double(subs(B, x, 4)); + D = expm(double(subs(A, x, 4))); + assert (max (max (abs (C - D))) <= 1e-11) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/has.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/has.m +***** shared A, x, y syms x y - lhs = 2*x^2; rhs = y^3 + 7; - assert (isequal (children(lhs == rhs), [lhs rhs])) - assert (isequal (children(lhs < rhs), [lhs rhs])) - assert (isequal (children(lhs >= rhs), [lhs rhs])) + A = [sym(pi) 2*sym(pi); x*y x+y]; +***** assert (isequal (has(A, x), [false false; true true])); +***** assert (isequal (has(A, x+y), [false false; false true])); +***** assert (isequal (has(A, 2), [false true; false false])); +***** assert (isequal (has(A, sym(pi)), [true true; false false])); +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/dilog.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/dilog.m +***** assert (isequal (dilog (sym(1)), sym(0))) +***** assert (isequal (dilog (sym(0)), sym(pi)^2/6)) +***** assert (isequal (dilog (sym(2)), -sym(pi)^2/12)) +***** assert (double(dilog(sym(-1))), pi^2/4 - pi*1i*log(2), eps) ***** test - % matrix - syms x y - f = [4 + y 1 + x; 2 + x 3 + x]; - c = children(f); - ec = {[4 y], [1 x]; [2 x], [3 x]}; - assert (isequal (size(c), size(ec))) - for i=1:length(c) - assert (isempty (setxor (c{i}, ec{i}))) - end + % round-trip + syms x + f = dilog (x); + h = function_handle (f); + A = h (1.1); + B = dilog (1.1); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/laplace.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/laplace.m ***** test - % matrix, sum/prod - syms x y - f = [x + y; x*sin(y); sin(x)]; - ec = {[x y]; [x sin(y)]; [x]}; - c = children(f); - assert (isequal (size(c), size(ec))) - for i=1:length(c) - assert (isempty (setxor (c{i}, ec{i}))) - end + % basic + syms t s u w + assert(logical( laplace(cos(3*t)) == s/(s^2+9) )) + assert(logical( laplace(t^3) == 6/s^4 )) ***** test - % scalar symbol - syms x - assert (isequal (children(x), x)) + % matlab SMT compat + syms t s u w z + assert(logical( laplace(exp(2*t)) == 1/(s-2) )) + assert(logical( laplace(exp(2*s)) == 1/(z-2) )) + assert(logical( laplace(exp(2*u),w) == 1/(w-2) )) + assert(logical( laplace(exp(2*u),u,w) == 1/(w-2) )) ***** test - % scalar number - x = sym(6); - assert (isequal (children(x), x)) + syms x s t z + % matlab SMT prefers t over x + assert (isequal (laplace (x*exp (t), z), x/(z - 1))) + % as usual, you can just specify: + assert (isequal (laplace(x*exp(t), t, z), x/(z - 1))) % SMT result + assert (isequal (laplace(x*exp(t), x, z), exp(t)/z^2)) ***** test - % symbolic size matrix - syms n m integer - A = sym('a', [n m]); - C = children (A); - assert (isequal (C(2), n)) - assert (isequal (C(3), m)) + syms x a s + % if no t, use symvar: take x before a + assert (isequal (laplace (a*exp (x)), a/(s - 1))) +***** error laplace (sym('t')*sym('t', 'real')) +***** test + % constant, issue #250 + syms s + f = laplace(2, s); + assert (isequal (f, 2/s)) +***** test + % Dirac delta and Heaviside tests + syms t s + assert (isequal (laplace(dirac(t-3)), exp(-3*s))) + assert (isequal (laplace((t-3)*heaviside(t-3)), exp(-3*s)/s^2)) ***** xtest - % symbolic size matrix, fails on newer SymPy Issue #1089 - syms n m integer - A = sym('a', [n m]); - assert (isequal (children (A), [sym('a') n m])) + % Differential operator to algebraic + % SymPy cannot evaluate? (Issue #170) + syms s f(t) + assert(logical( laplace(diff(f(t),t),t,s) == s*laplace(f(t),t,s)-f(0) )) !!!!! known failure -assert (isequal (children (A), [sym('a'), n, m])) failed -10 tests, 9 passed, 1 known failure, 0 skipped -[inst/@sym/acosh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/acosh.m -***** error acosh (sym(1), 2) -***** assert (isequaln (acosh (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); +Python exception: TypeError: 'Add' object is not subscriptable + occurred at line 6 of the Python code block: + return F[0], +8 tests, 7 passed, 1 known failure, 0 skipped +[inst/@sym/subsref.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/subsref.m +***** shared a,b + b = [1:4]; + a = sym(b); +***** assert(isequal( a(1), b(1) )) +***** assert(isequal( a(2), b(2) )) +***** assert(isequal( a(4), b(4) )) +***** assert(isempty( a([]) )) +***** shared a,b + b = [1:4]; b = [b; 3*b; 5*b]; + a = sym(b); +***** assert(isequal( a(1), b(1) )) +***** assert(isequal( a(2), b(2) )) +***** assert(isequal( a(4), b(4) )) +***** assert(isequal( a(:,:), a )) +***** assert(isequal( a(1:2,1:3), a(1:2,1:3) )) +***** assert(isequal( a(1:2:3,[1 2 4]), b(1:2:3,[1 2 4]) )) +***** assert(isequal( a(1:2:3,[4 2 3 1]), b(1:2:3,[4 2 3 1]) )) +***** assert(isequal( a(1:2:3,[4 1 1 1]), b(1:2:3,[4 1 1 1]) )) +***** assert(isequal( a([],:), b([],:) )) +***** assert(isequal( size(a([],:)), [0 4] )) +***** assert(isequal( a(1:2,[]), b(1:2,[]) )) +***** assert(isequal( size(a(1:2,[])), [2 0] )) +***** assert(isempty( a(1:2,[]) )) +***** assert(isempty( a([],[]) )) +***** assert(isequal( a([],[]), sym([]) )) +***** assert(~isequal( a(1:2,[]), sym([]) )) +***** shared e + e = sym([1 3 5; 2 4 6]); +***** assert(isequal( e(:), sym((1:6)') )) +***** assert(isequal( e([1 2 3]), sym([1 2 3]) )) +***** assert(isequal( e([1; 3; 4]), sym([1; 3; 4]) )) +***** assert(isempty( e([]) )) +***** assert(isempty( e('') )) +***** assert(isequal( e([]), sym([]) )) +***** shared a,b + b = 1:5; a = sym(b); +***** assert(isequal( a([1 2 5]), b([1 2 5]) )) +***** assert(isequal( a([1; 2; 5]), b([1; 2; 5]) )) +***** shared x + syms x ***** test - f1 = acosh(x); - f2 = acosh(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % logical with empty result + assert(isempty( x(false) )) + a = [x x]; + assert(isempty( a([false false]) )) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = acosh(A); - f2 = acosh(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % issue 18, scalar access + assert(isequal( x(1), x )) + assert(isequal( x(true), x )) +***** shared ***** test - % round trip - y = sym('y'); - A = acosh (d); - f = acosh (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/besselh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselh.m + % older access tests + syms x + f = [x 2; 3 4*x]; + % element access + assert (logical( f(1,1) == x )) + assert (logical( f(1,2) == 2 )) + % linear access of 2d array + assert (logical( f(1) == x )) + assert (logical( f(2) == 3 )) % column based + assert (logical( f(3) == 2 )) +***** shared a,b + % effectively a random matrix + a = reshape( round(50*(sin(1:20)+1)), 5,4); + b = sym(a); ***** test - % default to k=1 - syms z a - A = besselh(a, z); - B = besselh(a, 1, z); - assert (isequal (A, B)) -***** error besselh(sym('z')) -***** error besselh(2, 0, sym('z')) -***** error besselh(2, 3, sym('z')) + % older array refs test + assert (logical(b(1,1) == a(1,1))) + assert (logical(b(3,1) == a(3,1))) + assert (logical(b(1,3) == a(1,3))) + assert (logical(b(4,4) == a(4,4))) ***** test - % doubles, relative error - X = [1 2 pi; 4i 5 6+6i]; - Xs = sym(X); - Alpha = [pi 3 1; 3 2 0]; - Alphas = sym(Alpha); - for k = 1:2 - A = double(besselh(Alphas, k, Xs)); - B = besselh(Alpha, k, X); - assert (all (all (abs(A - B) < 10*eps*abs(A)))) - end + % older array refs test: linear indices + assert (logical(b(1) == a(1))) + assert (logical(b(3) == a(3))) + assert (logical(b(13) == a(13))) ***** test - % round-trip + % older array refs test: end + assert (all(all(logical( b(end,1) == a(end,1) )))) + assert (all(all(logical( b(2,end) == a(2,end) )))) + assert (all(all(logical( b(end,end) == a(end,end) )))) + assert (all(all(logical( b(end-1,1) == a(end-1,1) )))) + assert (all(all(logical( b(2,end-1) == a(2,end-1) )))) + assert (all(all(logical( b(end-1,end-1) == a(end-1,end-1) )))) +***** shared +***** test + % older slicing tests syms x - for k = 1:2 - A = besselh(4, k, 10); - q = besselh(4, k, x); - h = function_handle(q); - B = h(10); - assert (abs(A - B) <= eps*abs(A)) - end -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/isinf.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isinf.m -***** shared x,zoo,oo,snan - oo = sym(inf); - zoo = sym('zoo'); - x = sym('x'); - snan = sym(nan); + a = [1 2 3 4 5 6]; a = [a; 3*a; 5*a; 2*a; 4*a]; + b = sym(a); + assert (isequal( b(:,1), a(:,1) )) + assert (isequal( b(:,2), a(:,2) )) + assert (isequal( b(1,:), a(1,:) )) + assert (isequal( b(2,:), a(2,:) )) + assert (isequal( b(:,:), a(:,:) )) + assert (isequal( b(1:3,2), a(1:3,2) )) + assert (isequal( b(1:4,:), a(1:4,:) )) + assert (isequal( b(1:2:5,:), a(1:2:5,:) )) + assert (isequal( b(1:2:4,:), a(1:2:4,:) )) + assert (isequal( b(2:2:4,3), a(2:2:4,3) )) + assert (isequal( b(2:2:4,3), a(2:2:4,3) )) ***** test - % various ops that give inf and nan - assert (isinf(oo)) - assert (isinf(zoo)) - assert (isinf(oo+oo)) - assert (~isinf(oo+zoo)) - assert (~isinf(0*oo)) - assert (~isinf(0*zoo)) - assert (~isinf(snan)) - assert (~isinf(oo-oo)) - assert (~isinf(oo-zoo)) + % 2D arrays + b = [1:4]; b = [b; 3*b; 5*b]; + a = sym(b); + I = rand(size(b)) > 0.5; + assert (isequal (a(I), b(I))) + I = I(:); + assert (isequal (a(I), b(I))) + I = I'; + assert (isequal (a(I), b(I))) + I = logical(zeros(size(b))); + assert (isequal (a(I), b(I))) ***** test - % arrays - assert (isequal( isinf([oo zoo]), [1 1] )) - assert (isequal( isinf([oo 1]), [1 0] )) - assert (isequal( isinf([10 zoo]), [0 1] )) - assert (isequal( isinf([x oo x]), [0 1 0] )) + % 1D arrays, does right with despite warning + r = [1:6]; + ar = sym(r); + c = r'; + ac = sym(c); + Ir = rand(size(r)) > 0.5; + Ic = rand(size(c)) > 0.5; + assert (isequal (ar(Ir), r(Ir))) + assert (isequal (ac(Ic), c(Ic))) + assert (isequal (ar(Ic), r(Ic))) + assert (isequal (ac(Ir), c(Ir))) ***** test - % Must not contain string 'symbol'; these all should make an - % actual infinity. Actually a ctor test, not isinf. - % IIRC, SMT in Matlab 2013b fails. - oo = sym(inf); - assert (isempty (strfind (sympy (oo), 'Symbol'))) - oo = sym(-inf); - assert (isempty (strfind (sympy (oo), 'Symbol'))) - oo = sym('inf'); - assert (isempty (strfind (sympy (oo), 'Symbol'))) - oo = sym('-inf'); - assert (isempty (strfind (sympy (oo), 'Symbol'))) - oo = sym('Inf'); - assert (isempty (strfind (sympy (oo), 'Symbol'))) + % rccross tests + B = [1 2 3 4; 5 6 7 9; 10 11 12 13]; + A = sym(B); + assert (isequal (A([1 3],[2 3]), B([1 3], [2 3]) )) + assert (isequal (A(1,[2 3]), B(1,[2 3]) )) + assert (isequal (A([1 2],4), B([1 2],4) )) + assert (isequal (A([2 1],[4 2]), B([2 1],[4 2]) )) + assert (isequal (A([],[]), B([],[]) )) +***** error + % issue #445 + A = sym([10 11]); + A(1.1) +***** error + % issue #445 + A = sym([10 11]); + A(sym(4)/3) +***** error + % issue #445 + A = sym([1 2; 3 4]); + A(1.1, 1) +***** error + % issue #445 + A = sym([1 2; 3 4]); + A(1, sym(4)/3) +***** shared a, b + a = [1 2 3 5; 4 5 6 9; 7 5 3 2]; + b = sym (a); ***** test - % ops with infinity shouldn't collapse - syms x oo zoo - y = x + oo; - assert (~isempty (strfind (lower (sympy (y)), 'add') )) - y = x - oo; - assert (~isempty (strfind (lower (sympy (y)), 'add') )) - y = x - zoo; - assert (~isempty (strfind (lower (sympy (y)), 'add') )) - y = x*oo; - assert (~isempty (strfind (lower (sympy (y)), 'mul') )) + c = true; + assert (isequal (a(c), b(c))) + c = false; + assert (isequal (a(c), b(c))) ***** test - % ops with infinity are not necessarily infinite - syms x oo zoo - y = x + oo; - assert(~isinf(y)) % SMT 2014a says "true", I disagree - y = x - zoo; - assert(~isinf(y)) - y = x*oo; - assert(~isinf(y)) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/real.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/real.m -***** assert (isequal (real (sym (4) + 3i),4)) + c = [false true]; + assert (isequal (a(c), b(c))) + d = c | true; + assert (isequal (a(d), b(d))) + d = c & false; + assert (isequal (a(d), b(d))) ***** test - syms x y real - z = x + 1i*y; - assert (isequal (real (z),x)) + c = [false true false true; true false true false; false true false true]; + assert (isequal (a(c), b(c))) + d = c | true; + assert (isequal (a(d), b(d))) + d = c & false; + assert (isequal (a(d), b(d))) ***** test - syms x y real - Z = [4 x + 1i*y; x 4 + 3i]; - assert (isequal (real (Z),[4 x; x 4])) + c = [false true false true false]; + assert (isequal (a(c), b(c))) + d = c | true; + assert (isequal (a(d), b(d))) + d = c & false; + assert (isequal (a(d), b(d))) ***** test - syms x real - d = exp (x*i); - assert (isequal (real (d), cos (x))) + c = [false; true; false; true; false]; + assert (isequal (a(c), b(c))) + d = c | true; + assert (isequal (a(d), b(d))) + d = c & false; + assert (isequal (a(d), b(d))) ***** test - % round trip + c = [false true; false true; true false]; + assert (isequal (a(c), b(c))) + d = c | true; + assert (isequal (a(d), b(d))) + d = c & false; + assert (isequal (a(d), b(d))) +***** shared +***** test + % Orientation of empty results of logical indexing on row or column vectors + r = [1:6]; + c = r'; + ar = sym(r); + ac = sym(c); + assert (isequal (ar(false), r(false))) + assert (isequal (ac(false), c(false))) + assert (isequal (ar(false (1, 6)), r(false (1, 6)))) + assert (isequal (ac(false (1, 6)), c(false (1, 6)))) + assert (isequal (ar(false (6, 1)), r(false (6, 1)))) + assert (isequal (ac(false (6, 1)), c(false (6, 1)))) +49 tests, 49 passed, 0 known failure, 0 skipped +[inst/@sym/lhs.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/lhs.m +***** test + syms x y + f = x + 1 == 2*y; + assert (isequal (lhs(f), x + 1)) + assert (isequal (rhs(f), 2*y)) +***** test + syms x y + f = x + 1 < 2*y; + assert (isequal (lhs(f), x + 1)) + assert (isequal (rhs(f), 2*y)) +***** test + syms x y + f = x + 1 >= 2*y; + assert (isequal (lhs(f), x + 1)) + assert (isequal (rhs(f), 2*y)) +***** test + syms x y + A = [x == y 2*x < 2*y; 3*x > 3*y 4*x <= 4*y; 5*x >= 5*y x < 0]; + L = [x 2*x; 3*x 4*x; 5*x x]; + R = [y 2*y; 3*y 4*y; 5*y 0]; + assert (isequal( lhs(A), L)) + assert (isequal( rhs(A), R)) +***** error syms x - d = 3 - 5i; - f = real (x); - A = real (d); - h = function_handle (f); - B = h (d); - assert (A, B) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/det.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/det.m -***** assert (isequal (det(sym([])), 1)) + lhs(x) +***** error + lhs(sym(true)) +***** error + syms x + A = [1 + x == 2*x sym(6)]; + lhs(A) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/hypot.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/hypot.m +***** assert (isequal (hypot (sym(3), 4), sym(5))) ***** test - syms x y real - assert (isequal (det([x 5; 7 y]), x*y-35)) + % compare to @double (note Matlab hypot only takes 2 inputs) + A = hypot (hypot ([1 2 3], [4 5 6]), [7 8 9]); + B = double (hypot (sym([1 2 3]), [4 5 6], [7 8 9])); + assert (A, B, -eps) +***** test + % compare to @double, with complex + A = hypot ([1+2i 3+4i], [1 3+1i]); + B = double (hypot (sym([1+2i 3+4i]), [1 3+1i])); + assert (A, B, -eps) +***** test + % matrices + x = sym([1 -2; 0 3]); + y = sym([0 0; 8 4]); + A = hypot (x, y); + B = sym([1 2; 8 5]); + assert (isequal (A, B)) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/or.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/or.m +***** shared t, f + t = sym(true); + f = sym(false); +***** test + % simple + assert (isequal (t | f, t)) + assert (isequal (t | t, t)) + assert (isequal (f | f, f)) +***** test + % array + w = [t t f f]; + z = [t f t f]; + assert (isequal (w | z, [t t t f])) +***** test + % output is sym even for scalar t/f + assert (isa (t | f, 'sym')) ***** test + % eqns syms x - assert (isequal (det(x), x)) - assert (isequal (det(sym(-6)), sym(-6))) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/double.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/double.m + e = or(x == 4, x == 5); + assert (isequal (subs(e, x, [3 4 5 6]), [f t t f])) +***** error or (sym(1), 2, 3) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/logspace.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/logspace.m ***** test - % numeric scalar - a = double(sym(10)); - assert (a == 10) - assert (isa (a, 'double')) + % default argument for N + A = logspace(0, 2); + assert (length (A) == 50); ***** test - % numeric vectors - a = double(sym([10 12])); - assert (isequal (a, [10 12])) - assert (isa (a, 'double')) + % special case: pi as end pt + A = logspace(-sym(3), sym(pi), 3); + assert (isequal (A(end), sym(pi))) ***** test - % complex - a = 3 + 4i; - b = sym(a); - assert (isequal (double (b), a)) -***** xtest - % unexpected, precisely same floating point - a = 3 + 4i; - b = sym(a); - assert (isequal (double (b/pi), a/pi)) + A = logspace(-sym(4), 0, 3); + B = [sym(1)/10000 sym(1)/100 sym(1)]; + assert (isequal (A, B)) ***** test - % floating point - x = sqrt(sym(2)); - assert( abs(double(x) - sqrt(2)) < 2*eps) - x = sym(pi); - assert( abs(double(x) - pi) < 2*eps) + % vpa support, might need recent sympy for sympy issue #10063 + n = 32; + A = logspace(-vpa(1,n), 0, 3); + B = [10^(-vpa(1,n)) 10^(-vpa(sym(1)/2,n)) vpa(1,n)]; + assert (isequal (A, B)) + assert (max(abs(double(A) - logspace(-1, 0, 3))) < 1e-15) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/transpose.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/transpose.m ***** test - oo = sym(inf); - assert( double(oo) == inf ) - assert( double(-oo) == -inf ) - assert( isnan(double(0*oo)) ) + x = sym(1); + assert (isequal (x.', x)) +***** assert (isempty (sym([]).')) ***** test - zoo = sym('zoo'); - assert (double(zoo) == complex(inf, inf)) + syms x; + assert (isequal (x.', x)) ***** test - zoo = sym('zoo'); - assert (double(-zoo) == double(zoo) ) - assert( isnan(double(0*zoo)) ) + A = [1 2; 3 4]; + assert(isequal( sym(A).' , sym(A.') )) ***** test - % nan - snan = sym(nan); - assert( isnan(double(snan))) + A = [1 2] + 1i; + assert(isequal( sym(A).' , sym(A.') )) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/gamma.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/gamma.m +***** error gamma (sym(1), 2) +***** assert (isequaln (gamma (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - % don't want NaN+NaNi - snan = sym(nan); - assert (isreal (double (snan))) + f1 = gamma(x); + f2 = gamma(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % arrays - a = [1 2; 3 4]; - assert( isequal( double(sym(a)), a )) - assert( isequal( double(sym(a)), a )) - % should fail with error for non-double -***** error syms x; double(x) -***** error syms x; double([1 2 x]) -13 tests, 13 passed, 0 known failure, 0 skipped + D = [d d; d d]; + A = [x x; x x]; + f1 = gamma(A); + f2 = gamma(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = gamma (d); + f = gamma (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped [inst/@sym/hypergeom.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/hypergeom.m ***** assert (isequal (double (hypergeom ([1, 2], [2, 3], sym(0))), 1)) @@ -5622,254 +5690,241 @@ assert (isequal (hypergeom([1 2], 3, z), hypergeom([1 2], {sym(3)}, z))) assert (isequal (hypergeom(1, [2 3], z), hypergeom({sym(1)}, [2 3], z))) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/intersect.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/intersect.m +[inst/@sym/ellipticCK.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticCK.m +***** error ellipticCK (sym (1), 2) +***** assert (double (ellipticCK (sym (1)/2)), 1.8541, 10e-5) +***** assert (double (ellipticCK (sym (101)/10)), 0.812691836806976, -3*eps) +***** assert (isequal (ellipticCK (sym (1)), sym(pi)/2)) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/atan2.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/atan2.m +***** error atan2 (1) +***** error atan2 (1, 2, 3) +***** test + % some angles + e = sym(1); + a = atan2(0, e); + assert (isequal (a, sym(0))) + a = atan2(e, 0); + assert (isequal (a, sym(pi)/2)) +***** test + % symbols can give numerical answer + syms x positive + a = atan2(0, x); + assert (isequal (a, sym(0))) + a = atan2(x, 0); + assert (isequal (a, sym(pi)/2)) + a = atan2(-x, 0); + assert (isequal (a, -sym(pi)/2)) +***** test + % matrices + x = sym([1 -2; 0 0]); + y = sym([0 0; 8 -3]); + a = atan2(y, x); + sp = sym(pi); + aex = [0 sp; sp/2 -sp/2]; + assert (isequal (a, aex)) +***** test + % round trip + syms x y + xd = -2; yd = -3; + f = atan2 (x, y); + A = atan2 (xd, yd); + h = function_handle (f); + B = h (xd, yd); + assert (A, B, -eps) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/frac.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/frac.m +***** test + f1 = frac(sym(11)/10); + f2 = sym(1)/10; + assert (isequal (f1, f2)) +***** test + d = sym(-11)/10; + c = sym(9)/10; + assert (isequal (frac (d), c)) +***** test + d = sym(-19)/10; + c = sym(1)/10; + assert (isequal (frac (d), c)) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/erfcinv.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfcinv.m +***** error erfcinv (sym(1), 2) +***** assert (isequaln (erfcinv (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); +***** test + f1 = erfcinv(x); + f2 = erfcinv(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = erfcinv(A); + f2 = erfcinv(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = erfcinv (d); + f = erfcinv (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/setdiff.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/setdiff.m ***** test A = sym([1 2 3]); B = sym([1 2 4]); - C = intersect(A, B); - D = sym([1 2]); + C = setdiff(A, B); + D = sym([3]); assert (isequal (C, D)) ***** test % one nonsym A = sym([1 2 3]); B = [1 2 4]; - C = intersect(A, B); - D = sym([1 2]); + C = setdiff(A, B); + D = sym([3]); assert (isequal (C, D)) ***** test % empty A = sym([1 2 3]); - C = intersect(A, A); - assert (isequal (C, A)) + C = setdiff(A, A); + assert (isempty (C)) ***** test % empty input A = sym([1 2]); - C = intersect(A, []); - assert (isequal (C, sym([]))) + C = setdiff(A, []); + assert (isequal (C, A) || isequal (C, sym([2 1]))) ***** test % scalar syms x - assert (isequal (intersect([x 1], x), x)) - assert (isequal (intersect(x, x), x)) + assert (isequal (setdiff([x 1], x), sym(1))) + assert (isempty (setdiff(x, x))) ***** test A = interval(sym(1), 3); B = interval(sym(2), 5); - C = intersect(A, B); - assert( isequal( C, interval(sym(2), 3))) + C = setdiff(A, B); + assert( isequal( C, interval(sym(1), 2, false, true))) 6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/log10.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/log10.m -***** assert (isequal (log10 (sym (1000)), sym (3))) -***** assert (isequal (log10 (sym ([10 100])), sym ([1 2]))) +[inst/@sym/invhilb.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/invhilb.m ***** test - % round-trip - syms x - f = log10 (x); - h = function_handle (f); - A = h (1.1); - B = log10 (1.1); - assert (A, B, -eps) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/isconstant.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isconstant.m + A = invhilb(sym(3)); + B = sym([9 -36 30;-36 192 -180;30 -180 180]); + assert( isequal( A, B)) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/expint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/expint.m +***** error expint (sym(1), 2, 3) ***** test - syms x - A = [x 2 3]; - B = [false true true]; - assert (isequal (isconstant (A), B)) -/usr/lib/python3/dist-packages/sympy/matrices/common.py:2058: SymPyDeprecationWarning: - -non-Expr objects in a Matrix is deprecated. Matrix represents -a mathematical matrix. To represent a container of non-numeric -entities, Use a list of lists, TableForm, NumPy array, or some -other data structure instead. - -See https://docs.sympy.org/latest/explanation/active-deprecations.html#deprecated-non-expr-in-matrix -for details. - -This has been deprecated since SymPy version 1.9. It -will be removed in a future version of SymPy. - - return self._eval_applyfunc(f) + f1 = expint(sym(1)); + f2 = expint(1); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - syms x - A = [x 2; 3 x]; - B = [false true; true false]; - assert (isequal (isconstant (A), B)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/besselj.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselj.m + f1 = expint(sym(1i)); + f2 = expint(1i); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - X = [1 2 3; 4 5 6]; - ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; - n = double(ns); - A = double(besselj(ns, X)); - B = besselj(n, X); - assert (all (all (abs (A - B) < 50*eps*abs(A)))) + D = [1 2; 3 4]; + A = sym(D); + f1 = expint(A); + f2 = expint(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % roundtrip syms x - A = besselj(2, 10); - q = besselj(2, x); - h = function_handle(q); - B = h(10); - assert (abs (A - B) <= eps*abs(A)) -***** error besselj(sym('x')) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/solve.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/solve.m + A = expint(x); + B = expint(1, x); + assert (isequal (A, B)) ***** test - % Simple, single variable, single solution syms x - d = solve(10*x == 50); - assert (isequal (d, 5)) + A = exp(-x)/x; + B = expint(0, x); + assert (isequal (A, B)) ***** test - % Single variable, multiple solutions + % round trip syms x - d = solve(x^2 == 4); - assert (length(d) == 2); - assert (isequal (d, [2; -2]) || isequal (d, [-2; 2])) -***** shared x,y,eq - syms x y - eq = 10*x == 20*y; -***** test - d = solve(eq, x); - assert (isequal (d, 2*y)) -***** test - d = solve(eq, y); - assert (isequal (d, x/2)) -***** test - d = solve(eq); - assert (isequal (d, 2*y)) -***** shared x,y - syms x y -***** test - d = solve(2*x - 3*y == 0, x + y == 1); - assert (isequal (d.x, sym(3)/5) && isequal(d.y, sym(2)/5)) -***** test - d = solve(2*x - 3*y == 0, x + y == 1, x, y); - assert (isequal (d.x, sym(3)/5) && isequal(d.y, sym(2)/5)) -***** test - % Multiple solutions, multiple variables - d = solve(x^2 == 4, x + y == 1); - assert (length(d) == 2); - % FIXME: SMT has d.x gives vector and d.y giving vector, what is - % more intuitive? - for i = 1:2 - assert (isequal (d{i}.x + d{i}.y, 1)) - assert (isequal ((d{i}.x)^2, 4)) - end -***** test - % No solutions - syms x y z - d = solve(x == y, z); - assert (isempty (d)); -***** test - % Multiple outputs with single solution - [X, Y] = solve(2*x + y == 5, x + y == 3); - assert (isequal (X, 2)) - assert (isequal (Y, 1)) -***** test - % system: vector of equations, vector of vars - [X, Y] = solve([2*x + y == 5, x + y == 3], [x y]); - assert (isequal (X, 2)) - assert (isequal (Y, 1)) -***** test - % system: vector of equations, individual vars - [X, Y] = solve([2*x + y == 5, x + y == 3], x, y); - assert (isequal (X, 2)) - assert (isequal (Y, 1)) -***** test - % system: individual equations, vector of vars - [X, Y] = solve(2*x + y == 5, x + y == 3, [x y]); - assert (isequal (X, 2)) - assert (isequal (Y, 1)) -***** test - % Multiple outputs with multiple solns - [X, Y] = solve(x*x == 4, x == 2*y); - assert ((isequal (X, [2; -2]) && isequal (Y, [1; -1])) || ... - (isequal (X, [-2; 2]) && isequal (Y, [-1; 1]))) -***** test - % Multiple outputs with multiple solns, specify vars - [X, Y] = solve(x*x == 4, x == 2*y, x, y); - assert ((isequal (X, [2; -2]) && isequal (Y, [1; -1])) || ... - (isequal (X, [-2; 2]) && isequal (Y, [-1; 1]))) -***** error - % mult outputs not allowed for scalar equation, even with mult soln (?) - [s1, s2] = solve(x^2 == 4, x); -***** test - % overdetermined - X = solve(2*x - 10 == 0, 3*x - 15 == 0, x); - assert (isequal (X, sym(5))) -***** test - a = solve(2*x >= 10, 10*x <= 50); - assert (isequal( a, x==sym(5))) -***** test - A = solve([2*x == 4*y, 2 == 3], x); - assert (isempty (A)) -***** test - % Issue #850 - A = solve (sym(pi)^2*x + y == 0); - assert (isequal (A, -y/sym(pi)^2)) -***** test - % https://github.com/sympy/sympy/issues/14632 - A = solve([2*x == 4*y, sym(2) == 2], x); - assert (isequal (A, 2*y)) -***** test - % https://github.com/sympy/sympy/issues/14632 - A = solve([2*x^2 == 32*y^2, sym(2) == 2], x); - B = solve([2*x^2 == 32*y^2], x); - assert (isequal (A, B) || isequal (A, flip (B))) + A = expint (3); + f = expint (x); + h = function_handle (f); + B = h (3); + assert (A, B, -eps) +***** error + % round trip + syms n x + f = expint (n, x); + h = function_handle (f); +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/chebyshevT.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/chebyshevT.m +***** error chebyshevT (sym(1)) +***** error chebyshevT (sym(1), 2, 3) +***** assert (isequaln (chebyshevT (2, sym(nan)), sym(nan))) +***** shared x + syms x +***** assert(isequal(chebyshevT(0, x), sym(1))) +***** assert(isequal(chebyshevT(1, x), x)) +***** assert(isequal(chebyshevT(2, x), 2*x*x - 1)) +***** assert(isequal(chebyshevT([0 1 2], x), [sym(1) x (2*x*x-1)])) ***** test - A = solve ([x+1 0], x); - assert (isequal (A, sym (-1))) + % round trip + syms n z + f = chebyshevT (n, z); + h = function_handle (f, 'vars', [n z]); + A = h (1.1, 2.2); + B = chebyshevT (1.1, 2.2); + assert (A, B) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/besselj.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselj.m ***** test - A = solve (x + 1, x); - assert (isequal (A, sym (-1))) - A = solve (x, x); - assert (isequal (A, sym (0))) -24 tests, 24 passed, 0 known failure, 0 skipped -[inst/@sym/orth.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/orth.m + X = [1 2 3; 4 5 6]; + ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; + n = double(ns); + A = double(besselj(ns, X)); + B = besselj(n, X); + assert (all (all (abs (A - B) < 50*eps*abs(A)))) ***** test - A = [1 2; 3 6]; - K = orth(A); - L = orth(sym(A)); - assert (isequal (size(L), [2 1])) - dif1 = abs (double(L) - K); - dif2 = abs (double(L) + K); - assert (all (dif1 < 1e-15) || all (dif2 < 1e-15)) + % roundtrip + syms x + A = besselj(2, 10); + q = besselj(2, x); + h = function_handle(q); + B = h(10); + assert (abs (A - B) <= eps*abs(A)) +***** error besselj(sym('x')) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/floor.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/floor.m +***** error floor (sym(1), 2) +***** assert (isequaln (floor (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - A = [1; 3]; - K = orth(A); - L = orth(sym(A)); - assert (isequal (size(L), [2 1])) - dif1 = abs (double(L) - K); - dif2 = abs (double(L) + K); - assert (all (dif1 < 1e-16) || all (dif2 < 1e-16)) + f1 = floor(x); + f2 = floor(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - A = sym([1 2; 3 4]); - L = orth(sym(A)); - assert (isequal (size(L), [2 2])) - v = L(:, 1); - w = L(:, 2); - assert (isAlways (v' * v == 1)) - assert (isAlways (w' * w == 1)) - assert (isAlways (v' * w == 0)) + D = [d d; d d]; + A = [x x; x x]; + f1 = floor(A); + f2 = floor(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - A = sym([1 1; 1 0; 1 0]); - L = orth(sym(A)); - assert (isequal (size(L), [3 2])) - v = L(:, 1); - w = L(:, 2); - assert (isAlways (v' * v == 1)) - assert (isAlways (w' * w == 1)) - assert (isAlways (v' * w == 0)) - % y and z components must be equal - assert (isAlways (v(2) == v(3))) - assert (isAlways (w(2) == w(3))) -4 tests, 4 passed, 0 known failure, 0 skipped + % round trip + y = sym('y'); + A = floor (d); + f = floor (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped [inst/@sym/toeplitz.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/toeplitz.m ***** test @@ -5920,779 +5975,999 @@ toeplitz at line 84 column 7 __test__ at line 6 column 4 test at line 683 column 11 - /tmp/tmp.TtggOOunpq at line 550 column 31 + /tmp/tmp.YpV62juqem at line 558 column 31 6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/sign.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sign.m -***** error sign (sym(1), 2) -***** assert (isequaln (sign (sym(nan)), sym(nan))) +[inst/@sym/ne.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ne.m +***** test + % simple + x = sym(1); y = sym(1); e = x ~= y; + assert (~logical (e)) + x = sym(1); y = sym(2); e = x ~= y; + assert (logical(e)) +***** test + % array -- array + syms x + a = sym([1 3 3 2*x]); + b = sym([2 x 3 10]); + e = a ~= b; + assert (isa (e, 'sym')) + assert (logical (e(1))) + assert (isa (e(2), 'sym')) + assert (isequal (e(2), 3 ~= x)) + assert (~logical (e(3))) + assert (isa (e(4), 'sym')) + assert (isequal (e(4), 2*x ~= 10)) +***** test + % oo + syms oo x + e = oo ~= x; + assert (isa (e, 'sym')) + s = strtrim (disp (e, 'flat')); + % SymPy <= 0.7.6.x will be '!=', newer gives 'Ne', test both + assert (strcmp (s, 'oo != x') || strcmp (s, 'Ne(oo, x)')) +***** test + % nan + syms oo x + snan = sym(nan); + e = snan ~= sym(0); + assert (logical (e)) + e = snan ~= snan; + assert (logical (e)) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/private_disp_name.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/private_disp_name.m +***** test + syms x + s = private_disp_name(x, 'x'); + assert (strcmp (s, 'x')) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/erfc.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfc.m +***** error erfc (sym(1), 2) +***** assert (isequaln (erfc (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = sign(x); - f2 = sign(d); + f1 = erfc(x); + f2 = erfc(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = sign(A); - f2 = sign(D); + f1 = erfc(A); + f2 = erfc(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = sign (d); - f = sign (y); + A = erfc (d); + f = erfc (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/kroneckerDelta.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/kroneckerDelta.m -***** error kroneckerDelta (sym(1), 2, 3) +[inst/@sym/ellipticCE.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticCE.m +***** error ellipticCE (sym (1), 2) +***** assert (isequal (ellipticCE (sym (0)), sym (1))) +***** assert (isequal (ellipticCE (sym (1)), sym (pi)/2)) +***** assert (double (ellipticCE (sym (pi)/4)), 1.482786927, 10e-10) +***** assert (double (ellipticCE (sym (pi)/2)), 1.775344699, 10e-10) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/log10.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/log10.m +***** assert (isequal (log10 (sym (1000)), sym (3))) +***** assert (isequal (log10 (sym ([10 100])), sym ([1 2]))) ***** test + % round-trip syms x - assert (isequal (kroneckerDelta (x, x), sym(1))) -***** assert (isequal (kroneckerDelta ([sym(1) 2 3], [1 2 0]), sym([1 1 0]))) + f = log10 (x); + h = function_handle (f); + A = h (1.1); + B = log10 (1.1); + assert (A, B, -eps) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/asech.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/asech.m +***** error asech (sym(1), 2) +***** assert (isequaln (asech (sym(nan)), sym(nan))) +***** shared x, d + d = 1/2; + x = sym('1/2'); +***** test + f1 = asech(x); + f2 = asech(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = asech(A); + f2 = asech(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip - syms x y - f = kroneckerDelta (x, y); + y = sym('y'); + A = asech (d); + f = asech (y); h = function_handle (f); - assert (h (1, 2), 0) - assert (h (2, 2), 1) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/symvar.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/symvar.m -***** error symvar (sym(1), 2, 3) + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/isAlways.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isAlways.m ***** test - %% some empty cases - assert (isempty (symvar (sym(1)))); - assert (isempty (symvar (sym(1),1))); - assert (isempty (symvar (sym(1),0))); - assert (isempty (symvar (sym('x'),0))); -***** shared x,y,f - x=sym('x'); y=sym('y'); f=x^2+3*x*y-y^2; -***** assert (isequal (symvar (f), [x y])); -***** assert (isequal (symvar (f, 1), x)); + % basics + assert(isAlways(true)) + assert(isAlways(1==1)) + assert(isAlways(sym(1)==sym(1))) + assert(isAlways(sym(1)==1)) ***** test - %% closest to x - syms x y a b c xx - alpha = sym('alpha'); - % https://www.mathworks.com/matlabcentral/newsreader/view_thread/237730 - assert( isequal (symvar (b*xx*exp(alpha) + c*sin(a*y), 2), [xx y])) - %% tests to match Matlab R2013b -***** shared x,y,z,a,b,c,X,Y,Z - syms x y z a b c X Y Z + % numbers to logic? + assert (isAlways(sym(1))) + assert (isAlways(sym(-1))) + assert (~isAlways(sym(0))) +***** shared x + syms x ***** test - %% X,Y,Z first if no 2nd argument - s = prod([x y z a b c X Y Z]); - assert (isequal( symvar (s), [X Y Z a b c x y z] )) + % in this case it is boolean + expr = x - x == 0; + assert (logical(expr)) + assert (isAlways(expr)) + % and both are logical type + assert (islogical(logical(expr))) + assert (islogical(isAlways(expr))) ***** test - %% uppercase have *low* priority with argument? - s = prod([x y z a b c X Y Z]); - assert (isequal (symvar (s,4), [x, y, z, c] )) + % structurally same and mathematically true + % (here expr should be sym, non-boolean) + expr = x == x; + assert (logical(expr)) + assert (isAlways(expr)) + %assert (~islogical(expr)) % FIXME: Issue #56 + %assert (isa(expr, 'sym)) ***** test - %% closest to x - s = prod([y z a b c Y Z]); - assert (isequal( symvar (s,6), [ y, z, c, b, a, Y] )) - s = prod([a b c Y Z]); - assert (isequal( symvar (s,4), [ c, b, a, Y] )) + % structurally same and mathematically true + % (here expr should be sym, non-boolean) + expr = 1 + x == x + 1; + assert (logical(expr)) + assert (isAlways(expr)) ***** test - %% upper case letters in correct order - s = X*Y*Z; - assert (isequal( symvar (s,3), [X Y Z] )) + % non-zero numbers are true + assert (isAlways(sym(1))) + assert (isAlways(sym(-10))) + assert (~isAlways(sym(0))) +***** shared x, y + syms x y ***** test - % diff. assumptions make diff. symbols - x1 = sym('x'); - x2 = sym('x', 'positive'); - f = x1*x2; - assert (length (symvar (f)) == 2) - z = symvar (f, 1); - assert (xor (isequal (z, x1), isequal (z, x2))) -10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@sym/colon.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/colon.m + % structurally same and mathematically true + % (here expr should be sym, non-boolean) + expr = x*(1+y) == x*(y+1); + assert (logical(expr)) + assert (isAlways(expr)) + assert (islogical(isAlways(expr))) ***** test - a = sym(1):5; - b = sym(1:5); - assert(isequal(a,b)); - a = 1:sym(5); - b = sym(1:5); - assert(isequal(a,b)); + % Now for some differences + % simplest example from SymPy FAQ + expr = x*(1+y) == x+x*y; + assert (~logical(expr)) + assert (isAlways(expr)) ***** test - a = 2:sym(2):8; - b = sym(2:2:8); - assert(isequal(a,b)); + % more differences 1, these don't simplify in sympy (as of 2016-01) + expr = (x+1)^2 == x*x + 2*x + 1; + assert (~logical(expr)) + assert (isAlways(expr)) ***** test - a = sym(10):-2:-4; - b = sym(10:-2:-4); - assert(isequal(a,b)); + % more differences 2 + expr = sin(2*x) == 2*sin(x)*cos(x); + assert (~logical(expr)) + assert (isAlways(expr)) ***** test - % symbolic intervals - p = sym(pi); - L = 0:p/4:p; - assert(isa(L,'sym')); - assert(isequal(L, [0 p/4 p/2 3*p/4 p])); + % more differences 3, false + expr = x*(x+y) == x^2 + x*y + 1; + assert (~logical(expr)) + assert (~isAlways(expr)) + assert (~isAlways(expr, 'unknown', 'error')) ***** test - % mixed symbolic and double intervals - p = sym(pi); - s = warning ('off', 'OctSymPy:sym:rationalapprox'); - L = 0.1:(sym(pi)/3):2.3; - warning(s) - assert(isa(L,'sym')); - t = sym(1)/10; - assert(isequal(L, [t p/3+t 2*p/3+t])); -***** error syms x; a = 0:x; -***** error syms x; a = 1:x; -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/airy.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/airy.m + % logically not equal, math equal + exprn = x*(x+y) ~= x^2 + x*y; + assert (logical(exprn)) + assert (~isAlways(exprn)) ***** test - syms z - a = airy(0, z); - ap = airy(1, z); - assert (isequal (diff (a), ap)) - assert (isequal (diff (ap), z*a)) + % logically not equal, math not equal + exprn = x*(x+y) ~= x^2 + x*y + 1; + assert (logical(exprn)) + assert (isAlways(exprn)) ***** test - syms z - b = airy(2, z); - bp = airy(3, z); - assert (isequal (diff (b), bp)) - assert (isequal (diff (bp), z*b)) + % equal and not equal + e1 = sin(x)^2 + cos(x)^2 == 1; + e2 = sin(x)^2 + cos(x)^2 == 2; + assert (~logical(e1)) + assert (isAlways(e1)) + assert (~logical(e2)) + assert (~isAlways(e2)) + assert (~isAlways(e2, 'unknown', 'error')) +***** error isAlways(x, 'unknown', 'kevin') +***** error isAlways(x, 'unknown') +***** error isAlways(x, 'kevin', 'true') +***** error + a = [x*(x+y)==x^2+x*y x==y]; + b = isAlways(a, 'unknown', 'error'); +***** error + a = x==y; + b = isAlways(a, 'unknown', 'error'); ***** test - % default to k=0 - syms z - a = airy(0, z); - a2 = airy(z); - assert (isequal (a, a2)) -***** error airy(0, sym('x'), 2) -***** error airy(4, sym('z')) -***** error airy(-1, sym('z')) + % array, unknown keyword + a = [x==x x==x+1 x==y x*(x+y)==x^2+x*y cos(x)^2+sin(x)^2==2]; + b = isAlways(a, 'unknown', false); + c = isAlways(a, 'unknown', 'false'); + expect = [true false false true false]; + assert (islogical(b)) + assert (isequal (b, expect)) + assert (isequal (c, expect)) + b = isAlways(a, 'unknown', true); + c = isAlways(a, 'unknown', 'true'); + expect = [true false true true false]; + assert (islogical(b)) + assert (isequal (b, expect)) + assert (isequal (c, expect)) ***** test - % symbolic k - syms z - b1 = airy(2, z); - b2 = airy(sym(2), z); - assert (isequal (b1, b2)) + % ineq + e = x*(x+y) <= x^2 + x*y + 1; + assert (~logical(e)) + assert (isAlways(e)) + e = x*(x+y) <= x^2 + x*y; + assert (~logical(e)) + assert (isAlways(e)) +21 tests, 21 passed, 0 known failure, 0 skipped +[inst/@sym/asec.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/asec.m +***** error asec (sym(1), 2) +***** assert (isequaln (asec (sym(nan)), sym(nan))) +***** shared x, d + d = 2; + x = sym('2'); ***** test - % doubles, relative error - X = [1 2 pi; 4i 5 6+6i]; - Xs = sym(X); - for k = 0:3 - A = double(airy(k, Xs)); - B = airy(k, X); - assert (all (all (abs(A - B) < 500*eps*abs(A)))) - end + f1 = asec(x); + f2 = asec(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % round-trip + D = [d d; d d]; + A = [x x; x x]; + f1 = asec(A); + f2 = asec(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = asec (d); + f = asec (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/asind.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/asind.m +***** error asind (sym(1), 2) +***** assert (isequaln (asind (sym(nan)), sym(nan))) +***** test + f1 = asind (sym(1)/2); + f2 = asind (1/2); + assert (double (f1), f2, -eps) +***** test + D = [1 2; 3 4]/4; + A = sym([1 2; 3 4])/4; + f1 = asind (A); + f2 = asind (D); + assert (double (f1), f2, -eps) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/plus.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/plus.m +***** test + % basic addition syms x - for k = 0:3 - A = airy(k, 10); - q = airy(k, x); - h = function_handle(q); - B = h(10); - assert (abs(A-B) < 500*eps*abs(A)) - end -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/limit.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/limit.m -***** error limit (sym(1), 2, 3, 4, 5) -***** shared x, oo + assert (isa (x+5, 'sym')) + assert (isa (5+x, 'sym')) + assert (isa (5+sym(4), 'sym')) + assert (isequal (5+sym(4), sym(9))) +***** test + % array addition syms x - oo = sym(inf); -***** assert (isa (limit(x, x, pi), 'sym')) -***** assert (isequal (limit(x, x, pi), sym(pi))) -***** assert (isequal (limit(sin(x)/x, x, 0), 1)) + D = [0 1; 2 3]; + A = [sym(0) 1; sym(2) 3]; + DZ = D - D; + assert( isequal ( A + D , 2*D )) + assert( isequal ( D + A , 2*D )) + assert( isequal ( A + A , 2*D )) + assert( isequal ( A + 2 , D + 2 )) + assert( isequal ( 4 + A , 4 + D )) ***** test - % left/right-hand limit - assert (isequal (limit(1/x, x, 0, 'right'), oo)) - assert (isequal (limit(1/x, x, 0), oo)) - assert (isequal (limit(1/x, x, 0, 'left'), -oo)) - assert (isequal (limit(1/x, x, oo), 0)) - assert (isequal (limit(sign(x), x, 0, 'left'), -1)) - assert (isequal (limit(sign(x), x, 0, 'right'), 1)) - assert (isequal (limit(sign(x), x, 0, '-'), -1)) - assert (isequal (limit(sign(x), x, 0, '+'), 1)) + % ensure MatrixExpr can be manipulated somewhat + syms n m integer + A = sym('A', [n m]); + B = subs(A, [n m], [5 6]); + B = B + 1; + assert (isa (B, 'sym')) + C = B(1, 1); % currently makes a MatrixElement + C = C + 1; + assert (isa (C, 'sym')) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/assume.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/assume.m ***** test - % matrix - syms y - A = [x 1/x x*y]; - B = sym([3 sym(1)/3 3*y]); - assert (isequal (limit(A, x, 3), B)) + syms x + x = assume(x, 'positive'); + a = assumptions(x); + assert(strcmp(a, 'x: positive')) + x = assume(x, 'even'); + a = assumptions(x); + assert(strcmp(a, 'x: even')) + x = assume(x, 'odd'); + a = assumptions(x); + assert(strcmp(a, 'x: odd')) +***** error + syms x + x = assume (x, x); +***** error + syms x + x = assume (x/pi, 'integer') ***** test - % omitting arguments - syms a - assert (isequal (limit(a), 0)) - assert (isequal (limit(a*x+a+2), a+2)) - assert (isequal (limit(a*x+a+2, 6), 7*a+2)) + % multiple assumptions + syms x + x = assume(x, 'positive', 'integer'); + [tilde, a] = assumptions(x, 'dict'); + assert(a{1}.integer) + assert(a{1}.positive) ***** test - % constants - assert (isequal (limit(sym(6)), 6)) - assert (isequal (limit(sym(6), 7), 6)) - assert (isequal (limit([sym(6) sym(2)], 7), [6 2])) + % multiple assumptions + syms x + x = assume(x, 'even', 'positive'); + [tilde, a] = assumptions(x, 'dict'); + assert(a{1}.even) + assert(a{1}.positive) ***** test - % double constant, with sym limit - a = limit (6, sym(0)); - assert (isa (a, 'sym')) - assert (isequal (a, sym(6))) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/char.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/char.m + % has output so avoids workspace + syms x positive + x2 = x; + f = sin(x); + x = assume(x, 'negative'); + a = assumptions(x); + assert(strcmp(a, 'x: negative')) + a = assumptions(x2); + assert(strcmp(a, 'x: positive')) + a = assumptions(f); + assert(strcmp(a, 'x: positive')) ***** test - % issue #91: expose as string - a = sym(pi); - assert (strcmp (char (a), 'pi')) -***** shared x - x = sym('x'); -***** assert (strcmp (char (x), 'x')) -***** assert (strcmp (char (2*x), '2*x')) -***** assert (strcmp (char ([2*x x]), 'Matrix([[2*x, x]])')) -***** assert (strcmp (char ([2*x 2; 1 x]), 'Matrix([[2*x, 2], [1, x]])')) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ezsurf.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ezsurf.m -***** error - syms u v t - ezsurf(u*v, 2*u*v, 3*v*t) -***** error - syms u v t - ezsurf(u*v, 2*u*v, u*v*t) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/permute.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/permute.m -***** error permute (sym(1)) -***** error permute (sym(1), 2, 3) + % clear: has output so avoids workspace + syms x positive + f = 2*x; + x2 = assume(x, 'clear'); + assert (~ isempty (assumptions (f))); ***** test - D = round(10*rand(5,3)); - A = sym(D); - B = permute(A, [1 2]); - assert (isequal(B, A)) - B = permute(A, [2 1]); - assert (isequal(B, A.')) + % has no output so does workspace + syms x positive + x2 = x; + f = sin(x); + assume(x, 'negative'); + a = assumptions(x); + assert(strcmp(a, 'x: negative')) + a = assumptions(x2); + assert(strcmp(a, 'x: negative')) + a = assumptions(f); + assert(strcmp(a, 'x: negative')) ***** test - syms x - A = [1 x]; - B = permute(A, [2 1]); - assert (isequal(B, [1; x])) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/fourier.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/fourier.m + % clear: has not output so does workspace + syms x positive + f = 2*x; + assume(x, 'clear'); + assert (isempty (assumptions (f))); + assert (isempty (assumptions ())); ***** test - % matlab SMT compatibiliy for arguments - syms r x u w v - Pi=sym('pi'); - assert(logical( fourier(exp(-x^2)) == sqrt(Pi)/exp(w^2/4) )) - assert(logical( fourier(exp(-w^2)) == sqrt(Pi)/exp(v^2/4) )) - assert(logical( fourier(exp(-r^2),u) == sqrt(Pi)/exp(u^2/4) )) - assert(logical( fourier(exp(-r^2),r,u) == sqrt(Pi)/exp(u^2/4) )) + syms x positive + assume (x, 'clear') + assert (isempty (assumptions ())) +***** error + syms x + x2 = assume (x, 'clear', 'real'); +***** error + syms a + assume (a > 0) ***** test - % basic tests - syms x w - assert(logical( fourier(exp(-abs(x))) == 2/(w^2 + 1) )) - assert(logical( fourier(x*exp(-abs(x))) == -(w*4*1i)/(w^4 + 2*w^2 + 1) )) + syms x y + assume ([x y], 'real') + assert (strcmp (assumptions (x), 'x: real')) + assert (strcmp (assumptions (y), 'y: real')) ***** test - % Dirac delta tests - syms x w - Pi=sym('pi'); - assert(logical( fourier(dirac(x-2)) == exp(-2*1i*w) )) - assert (logical( fourier(sym(2), x, w) == 4*Pi*dirac(w) )) + syms x y + assume ([x y], 'positive', 'even') + assert (strcmp (assumptions (x), 'x: positive, even') || strcmp (assumptions (x), 'x: even, positive')) + assert (strcmp (assumptions (y), 'y: positive, even') || strcmp (assumptions (y), 'y: even, positive')) ***** test - % advanced test - syms x w c d - Pi=sym('pi'); - F=Pi*(dirac(w-c)+dirac(w+c))+2*Pi*1i*(dirac(w+3*d)-dirac(w-3*d))+2/(w^2+1); - assert(logical( fourier(cos(c*x)+2*sin(3*d*x)+exp(-abs(x))) == expand(F) )) -***** xtest - % Differential operator to algebraic - % SymPy cannot evaluate? (Issue #170) - syms x w f(x) - assert(logical( fourier(diff(f(x),x),x,w) == -1i*w*fourier(f(x),x,w) )) -!!!!! known failure -assert (logical (fourier (diff (f (x), x), x, w) == -1i * w * fourier (f (x), x, w))) failed -5 tests, 4 passed, 1 known failure, 0 skipped -[inst/@sym/or.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/or.m -***** shared t, f - t = sym(true); - f = sym(false); + % with output, original x and y are unchanged + syms x y + [p, q] = assume ([x y], 'real'); + assert (isempty (assumptions (x))) + assert (isempty (assumptions (y))) + assert (strcmp (assumptions (p), 'x: real')) + assert (strcmp (assumptions (q), 'y: real')) ***** test - % simple - assert (isequal (t | f, t)) - assert (isequal (t | t, t)) - assert (isequal (f | f, f)) + % matrix input + syms a b c d + assume ([a b; c d], 'real') + assert (strcmp (assumptions (a), 'a: real')) + assert (strcmp (assumptions (b), 'b: real')) + assert (strcmp (assumptions (c), 'c: real')) + assert (strcmp (assumptions (d), 'd: real')) +16 tests, 16 passed, 0 known failure, 0 skipped +[inst/@sym/hilb.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/hilb.m ***** test - % array - w = [t t f f]; - z = [t f t f]; - assert (isequal (w | z, [t t t f])) + A = hilb (sym(3)); + B = [sym(1) sym(1)/2 sym(1)/3; sym(1)/2 sym(1)/3 sym(1)/4; sym(1)/3 sym(1)/4 sym(1)/5]; + assert (isequal (A, B)) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/inv.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/inv.m ***** test - % output is sym even for scalar t/f - assert (isa (t | f, 'sym')) + % scalar + syms x + assert (isequal (inv(x), 1/x)) ***** test - % eqns + % diagonal syms x - e = or(x == 4, x == 5); - assert (isequal (subs(e, x, [3 4 5 6]), [f t t f])) -***** error or (sym(1), 2, 3) + A = [sym(1) 0; 0 x]; + B = [sym(1) 0; 0 1/x]; + assert (isequal (inv(A), B)) +***** test + % 2x2 inverse + A = [1 2; 3 4]; + assert (max (max (abs (double (inv (sym (A))) - inv(A)))) <= 3*eps) +***** error + syms a; + A = [a a; a a]; + inv(A) +***** error + syms a; + A = [a a]; + inv(A) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/atanh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/atanh.m -***** error atanh (sym(1), 2) -***** assert (isequaln (atanh (sym(nan)), sym(nan))) -***** shared x, d - d = 1/2; - x = sym('1/2'); +[inst/@sym/isscalar.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isscalar.m +***** assert(isscalar(sym('x'))) ***** test - f1 = atanh(x); - f2 = atanh(d); - assert( abs(double(f1) - f2) < 1e-15 ) + a = sym([1 2 3]); + assert(~isscalar(a)) +***** assert(~isscalar(sym([]))) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/heaviside.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/heaviside.m +***** error heaviside (sym(1), 2, 3) +***** assert (isequal (heaviside (sym(1)), sym(1))) +***** assert (isequal (heaviside (-sym(1)), sym(0))) +***** assert (double (heaviside (1)), heaviside (1)) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = atanh(A); - f2 = atanh(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + D = [1 -1; -10 20]; + A = sym(D); + assert (double (heaviside (A)), heaviside (D)) +***** test + H0 = sym([1 -2 0; 3 0 pi]); + A = heaviside (sym(0), H0); + assert (isequal (A, H0)) +***** test + A = heaviside ([-1 0 1], sym(1)/2); + assert (isequal (A, [0 sym(1)/2 1])) +***** test + A = heaviside ([-1 0 1], sym(1)/2); + assert (isequal (A, [0 sym(1)/2 1])) +***** assert (isequaln (heaviside (sym(nan)), sym(nan))) +***** test + assert (isequaln (heaviside (sym(nan), sym(nan)), sym(nan))) + assert (isequaln (heaviside (0, sym(nan)), sym(nan))) + assert (isequaln (heaviside (2, sym(nan)), sym(1))) + assert (isequaln (heaviside (-2, sym(nan)), sym(0))) ***** test % round trip - y = sym('y'); - A = atanh (d); - f = atanh (y); + syms x + A = heaviside (1); + f = heaviside (x); h = function_handle (f); - B = h (d); + B = h (1); assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/isNone.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isNone.m ***** test - None = pycall_sympy__ ('return None'); -***** shared None - None = pycall_sympy__ ('return None'); -***** assert (isNone(None)) -***** assert (~isNone(sym('x'))) -***** assert (islogical(isNone(None))) + % round trip + syms x h0 + f = heaviside (x, h0); + h = function_handle (f, 'vars', {x h0}); + A = heaviside (1, 1/2); + B = h (1, 1/2); + assert (A, B, -eps) + A = heaviside (0, 1/2); + B = h (0, 1/2); + assert (A, B, -eps) +12 tests, 12 passed, 0 known failure, 0 skipped +[inst/@sym/kroneckerDelta.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/kroneckerDelta.m +***** error kroneckerDelta (sym(1), 2, 3) ***** test - a = [1 None]; - a = [None None]; - a = [None; 1]; - a = [None; None]; - a = [None 2; 3 None]; + syms x + assert (isequal (kroneckerDelta (x, x), sym(1))) +***** assert (isequal (kroneckerDelta ([sym(1) 2 3], [1 2 0]), sym([1 1 0]))) ***** test - a = sym([1 2]); - a(1,2) = None; - assert (isequal (a, [sym(1) None])); -***** assert (isequal (None(1), None)); -***** error None(None); -***** error x=sym('x'); x(None); -***** error x=1; x(None); -***** error None(None); -***** error 1 + None; -***** error None - 1; -***** error 6*None; -***** error 2^None; -***** error [1 2].*None; -***** error isconstant(None); -***** error nnz(None); -***** error logical(None); -***** error isAlways(None); -***** error logical([sym(true) None]); -***** error isAlways([sym(true) None]); -***** assert (isequal (children(None), None)) -***** assert (isequal (repmat(None, 1, 2), [None None])) -***** assert (isequal (fliplr(None), None)) -***** assert (isequal (flipud(None), None)) -26 tests, 26 passed, 0 known failure, 0 skipped -[inst/@sym/argnames.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/argnames.m + % round trip + syms x y + f = kroneckerDelta (x, y); + h = function_handle (f); + assert (h (1, 2), 0) + assert (h (2, 2), 1) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/cumprod.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cumprod.m +***** shared x, y + x = sym ('x'); + y = sym ('y'); +***** error cumprod (x, 1, 2) +***** assert (isequal (cumprod ([-x; -2*x; -3*x]), [-x; 2*x^2; -6*x^3])) +***** assert (isequal (expand (cumprod ([x + i, x - i])), [x + i, x^2 + 1])) +***** assert (isequal (cumprod ([1, x; y, 2], 1), [1, x; y, 2*x] )) +***** assert (isequal (cumprod ([1, x; y, 2], 2), [1, x; y, 2*y] )) +***** test cumprod ([x, x], [2, 1]); # ensure behaves like builtin cumprod +***** test cumprod ([x, x], [1, -2]); # ensure behaves like builtin cumprod +***** error cumprod (x, []) +***** error cumprod (x, {1}) +***** error cumprod (x, struct('a', 1)) +***** error cumprod (x, x) +***** error cumprod (x, 0) +***** error cumprod (x, -1) +13 tests, 13 passed, 0 known failure, 0 skipped +[inst/@sym/svd.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/svd.m ***** test - % basic tests + % basic + A = [1 2; 3 4]; + B = sym(A); + sd = svd(A); + s = svd(B); + s2 = double(s); + assert (norm(s2 - sd) <= 10*eps) +***** test + % scalars syms x - f = 2*x; - assert (isempty (argnames(x))) - assert (isempty (argnames(f))) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/asin.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/asin.m -***** error asin (sym(1), 2) -***** assert (isequaln (asin (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + syms y positive + a = sym(-10); + assert (isequal (svd(a), sym(10))) + assert (isequal (svd(x), sqrt(x*conj(x)))) + assert (isequal (svd(y), y)) ***** test - f1 = asin(x); - f2 = asin(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % matrix with symbols + syms x positive + A = [x+1 0; sym(0) 2*x+1]; + s = svd(A); + s2 = subs(s, x, 2); + assert (isequal (s2, [sym(5); 3])) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = asin(A); - f2 = asin(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % matrix with symbols + syms x positive + A = [x+1 0; sym(0) 2*x+1]; + s = svd(A); + s2 = subs(s, x, 2); + assert (isequal (s2, [sym(5); 3])) ***** test - % round trip - y = sym('y'); - A = asin (d); - f = asin (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) + % matrix with symbols, nonneg sing values + syms x real + A = [x 0; 0 sym(-5)]; + s = svd(A); + assert (isequal (s, [abs(x); 5])) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/sort.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sort.m -***** error sort (sym(1), 2) +[inst/@sym/length.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/length.m ***** test - f = [sym(1), sym(0)]; - expected = sym([0, 1]); - assert (isequal (sort(f), expected)) + a = sym([1 2 3]); + assert(length(a) == 3); ***** test - f = [sym(1)]; - expected = sym(1); - assert (isequal (sort(f), expected)) + % 2D array + a = sym([1 2 3; 4 5 6]); + assert(length(a) == 3); ***** test - f = [sym(3), sym(2), sym(6)]; - s = sort(f); - expected_s = sym([2, 3, 6]); - assert (isequal (s, expected_s)) + % empty + a = sym([]); + assert(length(a) == 0); +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/resize.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/resize.m ***** test - f = [sym(pi), sin(sym(2)), sqrt(sym(6))]; - s = sort(f); - expected_s = sym([sin(sym(2)), sqrt(sym(6)), sym(pi)]); - assert (isequal (s, expected_s)) + B = sym([1 0 0; 0 0 0]); + assert (isequal (resize (sym(1), 2, 3), B)) + assert (isequal (resize (sym(1), [2 3]), B)) ***** test - f = [sym(1), sym(2); sym(2), sym(pi); sym(pi), sym(1)]; - s = sort(f); - expected_s = ([sym(1), sym(1); sym(2), sym(2); sym(pi), sym(pi)]); - assert (isequal (s, expected_s)) -***** assert (isequal (sort(sym([])), sym([]))) -***** error sort([sym('x') 1]) + B = sym([1 0; 0 0]); + assert (isequal (resize (sym(1), 2), B)) ***** test - % but with assumptions, symbols can be sorted - p = sym('p', 'positive'); - n = sym('n', 'negative'); - expected_s = [n p]; - s = sort ([p n]); - assert (isequal (s, expected_s)) + A = sym([pi 2; 3 4]); + assert (isequal (resize (A, 1), sym(pi))) +***** assert (isequal (size (resize (sym(1), 0, 0)), [0 0])) +***** assert (isequal (size (resize (sym(1), 6, 0)), [6 0])) +***** assert (isequal (size (resize (sym(1), 0, 3)), [0 3])) +***** error resize (sym(1)) +***** error resize (sym(1), 2, 3, 4) +***** error resize (sym(1), [2 3 4]) 9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/dirac.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/dirac.m -***** error dirac (sym(1), 2) -***** assert (isequaln (dirac (sym(nan)), sym(nan))) +[inst/@sym/cos.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cos.m +***** error cos (sym(1), 2) +***** assert (isequaln (cos (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = dirac(x); - f2 = dirac(d); + f1 = cos(x); + f2 = cos(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = dirac(A); - f2 = dirac(D); + f1 = cos(A); + f2 = cos(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = dirac (d); - f = dirac (y); + A = cos (d); + f = cos (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/isrow.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isrow.m -***** assert (isrow (sym ([1]))) -***** assert (isrow (sym ([1 2 3]))) -***** assert (~isrow (sym ([]))) -***** assert (~isrow (sym ([1 2 3]'))) -***** assert (~isrow (sym ([1 2; 3 4]))) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/kron.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/kron.m +[inst/@sym/rdivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/rdivide.m ***** test - syms x y - A = [sin(x), sin(y); x, y]; - B = ones(2); - expected = sym([sin(x), sin(x), sin(y), sin(y); sin(x), sin(x), sin(y), sin(y); x, x, y, y; x, x, y, y]); - assert (isequal (kron(A, B), expected)) + % scalar + syms x + assert (isa (x ./ 1, 'sym')) + assert (isa (x ./ x, 'sym')) + assert (isequal (x ./ 1, x)) + assert (isequal (x ./ x, sym(1))) ***** test - syms x y - A = [sin(x), sin(y); x, y]; - B = 2; - assert (isequal (kron(A, B), 2*A)) + % matrix-scalar + D = 2*[0 1; 2 3]; + A = sym(D); + assert (isequal ( A./2 , D/2 )) + assert (isequal ( A./sym(2) , D/2 )) + assert (isequal ( D./sym(2) , D/2 )) +***** test + % matrix ./ matrix + D = [1 2; 3 4]; + A = sym(D); + assert (isequal ( A./A , D./D )) + assert (isequal ( A./D , D./D )) + assert (isequal ( D./A , D./D )) ***** test + % matrix ./ matrix with symbols syms x y - A = [sin(x), sin(y)]; - B = 2; - assert (isequal( kron(B, A), 2*A)) + A = [x y; x^2 2*y]; + B = [y x; x y]; + assert (isequal ( A./A , sym(ones(2,2)) )) + assert (isequal ( A./B , [x/y y/x; x 2] )) ***** test - syms x y; - X = [tan(x), tan(x)]; - Y = [cot(x); cot(x)]; - expected = sym(ones(2)); - assert (isequal (simplify(kron(X, Y)), expected)) + % scalar ./ matrix + D = [1 2; 3 4]; + A = sym(D); + assert (isequal ( 12./A , 12./D )) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/det.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/det.m +***** assert (isequal (det(sym([])), 1)) ***** test - syms x y z - X = [x, y, z]; - Y = [y, y; x, x]; - expected = [x*y, x*y, y^2, y^2, y*z, y*z; x^2, x^2, x*y, x*y, x*z, x*z]; - assert (isequal (kron(X, Y), expected)) + syms x y real + assert (isequal (det([x 5; 7 y]), x*y-35)) ***** test - syms x y - X = [x, x^2; y, y^2]; - Y = [1, 0; 0, 1]; - expected = [x, x^2, 0, 0; y, y^2, 0, 0; 0, 0, x, x^2; 0, 0, y, y^2]; - assert (isequal (kron(Y, X), expected)) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/fresnelc.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/fresnelc.m -***** error fresnelc (sym(1), 2) + syms x + assert (isequal (det(x), x)) + assert (isequal (det(sym(-6)), sym(-6))) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/divergence.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/divergence.m +***** shared x,y,z + syms x y z ***** test - a = fresnelc(sym(0)); - assert (isequal (a, sym(0))) + % 1D + f = x^2; + assert (isequal (divergence(f), diff(f,x))) + assert (isequal (divergence(f,{x}), diff(f,x))) + assert (isequal (divergence(f,[x]), diff(f,x))) + assert (isequal (divergence(f,x), diff(f,x))) ***** test - b = fresnelc(sym('oo')); - assert (isequal (b, sym(1)/2)) + % const + f = [sym(1); 2; exp(sym(3))]; + assert (isequal (divergence(f,{x,y,z}), 0)) + f = [sym(1); 2; exp(sym('c'))]; + assert (isequal (divergence(f,{x,y,z}), 0)) ***** test - % values in a matrix - syms x - a = fresnelc([sym(0) sym('oo') x 1]); - b = [sym(0) sym(1)/2 fresnelc(x) fresnelc(sym(1))]; - assert (isequal (a, b)) + % double const + f = [1 2]; + g = sym(0); + assert (isequal (divergence(f, [x y]), g)) + % should fail, calls @double: divergence(f, {x y}), g)) ***** test - % round trip - syms x - f = fresnelc (x); - h = function_handle (f); - A = h (1.1); - B = fresnelc (1.1); - assert (A, B) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/beta.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/beta.m -***** error beta (sym(1), 2, 3) -***** assert (isequal (double (beta (sym(1), 2)), 1/2)) -***** assert (isinf (double (beta (sym(1), 0)))) + % 1D fcn in 2d/3d + f = [x y z]; + assert (isequal (divergence(f), 3)) + assert (isequal (divergence(f, {x,y,z}), 3)) + assert (isequal (divergence(f, [x,y,z]), 3)) ***** test - % round trip - syms x y - f = beta (x, y); - h = function_handle (f); - A = h (1.1, 2.2); - B = beta (1.1, 2.2); - assert (A, B) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/acsc.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/acsc.m -***** error acsc (sym(1), 2) -***** assert (isequaln (acsc (sym(nan)), sym(nan))) + % 2d fcn in 2d/3d + f = sin(exp(x)*y+sinh(z)); + g2 = [diff(f,x); diff(f,y)]; + l2 = diff(g2(1),x) + diff(g2(2),y); + g3 = [diff(f,x); diff(f,y); diff(f,z)]; + l3 = diff(g3(1),x) + diff(g3(2),y) + diff(g3(3),z); + assert (isequal (divergence(g2, {x,y}), l2)) + assert (isequal (divergence(g3, {x,y,z}), l3)) +***** error divergence ([1 2], [sym('x')]) +***** error divergence ([1 2], sym('x'), 42) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/coshint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/coshint.m +***** error coshint (sym(1), 2) +***** xtest + assert (isequaln (coshint (sym(nan)), sym(nan))) +!!!!! known failure +assert (isequaln (coshint (sym (nan)), sym (nan))) failed ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = acsc(x); - f2 = acsc(d); + f1 = coshint(x); + f2 = 0.8378669409802082408947; assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = acsc(A); - f2 = acsc(D); + f1 = coshint(A); + f2 = 0.8378669409802082408947; + f2 = [f2 f2; f2 f2]; assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = acsc (d); - f = acsc (y); + A = coshint (d); + f = coshint (y); h = function_handle (f); B = h (d); assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/expm.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/expm.m -***** test - % scalar - syms x - assert (isequal (expm(x), exp(x))) -***** test - % diagonal - A = [sym(1) 0; 0 sym(3)]; - B = [exp(sym(1)) 0; 0 exp(sym(3))]; - assert (isequal (expm(A), B)) -***** test - % diagonal w/ x - syms x positive - A = [sym(1) 0; 0 x+2]; - B = [exp(sym(1)) 0; 0 exp(x+2)]; - assert (isequal (expm(A), B)) -***** test - % non-diagonal - syms x positive - A = [sym(1) 2; 0 x+2]; - B = expm(A); - C = double(subs(B, x, 4)); - D = expm(double(subs(A, x, 4))); - assert (max (max (abs (C - D))) <= 1e-11) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/erfcinv.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfcinv.m -***** error erfcinv (sym(1), 2) -***** assert (isequaln (erfcinv (sym(nan)), sym(nan))) +5 tests, 4 passed, 1 known failure, 0 skipped +[inst/@sym/sinh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinh.m +***** error sinh (sym(1), 2) +***** assert (isequaln (sinh (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = erfcinv(x); - f2 = erfcinv(d); + f1 = sinh(x); + f2 = sinh(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = erfcinv(A); - f2 = erfcinv(D); + f1 = sinh(A); + f2 = sinh(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = erfcinv (d); - f = erfcinv (y); + A = sinh (d); + f = sinh (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/isequaln.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isequaln.m +[inst/@sym/fix.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/fix.m ***** test - a = sym([1 2]); - b = a; - assert (isequaln (a, b)) - b(1) = 42; - assert (~isequaln (a, b)) + d = 3/2; + x = sym('3/2'); + f1 = fix(x); + f2 = fix(d); + assert (isequal (f1, f2)) ***** test - a = sym([1 2; 3 4]); - b = a; - assert (isequaln (a, b)) - b(1) = 42; - assert (~isequaln (a, b)) + D = [1.1 4.6; -3.4 -8.9]; + A = [sym(11)/10 sym(46)/10; sym(-34)/10 sym(-89)/10]; + f1 = fix(A); + f2 = fix(D); + assert( isequal (f1, f2)) ***** test - a = sym([nan; 2]); - b = a; - assert (isequaln (a, b)) + d = sym(-11)/10; + c = -1; + assert (isequal (fix (d), c)) ***** test - a = sym([nan 2; 3 4]); - b = a; - assert (isequaln (a, b)) + d = sym(-19)/10; + c = -1; + assert (isequal (fix (d), c)) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/mpower.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/mpower.m ***** test - % more than two arrays - a = sym([nan 2 3]); - b = a; - c = a; - assert (isequaln (a, b, c)) - c(1) = 42; - assert (~isequaln (a, b, c)) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/diff.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/diff.m -***** shared x,y,z - syms x y z + syms x + assert(isequal(x^(sym(4)/5), x.^(sym(4)/5))) +***** test + % integer powers of scalars + syms x + assert (isequal (x^2, x*x)) + assert (isequal (x^sym(3), x*x*x)) +***** test + % array ^ integer + syms x y + A = [x 2; y 4]; + assert (isequal (A^2, A*A)) + assert (isequal (simplify(A^3 - A*A*A), [0 0; 0 0])) +***** test + % array ^ rational + Ad = [1 2; 0 3]; + A = sym(Ad); + B = A^(sym(1)/3); + Bd = Ad^(1/3); + assert (max(max(abs(double(B) - Bd))) < 1e-14) +***** test + % non-integer power + A = sym([1 2; 0 3]); + B = A^pi; + C = [1 -1+3^sym(pi); 0 sym(3)^pi]; + assert (isequal (B, C)) +***** test + % matpow + syms n + A = sym([1 2; 3 4]); + B = A^n; + C = 10 + B + B^2; + D = subs(C, n, 1); + E = 10 + A + A^2; + assert (isequal (simplify(D), simplify(E))) +***** test + % matpow, sub in zero gives identity + A = sym([1 2; 0 3]); + syms n; + B = A^n; + C = subs(B, n, 1); + assert (isequal (C, A)) + C = subs(B, n, 0); + assert (isequal (C, sym(eye(2)))) +***** xtest + % scalar^array (e.g., defined by matrix exponential) not implemented in SymPy? + % on 1.0 < SymPy <= 1.5.1, you can form the expression but still cannot eval + syms x + A = [1 2; 3 4]; + B = x^A; + assert (strcmp (regexprep (disp (B, 'flat'), '\s+', ''), 'x**Matrix([[1,2],[3,4]])')) + % sub in and compare to double + Bs = subs(B, x, sym(3)/2); + D1 = double(Bs); + D2 = (3/2)^[1 2; 3 4]; + assert (max(max(abs(D1 - D2))) < 1e-14) +!!!!! known failure +Python exception: TypeError: unsupported operand type(s) for ** or pow(): 'Symbol' and 'MutableDenseMatrix' + occurred at line 2 of the Python code block: + return x**y +***** error + A = sym([1 2; 3 4]); + B = A^A; +9 tests, 8 passed, 1 known failure, 0 skipped +[inst/@sym/eig.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/eig.m ***** test % basic - assert(logical( diff(sin(x)) - cos(x) == 0 )) - assert(logical( diff(sin(x),x) - cos(x) == 0 )) - assert(logical( diff(sin(x),x,x) + sin(x) == 0 )) + A = [1 2; 3 4]; + B = sym(A); + sd = eig(A); + s = eig(B); + s2 = double(s); + assert (norm(sort(s2) - sort(sd)) <= 10*eps) ***** test - % these fail when doubles are not converted to sym - assert(logical( diff(sin(x),x,2) + sin(x) == 0 )) - assert(logical( diff(sym(1),x) == 0 )) - assert(logical( diff(1,x) == 0 )) - assert(logical( diff(pi,x) == 0 )) + % scalars + syms x + a = sym(-10); + assert (isequal (eig(a), a)) + assert (isequal (eig(x), x)) ***** test - % symbolic diff of const (w/o variable) fails in sympy, but we work around - assert (isequal (diff(sym(1)), sym(0))) + % diag, multiplicity + A = diag([6 6 7]); + B = sym(A); + e = eig(B); + assert (isequal (size (e), [3 1])) + assert (sum(logical(e == 6)) == 2) + assert (sum(logical(e == 7)) == 1) ***** test - % nth symbolic diff of const - assert (isequal (diff(sym(1), 2), sym(0))) - assert (isequal (diff(sym(1), sym(1)), sym(0))) + % matrix with symbols + syms x y positive + A = [x+9 y; sym(0) 6]; + s = eig(A); + s = simplify(s); + assert (isequal (s, [x+9; 6]) || isequal (s, [6; x+9])) ***** test - % octave's vector difference still works - assert(isempty(diff(1))) - assert((diff([2 6]) == 4)) + % eigenvects + e = sym([5 5 5 6 7]); + A = diag(e); + [V, D] = eig(A); + assert (isequal (diag(D), e.')) + assert (isequal (V, diag(sym([1 1 1 1 1])))) ***** test - % other forms - f = sin(x); - g = diff(f,x,2); - assert (isequal (diff(f,2), g)) - assert (isequal (diff(f,sym(2)), g)) - g = diff(f,x); - assert (isequal (diff(f), g)) - assert (isequal (diff(f,1), g)) + % alg/geom mult, eigenvects + e = sym([5 5 5 6]); + A = diag(e); + A(1,2) = 1; + [V, D] = eig(A); + assert (isequal (diag(D), e.')) + assert (sum(logical(V(1,:) ~= 0)) == 2) + assert (sum(logical(V(2,:) ~= 0)) == 0) + assert (sum(logical(V(3,:) ~= 0)) == 1) + assert (sum(logical(V(4,:) ~= 0)) == 1) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/numel.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/numel.m ***** test - % old SMT supported (still does?) the 'n' before the 'x' - % we might remove this someday, no longer seems documented in SMT - f = sin(x); - g = diff(f,x,2); - assert (isequal (diff(f,2,x), g)) - assert (isequal (diff(f,sym(2),x), g)) - g = diff(f,x); - assert (isequal (diff(f,1,x), g)) + a = sym([1 2 3]); + assert(numel(a) == 3); ***** test - % matrix - A = [x sin(x); x*y 10]; - B = [1 cos(x); y 0]; - assert(isequal(diff(A,x),B)) + % 2D array + a = sym([1 2 3; 4 5 6]); + assert(numel(a) == 6); ***** test - % bug: use symvar - a = x*y; - b = diff(a); - assert (isequal (b, y)) + % empty + a = sym([]); + assert(numel(a) == 0); +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/bernoulli.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/bernoulli.m +***** error bernoulli (sym(1), 2, 3) +***** assert (isequal (bernoulli (sym(8)), -sym(1)/30)) +***** assert (isequal (bernoulli (sym(9)), sym(0))) +***** test syms x + assert (isequal (bernoulli(3,x), x^3 - 3*x^2/2 + x/2)) ***** test - % bug: symvar should be used on the matrix, not comp-by-comp - a = [x y x*x]; - b = diff(a); - assert (~isequal (b(2), 1)) - assert (isequal (b, [1 0 2*x])) - b = diff(a,1); - assert (~isequal (b(2), 1)) - assert (isequal (b, [1 0 2*x])) -10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@sym/sinh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinh.m -***** error sinh (sym(1), 2) -***** assert (isequaln (sinh (sym(nan)), sym(nan))) + m = sym([0 1; 8 888889]); + A = bernoulli (m); + B = [1 -sym(1)/2; -sym(1)/30 0]; + assert (isequal (A, B)) +***** test + syms x + A = bernoulli ([0; 1], x); + B = [sym(1); x - sym(1)/2]; + assert (isequal (A, B)) +***** test + % round trip + syms n x + f = bernoulli (n, x); + h = function_handle (f, 'vars', [n x]); + A = h (2, 2.2); + B = bernoulli (2, 2.2); + assert (A, B) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/cot.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cot.m +***** error cot (sym(1), 2) +***** assert (isequaln (cot (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = sinh(x); - f2 = sinh(d); + f1 = cot(x); + f2 = cot(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = sinh(A); - f2 = sinh(D); + f1 = cot(A); + f2 = cot(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = sinh (d); - f = sinh (y); + A = cot (d); + f = cot (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/dawson.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/dawson.m -***** test - if (exist ('OCTAVE_VERSION', 'builtin')) - % dawson missing on Matlab, Issue #742 - A = dawson([1 2]); - B = double(dawson(sym([1 2]))); - assert(A, B, -eps) - end -1 test, 1 passed, 0 known failure, 0 skipped [inst/@sym/gammainc.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/gammainc.m ***** assert (isequal (gammainc (sym(0), 1), sym(0))) @@ -6801,164 +7076,64 @@ B = gammainc (1.1, 2.2, 'lower'); assert (A, B) 22 tests, 22 passed, 0 known failure, 0 skipped -[inst/@sym/assumeAlso.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/assumeAlso.m -***** test - syms x - x = assumeAlso(x, 'positive'); - a = assumptions(x); - assert(strcmp(a, 'x: positive')) -***** error - syms x - x = assumeAlso (x, x); -***** test - syms x positive - x = assumeAlso(x, 'integer'); - [tilde, a] = assumptions(x, 'dict'); - assert(a{1}.integer) - assert(a{1}.positive) -***** test - % multiple assumptions - syms x positive - x = assumeAlso(x, 'integer', 'even'); - [tilde, a] = assumptions(x, 'dict'); - assert(a{1}.integer) - assert(a{1}.positive) - assert(a{1}.even) -***** test - % multiple assumptions - syms x integer - x = assumeAlso (x, 'even', 'positive'); - [tilde, a] = assumptions (x, 'dict'); - assert (a{1}.integer) - assert (a{1}.even) - assert (a{1}.positive) -***** test - % has output so avoids workspace - syms x positive - x2 = x; - f = sin(x); - assumeAlso(x, 'integer'); - a = assumptions(x); - assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) - a = assumptions(x2); - assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) - a = assumptions(f); - assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) -***** test - % has no output so does workspace - syms x positive - x2 = x; - f = sin(x); - assumeAlso(x, 'integer'); - a = assumptions(x); - assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) - a = assumptions(x2); - assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) - a = assumptions(f); - assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) -***** error - syms a - assumeAlso (a > 0) -***** test - syms x y - assumeAlso ([x y], 'even') - assert (strcmp (assumptions (x), 'x: even')) - assert (strcmp (assumptions (y), 'y: even')) -***** test - syms x y positive - f = sin (2*x); - assumeAlso ([x y], 'even') - assert (strcmp (assumptions (x), 'x: even, positive') || strcmp (assumptions (x), 'x: positive, even')) - assert (strcmp (assumptions (y), 'y: even, positive') || strcmp (assumptions (y), 'y: positive, even')) - assert (strcmp (assumptions (f), 'x: even, positive') || strcmp (assumptions (f), 'x: positive, even')) -***** test - % with output, original x and y are unchanged - syms x y positive - f = sin (2*x); - [p, q] = assumeAlso ([x y], 'even'); - assert (strcmp (assumptions (x), 'x: positive')) - assert (strcmp (assumptions (y), 'y: positive')) - assert (strcmp (assumptions (f), 'x: positive')) - assert (strcmp (assumptions (p), 'x: even, positive') || strcmp (assumptions (p), 'x: positive, even')) - assert (strcmp (assumptions (q), 'y: even, positive') || strcmp (assumptions (q), 'y: positive, even')) -11 tests, 11 passed, 0 known failure, 0 skipped -[inst/@sym/isallconstant.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isallconstant.m -***** assert (isallconstant([sym(1) 2 3])) -***** test - syms x - assert (~isallconstant([sym(1) x 3])) -***** test - syms x - assert (~isallconstant([sym(1) x; sym(2) 3])) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/expand.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/expand.m -***** test - syms x - assert (logical (x^2 + 6*x + 5 == expand ((x+5)*(x+1)))) - assert (isequal (x^2 + 6*x + 5, expand ((x+5)*(x+1)))) +[inst/@sym/gradient.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/gradient.m +***** shared x,y,z + syms x y z ***** test - % array - syms x - assert (isequal (expand ([x (x+1)*x]), [x x^2+x])) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/chebyshevU.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/chebyshevU.m -***** error chebyshevU (sym(1)) -***** error chebyshevU (sym(1), 2, 3) -***** assert (isequaln (chebyshevU (2, sym(nan)), sym(nan))) -***** shared x - syms x -***** assert(isequal(chebyshevU(0, x), sym(1))) -***** assert(isequal(chebyshevU(1, x), 2*x)) -***** assert(isequal(chebyshevU(2, x), 4*x*x - 1)) -***** assert(isequal(chebyshevU([0 1 2], x), [sym(1) 2*x (4*x*x-1)])) + % 1D + f = x^2; + assert (isequal (gradient(f), diff(f,x))) + assert (isequal (gradient(f,{x}), diff(f,x))) + assert (isequal (gradient(f,[x]), diff(f,x))) + assert (isequal (gradient(f,x), diff(f,x))) ***** test - % round trip - syms n z - f = chebyshevU (n, z); - h = function_handle (f, 'vars', [n z]); - A = h (1.1, 2.2); - B = chebyshevU (1.1, 2.2); - assert (A, B) -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/rhs.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/rhs.m + % const + f = sym(1); + g = sym(0); + assert (isequal (gradient(f), g)) + assert (isequal (gradient(f,x), g)) ***** test - syms x - f = x + 1 == 2*x; - assert (isequal (rhs(f), 2*x)) -***** error - syms x - rhs(x) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/imag.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/imag.m -***** assert (isequal (imag (sym (4) + 3i),3)) + % double const + f = 1; + g = sym(0); + assert (isequal (gradient(f,x), g)) ***** test - syms x y real - z = x + 1i*y; - assert (isequal (imag (z),y)) + % 1D fcn in 2d/3d + f = sin(y); + assert (isequal (gradient(f), diff(f,y))) + assert (isequal (gradient(f, {x,y}), [sym(0); diff(f,y)])) + assert (isequal (gradient(f, [x y]), [sym(0); diff(f,y)])) + assert (isequal (size (gradient(f, {x,y})), [2 1])) + assert (isequal (gradient(f, {x,y,z}), [0; diff(f,y); 0])) + assert (isequal (gradient(f, [x y z]), [0; diff(f,y); 0])) + assert (isequal (size (gradient(f, {x,y,z})), [3 1])) ***** test - syms x y real - Z = [4 x + 1i*y; 1i*y 4 + 3i]; - assert (isequal (imag (Z),[0 y; y 3])) + % grad is column vector + f = sin(y); + assert (isequal (size (gradient(f, {x,y})), [2 1])) + assert (isequal (size (gradient(f, {x,y,z})), [3 1])) + assert (isequal (size (gradient(f, [x y])), [2 1])) + assert (isequal (size (gradient(f, [x;y])), [2 1])) ***** test - syms x real - d = exp (x*i); - assert (isequal (imag (d), sin (x))) + % 2d fcn in 2d/3d + f = sin(exp(x)*y); + g2 = [diff(f,x); diff(f,y)]; + g3 = [diff(f,x); diff(f,y); diff(f,z)]; + assert (isequal (gradient(f), g2)) + assert (isequal (gradient(f, {x,y}), g2)) + assert (isequal (gradient(f, {x,y,z}), g3)) ***** test - % round trip - syms x - d = 3 - 5i; - f = imag (x); - A = imag (d); - h = function_handle (f); - B = h (d); - assert (A, B) -5 tests, 5 passed, 0 known failure, 0 skipped + % 2d fcn in 2d/3d + f = sin(exp(x)*y+sinh(z)); + g2 = [diff(f,x); diff(f,y)]; + g3 = [diff(f,x); diff(f,y); diff(f,z)]; + assert (isequal (gradient(f), g3)) + assert (isequal (gradient(f, {x,y}), g2)) + assert (isequal (gradient(f, {x,y,z}), g3)) +***** error gradient(sym('x'), 42, 42) +***** error gradient([sym('x') sym('x')]) +9 tests, 9 passed, 0 known failure, 0 skipped [inst/@sym/dsolve.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/dsolve.m ***** error dsolve (1, sym('x')) @@ -6995,15 +7170,14 @@ eqn = lhs (eqn) - rhs (eqn); sol2 = subs (sol, C1, -C1); assert (isequal (sol, eqn) || isequal (sol2, eqn)) -Waiting............ +Waiting......... ***** test % Compute solution and classification syms y(x) C1 de = (2*x*y(x) - exp(-2*y(x)))*diff(y(x), x) + y(x) == 0; [sol, classy] = dsolve (de); assert (any (strcmp (classy, '1st_exact'))) -Waiting.... -Waiting........... +Waiting....... ***** test % initial conditions (first order ode) syms y(x) @@ -7143,372 +7317,218 @@ assert (isequal (soln, exact_soln)) end 21 tests, 21 passed, 0 known failure, 0 skipped -[inst/@sym/logical.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/logical.m -***** test - % basics, many others in isAlways.m - assert (logical(true)) - assert (~(logical(false))) -***** test - % numbers to logic? - assert (logical(sym(1))) - assert (logical(sym(-1))) - assert (~logical(sym(0))) -***** test - % eqns, "structurally equivalent" - syms x - e = logical(x == x); - assert ( islogical (e)) - assert (e) - e = logical(x == 1); - assert ( islogical (e)) - assert (~e) -***** test - % eqn could have solutions but are false in general - syms x - e = logical(x^2 == x); - assert ( islogical (e)) - assert (~e) - e = logical(2*x == x); - assert ( islogical (e)) - assert (~e) -***** test - % FIXME: (not sure yet) T/F matrices should stay sym until logical() - a = sym(1); - e = a == a; - assert (isa (e, 'sym')) - assert (islogical (logical (e))) - e = [a == a a == 0 a == a]; - assert (isa (e, 'sym')) - assert (islogical (logical (e))) -***** test - % sym vectors of T/F to logical - a = sym(1); - e = [a == a a == 0 a == a]; - w = logical(e); - assert (islogical (w)) - assert (isequal (w, [true false true])) - e = e'; - w = logical(e); - assert (islogical (w)) - assert (isequal (w, [true; false; true])) -***** test - % sym matrix of T/F to logical - a = sym([1 2 3; 4 5 6]); - b = sym([1 2 0; 4 0 6]); - e = a == b; - w = logical(e); - assert (islogical (w)) - assert (isequal (w, [true true false; true false true])) -***** error - syms x - logical(x); -***** error - logical(sym(nan)) -***** test - % but oo and zoo are non-zero so we call those true - % (SMT errors on these) FIXME - syms oo zoo - assert (logical (oo)) - % assert (logical (zoo)) -***** test - % older Octave (< 4.2) didn't automatically do "if (logical(obj))" - e = sym(true); - if (e) - assert(true); - else - assert(false); - end -***** test - % more of above - e2 = sym(1) == sym(1); - if (e2) - assert(true); - else - assert(false); - end - e3 = sym([1 2]) == sym([1 1]); - if (e3(1)) - assert(true); - else - assert(false); - end -12 tests, 12 passed, 0 known failure, 0 skipped -[inst/@sym/degree.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/degree.m -***** error degree (sym(1), 2, 3) -***** test - syms x - assert (isequal (degree(x^3), 3)) - assert (isequal (degree(x^3 + 6), 3)) -***** test - % specify variable - syms x y - p = x^2 + y*x + 1; - assert (isequal (degree(p), 2)) - assert (isequal (degree(p, x), 2)) - assert (isequal (degree(p, y), 1)) -***** test - syms x a oo - assert (isequal (degree(x^3, a), 0)) - assert (isequal (degree(sym(1), a), 0)) - assert (isequal (degree(sym(0), a), -oo)) -***** xtest - % constant inputs - syms oo - assert (isequal (degree(sym(1)), 0)) - assert (isequal (degree(sym(0)), -oo)) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/norm.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/norm.m -***** assert (isequal (norm(sym(-6)), 6)) -***** test - % 2-norm default - A = [1 2; 3 4]; - n1 = norm (sym (A)); - assert (isequal (n1, sqrt (sqrt (sym(221)) + 15))) - assert (norm (A), double (n1), -eps) -***** test - syms x y real - assert (isequal (norm([x 1; 3 y], 'fro'), sqrt(x^2 + y^2 + 10))) -***** test - syms x real - assert (isequal (norm([x 1], 2), sqrt(x^2 + 1))) -***** test - % test sym vs double ord - syms x - assert (isequal (norm([x 2 1], 1), abs(x) + 3)) - assert (isequal (norm([x 2 1], sym(1)), abs(x) + 3)) - assert (isequal (norm([sym(-3) 2 1], inf), sym(3))) - assert (isequal (norm([sym(-3) 2 1], sym(inf)), sym(3))) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/cumsum.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cumsum.m -***** shared x, y - x = sym ('x'); - y = sym ('y'); -***** error cumsum (x, 1, 2) -***** assert (isequal (cumsum ([-x; -2*x; -3*x]), [-x; -3*x; -6*x])) -***** assert (isequal (cumsum ([x + 2i*y, 2*x + i*y]), [x + 2i*y, 3*x + 3i*y])) -***** assert (isequal (cumsum ([x, 2*x; 3*x, 4*x], 1), [1*x, 2*x; 4*x, 6*x] )) -***** assert (isequal (cumsum ([x, 2*x; 3*x, 4*x], 2), [1*x, 3*x; 3*x, 7*x] )) -***** test cumsum ([x, x], [2, 1]); # ensure behaves like builtin cumsum -***** test cumsum ([x, x], [1, -2]); # ensure behaves like builtin cumsum -***** error cumsum (x, []) -***** error cumsum (x, {1}) -***** error cumsum (x, struct('a', 1)) -***** error cumsum (x, x) -***** error cumsum (x, 0) -***** error cumsum (x, -1) -13 tests, 13 passed, 0 known failure, 0 skipped -[inst/@sym/sin.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sin.m -***** error sin (sym(1), 2) -***** assert (isequaln (sin (sym(nan)), sym(nan))) +[inst/@sym/asinh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/asinh.m +***** error asinh (sym(1), 2) +***** assert (isequaln (asinh (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = sin(x); - f2 = sin(d); + f1 = asinh(x); + f2 = asinh(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = sin(A); - f2 = sin(D); + f1 = asinh(A); + f2 = asinh(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = sin (d); - f = sin (y); + A = asinh (d); + f = asinh (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/function_handle.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/function_handle.m -***** shared x,y,z - syms x y z +[inst/@sym/isrow.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isrow.m +***** assert (isrow (sym ([1]))) +***** assert (isrow (sym ([1 2 3]))) +***** assert (~isrow (sym ([]))) +***** assert (~isrow (sym ([1 2 3]'))) +***** assert (~isrow (sym ([1 2; 3 4]))) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/isinf.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isinf.m +***** shared x,zoo,oo,snan + oo = sym(inf); + zoo = sym('zoo'); + x = sym('x'); + snan = sym(nan); ***** test - % basic test - h = function_handle(2*x); - assert(isa(h, 'function_handle')) - assert(h(3)==6) + % various ops that give inf and nan + assert (isinf(oo)) + assert (isinf(zoo)) + assert (isinf(oo+oo)) + assert (~isinf(oo+zoo)) + assert (~isinf(0*oo)) + assert (~isinf(0*zoo)) + assert (~isinf(snan)) + assert (~isinf(oo-oo)) + assert (~isinf(oo-zoo)) ***** test - % autodetect inputs - h = function_handle(2*x*y, x+y); - [t1, t2] = h(3,5); - assert(t1 == 30 && t2 == 8) + % arrays + assert (isequal( isinf([oo zoo]), [1 1] )) + assert (isequal( isinf([oo 1]), [1 0] )) + assert (isequal( isinf([10 zoo]), [0 1] )) + assert (isequal( isinf([x oo x]), [0 1 0] )) ***** test - % specified inputs - h = function_handle(2*x*y, 'vars', [x y]); - assert(h(3,5)==30) - h = function_handle(2*x*y, x+y, 'vars', [x y]); - [t1, t2] = h(3,5); - assert(t1 == 30 && t2 == 8) + % Must not contain string 'symbol'; these all should make an + % actual infinity. Actually a ctor test, not isinf. + % IIRC, SMT in Matlab 2013b fails. + oo = sym(inf); + assert (isempty (strfind (sympy (oo), 'Symbol'))) + oo = sym(-inf); + assert (isempty (strfind (sympy (oo), 'Symbol'))) + oo = sym('inf'); + assert (isempty (strfind (sympy (oo), 'Symbol'))) + oo = sym('-inf'); + assert (isempty (strfind (sympy (oo), 'Symbol'))) + oo = sym('Inf'); + assert (isempty (strfind (sympy (oo), 'Symbol'))) ***** test - % cell arrays for vars list - h = function_handle(2*x*y, x+y, 'vars', {x y}); - [t1, t2] = h(3,5); - assert(t1 == 30 && t2 == 8) - h = function_handle(2*x*y, x+y, 'vars', {'x' 'y'}); - [t1, t2] = h(3,5); - assert(t1 == 30 && t2 == 8) + % ops with infinity shouldn't collapse + syms x oo zoo + y = x + oo; + assert (~isempty (strfind (lower (sympy (y)), 'add') )) + y = x - oo; + assert (~isempty (strfind (lower (sympy (y)), 'add') )) + y = x - zoo; + assert (~isempty (strfind (lower (sympy (y)), 'add') )) + y = x*oo; + assert (~isempty (strfind (lower (sympy (y)), 'mul') )) ***** test - % cell arrays specfies order, overriding symvar order - h = function_handle(x*y, 12/y, 'vars', {y x}); - [t1, t2] = h(3, 6); - assert(t1 == 18 && t2 == 4) - h = function_handle(x*y, 12/y, 'vars', [y x]); - [t1, t2] = h(3, 6); - assert(t1 == 18 && t2 == 4) + % ops with infinity are not necessarily infinite + syms x oo zoo + y = x + oo; + assert(~isinf(y)) % SMT 2014a says "true", I disagree + y = x - zoo; + assert(~isinf(y)) + y = x*oo; + assert(~isinf(y)) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/ismember.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ismember.m +***** assert (ismember (2, interval(sym(0),2))) +***** assert (~ismember (3, interval(sym(0),2))) ***** test - % cell arrays specfies order, overriding symvar order - h = function_handle(x*y, 12/y, 'vars', {y x}); - [t1, t2] = h(3, 6); - assert(t1 == 18 && t2 == 4) - h = function_handle(x*y, 12/y, 'vars', [y x]); - [t1, t2] = h(3, 6); - assert(t1 == 18 && t2 == 4) + % something in a matrix + syms x + A = [1 x; sym(pi) 4]; + assert (ismember (sym(pi), A)) + assert (ismember (x, A)) + assert (~ismember (2, A)) ***** test - % Functions with different names in Sympy. - f = abs(x); % becomes Abs(x) - h = function_handle(f); - assert(h(-10) == 10) - f = ceil(x); - h = function_handle(f); - assert(h(10.1) == 11) + % set + syms x + S = finiteset(2, sym(pi), x); + assert (ismember (x, S)) ***** test - % 'file' with empty filename returns handle - h = function_handle(2*x*y, 'file', ''); - assert(isa(h, 'function_handle')) - assert(h(3,5)==30) - h = function_handle(2*x*y, 'vars', {x y}, 'file', ''); - assert(isa(h, 'function_handle')) - assert(h(3,5)==30) + % set with positive symbol + syms p positive + S = finiteset(2, sym(pi), p); + assert (~ismember (-1, S)) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/lambertw.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/lambertw.m ***** test - % output to disk - fprintf('\n') - if (exist ('OCTAVE_VERSION', 'builtin')) - temp_file = tempname('', 'oct_'); - else - temp_file = tempname(); - end - % allow loading function from temp_file - [temp_path, ans, ans] = fileparts(temp_file); - addpath(temp_path); - f = function_handle(2*x*y, 2^x, 'vars', {x y z}, 'file', temp_file); - assert( isa(f, 'function_handle')) - addpath(temp_path); % Matlab 2014a needs this? - [a,b] = f(10,20,30); - assert (isnumeric (a) && isnumeric (b)) - assert (a == 400) - assert (b == 1024) - if (exist ('OCTAVE_VERSION', 'builtin')) - assert (unlink([temp_file '.m']) == 0) - else - delete ([temp_file '.m']) - end - % remove temp_path from load path - rmpath(temp_path); + % W(x)*exp(W(x)) == x + syms x + T = lambertw(x)*exp(lambertw(x)); + T = double (subs (T, x, 10)); + assert (isequal (T, 10)); +***** test + % k, x not x, k to match SMT + syms x + T = lambertw(2, x)*exp(lambertw(2, x)); + T = double (subs (T, x, 10)); + assert (abs(T - 10) < 1e-15) +***** assert (isequal (lambertw(sym(0)), sym(0))) +***** assert ( isequal (lambertw (-1/exp(sym(1))), -sym(1))) +***** assert ( isequal (lambertw (0, -1/exp(sym(1))), -sym(1))) +***** assert ( isequal (lambertw (-1, -1/exp(sym(1))), -sym(1))) +***** xtest + % W(x)*exp(W(x)) == x; FIXME: a failure in SymPy? + syms x + T = simplify(lambertw(x)*exp(lambertw(x))); + assert (isequal (T, x)) +!!!!! known failure +assert (isequal (T, x)) failed +***** assert (abs (lambertw(pi) - double(lambertw(sym(pi)))) < 5*eps) +***** assert (abs (lambertw(-1, 5) - double(lambertw(-1, sym(5)))) < 5*eps) +***** assert (abs (lambertw(2, 2) - double(lambertw(2, sym(2)))) < 5*eps) +***** test + % round trip + syms x k + A = lambertw (5); + f = lambertw (x); + h = function_handle (f); + B = h (5); + assert (A, B) -Wrote file /tmp/oct_AgNgTI.m. + A = lambertw (3, 5); + f = lambertw (k, x); + h = function_handle (f); + B = h (3, 5); + assert (A, B) +11 tests, 10 passed, 1 known failure, 0 skipped +[inst/@sym/minus.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/minus.m ***** test - % output to disk: also works with .m specified - if (exist ('OCTAVE_VERSION', 'builtin')) - temp_file = [tempname('', 'oct_') '.m']; - else - temp_file = [tempname() '.m']; - end - % allow loading function from temp_file - [temp_path, ans, ans] = fileparts(temp_file); - addpath(temp_path); - f = function_handle(2*x*y, 2^x, 'vars', {x y z}, 'file', temp_file); - assert( isa(f, 'function_handle')) - addpath(temp_path); % Matlab 2014a needs this? - [a,b] = f(10,20,30); - assert (isnumeric (a) && isnumeric (b)) - assert (a == 400) - assert (b == 1024) - if (exist ('OCTAVE_VERSION', 'builtin')) - assert (unlink(temp_file) == 0) - else - delete (temp_file) - end - % remove temp_path from load path - rmpath(temp_path); -Wrote file /tmp/oct_T5NsQO.m. + % scalar + syms x + assert (isa (x-1, 'sym')) + assert (isa (x-x, 'sym')) + assert (isequal (x-x, sym(0))) ***** test - % non-scalar outputs - H = [x y z]; - M = [x y; z 16]; - V = [x;y;z]; - h = function_handle(H, M, V); - [t1,t2,t3] = h(1,2,3); - assert(isequal(t1, [1 2 3])) - assert(isequal(t2, [1 2; 3 16])) - assert(isequal(t3, [1;2;3])) + % matrices + D = [0 1; 2 3]; + A = sym(D); + DZ = D - D; + assert (isequal ( A - D , DZ )) + assert (isequal ( A - A , DZ )) + assert (isequal ( D - A , DZ )) + assert (isequal ( A - 2 , D - 2 )) + assert (isequal ( 4 - A , 4 - D )) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/fourier.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/fourier.m ***** test - % non-scalar outputs in .m files - H = [x y z]; - M = [x y; z 16]; - V = [x;y;z]; - if (exist ('OCTAVE_VERSION', 'builtin')) - temp_file = tempname('', 'oct_'); - else - temp_file = tempname(); - end - % allow loading function from temp_file - [temp_path, ans, ans] = fileparts(temp_file); - addpath(temp_path); - h = function_handle(H, M, V, 'vars', {x y z}, 'file', temp_file); - assert( isa(h, 'function_handle')) - addpath(temp_path); % Matlab 2014a needs this? - [t1,t2,t3] = h(1,2,3); - assert(isequal(t1, [1 2 3])) - assert(isequal(t2, [1 2; 3 16])) - assert(isequal(t3, [1;2;3])) - if (exist ('OCTAVE_VERSION', 'builtin')) - assert (unlink([temp_file '.m']) == 0) - else - delete ([temp_file '.m']) - end - % remove temp_path from load path - rmpath(temp_path); -Wrote file /tmp/oct_x8ig0h.m. + % matlab SMT compatibiliy for arguments + syms r x u w v + Pi=sym('pi'); + assert(logical( fourier(exp(-x^2)) == sqrt(Pi)/exp(w^2/4) )) + assert(logical( fourier(exp(-w^2)) == sqrt(Pi)/exp(v^2/4) )) + assert(logical( fourier(exp(-r^2),u) == sqrt(Pi)/exp(u^2/4) )) + assert(logical( fourier(exp(-r^2),r,u) == sqrt(Pi)/exp(u^2/4) )) ***** test - % order of outputs is lexiographic - syms a A x y - f = y + 10*a + 100*x + 1000*A; - h = function_handle(f); - assert (h(1, 2, 3, 4) == 1000 + 20 + 300 + 4) + % basic tests + syms x w + assert(logical( fourier(exp(-abs(x))) == 2/(w^2 + 1) )) + assert(logical( fourier(x*exp(-abs(x))) == -(w*4*1i)/(w^4 + 2*w^2 + 1) )) ***** test - % https://github.com/cbm755/octsympy/issues/854 - f = function_handle (x + 1i*sqrt (sym(3))); - assert (f (1), complex (1, sqrt (3)), -eps) -14 tests, 14 passed, 0 known failure, 0 skipped -[inst/@sym/chebyshevT.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/chebyshevT.m -***** error chebyshevT (sym(1)) -***** error chebyshevT (sym(1), 2, 3) -***** assert (isequaln (chebyshevT (2, sym(nan)), sym(nan))) -***** shared x - syms x -***** assert(isequal(chebyshevT(0, x), sym(1))) -***** assert(isequal(chebyshevT(1, x), x)) -***** assert(isequal(chebyshevT(2, x), 2*x*x - 1)) -***** assert(isequal(chebyshevT([0 1 2], x), [sym(1) x (2*x*x-1)])) + % Dirac delta tests + syms x w + Pi=sym('pi'); + assert(logical( fourier(dirac(x-2)) == exp(-2*1i*w) )) + assert (logical( fourier(sym(2), x, w) == 4*Pi*dirac(w) )) ***** test - % round trip - syms n z - f = chebyshevT (n, z); - h = function_handle (f, 'vars', [n z]); - A = h (1.1, 2.2); - B = chebyshevT (1.1, 2.2); - assert (A, B) -8 tests, 8 passed, 0 known failure, 0 skipped + % advanced test + syms x w c d + Pi=sym('pi'); + F=Pi*(dirac(w-c)+dirac(w+c))+2*Pi*1i*(dirac(w+3*d)-dirac(w-3*d))+2/(w^2+1); + assert(logical( fourier(cos(c*x)+2*sin(3*d*x)+exp(-abs(x))) == expand(F) )) +***** xtest + % Differential operator to algebraic + % SymPy cannot evaluate? (Issue #170) + syms x w f(x) + assert(logical( fourier(diff(f(x),x),x,w) == -1i*w*fourier(f(x),x,w) )) +!!!!! known failure +assert (logical (fourier (diff (f (x), x), x, w) == -1i * w * fourier (f (x), x, w))) failed +5 tests, 4 passed, 1 known failure, 0 skipped [inst/@sym/min.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/min.m ***** test @@ -7699,330 +7719,413 @@ a = max([x -2 6]); assert (isequal (a, 6)) 21 tests, 21 passed, 0 known failure, 0 skipped -[inst/@sym/dot.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/dot.m -***** error dot (sym(1), 2, 3) +[inst/@sym/conj.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/conj.m ***** test - a = sym([1; 1; 0]); - b = sym([1; 2; 4]); - c = dot(a, b); - assert (isequal (c, sym(3))) + a = sym(6); + b = sym(5i); + assert (isequal (conj(a), a)) + assert (isequal (conj(b), -b)) + assert (isequal (conj(a+b), a-b)) ***** test syms x - a = sym([x; 0; 0]); - b = sym([0; 1; 0]); - c = dot(a, b); - assert (isequal (c, sym(0))) + assert (isequal (conj(conj(x)), x)) ***** test - assert (isequal (dot (sym([1 i]), sym([i 2])), sym(-i))) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/laguerreL.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/laguerreL.m -***** shared x + syms x real + assert (isequal (conj(x), x)) +***** test + % array syms x -***** assert (isequal (laguerreL(0, x), sym(1))) -***** assert (isequal (laguerreL(1, x), 1-x)) -***** assert (isequal (laguerreL(2, x), x^2/2 - 2*x + 1)) -***** error laguerreL(x) -***** error laguerreL(1, 2, x, 3) -***** shared + A = [x 6+1i; sym(1) x+2i]; + B = [conj(x) 6-1i; sym(1) conj(x)-2i]; + assert (isequal (conj(A), B)) ***** test - if (pycall_sympy__ ('return Version(spver) > Version("1.4")')) + % true/false + t = sym(true); + f = sym(false); + assert (isequal ( conj(t), t)) + assert (isequal ( conj(f), f)) +***** test + % round trip syms x - assert (isequal (laguerreL (-3, x), exp(x)*(x^2/2 + 2*x + 1))) + d = 3 - 5i; + f = conj (x); + A = conj (d); + h = function_handle (f); + B = h (d); + assert (A, B) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/all.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/all.m +***** test + % matrix + a = [0 3; 1 2]; + s = sym (a); + assert (isequal (all (s), all (a))) + assert (isequal (all (s,1), all (a,1))) + assert (isequal (all (s,2), all (a,2))) +***** test + % vector + a = [1 2 3]; + s = sym (a); + assert (isequal (all (s), all (a))) + assert (isequal (all (s,1), all (a,1))) + assert (isequal (all (s,2), all (a,2))) +***** test + % should fail on symbols + syms x + s = [1 2 x]; + try + all (s) + waserr = false; + catch + waserr = true; end + assert (waserr) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/isconstant.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isconstant.m ***** test - syms x n - L = laguerreL([2 n], x); - expected = [laguerreL(2, x) laguerreL(n, x)]; - assert (isequal (L, expected)) + syms x + A = [x 2 3]; + B = [false true true]; + assert (isequal (isconstant (A), B)) +/usr/lib/python3/dist-packages/sympy/matrices/common.py:2058: SymPyDeprecationWarning: + +non-Expr objects in a Matrix is deprecated. Matrix represents +a mathematical matrix. To represent a container of non-numeric +entities, Use a list of lists, TableForm, NumPy array, or some +other data structure instead. + +See https://docs.sympy.org/latest/explanation/active-deprecations.html#deprecated-non-expr-in-matrix +for details. + +This has been deprecated since SymPy version 1.9. It +will be removed in a future version of SymPy. + + return self._eval_applyfunc(f) ***** test - syms x y - L = laguerreL([1; 2], [x; y]); - expected = [laguerreL(1, x); laguerreL(2, y)]; - assert (isequal (L, expected)) + syms x + A = [x 2; 3 x]; + B = [false true; true false]; + assert (isequal (isconstant (A), B)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/besselk.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselk.m ***** test - syms x n - assert (isequal (laguerreL(n, 0, x), laguerreL(n, x))) -***** shared x, y, n - syms x y n -***** assert (isequal (laguerreL([1 n], 0, x), laguerreL([1 n], x))) + X = [1 2 3; 4 5 6]; + ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; + n = double(ns); + A = double(besselk(ns, X)); + B = besselk(n, X); + assert (all (all (abs (A - B) < 2*eps*abs(A)))) ***** test - L = laguerreL([1; n], [pi; 0], [x; y]); - expected = [laguerreL(1, pi, x); laguerreL(n, 0, y)]; - assert (isequal (L, expected)) + % roundtrip + syms x + A = besselk(2, 10); + q = besselk(2, x); + h = function_handle(q); + B = h(10); + assert (abs (A - B) <= eps*abs(A)) +***** error besselk(sym('x')) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/lt.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/lt.m ***** test - L = laguerreL([1 n], [pi 0], x); - expected = [laguerreL(1, pi, x) laguerreL(n, 0, x)]; - assert (isequal (L, expected)) + % simple + x = sym(1); y = sym(1); e = x < y; + assert (~logical (e)) + x = sym(1); y = sym(2); e = x < y; + assert (logical (e)) ***** test - L = laguerreL([1 n], pi, [x y]); - expected = [laguerreL(1, pi, x) laguerreL(n, pi, y)]; - assert (isequal (L, expected)) + % mix sym and double + x = sym(1); y = 1; e = x < y; + assert (~logical (e)) + x = sym(1); y = 2; e = x < y; + assert (logical (e)) + x = 1; y = sym(1); e = x < y; + assert (~logical (e)) + x = 1; y = sym(2); e = x < y; + assert (logical (e)) ***** test - L = laguerreL(1, [pi 0], [x y]); - expected = [laguerreL(1, pi, x) laguerreL(1, 0, y)]; - assert (isequal (L, expected)) + % Type of the output is sym or logical? + % FIXME: in current version, they are sym + x = sym(1); y = sym(1); e1 = x < y; + x = sym(1); y = sym(2); e2 = x < y; + %assert (islogical (e1)) + %assert (islogical (e2)) + assert (isa (e1, 'sym')) + assert (isa (e2, 'sym')) ***** test - L = laguerreL([1 n], pi, x); - expected = [laguerreL(1, pi, x) laguerreL(n, pi, x)]; - assert (isequal (L, expected)) + % ineq w/ symbols + syms x y + e = x < y; + assert (~islogical (e)) + assert (isa (e, 'sym')) ***** test - L = laguerreL(1, [pi 0], x); - expected = [laguerreL(1, pi, x) laguerreL(1, 0, x)]; - assert (isequal (L, expected)) + % array -- array + syms x + a = sym([1 3 3 2*x]); + b = sym([2 x 3 10]); + e = a < b; + assert (isa (e, 'sym')) + assert (logical (e(1))) + assert (isa (e(2), 'sym')) + assert (isequal (e(2), 3 < x)) + assert (~logical (e(3))) + assert (isa (e(4), 'sym')) + assert (isequal (e(4), 2*x < 10)) ***** test - L = laguerreL(1, pi, [x y]); - expected = [laguerreL(1, pi, x) laguerreL(1, pi, y)]; - assert (isequal (L, expected)) + % array -- scalar + syms x oo + a = sym([1 x oo]); + b = sym(3); + e = a < b; + assert (isa (e, 'sym')) + assert (logical (e(1))) + assert (isa (e(2), 'sym')) + assert (isequal (e(2), x < 3)) + assert (~logical (e(3))) ***** test - % round trip - f = laguerreL (n, x); - h = function_handle (f); - A = h (1, 3.2); - B = laguerreL (1, 3.2); - assert (A, B) - A = h ([1 2], [3.3 4.4]); - B = laguerreL ([1 2], [3.3 4.4]); - assert (A, B) -***** error - % round trip - f = laguerreL (n, y, x); - h = function_handle (f); -19 tests, 19 passed, 0 known failure, 0 skipped -[inst/@sym/fortran.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/fortran.m -***** shared x,y,z - syms x y z + % scalar -- array + syms x oo + a = sym(1); + b = sym([2 x -oo]); + e = a < b; + assert (isa (e, 'sym')) + assert (logical (e(1))) + assert (isa (e(2), 'sym')) + assert (isequal (e(2), 1 < x)) + assert (~logical (e(3))) ***** test - % basic test - f = x*sin(y) + abs(z); - source = fortran(f); - expected = ' x*sin(y) + abs(z)'; - s1 = strrep (expected, 'abs', 'Abs'); - assert (strcmp (source, expected) || strcmp (source, s1)) + % ineq w/ nan + syms x + snan = sym(nan); + e = x < snan; + assert (~logical (e)) + e = snan < x; + assert (~logical (e)) + b = [sym(0) x]; + e = b < snan; + assert (isequal (e, [false false])) ***** test - % output test - f = x*sin(y) + abs(z); - [F,H] = fortran(f, 'file', '', 'show_header', false); - expected_h_code = sprintf('\ninterface\nREAL*8 function myfun(x, y, z)\nimplicit none\nREAL*8, intent(in) :: x\nREAL*8, intent(in) :: y\nREAL*8, intent(in) :: z\nend function\nend interface\n\n'); - expected_f_code = sprintf('\nREAL*8 function myfun(x, y, z)\nimplicit none\nREAL*8, intent(in) :: x\nREAL*8, intent(in) :: y\nREAL*8, intent(in) :: z\n\nmyfun = x*sin(y) + abs(z)\n\nend function\n'); - assert(strcmp(F.name, 'file.f90')) - assert(strcmp(H.name, 'file.h')) - %disp(expected_f_code); disp(F.code) - s1 = strrep (expected_f_code, 'abs', 'Abs'); - s2 = strrep (expected_f_code, sprintf ('\n'), sprintf ('\r\n')); - s3 = strrep (s2, 'abs', 'Abs'); - s4 = strrep (expected_h_code, sprintf ('\n'), sprintf ('\r\n')); - assert (strcmp (F.code, expected_f_code) || strcmp (F.code, s1) || strcmp (F.code, s2) || strcmp (F.code, s3)) - assert (strcmp (H.code, expected_h_code) || strcmp (H.code, s4)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/display.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/display.m + % oo + syms oo x + e = oo < x; + assert (isa (e, 'sym')) + assert (strcmp (strtrim (disp (e, 'flat')), 'oo < x')) ***** test - assert(true) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/isscalar.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isscalar.m -***** assert(isscalar(sym('x'))) + % sympy true matrix + a = sym([1 3 3]); + b = sym([2 4 1]); + e = a < b; + %assert (~isa (e, 'sym')) + %assert (islogical (e)) + assert (isequal (e, [true true false])) ***** test - a = sym([1 2 3]); - assert(~isscalar(a)) -***** assert(~isscalar(sym([]))) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/numel.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/numel.m + % oo, finite real variables + syms oo + syms z real + assumeAlso(z, 'finite') + e = -oo < z; + assert (isequal (e, sym(true))) + e = z < oo; + assert (isequal (e, sym(true))) ***** test - a = sym([1 2 3]); - assert(numel(a) == 3); + % -oo, positive var (known failure w/ sympy 0.7.6.x) + syms oo + syms z positive + e = -oo < z; + assert (logical (e)) + assert (isequal (e, sym(true))) ***** test - % 2D array - a = sym([1 2 3; 4 5 6]); - assert(numel(a) == 6); + % positive + syms z positive + e = -1 < z; + assert (isequal (e, sym(true))) ***** test - % empty - a = sym([]); - assert(numel(a) == 0); -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/zeta.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/zeta.m -***** error zeta (sym(1), 2, 3) -***** assert (isequaln (zeta (sym(nan)), sym(nan))) + syms oo + z = sym('z', 'negative'); + e = z < oo; + assert (isequal (e, sym(true))) +14 tests, 14 passed, 0 known failure, 0 skipped +[inst/@sym/cosint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cosint.m +***** error cosint (sym(1), 2) +***** xtest + assert (isequaln (cosint (sym(nan)), sym(nan))) +!!!!! known failure +assert (isequaln (cosint (sym (nan)), sym (nan))) failed +***** shared x, d + d = 1; + x = sym('1'); ***** test - f1 = zeta (sym(2)); - f2 = pi^2/6; - assert (double (f1), f2, -1e-15) + f1 = cosint(x); + f2 = 0.3374039229009681346626; + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - A = sym([0 2; 4 6]); - f1 = zeta (A); - f2 = [-1/2 pi^2/6; pi^4/90 pi^6/945]; + D = [d d; d d]; + A = [x x; x x]; + f1 = cosint(A); + f2 = 0.3374039229009681346626; + f2 = [f2 f2; f2 f2]; assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - f = zeta (y); + A = cosint (d); + f = cosint (y); h = function_handle (f); - A = zeta (2); - B = h (2); + B = h (d); assert (A, B, -eps) +5 tests, 4 passed, 1 known failure, 0 skipped +[inst/@sym/ellipke.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipke.m +***** error ellipke (sym(1), 2) ***** test - syms x - assert (isequal (zeta (0, x), zeta(x))) -***** test - % ensure its the nth deriv wrt x, not the n deriv - syms x n - F = zeta (n, x); - F = subs(F, n, 3); - assert (isequal (F, diff (zeta (x), x, x, x))) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/mtimes.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/mtimes.m + for i = 2:10 + [K E] = ellipke (sym (1)/i); + [k e] = ellipke (1/i); + assert (double ([K E]), [k e], 2*eps) + end +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/adjoint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/adjoint.m ***** test - % scalar syms x - assert (isa (x*2, 'sym')) - assert (isequal (2*sym(3), sym(6))) - assert (isequal (sym(2)*3, sym(6))) + A = [x x^2; x^3 x^4]; + B = [x^4 -x^2; -x^3 x]; + assert( isequal( adjoint(A), B )) +***** test syms x + assert( isequal( adjoint(x), 1)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/besseli.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/besseli.m ***** test - % matrix-scalar - D = [0 1; 2 3]; - A = sym(D); - assert (isa (2*A, 'sym')) - assert (isequal ( 2*A , 2*D )) - assert (isequal ( A*2 , 2*D )) + X = [1 2 3; 4 5 6]; + ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; + n = double(ns); + A = double(besseli(ns, X)); + B = besseli(n, X); + assert (all (all (abs (A - B) < 100*eps*abs(A)))) ***** test - % matrix-matrix - D = [0 1; 2 3]; - A = sym(D); - assert (isa (A*A, 'sym')) - assert (isequal ( A*A , D*D )) + % roundtrip + syms x + A = besseli(2, 10); + q = besseli(2, x); + h = function_handle(q); + B = h(10); + assert (abs (A - B) <= eps*abs(A)) +***** error besseli(sym('x')) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/repmat.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/repmat.m +[inst/@sym/latex.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/latex.m ***** test - % simple syms x - A = [x x x; x x x]; - assert (isequal (repmat(x, 2, 3), A)) -***** test - % block cf double - A = [1 2 3; 4 5 6]; - B = sym(A); - C = repmat(A, 2, 3); - D = repmat(B, 2, 3); - assert (isequal (C, D)) -***** test - % empty - A = repmat(sym([]), 2, 3); - assert (isempty(A)); - assert (isequal (size(A), [0 0])) + y = sin(x); + assert (strcmp (latex (y), '\sin{\left(x \right)}')) +***** assert (strcmp (latex (exp (sym('x'))), 'e^{x}')) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/subsindex.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/subsindex.m ***** test - % more empties - A = repmat(sym(pi), [0 0]); - assert (isequal (size(A), [0 0])) - A = repmat(sym(pi), [0 3]); - assert (isequal (size(A), [0 3])) - A = repmat(sym(pi), [2 0]); - assert (isequal (size(A), [2 0])) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/laplacian.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/laplacian.m -***** shared x,y,z - syms x y z + i = sym(1); + a = 7; + assert(a(i)==a); + i = sym(2); + a = 2:2:10; + assert(a(i)==4); ***** test - % 1D - f = x^2; - g = diff(f,x,x); - assert (isequal (laplacian(f), g)) - assert (isequal (laplacian(f,{x}), g)) - assert (isequal (laplacian(f,[x]), g)) - assert (isequal (laplacian(f,x), g)) + i = sym([1 3 5]); + a = 1:10; + assert( isequal (a(i), [1 3 5])) ***** test - % const - f = sym(1); - g = sym(0); - assert (isequal (laplacian(f), g)) - assert (isequal (laplacian(f,x), g)) - f = sym('c'); - assert (isequal (laplacian(f,x), g)) + i = sym([1 3 5]); + a = sym(1:10); + assert( isequal (a(i), sym([1 3 5]))); ***** test - % double const - f = 1; - g = sym(0); - assert (isequal (laplacian(f,x), g)) + % should be an error if it doesn't convert to double + syms x + a = 1:10; + try + a(x) + waserr = false; + catch + waserr = true; + end + assert(waserr) ***** test - % 1D fcn in 2d/3d - f = sin(2*y); - g = -4*f; - assert (isequal (laplacian(f), g)) - assert (isequal (laplacian(f, {x,y}), g)) - assert (isequal (laplacian(f, {x,y,z}), g)) + syms x + assert (isequal (x(sym (true)), x)) + assert (isequal (x(sym (false)), sym ([]))) ***** test - % 2d fcn in 2d/3d - f = sin(exp(x)*y); - g = diff(f,x,x) + diff(f,y,y); - assert (isequal (laplacian(f), g)) - assert (isequal (laplacian(f, {x,y}), g)) + x = 6; + assert (isequal (x(sym (true)), 6)) + assert (isequal (x(sym (false)), [])) ***** test - % 2d fcn in 2d/3d - f = sin(exp(x)*y+sinh(z)); - gr2 = gradient(f, {x,y}); - divgr2 = divergence(gr2, {x,y}); - l2 = laplacian(f,{x,y}); - gr3 = gradient(f, {x,y,z}); - divgr3 = divergence(gr3, {x,y,z}); - l3 = laplacian(f,{x,y,z}); - assert (isAlways (l2 == divgr2)) - assert (isAlways (l3 == divgr3)) -Waiting...... -Waiting................... -***** error laplacian(sym('x'), sym('x'), 42) -***** error laplacian([sym('x'), sym('x')]) -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/sec.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sec.m -***** error sec (sym(1), 2) -***** assert (isequaln (sec (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + a = sym([10 12 14]); + assert (isequal (a(sym ([true false true])), a([1 3]))) + assert (isequal (a(sym ([false false false])), sym (ones(1,0)))) ***** test - f1 = sec(x); - f2 = sec(d); - assert( abs(double(f1) - f2) < 1e-15 ) + a = [10 11; 12 13]; + p = [true false; true true]; + assert (isequal (a(sym (p)), a(p))) + p = [false false false]; + assert (isequal (a(sym (p)), a(p))) +***** error + a = [10 12]; + I = [sym(true) 2]; + b = a(I); +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/airy.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/airy.m ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = sec(A); - f2 = sec(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + syms z + a = airy(0, z); + ap = airy(1, z); + assert (isequal (diff (a), ap)) + assert (isequal (diff (ap), z*a)) ***** test - % round trip - y = sym('y'); - A = sec (d); - f = sec (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/rank.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/rank.m + syms z + b = airy(2, z); + bp = airy(3, z); + assert (isequal (diff (b), bp)) + assert (isequal (diff (bp), z*b)) ***** test - A = sym([1 2; 3 4]); - assert (rank(A) == 2); + % default to k=0 + syms z + a = airy(0, z); + a2 = airy(z); + assert (isequal (a, a2)) +***** error airy(0, sym('x'), 2) +***** error airy(4, sym('z')) +***** error airy(-1, sym('z')) ***** test - A = sym([1 2 3; 3 4 5]); - assert (rank(A) == 2); + % symbolic k + syms z + b1 = airy(2, z); + b2 = airy(sym(2), z); + assert (isequal (b1, b2)) ***** test - A = sym([1 2; 1 2]); - assert (rank(A) == 1); + % doubles, relative error + X = [1 2 pi; 4i 5 6+6i]; + Xs = sym(X); + for k = 0:3 + A = double(airy(k, Xs)); + B = airy(k, X); + assert (all (all (abs(A - B) < 500*eps*abs(A)))) + end ***** test - A = sym([1 2; 3 4]); - assert (rank(A) == 2); -***** assert (rank(sym(1)) == 1); -***** assert (rank(sym(0)) == 0); -***** assert (rank(sym('x', 'positive')) == 1); -7 tests, 7 passed, 0 known failure, 0 skipped + % round-trip + syms x + for k = 0:3 + A = airy(k, 10); + q = airy(k, x); + h = function_handle(q); + B = h(10); + assert (abs(A-B) < 500*eps*abs(A)) + end +9 tests, 9 passed, 0 known failure, 0 skipped [inst/@sym/vertcat.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/vertcat.m ***** test @@ -8107,1267 +8210,1263 @@ B = simplify (A); assert (isequal ([B; A], [A; B])) 11 tests, 10 passed, 1 known failure, 0 skipped -[inst/@sym/erf.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/erf.m -***** error erf (sym(1), 2) -***** assert (isequaln (erf (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); +[inst/@sym/sort.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sort.m +***** error sort (sym(1), 2) ***** test - f1 = erf(x); - f2 = erf(d); - assert( abs(double(f1) - f2) < 1e-15 ) + f = [sym(1), sym(0)]; + expected = sym([0, 1]); + assert (isequal (sort(f), expected)) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = erf(A); - f2 = erf(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + f = [sym(1)]; + expected = sym(1); + assert (isequal (sort(f), expected)) +***** test + f = [sym(3), sym(2), sym(6)]; + s = sort(f); + expected_s = sym([2, 3, 6]); + assert (isequal (s, expected_s)) +***** test + f = [sym(pi), sin(sym(2)), sqrt(sym(6))]; + s = sort(f); + expected_s = sym([sin(sym(2)), sqrt(sym(6)), sym(pi)]); + assert (isequal (s, expected_s)) +***** test + f = [sym(1), sym(2); sym(2), sym(pi); sym(pi), sym(1)]; + s = sort(f); + expected_s = ([sym(1), sym(1); sym(2), sym(2); sym(pi), sym(pi)]); + assert (isequal (s, expected_s)) +***** assert (isequal (sort(sym([])), sym([]))) +***** error sort([sym('x') 1]) +***** test + % but with assumptions, symbols can be sorted + p = sym('p', 'positive'); + n = sym('n', 'negative'); + expected_s = [n p]; + s = sort ([p n]); + assert (isequal (s, expected_s)) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/imag.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/imag.m +***** assert (isequal (imag (sym (4) + 3i),3)) +***** test + syms x y real + z = x + 1i*y; + assert (isequal (imag (z),y)) +***** test + syms x y real + Z = [4 x + 1i*y; 1i*y 4 + 3i]; + assert (isequal (imag (Z),[0 y; y 3])) +***** test + syms x real + d = exp (x*i); + assert (isequal (imag (d), sin (x))) ***** test % round trip - y = sym('y'); - A = erf (d); - f = erf (y); + syms x + d = 3 - 5i; + f = imag (x); + A = imag (d); h = function_handle (f); B = h (d); - assert (A, B, -eps) + assert (A, B) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/uplus.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/uplus.m +[inst/@sym/atand.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/atand.m +***** error atand (sym(1), 2) +***** assert (isequaln (atand (sym(nan)), sym(nan))) ***** test - syms x - assert (isa (+x, 'sym')) - assert (isequal (+x, x)) + f1 = atand (sym(1)/2); + f2 = atand (1/2); + assert (double (f1), f2, -eps) ***** test - A = sym([0 -1 inf]); - assert( isequal ( +A, A)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/latex.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/latex.m + D = [1 2; 3 4]/4; + A = sym([1 2; 3 4])/4; + f1 = atand (A); + f2 = atand (D); + assert (double (f1), f2, -eps) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/ei.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ei.m ***** test syms x - y = sin(x); - assert (strcmp (latex (y), '\sin{\left(x \right)}')) -***** assert (strcmp (latex (exp (sym('x'))), 'e^{x}')) + f = ei(sym(0)); + assert (double(f) == -inf) +***** test + D = [1.895117816355937 4.954234356001890]; + A = ei(sym([1 2])); + assert (all (abs(double(A) - D) < 1e-15)) 2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/atan.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/atan.m -***** error atan (sym(1), 2) -***** assert (isequaln (atan (sym(nan)), sym(nan))) +[inst/@sym/symvar.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/symvar.m +***** error symvar (sym(1), 2, 3) +***** test + %% some empty cases + assert (isempty (symvar (sym(1)))); + assert (isempty (symvar (sym(1),1))); + assert (isempty (symvar (sym(1),0))); + assert (isempty (symvar (sym('x'),0))); +***** shared x,y,f + x=sym('x'); y=sym('y'); f=x^2+3*x*y-y^2; +***** assert (isequal (symvar (f), [x y])); +***** assert (isequal (symvar (f, 1), x)); +***** test + %% closest to x + syms x y a b c xx + alpha = sym('alpha'); + % https://www.mathworks.com/matlabcentral/newsreader/view_thread/237730 + assert( isequal (symvar (b*xx*exp(alpha) + c*sin(a*y), 2), [xx y])) + %% tests to match Matlab R2013b +***** shared x,y,z,a,b,c,X,Y,Z + syms x y z a b c X Y Z +***** test + %% X,Y,Z first if no 2nd argument + s = prod([x y z a b c X Y Z]); + assert (isequal( symvar (s), [X Y Z a b c x y z] )) +***** test + %% uppercase have *low* priority with argument? + s = prod([x y z a b c X Y Z]); + assert (isequal (symvar (s,4), [x, y, z, c] )) +***** test + %% closest to x + s = prod([y z a b c Y Z]); + assert (isequal( symvar (s,6), [ y, z, c, b, a, Y] )) + s = prod([a b c Y Z]); + assert (isequal( symvar (s,4), [ c, b, a, Y] )) +***** test + %% upper case letters in correct order + s = X*Y*Z; + assert (isequal( symvar (s,3), [X Y Z] )) +***** test + % diff. assumptions make diff. symbols + x1 = sym('x'); + x2 = sym('x', 'positive'); + f = x1*x2; + assert (length (symvar (f)) == 2) + z = symvar (f, 1); + assert (xor (isequal (z, x1), isequal (z, x2))) +10 tests, 10 passed, 0 known failure, 0 skipped +[inst/@sym/cbrt.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cbrt.m +***** error cbrt (sym(1), 2) +***** assert (isequaln (cbrt (sym(nan)), sym(nan))) ***** shared x, d - d = 1; - x = sym('1'); + d = 2; + x = sym('2'); ***** test - f1 = atan(x); - f2 = atan(d); + f1 = cbrt(x); + f2 = 1.2599210498948731647; assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = atan(A); - f2 = atan(D); + f1 = cbrt(A); + f2 = 1.2599210498948731647; + f2 = [f2 f2; f2 f2]; assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = atan (d); - f = atan (y); + if (exist ('OCTAVE_VERSION', 'builtin')) + A = cbrt (d); + else + % Issue #742 + A = d^(1/3); + end + f = cbrt (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ilaplace.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ilaplace.m -***** error ilaplace (sym(1), 2, 3, 4) -***** test - % basic SMT compact: no heaviside - syms s - syms t positive - assert (isequal (ilaplace(1/s^2), t)) - assert (isequal (ilaplace(s/(s^2+9)), cos(3*t))) - assert (isequal (ilaplace(6/s^4), t^3)) -Waiting............... -***** test - % more SMT compact - syms r - syms u positive - assert (isequal (ilaplace(1/r^2, u), u)) - assert (isequal (ilaplace(1/r^2, r, u), u)) -***** test - % if t specified and not positive, we expect heaviside - clear s t - syms s t - assert (isequal (ilaplace(1/s^2, s, t), t*heaviside(t))) - assert (isequal (ilaplace(s/(s^2+9), t), cos(3*t)*heaviside(t))) - assert (isequal (ilaplace(6/s^4, t), t^3*heaviside(t))) -Waiting................. -***** test - % Heaviside test - syms s - t=sym('t', 'positive'); - assert(logical( ilaplace(exp(-5*s)/s^2,t) == (t-5)*heaviside(t-5) )) +[inst/@sym/matlabFunction.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/matlabFunction.m ***** test - % Delta dirac test - syms s - t = sym('t'); - assert (isequal (ilaplace (sym('2'), t), 2*dirac(t))) + % autodetect inputs + syms x y + s = warning('off', 'OctSymPy:function_handle:nocodegen'); + h = matlabFunction(2*x*y, x+y); + warning(s) + [t1, t2] = h(3,5); + assert(t1 == 30 && t2 == 8) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/eq.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/eq.m ***** test - % Delta dirac test 2 - syms s c - t = sym('t', 'positive'); - assert (isequal (ilaplace (5*exp(-3*s) + 2*exp(c*s) - 2*exp(-2*s)/s,t), ... - 5*dirac(t-3) + 2*dirac(c+t) - 2*heaviside(t-2))) -***** error ilaplace (sym('s', 'positive')*sym('s')) + % simple tests with scalar numbers + assert (logical (sym(1) == sym(1))) + assert (logical (sym(1) == 1)) + assert (~logical (sym(1) == 0)) + assert (isequal (sym(1) == sym(1), sym(true))) + assert (isequal (sym(1) == 1, sym(true))) + assert (isequal (sym(1) == 0, sym(false))) ***** test - % SMT compact, prefers s over symvar - syms s x - syms t positive - assert (isequal (ilaplace(x/s^4), x*t^3/6)) - t = sym('t'); - assert (isequal (ilaplace(x/s^4, t), x*t^3/6*heaviside(t))) + % Type of the output is sym or logical? + % FIXME: in current version, they are sym + e = sym(1) == sym(1); + %assert (islogical (e)) + assert (isa (e, 'sym')) ***** test - % pick s even it has assumptions - syms s real - syms x t - assert (isequal (ilaplace (x/s^2, t), x*t*heaviside(t))) -10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@sym/length.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/length.m + % things involving a variable are usually not bool but sym. + % (SMT behaviour says always, FIXME: currently we differ.) + syms x + e = x == 0; + assert (~islogical (e)) + assert (isa (e, 'sym')) ***** test - a = sym([1 2 3]); - assert(length(a) == 3); + % ... except of course via cancelation + syms x + e = x - x == 0; + assert (logical (e)) + assert (isequal (e, sym(true))) ***** test - % 2D array - a = sym([1 2 3; 4 5 6]); - assert(length(a) == 3); + % array == array + a = sym([1 2; 3 4]); + y = a == a; + assert (isequal( size(y), [2 2])) + assert (isequal (y, sym([true true; true true]))) + assert (all(all(y))) + y = a == 1; + assert (isequal( size(y), [2 2])) + assert (isequal (y, sym([true false; false false]))) + assert (any(any(y))) + y = a == 42; + assert (isequal( size(y), [2 2])) + assert (isequal (y, sym([false false; false false]))) ***** test - % empty - a = sym([]); - assert(length(a) == 0); -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/ipermute.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ipermute.m -***** error permute (sym(1)) -***** error permute (sym(1), 2, 3) + % more array == array + D = [0 1; 2 3]; + A = [sym(0) 1; sym(2) 3]; + DZ = D - D; + assert (isequal (logical(A == A), [true true; true true])) + assert (isequal (logical(A == D), [true true; true true])) + assert (isequal (logical(A - D == DZ), [true true; true true])) + assert (all (all ( A == A ))) + assert (all (all ( A == D ))) + assert (all (all ( A - D == DZ ))) ***** test - syms x - A = [1 x]; - perm = [2 1]; - B = permute(A, perm); - C = ipermute(B, perm); - assert (isequal(C, A)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/null.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/null.m + % logical output, right shape, etc + t = true; f = false; + a = sym([0 1 2; 3 4 5]); + b = sym([0 1 1; 3 5 5]); + e = a == b; + eexp = sym(logical([1 1 0; 1 0 1])); + assert (isequal (e, eexp)) + a = sym([0 1 2]); + b = sym([0 1 1]); + e = a == b; + eexp = sym(logical([1 1 0])); + assert (isequal (e, eexp)) + e = a' == b'; + eexp = eexp.'; % is/was bug here with ' + assert (isequal (e, eexp)) ***** test - A = sym([1 2; 3 4]); - assert (isempty (null (A))) -***** assert (isempty (null (sym(4)))) + % empty matrices compare to correct empty size + a = zeros (sym(3), 0); + assert (size (a == a), [3, 0]) + a = zeros (sym(0), 2); + assert (size (a == a), [0, 2]) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/isna.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isna.m ***** test - A = sym([1 2 3; 3 4 5]); - assert (isequal (null(A), sym([1;-2;1]))) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/pinv.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/pinv.m + % no sym should be NA + syms x oo + assert (~isna(sym(1))) + assert (~isna(x)) + assert (~isna(oo)) + assert (~isna(sym(nan))) + assert (isequal (isna (sym ([1 nan])), [false false])) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/eye.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/eye.m ***** test - % scalar - syms x - assert (isequal (pinv(x), 1/x)) + y = eye(sym(2)); + x = [1 0; 0 1]; + assert( isequal( y, sym(x))) ***** test - % 2x3 - A = [1 2 3; 4 5 6]; - assert (max (max (abs (double (pinv (sym (A))) - pinv(A)))) <= 10*eps) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/reshape.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/reshape.m + y = eye(sym(2), 1); + x = [1; 0]; + assert( isequal( y, sym(x))) ***** test - d = [2 4 6; 8 10 12]; - a = sym(d); - assert (isequal (reshape(a, [1 6]), reshape(d, [1 6]))) - assert (isequal (reshape(a, 1, 6), reshape(d, 1, 6))) - assert (isequal (reshape(a, 2, 3), reshape(d, 2, 3))) - assert (isequal (reshape(a, 3, 2), reshape(d, 3, 2))) - assert (isequal (reshape(a, 6, 1), reshape(d, 6, 1))) -***** shared x, a, d - syms x - a = [1 x^2 x^4; x x^3 x^5]; - d = [0 2 4; 1 3 5]; - + y = eye(sym(1), 2); + x = [1 0]; + assert( isequal( y, sym(x))) ***** test - b = reshape(a, [1 6]); - assert (isequal (size(b), [1 6])) - assert (isequal (b, x.^reshape(d,1,6))) - + y = eye (sym([2 3])); + x = sym (eye ([2 3])); + assert (isequal (y, x)) +***** assert( isa( eye(sym(2), 'double'), 'double')) +***** assert( isa( eye(3, sym(3), 'single') , 'single')) +***** assert( isa( eye(3, sym(3)), 'sym')) +***** assert( isa( eye(3, sym(3), 'sym'), 'sym')) +***** xtest + % Issue #13 + assert( isa( eye(3, 3, 'sym'), 'sym')) +!!!!! known failure +invalid data type specified +9 tests, 8 passed, 1 known failure, 0 skipped +[inst/@sym/and.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/and.m +***** shared t, f + t = sym(true); + f = sym(false); ***** test - b = reshape(a, [6 1]); - assert (isequal (size(b), [6 1])) - assert (isequal (b, x.^reshape(d,6,1))) - b = reshape(b, size(a)); - assert (isequal (size(b), [2 3])) - assert (isequal (b, a)) - + % simple + assert (isequal (t & f, f)) + assert (isequal (t & t, t)) ***** test - b = a(:); - assert( isequal (size(b), [6 1])) - assert( isequal (b, x.^(d(:)))) - + % mix wih nonsym + assert (isequal (t & false, f)) + assert (isequal (t & true, t)) + assert (isequal (t & 0, f)) + assert (isequal (t & 1, t)) + assert (isa (t & false, 'sym')) + assert (isa (t & 1, 'sym')) ***** test - % reshape scalar - assert (logical( reshape(x, 1, 1) == x )) - assert (logical( reshape(x, [1 1]) == x )) -***** shared a - syms a -***** error reshape(a, 2, 1) -***** error reshape(a, 1, 2) -***** error reshape(a, 1, 1, 1) -***** error reshape(a, [1, 1, 1]) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/invhilb.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/invhilb.m + % array + w = [t t f f]; + z = [t f t f]; + assert (isequal (w & z, [t f f f])) ***** test - A = invhilb(sym(3)); - B = sym([9 -36 30;-36 192 -180;30 -180 180]); - assert( isequal( A, B)) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/laplace.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/laplace.m + % number + assert (isequal( sym(1) & t, t)) + assert (isequal( sym(0) & t, f)) ***** test - % basic - syms t s u w - assert(logical( laplace(cos(3*t)) == s/(s^2+9) )) - assert(logical( laplace(t^3) == 6/s^4 )) + % output is sym even for scalar t/f + assert (isa (t & f, 'sym')) ***** test - % matlab SMT compat - syms t s u w z - assert(logical( laplace(exp(2*t)) == 1/(s-2) )) - assert(logical( laplace(exp(2*s)) == 1/(z-2) )) - assert(logical( laplace(exp(2*u),w) == 1/(w-2) )) - assert(logical( laplace(exp(2*u),u,w) == 1/(w-2) )) + % eqns, exclusive + syms x + e = (x == 3) & (x^2 == 9); + assert (isequal (subs(e, x, [-3 0 3]), [f f t])) +***** error and (sym('x'), 2, 3) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/signIm.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/signIm.m +***** assert (isequal (signIm (sym(1)), sym(0))) +***** assert (isequal (signIm (sym(1) + 2i), sym(1))) +***** assert (isequal (signIm (sym(1) - 2i), sym(-1))) ***** test - syms x s t z - % matlab SMT prefers t over x - assert (isequal (laplace (x*exp (t), z), x/(z - 1))) - % as usual, you can just specify: - assert (isequal (laplace(x*exp(t), t, z), x/(z - 1))) % SMT result - assert (isequal (laplace(x*exp(t), x, z), exp(t)/z^2)) + % intermediate A looks bit weird, but it works + syms z + A = signIm (z); + assert (isequal (subs(A, z, 3+sym(4i)), sym(1))) + assert (isequal (subs(A, z, 3-sym(4i)), sym(-1))) ***** test - syms x a s - % if no t, use symvar: take x before a - assert (isequal (laplace (a*exp (x)), a/(s - 1))) -***** error laplace (sym('t')*sym('t', 'real')) + % really a @sym/sign test, but that one is autogen + z = 3 + sym(4i); + A = sign (z); + B = z / abs(z); + assert (double (A), double (B), eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/symreplace.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/symreplace.m ***** test - % constant, issue #250 - syms s - f = laplace(2, s); - assert (isequal (f, 2/s)) + % start with assumptions on x then remove them + syms x positive + f = x*10; + symreplace(x, sym('x')) + assert(isempty(assumptions(x))) ***** test - % Dirac delta and Heaviside tests - syms t s - assert (isequal (laplace(dirac(t-3)), exp(-3*s))) - assert (isequal (laplace((t-3)*heaviside(t-3)), exp(-3*s)/s^2)) -***** xtest - % Differential operator to algebraic - % SymPy cannot evaluate? (Issue #170) - syms s f(t) - assert(logical( laplace(diff(f(t),t),t,s) == s*laplace(f(t),t,s)-f(0) )) -!!!!! known failure -Python exception: TypeError: 'Add' object is not subscriptable - occurred at line 6 of the Python code block: - return F[0], -8 tests, 7 passed, 1 known failure, 0 skipped -[inst/@sym/equationsToMatrix.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/equationsToMatrix.m + % replace x with y + syms x + f = x*10; + symreplace(x, sym('y')) + assert( isequal (f, 10*sym('y'))) ***** test - syms x y z - [A, B] = equationsToMatrix ([x + y - z == 1, 3*x - 2*y + z == 3, 4*x - 2*y + z + 9 == 0], [x, y, z]); - a = sym ([1 1 -1; 3 -2 1; 4 -2 1]); - b = sym ([1; 3; -9]); - assert (isequal (A, a)) - assert (isequal (B, b)) + % gets inside cells + syms x + f = {x 1 2 {3 4*x}}; + symreplace(x, sym('y')) + syms y + assert( isequal (f{1}, y)) + assert( isequal (f{4}{2}, 4*y)) ***** test - syms x y z - A = equationsToMatrix ([3*x + -3*y - 5*z == 9, 4*x - 7*y + -3*z == -1, 4*x - 9*y - 3*z + 2 == 0], [x, y, z]); - a = sym ([3 -3 -5; 4 -7 -3; 4 -9 -3]); - assert (isequal (A, a)) + % gets inside structs/cells + syms x + my.foo = {x 1 2 {3 4*x}}; + my.bar = x; + g = {'ride' my 'motor' 'sicle'}; + symreplace(x, sym('y')) + syms y + f = g{2}; + assert( isequal (f.foo{1}, y)) + assert( isequal (f.foo{4}{2}, 4*y)) + assert( isequal (f.bar, y)) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/unique.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/unique.m ***** test - syms x y - [A, B] = equationsToMatrix ([3*x + 9*y - 5 == 0, -8*x - 3*y == -2]); - a = sym ([3 9; -8 -3]); - b = sym ([5; -2]); - assert (isequal (A, a)) - assert (isequal (B, b)) + A = sym([1 2 3 3 5 3 2 6 5]); + B = sym([1 2 3 5 6]); + assert (isequal (unique(A), B)) ***** test - % override symvar order syms x y - [A, B] = equationsToMatrix ([3*x + 9*y - 5 == 0, -8*x - 3*y == -2], [y x]); - a = sym ([9 3; -3 -8]); - b = sym ([5; -2]); - assert (isequal (A, a)) - assert (isequal (B, b)) -***** test - syms x y z - [A, B] = equationsToMatrix ([x - 9*y + z == -5, -9*y*z == -5], [y, x]); - a = sym ([[-9 1]; -9*z 0]); - b = sym ([-5 - z; -5]); - assert (isequal (A, a)) - assert (isequal (B, b)) + A = [1 2 3 3 4 5 5 6 7 7 x x y y]; + B = [1 2 3 4 5 6 7 x y]; + assert (isequal (unique(A), B)) ***** test - syms x y - [A, B] = equationsToMatrix (-6*x + 4*y == 5, 4*x - 4*y - 5, x, y); - a = sym ([-6 4; 4 -4]); - b = sym ([5; 5]); - assert (isequal (A, a)) - assert (isequal (B, b)) + syms x + assert (isequal (unique(x), x)) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/cond.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cond.m ***** test - % vertical list of equations - syms x y - [A, B] = equationsToMatrix ([-6*x + 4*y == 5; 4*x - 4*y - 5], [x y]); - a = sym ([-6 4; 4 -4]); - b = sym ([5; 5]); - assert (isequal (A, a)) - assert (isequal (B, b)) + A = [1 2; 3 4]; + B = sym(A); + k1 = cond(A); + k2 = cond(B); + k3 = double(k2); + assert (k1 - k3 <= 100*eps) ***** test - syms x y - [A, B] = equationsToMatrix (5*x == 1, y, x - 6*y - 7, y); - a = sym ([0; 1; -6]); - b = sym ([1 - 5*x; 0; -x + 7]); - assert (isequal (A, a)) - assert (isequal (B, b)) -***** error - syms x y - [A, B] = equationsToMatrix (x^2 + y^2 == 1, x - y + 1, x, y); + % matrix with symbols + syms x positive + A = [x 0; sym(0) 2*x]; + k1 = cond(A); + assert (isequal (k1, sym(2))) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/mrdivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/mrdivide.m ***** test - % single equation + % scalar syms x - [A, B] = equationsToMatrix (3*x == 2, x); - a = sym (3); - b = sym (2); - assert (isequal (A, a)) - assert (isequal (B, b)) + assert (isa( x/x, 'sym')) + assert (isequal( x/x, sym(1))) + assert (isa( 2/x, 'sym')) + assert (isa( x/2, 'sym')) ***** test - % single equation w/ symvar - syms x - [A, B] = equationsToMatrix (3*x == 2); - a = sym (3); - b = sym (2); - assert (isequal (A, a)) - assert (isequal (B, b)) -***** error - syms x - equationsToMatrix (3*x == 2, [x x]) -12 tests, 12 passed, 0 known failure, 0 skipped -[inst/@sym/potential.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/potential.m -***** error potential (sym(1), 2, 3, 4) -***** shared x,y,z - syms x y z + % matrix / scalar + D = 2*[0 1; 2 3]; + A = sym(D); + assert (isequal ( A/2 , D/2 )) + assert (isequal ( A/sym(2) , D/2 )) ***** test - % 1D - f = 3*x^2; - F = x^3; - assert (isequal (potential(f), F)) - assert (isequal (potential(f, x), F)) - assert (isequal (potential(f, x, 0), F)) - assert (isequal (potential(f, x, 2), F - 8)) + % I/A: either invert A or leave unevaluated: not bothered which + A = sym([1 2; 3 4]); + B = sym(eye(2)) / A; + assert (isequal (B, inv(A)) || strncmpi (sympy (B), 'MatPow', 6)) +***** xtest + % immutable test, upstream: TODO + A = sym([1 2; 3 4]); + B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])'); + assert (isequal (A/A, B/B)) ***** test - F = x*exp(y) + (z-1)^2; - f = gradient(F); - G = potential(f, [x;y;z], [0;1;1]); - assert (isAlways (G == F)) + % A = C/B is C = A*B + A = sym([1 2; 3 4]); + B = sym([1 3; 4 8]); + C = A*B; + A2 = C / B; + assert (isequal (A, A2)) ***** test - F = x*exp(y); - f = gradient(F); - G = potential(f); - assert (isAlways (G == F)) + A = [1 2; 3 4]; + B = A / A; + % assert (isequal (B, sym(eye(2)) + assert (isequal (B(1,1), 1)) + assert (isequal (B(2,2), 1)) + assert (isequal (B(2,1), 0)) + assert (isequal (B(1,2), 0)) ***** test - % no potential exists - syms x y - a = [x; x*y^2]; - assert (isnan (potential (a))) -***** shared -***** xtest - % fails b/c of sympy #8458 (piecewise expr that should simplify) - syms x - f = cos(x); - assert (isequal (potential(f, x), sin(x))) -!!!!! known failure -assert (isequal (potential (f, x), sin (x))) failed -6 tests, 5 passed, 1 known failure, 0 skipped -[inst/@sym/symprod.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/symprod.m -***** error symprod (sym(1), 2, 3, 4, 5) + A = sym([5 6]); + B = sym([1 2; 3 4]); + C = A*B; + A2 = C / B; + assert (isequal (A, A2)) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/symsum.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/symsum.m +***** error symsum (sym(1), 2, 3, 4, 5) ***** test - % simple + % finite sums syms n - assert (isequal (symprod(n, n, 1, 10), factorial(sym(10)))) - assert (isequal (symprod(n, n, sym(1), sym(10)), factorial(10))) + assert (isequal (symsum(n,n,1,10), 55)) + assert(isa(symsum(n,n,1,10), 'sym')) + assert (isequal (symsum(n,n,sym(1),sym(10)), 55)) + assert (isequal (symsum(n,n,sym(1),sym(10)), 55)) + assert (isequal (symsum(1/n,n,1,10), sym(7381)/2520)) +***** test + % negative limits + syms n + assert (isequal (symsum(n,n,-3,3), sym(0))) + assert (isequal (symsum(n,n,-3,0), sym(-6))) + assert (isequal (symsum(n,n,-3,-1), sym(-6))) ***** test % one input syms n - f = symprod (n); - g = factorial (n); + f = symsum (n); + g = n^2/2 - n/2; assert (isequal (f, g)) - f = symprod (2*n); - g = 2^n * factorial (n); + f = symsum (2*n); + g = n^2 - n; assert (isequal (f, g)) ***** test % constant input - f = symprod (sym(2)); + f = symsum (sym(2)); syms x - g = 2^x; + g = 2*x; assert (isequal (f, g)) ***** test % two inputs syms n - f = symprod (2*n, n); - g = 2^n * factorial (n); + f = symsum (2*n, n); + g = n^2 - n; assert (isequal (f, g)) ***** test % two inputs, second is range syms n - f = symprod (n, [1 6]); - g = 720; + f = symsum (n, [1 6]); + g = 21; assert (isequal (f, g)) - f = symprod (n, [sym(1) 6]); - g = 720; + f = symsum (n, [sym(1) 6]); + g = 21; assert (isequal (f, g)) - f = symprod (2*n, [1 6]); - g = sym(2)^6*720; + f = symsum (2*n, [1 6]); + g = 2*21; assert (isequal (f, g)) ***** test % three inputs, last is range syms n - f = symprod (2*n, n, [1 4]); - g = sym(384); + f = symsum (2*n, n, [1 4]); + g = sym(20); assert (isequal (f, g)) - f = symprod (2*n, n, [sym(1) 4]); - g = sym(384); + f = symsum (2*n, n, [sym(1) 4]); + g = sym(20); assert (isequal (f, g)) - f = symprod (2, n, [sym(1) 4]); - g = sym(16); + f = symsum (2, n, [sym(1) 4]); + g = sym(8); assert (isequal (f, g)) ***** test % three inputs, no range syms n - f = symprod (2*n, 1, 4); - g = sym(384); + f = symsum (2*n, 1, 4); + g = sym(20); assert (isequal (f, g)) - f = symprod (5, sym(1), 3); - g = sym(125); + f = symsum (5, sym(1), 3); + g = sym(15); assert (isequal (f, g)) ***** test - % infinite product - syms a n oo - zoo = sym('zoo'); - assert (isequal (symprod(a, n, 1, oo), a^oo)) - assert (isequal (symprod(a, n, 1, inf), a^oo)) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/ellipticCPi.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticCPi.m -***** error ellipticCPi (sym (1)) -***** error ellipticCPi (sym (1), 2, 3) -***** assert (double (ellipticCPi (0, sym (1)/2)), 1.854074677, 10e-10) -***** assert (double (ellipticCPi (sym (6)/10, sym(71)/10)), 1.29469534336658, -20*eps) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/eig.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/eig.m + % ok to use double's for arguments in infinite series + syms n oo + assert(isequal(symsum(1/n^2,n,1,oo), sym(pi)^2/6)) + assert(isequal(symsum(1/n^2,n,1,inf), sym(pi)^2/6)) ***** test - % basic - A = [1 2; 3 4]; - B = sym(A); - sd = eig(A); - s = eig(B); - s2 = double(s); - assert (norm(sort(s2) - sort(sd)) <= 10*eps) + % should be oo because 1 is real but seems to be + % zoo/oo depending on sympy version + syms n oo + zoo = sym('zoo'); + assert (isequal (symsum(1/n,n,1,oo), oo) || ... + isequal (symsum(1/n,n,1,oo), zoo)) +11 tests, 11 passed, 0 known failure, 0 skipped +[inst/@sym/fliplr.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/fliplr.m ***** test - % scalars + % simple syms x - a = sym(-10); - assert (isequal (eig(a), a)) - assert (isequal (eig(x), x)) + A = [x 2; sym(pi) x]; + B = [2 x; x sym(pi)]; + assert (isequal (fliplr(A), B)) ***** test - % diag, multiplicity - A = diag([6 6 7]); - B = sym(A); - e = eig(B); - assert (isequal (size (e), [3 1])) - assert (sum(logical(e == 6)) == 2) - assert (sum(logical(e == 7)) == 1) + % simple, odd # cols + syms x + A = [x 2 sym(pi); x 1 2]; + B = [sym(pi) 2 x; 2 1 x]; + assert (isequal (fliplr(A), B)) ***** test - % matrix with symbols - syms x y positive - A = [x+9 y; sym(0) 6]; - s = eig(A); - s = simplify(s); - assert (isequal (s, [x+9; 6]) || isequal (s, [6; x+9])) + % scalar + syms x + assert (isequal (fliplr(x), x)) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/norm.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/norm.m +***** assert (isequal (norm(sym(-6)), 6)) ***** test - % eigenvects - e = sym([5 5 5 6 7]); - A = diag(e); - [V, D] = eig(A); - assert (isequal (diag(D), e.')) - assert (isequal (V, diag(sym([1 1 1 1 1])))) + % 2-norm default + A = [1 2; 3 4]; + n1 = norm (sym (A)); + assert (isequal (n1, sqrt (sqrt (sym(221)) + 15))) + assert (norm (A), double (n1), -eps) ***** test - % alg/geom mult, eigenvects - e = sym([5 5 5 6]); - A = diag(e); - A(1,2) = 1; - [V, D] = eig(A); - assert (isequal (diag(D), e.')) - assert (sum(logical(V(1,:) ~= 0)) == 2) - assert (sum(logical(V(2,:) ~= 0)) == 0) - assert (sum(logical(V(3,:) ~= 0)) == 1) - assert (sum(logical(V(4,:) ~= 0)) == 1) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/isvector.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isvector.m -***** assert(isvector(sym('x'))) -***** assert(isvector(sym([1 2 3]))) -***** assert(isvector(sym([1; 2]))) -***** assert(~isvector(sym([1 2; 3 4]))) -***** assert(~isvector(sym([]))) -***** assert(isvector(sym(ones(1,0)))) -***** assert(~isvector(sym(ones(0,3)))) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/ssinint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ssinint.m -***** assert (isequal (ssinint(sym(0)), -sym(pi)/2)) + syms x y real + assert (isequal (norm([x 1; 3 y], 'fro'), sqrt(x^2 + y^2 + 10))) ***** test - A = ssinint (sym ([0 1])); - B = [-pi/2 -0.62471325642771360426]; - assert( all(all( abs(double(A)-B) < 1e-15 ))) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/nextprime.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/nextprime.m -***** assert (isequal (nextprime(sym(2)), 3)); -***** assert (isequal (nextprime(sym(18)), 19)); -***** assert (isequal (nextprime(sym([1 2 3])), [2 3 5])); -***** assert (isequal (nextprime(sym([-1 0])), [2 2])); + syms x real + assert (isequal (norm([x 1], 2), sqrt(x^2 + 1))) ***** test - % result is a sym - p = nextprime(sym(2)); - assert (isa (p, 'sym')) + % test sym vs double ord + syms x + assert (isequal (norm([x 2 1], 1), abs(x) + 3)) + assert (isequal (norm([x 2 1], sym(1)), abs(x) + 3)) + assert (isequal (norm([sym(-3) 2 1], inf), sym(3))) + assert (isequal (norm([sym(-3) 2 1], sym(inf)), sym(3))) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/isprime.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isprime.m -***** assert (isprime (sym(5))) -***** assert (~isprime (sym(4))) -***** assert (~isprime (sym(0))) -***** assert (~isprime (sym(1))) -***** test - a = [5 7 6; 1 2 337]; - assert (isequal (isprime (a), [true true false; false true true])) -***** assert (~isprime(sym(-4))) -***** assert (~isprime(sym(4i))) -***** assert (~isprime(sym(3)/5)) -***** error - isprime(sym('x')); -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/asech.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/asech.m -***** error asech (sym(1), 2) -***** assert (isequaln (asech (sym(nan)), sym(nan))) -***** shared x, d - d = 1/2; - x = sym('1/2'); -***** test - f1 = asech(x); - f2 = asech(d); - assert( abs(double(f1) - f2) < 1e-15 ) -***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = asech(A); - f2 = asech(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +[inst/@sym/chebyshevU.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/chebyshevU.m +***** error chebyshevU (sym(1)) +***** error chebyshevU (sym(1), 2, 3) +***** assert (isequaln (chebyshevU (2, sym(nan)), sym(nan))) +***** shared x + syms x +***** assert(isequal(chebyshevU(0, x), sym(1))) +***** assert(isequal(chebyshevU(1, x), 2*x)) +***** assert(isequal(chebyshevU(2, x), 4*x*x - 1)) +***** assert(isequal(chebyshevU([0 1 2], x), [sym(1) 2*x (4*x*x-1)])) ***** test % round trip - y = sym('y'); - A = asech (d); - f = asech (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/harmonic.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/harmonic.m -***** error harmonic (sym(1), 2) -***** xtest - assert (isequaln (harmonic (sym(nan)), sym(nan))) -!!!!! known failure -assert (isequaln (harmonic (sym (nan)), sym (nan))) failed -***** assert (isequal (harmonic (sym(0)), sym(0))) -***** assert (isinf (harmonic (sym(inf)))) -***** assert (isequal (harmonic (sym([9 10])), [sym(7129)/2520 sym(7381)/2520])) + syms n z + f = chebyshevU (n, z); + h = function_handle (f, 'vars', [n z]); + A = h (1.1, 2.2); + B = chebyshevU (1.1, 2.2); + assert (A, B) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/subs.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/subs.m +***** error subs (sym(1), 2, 3, 4) +***** shared x,y,t,f + syms x y t + f = x*y; ***** test - % round trip - y = sym('y'); - A = harmonic (7); - f = harmonic (y); - h = function_handle (f); - B = h (7); - assert (A, B, -eps) -6 tests, 5 passed, 1 known failure, 0 skipped -[inst/@sym/curl.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/curl.m -***** error curl([sym(1) 2 3], 42, 42) -***** shared x,y,z - syms x y z + assert( isequal( subs(f, x, y), y^2 )) + assert( isequal( subs(f, y, sin(x)), x*sin(x) )) + assert( isequal( subs(f, x, 16), 16*y )) ***** test - % double const - f = [1 2 3]; - g = [sym(0); 0; 0]; - assert (isequal (curl(f, [x y z]), g)) - % should fail, calls @double: curl(f, {x y z}), g)) + % multiple subs w/ cells + assert( isequal( subs(f, {x}, {t}), y*t )) + assert( isequal( subs(f, {x y}, {t t}), t*t )) + assert( isequal( subs(f, {x y}, {t 16}), 16*t )) + assert( isequal( subs(f, {x y}, {16 t}), 16*t )) + assert( isequal( subs(f, {x y}, {2 16}), 32 )) ***** test - % div curl always 0 - v = [exp(x); x*y; sin(z)]; - g = curl(v); - a = divergence(g, [x y z]); - assert (isAlways (a == sym(0))) - assert (isa (a, 'sym')) - g = curl(v, [x y z]); - a = divergence(g, [x y z]); - assert (isAlways (a == sym(0))) - assert (isa (a, 'sym')) + % multiple subs w/ vectors + assert( isequal( subs(f, [x y], [t t]), t*t )) + assert( isequal( subs(f, [x y], [t 16]), 16*t )) + assert( isequal( subs(f, [x y], [2 16]), 32 )) ***** test - % div curl always 0 - v = [exp(x); erfc(x*y); sin(exp(x)*y+sinh(z))]; - g = curl(v, [x y z]); - a = divergence(g, [x y z]); - assert (isAlways (a == sym(0))) - assert (isa (a, 'sym')) + % anything you can think of + assert( isequal( subs(f, [x y], {t t}), t*t )) + assert( isequal( subs(f, {x y}, [t t]), t*t )) + assert( isequal( subs(f, {x; y}, [t; t]), t*t )) ***** test - % curl grad is vec zero - f = sin(exp(x)*y+sinh(z)); - g = curl(gradient(f, [x,y,z])); - assert (isequal (g, sym([0;0;0]))) -Waiting............ + % sub in doubles gives sym (matches SMT 2013b) + % FIXME: but see + % http://www.mathworks.co.uk/help/symbolic/gradient.html + assert( isequal( subs(f, {x y}, {2 pi}), 2*sym(pi) )) + assert( ~isa(subs(f, {x y}, {2 pi}), 'double')) + assert( isa(subs(f, {x y}, {2 pi}), 'sym')) + assert( isa(subs(f, {x y}, {2 sym(pi)}), 'sym')) + assert( isa(subs(f, {x y}, {sym(2) sym(pi)}), 'sym')) +***** shared x,y,t,f,F + syms x y t + f = sin(x)*y; + F = [f; 2*f]; ***** test - % 2d fcn in 2d/3d - u = sin(exp(x)*y); - v = x^2*y^3; - vorticity2d = diff(v,x) - diff(u,y); - omega = curl([u; v; 0], [x y z]); - assert (isequal (omega, [0; 0; vorticity2d])) -***** error <3D vector> curl([sym(1) 2 3 4]) -***** error curl([sym(1) 2 3], {sym('x') sym('y') sym('z') sym('t')}) -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/logspace.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/logspace.m + % need the simultaneous=True flag in SymPy (matches SMT 2013b) + assert( isequal( subs(f, [x t], [t 6]), y*sin(t) )) + assert( isequal( subs(F, [x t], [t 6]), [y*sin(t); 2*y*sin(t)] )) ***** test - % default argument for N - A = logspace(0, 2); - assert (length (A) == 50); + % swap x and y (also needs simultaneous=True + assert( isequal( subs(f, [x y], [y x]), x*sin(y) )) ***** test - % special case: pi as end pt - A = logspace(-sym(3), sym(pi), 3); - assert (isequal (A(end), sym(pi))) + % but of course both x and y to t still works + assert( isequal( subs(f, [x y], [t t]), t*sin(t) )) +***** shared ***** test - A = logspace(-sym(4), 0, 3); - B = [sym(1)/10000 sym(1)/100 sym(1)]; - assert (isequal (A, B)) + % Issue #10, subbing matrices in for scalars + syms y + a = sym([1 2; 3 4]); + f = sin(y); + g = subs(f, y, a); + assert (isequal (g, sin(a))) ***** test - % vpa support, might need recent sympy for sympy issue #10063 - n = 32; - A = logspace(-vpa(1,n), 0, 3); - B = [10^(-vpa(1,n)) 10^(-vpa(sym(1)/2,n)) vpa(1,n)]; - assert (isequal (A, B)) - assert (max(abs(double(A) - logspace(-1, 0, 3))) < 1e-15) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/chol.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/chol.m -***** error chol (sym ([1 2; 3 4])); -***** error chol (sym ([1 2; 3 4; 5 6])); + % Issue #10, subbing matrices in for scalars + syms y + a = sym([1 2]); + g = subs(sin(y), {y}, {a}); + assert (isequal (g, sin(a))) ***** test - A = chol(hilb(sym(2))); - B = [[1 0]; sym(1)/2 sqrt(sym(3))/6]; - assert( isequal( A, B )) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/sinhint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinhint.m -***** error sinhint (sym(1), 2) -***** xtest - assert (isequaln (sinhint (sym(nan)), sym(nan))) -!!!!! known failure -assert (isequaln (sinhint (sym (nan)), sym (nan))) failed -***** shared x, d - d = 1; - x = sym('1'); + % Issue #10, subbing matrices in for scalars + syms y + a = sym([1; 2]); + g = subs(sin(y), {y}, a); + assert (isequal (g, sin(a))) ***** test - f1 = sinhint(x); - f2 = 1.057250875375728514572; - assert( abs(double(f1) - f2) < 1e-15 ) + % Issue #10, subbing matrices in for scalars + syms y + a = [10 20 30]; + f = 2*y; + g = subs(f, y, a); + assert (isequal (g, 2*a)) + assert (isa (g, 'sym')) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = sinhint(A); - f2 = 1.057250875375728514572; - f2 = [f2 f2; f2 f2]; - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % Issue #10, sub matrices in for two scalars + syms x y + a = [10 20 30]; + f = x^2*y; + g = subs(f, {x y}, {a a+1}); + h = a.^2.*(a+1); + assert (isequal (g, h)) ***** test - % round trip - y = sym('y'); - A = sinhint (d); - f = sinhint (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 4 passed, 1 known failure, 0 skipped -[inst/@sym/subsasgn.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/subsasgn.m -***** shared a,b - b = [1:4]; - a = sym(b); -***** test a(1) = 10; b(1) = 10; - assert(isequal( a, b )) -***** test I = logical([1 0 1 0]); - a(I) = 2; b(I) = 2; - assert(isequal( a, b )) -***** test I = logical([1 0 1 0]); - a(I) = [2 4]; b(I) = [2 4]; - assert(isequal( a, b )) -***** test I = logical([1 0 1 0]); - a(I) = [2; 4]; b(I) = [2; 4]; - assert(isequal( a, b )) -***** shared -***** test - b = 1:4; b = [b; 2*b; 3*b]; - a = sym(b); - rhs = [10 11; 12 13]; - a([1:2],[1:2]) = rhs; - b([1:2],[1:2]) = rhs; - assert(isequal( a, b )) - a(1:2,1:2) = rhs; - assert(isequal( a, b )) + % Issue #10, sub matrices in for two scalars + syms x y z + a = [10 20 30]; + f = x^2*y; + g = subs(f, {x y}, {a z}); + h = a.^2*z; + assert (isequal (g, h)) + g = subs(f, {x y}, {a 6}); + h = a.^2*6; + assert (isequal (g, h)) +***** error + syms x y + a = [10 20 30]; + f = x^2*y; + g = subs(f, {x y}, {[10 20 30] [10 20]}); ***** test - % slice : - b = 1:4; b = [b; 2*b]; - a = sym(b); - rhs = [10 11; 12 13]; - a(:,2:3) = rhs; - b(:,2:3) = rhs; - assert(isequal( a, b )) + % two inputs + syms x y + assert (isequal (subs (2*x, 6), sym(12))) + assert (isequal (subs (2*x*y^2, 6), 12*y^2)) + assert (isequal (subs (2*y, 6), sym(12))) + assert (isequal (subs (sym(2), 6), sym(2))) ***** test - % grow 2D - b = 1:4; b = [b; 2*b]; - a = sym(b); - rhs = [10 11; 12 13]; - a([1 end+1],end:end+1) = rhs; - b([1 end+1],end:end+1) = rhs; - assert(isequal( a, b )) + % only two inputs, vector + syms x + assert (isequal (subs (2*x, [3 5]), sym([6 10]))) ***** test - % grow from nothing - clear a - a(3) = sym (1); - b = sym ([0 0 1]); - assert (isequal (a, b)) + % SMT compat, subbing in vec/mat for nonexist x + syms x y z + % you might think this would be y: + assert (~ isequal (subs (y, x, [1 2]), y)) + % but it gives two y's: + assert (isequal (subs (y, x, [1 2]), [y y])) + assert (isequal (subs (sym(42), [3 5]), sym([42 42]))) + assert (isequal (subs (sym(42), x, []), sym([]))) + assert (isequal (subs (y, {x y}, {[1 2; 3 4], 6}), sym([6 6; 6 6]))) + assert (isequal (subs (y, {x z}, {[1 2; 3 4], 6}), [y y; y y])) ***** test - % grow from nothing, 2D - clear a - a(2, 3) = sym (1); - b = sym ([0 0 0; 0 0 1;]); - assert (isequal (a, b)) + syms x y + assert (isequal (subs (sym(42), x, y), sym(42))) + assert (isequal (subs (sym(42), y), sym(42))) + assert (isequal (subs (sym(42)), sym(42))) ***** test - % linear indices of 2D - b = 1:4; b = [b; 2*b; 3*b]; - a = sym(b); - b(1:4) = [10 11 12 13]; - a(1:4) = [10 11 12 13]; - assert(isequal( a, b )) - b(1:4) = [10 11; 12 13]; - a(1:4) = [10 11; 12 13]; - assert(isequal( a, b )) -***** error - % Wrong shape matrix RHS: Matlab/Octave don't allow this on doubles. - % Matlab SMT 2013b gets it wrong. We throw an error. - rhs = [10 11; 12 13]; - a = sym (magic (3)); - a(1:2,1:2) = rhs(:); + % empty lists + assert (isequal (subs (sym(42), {}, {}), sym(42))) + assert (isequal (subs (42, sym([]), sym([])), sym(42))) ***** test - % Issue #963: vector RHS with diff orientation from 2D indexing - b = 1:4; b = [b; 2*b; 3*b]; - a = sym(b); - b(1:2:3, 1) = 11:2:13; - a(1:2:3, 1) = sym(11:2:13); - assert (isequal (a, b)) - b(1:2:3, 1) = 1:2:3; - a(1:2:3, 1) = 1:2:3; - assert (isequal (a, b)) + syms x y + f = x*y; + x = 6; y = 7; + g = subs (f); + assert (isequal (g, sym (42))) + assert (isa (g, 'sym')) ***** test - % Issue #963: vector RHS with diff orientation from 2D indexing - a = sym (magic (3)); - b = a; - a(1:2:3, 2) = [14 15]; - b(1:2:3, 2) = [14; 15]; - assert (isequal (a, b)) - a(2, 1:2:3) = [24 25]; - b(2, 1:2:3) = [24; 25]; - assert (isequal (a, b)) + syms x y + f = x*y; + x = 6; + g = subs (f); + assert (isequal (g, 6*y)) ***** test - % 1D growth and 'end' - g = sym([1 2 3]); - g(3:4) = [67 68]; - g(end:end+1) = [12 14]; - assert(isequal( g, [1 2 67 12 14] )) + syms x y + f = x*y; + xsave = x; + x = 6; + g = subs (f); + assert (isequal (g, 6*y)) + assert (isequal (f, xsave*y)) ***** test - % expanding empty and scalar + syms a x y + f = a*x*y; + a = 6; + clear x + g = subs (f); syms x - c = sym([]); - c(1) = x; - assert(isequal( c, x )) - c(2) = 2*x; - assert(isequal( c, [x 2*x] )) -***** shared a,b,I,J - b = 1:4; b = [b; 3*b; 5*b]; a = sym(b); - I = logical([1 0 1]); - J = logical([1 0 1 0]); -***** assert(isequal( a(I,J), b(I,J) )) + assert (isequal (g, 6*x*y)) +25 tests, 25 passed, 0 known failure, 0 skipped +[inst/@sym/kron.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/kron.m ***** test - rhs = [90 91; 92 93]; - b(I, J) = rhs; - a(I, J) = rhs; - assert(isequal( a, b )) + syms x y + A = [sin(x), sin(y); x, y]; + B = ones(2); + expected = sym([sin(x), sin(x), sin(y), sin(y); sin(x), sin(x), sin(y), sin(y); x, x, y, y; x, x, y, y]); + assert (isequal (kron(A, B), expected)) ***** test - b(I, J) = 100; - a(I, J) = 100; - assert(isequal( a, b )) -***** shared + syms x y + A = [sin(x), sin(y); x, y]; + B = 2; + assert (isequal (kron(A, B), 2*A)) ***** test - % logical with all false - syms x - y = x; - y(false) = 6; - assert(isequal( y, x )); - a = [x x]; - a([false false]) = [6 6]; - assert(isequal( a, [x x] )); + syms x y + A = [sin(x), sin(y)]; + B = 2; + assert (isequal( kron(B, A), 2*A)) ***** test - % issue #18, scalar access - syms x - x(1) = sym(6); - assert(isequal( x, sym(6) )); - x(1) = 6; - assert(isequal( x, sym(6) )); - x(true) = 88; - assert(isequal( x, sym(88) )); + syms x y; + X = [tan(x), tan(x)]; + Y = [cot(x); cot(x)]; + expected = sym(ones(2)); + assert (isequal (simplify(kron(X, Y)), expected)) ***** test - % bug: assignment to column vector used to fail - A = sym(zeros(3,1)); - A(1) = 5; + syms x y z + X = [x, y, z]; + Y = [y, y; x, x]; + expected = [x*y, x*y, y^2, y^2, y*z, y*z; x^2, x^2, x*y, x*y, x*z, x*z]; + assert (isequal (kron(X, Y), expected)) ***** test - % symfun creation (generic function) - syms x - g(x) = x*x; - assert(isa(g,'symfun')) + syms x y + X = [x, x^2; y, y^2]; + Y = [1, 0; 0, 1]; + expected = [x, x^2, 0, 0; y, y^2, 0, 0; 0, 0, x, x^2; 0, 0, y, y^2]; + assert (isequal (kron(Y, X), expected)) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/logint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/logint.m +***** error logint (sym(1), 2) +***** xtest + assert (isequaln (logint (sym(nan)), sym(nan))) +!!!!! known failure +assert (isequaln (logint (sym (nan)), sym (nan))) failed +***** shared x, d + d = 2; + x = sym('2'); ***** test - % symfun creation (generic function) - syms x g(x) - assert(isa(g,'symfun')) + f1 = logint(x); + f2 = 1.045163780117492784845; + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % symfun creation when g already exists and is a sym/symfun - syms x - g = x; - syms g(x) - assert(isa(g,'symfun')) - clear g - g(x) = x; - g(x) = x*x; - assert(isa(g,'symfun')) + D = [d d; d d]; + A = [x x; x x]; + f1 = logint(A); + f2 = 1.045163780117492784845; + f2 = [f2 f2; f2 f2]; + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % Issue #443: assignment with sym indices - A = sym([10 11]); - A(sym(1)) = 12; - assert (isequal (A, sym([12 11]))) + % round trip + y = sym('y'); + A = logint (d); + f = logint (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 4 passed, 1 known failure, 0 skipped +[inst/@sym/abs.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/abs.m +***** error abs (sym(1), 2) +***** assert (isequaln (abs (sym(nan)), sym(nan))) +***** shared x, d + d = -1; + x = sym('-1'); ***** test - % Issue #443: assignment with sym indices - A = sym([10 11]); - A(sym(1), 1) = 12; - assert (isequal (A, sym([12 11]))) - A(sym(1), sym(1)) = 13; - assert (isequal (A, sym([13 11]))) + f1 = abs(x); + f2 = abs(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = abs(A); + f2 = abs(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = abs (d); + f = abs (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/rank.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/rank.m ***** test - % Issue #443: assignment with sym indices, increase size - A = sym([10 11]); - A(sym(2), 1) = 12; - assert (isequal (A, sym([10 11; 12 0]))) -***** error - % Issue #443 - A = sym([10 11]); - A(2, sym('x')) = sym(12); -***** error - % Issue #443 - A = sym([10 11]); - A(sym(2), sym('x')) = sym(12); -***** error - % issue #445 - A = sym([10 11]); - A(1.1) = 13 -***** error - % issue #445 - A = sym([10 11]); - A(sym(pi)) = 13 -***** error - % issue #445 A = sym([1 2; 3 4]); - A(1.3, 1.2) = 13 + assert (rank(A) == 2); ***** test - % older expansion tests - syms x - f = [2*x 3*x]; - f(2) = 4*x; - assert (isequal (f, [2*x 4*x])) - f(2) = 2; - assert (isequal(f, [2*x 2])) - g = f; - g(1,3) = x*x; - assert (isequal(g, [2*x 2 x^2])) - g = f; - g(3) = x*x; - assert (isequal(g, [2*x 2 x^2])) - g = f; - g(3) = 4; - assert (isequal(g, [2*x 2 4])) + A = sym([1 2 3; 3 4 5]); + assert (rank(A) == 2); ***** test - % older slicing tests - syms x - f = [1 x^2 x^4]; - f(1:2) = [x x]; - assert (isequal( f, [x x x^4] )) - f(1:2) = [1 2]; - assert (isequal( f, [1 2 x^4] )) - f(end-1:end) = [3 4]; - assert (isequal( f, [1 3 4] )) - f(3:4) = [10 11]; - assert (isequal( f, [1 3 10 11] )) - f(end:end+1) = [12 14]; - assert (isequal( f, [1 3 10 12 14] )) + A = sym([1 2; 1 2]); + assert (rank(A) == 1); ***** test - % struct.str = sym, sometimes calls subsasgn - d = struct(); - syms x - d.a = x; - assert (isa (d, 'struct')) - assert (isequal (d.a, x)) - d.('a') = x; - assert (isa (d, 'struct')) - assert (isequal (d.a, x)) - d = setfield(d, 'a', x); - assert (isa (d, 'struct')) - assert (isequal (d.a, x)) - % at least on Oct 3.8, this calls sym's subsasgn - d = struct(); - d = setfield(d, 'a', x); - assert (isa (d, 'struct')) - assert (isequal (d.a, x)) + A = sym([1 2; 3 4]); + assert (rank(A) == 2); +***** assert (rank(sym(1)) == 1); +***** assert (rank(sym(0)) == 0); +***** assert (rank(sym('x', 'positive')) == 1); +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/acot.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/acot.m +***** error acot (sym(1), 2) +***** assert (isequaln (acot (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - % bool scalar assignments of true/false into sym - syms x - a = sym([1 2 x 3]); - b = [1 2 10 4]; - e = a == b; - assert (logical (e(2))) - e(2) = false; - assert (~logical (e(2))) + f1 = acot(x); + f2 = acot(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % bool vector assignments of true/false into sym - syms x - a = sym([1 2 x 3]); - b = [1 2 10 4]; - e = a == b; - e(1:2) = [true true]; - assert (isequal (e, [sym(1)==1 sym(2)==2 x==10 sym(3)==4])) + D = [d d; d d]; + A = [x x; x x]; + f1 = acot(A); + f2 = acot(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % bool scalar promoted to vector assignments into sym - syms x - a = sym([1 2 x 3]); - b = [1 2 10 4]; - e = a == b; - e(1:2) = true; - assert (isequal (e, [sym(1)==1 sym(2)==2 x==10 sym(3)==4])) + % round trip + y = sym('y'); + A = acot (d); + f = acot (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/ilaplace.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ilaplace.m +***** error ilaplace (sym(1), 2, 3, 4) ***** test - % grow scalar equality expression into a matrix of equalities - syms a b c d - e = a == b; - e(2) = c == d; - assert (isequal (e, [a==b c==d])) -***** shared a, b, I - b = [1:4]; b = [b; 3*b; 5*b]; - a = sym(b); - I = mod (b, 5) > 1; + % basic SMT compact: no heaviside + syms s + syms t positive + assert (isequal (ilaplace(1/s^2), t)) + assert (isequal (ilaplace(s/(s^2+9)), cos(3*t))) + assert (isequal (ilaplace(6/s^4), t^3)) +Waiting...... ***** test - A = a; A(I) = 2*b(I); - B = b; B(I) = 2*b(I); - assert (isequal (A, B)) + % more SMT compact + syms r + syms u positive + assert (isequal (ilaplace(1/r^2, u), u)) + assert (isequal (ilaplace(1/r^2, r, u), u)) ***** test - % scalar RHS - A = a; A(I) = 17; - B = b; B(I) = 17; - assert (isequal (A, B)) + % if t specified and not positive, we expect heaviside + clear s t + syms s t + assert (isequal (ilaplace(1/s^2, s, t), t*heaviside(t))) + assert (isequal (ilaplace(s/(s^2+9), t), cos(3*t)*heaviside(t))) + assert (isequal (ilaplace(6/s^4, t), t^3*heaviside(t))) +Waiting...... ***** test - % nonetheless, above strange case should give right answer - I = logical([1 0 1 0; 0 1 0 1; 1 0 1 0]); - rhs = 2*b(I); - rhs2 = reshape(rhs, 2, 3); - A0 = a; A1 = a; - A0(I) = rhs; - A1(I) = rhs2; - assert (isequal (A0, A1)) -***** shared AA, BB - BB = [1 2 3; 4 5 6]; - AA = sym(BB); + % Heaviside test + syms s + t=sym('t', 'positive'); + assert(logical( ilaplace(exp(-5*s)/s^2,t) == (t-5)*heaviside(t-5) )) ***** test - A = AA; B = BB; - B([1 6]) = [8 9]; - A([1 6]) = [8 9]; - assert (isequal (A, B)) + % Delta dirac test + syms s + t = sym('t'); + assert (isequal (ilaplace (sym('2'), t), 2*dirac(t))) ***** test - % rhs scalar - A = AA; B = BB; - B([1 6]) = 88; - A([1 6]) = 88; - assert (isequal (A, B)) + % Delta dirac test 2 + syms s c + t = sym('t', 'positive'); + assert (isequal (ilaplace (5*exp(-3*s) + 2*exp(c*s) - 2*exp(-2*s)/s,t), ... + 5*dirac(t-3) + 2*dirac(c+t) - 2*heaviside(t-2))) +***** error ilaplace (sym('s', 'positive')*sym('s')) ***** test - % If rhs is not a vector, make sure col-based access works - rhs = [18 20; 19 21]; - A = AA; B = BB; - B([1 6]) = 88; - A([1 6]) = 88; - B([1 2 3 4]) = rhs; - A([1 2 3 4]) = rhs; - assert (isequal (A, B)) + % SMT compact, prefers s over symvar + syms s x + syms t positive + assert (isequal (ilaplace(x/s^4), x*t^3/6)) + t = sym('t'); + assert (isequal (ilaplace(x/s^4, t), x*t^3/6*heaviside(t))) ***** test - % Growth - A = AA; B = BB; - A(1,5) = 10; - B(1,5) = 10; - assert (isequal (A, B)) -***** shared + % pick s even it has assumptions + syms s real + syms x t + assert (isequal (ilaplace (x/s^2, t), x*t*heaviside(t))) +10 tests, 10 passed, 0 known failure, 0 skipped +[inst/@sym/sech.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sech.m +***** error sech (sym(1), 2) +***** assert (isequaln (sech (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - % Check row deletion 1D - a = sym([1; 3; 5]); - b = sym([3; 5]); - a(1) = []; - assert( isequal( a, b)) + f1 = sech(x); + f2 = sech(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % Check column deletion 1D - a = sym([1, 4, 8]); - b = sym([4, 8]); - a(1) = []; - assert( isequal( a, b)) + D = [d d; d d]; + A = [x x; x x]; + f1 = sech(A); + f2 = sech(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % Check row deletion 2D - a = sym([1, 2; 3, 4]); - b = sym([3, 4]); - a(1, :) = []; - assert( isequal( a, b)) + % round trip + y = sym('y'); + A = sech (d); + f = sech (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/argnames.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/argnames.m ***** test - % Check column deletion 2D - a = sym([1, 2; 3, 4]); - b = sym([2; 4]); - a(:, 1) = []; - assert( isequal( a, b)) + % basic tests + syms x + f = 2*x; + assert (isempty (argnames(x))) + assert (isempty (argnames(f))) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/ezcontour.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ezcontour.m +***** error + syms x y z + ezcontour (x*y*z) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/prod.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/prod.m +***** error prod (sym(1), 2, 3) +***** error prod (sym(1), 42) +***** shared x,y,z + syms x y z +***** assert (isequal (prod (x), x)) +***** assert (isequal (prod ([x y z]), x*y*z)) +***** assert (isequal (prod ([x; y; z]), x*y*z)) +***** assert (isequal (prod ([x y z], 1), [x y z])) +***** assert (isequal (prod ([x y z], 2), x*y*z)) +***** shared a,b + b = [1 2; 3 4]; a = sym(b); +***** assert (isequal (prod(a), prod(b))) +***** assert (isequal (prod(a,1), prod(b,1))) +***** assert (isequal (prod(a,2), prod(b,2))) ***** test - % General assign - a = sym([1, 2; 3, 4]); - b = sym([5, 5; 5, 5]); - a(:) = 5; - assert( isequal( a, b)) + % weird inputs + a = prod('xx', sym(1)); + assert (isequal (a, sym('xx'))) +11 tests, 11 passed, 0 known failure, 0 skipped +[inst/@sym/log.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/log.m +***** error log (sym(1), 2) +***** assert (isequaln (log (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - % Empty matrix - a = sym([1, 2; 3, 4]); - a(:) = []; - assert( isequal( a, sym([]))) + f1 = log(x); + f2 = log(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % Disassemble matrix - a = sym([1 2; 3 4; 5 6]); - b = sym([3 5 2 4 6]); - a(1) = []; - assert (isequal (a, b)); -***** error - a = sym([1, 2; 3, 4]); - a(1, 2) = []; + D = [d d; d d]; + A = [x x; x x]; + f1 = log(A); + f2 = log(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % Issue #964 - a = sym(10); - a(1) = []; - assert (isempty (a)) - assert (isequal (a, zeros(1, 0))) + % round trip + y = sym('y'); + A = log (d); + f = log (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/horzcat.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/horzcat.m ***** test - % Issue #963: scalar asgn to empty part of matrix - A = sym (magic (3)); - B = A; - A(1, []) = 42; - assert (isequal (A, B)) - A([], 2) = 42; - assert (isequal (A, B)) - A([]) = 42; - assert (isequal (A, B)) - A([], []) = 42; - assert (isequal (A, B)) - A(2:3, []) = 42; - assert (isequal (A, B)) - A([], 2:3) = 42; - assert (isequal (A, B)) - A(:, []) = 42; - assert (isequal (A, B)) - A([], :) = 42; - assert (isequal (A, B)) + % basic + syms x + A = [x x]; + B = horzcat(x, x); + C = horzcat(x, x, x); + assert (isa (A, 'sym')) + assert (isa (B, 'sym')) + assert (isa (C, 'sym')) + assert (isequal (size(A), [1 2])) + assert (isequal (size(B), [1 2])) + assert (isequal (size(C), [1 3])) ***** test - % Issue #1026 - a = sym(1:5); - a(1:3) = []; - assert (isequal (a, sym([4 5]))) + % basic, part 2 + syms x + A = [x 1]; + B = [1 x]; + C = [1 2 x]; + assert (isa (A, 'sym')) + assert (isa (B, 'sym')) + assert (isa (C, 'sym')) + assert (isequal (size(A), [1 2])) + assert (isequal (size(B), [1 2])) + assert (isequal (size(C), [1 3])) ***** test - % Issue #1026 - B = eye(4); - A = sym(B); - A(1:2, :) = []; - B(1:2, :) = []; - assert (isequal (A, B)) -***** error - % TODO: do we care what error? - A = sym (magic (3)); - A(2:3, []) = [66; 66]; -***** error - A = sym (magic (3)); - A([]) = [66; 66]; -***** error - A = sym (magic (3)); - A([], 1) = [66; 66]; + % row vectors + a = [sym(1) 2]; + b = [sym(3) 4]; + assert (isequal ( [a b] , [1 2 3 4] )) + assert (isequal ( [a 3 4] , [1 2 3 4] )) + assert (isequal ( [3 4 a] , [3 4 1 2] )) + assert (isequal ( [a [3 4]] , [1 2 3 4] )) + assert (isequal ( [a sym(3) 4] , [1 2 3 4] )) + assert (isequal ( [a [sym(3) 4]] , [1 2 3 4] )) ***** test - % Issue #966: empty indexing, empty RHS, A unchanged - B = magic(3); - A = sym(B); - A(1, []) = []; - assert (isequal (A, B)) - A([], 2) = []; - assert (isequal (A, B)) - A([], []) = []; - assert (isequal (A, B)) - A(2:3, []) = []; - assert (isequal (A, B)) - A([], 2:3) = []; - assert (isequal (A, B)) - A(:, []) = []; - assert (isequal (A, B)) - A([], :) = []; - assert (isequal (A, B)) + % col vectors + a = [sym(1); 2]; + b = [sym(3); 4]; + assert (isequal ( [a b] , [1 3; 2 4] )) + assert (isequal ( [a b a] , [1 3 1; 2 4 2] )) ***** test - % Issue 967 - B = [1 2; 3 4]; - A = sym(B); - A([]) = []; - assert (isequal (A, B)) + % empty vectors + v = sym(1); + a = [v []]; + assert (isequal (a, v)) + a = [[] v []]; + assert (isequal (a, v)) + a = [v [] []]; + assert (isequal (a, v)) ***** test - % Issue #965 - a = sym(7); - a([]) = []; - assert (isequal (a, sym(7))) + % more empty vectors + v = [sym(1) sym(2)]; + q = sym(ones(1, 0)); + assert (isequal ([v q], v)) +***** error + v = [sym(1) sym(2)]; + q = sym(ones(3, 0)); + w = horzcat(v, q); ***** test - % Issue #965 - a = sym(7); - a([]) = 42; - assert (isequal (a, sym(7))) -***** error - % Issue #965 - a = sym(7); - a([]) = [42 42] + % issue #700 + A = sym ([1 2]); + B = simplify (A); + assert (isequal ([B A], [A B])) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/simplify.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/simplify.m +***** shared x,p,q + syms x + p = x^2 + x + 1; + q = horner (p); +***** assert(~isequal( p - q, 0)) +***** assert(isequal( simplify(p - q), 0)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/cosh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cosh.m +***** error cosh (sym(1), 2) +***** assert (isequaln (cosh (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - b = eye (3); - a = sym (b); - I = [2 3; 4 5]; - a(I) = -2*I; - b(I) = -2*I; - assert (isequal (a, sym (b))); - assert (size (a), [3 3]); + f1 = cosh(x); + f2 = cosh(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % 2D indexing with length in one dimension more than 2 - a = sym ([1 2; 3 4; 5 6]); - indices = [1 4; 2 5; 3 6]; - b = [10 11; 12 13; 14 15]; - a(indices) = b; - assert (isequal (a, sym (b))); + D = [d d; d d]; + A = [x x; x x]; + f1 = cosh(A); + f2 = cosh(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - A = sym ([0 0 0]); - indices = [false true false]; - A(indices) = 1; - assert (isequal (A, sym ([0 1 0]))); - A(indices) = []; - assert (isequal (A, sym ([0 0]))); - indices = [false false]; - A(indices) = []; - assert (isequal (A, sym ([0 0]))); -***** shared a, b - a = [1 2 3 5; 4 5 6 9; 7 5 3 2]; - b = sym (a); + % round trip + y = sym('y'); + A = cosh (d); + f = cosh (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/max.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/max.m ***** test - A = a; B = b; - A(true) = 0; - B(true) = 0; - assert (isequal (A, B)) + % simple + assert (isequal (max([sym(10) sym(11)]), sym(11))) ***** test - A = a; B = b; - A(false) = 0; - B(false) = 0; - assert (isequal (A, B)) + syms x y + assert (isequal (children (max (x, y)), [x y])) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/setxor.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/setxor.m ***** test - c = [false true]; - A = a; B = b; - A(c) = 0; B(c) = 0; - assert (isequal (A, B)) - d = c | true; - A(d) = 1; B(d) = 1; - assert (isequal (A, B)) - d = c & false; - A(d) = 2; B(d) = 2; - assert (isequal (A, B)) + A = sym([1 2 3]); + B = sym([1 2 4]); + C = setxor(A, B); + D1 = sym([3 4]); + D2 = sym([4 3]); + assert (isequal (C, D1) || isequal (C, D2)) ***** test - c = [false true false true; true false true false; false true false true]; - A = a; B = b; - A(c) = 0; B(c) = 0; - assert (isequal (A, B)) - d = c | true; - A(d) = 1; B(d) = 1; - assert (isequal (A, B)) - d = c & false; - A(d) = 2; B(d) = 2; - assert (isequal (A, B)) + % one nonsym + A = sym([1 2 3]); + B = [1 2 4]; + C = setxor(A, B); + D1 = sym([3 4]); + D2 = sym([4 3]); + assert (isequal (C, D1) || isequal (C, D2)) ***** test - c = [false true false true false]; - A = a; B = b; - A(c) = 0; B(c) = 0; - assert (isequal (A, B)) - d = c | true; - A(d) = 1; B(d) = 1; - assert (isequal (A, B)) - d = c & false; - A(d) = 2; B(d) = 2; - assert (isequal (A, B)) + % empty + A = sym([1 2 3]); + C = setxor(A, A); + assert (isempty (C)) ***** test - c = [false; true; false; true; false]; - A = a; B = b; - A(c) = 0; B(c) = 0; - assert (isequal (A, B)) - d = c | true; - A(d) = 1; B(d) = 1; - assert (isequal (A, B)) - d = c & false; - A(d) = 2; B(d) = 2; - assert (isequal (A, B)) + % empty input + A = sym([1 2]); + C = setxor(A, []); + assert (isequal (C, A) || isequal (C, sym([2 1]))) ***** test - c = [false true; false true; true false]; - A = a; B = b; - A(c) = 0; B(c) = 0; - assert (isequal (A, B)) - d = c | true; - A(d) = 1; B(d) = 1; - assert (isequal (A, B)) - d = c & false; - A(d) = 2; B(d) = 2; - assert (isequal (A, B)) -76 tests, 76 passed, 0 known failure, 0 skipped + % scalar + syms x + assert (isequal (setxor([x 1], x), sym(1))) + assert (isempty (setxor(x, x))) +***** test + A = interval(sym(1), 3); + B = interval(sym(2), 5); + C = setxor(A, B); + D = union (interval (sym(1), 2, false, true), interval (sym(3), 5, true, false)); + assert( isequal( C, D)) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/ellipticF.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticF.m +***** error ellipticF (sym(1)) +***** error ellipticF (sym(1), 2, 3) +***** assert (double (ellipticF (sym (pi)/3, sym (-105)/10)), 0.6184459461, 10e-11) +***** assert (double (ellipticF (sym (pi)/4, sym (-pi))), 0.6485970495, 10e-11) +***** assert (double (ellipticF (sym (1), sym (-1))), 0.8963937895, 10e-11) +***** assert (double (ellipticF (sym (pi)/6, sym (0))), 0.5235987756, 10e-11) +***** test + % compare to Maple + us = vpa (ellipticF (sym(11)/10, sym(9)/4), 40); + % > evalf(EllipticF(sin(11/10), sqrt(9/4)), 40); + maple = vpa ('1.206444996991058996424988192917728014427', 40) - ... + vpa ('0.8157358125823472313001683083685348517476j', 40); + assert (abs (double (maple - us)), 0, 1e-39) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/polylog.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/polylog.m +***** assert (isequal (polylog (sym('s'), 0), sym(0))) +***** assert (isequal (double (polylog (1, sym(-1))), -log(2))) +***** assert (isequal (double (polylog (0, sym(2))), -2)) +***** assert (isequal (double (polylog (-1, sym(2))), 2)) +***** assert (isequal (double (polylog (-2, sym(3))), -1.5)) +***** assert (isequal (double (polylog (-3, sym(2))), 26)) +***** assert (isequal (double (polylog (-4, sym(3))), -15)) +***** assert (isequal (double (polylog (1, sym(1)/2)), log(2))) +***** test + % round trip + syms s z + f = polylog (s, z); + h = function_handle (f, 'vars', [s z]); + A = h (1.1, 2.2); + B = polylog (1.1, 2.2); + assert (A, B) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/disp.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/disp.m +***** test + syms x + s = disp(sin(x)); + assert(strcmp(s, sprintf(' sin(x)\n'))) +***** test + syms x + s = disp(sin(x/2), 'flat'); + assert(strcmp(s, sprintf(' sin(x/2)\n'))) +***** test + % Examples of 2x0 and 0x2 empty matrices: + a = sym([1 2; 3 4]); + b2x0 = a([true true], [false false]); + b0x2 = a([false false], [true true]); + assert (isequal (size (b2x0), [2 0])) + assert (isequal (size (b0x2), [0 2])) + s = disp(b2x0); + assert(strcmp(s, sprintf(' []\n'))) + s = disp(b0x2); + assert(strcmp(s, sprintf(' []\n'))) +3 tests, 3 passed, 0 known failure, 0 skipped [inst/@sym/pretty.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/pretty.m ***** test @@ -9391,123 +9490,522 @@ swin = strrep(s1, sprintf('\r\n'), sprintf('\n')); assert (strcmp (s1, s2) || strcmp (swin, s2)) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/ge.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ge.m +[inst/@sym/nnz.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/nnz.m +***** assert (nnz (sym ([1])) == 1) +***** assert (nnz (sym ([0])) == 0) +***** assert (nnz (sym ([])) == 0) +***** assert (nnz (sym ([1 0; 0 3])) == 2) ***** test - % simple - x = sym(1); y = sym(1); e = x >= y; - assert (logical (e)) - x = sym(1); y = sym(2); e = x >= y; - assert (~logical(e)) + syms x + assert (nnz ([x 0]) == 1) +***** assert (nnz (sym (true)) == 1) +***** assert (nnz (sym (false)) == 0) +***** assert (nnz (sym (inf)) == 1) +***** assert (nnz (sym (nan)) == 1) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/uminus.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/uminus.m ***** test - % array -- array + % scalar syms x - a = sym([1 3 3 2*x]); - b = sym([2 x 3 10]); - e = a >= b; - assert (isa (e, 'sym')) - assert (~logical (e(1))) - assert (isa (e(2), 'sym')) - assert (isequal (e(2), 3 >= x)) - assert (logical (e(3))) - assert (isa (e(4), 'sym')) - assert (isequal (e(4), 2*x >= 10)) + assert (isa (-x, 'sym')) + assert (isequal (-(-x), x)) +***** test + % matrix + D = [0 1; 2 3]; + A = sym(D); + assert( isequal( -A, -D )) 2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/qr.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/qr.m -***** error qr (sym(1), 2, 3) -***** error [Q, R, P] = qr (sym(1)) -***** error qr (sym(1), 1) +[inst/@sym/ellipticCPi.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticCPi.m +***** error ellipticCPi (sym (1)) +***** error ellipticCPi (sym (1), 2, 3) +***** assert (double (ellipticCPi (0, sym (1)/2)), 1.854074677, 10e-10) +***** assert (double (ellipticCPi (sym (6)/10, sym(71)/10)), 1.29469534336658, -20*eps) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/acsc.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/acsc.m +***** error acsc (sym(1), 2) +***** assert (isequaln (acsc (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - % scalar - [q, r] = qr(sym(6)); - assert (isequal (q, sym(1))) - assert (isequal (r, sym(6))) + f1 = acsc(x); + f2 = acsc(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - syms x positive - [q, r] = qr(x); - assert (isequal (q*r, x)) - assert (isequal (q, sym(1))) - assert (isequal (r, x)) + D = [d d; d d]; + A = [x x; x x]; + f1 = acsc(A); + f2 = acsc(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % trickier if x could be zero, fails on 1.8 <= SymPy <= 1.10.1 + % round trip + y = sym('y'); + A = acsc (d); + f = acsc (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/ctranspose.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ctranspose.m +***** test + x = sym(1); + assert (isequal (x', x)) +***** assert (isempty (sym([])')) +***** test + % conjugate does nothing to real x + syms x real + assert (isequal (x', x)) +***** test + % complex syms x - [q, r] = qr(x); - if (pycall_sympy__ ('return Version(spver) > Version("1.10.1")')) - assert (isequal (q*r, x)) - end + assert (isequal (x', conj(x))) +***** test + % complex array + syms x + A = [x 2*x]; + B = [conj(x); 2*conj(x)]; + assert(isequal(A', B)) ***** test A = [1 2; 3 4]; - B = sym(A); - [Q, R] = qr(B); - assert (isequal (Q*R, B)) - assert (isequal (R(2,1), sym(0))) - assert (isequal (Q(:,1)'*Q(:,2), sym(0))) - %[QA, RA] = qr(A) - %assert ( max(max(double(Q)-QA)) <= 10*eps) - %assert ( max(max(double(Q)-QA)) <= 10*eps) + assert(isequal( sym(A)' , sym(A') )) ***** test - % non square: tall skinny - A = sym([1 2; 3 4; 5 6]); - [Q, R] = qr (A, 0); - assert (size (Q), [3 2]) - assert (size (R), [2 2]) - assert (isequal (Q*R, A)) + A = [1 2] + 1i; + assert(isequal( sym(A)' , sym(A') )) ***** test - % non square: short fat - A = sym([1 2 3; 4 5 6]); - [Q, R] = qr (A); - assert (isequal (Q*R, A)) + % true/false + t = sym(true); + f = sym(false); + assert (isequal ( t', t)) + assert (isequal ( f', f)) ***** test - % non square: short fat, rank deficient - A = sym([1 2 3; 2 4 6]); - [Q, R] = qr (A); - assert (isequal (Q*R, A)) - A = sym([1 2 3; 2 4 6; 0 0 0]); - [Q, R] = qr (A); - assert (isequal (Q*R, A)) + % more true/false + syms x + A = [x true 1i]; + B = [conj(x); true; -sym(1i)]; + assert (isequal ( A', B)) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/interval.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/interval.m ***** test - % rank deficient - A = sym([1 2 3; 2 4 6; 0 0 0]); - [Q, R] = qr (A); - assert (isequal (Q*R, A)) - A = sym([1 2 3; 2 5 6; 0 0 0]); - [Q, R] = qr (A); - assert (isequal (Q*R, A)) + a = interval(sym(1), 2); + assert (isa (a, 'sym')) ***** test - % single return value R not Q - assert (isequal (qr (sym(4)), sym(4))) -12 tests, 12 passed, 0 known failure, 0 skipped -[inst/@sym/cosint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cosint.m -***** error cosint (sym(1), 2) -***** xtest - assert (isequaln (cosint (sym(nan)), sym(nan))) -!!!!! known failure -assert (isequaln (cosint (sym (nan)), sym (nan))) failed + % some set subtraction + a = interval(sym(0), 4); + b = interval(sym(0), 1); + c = interval(sym(1), 4, true); + q = a - b; + assert (isequal( q, c)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/tan.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/tan.m +***** error tan (sym(1), 2) +***** assert (isequaln (tan (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = cosint(x); - f2 = 0.3374039229009681346626; + f1 = tan(x); + f2 = tan(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = cosint(A); - f2 = 0.3374039229009681346626; - f2 = [f2 f2; f2 f2]; + f1 = tan(A); + f2 = tan(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = cosint (d); - f = cosint (y); + A = tan (d); + f = tan (y); h = function_handle (f); B = h (d); assert (A, B, -eps) -5 tests, 4 passed, 1 known failure, 0 skipped +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/besselh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselh.m +***** test + % default to k=1 + syms z a + A = besselh(a, z); + B = besselh(a, 1, z); + assert (isequal (A, B)) +***** error besselh(sym('z')) +***** error besselh(2, 0, sym('z')) +***** error besselh(2, 3, sym('z')) +***** test + % doubles, relative error + X = [1 2 pi; 4i 5 6+6i]; + Xs = sym(X); + Alpha = [pi 3 1; 3 2 0]; + Alphas = sym(Alpha); + for k = 1:2 + A = double(besselh(Alphas, k, Xs)); + B = besselh(Alpha, k, X); + assert (all (all (abs(A - B) < 10*eps*abs(A)))) + end +***** test + % round-trip + syms x + for k = 1:2 + A = besselh(4, k, 10); + q = besselh(4, k, x); + h = function_handle(q); + B = h(10); + assert (abs(A - B) <= eps*abs(A)) + end +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/findsym.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/findsym.m +***** assert (strcmp (findsym (sym(2)), '')); +***** shared x,y,f + x=sym('x'); y=sym('y'); f=x^2+3*x*y-y^2; +***** assert (strcmp (findsym (f), 'x,y')); +***** assert (strcmp (findsym (f,1), 'x')); +***** test + % test order of returned vars + syms x y a b c xx + % https://www.mathworks.com/matlabcentral/newsreader/view_thread/237730 + alpha = sym('alpha'); + assert (strcmp (findsym(b*xx*exp(alpha) + c*sin(a*y), 2), 'xx,y')) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/zeta.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/zeta.m +***** error zeta (sym(1), 2, 3) +***** assert (isequaln (zeta (sym(nan)), sym(nan))) +***** test + f1 = zeta (sym(2)); + f2 = pi^2/6; + assert (double (f1), f2, -1e-15) +***** test + A = sym([0 2; 4 6]); + f1 = zeta (A); + f2 = [-1/2 pi^2/6; pi^4/90 pi^6/945]; + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + f = zeta (y); + h = function_handle (f); + A = zeta (2); + B = h (2); + assert (A, B, -eps) +***** test + syms x + assert (isequal (zeta (0, x), zeta(x))) +***** test + % ensure its the nth deriv wrt x, not the n deriv + syms x n + F = zeta (n, x); + F = subs(F, n, 3); + assert (isequal (F, diff (zeta (x), x, x, x))) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/isallconstant.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isallconstant.m +***** assert (isallconstant([sym(1) 2 3])) +***** test + syms x + assert (~isallconstant([sym(1) x 3])) +***** test + syms x + assert (~isallconstant([sym(1) x; sym(2) 3])) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/coth.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/coth.m +***** error coth (sym(1), 2) +***** assert (isequaln (coth (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); +***** test + f1 = coth(x); + f2 = coth(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = coth(A); + f2 = coth(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = coth (d); + f = coth (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/gammaln.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/gammaln.m +***** assert (isequal (gammaln (sym (3)), log (sym (2)))) +***** assert (isequal (gammaln (sym (10)), log (gamma (sym (10))))) +***** test + % compare to Maple: evalf(lnGAMMA(Pi)); + maple = vpa ('0.827694592323437101529578558452359951153502', 40); + us = vpa (gammaln (sym(pi)), 40); + assert (abs(double(maple-us)) < 1e-39) +***** test + % compare to Maple: evalf(lnGAMMA(3+2*I)); + maple = vpa ('-0.0316390593739611898037677296008797172022603', 40) + ... + vpa ('2.02219319750132712401643376238334982100512j', 40); + us = vpa (gammaln (sym(3) + 2i), 40); + assert (abs(double(maple-us)) < 1e-39) +***** test + % compare to Maple: evalf(lnGAMMA(-1.5)); + % notably, @double/gammaln has zero imag part + maple = vpa ('0.8600470153764810145109326816703567873271571', 40) - ... + vpa ('6.2831853071795864769252867665590057683943388j', 40); + us = vpa (gammaln (-sym(3)/2), 40); + assert (abs(double(maple-us)) < 1e-39) +***** assert (gammaln (pi), double (gammaln (sym (pi))), -3*eps) +***** assert (gammaln (100), double (gammaln (sym (100))), -3*eps) +***** assert (gammaln (1e-3), double (gammaln (1/sym (1e3))), -100*eps) +***** test + % round trip + syms x + f = gammaln (x); + h = function_handle (f); + A = h (1.1); + B = gammaln (1.1); + assert (A, B) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/lu.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/lu.m +***** test + % scalar + [l, u, p] = lu(sym(6)); + assert (isequal (l, sym(1))) + assert (isequal (u, sym(6))) + assert (isequal (p, sym(1))) + syms x + [l, u, p] = lu(x); + assert (isequal (l*u, p*x)) + [l, u] = lu(x); + assert (isequal (l*u, x)) +***** test + % perm + A = sym(fliplr(2*eye(3))); + [L, U, P] = lu(A); + assert (isequal (L*U, P*A)) + [L, U, P] = lu(A, 'matrix'); + assert (isequal (L*U, P*A)) + [L, U, p] = lu(A, 'vector'); + assert (isequal (L*U, A(p,:))) + [L, U] = lu(A); + assert (isequal (L*U, A)) +***** test + % p is col vectpr + A = sym([0 2; 3 4]); + [L, U, p] = lu(A, 'vector'); + assert(iscolumn(p)) +***** test + % simple matrix + A = [1 2; 3 4]; + B = sym(A); + [L, U, P] = lu(B); + assert (isequal (L*U, P*B)) + assert (isequal (U(2,1), sym(0))) + % needs pivot + A = [0 2; 3 4]; + B = sym(A); + [L, U, P] = lu(B); + [Ld, Ud, Pd] = lu(A); + assert (isequal (L*U, P*A)) + assert (isequal (U(2,1), sym(0))) + % matches regular LU + assert ( max(max(double(L)-Ld)) <= 10*eps) + assert ( max(max(double(U)-Ud)) <= 10*eps) + assert ( isequal (P, Pd)) +***** test + % rectangular + A = sym([1 2; 3 4; 5 6]); + [L, U] = lu (A); + assert (isequal (L*U, A)) +***** test + % rectangular + A = sym([1 2 3; 4 5 6]); + [L, U] = lu (A); + assert (isequal (L*U, A)) +***** test + % rectangular, repeated row + A = sym([1 2 3; 2 4 6]); + [L, U] = lu (A); + assert (isequal (L*U, A)) +***** test + % rectangular, needs permutation + A = sym([0 0 0; 1 2 3]); + [L, U] = lu (A); + assert (isequal (L*U, A)) + assert (~isequal (tril (L), L)) + [L, U, P] = lu (A); + assert (isequal (L*U, P*A)) + assert (isequal (tril (L), L)) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/coeffs.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/coeffs.m +***** error coeffs (sym(1), 2, 3, 4) +***** error coeffs (sym(1), 2, 'al') +***** error coeffs (sym(1), 'al') +***** test + % simple + syms x + [c, t] = coeffs(6*x*x + 27); + assert (isequal (c, [6 27])) + assert (isequal (t, [x*x 1])) +***** test + % specify a variable + syms x + [c, t] = coeffs(6*x*x + 27, x); + assert (isequal (c, [6 27])) + assert (isequal (t, [x*x 1])) +***** test + % specify another variable + syms x y + [c, t] = coeffs(6*x + 27, y); + assert (isequal (c, 6*x + 27)) + assert (isequal (t, 1)) +***** test + % weird SMT order + syms x + a1 = [27 6]; + a2 = [6 27]; + c = coeffs(6*x*x + 27); + assert (isequal (c, a1)) + coeffs(6*x*x + 27); + assert (isequal (ans, a1)) + [c, t] = coeffs(6*x*x + 27); + assert (isequal (c, a2)) +***** test + % no weird order with "all" + syms x + c = coeffs(6*x*x + 27, 'all'); + assert (isequal (c, [6 0 27])) +***** test + % "all" + syms x + [c, t] = coeffs(6*x*x + 27, 'all'); + assert (isequal (c, [6 0 27])) + assert (isequal (t, [x^2 x 1])) +***** test + % "All" + syms x + [c, t] = coeffs(6*x, 'All'); + assert (isequal (c, [6 0])) + assert (isequal (t, [x 1])) +***** test + % multivariable array + syms x y + [c, t] = coeffs(6*x*x + 27*y*x + 36, [x y]); + a = [6 27 36]; + s = [x^2 x*y 1]; + assert (isequal (c, a)) + assert (isequal (t, s)) + % with list + [c, t] = coeffs(6*x*x + 27*y*x + 36, {x y}); + assert (isequal (c, a)) + assert (isequal (t, s)) +***** test + % other symbols treated as part of coeffs + syms x y + [c, t] = coeffs(6*x*x + 27*y*x + 36, x); + a = [6 27*y 36]; + s = [x^2 x 1]; + assert (isequal (c, a)) + assert (isequal (t, s)) +***** error + % TODO: multivariate all not working (https://github.com/cbm755/octsympy/issues/720) + syms x y + [c, t] = coeffs(6*x^2 + 7*y + 19, [x y], 'all'); +***** test + % empty same as not specifying; maybe not SMT compatible: + % https://github.com/cbm755/octsympy/pull/708#discussion_r94292831 + syms x y + [c, t] = coeffs(6*x*x + 27*y*x + 36, {}); + a = [6 27 36]; + assert (isequal (c, a)) + [c, t] = coeffs(6*x*x + 27*y*x + 36); + assert (isequal (c, a)) +***** test + % no input defaults to all symbols (not symvar to get x) + syms x y + [c, t] = coeffs(6*x*x + 27*y*x + 36); + assert (isequal (c, [6 27 36])) +***** test + % non sym input + syms x + assert (isequal (coeffs(6, x), sym(6))) +***** test + % constant input without x + assert (isequal (coeffs(sym(6)), sym(6))) +***** test + % constant input without x + assert (isequal (coeffs (sym(6), {}), sym(6))) + % irrational coefficients + syms x + f = x^2 + sqrt(sym(2))*x; + [c1, t1] = coeffs (f); + [c2, t2] = coeffs (f, x); + assert (isequal (c1, c2)) + assert (isequal (t1, t2)) +18 tests, 18 passed, 0 known failure, 0 skipped +[inst/@sym/cross.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cross.m +***** error cross (sym(1), 2, 3) +***** test + a = sym([1; 0; 0]); + b = sym([0; 1; 0]); + c = cross(a, b); + assert (isequal (c, sym([0; 0; 1]))) +***** test + syms x + a = sym([x; 0; 0]); + b = sym([0; 1; 0]); + c = cross(a, b); + assert (isequal (c, sym([0; 0; x]))) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/factor.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/factor.m +***** test + % n = 152862; + % [p,m] = factor(n); % only works on Octave, no Matlab as of 2014a + n = 330; % so we use an output without repeated factors + p = factor(n); m = ones(size(p)); + [ps,ms] = factor(sym(n)); + assert (isequal (p, ps)) + assert (isequal (m, ms)) +***** test + n = sym(2)^4*13; + [p,m] = factor(n); + assert (isequal (p, [2 13])) + assert (isequal (m, [4 1])) +***** test syms x + assert( logical (factor(x^2 + 6*x + 5) == (x+5)*(x+1))) +***** test + syms x + f = [ x^4/2 + 5*x^3/12 - x^2/3 x^2 - 1 10]; + g = [ x^2*(2*x - 1)*(3*x + 4)/12 (x+1)*(x-1) 10]; + assert (isequal (factor(f), g)) +***** test + % "fragile form" works + A = factor(sym(124)); + B = strtrim(disp(A, 'flat')); + assert (strcmp (B, '2**2*31**1')) +***** error [p, m] = factor(sym('x')); +***** error [p, m] = factor(sym(42), sym('x')); +***** test + % if polynomial happens to be a constant, don't attempt integer + % factorization if a variable is specified + f = sym(42); + q = factor(f, sym('x')); + assert (isequal (f, q)); +8 tests, 8 passed, 0 known failure, 0 skipped [inst/@sym/hessian.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/hessian.m ***** error hessian (sym(1), 2, 3) @@ -9555,440 +10053,266 @@ H = hessian(f, {x y z}); assert (isequal (H, Hexp)) 9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/setdiff.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/setdiff.m -***** test - A = sym([1 2 3]); - B = sym([1 2 4]); - C = setdiff(A, B); - D = sym([3]); - assert (isequal (C, D)) +[inst/@sym/sign.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sign.m +***** error sign (sym(1), 2) +***** assert (isequaln (sign (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - % one nonsym - A = sym([1 2 3]); - B = [1 2 4]; - C = setdiff(A, B); - D = sym([3]); - assert (isequal (C, D)) + f1 = sign(x); + f2 = sign(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % empty - A = sym([1 2 3]); - C = setdiff(A, A); - assert (isempty (C)) + D = [d d; d d]; + A = [x x; x x]; + f1 = sign(A); + f2 = sign(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % empty input - A = sym([1 2]); - C = setdiff(A, []); - assert (isequal (C, A) || isequal (C, sym([2 1]))) + % round trip + y = sym('y'); + A = sign (d); + f = sign (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/double.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/double.m ***** test - % scalar - syms x - assert (isequal (setdiff([x 1], x), sym(1))) - assert (isempty (setdiff(x, x))) + % numeric scalar + a = double(sym(10)); + assert (a == 10) + assert (isa (a, 'double')) ***** test - A = interval(sym(1), 3); - B = interval(sym(2), 5); - C = setdiff(A, B); - assert( isequal( C, interval(sym(1), 2, false, true))) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/round.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/round.m + % numeric vectors + a = double(sym([10 12])); + assert (isequal (a, [10 12])) + assert (isa (a, 'double')) ***** test - d = 3/2; - x = sym('3/2'); - f1 = round(x); - f2 = round(d); - assert (isequal (f1, f2)) + % complex + a = 3 + 4i; + b = sym(a); + assert (isequal (double (b), a)) ***** xtest - % ideally rounding direction would match Octave - d = 5/2; - x = sym('5/2'); - f1 = round(x); - f2 = round(d); - assert (isequal (f1, f2)) -!!!!! known failure -assert (isequal (f1, f2)) failed -***** test - D = [1.1 4.6; -3.4 -8.9]; - A = [sym(11)/10 sym(46)/10; sym(-34)/10 sym(-89)/10]; - f1 = round(A); - f2 = round(D); - assert( isequal (f1, f2)) -***** test - d = sym(-11)/10; - c = -1; - assert (isequal (round (d), c)) -***** test - d = sym(-19)/10; - c = -2; - assert (isequal (round (d), c)) -***** test - d = 7j/2; - x = sym(7j)/2; - f1 = round (x); - f2 = round (d); - assert (isequal (f1, f2)) -***** test - d = 5/3 - 4j/7; - x = sym(5)/3 - sym(4j)/7; - f1 = round (x); - f2 = round (d); - assert (isequal (f1, f2)) -7 tests, 6 passed, 1 known failure, 0 skipped -[inst/@sym/plus.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/plus.m -***** test - % basic addition - syms x - assert (isa (x+5, 'sym')) - assert (isa (5+x, 'sym')) - assert (isa (5+sym(4), 'sym')) - assert (isequal (5+sym(4), sym(9))) -***** test - % array addition - syms x - D = [0 1; 2 3]; - A = [sym(0) 1; sym(2) 3]; - DZ = D - D; - assert( isequal ( A + D , 2*D )) - assert( isequal ( D + A , 2*D )) - assert( isequal ( A + A , 2*D )) - assert( isequal ( A + 2 , D + 2 )) - assert( isequal ( 4 + A , 4 + D )) -***** test - % ensure MatrixExpr can be manipulated somewhat - syms n m integer - A = sym('A', [n m]); - B = subs(A, [n m], [5 6]); - B = B + 1; - assert (isa (B, 'sym')) - C = B(1, 1); % currently makes a MatrixElement - C = C + 1; - assert (isa (C, 'sym')) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/ellipke.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipke.m -***** error ellipke (sym(1), 2) -***** test - for i = 2:10 - [K E] = ellipke (sym (1)/i); - [k e] = ellipke (1/i); - assert (double ([K E]), [k e], 2*eps) - end -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/linspace.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/linspace.m + % unexpected, precisely same floating point + a = 3 + 4i; + b = sym(a); + assert (isequal (double (b/pi), a/pi)) ***** test - a = linspace(sym(3), 5, 5); - b = [sym(6) 7 8 9 10]/2; - assert (isequal (a, b)) + % floating point + x = sqrt(sym(2)); + assert( abs(double(x) - sqrt(2)) < 2*eps) + x = sym(pi); + assert( abs(double(x) - pi) < 2*eps) ***** test - % non-integers - A = linspace(0, sym(pi), 10); - assert (length (A) == 10); - assert (isequal (A(6), 5*sym(pi)/9)); + oo = sym(inf); + assert( double(oo) == inf ) + assert( double(-oo) == -inf ) + assert( isnan(double(0*oo)) ) ***** test - % default argument for N - A = linspace(1, 100); - assert (length (A) == 100); + zoo = sym('zoo'); + assert (double(zoo) == complex(inf, inf)) ***** test - % special case for just N = 1 - A = linspace(sym(2), 3, 1); - assert (isequal (A, 3)) - A = linspace(sym(2), 3, 0); - assert (isequal (A, 3)) - A = linspace(sym(2), 3, sym(3)/2); - assert (isequal (A, 3)) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/besselk.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselk.m + zoo = sym('zoo'); + assert (double(-zoo) == double(zoo) ) + assert( isnan(double(0*zoo)) ) ***** test - X = [1 2 3; 4 5 6]; - ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; - n = double(ns); - A = double(besselk(ns, X)); - B = besselk(n, X); - assert (all (all (abs (A - B) < 2*eps*abs(A)))) + % nan + snan = sym(nan); + assert( isnan(double(snan))) ***** test - % roundtrip - syms x - A = besselk(2, 10); - q = besselk(2, x); - h = function_handle(q); - B = h(10); - assert (abs (A - B) <= eps*abs(A)) -***** error besselk(sym('x')) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/size.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/size.m + % don't want NaN+NaNi + snan = sym(nan); + assert (isreal (double (snan))) ***** test - a = sym([1 2 3]); - [n,m] = size(a); - assert (n == 1 && m == 3) + % arrays + a = [1 2; 3 4]; + assert( isequal( double(sym(a)), a )) + assert( isequal( double(sym(a)), a )) + % should fail with error for non-double +***** error syms x; double(x) +***** error syms x; double([1 2 x]) +13 tests, 13 passed, 0 known failure, 0 skipped +[inst/@sym/sqrt.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sqrt.m +***** error sqrt (sym(1), 2) +***** assert (isequaln (sqrt (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - a = sym([1 2 3]); - n = size(a); - assert (isequal (n, [1 3])) + f1 = sqrt(x); + f2 = sqrt(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - %% size, numel, length - a = sym([1 2 3; 4 5 6]); - assert (isa (size(a), 'double')) - assert (isa (numel(a), 'double')) - assert (isa (length(a), 'double')) - assert (isequal (size(a), [2 3])) - assert (length(a) == 3) - assert (numel(a) == 6) - a = sym([1; 2; 3]); - assert (isequal (size(a), [3 1])) - assert (length(a) == 3) - assert (numel(a) == 3) + D = [d d; d d]; + A = [x x; x x]; + f1 = sqrt(A); + f2 = sqrt(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - %% size by dim - a = sym([1 2 3; 4 5 6]); - n = size(a, 1); - assert (n == 2) - m = size(a, 2); - assert (m == 3) - a = sym([1 2 3]'); - n = size(a, 1); - assert (n == 3) - m = size(a, 2); - assert (m == 1) -***** xtest - % symbolic-size matrices - syms n m integer - A = sym('A', [n m]); - d = size(A); - assert (~isa(d, 'sym')) - assert (isnumeric(d)) - assert (isequaln (d, [NaN NaN])) -!!!!! known failure -assert (isequaln (d, [NaN, NaN])) failed + % round trip + y = sym('y'); + A = sqrt (d); + f = sqrt (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/harmonic.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/harmonic.m +***** error harmonic (sym(1), 2) ***** xtest - % half-symbolic-size matrices - % FIXME: will fail until size stop lying by saying 1x1 - syms n integer - A = sym('A', [n 3]); - assert (isequaln (size(A), [NaN 3])) - A = sym('A', [4 n]); - assert (isequaln (size(A), [4 NaN])) + assert (isequaln (harmonic (sym(nan)), sym(nan))) !!!!! known failure -assert (isequaln (size (A), [NaN, 3])) failed +assert (isequaln (harmonic (sym (nan)), sym (nan))) failed +***** assert (isequal (harmonic (sym(0)), sym(0))) +***** assert (isinf (harmonic (sym(inf)))) +***** assert (isequal (harmonic (sym([9 10])), [sym(7129)/2520 sym(7381)/2520])) +***** test + % round trip + y = sym('y'); + A = harmonic (7); + f = harmonic (y); + h = function_handle (f); + B = h (7); + assert (A, B, -eps) +6 tests, 5 passed, 1 known failure, 0 skipped +[inst/@sym/factorial.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/factorial.m +***** error factorial (sym(1), 2) ***** xtest - % half-symbolic-size empty matrices - % FIXME: will fail until size stop lying by saying 1x1 - syms n integer - A = sym('A', [n 0]); - assert (isequaln (size(A), [NaN 0])) + assert (isequaln (factorial (sym(nan)), sym(nan))) !!!!! known failure -assert (isequaln (size (A), [NaN, 0])) failed -7 tests, 4 passed, 3 known failures, 0 skipped -[inst/@sym/le.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/le.m -***** test - % simple - x = sym(1); y = sym(1); e = x <= y; - assert (logical (e)) - x = sym(1); y = sym(2); e = x <= y; - assert (logical (e)) -***** test - % array -- array - syms x - a = sym([1 3 3 2*x]); - b = sym([2 x 3 10]); - e = a <= b; - assert (isa (e, 'sym')) - assert (logical (e(1))) - assert (isa (e(2), 'sym')) - assert (isequal (e(2), 3 <= x)) - assert (logical (e(3))) - assert (isa (e(4), 'sym')) - assert (isequal (e(4), 2*x <= 10)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/sympy.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sympy.m -***** assert (strcmp (sympy (sym(pi)), 'pi')) -***** assert (strcmp (sympy (sym(1)), 'Integer(1)')) -***** assert (strcmp (sympy (sym(2)/3), 'Rational(2, 3)')) -***** assert (strcmp (sympy (sym('x')), 'Symbol(''x'')')) -***** test - x = sym('x'); - assert (isequal (sym(sympy(x)), x)) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/taylor.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/taylor.m -***** test - syms x - f = exp(x); - expected = 1 + x + x^2/2 + x^3/6 + x^4/24 + x^5/120; - assert (isequal (taylor(f), expected)) - assert (isequal (taylor(f,x), expected)) - assert (isequal (taylor(f,x,0), expected)) -***** test - syms x - f = exp(x); - expected = 1 + x + x^2/2 + x^3/6 + x^4/24; - assert (isequal (taylor(f,'order',5), expected)) - assert (isequal (taylor(f,x,'order',5), expected)) - assert (isequal (taylor(f,x,0,'order',5), expected)) -***** test - % key/value ordering doesn't matter - syms x - f = exp(x); - g1 = taylor(f, 'expansionPoint', 1, 'order', 3); - g2 = taylor(f, 'order', 3, 'expansionPoint', 1); - assert (isequal (g1, g2)) +assert (isequaln (factorial (sym (nan)), sym (nan))) failed +***** shared x, d + d = 1; + x = sym('1'); ***** test - syms x - f = x^2; - assert (isequal (taylor(f,x,0,'order',0), 0)) - assert (isequal (taylor(f,x,0,'order',1), 0)) - assert (isequal (taylor(f,x,0,'order',2), 0)) - assert (isequal (taylor(f,x,0,'order',3), x^2)) - assert (isequal (taylor(f,x,0,'order',4), x^2)) + f1 = factorial(x); + f2 = factorial(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - syms x y - f = exp(x)+exp(y); - expected = 2 + x + x^2/2 + x^3/6 + x^4/24 + y + y^2/2 + y^3/6 + y^4/24; - assert (isAlways(taylor(f,[x,y],'order',5)== expected)) - assert (isAlways(taylor(f,[x,y],[0,0],'order',5) == expected)) + D = [d d; d d]; + A = [x x; x x]; + f1 = factorial(A); + f2 = factorial(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % key/value ordering doesn't matter - syms x - f = exp(x); - g1 = taylor(f, 'expansionPoint', 1, 'order', 3); - g2 = taylor(f, 'order', 3, 'expansionPoint', 1); - assert (isequal (g1, g2)) + % round trip + y = sym('y'); + A = factorial (d); + f = factorial (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 4 passed, 1 known failure, 0 skipped +[inst/@sym/dirac.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/dirac.m +***** error dirac (sym(1), 2) +***** assert (isequaln (dirac (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - syms x - f = x^2; - assert (isequal (taylor(f,x,0,'order',0), 0)) - assert (isequal (taylor(f,x,0,'order',1), 0)) - assert (isequal (taylor(f,x,0,'order',2), 0)) - assert (isequal (taylor(f,x,0,'order',3), x^2)) - assert (isequal (taylor(f,x,0,'order',4), x^2)) + f1 = dirac(x); + f2 = dirac(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - % syms for a and order - syms x - f = x^2; - assert (isequal (taylor(f,x,sym(0),'order',sym(2)), 0)) - assert (isequal (taylor(f,x,sym(0),'order',sym(4)), x^2)) + D = [d d; d d]; + A = [x x; x x]; + f1 = dirac(A); + f2 = dirac(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - syms x y - f = exp (x^2 + y^2); - expected = 1+ x^2 +y^2 + x^4/2 + x^2*y^2 + y^4/2; - assert (isAlways(taylor(f,[x,y],'order',5)== expected)) - assert (isAlways(taylor(f,[x,y],'expansionPoint', [0,0],'order',5) == expected)) + % round trip + y = sym('y'); + A = dirac (d); + f = dirac (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/potential.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/potential.m +***** error potential (sym(1), 2, 3, 4) +***** shared x,y,z + syms x y z ***** test - syms x y - f = sqrt(1+x^2+y^2); - expected = 1+ x^2/2 +y^2/2 - x^4/8 - x^2*y^2/4 - y^4/8; - assert (isAlways(taylor(f,[x,y],'order',6)== expected)) - assert (isAlways(taylor(f,[x,y],'expansionPoint', [0,0],'order',5) == expected)) + % 1D + f = 3*x^2; + F = x^3; + assert (isequal (potential(f), F)) + assert (isequal (potential(f, x), F)) + assert (isequal (potential(f, x, 0), F)) + assert (isequal (potential(f, x, 2), F - 8)) ***** test - syms x y - f = sin (x^2 + y^2); - expected = sin(sym(1))+2*cos(sym(1))*(x-1)+(cos(sym(1))-2*sin(sym(1)))*(x-1)^2 + cos(sym(1))*y^2; - assert (isAlways(taylor(f,[x,y],'expansionPoint', [1,0],'order',3) == expected)) + F = x*exp(y) + (z-1)^2; + f = gradient(F); + G = potential(f, [x;y;z], [0;1;1]); + assert (isAlways (G == F)) ***** test - % key/value ordering doesn't matter - syms x y - f = exp(x+y); - g1 = taylor(f, 'expansionPoint',1, 'order', 3); - g2 = taylor(f, 'order', 3, 'expansionPoint',1); - assert (isAlways(g1== g2)) + F = x*exp(y); + f = gradient(F); + G = potential(f); + assert (isAlways (G == F)) ***** test + % no potential exists syms x y - f = x^2 + y^2; - assert (isAlways(taylor(f,[x,y],[0,0],'order',0)== sym(0) )) - assert (isAlways(taylor(f,[x,y],[0,0],'order',1)== sym(0) )) - assert (isAlways(taylor(f,[x,y],[0,0],'order',2)== sym(0) )) - assert (isAlways(taylor(f,[x,y],[0,0],'order',3)== sym(x^2 + y^2))) - assert (isAlways(taylor(f,[x,y],[0,0],'order',4)== sym(x^2 + y^2))) -***** test - % expansion point - syms x a - f = x^2; - g = taylor(f,x,2); - assert (isequal (simplify(g), f)) - assert (isequal (g, 4*x+(x-2)^2-4)) - g = taylor(f,x,a); - assert (isequal (simplify(g), f)) -***** test - % wrong order-1 series with nonzero expansion pt: - % upstream bug https://github.com/sympy/sympy/issues/9351 + a = [x; x*y^2]; + assert (isnan (potential (a))) +***** shared +***** xtest + % fails b/c of sympy #8458 (piecewise expr that should simplify) syms x - g = x^2 + 2*x + 3; - h = taylor (g, x, 4, 'order', 1); - assert (isequal (h, 27)) -***** test - syms x y z - g = x^2 + 2*y + 3*z; - h = taylor (g, [x,y,z], 'order', 4); - assert (isAlways(h == g)) ; -***** test - syms x y z - g = sin(x*y*z); - h = taylor (g, [x,y,z], 'order', 4); - assert (isAlways(h == x*y*z)) ; -***** error - syms x y - taylor(0, [x, y], [1, 2, 3]); -18 tests, 18 passed, 0 known failure, 0 skipped -[inst/@sym/sech.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sech.m -***** error sech (sym(1), 2) -***** assert (isequaln (sech (sym(nan)), sym(nan))) + f = cos(x); + assert (isequal (potential(f, x), sin(x))) +!!!!! known failure +assert (isequal (potential (f, x), sin (x))) failed +6 tests, 5 passed, 1 known failure, 0 skipped +[inst/@sym/sinint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinint.m +***** error sinint (sym(1), 2) +***** xtest + assert (isequaln (sinint (sym(nan)), sym(nan))) +!!!!! known failure +assert (isequaln (sinint (sym (nan)), sym (nan))) failed ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = sech(x); - f2 = sech(d); + f1 = sinint(x); + f2 = 0.9460830703671830149414; assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = sech(A); - f2 = sech(D); + f1 = sinint(A); + f2 = 0.9460830703671830149414; + f2 = [f2 f2; f2 f2]; assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = sech (d); - f = sech (y); + A = sinint (d); + f = sinint (y); h = function_handle (f); B = h (d); assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/eye.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/eye.m -***** test - y = eye(sym(2)); - x = [1 0; 0 1]; - assert( isequal( y, sym(x))) -***** test - y = eye(sym(2), 1); - x = [1; 0]; - assert( isequal( y, sym(x))) -***** test - y = eye(sym(1), 2); - x = [1 0]; - assert( isequal( y, sym(x))) -***** test - y = eye (sym([2 3])); - x = sym (eye ([2 3])); - assert (isequal (y, x)) -***** assert( isa( eye(sym(2), 'double'), 'double')) -***** assert( isa( eye(3, sym(3), 'single') , 'single')) -***** assert( isa( eye(3, sym(3)), 'sym')) -***** assert( isa( eye(3, sym(3), 'sym'), 'sym')) -***** xtest - % Issue #13 - assert( isa( eye(3, 3, 'sym'), 'sym')) -!!!!! known failure -invalid data type specified -9 tests, 8 passed, 1 known failure, 0 skipped +5 tests, 4 passed, 1 known failure, 0 skipped +[inst/@sym/ismatrix.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ismatrix.m +***** assert(ismatrix(sym('x'))) +***** assert(ismatrix(sym([1 2 3]))) +***** assert(ismatrix(sym([1; 2]))) +***** assert(ismatrix(sym([1 2; 3 4]))) +***** assert(ismatrix(sym([]))) +***** assert(ismatrix(sym(ones(1,0)))) +***** assert(ismatrix(sym(ones(0,3)))) +7 tests, 7 passed, 0 known failure, 0 skipped [inst/@sym/psi.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/psi.m ***** assert (isequal (psi (sym (1)), -eulergamma)) @@ -10050,771 +10374,703 @@ assert (A, B) end 10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@sym/isequal.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isequal.m +[inst/@sym/jordan.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/jordan.m ***** test - a = sym([1 2]); - b = a; - assert (isequal (a, b)) - b(1) = 42; - assert (~isequal (a, b)) + % basic + A = sym ([2 1 0 0; 0 2 1 0; 0 0 3 0; 0 1 -1 3]); + [V, J] = jordan (A); + assert (isequal (inv (V) * A * V, J)); + assert (isequal (J, sym ([2 1 0 0; 0 2 0 0; 0 0 3 0; 0 0 0 3]))) + % the first 2 generalized eigenvectors form a cycle + assert (isequal ((A - J(1, 1) * eye (4)) * V(:, 1), zeros (4, 1))); + assert (isequal ((A - J(2, 2) * eye (4)) * V(:, 2), V(:, 1))); + % the last 2 generalized eigenvectors are eigenvectors + assert (isequal ((A - J(3, 3) * eye (4)) * V(:, 3), zeros (4, 1))); + assert (isequal ((A - J(4, 4) * eye (4)) * V(:, 4), zeros (4, 1))); ***** test - a = sym([1 2; 3 4]); - b = a; - assert (isequal (a, b)) - b(1) = 42; - assert (~isequal (a, b)) + % scalars + assert (isequal (jordan (sym (-10)), sym (-10))); + assert (isequal (jordan (sym ('x')), sym ('x'))); ***** test - a = sym([nan; 2]); - b = a; - assert (~isequal (a, b)) + % diagonal matrices + A = diag (sym ([6 6 7])); + [V1, D] = eig (A); + [V2, J] = jordan (A); + assert (isequal (V1, V2)); + assert (isequal (D, J)); ***** test - % proper nan treatment - a = sym([nan 2; 3 4]); - b = a; - assert (~isequal (a, b)) + % matrices of unknown entries + A = [sym('a') sym('b'); sym('c') sym('d')]; + [V, D] = eig (A); + J = jordan (A); + assert (isequal (simplify (D), simplify (J))); ***** test - % more than two arrays - a = sym([1 2 3]); - b = a; - c = a; - assert (isequal (a, b, c)) - c(1) = 42; - assert (~isequal (a, b, c)) + % matrices of mixed entries + A = [sym('x')+9 sym('y'); sym(0) 6]; + [V, D] = eig (A); + J = jordan (A); + assert (isequal (simplify (D), simplify (J))); 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/lambertw.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/lambertw.m +[inst/@sym/curl.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/curl.m +***** error curl([sym(1) 2 3], 42, 42) +***** shared x,y,z + syms x y z ***** test - % W(x)*exp(W(x)) == x - syms x - T = lambertw(x)*exp(lambertw(x)); - T = double (subs (T, x, 10)); - assert (isequal (T, 10)); + % double const + f = [1 2 3]; + g = [sym(0); 0; 0]; + assert (isequal (curl(f, [x y z]), g)) + % should fail, calls @double: curl(f, {x y z}), g)) ***** test - % k, x not x, k to match SMT - syms x - T = lambertw(2, x)*exp(lambertw(2, x)); - T = double (subs (T, x, 10)); - assert (abs(T - 10) < 1e-15) -***** assert (isequal (lambertw(sym(0)), sym(0))) -***** assert ( isequal (lambertw (-1/exp(sym(1))), -sym(1))) -***** assert ( isequal (lambertw (0, -1/exp(sym(1))), -sym(1))) -***** assert ( isequal (lambertw (-1, -1/exp(sym(1))), -sym(1))) -***** xtest - % W(x)*exp(W(x)) == x; FIXME: a failure in SymPy? - syms x - T = simplify(lambertw(x)*exp(lambertw(x))); - assert (isequal (T, x)) -!!!!! known failure -assert (isequal (T, x)) failed -***** assert (abs (lambertw(pi) - double(lambertw(sym(pi)))) < 5*eps) -***** assert (abs (lambertw(-1, 5) - double(lambertw(-1, sym(5)))) < 5*eps) -***** assert (abs (lambertw(2, 2) - double(lambertw(2, sym(2)))) < 5*eps) + % div curl always 0 + v = [exp(x); x*y; sin(z)]; + g = curl(v); + a = divergence(g, [x y z]); + assert (isAlways (a == sym(0))) + assert (isa (a, 'sym')) + g = curl(v, [x y z]); + a = divergence(g, [x y z]); + assert (isAlways (a == sym(0))) + assert (isa (a, 'sym')) ***** test - % round trip - syms x k - A = lambertw (5); - f = lambertw (x); - h = function_handle (f); - B = h (5); - assert (A, B) - - A = lambertw (3, 5); - f = lambertw (k, x); - h = function_handle (f); - B = h (3, 5); - assert (A, B) -11 tests, 10 passed, 1 known failure, 0 skipped -[inst/@sym/erfinv.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfinv.m -***** error erfinv (sym(1), 2) -***** assert (isequaln (erfinv (sym(nan)), sym(nan))) -***** shared x, d - d = 1/2; - x = sym('1/2'); + % div curl always 0 + v = [exp(x); erfc(x*y); sin(exp(x)*y+sinh(z))]; + g = curl(v, [x y z]); + a = divergence(g, [x y z]); + assert (isAlways (a == sym(0))) + assert (isa (a, 'sym')) ***** test - f1 = erfinv(x); - f2 = erfinv(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % curl grad is vec zero + f = sin(exp(x)*y+sinh(z)); + g = curl(gradient(f, [x,y,z])); + assert (isequal (g, sym([0;0;0]))) +Waiting..... ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = erfinv(A); - f2 = erfinv(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % 2d fcn in 2d/3d + u = sin(exp(x)*y); + v = x^2*y^3; + vorticity2d = diff(v,x) - diff(u,y); + omega = curl([u; v; 0], [x y z]); + assert (isequal (omega, [0; 0; vorticity2d])) +***** error <3D vector> curl([sym(1) 2 3 4]) +***** error curl([sym(1) 2 3], {sym('x') sym('y') sym('z') sym('t')}) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/angle.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/angle.m ***** test - % round trip - y = sym('y'); - A = erfinv (d); - f = erfinv (y); + Z = [sqrt(sym(3)) + 3*sym(i), 3 + sqrt(sym(3))*sym(i); 1 + sym(i), sym(i)]; + Q = [sym(pi)/3 sym(pi)/6; sym(pi)/4 sym(pi)/2]; + assert( isequal( angle(Z), Q)); +***** test + % roundtrip + syms x + A = angle (2+2i); + f = angle (x); h = function_handle (f); - B = h (d); + B = h (2+2i); assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/bessely.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/bessely.m -***** test - X = [1 2 3; 4 5 6]; - ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; - n = double(ns); - A = double(bessely(ns, X)); - B = bessely(n, X); - assert (all (all (abs (A - B) < 50*eps*abs(A)))) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/mtimes.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/mtimes.m ***** test - % roundtrip + % scalar syms x - A = bessely(2, 10); - q = bessely(2, x); - h = function_handle(q); - B = h(10); - assert (abs (A - B) <= eps*abs(A)) -***** error bessely(sym('x')) + assert (isa (x*2, 'sym')) + assert (isequal (2*sym(3), sym(6))) + assert (isequal (sym(2)*3, sym(6))) +***** test + % matrix-scalar + D = [0 1; 2 3]; + A = sym(D); + assert (isa (2*A, 'sym')) + assert (isequal ( 2*A , 2*D )) + assert (isequal ( A*2 , 2*D )) +***** test + % matrix-matrix + D = [0 1; 2 3]; + A = sym(D); + assert (isa (A*A, 'sym')) + assert (isequal ( A*A , D*D )) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/unique.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/unique.m +[inst/@sym/ssinint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ssinint.m +***** assert (isequal (ssinint(sym(0)), -sym(pi)/2)) ***** test - A = sym([1 2 3 3 5 3 2 6 5]); - B = sym([1 2 3 5 6]); - assert (isequal (unique(A), B)) + A = ssinint (sym ([0 1])); + B = [-pi/2 -0.62471325642771360426]; + assert( all(all( abs(double(A)-B) < 1e-15 ))) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/solve.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/solve.m ***** test - syms x y - A = [1 2 3 3 4 5 5 6 7 7 x x y y]; - B = [1 2 3 4 5 6 7 x y]; - assert (isequal (unique(A), B)) + % Simple, single variable, single solution + syms x + d = solve(10*x == 50); + assert (isequal (d, 5)) ***** test + % Single variable, multiple solutions syms x - assert (isequal (unique(x), x)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/lgamma.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/lgamma.m + d = solve(x^2 == 4); + assert (length(d) == 2); + assert (isequal (d, [2; -2]) || isequal (d, [-2; 2])) +***** shared x,y,eq + syms x y + eq = 10*x == 20*y; ***** test - % tested by gammaln - assert (isequal (lgamma (sym ('x')), gammaln (sym ('x')))) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/union.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/union.m + d = solve(eq, x); + assert (isequal (d, 2*y)) ***** test - A = sym([1 2 3]); - B = sym([1 2 4]); - C = union(A, B); - D = sym([1 2 3 4]); - assert (isequal (C, D)) + d = solve(eq, y); + assert (isequal (d, x/2)) ***** test - % one nonsym - A = sym([1 2 3]); - B = [1 2 4]; - C = union(A, B); - D = sym([1 2 3 4]); - assert (isequal (C, D)) + d = solve(eq); + assert (isequal (d, 2*y)) +***** shared x,y + syms x y ***** test - % empty - A = sym([1 2 3]); - C = union(A, A); - assert (isequal(C, A)) + d = solve(2*x - 3*y == 0, x + y == 1); + assert (isequal (d.x, sym(3)/5) && isequal(d.y, sym(2)/5)) ***** test - % empty input - A = sym([1 2]); - C = union(A, []); - assert (isequal (C, sym([1 2]))) + d = solve(2*x - 3*y == 0, x + y == 1, x, y); + assert (isequal (d.x, sym(3)/5) && isequal(d.y, sym(2)/5)) ***** test - % scalar - syms x - assert (isequal (union([x 1], x), [1 x])) - assert (isequal (union(x, x), x)) + % Multiple solutions, multiple variables + d = solve(x^2 == 4, x + y == 1); + assert (length(d) == 2); + % FIXME: SMT has d.x gives vector and d.y giving vector, what is + % more intuitive? + for i = 1:2 + assert (isequal (d{i}.x + d{i}.y, 1)) + assert (isequal ((d{i}.x)^2, 4)) + end ***** test - A = interval(sym(1), 3); - B = interval(sym(2), 5); - C = union(A, B); - assert( isequal( C, interval(sym(1), 5))) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/tril.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/tril.m + % No solutions + syms x y z + d = solve(x == y, z); + assert (isempty (d)); ***** test - syms x - assert (isequal (tril(x), x)) + % Multiple outputs with single solution + [X, Y] = solve(2*x + y == 5, x + y == 3); + assert (isequal (X, 2)) + assert (isequal (Y, 1)) ***** test - % with symbols - syms x - A = [x 2*x; 3*x 4*x]; - assert (isequal (tril(A), [x 0; 3*x 4*x])) + % system: vector of equations, vector of vars + [X, Y] = solve([2*x + y == 5, x + y == 3], [x y]); + assert (isequal (X, 2)) + assert (isequal (Y, 1)) ***** test - % diagonal shifts - B = round(10*rand(3,4)); - A = sym(B); - assert (isequal (tril(A), tril(B))) - assert (isequal (tril(A,0), tril(B,0))) - assert (isequal (tril(A,1), tril(B,1))) - assert (isequal (tril(A,-1), tril(B,-1))) + % system: vector of equations, individual vars + [X, Y] = solve([2*x + y == 5, x + y == 3], x, y); + assert (isequal (X, 2)) + assert (isequal (Y, 1)) ***** test - % double array pass through - B = round(10*rand(3,4)); - assert (isequal (tril(B,sym(1)), tril(B,1))) - assert (isa (tril(B,sym(1)), 'double')) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/exp.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/exp.m -***** error exp (sym(1), 2) -***** assert (isequaln (exp (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + % system: individual equations, vector of vars + [X, Y] = solve(2*x + y == 5, x + y == 3, [x y]); + assert (isequal (X, 2)) + assert (isequal (Y, 1)) ***** test - f1 = exp(x); - f2 = exp(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % Multiple outputs with multiple solns + [X, Y] = solve(x*x == 4, x == 2*y); + assert ((isequal (X, [2; -2]) && isequal (Y, [1; -1])) || ... + (isequal (X, [-2; 2]) && isequal (Y, [-1; 1]))) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = exp(A); - f2 = exp(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % Multiple outputs with multiple solns, specify vars + [X, Y] = solve(x*x == 4, x == 2*y, x, y); + assert ((isequal (X, [2; -2]) && isequal (Y, [1; -1])) || ... + (isequal (X, [-2; 2]) && isequal (Y, [-1; 1]))) +***** error + % mult outputs not allowed for scalar equation, even with mult soln (?) + [s1, s2] = solve(x^2 == 4, x); ***** test - % round trip - y = sym('y'); - A = exp (d); - f = exp (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/hilb.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/hilb.m + % overdetermined + X = solve(2*x - 10 == 0, 3*x - 15 == 0, x); + assert (isequal (X, sym(5))) ***** test - A = hilb (sym(3)); - B = [sym(1) sym(1)/2 sym(1)/3; sym(1)/2 sym(1)/3 sym(1)/4; sym(1)/3 sym(1)/4 sym(1)/5]; - assert (isequal (A, B)) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/matlabFunction.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/matlabFunction.m + a = solve(2*x >= 10, 10*x <= 50); + assert (isequal( a, x==sym(5))) ***** test - % autodetect inputs - syms x y - s = warning('off', 'OctSymPy:function_handle:nocodegen'); - h = matlabFunction(2*x*y, x+y); - warning(s) - [t1, t2] = h(3,5); - assert(t1 == 30 && t2 == 8) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/atan2.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/atan2.m -***** error atan2 (1) -***** error atan2 (1, 2, 3) + A = solve([2*x == 4*y, 2 == 3], x); + assert (isempty (A)) ***** test - % some angles - e = sym(1); - a = atan2(0, e); - assert (isequal (a, sym(0))) - a = atan2(e, 0); - assert (isequal (a, sym(pi)/2)) + % Issue #850 + A = solve (sym(pi)^2*x + y == 0); + assert (isequal (A, -y/sym(pi)^2)) ***** test - % symbols can give numerical answer - syms x positive - a = atan2(0, x); - assert (isequal (a, sym(0))) - a = atan2(x, 0); - assert (isequal (a, sym(pi)/2)) - a = atan2(-x, 0); - assert (isequal (a, -sym(pi)/2)) + % https://github.com/sympy/sympy/issues/14632 + A = solve([2*x == 4*y, sym(2) == 2], x); + assert (isequal (A, 2*y)) ***** test - % matrices - x = sym([1 -2; 0 0]); - y = sym([0 0; 8 -3]); - a = atan2(y, x); - sp = sym(pi); - aex = [0 sp; sp/2 -sp/2]; - assert (isequal (a, aex)) + % https://github.com/sympy/sympy/issues/14632 + A = solve([2*x^2 == 32*y^2, sym(2) == 2], x); + B = solve([2*x^2 == 32*y^2], x); + assert (isequal (A, B) || isequal (A, flip (B))) ***** test - % round trip - syms x y - xd = -2; yd = -3; - f = atan2 (x, y); - A = atan2 (xd, yd); - h = function_handle (f); - B = h (xd, yd); - assert (A, B, -eps) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/prevprime.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/prevprime.m -***** assert (isequal (prevprime(sym(3)), 2)); -***** assert (isequal (prevprime(sym(20)), 19)); -***** assert (isequal (prevprime(sym([3 5 10])), [2 3 7])); -***** error prevprime(sym(2)) -***** error prevprime(sym(-2)) + A = solve ([x+1 0], x); + assert (isequal (A, sym (-1))) ***** test - % result is a sym - p = prevprime(sym(3)); - assert (isa (p, 'sym')) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/sqrt.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sqrt.m -***** error sqrt (sym(1), 2) -***** assert (isequaln (sqrt (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + A = solve (x + 1, x); + assert (isequal (A, sym (-1))) + A = solve (x, x); + assert (isequal (A, sym (0))) +24 tests, 24 passed, 0 known failure, 0 skipped +[inst/@sym/function_handle.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/function_handle.m +***** shared x,y,z + syms x y z ***** test - f1 = sqrt(x); - f2 = sqrt(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % basic test + h = function_handle(2*x); + assert(isa(h, 'function_handle')) + assert(h(3)==6) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = sqrt(A); - f2 = sqrt(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % autodetect inputs + h = function_handle(2*x*y, x+y); + [t1, t2] = h(3,5); + assert(t1 == 30 && t2 == 8) ***** test - % round trip - y = sym('y'); - A = sqrt (d); - f = sqrt (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/polylog.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/polylog.m -***** assert (isequal (polylog (sym('s'), 0), sym(0))) -***** assert (isequal (double (polylog (1, sym(-1))), -log(2))) -***** assert (isequal (double (polylog (0, sym(2))), -2)) -***** assert (isequal (double (polylog (-1, sym(2))), 2)) -***** assert (isequal (double (polylog (-2, sym(3))), -1.5)) -***** assert (isequal (double (polylog (-3, sym(2))), 26)) -***** assert (isequal (double (polylog (-4, sym(3))), -15)) -***** assert (isequal (double (polylog (1, sym(1)/2)), log(2))) + % specified inputs + h = function_handle(2*x*y, 'vars', [x y]); + assert(h(3,5)==30) + h = function_handle(2*x*y, x+y, 'vars', [x y]); + [t1, t2] = h(3,5); + assert(t1 == 30 && t2 == 8) ***** test - % round trip - syms s z - f = polylog (s, z); - h = function_handle (f, 'vars', [s z]); - A = h (1.1, 2.2); - B = polylog (1.1, 2.2); - assert (A, B) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/subsref.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/subsref.m -***** shared a,b - b = [1:4]; - a = sym(b); -***** assert(isequal( a(1), b(1) )) -***** assert(isequal( a(2), b(2) )) -***** assert(isequal( a(4), b(4) )) -***** assert(isempty( a([]) )) -***** shared a,b - b = [1:4]; b = [b; 3*b; 5*b]; - a = sym(b); -***** assert(isequal( a(1), b(1) )) -***** assert(isequal( a(2), b(2) )) -***** assert(isequal( a(4), b(4) )) -***** assert(isequal( a(:,:), a )) -***** assert(isequal( a(1:2,1:3), a(1:2,1:3) )) -***** assert(isequal( a(1:2:3,[1 2 4]), b(1:2:3,[1 2 4]) )) -***** assert(isequal( a(1:2:3,[4 2 3 1]), b(1:2:3,[4 2 3 1]) )) -***** assert(isequal( a(1:2:3,[4 1 1 1]), b(1:2:3,[4 1 1 1]) )) -***** assert(isequal( a([],:), b([],:) )) -***** assert(isequal( size(a([],:)), [0 4] )) -***** assert(isequal( a(1:2,[]), b(1:2,[]) )) -***** assert(isequal( size(a(1:2,[])), [2 0] )) -***** assert(isempty( a(1:2,[]) )) -***** assert(isempty( a([],[]) )) -***** assert(isequal( a([],[]), sym([]) )) -***** assert(~isequal( a(1:2,[]), sym([]) )) -***** shared e - e = sym([1 3 5; 2 4 6]); -***** assert(isequal( e(:), sym((1:6)') )) -***** assert(isequal( e([1 2 3]), sym([1 2 3]) )) -***** assert(isequal( e([1; 3; 4]), sym([1; 3; 4]) )) -***** assert(isempty( e([]) )) -***** assert(isempty( e('') )) -***** assert(isequal( e([]), sym([]) )) -***** shared a,b - b = 1:5; a = sym(b); -***** assert(isequal( a([1 2 5]), b([1 2 5]) )) -***** assert(isequal( a([1; 2; 5]), b([1; 2; 5]) )) -***** shared x - syms x + % cell arrays for vars list + h = function_handle(2*x*y, x+y, 'vars', {x y}); + [t1, t2] = h(3,5); + assert(t1 == 30 && t2 == 8) + h = function_handle(2*x*y, x+y, 'vars', {'x' 'y'}); + [t1, t2] = h(3,5); + assert(t1 == 30 && t2 == 8) ***** test - % logical with empty result - assert(isempty( x(false) )) - a = [x x]; - assert(isempty( a([false false]) )) + % cell arrays specfies order, overriding symvar order + h = function_handle(x*y, 12/y, 'vars', {y x}); + [t1, t2] = h(3, 6); + assert(t1 == 18 && t2 == 4) + h = function_handle(x*y, 12/y, 'vars', [y x]); + [t1, t2] = h(3, 6); + assert(t1 == 18 && t2 == 4) ***** test - % issue 18, scalar access - assert(isequal( x(1), x )) - assert(isequal( x(true), x )) -***** shared + % cell arrays specfies order, overriding symvar order + h = function_handle(x*y, 12/y, 'vars', {y x}); + [t1, t2] = h(3, 6); + assert(t1 == 18 && t2 == 4) + h = function_handle(x*y, 12/y, 'vars', [y x]); + [t1, t2] = h(3, 6); + assert(t1 == 18 && t2 == 4) ***** test - % older access tests - syms x - f = [x 2; 3 4*x]; - % element access - assert (logical( f(1,1) == x )) - assert (logical( f(1,2) == 2 )) - % linear access of 2d array - assert (logical( f(1) == x )) - assert (logical( f(2) == 3 )) % column based - assert (logical( f(3) == 2 )) -***** shared a,b - % effectively a random matrix - a = reshape( round(50*(sin(1:20)+1)), 5,4); - b = sym(a); + % Functions with different names in Sympy. + f = abs(x); % becomes Abs(x) + h = function_handle(f); + assert(h(-10) == 10) + f = ceil(x); + h = function_handle(f); + assert(h(10.1) == 11) ***** test - % older array refs test - assert (logical(b(1,1) == a(1,1))) - assert (logical(b(3,1) == a(3,1))) - assert (logical(b(1,3) == a(1,3))) - assert (logical(b(4,4) == a(4,4))) + % 'file' with empty filename returns handle + h = function_handle(2*x*y, 'file', ''); + assert(isa(h, 'function_handle')) + assert(h(3,5)==30) + h = function_handle(2*x*y, 'vars', {x y}, 'file', ''); + assert(isa(h, 'function_handle')) + assert(h(3,5)==30) ***** test - % older array refs test: linear indices - assert (logical(b(1) == a(1))) - assert (logical(b(3) == a(3))) - assert (logical(b(13) == a(13))) + % output to disk + fprintf('\n') + if (exist ('OCTAVE_VERSION', 'builtin')) + temp_file = tempname('', 'oct_'); + else + temp_file = tempname(); + end + % allow loading function from temp_file + [temp_path, ans, ans] = fileparts(temp_file); + addpath(temp_path); + f = function_handle(2*x*y, 2^x, 'vars', {x y z}, 'file', temp_file); + assert( isa(f, 'function_handle')) + addpath(temp_path); % Matlab 2014a needs this? + [a,b] = f(10,20,30); + assert (isnumeric (a) && isnumeric (b)) + assert (a == 400) + assert (b == 1024) + if (exist ('OCTAVE_VERSION', 'builtin')) + assert (unlink([temp_file '.m']) == 0) + else + delete ([temp_file '.m']) + end + % remove temp_path from load path + rmpath(temp_path); + +Wrote file /tmp/oct_bX71vc.m. ***** test - % older array refs test: end - assert (all(all(logical( b(end,1) == a(end,1) )))) - assert (all(all(logical( b(2,end) == a(2,end) )))) - assert (all(all(logical( b(end,end) == a(end,end) )))) - assert (all(all(logical( b(end-1,1) == a(end-1,1) )))) - assert (all(all(logical( b(2,end-1) == a(2,end-1) )))) - assert (all(all(logical( b(end-1,end-1) == a(end-1,end-1) )))) -***** shared + % output to disk: also works with .m specified + if (exist ('OCTAVE_VERSION', 'builtin')) + temp_file = [tempname('', 'oct_') '.m']; + else + temp_file = [tempname() '.m']; + end + % allow loading function from temp_file + [temp_path, ans, ans] = fileparts(temp_file); + addpath(temp_path); + f = function_handle(2*x*y, 2^x, 'vars', {x y z}, 'file', temp_file); + assert( isa(f, 'function_handle')) + addpath(temp_path); % Matlab 2014a needs this? + [a,b] = f(10,20,30); + assert (isnumeric (a) && isnumeric (b)) + assert (a == 400) + assert (b == 1024) + if (exist ('OCTAVE_VERSION', 'builtin')) + assert (unlink(temp_file) == 0) + else + delete (temp_file) + end + % remove temp_path from load path + rmpath(temp_path); +Wrote file /tmp/oct_rXjs87.m. ***** test - % older slicing tests - syms x - a = [1 2 3 4 5 6]; a = [a; 3*a; 5*a; 2*a; 4*a]; - b = sym(a); - assert (isequal( b(:,1), a(:,1) )) - assert (isequal( b(:,2), a(:,2) )) - assert (isequal( b(1,:), a(1,:) )) - assert (isequal( b(2,:), a(2,:) )) - assert (isequal( b(:,:), a(:,:) )) - assert (isequal( b(1:3,2), a(1:3,2) )) - assert (isequal( b(1:4,:), a(1:4,:) )) - assert (isequal( b(1:2:5,:), a(1:2:5,:) )) - assert (isequal( b(1:2:4,:), a(1:2:4,:) )) - assert (isequal( b(2:2:4,3), a(2:2:4,3) )) - assert (isequal( b(2:2:4,3), a(2:2:4,3) )) + % non-scalar outputs + H = [x y z]; + M = [x y; z 16]; + V = [x;y;z]; + h = function_handle(H, M, V); + [t1,t2,t3] = h(1,2,3); + assert(isequal(t1, [1 2 3])) + assert(isequal(t2, [1 2; 3 16])) + assert(isequal(t3, [1;2;3])) ***** test - % 2D arrays - b = [1:4]; b = [b; 3*b; 5*b]; - a = sym(b); - I = rand(size(b)) > 0.5; - assert (isequal (a(I), b(I))) - I = I(:); - assert (isequal (a(I), b(I))) - I = I'; - assert (isequal (a(I), b(I))) - I = logical(zeros(size(b))); - assert (isequal (a(I), b(I))) + % non-scalar outputs in .m files + H = [x y z]; + M = [x y; z 16]; + V = [x;y;z]; + if (exist ('OCTAVE_VERSION', 'builtin')) + temp_file = tempname('', 'oct_'); + else + temp_file = tempname(); + end + % allow loading function from temp_file + [temp_path, ans, ans] = fileparts(temp_file); + addpath(temp_path); + h = function_handle(H, M, V, 'vars', {x y z}, 'file', temp_file); + assert( isa(h, 'function_handle')) + addpath(temp_path); % Matlab 2014a needs this? + [t1,t2,t3] = h(1,2,3); + assert(isequal(t1, [1 2 3])) + assert(isequal(t2, [1 2; 3 16])) + assert(isequal(t3, [1;2;3])) + if (exist ('OCTAVE_VERSION', 'builtin')) + assert (unlink([temp_file '.m']) == 0) + else + delete ([temp_file '.m']) + end + % remove temp_path from load path + rmpath(temp_path); +Wrote file /tmp/oct_o4DKIs.m. ***** test - % 1D arrays, does right with despite warning - r = [1:6]; - ar = sym(r); - c = r'; - ac = sym(c); - Ir = rand(size(r)) > 0.5; - Ic = rand(size(c)) > 0.5; - assert (isequal (ar(Ir), r(Ir))) - assert (isequal (ac(Ic), c(Ic))) - assert (isequal (ar(Ic), r(Ic))) - assert (isequal (ac(Ir), c(Ir))) + % order of outputs is lexiographic + syms a A x y + f = y + 10*a + 100*x + 1000*A; + h = function_handle(f); + assert (h(1, 2, 3, 4) == 1000 + 20 + 300 + 4) ***** test - % rccross tests - B = [1 2 3 4; 5 6 7 9; 10 11 12 13]; - A = sym(B); - assert (isequal (A([1 3],[2 3]), B([1 3], [2 3]) )) - assert (isequal (A(1,[2 3]), B(1,[2 3]) )) - assert (isequal (A([1 2],4), B([1 2],4) )) - assert (isequal (A([2 1],[4 2]), B([2 1],[4 2]) )) - assert (isequal (A([],[]), B([],[]) )) -***** error - % issue #445 - A = sym([10 11]); - A(1.1) -***** error - % issue #445 - A = sym([10 11]); - A(sym(4)/3) -***** error - % issue #445 - A = sym([1 2; 3 4]); - A(1.1, 1) -***** error - % issue #445 - A = sym([1 2; 3 4]); - A(1, sym(4)/3) -***** shared a, b - a = [1 2 3 5; 4 5 6 9; 7 5 3 2]; - b = sym (a); + % https://github.com/cbm755/octsympy/issues/854 + f = function_handle (x + 1i*sqrt (sym(3))); + assert (f (1), complex (1, sqrt (3)), -eps) +14 tests, 14 passed, 0 known failure, 0 skipped +[inst/@sym/columns.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/columns.m ***** test - c = true; - assert (isequal (a(c), b(c))) - c = false; - assert (isequal (a(c), b(c))) + a = sym([1 2 3]); + assert (columns(a) == 3) ***** test - c = [false true]; - assert (isequal (a(c), b(c))) - d = c | true; - assert (isequal (a(d), b(d))) - d = c & false; - assert (isequal (a(d), b(d))) + a = sym([1; 2]); + assert (columns(a) == 1) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/isNone.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isNone.m ***** test - c = [false true false true; true false true false; false true false true]; - assert (isequal (a(c), b(c))) - d = c | true; - assert (isequal (a(d), b(d))) - d = c & false; - assert (isequal (a(d), b(d))) + None = pycall_sympy__ ('return None'); +***** shared None + None = pycall_sympy__ ('return None'); +***** assert (isNone(None)) +***** assert (~isNone(sym('x'))) +***** assert (islogical(isNone(None))) ***** test - c = [false true false true false]; - assert (isequal (a(c), b(c))) - d = c | true; - assert (isequal (a(d), b(d))) - d = c & false; - assert (isequal (a(d), b(d))) + a = [1 None]; + a = [None None]; + a = [None; 1]; + a = [None; None]; + a = [None 2; 3 None]; ***** test - c = [false; true; false; true; false]; - assert (isequal (a(c), b(c))) - d = c | true; - assert (isequal (a(d), b(d))) - d = c & false; - assert (isequal (a(d), b(d))) + a = sym([1 2]); + a(1,2) = None; + assert (isequal (a, [sym(1) None])); +***** assert (isequal (None(1), None)); +***** error None(None); +***** error x=sym('x'); x(None); +***** error x=1; x(None); +***** error None(None); +***** error 1 + None; +***** error None - 1; +***** error 6*None; +***** error 2^None; +***** error [1 2].*None; +***** error isconstant(None); +***** error nnz(None); +***** error logical(None); +***** error isAlways(None); +***** error logical([sym(true) None]); +***** error isAlways([sym(true) None]); +***** assert (isequal (children(None), None)) +***** assert (isequal (repmat(None, 1, 2), [None None])) +***** assert (isequal (fliplr(None), None)) +***** assert (isequal (flipud(None), None)) +26 tests, 26 passed, 0 known failure, 0 skipped +[inst/@sym/equationsToMatrix.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/equationsToMatrix.m ***** test - c = [false true; false true; true false]; - assert (isequal (a(c), b(c))) - d = c | true; - assert (isequal (a(d), b(d))) - d = c & false; - assert (isequal (a(d), b(d))) -***** shared + syms x y z + [A, B] = equationsToMatrix ([x + y - z == 1, 3*x - 2*y + z == 3, 4*x - 2*y + z + 9 == 0], [x, y, z]); + a = sym ([1 1 -1; 3 -2 1; 4 -2 1]); + b = sym ([1; 3; -9]); + assert (isequal (A, a)) + assert (isequal (B, b)) ***** test - % Orientation of empty results of logical indexing on row or column vectors - r = [1:6]; - c = r'; - ar = sym(r); - ac = sym(c); - assert (isequal (ar(false), r(false))) - assert (isequal (ac(false), c(false))) - assert (isequal (ar(false (1, 6)), r(false (1, 6)))) - assert (isequal (ac(false (1, 6)), c(false (1, 6)))) - assert (isequal (ar(false (6, 1)), r(false (6, 1)))) - assert (isequal (ac(false (6, 1)), c(false (6, 1)))) -49 tests, 49 passed, 0 known failure, 0 skipped -[inst/@sym/abs.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/abs.m -***** error abs (sym(1), 2) -***** assert (isequaln (abs (sym(nan)), sym(nan))) -***** shared x, d - d = -1; - x = sym('-1'); + syms x y z + A = equationsToMatrix ([3*x + -3*y - 5*z == 9, 4*x - 7*y + -3*z == -1, 4*x - 9*y - 3*z + 2 == 0], [x, y, z]); + a = sym ([3 -3 -5; 4 -7 -3; 4 -9 -3]); + assert (isequal (A, a)) ***** test - f1 = abs(x); - f2 = abs(d); - assert( abs(double(f1) - f2) < 1e-15 ) + syms x y + [A, B] = equationsToMatrix ([3*x + 9*y - 5 == 0, -8*x - 3*y == -2]); + a = sym ([3 9; -8 -3]); + b = sym ([5; -2]); + assert (isequal (A, a)) + assert (isequal (B, b)) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = abs(A); - f2 = abs(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % override symvar order + syms x y + [A, B] = equationsToMatrix ([3*x + 9*y - 5 == 0, -8*x - 3*y == -2], [y x]); + a = sym ([9 3; -3 -8]); + b = sym ([5; -2]); + assert (isequal (A, a)) + assert (isequal (B, b)) ***** test - % round trip - y = sym('y'); - A = abs (d); - f = abs (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/nnz.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/nnz.m -***** assert (nnz (sym ([1])) == 1) -***** assert (nnz (sym ([0])) == 0) -***** assert (nnz (sym ([])) == 0) -***** assert (nnz (sym ([1 0; 0 3])) == 2) + syms x y z + [A, B] = equationsToMatrix ([x - 9*y + z == -5, -9*y*z == -5], [y, x]); + a = sym ([[-9 1]; -9*z 0]); + b = sym ([-5 - z; -5]); + assert (isequal (A, a)) + assert (isequal (B, b)) +***** test + syms x y + [A, B] = equationsToMatrix (-6*x + 4*y == 5, 4*x - 4*y - 5, x, y); + a = sym ([-6 4; 4 -4]); + b = sym ([5; 5]); + assert (isequal (A, a)) + assert (isequal (B, b)) ***** test + % vertical list of equations + syms x y + [A, B] = equationsToMatrix ([-6*x + 4*y == 5; 4*x - 4*y - 5], [x y]); + a = sym ([-6 4; 4 -4]); + b = sym ([5; 5]); + assert (isequal (A, a)) + assert (isequal (B, b)) +***** test + syms x y + [A, B] = equationsToMatrix (5*x == 1, y, x - 6*y - 7, y); + a = sym ([0; 1; -6]); + b = sym ([1 - 5*x; 0; -x + 7]); + assert (isequal (A, a)) + assert (isequal (B, b)) +***** error + syms x y + [A, B] = equationsToMatrix (x^2 + y^2 == 1, x - y + 1, x, y); +***** test + % single equation syms x - assert (nnz ([x 0]) == 1) -***** assert (nnz (sym (true)) == 1) -***** assert (nnz (sym (false)) == 0) -***** assert (nnz (sym (inf)) == 1) -***** assert (nnz (sym (nan)) == 1) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/assume.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/assume.m + [A, B] = equationsToMatrix (3*x == 2, x); + a = sym (3); + b = sym (2); + assert (isequal (A, a)) + assert (isequal (B, b)) ***** test + % single equation w/ symvar syms x - x = assume(x, 'positive'); - a = assumptions(x); - assert(strcmp(a, 'x: positive')) - x = assume(x, 'even'); - a = assumptions(x); - assert(strcmp(a, 'x: even')) - x = assume(x, 'odd'); - a = assumptions(x); - assert(strcmp(a, 'x: odd')) -***** error + [A, B] = equationsToMatrix (3*x == 2); + a = sym (3); + b = sym (2); + assert (isequal (A, a)) + assert (isequal (B, b)) +***** error syms x - x = assume (x, x); -***** error + equationsToMatrix (3*x == 2, [x x]) +12 tests, 12 passed, 0 known failure, 0 skipped +[inst/@sym/diag.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/diag.m +***** test + % scalar syms x - x = assume (x/pi, 'integer') + assert (isequal (diag(x), x)) ***** test - % multiple assumptions + % row,col vec input syms x - x = assume(x, 'positive', 'integer'); - [tilde, a] = assumptions(x, 'dict'); - assert(a{1}.integer) - assert(a{1}.positive) + r = [1 x 2]; + c = [sym(1); x]; + assert (isequal (diag(diag(c)), c)) + assert (isequal (diag(c), [sym(1) 0; 0 x])) + assert (isequal (diag(diag(r)), r.')) + assert (isequal (diag(r), [sym(1) 0 0; 0 x 0; sym(0) 0 2])) ***** test - % multiple assumptions + % create matrix, kth diag syms x - x = assume(x, 'even', 'positive'); - [tilde, a] = assumptions(x, 'dict'); - assert(a{1}.even) - assert(a{1}.positive) + r = [1 x]; + z = sym(0); + assert (isequal (diag (x, 0), x)) + assert (isequal (diag (x, 1), [z x; z z])) + assert (isequal (diag (x, -1), [z z; x z])) + assert (isequal (diag (x, 2), [z z x; z z z; z z z])) + assert (isequal (diag (r, 1), [z 1 z; z z x; z z z])) ***** test - % has output so avoids workspace - syms x positive - x2 = x; - f = sin(x); - x = assume(x, 'negative'); - a = assumptions(x); - assert(strcmp(a, 'x: negative')) - a = assumptions(x2); - assert(strcmp(a, 'x: positive')) - a = assumptions(f); - assert(strcmp(a, 'x: positive')) + % extract kth diag + A = sym([1 2 3; 4 5 6]); + assert (isequal (diag(A), sym([1; 5]))) + assert (isequal (diag(A, 0), sym([1; 5]))) + assert (isequal (diag(A, 1), sym([2; 6]))) + assert (isequal (diag(A, 2), sym(3))) + assert (isequal (diag(A, -1), sym(4))) + assert (isempty (diag(A, -2))) + assert (isempty (diag(A, 3))) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/linspace.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/linspace.m ***** test - % clear: has output so avoids workspace - syms x positive - f = 2*x; - x2 = assume(x, 'clear'); - assert (~ isempty (assumptions (f))); + a = linspace(sym(3), 5, 5); + b = [sym(6) 7 8 9 10]/2; + assert (isequal (a, b)) ***** test - % has no output so does workspace - syms x positive - x2 = x; - f = sin(x); - assume(x, 'negative'); - a = assumptions(x); - assert(strcmp(a, 'x: negative')) - a = assumptions(x2); - assert(strcmp(a, 'x: negative')) - a = assumptions(f); - assert(strcmp(a, 'x: negative')) + % non-integers + A = linspace(0, sym(pi), 10); + assert (length (A) == 10); + assert (isequal (A(6), 5*sym(pi)/9)); ***** test - % clear: has not output so does workspace - syms x positive - f = 2*x; - assume(x, 'clear'); - assert (isempty (assumptions (f))); - assert (isempty (assumptions ())); + % default argument for N + A = linspace(1, 100); + assert (length (A) == 100); ***** test - syms x positive - assume (x, 'clear') - assert (isempty (assumptions ())) -***** error - syms x - x2 = assume (x, 'clear', 'real'); -***** error - syms a - assume (a > 0) + % special case for just N = 1 + A = linspace(sym(2), 3, 1); + assert (isequal (A, 3)) + A = linspace(sym(2), 3, 0); + assert (isequal (A, 3)) + A = linspace(sym(2), 3, sym(3)/2); + assert (isequal (A, 3)) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/colon.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/colon.m ***** test - syms x y - assume ([x y], 'real') - assert (strcmp (assumptions (x), 'x: real')) - assert (strcmp (assumptions (y), 'y: real')) + a = sym(1):5; + b = sym(1:5); + assert(isequal(a,b)); + a = 1:sym(5); + b = sym(1:5); + assert(isequal(a,b)); ***** test - syms x y - assume ([x y], 'positive', 'even') - assert (strcmp (assumptions (x), 'x: positive, even') || strcmp (assumptions (x), 'x: even, positive')) - assert (strcmp (assumptions (y), 'y: positive, even') || strcmp (assumptions (y), 'y: even, positive')) + a = 2:sym(2):8; + b = sym(2:2:8); + assert(isequal(a,b)); ***** test - % with output, original x and y are unchanged - syms x y - [p, q] = assume ([x y], 'real'); - assert (isempty (assumptions (x))) - assert (isempty (assumptions (y))) - assert (strcmp (assumptions (p), 'x: real')) - assert (strcmp (assumptions (q), 'y: real')) + a = sym(10):-2:-4; + b = sym(10:-2:-4); + assert(isequal(a,b)); ***** test - % matrix input - syms a b c d - assume ([a b; c d], 'real') - assert (strcmp (assumptions (a), 'a: real')) - assert (strcmp (assumptions (b), 'b: real')) - assert (strcmp (assumptions (c), 'c: real')) - assert (strcmp (assumptions (d), 'd: real')) -16 tests, 16 passed, 0 known failure, 0 skipped -[inst/@sym/ellipticCK.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticCK.m -***** error ellipticCK (sym (1), 2) -***** assert (double (ellipticCK (sym (1)/2)), 1.8541, 10e-5) -***** assert (double (ellipticCK (sym (101)/10)), 0.812691836806976, -3*eps) -***** assert (isequal (ellipticCK (sym (1)), sym(pi)/2)) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/ceil.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ceil.m -***** error ceil (sym(1), 2) -***** assert (isequaln (ceil (sym(nan)), sym(nan))) + % symbolic intervals + p = sym(pi); + L = 0:p/4:p; + assert(isa(L,'sym')); + assert(isequal(L, [0 p/4 p/2 3*p/4 p])); +***** test + % mixed symbolic and double intervals + p = sym(pi); + s = warning ('off', 'OctSymPy:sym:rationalapprox'); + L = 0.1:(sym(pi)/3):2.3; + warning(s) + assert(isa(L,'sym')); + t = sym(1)/10; + assert(isequal(L, [t p/3+t 2*p/3+t])); +***** error syms x; a = 0:x; +***** error syms x; a = 1:x; +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/acsch.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/acsch.m +***** error acsch (sym(1), 2) +***** assert (isequaln (acsch (sym(nan)), sym(nan))) ***** shared x, d - d = 3/2; - x = sym('3/2'); + d = 1; + x = sym('1'); ***** test - f1 = ceil(x); - f2 = ceil(d); + f1 = acsch(x); + f2 = acsch(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = ceil(A); - f2 = ceil(D); + f1 = acsch(A); + f2 = acsch(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = ceil (d); - f = ceil (y); + A = acsch (d); + f = acsch (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/isfinite.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isfinite.m -***** assert (isfinite(sym(1))) -***** assert (isfinite(sym(-10))) -***** assert (~isfinite(sym('oo'))) -***** assert (~isfinite(sym('-oo'))) -***** assert (~isfinite(sym(1)/0)) -***** assert (~isfinite(sym(nan))) -***** assert (isequal (isfinite (sym ([1 inf])), [true false])) +[inst/@sym/isprime.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isprime.m +***** assert (isprime (sym(5))) +***** assert (~isprime (sym(4))) +***** assert (~isprime (sym(0))) +***** assert (~isprime (sym(1))) ***** test - % finite-by-assumption - syms x finite - assert (isfinite (x)) -8 tests, 8 passed, 0 known failure, 0 skipped -[inst/@sym/gt.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/gt.m + a = [5 7 6; 1 2 337]; + assert (isequal (isprime (a), [true true false; false true true])) +***** assert (~isprime(sym(-4))) +***** assert (~isprime(sym(4i))) +***** assert (~isprime(sym(3)/5)) +***** error + isprime(sym('x')); +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/eval.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/eval.m +***** error eval (sym(1), 2) +***** assert (isnumeric (eval (sym(3)))) +***** assert (isnumeric (eval (sin (sym(3))))) ***** test - % simple - x = sym(1); y = sym(1); e = x > y; - assert (~logical (e)) - x = sym(1); y = sym(2); e = x > y; - assert (~logical (e)) + syms x y + f = 2*x*y; + x = 3; + y = 4; + g = eval (f); + assert (isequal (g, 24)) ***** test - % array -- array - syms x - a = sym([1 3 3 2*x]); - b = sym([2 x 3 10]); - e = a > b; - assert (isa (e, 'sym')) - assert (~logical (e(1))) - assert (isa (e(2), 'sym')) - assert (isequal (e(2), 3 > x)) - assert (~logical (e(3))) - assert (isa (e(4), 'sym')) - assert (isequal (e(4), 2*x > 10)) -2 tests, 2 passed, 0 known failure, 0 skipped + syms x y + f = 2*x*y; + clear y + x = 3; + g = eval (f); + assert (isequal (g, 6*sym('y'))) +***** test + % do not convert inputs to sym, for SMT compat + nearpi = pi + 1e-14; % sym could make this pi + x = sym('x'); + f = 2*x; + x = nearpi; + d = eval (f); + assert (abs (d - 2*pi) > 1e-15) +6 tests, 6 passed, 0 known failure, 0 skipped [inst/@sym/find.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/find.m ***** error find (sym (1), 2, 3, 4) @@ -10861,358 +11117,348 @@ assert (isequal (j, [1; 1; 2])) assert (isequal (v, [x; x+y; sym(5)])) 9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/acoth.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/acoth.m -***** error acoth (sym(1), 2) -***** assert (isequaln (acoth (sym(nan)), sym(nan))) -***** shared x, d - d = 2; - x = sym('2'); +[inst/@sym/real.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/real.m +***** assert (isequal (real (sym (4) + 3i),4)) ***** test - f1 = acoth(x); - f2 = acoth(d); - assert( abs(double(f1) - f2) < 1e-15 ) + syms x y real + z = x + 1i*y; + assert (isequal (real (z),x)) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = acoth(A); - f2 = acoth(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + syms x y real + Z = [4 x + 1i*y; x 4 + 3i]; + assert (isequal (real (Z),[4 x; x 4])) +***** test + syms x real + d = exp (x*i); + assert (isequal (real (d), cos (x))) ***** test % round trip - y = sym('y'); - A = acoth (d); - f = acoth (y); + syms x + d = 3 - 5i; + f = real (x); + A = real (d); h = function_handle (f); B = h (d); - assert (A, B, -eps) + assert (A, B) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/sum.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sum.m -***** error sum (sym(1), 2, 3) -***** error sum (sym(1), 42) -***** shared x,y,z - syms x y z -***** assert (isequal (sum (x), x)) -***** assert (isequal (sum ([x y z]), x+y+z)) -***** assert (isequal (sum ([x; y; z]), x+y+z)) -***** assert (isequal (sum ([x y z], 1), [x y z])) -***** assert (isequal (sum ([x y z], 2), x+y+z)) -***** shared a,b - b = [1 2; 3 4]; a = sym(b); -***** assert (isequal (sum(a), sum(b))) -***** assert (isequal (sum(a,1), sum(b,1))) -***** assert (isequal (sum(a,2), sum(b,2))) +[inst/@sym/children.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/children.m ***** test - % weird inputs - a = sum('xx', sym(1)); - assert (isequal (a, sym('xx'))) -11 tests, 11 passed, 0 known failure, 0 skipped -[inst/@sym/jordan.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/jordan.m + % basics, sum + syms x y + f = 2*x + x*x + sin(y); + assert (isempty (setxor (children(f), [2*x x*x sin(y)]))) ***** test - % basic - A = sym ([2 1 0 0; 0 2 1 0; 0 0 3 0; 0 1 -1 3]); - [V, J] = jordan (A); - assert (isequal (inv (V) * A * V, J)); - assert (isequal (J, sym ([2 1 0 0; 0 2 0 0; 0 0 3 0; 0 0 0 3]))) - % the first 2 generalized eigenvectors form a cycle - assert (isequal ((A - J(1, 1) * eye (4)) * V(:, 1), zeros (4, 1))); - assert (isequal ((A - J(2, 2) * eye (4)) * V(:, 2), V(:, 1))); - % the last 2 generalized eigenvectors are eigenvectors - assert (isequal ((A - J(3, 3) * eye (4)) * V(:, 3), zeros (4, 1))); - assert (isequal ((A - J(4, 4) * eye (4)) * V(:, 4), zeros (4, 1))); + % basics, product + syms x y + f = 2*x*sin(y); + assert (isempty (setxor (children(f), [2 x sin(y)]))) ***** test - % scalars - assert (isequal (jordan (sym (-10)), sym (-10))); - assert (isequal (jordan (sym ('x')), sym ('x'))); + % basics, product and powers + syms x y + f = 2*x^2*y^3; + assert (isempty (setxor (children(f), [2 x^2 y^3]))) ***** test - % diagonal matrices - A = diag (sym ([6 6 7])); - [V1, D] = eig (A); - [V2, J] = jordan (A); - assert (isequal (V1, V2)); - assert (isequal (D, J)); + % eqn, ineq + syms x y + lhs = 2*x^2; rhs = y^3 + 7; + assert (isequal (children(lhs == rhs), [lhs rhs])) + assert (isequal (children(lhs < rhs), [lhs rhs])) + assert (isequal (children(lhs >= rhs), [lhs rhs])) ***** test - % matrices of unknown entries - A = [sym('a') sym('b'); sym('c') sym('d')]; - [V, D] = eig (A); - J = jordan (A); - assert (isequal (simplify (D), simplify (J))); + % matrix + syms x y + f = [4 + y 1 + x; 2 + x 3 + x]; + c = children(f); + ec = {[4 y], [1 x]; [2 x], [3 x]}; + assert (isequal (size(c), size(ec))) + for i=1:length(c) + assert (isempty (setxor (c{i}, ec{i}))) + end ***** test - % matrices of mixed entries - A = [sym('x')+9 sym('y'); sym(0) 6]; - [V, D] = eig (A); - J = jordan (A); - assert (isequal (simplify (D), simplify (J))); -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/sinc.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinc.m -***** error sinc (sym(1), 2) -***** assert (isequaln (sinc (sym(nan)), sym(nan))) -***** assert (isequal (sinc (sym(0)), sym(1))) -***** assert (isequal (sinc (sym(1)), sym(0))) -***** assert (isequal (sinc (-sym(1)), sym(0))) -***** assert (double (sinc (sym(pi))), sinc (pi), -10*eps) + % matrix, sum/prod + syms x y + f = [x + y; x*sin(y); sin(x)]; + ec = {[x y]; [x sin(y)]; [x]}; + c = children(f); + assert (isequal (size(c), size(ec))) + for i=1:length(c) + assert (isempty (setxor (c{i}, ec{i}))) + end ***** test - A = [-sym(1)/2 sym(1)/2 pi; -sym(7)/2 sym(71)/2 sym(101)/3]; - D = double (A); - assert (sinc (D), double (sinc (A)), -200*eps) + % scalar symbol + syms x + assert (isequal (children(x), x)) ***** test - A = [sym(51)/2 sym(1001)/3 sym(10001)/3 sym(100001)/3]; - D = double (A); - assert (sinc (D), double (sinc (A)), 1e-10) + % scalar number + x = sym(6); + assert (isequal (children(x), x)) +***** test + % symbolic size matrix + syms n m integer + A = sym('a', [n m]); + C = children (A); + assert (isequal (C(2), n)) + assert (isequal (C(3), m)) +***** xtest + % symbolic size matrix, fails on newer SymPy Issue #1089 + syms n m integer + A = sym('a', [n m]); + assert (isequal (children (A), [sym('a') n m])) +!!!!! known failure +assert (isequal (children (A), [sym('a'), n, m])) failed +10 tests, 9 passed, 1 known failure, 0 skipped +[inst/@sym/expand.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/expand.m ***** test - % round trip syms x - A = sinc (1); - f = sinc (x); - h = function_handle (f); - B = h (1); - assert (A, B, -eps) + assert (logical (x^2 + 6*x + 5 == expand ((x+5)*(x+1)))) + assert (isequal (x^2 + 6*x + 5, expand ((x+5)*(x+1)))) ***** test - % round trip + % array syms x - f = sinc (x); + assert (isequal (expand ([x (x+1)*x]), [x x^2+x])) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/tanh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/tanh.m +***** error tanh (sym(1), 2) +***** assert (isequaln (tanh (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); +***** test + f1 = tanh(x); + f2 = tanh(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = tanh(A); + f2 = tanh(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = tanh (d); + f = tanh (y); h = function_handle (f); - A = sinc (1.5); - B = h (1.5); + B = h (d); assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/cat.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cat.m ***** test + % mostly tested in horzcat, vertcat: one for good measure syms x - h = function_handle (sinc (x)); - A = double (sinc (sym (12)/10)); - B = h (1.2); - C = sinc (1.2); - assert (A, B, -eps) - assert (A, C, -eps) -11 tests, 11 passed, 0 known failure, 0 skipped -[inst/@sym/disp.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/disp.m + assert (isequal (cat(1, x, x), [x x])) + assert (isequal (cat(2, x, x), [x; x])) +***** error cat(3, sym(2), sym(3)) +***** error cat(0, sym(2), sym(3)) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/le.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/le.m ***** test - syms x - s = disp(sin(x)); - assert(strcmp(s, sprintf(' sin(x)\n'))) + % simple + x = sym(1); y = sym(1); e = x <= y; + assert (logical (e)) + x = sym(1); y = sym(2); e = x <= y; + assert (logical (e)) ***** test + % array -- array syms x - s = disp(sin(x/2), 'flat'); - assert(strcmp(s, sprintf(' sin(x/2)\n'))) + a = sym([1 3 3 2*x]); + b = sym([2 x 3 10]); + e = a <= b; + assert (isa (e, 'sym')) + assert (logical (e(1))) + assert (isa (e(2), 'sym')) + assert (isequal (e(2), 3 <= x)) + assert (logical (e(3))) + assert (isa (e(4), 'sym')) + assert (isequal (e(4), 2*x <= 10)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/chol.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/chol.m +***** error chol (sym ([1 2; 3 4])); +***** error chol (sym ([1 2; 3 4; 5 6])); ***** test - % Examples of 2x0 and 0x2 empty matrices: - a = sym([1 2; 3 4]); - b2x0 = a([true true], [false false]); - b0x2 = a([false false], [true true]); - assert (isequal (size (b2x0), [2 0])) - assert (isequal (size (b0x2), [0 2])) - s = disp(b2x0); - assert(strcmp(s, sprintf(' []\n'))) - s = disp(b0x2); - assert(strcmp(s, sprintf(' []\n'))) + A = chol(hilb(sym(2))); + B = [[1 0]; sym(1)/2 sqrt(sym(3))/6]; + assert( isequal( A, B )) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/euler.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/euler.m -***** error euler (sym(1), 2, 3) -***** assert (isequal (euler (sym(0)), sym(1))) -***** test - m = sym([0 1 2; 8 10 888889]); - A = euler (m); - B = sym([1 0 -1; 1385 -50521 0]); - assert (isequal (A, B)) +[inst/@sym/besseljn.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/besseljn.m ***** test + % roundtrip syms x - assert (isequal (euler(6, x), x^6 - 3*x^5 + 5*x^3 - 3*x)) -***** assert (isnan (euler (3, sym(nan)))) -***** test - syms m x - em = euler (m, x); - A = subs(em, [m x], [2 sym(pi)]); - assert (isequal (A, sym(pi)^2 - sym(pi))) -***** test - % vectorized - syms x y - A = euler([1; 2], [x; y]); - B = [x - sym(1)/2; y^2 - y]; - assert (isequal (A, B)) -***** test - % round trip - syms m z - f = euler (m, z); - h = function_handle (f, 'vars', [m z]); - A = h (2, 2.2); - B = euler (2, 2.2); - assert (A, B) -***** test - % compare vpa to maple: Digits:=34; evalf(euler(13, exp(1)+Pi*I/13)); - A = vpa('1623.14184180556920918624604530515') + ... - vpa('4270.98066989140286451493108809574')*1i; - z = vpa (exp(1), 32) + vpa(pi, 32)/13*1i; - B = euler (13, z); - relerr = double(abs((B - A)/A)); - assert (abs(relerr) < 2e-31); -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/ezmesh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ezmesh.m -***** error - syms u v t - ezmesh(u*v, 2*u*v, 3*v*t) -***** error - syms u v t - ezmesh(u*v, 2*u*v, u*v*t) + A = double(besseljn(sym(2), sym(9))); + q = besseljn(sym(2), x); + h = function_handle(q); + B = h(9); + assert (abs (A - B) <= eps) +***** error jn(sym('x')) 2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/symreplace.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/symreplace.m +[inst/@sym/end.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/end.m ***** test - % start with assumptions on x then remove them - syms x positive - f = x*10; - symreplace(x, sym('x')) - assert(isempty(assumptions(x))) + % scalar + syms x + y = x(1:end); + assert (isequal (x, y)) ***** test - % replace x with y + % vector syms x - f = x*10; - symreplace(x, sym('y')) - assert( isequal (f, 10*sym('y'))) + A = [1 2 x 4]; + y = A(end-1:end); + assert (isequal (y, [x 4])) ***** test - % gets inside cells + % subset of matrix syms x - f = {x 1 2 {3 4*x}}; - symreplace(x, sym('y')) - syms y - assert( isequal (f{1}, y)) - assert( isequal (f{4}{2}, 4*y)) + A = [1 2 x; x 3 9; 4 x*x 6]; + y = A(end,1:end-1); + assert (isequal (y, [4 x*x])) ***** test - % gets inside structs/cells + % linear index of matrix syms x - my.foo = {x 1 2 {3 4*x}}; - my.bar = x; - g = {'ride' my 'motor' 'sicle'}; - symreplace(x, sym('y')) - syms y - f = g{2}; - assert( isequal (f.foo{1}, y)) - assert( isequal (f.foo{4}{2}, 4*y)) - assert( isequal (f.bar, y)) + A = [1 2 x; x 3 9]; + y = A(end); + assert (isequal (y, sym(9))) 4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/mrdivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/mrdivide.m +[inst/@sym/assumeAlso.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/assumeAlso.m ***** test - % scalar syms x - assert (isa( x/x, 'sym')) - assert (isequal( x/x, sym(1))) - assert (isa( 2/x, 'sym')) - assert (isa( x/2, 'sym')) + x = assumeAlso(x, 'positive'); + a = assumptions(x); + assert(strcmp(a, 'x: positive')) +***** error + syms x + x = assumeAlso (x, x); ***** test - % matrix / scalar - D = 2*[0 1; 2 3]; - A = sym(D); - assert (isequal ( A/2 , D/2 )) - assert (isequal ( A/sym(2) , D/2 )) + syms x positive + x = assumeAlso(x, 'integer'); + [tilde, a] = assumptions(x, 'dict'); + assert(a{1}.integer) + assert(a{1}.positive) ***** test - % I/A: either invert A or leave unevaluated: not bothered which - A = sym([1 2; 3 4]); - B = sym(eye(2)) / A; - assert (isequal (B, inv(A)) || strncmpi (sympy (B), 'MatPow', 6)) -***** xtest - % immutable test, upstream: TODO - A = sym([1 2; 3 4]); - B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])'); - assert (isequal (A/A, B/B)) + % multiple assumptions + syms x positive + x = assumeAlso(x, 'integer', 'even'); + [tilde, a] = assumptions(x, 'dict'); + assert(a{1}.integer) + assert(a{1}.positive) + assert(a{1}.even) ***** test - % A = C/B is C = A*B - A = sym([1 2; 3 4]); - B = sym([1 3; 4 8]); - C = A*B; - A2 = C / B; - assert (isequal (A, A2)) + % multiple assumptions + syms x integer + x = assumeAlso (x, 'even', 'positive'); + [tilde, a] = assumptions (x, 'dict'); + assert (a{1}.integer) + assert (a{1}.even) + assert (a{1}.positive) ***** test - A = [1 2; 3 4]; - B = A / A; - % assert (isequal (B, sym(eye(2)) - assert (isequal (B(1,1), 1)) - assert (isequal (B(2,2), 1)) - assert (isequal (B(2,1), 0)) - assert (isequal (B(1,2), 0)) + % has output so avoids workspace + syms x positive + x2 = x; + f = sin(x); + assumeAlso(x, 'integer'); + a = assumptions(x); + assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) + a = assumptions(x2); + assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) + a = assumptions(f); + assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) ***** test - A = sym([5 6]); - B = sym([1 2; 3 4]); - C = A*B; - A2 = C / B; - assert (isequal (A, A2)) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/lu.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/lu.m + % has no output so does workspace + syms x positive + x2 = x; + f = sin(x); + assumeAlso(x, 'integer'); + a = assumptions(x); + assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) + a = assumptions(x2); + assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) + a = assumptions(f); + assert(strcmp(a, 'x: positive, integer') || strcmp(a, 'x: integer, positive')) +***** error + syms a + assumeAlso (a > 0) ***** test - % scalar - [l, u, p] = lu(sym(6)); - assert (isequal (l, sym(1))) - assert (isequal (u, sym(6))) - assert (isequal (p, sym(1))) - syms x - [l, u, p] = lu(x); - assert (isequal (l*u, p*x)) - [l, u] = lu(x); - assert (isequal (l*u, x)) + syms x y + assumeAlso ([x y], 'even') + assert (strcmp (assumptions (x), 'x: even')) + assert (strcmp (assumptions (y), 'y: even')) ***** test - % perm - A = sym(fliplr(2*eye(3))); - [L, U, P] = lu(A); - assert (isequal (L*U, P*A)) - [L, U, P] = lu(A, 'matrix'); - assert (isequal (L*U, P*A)) - [L, U, p] = lu(A, 'vector'); - assert (isequal (L*U, A(p,:))) - [L, U] = lu(A); - assert (isequal (L*U, A)) + syms x y positive + f = sin (2*x); + assumeAlso ([x y], 'even') + assert (strcmp (assumptions (x), 'x: even, positive') || strcmp (assumptions (x), 'x: positive, even')) + assert (strcmp (assumptions (y), 'y: even, positive') || strcmp (assumptions (y), 'y: positive, even')) + assert (strcmp (assumptions (f), 'x: even, positive') || strcmp (assumptions (f), 'x: positive, even')) ***** test - % p is col vectpr - A = sym([0 2; 3 4]); - [L, U, p] = lu(A, 'vector'); - assert(iscolumn(p)) + % with output, original x and y are unchanged + syms x y positive + f = sin (2*x); + [p, q] = assumeAlso ([x y], 'even'); + assert (strcmp (assumptions (x), 'x: positive')) + assert (strcmp (assumptions (y), 'y: positive')) + assert (strcmp (assumptions (f), 'x: positive')) + assert (strcmp (assumptions (p), 'x: even, positive') || strcmp (assumptions (p), 'x: positive, even')) + assert (strcmp (assumptions (q), 'y: even, positive') || strcmp (assumptions (q), 'y: positive, even')) +11 tests, 11 passed, 0 known failure, 0 skipped +[inst/@sym/display.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/display.m ***** test - % simple matrix - A = [1 2; 3 4]; - B = sym(A); - [L, U, P] = lu(B); - assert (isequal (L*U, P*B)) - assert (isequal (U(2,1), sym(0))) - % needs pivot - A = [0 2; 3 4]; - B = sym(A); - [L, U, P] = lu(B); - [Ld, Ud, Pd] = lu(A); - assert (isequal (L*U, P*A)) - assert (isequal (U(2,1), sym(0))) - % matches regular LU - assert ( max(max(double(L)-Ld)) <= 10*eps) - assert ( max(max(double(U)-Ud)) <= 10*eps) - assert ( isequal (P, Pd)) + assert(true) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/pochhammer.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/pochhammer.m +***** error pochhammer (sym(1)) +***** error pochhammer (sym(1), 2, 3) +***** assert (isequal (pochhammer (sym(3), 4), sym(360))) +***** assert (isequal (pochhammer (sym([2 3]), 3), sym([24 60]))) ***** test - % rectangular - A = sym([1 2; 3 4; 5 6]); - [L, U] = lu (A); - assert (isequal (L*U, A)) + % round trip + syms n z + f = pochhammer (z, n); + h = function_handle (f, 'vars', [z n]); + A = h (1.1, 2.2); + B = pochhammer (1.1, 2.2); + assert (A, B) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/isequal.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isequal.m ***** test - % rectangular - A = sym([1 2 3; 4 5 6]); - [L, U] = lu (A); - assert (isequal (L*U, A)) + a = sym([1 2]); + b = a; + assert (isequal (a, b)) + b(1) = 42; + assert (~isequal (a, b)) ***** test - % rectangular, repeated row - A = sym([1 2 3; 2 4 6]); - [L, U] = lu (A); - assert (isequal (L*U, A)) + a = sym([1 2; 3 4]); + b = a; + assert (isequal (a, b)) + b(1) = 42; + assert (~isequal (a, b)) ***** test - % rectangular, needs permutation - A = sym([0 0 0; 1 2 3]); - [L, U] = lu (A); - assert (isequal (L*U, A)) - assert (~isequal (tril (L), L)) - [L, U, P] = lu (A); - assert (isequal (L*U, P*A)) - assert (isequal (tril (L), L)) -8 tests, 8 passed, 0 known failure, 0 skipped + a = sym([nan; 2]); + b = a; + assert (~isequal (a, b)) +***** test + % proper nan treatment + a = sym([nan 2; 3 4]); + b = a; + assert (~isequal (a, b)) +***** test + % more than two arrays + a = sym([1 2 3]); + b = a; + c = a; + assert (isequal (a, b, c)) + c(1) = 42; + assert (~isequal (a, b, c)) +5 tests, 5 passed, 0 known failure, 0 skipped [inst/@sym/csch.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/csch.m ***** error csch (sym(1), 2) @@ -11239,58 +11485,124 @@ B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ismember.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ismember.m -***** assert (ismember (2, interval(sym(0),2))) -***** assert (~ismember (3, interval(sym(0),2))) +[inst/@sym/atan.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/atan.m +***** error atan (sym(1), 2) +***** assert (isequaln (atan (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - % something in a matrix + f1 = atan(x); + f2 = atan(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = atan(A); + f2 = atan(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = atan (d); + f = atan (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/triu.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/triu.m +***** test + % scalar syms x - A = [1 x; sym(pi) 4]; - assert (ismember (sym(pi), A)) - assert (ismember (x, A)) - assert (~ismember (2, A)) + assert (isequal (triu(x), x)) + assert (isequal (triu(x,0), x)) + assert (isequal (triu(x,1), 0)) + assert (isequal (triu(x,-1), 0)) ***** test - % set + % with symbols syms x - S = finiteset(2, sym(pi), x); - assert (ismember (x, S)) + A = [x 2*x; 3*x 4*x]; + assert (isequal (triu(A), [x 2*x; 0 4*x])) ***** test - % set with positive symbol - syms p positive - S = finiteset(2, sym(pi), p); - assert (~ismember (-1, S)) + % diagonal shifts + B = round(10*rand(3,4)); + A = sym(B); + assert (isequal (triu(A), triu(B))) + assert (isequal (triu(A,0), triu(B,0))) + assert (isequal (triu(A,1), triu(B,1))) + assert (isequal (triu(A,-1), triu(B,-1))) +***** test + % double array pass through + B = round(10*rand(3,4)); + assert (isequal (triu(B,sym(1)), triu(B,1))) + assert (isa (triu(B,sym(1)), 'double')) +***** test + % immutable test + A = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])'); + assert (isequal (triu (A), sym ([1 2; 0 4]))) + assert (isequal (tril (A), sym ([1 0; 3 4]))) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/logint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/logint.m -***** error logint (sym(1), 2) -***** xtest - assert (isequaln (logint (sym(nan)), sym(nan))) -!!!!! known failure -assert (isequaln (logint (sym (nan)), sym (nan))) failed +[inst/@sym/sym2poly.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sym2poly.m +***** shared x,y,a,b,c + syms x y a b c +***** assert (isequal (sym2poly (x^2 + 3*x - 4), [1 3 -4])) +***** assert (isequal (sym2poly (x^6 - x^3), [1 0 0 -1 0 0 0])) +***** assert (isequal (sym2poly (x^2 + 3*x - 4, x), [1 3 -4])) +***** assert (norm (sym2poly (pi*x^2 + exp(sym(1))) - [pi 0 exp(1)]) < 10*eps) +***** assert (isa (sym2poly (x^2 + 3*x - 4), 'double')) +***** assert (isa (sym2poly (x^2 + 3*x - 4, x), 'sym')) +***** assert (isequal (sym2poly (x^2+y*x, x), [sym(1) y sym(0)])) +***** assert (isequal (sym2poly (x^2+y*x, y), [x x^2])) +***** assert (isequal (sym2poly (poly2sym ([a b c], x), x), [a b c])) +***** assert (isequal (poly2sym (sym2poly(a*x^2 + c, x), x), a*x^2 + c)) +***** assert (isequal (sym2poly (poly2sym ([1 2 3])), [1 2 3])) +***** error + % too many symbols for single-input + p = a*x^2 + 2; + c = sym2poly (p); +***** assert (isequal (sym2poly (sym(5)), sym(5))) +13 tests, 13 passed, 0 known failure, 0 skipped +[inst/@sym/nextprime.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/nextprime.m +***** assert (isequal (nextprime(sym(2)), 3)); +***** assert (isequal (nextprime(sym(18)), 19)); +***** assert (isequal (nextprime(sym([1 2 3])), [2 3 5])); +***** assert (isequal (nextprime(sym([-1 0])), [2 2])); +***** test + % result is a sym + p = nextprime(sym(2)); + assert (isa (p, 'sym')) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/erfi.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfi.m +***** error erfi (sym(1), 2) +***** assert (isequaln (erfi (sym(nan)), sym(nan))) ***** shared x, d - d = 2; - x = sym('2'); + d = 0; + x = sym('0'); ***** test - f1 = logint(x); - f2 = 1.045163780117492784845; + f1 = erfi(x); + f2 = 0; assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = logint(A); - f2 = 1.045163780117492784845; + f1 = erfi(A); + f2 = 0; f2 = [f2 f2; f2 f2]; assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = logint (d); - f = logint (y); + A = erfi (d); + f = erfi (y); h = function_handle (f); B = h (d); assert (A, B, -eps) -5 tests, 4 passed, 1 known failure, 0 skipped +5 tests, 5 passed, 0 known failure, 0 skipped [inst/@sym/nchoosek.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/nchoosek.m ***** assert (isequal (nchoosek(sym(5), sym(2)), sym(10))) @@ -11330,6 +11642,468 @@ B = gamma (n + 1) / (gamma (k + 1) * gamma (n - k + 1)); assert (double (A), double (B), -2*eps) 11 tests, 11 passed, 0 known failure, 0 skipped +[inst/@sym/acosh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/acosh.m +***** error acosh (sym(1), 2) +***** assert (isequaln (acosh (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); +***** test + f1 = acosh(x); + f2 = acosh(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = acosh(A); + f2 = acosh(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = acosh (d); + f = acosh (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/ezsurf.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ezsurf.m +***** error + syms u v t + ezsurf(u*v, 2*u*v, 3*v*t) +***** error + syms u v t + ezsurf(u*v, 2*u*v, u*v*t) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/power.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/power.m +***** test + % scalar .^ scalar + syms x + assert (isa (x.^2, 'sym')) + assert (isa (2.^x, 'sym')) + assert (isa (x.^x, 'sym')) + assert (isequal (x.^2, x^2)) + assert (isequal (2.^x, 2^x)) + assert (isequal (x.^x, x^x)) +***** test + % scalar .^ matrix + D = [0 1; 2 3]; + A = sym(D); + assert (isequal ( sym(2).^D , 2.^D )) + assert (isequal ( sym(2).^A , 2.^A )) + assert (isequal ( 2.^D , 2.^A )) + assert (isequal ( 2.^A , 2.^A )) +***** test + % matrix .^ matrix + syms x + A = [x 2*x; 3*x 4*x]; + D = [0 1; 2 3]; + B = sym(D); + assert (isequal ( A.^D, [1 2*x; 9*x^2 64*x^3] )) + assert (isequal ( A.^B, [1 2*x; 9*x^2 64*x^3] )) +***** test + % matrix .^ scalar + syms x + A = [x 2*x]; + assert (isequal ( A.^2, [x^2 4*x^2] )) + assert (isequal ( A.^sym(2), [x^2 4*x^2] )) +***** test + % 1^oo + % (sympy >= 0.7.5 gives NaN, SMT R2013b: gives 1) + oo = sym(inf); + assert (isnan (1^oo)) +***** test + % 1^zoo + % (1 on sympy 0.7.4--0.7.6, but nan in git (2014-12-12, a210908d4)) + zoo = sym('zoo'); + assert (isnan (1^zoo)) +***** test + % immutable test + A = sym([1 2]); + B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)]])'); + assert (isequal (A.^A, B.^B)) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/acoth.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/acoth.m +***** error acoth (sym(1), 2) +***** assert (isequaln (acoth (sym(nan)), sym(nan))) +***** shared x, d + d = 2; + x = sym('2'); +***** test + f1 = acoth(x); + f2 = acoth(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = acoth(A); + f2 = acoth(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = acoth (d); + f = acoth (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/erfinv.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfinv.m +***** error erfinv (sym(1), 2) +***** assert (isequaln (erfinv (sym(nan)), sym(nan))) +***** shared x, d + d = 1/2; + x = sym('1/2'); +***** test + f1 = erfinv(x); + f2 = erfinv(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = erfinv(A); + f2 = erfinv(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = erfinv (d); + f = erfinv (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/mldivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/mldivide.m +***** test + % scalar + syms x + assert (isa( x\x, 'sym')) + assert (isequal( x\x, sym(1))) + assert (isa( 2\x, 'sym')) + assert (isa( x\2, 'sym')) +***** test + % scalar \ matrix: easy, no system + D = 2*[0 1; 2 3]; + A = sym(D); + assert (isequal ( 2 \ A , D/2 )) + assert (isequal ( sym(2) \ A , D/2 )) +***** test + % singular matrix + A = sym([1 2; 2 4]); + b = sym([5; 10]); + x = A \ b; + syms c1 + y = [-2*c1 + 5; c1]; + assert (isequal (x, y)) +***** test + % singular matrix, mult RHS + A = sym([1 2; 2 4]); + B = sym([[5; 10] [0; 2] [0; 0]]); + x = A \ B; + syms c1 c5 + y = [-2*c1 + 5 nan -2*c5; c1 nan c5]; + assert (isequaln (x, y)) +***** warning + % vpa, nearly singular matrix + A = sym([1 2; 2 4]); + A(1,1) = vpa('1.001'); + b = sym([1; 2]); + x = A \ b; + y = [sym(0); vpa('0.5')]; + assert (isequal (x, y)) +***** warning + % vpa, singular rhs + A = sym([1 2; 2 4]); + b = [vpa('1.01'); vpa('2')]; + x = A \ b; + assert (all(isnan(x))) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/cumsum.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/cumsum.m +***** shared x, y + x = sym ('x'); + y = sym ('y'); +***** error cumsum (x, 1, 2) +***** assert (isequal (cumsum ([-x; -2*x; -3*x]), [-x; -3*x; -6*x])) +***** assert (isequal (cumsum ([x + 2i*y, 2*x + i*y]), [x + 2i*y, 3*x + 3i*y])) +***** assert (isequal (cumsum ([x, 2*x; 3*x, 4*x], 1), [1*x, 2*x; 4*x, 6*x] )) +***** assert (isequal (cumsum ([x, 2*x; 3*x, 4*x], 2), [1*x, 3*x; 3*x, 7*x] )) +***** test cumsum ([x, x], [2, 1]); # ensure behaves like builtin cumsum +***** test cumsum ([x, x], [1, -2]); # ensure behaves like builtin cumsum +***** error cumsum (x, []) +***** error cumsum (x, {1}) +***** error cumsum (x, struct('a', 1)) +***** error cumsum (x, x) +***** error cumsum (x, 0) +***** error cumsum (x, -1) +13 tests, 13 passed, 0 known failure, 0 skipped +[inst/@sym/gt.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/gt.m +***** test + % simple + x = sym(1); y = sym(1); e = x > y; + assert (~logical (e)) + x = sym(1); y = sym(2); e = x > y; + assert (~logical (e)) +***** test + % array -- array + syms x + a = sym([1 3 3 2*x]); + b = sym([2 x 3 10]); + e = a > b; + assert (isa (e, 'sym')) + assert (~logical (e(1))) + assert (isa (e(2), 'sym')) + assert (isequal (e(2), 3 > x)) + assert (~logical (e(3))) + assert (isa (e(4), 'sym')) + assert (isequal (e(4), 2*x > 10)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/pinv.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/pinv.m +***** test + % scalar + syms x + assert (isequal (pinv(x), 1/x)) +***** test + % 2x3 + A = [1 2 3; 4 5 6]; + assert (max (max (abs (double (pinv (sym (A))) - pinv(A)))) <= 10*eps) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/beta.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/beta.m +***** error beta (sym(1), 2, 3) +***** assert (isequal (double (beta (sym(1), 2)), 1/2)) +***** assert (isinf (double (beta (sym(1), 0)))) +***** test + % round trip + syms x y + f = beta (x, y); + h = function_handle (f); + A = h (1.1, 2.2); + B = beta (1.1, 2.2); + assert (A, B) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/log2.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/log2.m +***** assert (isequal (log2 (sym (1024)), sym (10))) +***** assert (isequal (log2 (sym ([2 16; 32 1])), sym ([1 4; 5 0]))) +***** test + % round-trip + syms x + f = log2 (x); + h = function_handle (f); + A = h (1.1); + B = log2 (1.1); + assert (A, B, -5*eps) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/taylor.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/taylor.m +***** test + syms x + f = exp(x); + expected = 1 + x + x^2/2 + x^3/6 + x^4/24 + x^5/120; + assert (isequal (taylor(f), expected)) + assert (isequal (taylor(f,x), expected)) + assert (isequal (taylor(f,x,0), expected)) +***** test + syms x + f = exp(x); + expected = 1 + x + x^2/2 + x^3/6 + x^4/24; + assert (isequal (taylor(f,'order',5), expected)) + assert (isequal (taylor(f,x,'order',5), expected)) + assert (isequal (taylor(f,x,0,'order',5), expected)) +***** test + % key/value ordering doesn't matter + syms x + f = exp(x); + g1 = taylor(f, 'expansionPoint', 1, 'order', 3); + g2 = taylor(f, 'order', 3, 'expansionPoint', 1); + assert (isequal (g1, g2)) +***** test + syms x + f = x^2; + assert (isequal (taylor(f,x,0,'order',0), 0)) + assert (isequal (taylor(f,x,0,'order',1), 0)) + assert (isequal (taylor(f,x,0,'order',2), 0)) + assert (isequal (taylor(f,x,0,'order',3), x^2)) + assert (isequal (taylor(f,x,0,'order',4), x^2)) +***** test + syms x y + f = exp(x)+exp(y); + expected = 2 + x + x^2/2 + x^3/6 + x^4/24 + y + y^2/2 + y^3/6 + y^4/24; + assert (isAlways(taylor(f,[x,y],'order',5)== expected)) + assert (isAlways(taylor(f,[x,y],[0,0],'order',5) == expected)) +***** test + % key/value ordering doesn't matter + syms x + f = exp(x); + g1 = taylor(f, 'expansionPoint', 1, 'order', 3); + g2 = taylor(f, 'order', 3, 'expansionPoint', 1); + assert (isequal (g1, g2)) +***** test + syms x + f = x^2; + assert (isequal (taylor(f,x,0,'order',0), 0)) + assert (isequal (taylor(f,x,0,'order',1), 0)) + assert (isequal (taylor(f,x,0,'order',2), 0)) + assert (isequal (taylor(f,x,0,'order',3), x^2)) + assert (isequal (taylor(f,x,0,'order',4), x^2)) +***** test + % syms for a and order + syms x + f = x^2; + assert (isequal (taylor(f,x,sym(0),'order',sym(2)), 0)) + assert (isequal (taylor(f,x,sym(0),'order',sym(4)), x^2)) +***** test + syms x y + f = exp (x^2 + y^2); + expected = 1+ x^2 +y^2 + x^4/2 + x^2*y^2 + y^4/2; + assert (isAlways(taylor(f,[x,y],'order',5)== expected)) + assert (isAlways(taylor(f,[x,y],'expansionPoint', [0,0],'order',5) == expected)) +***** test + syms x y + f = sqrt(1+x^2+y^2); + expected = 1+ x^2/2 +y^2/2 - x^4/8 - x^2*y^2/4 - y^4/8; + assert (isAlways(taylor(f,[x,y],'order',6)== expected)) + assert (isAlways(taylor(f,[x,y],'expansionPoint', [0,0],'order',5) == expected)) +***** test + syms x y + f = sin (x^2 + y^2); + expected = sin(sym(1))+2*cos(sym(1))*(x-1)+(cos(sym(1))-2*sin(sym(1)))*(x-1)^2 + cos(sym(1))*y^2; + assert (isAlways(taylor(f,[x,y],'expansionPoint', [1,0],'order',3) == expected)) +***** test + % key/value ordering doesn't matter + syms x y + f = exp(x+y); + g1 = taylor(f, 'expansionPoint',1, 'order', 3); + g2 = taylor(f, 'order', 3, 'expansionPoint',1); + assert (isAlways(g1== g2)) +***** test + syms x y + f = x^2 + y^2; + assert (isAlways(taylor(f,[x,y],[0,0],'order',0)== sym(0) )) + assert (isAlways(taylor(f,[x,y],[0,0],'order',1)== sym(0) )) + assert (isAlways(taylor(f,[x,y],[0,0],'order',2)== sym(0) )) + assert (isAlways(taylor(f,[x,y],[0,0],'order',3)== sym(x^2 + y^2))) + assert (isAlways(taylor(f,[x,y],[0,0],'order',4)== sym(x^2 + y^2))) +***** test + % expansion point + syms x a + f = x^2; + g = taylor(f,x,2); + assert (isequal (simplify(g), f)) + assert (isequal (g, 4*x+(x-2)^2-4)) + g = taylor(f,x,a); + assert (isequal (simplify(g), f)) +***** test + % wrong order-1 series with nonzero expansion pt: + % upstream bug https://github.com/sympy/sympy/issues/9351 + syms x + g = x^2 + 2*x + 3; + h = taylor (g, x, 4, 'order', 1); + assert (isequal (h, 27)) +***** test + syms x y z + g = x^2 + 2*y + 3*z; + h = taylor (g, [x,y,z], 'order', 4); + assert (isAlways(h == g)) ; +***** test + syms x y z + g = sin(x*y*z); + h = taylor (g, [x,y,z], 'order', 4); + assert (isAlways(h == x*y*z)) ; +***** error + syms x y + taylor(0, [x, y], [1, 2, 3]); +18 tests, 18 passed, 0 known failure, 0 skipped +[inst/@sym/ipermute.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ipermute.m +***** error permute (sym(1)) +***** error permute (sym(1), 2, 3) +***** test + syms x + A = [1 x]; + perm = [2 1]; + B = permute(A, perm); + C = ipermute(B, perm); + assert (isequal(C, A)) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/fresnels.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/fresnels.m +***** error fresnels (sym(1), 2) +***** test + a = fresnels(sym(0)); + assert (isequal (a, sym(0))) +***** test + b = fresnels(sym('oo')); + assert (isequal (b, sym(1)/2)) +***** test + % values in a matrix + syms x + a = fresnels([sym(0) sym('oo') x 1]); + b = [sym(0) sym(1)/2 fresnels(x) fresnels(sym(1))]; + assert (isequal (a, b)) +***** test + % round trip + syms x + f = fresnels (x); + h = function_handle (f); + A = h (1.1); + B = fresnels (1.1); + assert (A, B) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/ifourier.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ifourier.m +***** error ifourier (sym(1), 2, 3, 4) +***** test + % matlab SMT compat + syms t r u x w + Pi=sym('pi'); + assert(logical( ifourier(exp(-abs(w))) == 1/(Pi*(x^2 + 1)) )) + assert(logical( ifourier(exp(-abs(x))) == 1/(Pi*(t^2 + 1)) )) + assert(logical( ifourier(exp(-abs(r)),u) == 1/(Pi*(u^2 + 1)) )) + assert(logical( ifourier(exp(-abs(r)),r,u) == 1/(Pi*(u^2 + 1)) )) +***** test + % basic + syms x w + Pi=sym('pi'); + assert(logical( ifourier(exp(-w^2/4)) == 1/(sqrt(Pi)*exp(x^2)) )) + assert(logical( ifourier(sqrt(Pi)/exp(w^2/4)) == exp(-x^2) )) +***** test + % Dirac delta tests + syms x w + Pi=sym('pi'); + assert(logical( ifourier(dirac(w-2)) == exp(2*1i*x)/(2*Pi) )) + assert (logical( ifourier(sym(2), w, x) == 2*dirac(x) )) +***** test + % advanced test + syms x w c d + Pi=sym('pi'); + f=(Pi*(dirac(x-c)+dirac(x+c))+2*Pi*1i*(-dirac(x+3*d)+dirac(x-3*d))+2/(x^2+1))/(2*Pi); + assert(logical( simplify(ifourier(cos(c*w)+2*sin(3*d*w)+exp(-abs(w)))-f) == 0 )) +***** xtest + % Inverse Fourier transform cannot recover non-smooth functions + % SymPy cannot evaluate correctly?? + syms x w + assert(logical( ifourier(2/(w^2 + 1)) == exp(-abs(x)) )) + assert(logical( ifourier(2/(w^2 + 1)) == heaviside(x)/exp(x) + heaviside(-x)*exp(x) )) + assert(logical( ifourier(-(w*4)/(w^4 + 2*w^2 + 1) )== -x*exp(-abs(x))*1i )) + assert(logical( ifourier(-(w*4)/(w^4 + 2*w^2 + 1) )== -x*(heaviside(x)/exp(x) + heaviside(-x)*exp(x))*1i )) +!!!!! known failure +assert (logical (ifourier (2 / (w ^ 2 + 1)) == exp (-abs (x)))) failed +***** error ifourier (sym('k', 'positive')*sym('k')) +***** test + % SMT compact, prefers k over symvar + syms k x y + assert (isequal (ifourier(y*exp(-k^2/4)), y/sqrt(sym(pi))*exp(-x^2))) +8 tests, 7 passed, 1 known failure, 0 skipped [inst/@sym/ccode.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/ccode.m ***** shared x,y,z @@ -11354,423 +12128,378 @@ s2 = strrep(expected_c_code, sprintf('\n'), sprintf('\r\n')); assert (strcmp (C.code, s1) || strcmp (C.code, s2)) 2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/has.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/has.m -***** shared A, x, y - syms x y - A = [sym(pi) 2*sym(pi); x*y x+y]; -***** assert (isequal (has(A, x), [false false; true true])); -***** assert (isequal (has(A, x+y), [false false; false true])); -***** assert (isequal (has(A, 2), [false true; false false])); -***** assert (isequal (has(A, sym(pi)), [true true; false false])); -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/gradient.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/gradient.m +[inst/@sym/char.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/char.m +***** test + % issue #91: expose as string + a = sym(pi); + assert (strcmp (char (a), 'pi')) +***** shared x + x = sym('x'); +***** assert (strcmp (char (x), 'x')) +***** assert (strcmp (char (2*x), '2*x')) +***** assert (strcmp (char ([2*x x]), 'Matrix([[2*x, x]])')) +***** assert (strcmp (char ([2*x 2; 1 x]), 'Matrix([[2*x, 2], [1, x]])')) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/sum.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sum.m +***** error sum (sym(1), 2, 3) +***** error sum (sym(1), 42) ***** shared x,y,z syms x y z +***** assert (isequal (sum (x), x)) +***** assert (isequal (sum ([x y z]), x+y+z)) +***** assert (isequal (sum ([x; y; z]), x+y+z)) +***** assert (isequal (sum ([x y z], 1), [x y z])) +***** assert (isequal (sum ([x y z], 2), x+y+z)) +***** shared a,b + b = [1 2; 3 4]; a = sym(b); +***** assert (isequal (sum(a), sum(b))) +***** assert (isequal (sum(a,1), sum(b,1))) +***** assert (isequal (sum(a,2), sum(b,2))) ***** test - % 1D - f = x^2; - assert (isequal (gradient(f), diff(f,x))) - assert (isequal (gradient(f,{x}), diff(f,x))) - assert (isequal (gradient(f,[x]), diff(f,x))) - assert (isequal (gradient(f,x), diff(f,x))) + % weird inputs + a = sum('xx', sym(1)); + assert (isequal (a, sym('xx'))) +11 tests, 11 passed, 0 known failure, 0 skipped +[inst/@sym/round.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/round.m ***** test - % const - f = sym(1); - g = sym(0); - assert (isequal (gradient(f), g)) - assert (isequal (gradient(f,x), g)) + d = 3/2; + x = sym('3/2'); + f1 = round(x); + f2 = round(d); + assert (isequal (f1, f2)) +***** xtest + % ideally rounding direction would match Octave + d = 5/2; + x = sym('5/2'); + f1 = round(x); + f2 = round(d); + assert (isequal (f1, f2)) +!!!!! known failure +assert (isequal (f1, f2)) failed ***** test - % double const - f = 1; - g = sym(0); - assert (isequal (gradient(f,x), g)) + D = [1.1 4.6; -3.4 -8.9]; + A = [sym(11)/10 sym(46)/10; sym(-34)/10 sym(-89)/10]; + f1 = round(A); + f2 = round(D); + assert( isequal (f1, f2)) ***** test - % 1D fcn in 2d/3d - f = sin(y); - assert (isequal (gradient(f), diff(f,y))) - assert (isequal (gradient(f, {x,y}), [sym(0); diff(f,y)])) - assert (isequal (gradient(f, [x y]), [sym(0); diff(f,y)])) - assert (isequal (size (gradient(f, {x,y})), [2 1])) - assert (isequal (gradient(f, {x,y,z}), [0; diff(f,y); 0])) - assert (isequal (gradient(f, [x y z]), [0; diff(f,y); 0])) - assert (isequal (size (gradient(f, {x,y,z})), [3 1])) + d = sym(-11)/10; + c = -1; + assert (isequal (round (d), c)) ***** test - % grad is column vector - f = sin(y); - assert (isequal (size (gradient(f, {x,y})), [2 1])) - assert (isequal (size (gradient(f, {x,y,z})), [3 1])) - assert (isequal (size (gradient(f, [x y])), [2 1])) - assert (isequal (size (gradient(f, [x;y])), [2 1])) + d = sym(-19)/10; + c = -2; + assert (isequal (round (d), c)) ***** test - % 2d fcn in 2d/3d - f = sin(exp(x)*y); - g2 = [diff(f,x); diff(f,y)]; - g3 = [diff(f,x); diff(f,y); diff(f,z)]; - assert (isequal (gradient(f), g2)) - assert (isequal (gradient(f, {x,y}), g2)) - assert (isequal (gradient(f, {x,y,z}), g3)) + d = 7j/2; + x = sym(7j)/2; + f1 = round (x); + f2 = round (d); + assert (isequal (f1, f2)) ***** test - % 2d fcn in 2d/3d - f = sin(exp(x)*y+sinh(z)); - g2 = [diff(f,x); diff(f,y)]; - g3 = [diff(f,x); diff(f,y); diff(f,z)]; - assert (isequal (gradient(f), g3)) - assert (isequal (gradient(f, {x,y}), g2)) - assert (isequal (gradient(f, {x,y,z}), g3)) -***** error gradient(sym('x'), 42, 42) -***** error gradient([sym('x') sym('x')]) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/log2.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/log2.m -***** assert (isequal (log2 (sym (1024)), sym (10))) -***** assert (isequal (log2 (sym ([2 16; 32 1])), sym ([1 4; 5 0]))) + d = 5/3 - 4j/7; + x = sym(5)/3 - sym(4j)/7; + f1 = round (x); + f2 = round (d); + assert (isequal (f1, f2)) +7 tests, 6 passed, 1 known failure, 0 skipped +[inst/@sym/isnan.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isnan.m +***** shared x,zoo,oo,snan + oo = sym(inf); + zoo = sym('zoo'); + x = sym('x'); + snan = sym(nan); ***** test - % round-trip - syms x - f = log2 (x); - h = function_handle (f); - A = h (1.1); - B = log2 (1.1); - assert (A, B, -5*eps) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/divergence.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/divergence.m -***** shared x,y,z - syms x y z + % various ops that give nan + assert (isnan(0*oo)) + assert (isnan(0*zoo)) + assert (isnan(snan)) + assert (isnan(snan-snan)) + assert (isnan(oo+snan)) + assert (isnan(oo-oo)) + assert (isnan(oo-zoo)) + assert (isnan(oo+zoo)) + assert (~isnan(oo)) + assert (~isnan(zoo)) + assert (~isnan(oo+oo)) ***** test - % 1D - f = x^2; - assert (isequal (divergence(f), diff(f,x))) - assert (isequal (divergence(f,{x}), diff(f,x))) - assert (isequal (divergence(f,[x]), diff(f,x))) - assert (isequal (divergence(f,x), diff(f,x))) + % more ops give nan + assert(isnan(x+snan)) + assert(isnan(x*snan)) + assert(isnan(0*snan)) + assert(isnan(x+nan)) + assert(isnan(x*nan)) + assert(isnan(sym(0)*nan)) ***** test - % const - f = [sym(1); 2; exp(sym(3))]; - assert (isequal (divergence(f,{x,y,z}), 0)) - f = [sym(1); 2; exp(sym('c'))]; - assert (isequal (divergence(f,{x,y,z}), 0)) + % array + assert (isequal( isnan([oo zoo]), [0 0] )) + assert (isequal( isnan([10 snan]), [0 1] )) + assert (isequal( isnan([snan snan]), [1 1] )) + assert (isequal( isnan([snan x]), [1 0] )) ***** test - % double const - f = [1 2]; - g = sym(0); - assert (isequal (divergence(f, [x y]), g)) - % should fail, calls @double: divergence(f, {x y}), g)) + % sub in to algebraic expression gives nan + y = x - oo; + y = subs(y, x, oo); + assert(isnan(y)) ***** test - % 1D fcn in 2d/3d - f = [x y z]; - assert (isequal (divergence(f), 3)) - assert (isequal (divergence(f, {x,y,z}), 3)) - assert (isequal (divergence(f, [x,y,z]), 3)) + % Must not contain string 'symbol'; these all should make an + % actual nan. Actually a ctor test, not isnan. + y = sym(nan); + assert (isempty (strfind (sympy (y), 'Symbol'))) + y = sym('nan'); + assert (isempty (strfind (sympy (y), 'Symbol'))) + y = sym('NaN'); + assert (isempty( strfind (sympy (y), 'Symbol'))) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/mod.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/mod.m +***** error mod (sym(1), 2, 3 ,4) +***** assert (isequal (mod (sym(5), 4), sym(1))) +***** assert (isequal (mod ([sym(5) 8], 4), [1 0] )) +***** assert (isequal (mod (sym(5), [2 3]), [1 2] )) +***** assert (isequal (mod ([sym(5) sym(6)], [2 3]), [1 0] )) ***** test - % 2d fcn in 2d/3d - f = sin(exp(x)*y+sinh(z)); - g2 = [diff(f,x); diff(f,y)]; - l2 = diff(g2(1),x) + diff(g2(2),y); - g3 = [diff(f,x); diff(f,y); diff(f,z)]; - l3 = diff(g3(1),x) + diff(g3(2),y) + diff(g3(3),z); - assert (isequal (divergence(g2, {x,y}), l2)) - assert (isequal (divergence(g3, {x,y,z}), l3)) -***** error divergence ([1 2], [sym('x')]) -***** error divergence ([1 2], sym('x'), 42) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/atand.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/atand.m -***** error atand (sym(1), 2) -***** assert (isequaln (atand (sym(nan)), sym(nan))) + syms x + assert (isequal ( mod (5*x, 3), 2*x )) ***** test - f1 = atand (sym(1)/2); - f2 = atand (1/2); - assert (double (f1), f2, -eps) + syms x + a = [7*x^2 + 3*x + 3 3*x; 13*x^4 6*x]; + assert (isequal ( mod (a,3), [x^2 0; x^4 0] )) ***** test - D = [1 2; 3 4]/4; - A = sym([1 2; 3 4])/4; - f1 = atand (A); - f2 = atand (D); - assert (double (f1), f2, -eps) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/frac.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/frac.m + % vector of polys with mix of vars: symvar on each + syms x y + a = [6*x 7*y]; + b = mod(a, 4); + c = [2*x 3*y]; + assert (isequal (b, c)) ***** test - f1 = frac(sym(11)/10); - f2 = sym(1)/10; - assert (isequal (f1, f2)) + % coeff has variable + syms x + n = sym('n', 'integer'); + p = (3*n + 2)*x; + q = mod(p, 3); + assert (isequal (q, 2*x)) ***** test - d = sym(-11)/10; - c = sym(9)/10; - assert (isequal (frac (d), c)) + % coeff has variable + syms x a + p = a*x; + q = mod(p, 3); + q = children(q); + q = q(2); % order might be fragile! + w = subs(q, a, 5); + assert (isequal (w, 2)) ***** test - d = sym(-19)/10; - c = sym(1)/10; - assert (isequal (frac (d), c)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/triu.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/triu.m + % different modulo + syms x y + q = mod([5*x + 10 5*y + 10], [2 3]); + assert (isequal (q, [x 2*y + 1])) +11 tests, 11 passed, 0 known failure, 0 skipped +[inst/@sym/fresnelc.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/fresnelc.m +***** error fresnelc (sym(1), 2) ***** test - % scalar + a = fresnelc(sym(0)); + assert (isequal (a, sym(0))) +***** test + b = fresnelc(sym('oo')); + assert (isequal (b, sym(1)/2)) +***** test + % values in a matrix syms x - assert (isequal (triu(x), x)) - assert (isequal (triu(x,0), x)) - assert (isequal (triu(x,1), 0)) - assert (isequal (triu(x,-1), 0)) + a = fresnelc([sym(0) sym('oo') x 1]); + b = [sym(0) sym(1)/2 fresnelc(x) fresnelc(sym(1))]; + assert (isequal (a, b)) ***** test - % with symbols + % round trip syms x - A = [x 2*x; 3*x 4*x]; - assert (isequal (triu(A), [x 2*x; 0 4*x])) + f = fresnelc (x); + h = function_handle (f); + A = h (1.1); + B = fresnelc (1.1); + assert (A, B) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/times.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/times.m ***** test - % diagonal shifts - B = round(10*rand(3,4)); - A = sym(B); - assert (isequal (triu(A), triu(B))) - assert (isequal (triu(A,0), triu(B,0))) - assert (isequal (triu(A,1), triu(B,1))) - assert (isequal (triu(A,-1), triu(B,-1))) + % scalar + syms x + assert (isa (x.*2, 'sym')) + assert (isequal (x.*2, x*2)) + assert (isequal (2.*sym(3), sym(6))) + assert (isequal (sym(2).*3, sym(6))) ***** test - % double array pass through - B = round(10*rand(3,4)); - assert (isequal (triu(B,sym(1)), triu(B,1))) - assert (isa (triu(B,sym(1)), 'double')) + % matrix-matrix and matrix-scalar + D = [0 1; 2 3]; + A = sym(D); + assert (isequal ( 2.*A , 2*D )) + assert (isequal ( A.*2 , 2*D )) + assert (isequal ( A.*A , D.*D )) + assert (isequal ( A.*D , D.*D )) + assert (isequal ( D.*A , D.*D )) +***** test + syms x + A = [1 x]; + B = [2 3]; + assert (isequal (A.*B, [2 3*x])) ***** test % immutable test - A = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])'); - assert (isequal (triu (A), sym ([1 2; 0 4]))) - assert (isequal (tril (A), sym ([1 0; 3 4]))) + A = sym([1 2]); + B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)]])'); + assert (isequal (A.*A, B.*B)) +***** test + % MatrixSymbol test + A = sym([1 2; 3 4]); + B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])'); + C = sym('MatrixSymbol("C", 2, 2)'); + assert (~ isempty (strfind (sympy (C.*C), 'Hadamard'))) + assert (~ isempty (strfind (sympy (A.*C), 'Hadamard'))) + assert (~ isempty (strfind (sympy (C.*A), 'Hadamard'))) + assert (~ isempty (strfind (sympy (B.*C), 'Hadamard'))) + assert (~ isempty (strfind (sympy (C.*B), 'Hadamard'))) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/asinh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/asinh.m -***** error asinh (sym(1), 2) -***** assert (isequaln (asinh (sym(nan)), sym(nan))) +[inst/@sym/igamma.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/igamma.m +***** test + % mostly tested in @sym/gammainc + syms x + assert (isequal (igamma (2, x), gammainc(x, 2, 'upper'))) +***** test + % unregularized + B = double (igamma (sym(3), 1)); + A = gammainc (1, 3, 'upper')*gamma (3); + assert (A, B, -2*eps) +***** test + % something like a round trip: no igamma() + syms x a + f = igamma (a, x); + h = function_handle (f, 'vars', [a x]); + A = h (1.1, 2.2); + B = double (igamma (sym(11)/10, sym(22)/10)); + C = gammainc (2.2, 1.1, 'upper')*gamma(1.1); + assert (A, B, -10*eps) + assert (A, C, -10*eps) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/ceil.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ceil.m +***** error ceil (sym(1), 2) +***** assert (isequaln (ceil (sym(nan)), sym(nan))) ***** shared x, d - d = 1; - x = sym('1'); + d = 3/2; + x = sym('3/2'); ***** test - f1 = asinh(x); - f2 = asinh(d); + f1 = ceil(x); + f2 = ceil(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = asinh(A); - f2 = asinh(D); + f1 = ceil(A); + f2 = ceil(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = asinh (d); - f = asinh (y); + A = ceil (d); + f = ceil (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/lt.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/lt.m -***** test - % simple - x = sym(1); y = sym(1); e = x < y; - assert (~logical (e)) - x = sym(1); y = sym(2); e = x < y; - assert (logical (e)) -***** test - % mix sym and double - x = sym(1); y = 1; e = x < y; - assert (~logical (e)) - x = sym(1); y = 2; e = x < y; - assert (logical (e)) - x = 1; y = sym(1); e = x < y; - assert (~logical (e)) - x = 1; y = sym(2); e = x < y; - assert (logical (e)) -***** test - % Type of the output is sym or logical? - % FIXME: in current version, they are sym - x = sym(1); y = sym(1); e1 = x < y; - x = sym(1); y = sym(2); e2 = x < y; - %assert (islogical (e1)) - %assert (islogical (e2)) - assert (isa (e1, 'sym')) - assert (isa (e2, 'sym')) -***** test - % ineq w/ symbols - syms x y - e = x < y; - assert (~islogical (e)) - assert (isa (e, 'sym')) +[inst/@sym/horner.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/horner.m +***** error horner (sym(1), 2, 3) +***** assert (isAlways (horner(sym(1)) == 1)) ***** test - % array -- array syms x - a = sym([1 3 3 2*x]); - b = sym([2 x 3 10]); - e = a < b; - assert (isa (e, 'sym')) - assert (logical (e(1))) - assert (isa (e(2), 'sym')) - assert (isequal (e(2), 3 < x)) - assert (~logical (e(3))) - assert (isa (e(4), 'sym')) - assert (isequal (e(4), 2*x < 10)) -***** test - % array -- scalar - syms x oo - a = sym([1 x oo]); - b = sym(3); - e = a < b; - assert (isa (e, 'sym')) - assert (logical (e(1))) - assert (isa (e(2), 'sym')) - assert (isequal (e(2), x < 3)) - assert (~logical (e(3))) + assert (isAlways (horner(x) == x)) ***** test - % scalar -- array - syms x oo - a = sym(1); - b = sym([2 x -oo]); - e = a < b; - assert (isa (e, 'sym')) - assert (logical (e(1))) - assert (isa (e(2), 'sym')) - assert (isequal (e(2), 1 < x)) - assert (~logical (e(3))) + syms x a + p = a^2 + a*x + 2*a + 2*x; + assert (isequal (horner (p, a), a*(a+x+2) + 2*x)) + q = a^2 + 2*a + x*(a + 2); + assert (isequal (horner (p, x), q)) + assert (isequal (horner (p), q)) ***** test - % ineq w/ nan syms x - snan = sym(nan); - e = x < snan; - assert (~logical (e)) - e = snan < x; - assert (~logical (e)) - b = [sym(0) x]; - e = b < snan; - assert (isequal (e, [false false])) -***** test - % oo - syms oo x - e = oo < x; - assert (isa (e, 'sym')) - assert (strcmp (strtrim (disp (e, 'flat')), 'oo < x')) -***** test - % sympy true matrix - a = sym([1 3 3]); - b = sym([2 4 1]); - e = a < b; - %assert (~isa (e, 'sym')) - %assert (islogical (e)) - assert (isequal (e, [true true false])) -***** test - % oo, finite real variables - syms oo - syms z real - assumeAlso(z, 'finite') - e = -oo < z; - assert (isequal (e, sym(true))) - e = z < oo; - assert (isequal (e, sym(true))) -***** test - % -oo, positive var (known failure w/ sympy 0.7.6.x) - syms oo - syms z positive - e = -oo < z; - assert (logical (e)) - assert (isequal (e, sym(true))) -***** test - % positive - syms z positive - e = -1 < z; - assert (isequal (e, sym(true))) -***** test - syms oo - z = sym('z', 'negative'); - e = z < oo; - assert (isequal (e, sym(true))) -14 tests, 14 passed, 0 known failure, 0 skipped -[inst/@sym/ellipticK.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticK.m -***** error ellipticK (sym(1), 2) -***** assert (isequal (ellipticK (sym (0)), sym (pi)/2)) -***** assert (isequal (ellipticK (sym (-inf)), sym (0))) -***** assert (double (ellipticK (sym (1)/2)), 1.854074677, 10e-10) -***** assert (double (ellipticK (sym (pi)/4)), 2.225253684, 10e-10) -***** assert (double (ellipticK (sym (-55)/10)), 0.9324665884, 10e-11) -***** test - % compare to double ellipke - m = 1/5; - ms = sym(1)/5; - [K, E] = ellipke (m); - assert (double (ellipticK (ms)), K, -1e-15) - assert (double (ellipticE (ms)), E, -1e-15) + p = poly2sym ([2 4 6 8], x); + q = horner (p); + assert (isAlways (p == q)) + assert (isAlways (horner(2*x^3 + 4*x^2 + 6*x + 8) == q)) ***** test - % compare to double ellipke - if (exist ('OCTAVE_VERSION', 'builtin')) - m = -10.3; - ms = -sym(103)/10; - [K, E] = ellipke (m); - assert (double (ellipticK (ms)), K, -1e-15) - assert (double (ellipticE (ms)), E, -1e-15) - end + % non-sym input + syms x + assert (isequal (horner(6, x), sym(6))) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/rewrite.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/rewrite.m ***** test - % compare to Maple - us = vpa (ellipticK (sym (7)), 40); - % > evalf(EllipticK(sqrt(7)), 40); - maple = vpa ('0.6168027921799632674669917683443602673441', 40) - ... - vpa ('0.9114898734184488922164103102629560336918j', 40); - assert (abs (double (maple - us)), 0, 1e-39) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/besseli.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/besseli.m + syms x + assert (isequal (rewrite(x, 'exp'), x)) ***** test - X = [1 2 3; 4 5 6]; - ns = [sym(0) 1 -2; sym(1)/2 -sym(3)/2 pi]; - n = double(ns); - A = double(besseli(ns, X)); - B = besseli(n, X); - assert (all (all (abs (A - B) < 100*eps*abs(A)))) + % empty + e = sym([]); + assert (isequal (rewrite(e, 'sin'), e)) ***** test - % roundtrip syms x - A = besseli(2, 10); - q = besseli(2, x); - h = function_handle(q); - B = h(10); - assert (abs (A - B) <= eps*abs(A)) -***** error besseli(sym('x')) + A = [exp(x) exp(2*x)]; + B = [sinh(x) + cosh(x) sinh(2*x) + cosh(2*x)]; + assert (isequal (rewrite(A, 'sin'), B)) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/zeros.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/zeros.m +[inst/@sym/atanh.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/atanh.m +***** error atanh (sym(1), 2) +***** assert (isequaln (atanh (sym(nan)), sym(nan))) +***** shared x, d + d = 1/2; + x = sym('1/2'); ***** test - y = zeros(sym(2)); - x = [0 0; 0 0]; - assert( isequal( y, sym(x))) + f1 = atanh(x); + f2 = atanh(d); + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - y = zeros(sym(2), 1); - x = [0; 0]; - assert( isequal( y, sym(x))) + D = [d d; d d]; + A = [x x; x x]; + f1 = atanh(A); + f2 = atanh(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - y = zeros(sym(1), 2); - x = [0 0]; - assert( isequal( y, sym(x))) + % round trip + y = sym('y'); + A = atanh (d); + f = atanh (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/erf.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/erf.m +***** error erf (sym(1), 2) +***** assert (isequaln (erf (sym(nan)), sym(nan))) +***** shared x, d + d = 1; + x = sym('1'); ***** test - y = zeros (sym([2 3])); - x = sym (zeros ([2 3])); - assert (isequal (y, x)) -***** assert( isa( zeros(sym(2), 'double'), 'double')) -***** assert( isa( zeros(3, sym(3), 'single') , 'single')) -***** assert( isa( zeros(3, sym(3)), 'sym')) -***** assert( isa( zeros(3, sym(3), 'sym'), 'sym')) -***** xtest - % Issue #13 - assert( isa( zeros(3, 3, 'sym'), 'sym')) -!!!!! known failure -invalid data type specified -9 tests, 8 passed, 1 known failure, 0 skipped -[inst/@sym/iscolumn.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/iscolumn.m -***** assert (iscolumn (sym ([1]))) -***** assert (iscolumn (sym ([1 2 3]'))) -***** assert (~iscolumn (sym ([]))) -***** assert (~iscolumn (sym ([1 2 3]))) -***** assert (~iscolumn (sym ([1 2; 3 4]))) + f1 = erf(x); + f2 = erf(d); + assert( abs(double(f1) - f2) < 1e-15 ) +***** test + D = [d d; d d]; + A = [x x; x x]; + f1 = erf(A); + f2 = erf(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) +***** test + % round trip + y = sym('y'); + A = erf (d); + f = erf (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped [inst/@sym/ellipticPi.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticPi.m @@ -11815,1905 +12544,1905 @@ vpa ('4.798862045930802761256228043192491271947j', 40); assert (abs (double (maple - us)), 0, 6e-39) 9 tests, 7 passed, 2 known failures, 0 skipped +[inst/@sym/ones.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ones.m +***** test + y = ones(sym(2)); + x = [1 1; 1 1]; + assert( isequal( y, sym(x))) +***** test + y = ones(sym(2), 1); + x = [1; 1]; + assert( isequal( y, sym(x))) +***** test + y = ones(sym(1), 2); + x = [1 1]; + assert( isequal( y, sym(x))) +***** test + y = ones (sym([2 3])); + x = sym (ones ([2 3])); + assert (isequal (y, x)) +***** assert( isa( ones(sym(2), 'double'), 'double')) +***** assert( isa( ones(3, sym(3), 'single') , 'single')) +***** assert( isa( ones(3, sym(3)), 'sym')) +***** assert( isa( ones(3, sym(3), 'sym'), 'sym')) +***** xtest + % Issue #13 + assert( isa( ones(3, 3, 'sym'), 'sym')) +!!!!! known failure +invalid data type specified +9 tests, 8 passed, 1 known failure, 0 skipped [inst/@sym/divisors.m] >>>>> /build/octave-symbolic-3.0.1/inst/@sym/divisors.m ***** test assert( isequal( divisors(sym(150)), divisors(sym(-150)) )) 1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/acosd.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/acosd.m -***** error acosd (sym(1), 2) -***** assert (isequaln (acosd (sym(nan)), sym(nan))) +[inst/@sym/ellipticE.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticE.m +***** error ellipticE (sym(1), 2, 3) +***** assert (double (ellipticE (sym (-105)/10)), 3.70961391, 10e-9) +***** assert (double (ellipticE (sym (-pi)/4)), 1.844349247, 10e-10) +***** assert (double (ellipticE (sym (0))), 1.570796327, 10e-10) +***** assert (double (ellipticE (sym (1))), 1, 10e-1) ***** test - f1 = acosd (sym(1)/2); - f2 = acosd (1/2); - assert (double (f1), f2, -eps) + % compare to Maple + us = vpa (ellipticE (sym(7)/6, sym(13)/7), 40); + % > evalf(EllipticE(sin(7/6), sqrt(13/7)), 40); + maple = vpa ('0.6263078268598504591831743625971763209496', 40) + ... + vpa ('0.1775496232203171126975790989055865596501j', 40); + assert (abs (double (maple - us)), 0, 2e-39) ***** test - D = [1 2; 3 4]/4; - A = sym([1 2; 3 4])/4; - f1 = acosd (A); - f2 = acosd (D); - assert (double (f1), f2, -eps) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/columns.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/columns.m + % compare to Maple + us = vpa (ellipticE (sym(8)/7), 40); + % > evalf(EllipticE(sqrt(8/7)), 40); + maple = vpa ('0.8717182992576322508542205614105802333270', 40) + ... + vpa ('0.1066754320328976949531350910798010526685j', 40); + assert (abs (double (maple - us)), 0, 2e-39) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/ellipticK.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticK.m +***** error ellipticK (sym(1), 2) +***** assert (isequal (ellipticK (sym (0)), sym (pi)/2)) +***** assert (isequal (ellipticK (sym (-inf)), sym (0))) +***** assert (double (ellipticK (sym (1)/2)), 1.854074677, 10e-10) +***** assert (double (ellipticK (sym (pi)/4)), 2.225253684, 10e-10) +***** assert (double (ellipticK (sym (-55)/10)), 0.9324665884, 10e-11) ***** test - a = sym([1 2 3]); - assert (columns(a) == 3) + % compare to double ellipke + m = 1/5; + ms = sym(1)/5; + [K, E] = ellipke (m); + assert (double (ellipticK (ms)), K, -1e-15) + assert (double (ellipticE (ms)), E, -1e-15) ***** test - a = sym([1; 2]); - assert (columns(a) == 1) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/ellipticCE.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticCE.m -***** error ellipticCE (sym (1), 2) -***** assert (isequal (ellipticCE (sym (0)), sym (1))) -***** assert (isequal (ellipticCE (sym (1)), sym (pi)/2)) -***** assert (double (ellipticCE (sym (pi)/4)), 1.482786927, 10e-10) -***** assert (double (ellipticCE (sym (pi)/2)), 1.775344699, 10e-10) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ellipticF.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ellipticF.m -***** error ellipticF (sym(1)) -***** error ellipticF (sym(1), 2, 3) -***** assert (double (ellipticF (sym (pi)/3, sym (-105)/10)), 0.6184459461, 10e-11) -***** assert (double (ellipticF (sym (pi)/4, sym (-pi))), 0.6485970495, 10e-11) -***** assert (double (ellipticF (sym (1), sym (-1))), 0.8963937895, 10e-11) -***** assert (double (ellipticF (sym (pi)/6, sym (0))), 0.5235987756, 10e-11) + % compare to double ellipke + if (exist ('OCTAVE_VERSION', 'builtin')) + m = -10.3; + ms = -sym(103)/10; + [K, E] = ellipke (m); + assert (double (ellipticK (ms)), K, -1e-15) + assert (double (ellipticE (ms)), E, -1e-15) + end ***** test % compare to Maple - us = vpa (ellipticF (sym(11)/10, sym(9)/4), 40); - % > evalf(EllipticF(sin(11/10), sqrt(9/4)), 40); - maple = vpa ('1.206444996991058996424988192917728014427', 40) - ... - vpa ('0.8157358125823472313001683083685348517476j', 40); + us = vpa (ellipticK (sym (7)), 40); + % > evalf(EllipticK(sqrt(7)), 40); + maple = vpa ('0.6168027921799632674669917683443602673441', 40) - ... + vpa ('0.9114898734184488922164103102629560336918j', 40); assert (abs (double (maple - us)), 0, 1e-39) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/asind.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/asind.m -***** error asind (sym(1), 2) -***** assert (isequaln (asind (sym(nan)), sym(nan))) -***** test - f1 = asind (sym(1)/2); - f2 = asind (1/2); - assert (double (f1), f2, -eps) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/xor.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/xor.m +***** shared t, f + t = sym(true); + f = sym(false); ***** test - D = [1 2; 3 4]/4; - A = sym([1 2; 3 4])/4; - f1 = asind (A); - f2 = asind (D); - assert (double (f1), f2, -eps) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/bernoulli.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/bernoulli.m -***** error bernoulli (sym(1), 2, 3) -***** assert (isequal (bernoulli (sym(8)), -sym(1)/30)) -***** assert (isequal (bernoulli (sym(9)), sym(0))) -***** test syms x - assert (isequal (bernoulli(3,x), x^3 - 3*x^2/2 + x/2)) + % simple + assert (isequal (xor(t, f), t)) + assert (isequal (xor(t, t), f)) ***** test - m = sym([0 1; 8 888889]); - A = bernoulli (m); - B = [1 -sym(1)/2; -sym(1)/30 0]; - assert (isequal (A, B)) + % array + w = [t t f f]; + z = [t f t f]; + assert (isequal (xor(w, z), [f t t f])) +***** xtest + % output is sym even for scalar t/f + % ₣IXME: should match other bool fcns + assert (isa (xor(t, f), 'sym')) ***** test + % eqns syms x - A = bernoulli ([0; 1], x); - B = [sym(1); x - sym(1)/2]; - assert (isequal (A, B)) -***** test - % round trip - syms n x - f = bernoulli (n, x); - h = function_handle (f, 'vars', [n x]); - A = h (2, 2.2); - B = bernoulli (2, 2.2); - assert (A, B) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/rewrite.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/rewrite.m + e = xor(x == 4, x == 5); + assert (isequal (subs(e, x, [3 4 5 6]), [f t t f])) ***** test + % eqns, exclusive syms x - assert (isequal (rewrite(x, 'exp'), x)) -***** test - % empty - e = sym([]); - assert (isequal (rewrite(e, 'sin'), e)) -***** test + e = xor(x == 3, x^2 == 9); + assert (isequal (subs(e, x, [-3 0 3]), [t f f])) +***** error xor (sym('x'), 1, 2) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/limit.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/limit.m +***** error limit (sym(1), 2, 3, 4, 5) +***** shared x, oo syms x - A = [exp(x) exp(2*x)]; - B = [sinh(x) + cosh(x) sinh(2*x) + cosh(2*x)]; - assert (isequal (rewrite(A, 'sin'), B)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/end.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/end.m + oo = sym(inf); +***** assert (isa (limit(x, x, pi), 'sym')) +***** assert (isequal (limit(x, x, pi), sym(pi))) +***** assert (isequal (limit(sin(x)/x, x, 0), 1)) ***** test - % scalar - syms x - y = x(1:end); - assert (isequal (x, y)) + % left/right-hand limit + assert (isequal (limit(1/x, x, 0, 'right'), oo)) + assert (isequal (limit(1/x, x, 0), oo)) + assert (isequal (limit(1/x, x, 0, 'left'), -oo)) + assert (isequal (limit(1/x, x, oo), 0)) + assert (isequal (limit(sign(x), x, 0, 'left'), -1)) + assert (isequal (limit(sign(x), x, 0, 'right'), 1)) + assert (isequal (limit(sign(x), x, 0, '-'), -1)) + assert (isequal (limit(sign(x), x, 0, '+'), 1)) ***** test - % vector - syms x - A = [1 2 x 4]; - y = A(end-1:end); - assert (isequal (y, [x 4])) + % matrix + syms y + A = [x 1/x x*y]; + B = sym([3 sym(1)/3 3*y]); + assert (isequal (limit(A, x, 3), B)) ***** test - % subset of matrix - syms x - A = [1 2 x; x 3 9; 4 x*x 6]; - y = A(end,1:end-1); - assert (isequal (y, [4 x*x])) + % omitting arguments + syms a + assert (isequal (limit(a), 0)) + assert (isequal (limit(a*x+a+2), a+2)) + assert (isequal (limit(a*x+a+2, 6), 7*a+2)) ***** test - % linear index of matrix - syms x - A = [1 2 x; x 3 9]; - y = A(end); - assert (isequal (y, sym(9))) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/private_disp_name.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/private_disp_name.m + % constants + assert (isequal (limit(sym(6)), 6)) + assert (isequal (limit(sym(6), 7), 6)) + assert (isequal (limit([sym(6) sym(2)], 7), [6 2])) ***** test - syms x - s = private_disp_name(x, 'x'); - assert (strcmp (s, 'x')) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/besselyn.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/besselyn.m + % double constant, with sym limit + a = limit (6, sym(0)); + assert (isa (a, 'sym')) + assert (isequal (a, sym(6))) +9 tests, 9 passed, 0 known failure, 0 skipped +[inst/@sym/sinhint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinhint.m +***** error sinhint (sym(1), 2) +***** xtest + assert (isequaln (sinhint (sym(nan)), sym(nan))) +!!!!! known failure +assert (isequaln (sinhint (sym (nan)), sym (nan))) failed +***** shared x, d + d = 1; + x = sym('1'); ***** test - % roundtrip - syms x - A = double(besselyn(sym(2), sym(10))); - q = besselyn(sym(2), x); - h = function_handle(q); - B = h(10); - assert (abs (A - B) <= eps) -***** error yn(sym('x')) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/angle.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/angle.m + f1 = sinhint(x); + f2 = 1.057250875375728514572; + assert( abs(double(f1) - f2) < 1e-15 ) ***** test - Z = [sqrt(sym(3)) + 3*sym(i), 3 + sqrt(sym(3))*sym(i); 1 + sym(i), sym(i)]; - Q = [sym(pi)/3 sym(pi)/6; sym(pi)/4 sym(pi)/2]; - assert( isequal( angle(Z), Q)); + D = [d d; d d]; + A = [x x; x x]; + f1 = sinhint(A); + f2 = 1.057250875375728514572; + f2 = [f2 f2; f2 f2]; + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - % roundtrip - syms x - A = angle (2+2i); - f = angle (x); + % round trip + y = sym('y'); + A = sinhint (d); + f = sinhint (y); h = function_handle (f); - B = h (2+2i); + B = h (d); assert (A, B, -eps) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/isAlways.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isAlways.m +5 tests, 4 passed, 1 known failure, 0 skipped +[inst/@sym/null.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/null.m ***** test - % basics - assert(isAlways(true)) - assert(isAlways(1==1)) - assert(isAlways(sym(1)==sym(1))) - assert(isAlways(sym(1)==1)) + A = sym([1 2; 3 4]); + assert (isempty (null (A))) +***** assert (isempty (null (sym(4)))) ***** test - % numbers to logic? - assert (isAlways(sym(1))) - assert (isAlways(sym(-1))) - assert (~isAlways(sym(0))) -***** shared x - syms x + A = sym([1 2 3; 3 4 5]); + assert (isequal (null(A), sym([1;-2;1]))) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@sym/union.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/union.m ***** test - % in this case it is boolean - expr = x - x == 0; - assert (logical(expr)) - assert (isAlways(expr)) - % and both are logical type - assert (islogical(logical(expr))) - assert (islogical(isAlways(expr))) + A = sym([1 2 3]); + B = sym([1 2 4]); + C = union(A, B); + D = sym([1 2 3 4]); + assert (isequal (C, D)) ***** test - % structurally same and mathematically true - % (here expr should be sym, non-boolean) - expr = x == x; - assert (logical(expr)) - assert (isAlways(expr)) - %assert (~islogical(expr)) % FIXME: Issue #56 - %assert (isa(expr, 'sym)) + % one nonsym + A = sym([1 2 3]); + B = [1 2 4]; + C = union(A, B); + D = sym([1 2 3 4]); + assert (isequal (C, D)) ***** test - % structurally same and mathematically true - % (here expr should be sym, non-boolean) - expr = 1 + x == x + 1; - assert (logical(expr)) - assert (isAlways(expr)) + % empty + A = sym([1 2 3]); + C = union(A, A); + assert (isequal(C, A)) ***** test - % non-zero numbers are true - assert (isAlways(sym(1))) - assert (isAlways(sym(-10))) - assert (~isAlways(sym(0))) -***** shared x, y - syms x y + % empty input + A = sym([1 2]); + C = union(A, []); + assert (isequal (C, sym([1 2]))) ***** test - % structurally same and mathematically true - % (here expr should be sym, non-boolean) - expr = x*(1+y) == x*(y+1); - assert (logical(expr)) - assert (isAlways(expr)) - assert (islogical(isAlways(expr))) + % scalar + syms x + assert (isequal (union([x 1], x), [1 x])) + assert (isequal (union(x, x), x)) ***** test - % Now for some differences - % simplest example from SymPy FAQ - expr = x*(1+y) == x+x*y; - assert (~logical(expr)) - assert (isAlways(expr)) + A = interval(sym(1), 3); + B = interval(sym(2), 5); + C = union(A, B); + assert( isequal( C, interval(sym(1), 5))) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/arg.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/arg.m ***** test - % more differences 1, these don't simplify in sympy (as of 2016-01) - expr = (x+1)^2 == x*x + 2*x + 1; - assert (~logical(expr)) - assert (isAlways(expr)) + syms x + assert (isequal (angle (x), arg (x))); +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@sym/isfinite.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isfinite.m +***** assert (isfinite(sym(1))) +***** assert (isfinite(sym(-10))) +***** assert (~isfinite(sym('oo'))) +***** assert (~isfinite(sym('-oo'))) +***** assert (~isfinite(sym(1)/0)) +***** assert (~isfinite(sym(nan))) +***** assert (isequal (isfinite (sym ([1 inf])), [true false])) ***** test - % more differences 2 - expr = sin(2*x) == 2*sin(x)*cos(x); - assert (~logical(expr)) - assert (isAlways(expr)) + % finite-by-assumption + syms x finite + assert (isfinite (x)) +8 tests, 8 passed, 0 known failure, 0 skipped +[inst/@sym/sind.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sind.m +***** error sind (sym(1), 2) +***** assert (isequaln (sind (sym(nan)), sym(nan))) ***** test - % more differences 3, false - expr = x*(x+y) == x^2 + x*y + 1; - assert (~logical(expr)) - assert (~isAlways(expr)) - assert (~isAlways(expr, 'unknown', 'error')) + f1 = sind (sym(1)); + f2 = sind (1); + assert (double (f1), f2, -eps) ***** test - % logically not equal, math equal - exprn = x*(x+y) ~= x^2 + x*y; - assert (logical(exprn)) - assert (~isAlways(exprn)) + D = [10 30; 110 -45]; + A = sym(D); + f1 = sind (A); + f2 = sind (D); + assert (double (f1), f2, -eps) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/intersect.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/intersect.m ***** test - % logically not equal, math not equal - exprn = x*(x+y) ~= x^2 + x*y + 1; - assert (logical(exprn)) - assert (isAlways(exprn)) + A = sym([1 2 3]); + B = sym([1 2 4]); + C = intersect(A, B); + D = sym([1 2]); + assert (isequal (C, D)) ***** test - % equal and not equal - e1 = sin(x)^2 + cos(x)^2 == 1; - e2 = sin(x)^2 + cos(x)^2 == 2; - assert (~logical(e1)) - assert (isAlways(e1)) - assert (~logical(e2)) - assert (~isAlways(e2)) - assert (~isAlways(e2, 'unknown', 'error')) -***** error isAlways(x, 'unknown', 'kevin') -***** error isAlways(x, 'unknown') -***** error isAlways(x, 'kevin', 'true') -***** error - a = [x*(x+y)==x^2+x*y x==y]; - b = isAlways(a, 'unknown', 'error'); -***** error - a = x==y; - b = isAlways(a, 'unknown', 'error'); + % one nonsym + A = sym([1 2 3]); + B = [1 2 4]; + C = intersect(A, B); + D = sym([1 2]); + assert (isequal (C, D)) ***** test - % array, unknown keyword - a = [x==x x==x+1 x==y x*(x+y)==x^2+x*y cos(x)^2+sin(x)^2==2]; - b = isAlways(a, 'unknown', false); - c = isAlways(a, 'unknown', 'false'); - expect = [true false false true false]; - assert (islogical(b)) - assert (isequal (b, expect)) - assert (isequal (c, expect)) - b = isAlways(a, 'unknown', true); - c = isAlways(a, 'unknown', 'true'); - expect = [true false true true false]; - assert (islogical(b)) - assert (isequal (b, expect)) - assert (isequal (c, expect)) + % empty + A = sym([1 2 3]); + C = intersect(A, A); + assert (isequal (C, A)) ***** test - % ineq - e = x*(x+y) <= x^2 + x*y + 1; - assert (~logical(e)) - assert (isAlways(e)) - e = x*(x+y) <= x^2 + x*y; - assert (~logical(e)) - assert (isAlways(e)) -21 tests, 21 passed, 0 known failure, 0 skipped -[inst/@sym/times.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/times.m + % empty input + A = sym([1 2]); + C = intersect(A, []); + assert (isequal (C, sym([]))) ***** test % scalar syms x - assert (isa (x.*2, 'sym')) - assert (isequal (x.*2, x*2)) - assert (isequal (2.*sym(3), sym(6))) - assert (isequal (sym(2).*3, sym(6))) + assert (isequal (intersect([x 1], x), x)) + assert (isequal (intersect(x, x), x)) ***** test - % matrix-matrix and matrix-scalar - D = [0 1; 2 3]; - A = sym(D); - assert (isequal ( 2.*A , 2*D )) - assert (isequal ( A.*2 , 2*D )) - assert (isequal ( A.*A , D.*D )) - assert (isequal ( A.*D , D.*D )) - assert (isequal ( D.*A , D.*D )) + A = interval(sym(1), 3); + B = interval(sym(2), 5); + C = intersect(A, B); + assert( isequal( C, interval(sym(2), 3))) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/iscolumn.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/iscolumn.m +***** assert (iscolumn (sym ([1]))) +***** assert (iscolumn (sym ([1 2 3]'))) +***** assert (~iscolumn (sym ([]))) +***** assert (~iscolumn (sym ([1 2 3]))) +***** assert (~iscolumn (sym ([1 2; 3 4]))) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/ztrans.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/ztrans.m ***** test - syms x - A = [1 x]; - B = [2 3]; - assert (isequal (A.*B, [2 3*x])) + % basic Z-transform table checks + % X1, ..., X4 must have inner radius of convergence 1 + syms n z + % trick to extract the closed form formula using the fact that inner roc = 1 + closed_form = @(X) subs (X, abs (1 / z), 1 / sym (2)); + % check if ztrans(f) == X + check_ztrans = @(f, X) logical (simplify (closed_form (ztrans (f)) == X)); + f1 = sym (1); + X1 = 1 / (1 - 1 / z); + assert (check_ztrans (f1, X1)); + f2 = n; + X2 = (1 / z) / (1 - 1 / z)^2; + assert (check_ztrans (f2, X2)); + f3 = n^2; + X3 = (1 / z) * (1 + 1 / z) / (1 - 1 / z)^3; + assert (check_ztrans (f3, X3)); + f4 = n^3; + X4 = (1 / z) * (1 + 4 / z + 1 / z^2) / (1 - 1 / z)^4; + assert (check_ztrans (f4, X4)); + % basic matrix checks + A1 = ztrans ([f1 f2; f3 f4]); + B1 = [ztrans(f1) ztrans(f2); ztrans(f3) ztrans(f4)]; + assert (isequal (A1, B1)); + A2 = ztrans ([f1 f2; f3 f4], z); + B2 = [ztrans(f1, z) ztrans(f2, z); ztrans(f3, z) ztrans(f4, z)]; + assert (isequal (A2, B2)); + A3 = ztrans ([f1 f2; f3 f4], n, z); + B3 = [ztrans(f1, n, z) ztrans(f2, n, z); ztrans(f3, n, z) ztrans(f4, n, z)]; + assert (isequal (A3, B3)); ***** test - % immutable test - A = sym([1 2]); - B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)]])'); - assert (isequal (A.*A, B.*B)) + % additional Z-transform table checks + % X1, ..., X4 must have inner radius of convergence a + syms n nonnegative integer + syms m positive integer + syms a + syms z + % trick to extract the closed form formula using the fact that inner roc = a + closed_form = @(X) subs (X, abs (a / z), 1 / sym (2)); + % check if ztrans(f) == X + check_ztrans = @(f, X) logical (simplify (closed_form (ztrans (f)) == X)); + f1 = a^n; + X1 = 1 / (1 - a / z); + assert (check_ztrans (f1, X1)); + f2 = n * a^n; + X2 = (a / z) / (1 - a / z)^2; + assert (check_ztrans (f2, X2)); + f3 = n^2 * a^n; + X3 = (a / z) * (1 + a / z) / (1 - a / z)^3; + assert (check_ztrans (f3, X3)); + f4 = nchoosek(n + m - 1, m - 1) * a^n; + X4 = 1 / (1 - a / z)^m; + assert (check_ztrans (f4, X4)); + % additional matrix checks + A1 = ztrans (f1, [n m; m n], [z a; a z]); + B1 = [ztrans(f1, n, z) ztrans(f1, m, a); ztrans(f1, m, a) ztrans(f1, n, z)]; + assert (isequal (A1, B1)); + A2 = ztrans (f1, m, [z a; a z]); + B2 = [ztrans(f1, m, z) ztrans(f1, m, a); ztrans(f1, m, a) ztrans(f1, m, z)]; + assert (isequal (A2, B2)); + A3 = ztrans (f1, [n m; m n], a); + B3 = [ztrans(f1, n, a) ztrans(f1, m, a); ztrans(f1, m, a) ztrans(f1, n, a)]; + assert (isequal (A3, B3)); ***** test - % MatrixSymbol test - A = sym([1 2; 3 4]); - B = sym('ImmutableDenseMatrix([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])'); - C = sym('MatrixSymbol("C", 2, 2)'); - assert (~ isempty (strfind (sympy (C.*C), 'Hadamard'))) - assert (~ isempty (strfind (sympy (A.*C), 'Hadamard'))) - assert (~ isempty (strfind (sympy (C.*A), 'Hadamard'))) - assert (~ isempty (strfind (sympy (B.*C), 'Hadamard'))) - assert (~ isempty (strfind (sympy (C.*B), 'Hadamard'))) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ldivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ldivide.m + % Kronecker delta checks + syms n n0 nonnegative integer + syms z + assert (isequal (ztrans (kroneckerDelta (n)), 1)); + assert (isequal (ztrans (kroneckerDelta (n - n0)), 1 / z^n0)); ***** test - % scalar - syms x - assert (isa (x .\ 1, 'sym')) - assert (isa (x .\ x, 'sym')) - assert (isequal (x .\ 1, 1/x)) - assert (isequal (x .\ x, sym(1))) + % basic var selection checks + syms n m z w + assert (isequal (ztrans (1 / factorial (n)), exp (1 / z))); + assert (isequal (ztrans (1 / factorial (z)), exp (1 / w))); + assert (isequal (ztrans (1 / factorial (m), w), exp (1 / w))); + assert (isequal (ztrans (1 / factorial (m), m, w), exp (1 / w))); ***** test - % matrix-scalar - D = [1 1; 2 3]; - A = sym(D); - assert (isequal ( A .\ 6 , D .\ 6 )) - assert (isequal ( A .\ sym(6) , D .\ 6 )) - assert (isequal ( D .\ sym(6) , D .\ 6 )) + % additional var selection checks + syms n m z + f = kroneckerDelta(m) / factorial (n); + assert (isequal (ztrans (f, z), exp (1 / z) * kroneckerDelta (m))); + assert (isequal (ztrans (f, n, z), exp (1 / z) * kroneckerDelta (m))); + assert (isequal (ztrans (f, m, z), 1 / factorial (n))); ***** test - % matrix-matrix - D = [1 2; 3 4]; - A = sym(D); - assert (isequal ( A .\ A , D .\ D )) - assert (isequal ( A .\ D , D .\ D )) - assert (isequal ( D .\ A , D .\ D )) + % if no t, use symvar: take x before a + syms a x z + assert (isequal (ztrans (a / factorial (x)), a * exp (1 / z))); +***** error ztrans (sym ('n')^sym ('n', 'nonnegative', 'integer')) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@sym/prevprime.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/prevprime.m +***** assert (isequal (prevprime(sym(3)), 2)); +***** assert (isequal (prevprime(sym(20)), 19)); +***** assert (isequal (prevprime(sym([3 5 10])), [2 3 7])); +***** error prevprime(sym(2)) +***** error prevprime(sym(-2)) ***** test - % matrix .\ matrix with symbols + % result is a sym + p = prevprime(sym(3)); + assert (isa (p, 'sym')) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@sym/isequaln.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/isequaln.m +***** test + a = sym([1 2]); + b = a; + assert (isequaln (a, b)) + b(1) = 42; + assert (~isequaln (a, b)) +***** test + a = sym([1 2; 3 4]); + b = a; + assert (isequaln (a, b)) + b(1) = 42; + assert (~isequaln (a, b)) +***** test + a = sym([nan; 2]); + b = a; + assert (isequaln (a, b)) +***** test + a = sym([nan 2; 3 4]); + b = a; + assert (isequaln (a, b)) +***** test + % more than two arrays + a = sym([nan 2 3]); + b = a; + c = a; + assert (isequaln (a, b, c)) + c(1) = 42; + assert (~isequaln (a, b, c)) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/degree.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/degree.m +***** error degree (sym(1), 2, 3) +***** test + syms x + assert (isequal (degree(x^3), 3)) + assert (isequal (degree(x^3 + 6), 3)) +***** test + % specify variable syms x y - A = [x y; x^2 2*y]; - B = [y x; x y]; - assert (isequal ( A .\ A , sym(ones(2, 2)) )) - assert (isequal ( B .\ A , [x/y y/x; x 2] )) + p = x^2 + y*x + 1; + assert (isequal (degree(p), 2)) + assert (isequal (degree(p, x), 2)) + assert (isequal (degree(p, y), 1)) ***** test - % scalar .\ matrix - D = 3*[1 2; 3 4]; - A = sym(D); - assert (isequal ( 3 .\ A , 3 .\ D )) + syms x a oo + assert (isequal (degree(x^3, a), 0)) + assert (isequal (degree(sym(1), a), 0)) + assert (isequal (degree(sym(0), a), -oo)) +***** xtest + % constant inputs + syms oo + assert (isequal (degree(sym(1)), 0)) + assert (isequal (degree(sym(0)), -oo)) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/isnan.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/isnan.m -***** shared x,zoo,oo,snan - oo = sym(inf); - zoo = sym('zoo'); - x = sym('x'); - snan = sym(nan); +[inst/@sym/orth.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/orth.m ***** test - % various ops that give nan - assert (isnan(0*oo)) - assert (isnan(0*zoo)) - assert (isnan(snan)) - assert (isnan(snan-snan)) - assert (isnan(oo+snan)) - assert (isnan(oo-oo)) - assert (isnan(oo-zoo)) - assert (isnan(oo+zoo)) - assert (~isnan(oo)) - assert (~isnan(zoo)) - assert (~isnan(oo+oo)) + A = [1 2; 3 6]; + K = orth(A); + L = orth(sym(A)); + assert (isequal (size(L), [2 1])) + dif1 = abs (double(L) - K); + dif2 = abs (double(L) + K); + assert (all (dif1 < 1e-15) || all (dif2 < 1e-15)) ***** test - % more ops give nan - assert(isnan(x+snan)) - assert(isnan(x*snan)) - assert(isnan(0*snan)) - assert(isnan(x+nan)) - assert(isnan(x*nan)) - assert(isnan(sym(0)*nan)) + A = [1; 3]; + K = orth(A); + L = orth(sym(A)); + assert (isequal (size(L), [2 1])) + dif1 = abs (double(L) - K); + dif2 = abs (double(L) + K); + assert (all (dif1 < 1e-16) || all (dif2 < 1e-16)) ***** test - % array - assert (isequal( isnan([oo zoo]), [0 0] )) - assert (isequal( isnan([10 snan]), [0 1] )) - assert (isequal( isnan([snan snan]), [1 1] )) - assert (isequal( isnan([snan x]), [1 0] )) + A = sym([1 2; 3 4]); + L = orth(sym(A)); + assert (isequal (size(L), [2 2])) + v = L(:, 1); + w = L(:, 2); + assert (isAlways (v' * v == 1)) + assert (isAlways (w' * w == 1)) + assert (isAlways (v' * w == 0)) ***** test - % sub in to algebraic expression gives nan - y = x - oo; - y = subs(y, x, oo); - assert(isnan(y)) + A = sym([1 1; 1 0; 1 0]); + L = orth(sym(A)); + assert (isequal (size(L), [3 2])) + v = L(:, 1); + w = L(:, 2); + assert (isAlways (v' * v == 1)) + assert (isAlways (w' * w == 1)) + assert (isAlways (v' * w == 0)) + % y and z components must be equal + assert (isAlways (v(2) == v(3))) + assert (isAlways (w(2) == w(3))) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/int.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/int.m +***** shared x,y,a + syms x y a +***** assert(logical(int(cos(x)) - sin(x) == 0)) +***** assert(logical(int(cos(x),x) - sin(x) == 0)) +***** assert(logical(int(cos(x),x,0,1) - sin(sym(1)) == 0)) ***** test - % Must not contain string 'symbol'; these all should make an - % actual nan. Actually a ctor test, not isnan. - y = sym(nan); - assert (isempty (strfind (sympy (y), 'Symbol'))) - y = sym('nan'); - assert (isempty (strfind (sympy (y), 'Symbol'))) - y = sym('NaN'); - assert (isempty( strfind (sympy (y), 'Symbol'))) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/flipud.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/flipud.m + %% limits might be syms + assert( isequal (int(cos(x),x,sym(0),sym(1)), sin(sym(1)))) + assert( isequal (int(cos(x),x,0,a), sin(a))) ***** test - % simple - syms x - A = [x 2; sym(pi) x]; - B = [sym(pi) x; x 2]; - assert (isequal (flipud(A), B)) + %% other variables present + assert( isequal (int(y*cos(x),x), y*sin(x))) ***** test - % simple, odd # rows - syms x - A = [x 2; sym(pi) x; [1 2]]; - B = [[1 2]; sym(pi) x; x 2]; - assert (isequal (flipud(A), B)) + %% limits as array + assert( isequal (int(cos(x),x,[0 1]), sin(sym(1)))) + assert( isequal (int(cos(x),x,sym([0 1])), sin(sym(1)))) + assert( isequal (int(cos(x),x,[0 a]), sin(a))) ***** test - % scalar - syms x - assert (isequal (flipud(x), x)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/asec.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/asec.m -***** error asec (sym(1), 2) -***** assert (isequaln (asec (sym(nan)), sym(nan))) + %% no x given + assert( isequal (int(cos(x),[0 1]), sin(sym(1)))) + assert( isequal (int(cos(x),sym([0 1])), sin(sym(1)))) + assert( isequal (int(cos(x),[0 a]), sin(a))) + assert( isequal (int(cos(x),0,a), sin(a))) +***** test + %% integration of const + assert( isequal (int(sym(2),y), 2*y)) + assert( isequal (int(sym(2)), 2*x)) + assert( isequal (int(sym(2),[0 a]), 2*a)) + assert( isequal (int(sym(2),0,a), 2*a)) +***** test + % componentwise int of array + A = [x x*x]; + assert (isequal (int(A, x), [x^2/2 x^3/3])) +***** test + % NonElementaryIntegral bug + % https://savannah.gnu.org/bugs/index.php?46831 + f = int(exp(exp(x))); + f = f + 2; + g = diff(f); + assert (isequal (g, exp(exp(x)))) +10 tests, 10 passed, 0 known failure, 0 skipped +[inst/@sym/sec.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/sec.m +***** error sec (sym(1), 2) +***** assert (isequaln (sec (sym(nan)), sym(nan))) ***** shared x, d - d = 2; - x = sym('2'); + d = 1; + x = sym('1'); ***** test - f1 = asec(x); - f2 = asec(d); + f1 = sec(x); + f2 = sec(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; A = [x x; x x]; - f1 = asec(A); - f2 = asec(D); + f1 = sec(A); + f2 = sec(D); assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test % round trip y = sym('y'); - A = asec (d); - f = asec (y); + A = sec (d); + f = sec (y); h = function_handle (f); B = h (d); assert (A, B, -eps) 5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/cat.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cat.m +[inst/@sym/rows.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/rows.m ***** test - % mostly tested in horzcat, vertcat: one for good measure + a = sym([1 2 3]); + assert (rows(a) == 1) +***** test + a = sym([1 2 3; 4 5 6]); + assert (rows(a) == 2) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/logical.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/logical.m +***** test + % basics, many others in isAlways.m + assert (logical(true)) + assert (~(logical(false))) +***** test + % numbers to logic? + assert (logical(sym(1))) + assert (logical(sym(-1))) + assert (~logical(sym(0))) +***** test + % eqns, "structurally equivalent" syms x - assert (isequal (cat(1, x, x), [x x])) - assert (isequal (cat(2, x, x), [x; x])) -***** error cat(3, sym(2), sym(3)) -***** error cat(0, sym(2), sym(3)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/cross.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cross.m -***** error cross (sym(1), 2, 3) + e = logical(x == x); + assert ( islogical (e)) + assert (e) + e = logical(x == 1); + assert ( islogical (e)) + assert (~e) ***** test - a = sym([1; 0; 0]); - b = sym([0; 1; 0]); - c = cross(a, b); - assert (isequal (c, sym([0; 0; 1]))) + % eqn could have solutions but are false in general + syms x + e = logical(x^2 == x); + assert ( islogical (e)) + assert (~e) + e = logical(2*x == x); + assert ( islogical (e)) + assert (~e) +***** test + % FIXME: (not sure yet) T/F matrices should stay sym until logical() + a = sym(1); + e = a == a; + assert (isa (e, 'sym')) + assert (islogical (logical (e))) + e = [a == a a == 0 a == a]; + assert (isa (e, 'sym')) + assert (islogical (logical (e))) ***** test + % sym vectors of T/F to logical + a = sym(1); + e = [a == a a == 0 a == a]; + w = logical(e); + assert (islogical (w)) + assert (isequal (w, [true false true])) + e = e'; + w = logical(e); + assert (islogical (w)) + assert (isequal (w, [true; false; true])) +***** test + % sym matrix of T/F to logical + a = sym([1 2 3; 4 5 6]); + b = sym([1 2 0; 4 0 6]); + e = a == b; + w = logical(e); + assert (islogical (w)) + assert (isequal (w, [true true false; true false true])) +***** error syms x - a = sym([x; 0; 0]); - b = sym([0; 1; 0]); - c = cross(a, b); - assert (isequal (c, sym([0; 0; x]))) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/sinint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sinint.m -***** error sinint (sym(1), 2) -***** xtest - assert (isequaln (sinint (sym(nan)), sym(nan))) -!!!!! known failure -assert (isequaln (sinint (sym (nan)), sym (nan))) failed + logical(x); +***** error + logical(sym(nan)) +***** test + % but oo and zoo are non-zero so we call those true + % (SMT errors on these) FIXME + syms oo zoo + assert (logical (oo)) + % assert (logical (zoo)) +***** test + % older Octave (< 4.2) didn't automatically do "if (logical(obj))" + e = sym(true); + if (e) + assert(true); + else + assert(false); + end +***** test + % more of above + e2 = sym(1) == sym(1); + if (e2) + assert(true); + else + assert(false); + end + e3 = sym([1 2]) == sym([1 1]); + if (e3(1)) + assert(true); + else + assert(false); + end +12 tests, 12 passed, 0 known failure, 0 skipped +[inst/@sym/fortran.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/fortran.m +***** shared x,y,z + syms x y z +***** test + % basic test + f = x*sin(y) + abs(z); + source = fortran(f); + expected = ' x*sin(y) + abs(z)'; + s1 = strrep (expected, 'abs', 'Abs'); + assert (strcmp (source, expected) || strcmp (source, s1)) +***** test + % output test + f = x*sin(y) + abs(z); + [F,H] = fortran(f, 'file', '', 'show_header', false); + expected_h_code = sprintf('\ninterface\nREAL*8 function myfun(x, y, z)\nimplicit none\nREAL*8, intent(in) :: x\nREAL*8, intent(in) :: y\nREAL*8, intent(in) :: z\nend function\nend interface\n\n'); + expected_f_code = sprintf('\nREAL*8 function myfun(x, y, z)\nimplicit none\nREAL*8, intent(in) :: x\nREAL*8, intent(in) :: y\nREAL*8, intent(in) :: z\n\nmyfun = x*sin(y) + abs(z)\n\nend function\n'); + assert(strcmp(F.name, 'file.f90')) + assert(strcmp(H.name, 'file.h')) + %disp(expected_f_code); disp(F.code) + s1 = strrep (expected_f_code, 'abs', 'Abs'); + s2 = strrep (expected_f_code, sprintf ('\n'), sprintf ('\r\n')); + s3 = strrep (s2, 'abs', 'Abs'); + s4 = strrep (expected_h_code, sprintf ('\n'), sprintf ('\r\n')); + assert (strcmp (F.code, expected_f_code) || strcmp (F.code, s1) || strcmp (F.code, s2) || strcmp (F.code, s3)) + assert (strcmp (H.code, expected_h_code) || strcmp (H.code, s4)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/rhs.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/rhs.m +***** test + syms x + f = x + 1 == 2*x; + assert (isequal (rhs(f), 2*x)) +***** error + syms x + rhs(x) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@sym/exp.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/exp.m +***** error exp (sym(1), 2) +***** assert (isequaln (exp (sym(nan)), sym(nan))) ***** shared x, d d = 1; x = sym('1'); ***** test - f1 = sinint(x); - f2 = 0.9460830703671830149414; + f1 = exp(x); + f2 = exp(d); assert( abs(double(f1) - f2) < 1e-15 ) ***** test D = [d d; d d]; - A = [x x; x x]; - f1 = sinint(A); - f2 = 0.9460830703671830149414; - f2 = [f2 f2; f2 f2]; - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) -***** test - % round trip - y = sym('y'); - A = sinint (d); - f = sinint (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 4 passed, 1 known failure, 0 skipped -[inst/@sym/sym2poly.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/sym2poly.m -***** shared x,y,a,b,c - syms x y a b c -***** assert (isequal (sym2poly (x^2 + 3*x - 4), [1 3 -4])) -***** assert (isequal (sym2poly (x^6 - x^3), [1 0 0 -1 0 0 0])) -***** assert (isequal (sym2poly (x^2 + 3*x - 4, x), [1 3 -4])) -***** assert (norm (sym2poly (pi*x^2 + exp(sym(1))) - [pi 0 exp(1)]) < 10*eps) -***** assert (isa (sym2poly (x^2 + 3*x - 4), 'double')) -***** assert (isa (sym2poly (x^2 + 3*x - 4, x), 'sym')) -***** assert (isequal (sym2poly (x^2+y*x, x), [sym(1) y sym(0)])) -***** assert (isequal (sym2poly (x^2+y*x, y), [x x^2])) -***** assert (isequal (sym2poly (poly2sym ([a b c], x), x), [a b c])) -***** assert (isequal (poly2sym (sym2poly(a*x^2 + c, x), x), a*x^2 + c)) -***** assert (isequal (sym2poly (poly2sym ([1 2 3])), [1 2 3])) -***** error - % too many symbols for single-input - p = a*x^2 + 2; - c = sym2poly (p); -***** assert (isequal (sym2poly (sym(5)), sym(5))) -13 tests, 13 passed, 0 known failure, 0 skipped -[inst/@sym/ones.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ones.m -***** test - y = ones(sym(2)); - x = [1 1; 1 1]; - assert( isequal( y, sym(x))) + A = [x x; x x]; + f1 = exp(A); + f2 = exp(D); + assert( all(all( abs(double(f1) - f2) < 1e-15 ))) ***** test - y = ones(sym(2), 1); - x = [1; 1]; - assert( isequal( y, sym(x))) + % round trip + y = sym('y'); + A = exp (d); + f = exp (y); + h = function_handle (f); + B = h (d); + assert (A, B, -eps) +5 tests, 5 passed, 0 known failure, 0 skipped +[inst/@sym/repmat.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/repmat.m ***** test - y = ones(sym(1), 2); - x = [1 1]; - assert( isequal( y, sym(x))) + % simple + syms x + A = [x x x; x x x]; + assert (isequal (repmat(x, 2, 3), A)) ***** test - y = ones (sym([2 3])); - x = sym (ones ([2 3])); - assert (isequal (y, x)) -***** assert( isa( ones(sym(2), 'double'), 'double')) -***** assert( isa( ones(3, sym(3), 'single') , 'single')) -***** assert( isa( ones(3, sym(3)), 'sym')) -***** assert( isa( ones(3, sym(3), 'sym'), 'sym')) -***** xtest - % Issue #13 - assert( isa( ones(3, 3, 'sym'), 'sym')) -!!!!! known failure -invalid data type specified -9 tests, 8 passed, 1 known failure, 0 skipped -[inst/@sym/ctranspose.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ctranspose.m + % block cf double + A = [1 2 3; 4 5 6]; + B = sym(A); + C = repmat(A, 2, 3); + D = repmat(B, 2, 3); + assert (isequal (C, D)) ***** test - x = sym(1); - assert (isequal (x', x)) -***** assert (isempty (sym([])')) + % empty + A = repmat(sym([]), 2, 3); + assert (isempty(A)); + assert (isequal (size(A), [0 0])) ***** test - % conjugate does nothing to real x - syms x real - assert (isequal (x', x)) + % more empties + A = repmat(sym(pi), [0 0]); + assert (isequal (size(A), [0 0])) + A = repmat(sym(pi), [0 3]); + assert (isequal (size(A), [0 3])) + A = repmat(sym(pi), [2 0]); + assert (isequal (size(A), [2 0])) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/dot.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/dot.m +***** error dot (sym(1), 2, 3) ***** test - % complex - syms x - assert (isequal (x', conj(x))) + a = sym([1; 1; 0]); + b = sym([1; 2; 4]); + c = dot(a, b); + assert (isequal (c, sym(3))) ***** test - % complex array syms x - A = [x 2*x]; - B = [conj(x); 2*conj(x)]; - assert(isequal(A', B)) + a = sym([x; 0; 0]); + b = sym([0; 1; 0]); + c = dot(a, b); + assert (isequal (c, sym(0))) ***** test - A = [1 2; 3 4]; - assert(isequal( sym(A)' , sym(A') )) + assert (isequal (dot (sym([1 i]), sym([i 2])), sym(-i))) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@sym/qr.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@sym/qr.m +***** error qr (sym(1), 2, 3) +***** error [Q, R, P] = qr (sym(1)) +***** error qr (sym(1), 1) ***** test - A = [1 2] + 1i; - assert(isequal( sym(A)' , sym(A') )) + % scalar + [q, r] = qr(sym(6)); + assert (isequal (q, sym(1))) + assert (isequal (r, sym(6))) ***** test - % true/false - t = sym(true); - f = sym(false); - assert (isequal ( t', t)) - assert (isequal ( f', f)) + syms x positive + [q, r] = qr(x); + assert (isequal (q*r, x)) + assert (isequal (q, sym(1))) + assert (isequal (r, x)) ***** test - % more true/false + % trickier if x could be zero, fails on 1.8 <= SymPy <= 1.10.1 syms x - A = [x true 1i]; - B = [conj(x); true; -sym(1i)]; - assert (isequal ( A', B)) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/rref.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/rref.m + [q, r] = qr(x); + if (pycall_sympy__ ('return Version(spver) > Version("1.10.1")')) + assert (isequal (q*r, x)) + end ***** test - A = sym([1 2; 3 4]); - [r, k] = rref(A); - assert (isequal (r, eye(2))) - assert (isequal (k, [1 2])) -***** assert (isequal (rref(sym([2 1])), [1 sym(1)/2])) -***** assert (isequal (rref(sym([1 2; 2 4])), [1 2; 0 0])) -***** assert (isequal (rref(sym([0 0; 2 4])), [1 2; 0 0])) + A = [1 2; 3 4]; + B = sym(A); + [Q, R] = qr(B); + assert (isequal (Q*R, B)) + assert (isequal (R(2,1), sym(0))) + assert (isequal (Q(:,1)'*Q(:,2), sym(0))) + %[QA, RA] = qr(A) + %assert ( max(max(double(Q)-QA)) <= 10*eps) + %assert ( max(max(double(Q)-QA)) <= 10*eps) ***** test - A = sym([1 2 3; 2 3 4]); - [r, k] = rref(A); - assert (isequal (r, [1 0 -1; 0 1 2])) - assert (isequal (k, [1 2])); -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/signIm.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/signIm.m -***** assert (isequal (signIm (sym(1)), sym(0))) -***** assert (isequal (signIm (sym(1) + 2i), sym(1))) -***** assert (isequal (signIm (sym(1) - 2i), sym(-1))) + % non square: tall skinny + A = sym([1 2; 3 4; 5 6]); + [Q, R] = qr (A, 0); + assert (size (Q), [3 2]) + assert (size (R), [2 2]) + assert (isequal (Q*R, A)) ***** test - % intermediate A looks bit weird, but it works - syms z - A = signIm (z); - assert (isequal (subs(A, z, 3+sym(4i)), sym(1))) - assert (isequal (subs(A, z, 3-sym(4i)), sym(-1))) + % non square: short fat + A = sym([1 2 3; 4 5 6]); + [Q, R] = qr (A); + assert (isequal (Q*R, A)) ***** test - % really a @sym/sign test, but that one is autogen - z = 3 + sym(4i); - A = sign (z); - B = z / abs(z); - assert (double (A), double (B), eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/findsym.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/findsym.m -***** assert (strcmp (findsym (sym(2)), '')); -***** shared x,y,f - x=sym('x'); y=sym('y'); f=x^2+3*x*y-y^2; -***** assert (strcmp (findsym (f), 'x,y')); -***** assert (strcmp (findsym (f,1), 'x')); + % non square: short fat, rank deficient + A = sym([1 2 3; 2 4 6]); + [Q, R] = qr (A); + assert (isequal (Q*R, A)) + A = sym([1 2 3; 2 4 6; 0 0 0]); + [Q, R] = qr (A); + assert (isequal (Q*R, A)) ***** test - % test order of returned vars - syms x y a b c xx - % https://www.mathworks.com/matlabcentral/newsreader/view_thread/237730 - alpha = sym('alpha'); - assert (strcmp (findsym(b*xx*exp(alpha) + c*sin(a*y), 2), 'xx,y')) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/subs.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/subs.m -***** error subs (sym(1), 2, 3, 4) -***** shared x,y,t,f - syms x y t - f = x*y; + % rank deficient + A = sym([1 2 3; 2 4 6; 0 0 0]); + [Q, R] = qr (A); + assert (isequal (Q*R, A)) + A = sym([1 2 3; 2 5 6; 0 0 0]); + [Q, R] = qr (A); + assert (isequal (Q*R, A)) ***** test - assert( isequal( subs(f, x, y), y^2 )) - assert( isequal( subs(f, y, sin(x)), x*sin(x) )) - assert( isequal( subs(f, x, 16), 16*y )) + % single return value R not Q + assert (isequal (qr (sym(4)), sym(4))) +12 tests, 12 passed, 0 known failure, 0 skipped +[inst/octsympy_tests.m] +>>>>> /build/octave-symbolic-3.0.1/inst/octsympy_tests.m +***** assert(true) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/finiteset.m] +>>>>> /build/octave-symbolic-3.0.1/inst/finiteset.m ***** test - % multiple subs w/ cells - assert( isequal( subs(f, {x}, {t}), y*t )) - assert( isequal( subs(f, {x y}, {t t}), t*t )) - assert( isequal( subs(f, {x y}, {t 16}), 16*t )) - assert( isequal( subs(f, {x y}, {16 t}), 16*t )) - assert( isequal( subs(f, {x y}, {2 16}), 32 )) + s1 = finiteset(sym(1), 2, 2); + s2 = finiteset(sym(1), 2, 2, 2); + assert (isequal (s1, s2)) ***** test - % multiple subs w/ vectors - assert( isequal( subs(f, [x y], [t t]), t*t )) - assert( isequal( subs(f, [x y], [t 16]), 16*t )) - assert( isequal( subs(f, [x y], [2 16]), 32 )) + s1 = finiteset(sym(0), 1); + s2 = finiteset(sym(0), 2, 3); + s = finiteset(sym(0), 1, 2, 3); + assert (isequal (s1 + s2, s)) ***** test - % anything you can think of - assert( isequal( subs(f, [x y], {t t}), t*t )) - assert( isequal( subs(f, {x y}, [t t]), t*t )) - assert( isequal( subs(f, {x; y}, [t; t]), t*t )) + e = finiteset(); + s = finiteset(sym(1)); + s2 = e + s; + assert (isequal (s, s2)) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/lambertw.m] +>>>>> /build/octave-symbolic-3.0.1/inst/lambertw.m +***** assert (isequal (lambertw (0), 0)) +***** assert (isequal (lambertw (0, 0), 0)) +***** assert (lambertw (-1/exp(1)), -1, 2*eps) +***** assert (lambertw (0, -1/exp(1)), -1, 2*eps) +***** assert (lambertw (-1, -1/exp(1)), -1, 2*eps) ***** test - % sub in doubles gives sym (matches SMT 2013b) - % FIXME: but see - % http://www.mathworks.co.uk/help/symbolic/gradient.html - assert( isequal( subs(f, {x y}, {2 pi}), 2*sym(pi) )) - assert( ~isa(subs(f, {x y}, {2 pi}), 'double')) - assert( isa(subs(f, {x y}, {2 pi}), 'sym')) - assert( isa(subs(f, {x y}, {2 sym(pi)}), 'sym')) - assert( isa(subs(f, {x y}, {sym(2) sym(pi)}), 'sym')) -***** shared x,y,t,f,F - syms x y t - f = sin(x)*y; - F = [f; 2*f]; + x = [1 2 3 pi 10 100 1000 12345]; + W = lambertw (x); + assert (W.*exp (W), x, -3*eps) ***** test - % need the simultaneous=True flag in SymPy (matches SMT 2013b) - assert( isequal( subs(f, [x t], [t 6]), y*sin(t) )) - assert( isequal( subs(F, [x t], [t 6]), [y*sin(t); 2*y*sin(t)] )) + x = [1 2 3 pi 10 100 1000 12345]; + k = [-3 -2 -1 0 1 2 3 4]; + W = lambertw (k, x); + assert (W.*exp (W), x, -10*eps) ***** test - % swap x and y (also needs simultaneous=True - assert( isequal( subs(f, [x y], [y x]), x*sin(y) )) + % input shape preserved + x = [0 1; 2 3]; + b = x; + W = lambertw (b, x); + assert (W.*exp (W), x, -10*eps) ***** test - % but of course both x and y to t still works - assert( isequal( subs(f, [x y], [t t]), t*sin(t) )) -***** shared + % input shape preserved + x = [0 1; 2 3]; + b = 0; + W = lambertw (b, x); + assert (W.*exp (W), x, -10*eps) ***** test - % Issue #10, subbing matrices in for scalars - syms y - a = sym([1 2; 3 4]); - f = sin(y); - g = subs(f, y, a); - assert (isequal (g, sin(a))) + % input shape preserved + x = 10; + b = [0 1; 2 3]; + W = lambertw (b, x); + assert (W.*exp (W), x*ones (size (b)), -10*eps) +***** assert (isnan (lambertw (nan))) ***** test - % Issue #10, subbing matrices in for scalars - syms y - a = sym([1 2]); - g = subs(sin(y), {y}, {a}); - assert (isequal (g, sin(a))) + % limiting behaviour as z large + k = 3; + A = lambertw (k, 1e100); + assert (abs (imag (A) - 2*pi*k) < 0.1) ***** test - % Issue #10, subbing matrices in for scalars - syms y - a = sym([1; 2]); - g = subs(sin(y), {y}, a); - assert (isequal (g, sin(a))) + % limiting behaviour as z large, up imag axis + k = 1; + A = lambertw (k, 1e100*1i); + assert (abs (imag (A) - (2*k+0.5)*pi) < 0.1) ***** test - % Issue #10, subbing matrices in for scalars - syms y - a = [10 20 30]; - f = 2*y; - g = subs(f, y, a); - assert (isequal (g, 2*a)) - assert (isa (g, 'sym')) + % limiting behaviour as z large, down imag axis + k = -2; + A = lambertw (k, -1e100*1i); + assert (abs (imag (A) - (2*k-0.5)*pi) < 0.1) ***** test - % Issue #10, sub matrices in for two scalars - syms x y - a = [10 20 30]; - f = x^2*y; - g = subs(f, {x y}, {a a+1}); - h = a.^2.*(a+1); - assert (isequal (g, h)) + % limiting behaviour as z large, near branch + k = 3; + A = lambertw (k, -1e100); + B = lambertw (k, -1e100 + 1i); + C = lambertw (k, -1e100 - 1i); + assert (abs (imag (A) - (2*k+1)*pi) < 0.1) + assert (abs (imag (B) - (2*k+1)*pi) < 0.1) + assert (abs (imag (C) - (2*k-1)*pi) < 0.1) ***** test - % Issue #10, sub matrices in for two scalars - syms x y z - a = [10 20 30]; - f = x^2*y; - g = subs(f, {x y}, {a z}); - h = a.^2*z; - assert (isequal (g, h)) - g = subs(f, {x y}, {a 6}); - h = a.^2*6; - assert (isequal (g, h)) -***** error - syms x y - a = [10 20 30]; - f = x^2*y; - g = subs(f, {x y}, {[10 20 30] [10 20]}); + % infinities and nan + A = lambertw ([inf exp(1) -inf nan]); + B = [inf 1 inf + pi*1i nan]; + assert (isequaln (A, B)) ***** test - % two inputs - syms x y - assert (isequal (subs (2*x, 6), sym(12))) - assert (isequal (subs (2*x*y^2, 6), 12*y^2)) - assert (isequal (subs (2*y, 6), sym(12))) - assert (isequal (subs (sym(2), 6), sym(2))) + % infinities and nan + A = lambertw (3, [inf 1 -inf nan]); + B = [inf + 2*3*pi*1i lambertw(3,1) inf + (2*3+1)*pi*1i nan]; + assert (isequaln (A, B)) ***** test - % only two inputs, vector - syms x - assert (isequal (subs (2*x, [3 5]), sym([6 10]))) + % infinities and nan + A = lambertw ([0 1 2 0], [inf -inf nan exp(1)]); + B = [inf inf+3*pi*1i nan 1]; + assert (isequaln (A, B)) ***** test - % SMT compat, subbing in vec/mat for nonexist x - syms x y z - % you might think this would be y: - assert (~ isequal (subs (y, x, [1 2]), y)) - % but it gives two y's: - assert (isequal (subs (y, x, [1 2]), [y y])) - assert (isequal (subs (sym(42), [3 5]), sym([42 42]))) - assert (isequal (subs (sym(42), x, []), sym([]))) - assert (isequal (subs (y, {x y}, {[1 2; 3 4], 6}), sym([6 6; 6 6]))) - assert (isequal (subs (y, {x z}, {[1 2; 3 4], 6}), [y y; y y])) + % scalar infinity z, vector b + A = lambertw ([1 2 -3], inf); + B = [lambertw(1, inf) lambertw(2, inf) lambertw(-3, inf)]; + assert (isequal (A, B)) ***** test - syms x y - assert (isequal (subs (sym(42), x, y), sym(42))) - assert (isequal (subs (sym(42), y), sym(42))) - assert (isequal (subs (sym(42)), sym(42))) + % scalar -infinity z, vector b + A = lambertw ([1 2 -3], -inf); + B = [lambertw(1, -inf) lambertw(2, -inf) lambertw(-3, -inf)]; + assert (isequal (A, B)) ***** test - % empty lists - assert (isequal (subs (sym(42), {}, {}), sym(42))) - assert (isequal (subs (42, sym([]), sym([])), sym(42))) + % scalar z nan, vector b + A = lambertw ([1 2 -3], nan); + B = [nan nan nan]; + assert (isequaln (A, B)) +21 tests, 21 passed, 0 known failure, 0 skipped +[inst/eulergamma.m] +>>>>> /build/octave-symbolic-3.0.1/inst/eulergamma.m +***** error catalan (sym(1)) +***** assert (double (eulergamma ()) > 0.577215664901) +***** assert (double (eulergamma ()) < 0.577215664902) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/vpa.m] +>>>>> /build/octave-symbolic-3.0.1/inst/vpa.m ***** test - syms x y - f = x*y; - x = 6; y = 7; - g = subs (f); - assert (isequal (g, sym (42))) - assert (isa (g, 'sym')) + a = vpa(0, 4); + b = double(a); + assert(b == 0) ***** test - syms x y - f = x*y; - x = 6; - g = subs (f); - assert (isequal (g, 6*y)) + a = vpa(pi, 4); + b = sin(a); + assert(abs(double(b)) < 1e-4) ***** test - syms x y - f = x*y; - xsave = x; - x = 6; - g = subs (f); - assert (isequal (g, 6*y)) - assert (isequal (f, xsave*y)) + % vpa from double is ok, doesn't warn (c.f., sym(2.3)) + a = vpa(2.3); + assert(true) ***** test - syms a x y - f = a*x*y; - a = 6; - clear x - g = subs (f); - syms x - assert (isequal (g, 6*x*y)) -25 tests, 25 passed, 0 known failure, 0 skipped -[inst/@sym/numden.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/numden.m -***** error numden (sym(1), 2) + % vpa from double not more than 16 digits + a = vpa(sqrt(pi), 32); + b = sin(a^2); + assert(abs(double(b)) > 1e-20) + assert(abs(double(b)) < 1e-15) ***** test - syms x - [n, d] = numden (1/x); - assert (isequal (n, sym(1)) && isequal (d, x)) + a = vpa(sym(pi), 32); + b = sin(a); + assert(abs(double(b)) < 1e-30) ***** test - syms x y - n1 = [sym(1); x]; - d1 = [x; y]; - [n, d] = numden (n1 ./ d1); - assert (isequal (n, n1) && isequal (d, d1)) + a = vpa(sym(pi), 256); + b = sin(a); + assert(abs(double(b)) < 1e-256) ***** test - [n, d] = numden (sym(2)); - assert (isequal (n, 2)); - assert (isequal (d, 1)); + % pi str + a = vpa('pi', 32); + b = sin(a); + assert(abs(double(b)) < 1e-32) ***** test - syms x y - [n, d] = numden ((x + pi)/(y + 6)); - assert (isequal (n, x + pi)); - assert (isequal (d, y + 6)); + % pi str + a = vpa('pi', 32); + b = vpa(sym('pi'), 32); + assert (double (a - b) == 0) ***** test - syms x y - [n, d] = numden ((x^2 + y^2)/(x*y)); - assert (isequal (n, x^2 + y^2)); - assert (isequal (d, x*y)); -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/subsindex.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/subsindex.m + spi = sym(pi); + a = vpa(spi, 10); + b = double(a); + assert(~isAlways(spi == a)) ***** test - i = sym(1); - a = 7; - assert(a(i)==a); - i = sym(2); - a = 2:2:10; - assert(a(i)==4); + % matrix of sym + a = [sym(pi) 0; sym(1)/2 1]; + b = [pi 0; 0.5 1]; + c = vpa(a, 6); + assert(max(max(abs(double(c)-b))) < 1e-6) ***** test - i = sym([1 3 5]); - a = 1:10; - assert( isequal (a(i), [1 3 5])) + % matrix of double + b = [pi 0; 0.5 1]; + c = vpa(b, 6); + assert(max(max(abs(double(c)-b))) < 1e-6) ***** test - i = sym([1 3 5]); - a = sym(1:10); - assert( isequal (a(i), sym([1 3 5]))); + % integer type + a = vpa(int32(6), 64); + b = vpa(6, 64); + assert (isequal (a, b)) ***** test - % should be an error if it doesn't convert to double - syms x - a = 1:10; - try - a(x) - waserr = false; - catch - waserr = true; - end - assert(waserr) + % matrix of int + b = int32([pi 0; 6.25 1]); + c = vpa(b, 6); + assert (isequal (double(c), [3 0; 6 1])) ***** test - syms x - assert (isequal (x(sym (true)), x)) - assert (isequal (x(sym (false)), sym ([]))) + % can pass pi directly to vpa + a = vpa(sym(pi), 128); + b = vpa(pi, 128); + assert (isequal (a, b)) ***** test - x = 6; - assert (isequal (x(sym (true)), 6)) - assert (isequal (x(sym (false)), [])) + % if sym does sth special for e so should vpa + a = vpa(sym(exp(1)), 64); + b = vpa(exp(1), 64); + assert (isequal (a, b)) ***** test - a = sym([10 12 14]); - assert (isequal (a(sym ([true false true])), a([1 3]))) - assert (isequal (a(sym ([false false false])), sym (ones(1,0)))) + % can pass pi directly to vpa, even in array + a = vpa(sym([2 pi]), 128); + b = vpa([2 pi], 128); + assert (isequal (a, b)) ***** test - a = [10 11; 12 13]; - p = [true false; true true]; - assert (isequal (a(sym (p)), a(p))) - p = [false false false]; - assert (isequal (a(sym (p)), a(p))) -***** error - a = [10 12]; - I = [sym(true) 2]; - b = a(I); -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/resize.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/resize.m + % can pass i directly to vpa + a = vpa(sym(i)); + b = vpa(i); ***** test - B = sym([1 0 0; 0 0 0]); - assert (isequal (resize (sym(1), 2, 3), B)) - assert (isequal (resize (sym(1), [2 3]), B)) + % 'i' and 'I' just make vars + a = vpa(sym(1i)); + b = vpa('i'); + c = vpa('I'); + assert (~isequal (a, b)) + assert (~isequal (a, c)) ***** test - B = sym([1 0; 0 0]); - assert (isequal (resize (sym(1), 2), B)) + % '1i' and '1j' strings + a = vpa(sym(1i)); + b = vpa('1i'); + c = vpa('1j'); + assert (isequal (a, b)) + assert (isequal (a, c)) ***** test - A = sym([pi 2; 3 4]); - assert (isequal (resize (A, 1), sym(pi))) -***** assert (isequal (size (resize (sym(1), 0, 0)), [0 0])) -***** assert (isequal (size (resize (sym(1), 6, 0)), [6 0])) -***** assert (isequal (size (resize (sym(1), 0, 3)), [0 3])) -***** error resize (sym(1)) -***** error resize (sym(1), 2, 3, 4) -***** error resize (sym(1), [2 3 4]) -9 tests, 9 passed, 0 known failure, 0 skipped -[inst/@sym/cosd.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cosd.m -***** error cosd (sym(1), 2) -***** assert (isequaln (cosd (sym(nan)), sym(nan))) + % Issue #868, precision loss on '0.33j' + a = vpa('0.33j', 40); + b = vpa('0.33i', 40); + assert (double (abs (imag (a)*100/33) - 1) < 1e-39) + assert (isequal (a, b)) ***** test - f1 = cosd (sym(1)); - f2 = cosd (1); - assert (double (f1), f2, -eps) + % inf/-inf do not become symbol('inf') + S = {'oo', '-oo', 'inf', 'Inf', '-inf', '+inf'}; + for j = 1:length(S) + a = vpa(S{j}); + b = vpa(sym(S{j})); + assert (isequal (a, b)) + end ***** test - D = [10 30; 110 -45]; - A = sym(D); - f1 = cosd (A); - f2 = cosd (D); - assert (double (f1), f2, -4*eps) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/ifourier.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ifourier.m -***** error ifourier (sym(1), 2, 3, 4) + a = vpa('2.3', 20); + s = strtrim(disp(a, 'flat')); + assert (strcmp (s, '2.3000000000000000000')) ***** test - % matlab SMT compat - syms t r u x w - Pi=sym('pi'); - assert(logical( ifourier(exp(-abs(w))) == 1/(Pi*(x^2 + 1)) )) - assert(logical( ifourier(exp(-abs(x))) == 1/(Pi*(t^2 + 1)) )) - assert(logical( ifourier(exp(-abs(r)),u) == 1/(Pi*(u^2 + 1)) )) - assert(logical( ifourier(exp(-abs(r)),r,u) == 1/(Pi*(u^2 + 1)) )) + % these should *not* be the same + a = vpa(2.3, 40); + b = vpa('2.3', 40); + sa = sympy (a); + sb = sympy (b); + assert (~isequal (a, b)) + assert (abs(double(a - b)) > 1e-20) + assert (abs(double(a - b)) < 1e-15) + assert (~strcmp(sa, sb)) ***** test - % basic - syms x w - Pi=sym('pi'); - assert(logical( ifourier(exp(-w^2/4)) == 1/(sqrt(Pi)*exp(x^2)) )) - assert(logical( ifourier(sqrt(Pi)/exp(w^2/4)) == exp(-x^2) )) + % these should *not* be the same + x = vpa('1/3', 32); + y = vpa(sym(1)/3, 32); + z = vpa(1/3, 32); + assert (isequal (x, y)) + assert (~isequal (x, z)) ***** test - % Dirac delta tests - syms x w - Pi=sym('pi'); - assert(logical( ifourier(dirac(w-2)) == exp(2*1i*x)/(2*Pi) )) - assert (logical( ifourier(sym(2), w, x) == 2*dirac(x) )) + % big integers + a = int64(12345678); + a = a*a; + b = vpa(a); + c = vpa('152415765279684'); + assert (isequal (b, c)) ***** test - % advanced test - syms x w c d - Pi=sym('pi'); - f=(Pi*(dirac(x-c)+dirac(x+c))+2*Pi*1i*(-dirac(x+3*d)+dirac(x-3*d))+2/(x^2+1))/(2*Pi); - assert(logical( simplify(ifourier(cos(c*w)+2*sin(3*d*w)+exp(-abs(w)))-f) == 0 )) -***** xtest - % Inverse Fourier transform cannot recover non-smooth functions - % SymPy cannot evaluate correctly?? - syms x w - assert(logical( ifourier(2/(w^2 + 1)) == exp(-abs(x)) )) - assert(logical( ifourier(2/(w^2 + 1)) == heaviside(x)/exp(x) + heaviside(-x)*exp(x) )) - assert(logical( ifourier(-(w*4)/(w^4 + 2*w^2 + 1) )== -x*exp(-abs(x))*1i )) - assert(logical( ifourier(-(w*4)/(w^4 + 2*w^2 + 1) )== -x*(heaviside(x)/exp(x) + heaviside(-x)*exp(x))*1i )) -!!!!! known failure -assert (logical (ifourier (2 / (w ^ 2 + 1)) == exp (-abs (x)))) failed -***** error ifourier (sym('k', 'positive')*sym('k')) + % big integers (workaround poor num2str, works in 4.0?) + a = int64(1234567891); a = a*a; + b = vpa(a); + c = vpa('1524157877488187881'); + assert (isequal (b, c)) +***** warning vpa ('sqrt(2.0)'); +***** warning + if (pycall_sympy__ ('return Version(spver) > Version("1.4")')) + a = vpa('2**0.5'); + b = vpa(sqrt(sym(2))); + assert (isequal (a, b)) + else + warning('dangerous') % fake it until we drop 1.4 + end ***** test - % SMT compact, prefers k over symvar - syms k x y - assert (isequal (ifourier(y*exp(-k^2/4)), y/sqrt(sym(pi))*exp(-x^2))) -8 tests, 7 passed, 1 known failure, 0 skipped -[inst/@sym/svd.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/svd.m + a = vpa('2.3e1'); + b = vpa(' 2.3e+1 '); + assert (isequal (a, b)) + a = vpa('21e-1'); + b = vpa('2.1'); + assert (isequal (a, b)) ***** test - % basic - A = [1 2; 3 4]; - B = sym(A); - sd = svd(A); - s = svd(B); - s2 = double(s); - assert (norm(s2 - sd) <= 10*eps) + % Issue #859, operations on immutable matrices + x = vpa (sym ([1 2])); + % If vpa no longer makes an ImmutableDenseMatrix, + % may need to adjust or remove this test. + assert (~ isempty (strfind (sympy (x), 'Immutable'))) + y = sin(x); + y2 = [sin(vpa(sym(1))) sin(vpa(sym(2)))]; + assert (isequal (y, y2)) +30 tests, 30 passed, 0 known failure, 0 skipped +[inst/@symfun/ldivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/ldivide.m ***** test - % scalars syms x - syms y positive - a = sym(-10); - assert (isequal (svd(a), sym(10))) - assert (isequal (svd(x), sqrt(x*conj(x)))) - assert (isequal (svd(y), y)) + f(x) = x^2; + assert( isa(f .\ f, 'symfun')) + assert( isa(f .\ x, 'symfun')) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@symfun/diff.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/diff.m ***** test - % matrix with symbols - syms x positive - A = [x+1 0; sym(0) 2*x+1]; - s = svd(A); - s2 = subs(s, x, 2); - assert (isequal (s2, [sym(5); 3])) + % concrete fcn + syms x + f(x) = x*x; + g(x) = 2*x; + assert (logical (diff(f) == g)) + assert (isa (diff(f), 'symfun')) ***** test - % matrix with symbols - syms x positive - A = [x+1 0; sym(0) 2*x+1]; - s = svd(A); - s2 = subs(s, x, 2); - assert (isequal (s2, [sym(5); 3])) + % abstract fcn + syms y(x) + assert (logical (diff(y) == diff(y(x)))) + assert (isa (diff(y), 'symfun')) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/size.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/size.m ***** test - % matrix with symbols, nonneg sing values - syms x real - A = [x 0; 0 sym(-5)]; - s = svd(A); - assert (isequal (s, [abs(x); 5])) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ismatrix.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ismatrix.m -***** assert(ismatrix(sym('x'))) -***** assert(ismatrix(sym([1 2 3]))) -***** assert(ismatrix(sym([1; 2]))) -***** assert(ismatrix(sym([1 2; 3 4]))) -***** assert(ismatrix(sym([]))) -***** assert(ismatrix(sym(ones(1,0)))) -***** assert(ismatrix(sym(ones(0,3)))) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/xor.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/xor.m -***** shared t, f - t = sym(true); - f = sym(false); + syms x + f(x) = x; + d = size(f); + assert (isequal (d, [1 1])) + [n, m] = size(f); + assert (isequal ([n m], [1 1])) + assert (size(f, 1) == 1) + assert (size(f, 2) == 1) +***** test + syms x + f(x) = [1 x]; + d = size(f); + assert (isequal (d, [1 1])) + [n, m] = size(f); + assert (isequal ([n m], [1 1])) + assert (size(f, 1) == 1) + assert (size(f, 2) == 1) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/formula.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/formula.m ***** test % simple - assert (isequal (xor(t, f), t)) - assert (isequal (xor(t, t), f)) + syms x + f(x) = sin(x); + g = formula(f); + assert (isequal (g, sin(x))); ***** test - % array - w = [t t f f]; - z = [t f t f]; - assert (isequal (xor(w, z), [f t t f])) -***** xtest - % output is sym even for scalar t/f - % ₣IXME: should match other bool fcns - assert (isa (xor(t, f), 'sym')) + % concrete: return is a sym, not a symfun + syms x + f(x) = sin(x); + g = formula(f); + assert (~isa(g, 'symfun')); +***** test + % abstract: return is a sym, not a symfun + syms f(x) + g = formula(f); + assert (~isa(g, 'symfun')); +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@symfun/subsref.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/subsref.m ***** test - % eqns syms x - e = xor(x == 4, x == 5); - assert (isequal (subs(e, x, [3 4 5 6]), [f t t f])) + f(x) = x^2; + v = f.vars; + assert(iscell(v)) + assert(length(v)==1) + assert(isequal(v{1},x)) ***** test - % eqns, exclusive + %% pass through to sym properties syms x - e = xor(x == 3, x^2 == 9); - assert (isequal (subs(e, x, [-3 0 3]), [t f f])) -***** error xor (sym('x'), 1, 2) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/lhs.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/lhs.m + f(x) = x^2; + y = x^2; % not a symfun + assert(strcmp(f.flat, y.flat)) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/private_disp_name.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/private_disp_name.m ***** test - syms x y - f = x + 1 == 2*y; - assert (isequal (lhs(f), x + 1)) - assert (isequal (rhs(f), 2*y)) + syms f(x) + s = private_disp_name(f, 'f'); + assert (strcmp (s, 'f(x)')) ***** test syms x y - f = x + 1 < 2*y; - assert (isequal (lhs(f), x + 1)) - assert (isequal (rhs(f), 2*y)) + g(y, x) = x + y; + s = private_disp_name(g, 'g'); + assert (strcmp (s, 'g(y, x)')) ***** test - syms x y - f = x + 1 >= 2*y; - assert (isequal (lhs(f), x + 1)) - assert (isequal (rhs(f), 2*y)) + syms f(x) + assert (isempty (private_disp_name(f, ''))) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@symfun/plus.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/plus.m ***** test - syms x y - A = [x == y 2*x < 2*y; 3*x > 3*y 4*x <= 4*y; 5*x >= 5*y x < 0]; - L = [x 2*x; 3*x 4*x; 5*x x]; - R = [y 2*y; 3*y 4*y; 5*y 0]; - assert (isequal( lhs(A), L)) - assert (isequal( rhs(A), R)) -***** error - syms x - lhs(x) -***** error - lhs(sym(true)) -***** error syms x - A = [1 + x == 2*x sym(6)]; - lhs(A) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@sym/ne.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ne.m + f(x) = x^2; + assert( isa(f + f, 'symfun')) + assert( isa(f + x, 'symfun')) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@symfun/rdivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/rdivide.m ***** test - % simple - x = sym(1); y = sym(1); e = x ~= y; - assert (~logical (e)) - x = sym(1); y = sym(2); e = x ~= y; - assert (logical(e)) + syms x + f(x) = x^2; + assert( isa(f./f, 'symfun')) + assert( isa(f./[x x^2], 'symfun')) ***** test - % array -- array syms x - a = sym([1 3 3 2*x]); - b = sym([2 x 3 10]); - e = a ~= b; - assert (isa (e, 'sym')) - assert (logical (e(1))) - assert (isa (e(2), 'sym')) - assert (isequal (e(2), 3 ~= x)) - assert (~logical (e(3))) - assert (isa (e(4), 'sym')) - assert (isequal (e(4), 2*x ~= 10)) + f(x) = [x 2*x]; + h = f./[x 2]; + assert( isa(h, 'symfun')) + assert (isequal (formula (h), [1 x])) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/mpower.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mpower.m ***** test - % oo - syms oo x - e = oo ~= x; - assert (isa (e, 'sym')) - s = strtrim (disp (e, 'flat')); - % SymPy <= 0.7.6.x will be '!=', newer gives 'Ne', test both - assert (strcmp (s, 'oo != x') || strcmp (s, 'Ne(oo, x)')) + syms x + f(x) = 2*x; + h = f^f; + assert( isa(h, 'symfun')) + assert (isequal (formula (h), (2*x)^(2*x))) + h = f^sym(2); + assert( isa(h, 'symfun')) + assert (isequal (formula (h), 4*x^2)) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@symfun/numel.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/numel.m ***** test - % nan - syms oo x - snan = sym(nan); - e = snan ~= sym(0); - assert (logical (e)) - e = snan ~= snan; - assert (logical (e)) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/acos.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/acos.m -***** error acos (sym(1), 2) -***** assert (isequaln (acos (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + syms x + f(x) = x^2; + assert(numel(f)==1) ***** test - f1 = acos(x); - f2 = acos(d); - assert( abs(double(f1) - f2) < 1e-15 ) + syms x + f(x) = [1 x]; + assert(numel(f)==1) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/minus.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/minus.m ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = acos(A); - f2 = acos(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + syms x + f(x) = x^2; + assert( isa(f - f, 'symfun')) + assert( isa(f - x, 'symfun')) ***** test - % round trip - y = sym('y'); - A = acos (d); - f = acos (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/tan.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/tan.m -***** error tan (sym(1), 2) -***** assert (isequaln (tan (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + % Octave bug #42735 fixed in 4.4.2 + syms x + f(x) = x^2; + g = x^2; + h = x - f; assert (isa (h, 'symfun') && isequal (formula (h), x - g)) + h = x + f; assert (isa (h, 'symfun') && isequal (formula (h), x + g)) + h = x * f; assert (isa (h, 'symfun') && isequal (formula (h), x * g)) + h = x / f; assert (isa (h, 'symfun') && isequal (formula (h), x / g)) + h = x ^ f; assert (isa (h, 'symfun') && isequal (formula (h), x ^ g)) + h = x .* f; assert (isa (h, 'symfun') && isequal (formula (h), x .* g)) + h = x ./ f; assert (isa (h, 'symfun') && isequal (formula (h), x ./ g)) + h = x .^ f; assert (isa (h, 'symfun') && isequal (formula (h), x .^ g)) ***** test - f1 = tan(x); - f2 = tan(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % different variables + syms x y + f(x) = 2*x; + g(y) = sin(y); + h = f - g(x); + assert( isa(h, 'symfun')) + assert( isequal (argnames (h), argnames (f))) + assert (isequal (formula (h), 2*x - sin(x))) + % and even if rh-sym has a dummy variable: + h = f - g(y); + assert( isa(h, 'symfun')) + assert( isequal (argnames (h), argnames(f))) + assert (isequal (formula (h), 2*x - sin(y))) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = tan(A); - f2 = tan(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % different variables, f has more + syms x y + f(x,y) = 2*x*y; + g(y) = sin(y); + h = f - g(y) + g(x); + assert( isa(h, 'symfun')) + assert( isequal (argnames (h), argnames (f))) + assert (isequal (formula (h), 2*x*y - sin(y) + sin(x))) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/@symfun/symvar.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/symvar.m ***** test - % round trip - y = sym('y'); - A = tan (d); - f = tan (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/eval.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/eval.m -***** error eval (sym(1), 2) -***** assert (isnumeric (eval (sym(3)))) -***** assert (isnumeric (eval (sin (sym(3))))) + % basic + syms f(t, s) + assert (isempty (symvar (f, 0))) + assert (isequal (symvar (f, 1), t)) + assert (isequal (symvar (f, 2), [t s])) + assert (isequal (symvar (f, 3), [t s])) ***** test - syms x y - f = 2*x*y; - x = 3; - y = 4; - g = eval (f); - assert (isequal (g, 24)) + % note preference for vars of symfun, if n requested + syms x f(y) + assert (isequal (symvar(f*x, 1), y)) + assert (isequal (symvar(f(y)*x, 1), x)) ***** test - syms x y - f = 2*x*y; - clear y - x = 3; - g = eval (f); - assert (isequal (g, 6*sym('y'))) + % symfun, checked smt + syms x f(y) + a = f*x; + b = f(y)*x; + assert (isequal (symvar(a), [x y])) + assert (isequal (symvar(b), [x y])) ***** test - % do not convert inputs to sym, for SMT compat - nearpi = pi + 1e-14; % sym could make this pi - x = sym('x'); - f = 2*x; - x = nearpi; - d = eval (f); - assert (abs (d - 2*pi) > 1e-15) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@sym/interval.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/interval.m + % preference for the explicit variables + syms a x f(t, s) + h = f*a + x; + assert (isequal (symvar (h, 1), t)) + assert (isequal (symvar (h, 2), [t s])) + assert (isequal (symvar (h, 3), [t s x])) + assert (isequal (symvar (h, 4), [t s x a])) + assert (isequal (symvar (h, 5), [t s x a])) + assert (isequal (symvar (h), [a s t x])) ***** test - a = interval(sym(1), 2); - assert (isa (a, 'sym')) + % symfun dep on some vars only, matches smt w/ n + syms x s t + f(s) = x; + g(s, t) = x*s; + assert (isequal (symvar(f, 1), s)) + assert (isequal (symvar(f, 2), [s x])) + assert (isequal (symvar(g, 1), s)) + assert (isequal (symvar(g, 2), [s t])) + assert (isequal (symvar(g, 3), [s t x])) ***** test - % some set subtraction - a = interval(sym(0), 4); - b = interval(sym(0), 1); - c = interval(sym(1), 4, true); - q = a - b; - assert (isequal( q, c)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/arg.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/arg.m + % A documented difference from SMT on symvar(symfun) w/o n + syms x s t + f(s) = x; + g(s, t) = x*s; + % SMT would have + %assert (isequal (symvar(f), x)) % no s + %assert (isequal (symvar(g), [s x])) % no t + assert (isequal (symvar(f), [s x])) + assert (isequal (symvar(g), [s t x])) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@symfun/mrdivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mrdivide.m ***** test syms x - assert (isequal (angle (x), arg (x))); + f(x) = x^2; + assert( isa(f/f, 'symfun')) + assert( isa(f/x, 'symfun')) 1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/jacobian.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/jacobian.m -***** error jacobian (sym(1), 2, 3) -***** error jacobian ([sym(1) 2; sym(3) 4]) -***** shared x,y,z - syms x y z +[inst/@symfun/argnames.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/argnames.m ***** test - % 1D - f = x^2; - assert (isequal (jacobian(f), diff(f,x))) - assert (isequal (jacobian(f,{x}), diff(f,x))) - assert (isequal (jacobian(f,x), diff(f,x))) + % basic test + syms f(x) + assert (isequal (argnames (f), x)) ***** test - % const - f = sym(1); - g = sym(0); - assert (isequal (jacobian(f), g)) - assert (isequal (jacobian(f,x), g)) + % Multiple variables, abstract symfun + syms f(t, x, y) + assert (isequal (argnames (f), [t x y])) ***** test - % double const - f = 1; - g = sym(0); - assert (isequal (jacobian(f,x), g)) + % Concrete symfun + syms x y z t + f(t, x, y) = x + y + z; + assert (isequal (argnames (f), [t x y])) +3 tests, 3 passed, 0 known failure, 0 skipped +[inst/@symfun/symfun.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/symfun.m +***** error symfun (1, sym('x'), 3) +***** error symfun ('f', sym('x')) ***** test - % diag - f = [x y^2]; - g = [sym(1) 0; 0 2*y]; - assert (isequal (jacobian(f), g)) - assert (isequal (jacobian(f, [x y]), g)) - assert (isequal (jacobian(f, {x y}), g)) + syms x y + syms f(x) + assert(isa(f,'symfun')) + clear f + f(x,y) = sym('f(x,y)'); + assert(isa(f,'symfun')) ***** test - % anti-diag - f = [y^2 x]; - g = [0 2*y; sym(1) 0]; - assert (isequal (jacobian(f), g)) - assert (isequal (jacobian(f, {x y}), g)) + % symfuns are syms as well + syms x + f(x) = 2*x; + assert (isa (f, 'symfun')) + assert (isa (f, 'sym')) + assert (isequal (f(3), 6)) + assert (isequal (f(sin(x)), 2*sin(x))) ***** test - % shape - f = [x y^2]; - assert (isequal (size(jacobian(f, {x y z})), [2 3])) - assert (isequal (size(jacobian(f, [x y z])), [2 3])) - assert (isequal (size(jacobian(f, [x; y; z])), [2 3])) - assert (isequal (size(jacobian(f.', {x y z})), [2 3])) + syms x y + f = symfun(sym('f(x)'), {x}); + assert(isa(f, 'symfun')) + f = symfun(sym('f(x,y)'), [x y]); + assert(isa(f, 'symfun')) + f = symfun(sym('f(x,y)'), {x y}); + assert(isa(f, 'symfun')) ***** test - % scalar f - f = x*y; - assert (isequal (size(jacobian(f, {x y})), [1 2])) - g = gradient(f, {x y}); - assert (isequal (jacobian(f, {x y}), g.')) + % rhs is not sym + syms x + f = symfun(8, x); + assert (isa (f,'symfun')) + assert (isequal (f(10), sym(8))) ***** test - % vect f wrt 1 var - f = [x x^2]; - assert (isequal (size(jacobian(f, x)), [2 1])) - f = f.'; % same shape output - assert (isequal (size(jacobian(f, x)), [2 1])) -10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@sym/cot.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cot.m -***** error cot (sym(1), 2) -***** assert (isequaln (cot (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + % vector symfun + syms x y + F(x,y) = [1; 2*x; y; y*sin(x)]; + assert (isa (F, 'symfun')) + assert (isa (F, 'sym')) + assert (isequal (F(sym(pi)/2,4) , [sym(1); sym(pi); 4; 4] )) ***** test - f1 = cot(x); - f2 = cot(d); - assert( abs(double(f1) - f2) < 1e-15 ) + x = sym('x'); + y = sym('y'); + f(x) = sym('f(x)'); + g(x,y) = sym('g(x,y)'); + % make sure these don't fail + f(1); + g(1,2); + g(x,y); + diff(g, x); + diff(g, y); ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = cot(A); - f2 = cot(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % defining 1D symfun in terms of a 2D symfun + syms x y t + syms 'g(x,y)' + f(t) = g(t,t); + f(5); + assert (length (argnames (f)) == 1) + assert (isequal (argnames (f), t)) + assert (isequal( formula(diff(f,x)), sym(0))) ***** test - % round trip - y = sym('y'); - A = cot (d); - f = cot (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/coshint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/coshint.m -***** error coshint (sym(1), 2) -***** xtest - assert (isequaln (coshint (sym(nan)), sym(nan))) -!!!!! known failure -assert (isequaln (coshint (sym (nan)), sym (nan))) failed -***** shared x, d - d = 1; - x = sym('1'); + % replace g with shorter and specific fcn + syms x g(x) + g; + g(x) = 2*x; + assert( isequal (g(5), 10)) ***** test - f1 = coshint(x); - f2 = 0.8378669409802082408947; - assert( abs(double(f1) - f2) < 1e-15 ) + % octave <= 3.8 needs quotes on 2D symfuns, so make sure it works + syms x y + syms 'f(x)' + syms 'g(x,y)' + assert (isa (f, 'symfun')) + assert (isa (g, 'symfun')) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = coshint(A); - f2 = 0.8378669409802082408947; - f2 = [f2 f2; f2 f2]; - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % Bug #41: Octave <= 3.8 parser fails without quotes around 2D fcn + syms x y + eval('syms g(x,y)') + assert (isa (g, 'symfun')) ***** test - % round trip - y = sym('y'); - A = coshint (d); - f = coshint (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 4 passed, 1 known failure, 0 skipped -[inst/@sym/mpower.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/mpower.m + % and these days it works without eval trick + syms g(x,y) + assert (isa (g, 'symfun')) ***** test - syms x - assert(isequal(x^(sym(4)/5), x.^(sym(4)/5))) + % syms f(x) without defining x + clear x + syms f(x) + assert(isa(f, 'symfun')) + assert(isa(x, 'sym')) ***** test - % integer powers of scalars + % SMT compat: symfun indep var overwrites existing var + t = 6; + syms f(t) + assert (logical (t ~= 6)) +***** test + % SMT compat: symfun indep var overwrites existing var, even if sym syms x - assert (isequal (x^2, x*x)) - assert (isequal (x^sym(3), x*x*x)) + t = x; + syms f(t) + assert (~ logical (t == x)) ***** test - % array ^ integer syms x y - A = [x 2; y 4]; - assert (isequal (A^2, A*A)) - assert (isequal (simplify(A^3 - A*A*A), [0 0; 0 0])) + f(x) = x^2; + g(x,y) = sym('g(x,y)'); + f2 = 2*f; + assert( isequal (f2(4), 32)) + assert( isa(f2, 'symfun')) + assert( isa(2*g, 'symfun')) + assert( isa(0*g, 'symfun')) % in SMT, this is the zero symfun ***** test - % array ^ rational - Ad = [1 2; 0 3]; - A = sym(Ad); - B = A^(sym(1)/3); - Bd = Ad^(1/3); - assert (max(max(abs(double(B) - Bd))) < 1e-14) + % syms has its own parsing code, check it works + syms f(x,y) + g = f; + syms f(x, y) + assert (isequal (f, g)) + syms 'f( x, y )' + assert (isequal (f, g)) ***** test - % non-integer power - A = sym([1 2; 0 3]); - B = A^pi; - C = [1 -1+3^sym(pi); 0 sym(3)^pi]; - assert (isequal (B, C)) + % syms own parsing code should not reorder the vars + syms f(y, x) + v = argnames (f); + assert (isequal (v(1), y) && isequal (v(2), x)) ***** test - % matpow - syms n - A = sym([1 2; 3 4]); - B = A^n; - C = 10 + B + B^2; - D = subs(C, n, 1); - E = 10 + A + A^2; - assert (isequal (simplify(D), simplify(E))) -Waiting........ + % assignment of symfun to symfun, issue #189 + syms t + x(t) = 2*t; + y(t) = x; + assert (isa (y, 'symfun')) + y = symfun(x, t); + assert (isa (y, 'symfun')) + % others + y = x; + assert (isa (y, 'symfun')) + y(t) = x(t); + assert (isa (y, 'symfun')) ***** test - % matpow, sub in zero gives identity - A = sym([1 2; 0 3]); - syms n; - B = A^n; - C = subs(B, n, 1); - assert (isequal (C, A)) - C = subs(B, n, 0); - assert (isequal (C, sym(eye(2)))) -***** xtest - % scalar^array (e.g., defined by matrix exponential) not implemented in SymPy? - % on 1.0 < SymPy <= 1.5.1, you can form the expression but still cannot eval + % assignment of generic symfun to symfun + syms t x(t) + y(t) = x; + assert (isa (y, 'symfun')) + y = symfun(x, t); + assert (isa (y, 'symfun')) +***** error + % Issue #444: invalid args syms x - A = [1 2; 3 4]; - B = x^A; - assert (strcmp (regexprep (disp (B, 'flat'), '\s+', ''), 'x**Matrix([[1,2],[3,4]])')) - % sub in and compare to double - Bs = subs(B, x, sym(3)/2); - D1 = double(Bs); - D2 = (3/2)^[1 2; 3 4]; - assert (max(max(abs(D1 - D2))) < 1e-14) -!!!!! known failure -Python exception: TypeError: unsupported operand type(s) for ** or pow(): 'Symbol' and 'MutableDenseMatrix' - occurred at line 2 of the Python code block: - return x**y + f(x, x) = 2*x; +***** error + % Issue #444: invalid args + syms x y + f(x, y, x) = x + y; +***** error + % Issue #444: invalid args + syms x y + f(x, y, x) = x + y; ***** error - A = sym([1 2; 3 4]); - B = A^A; -9 tests, 8 passed, 1 known failure, 0 skipped -[inst/@sym/partfrac.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/partfrac.m -***** test - % basic - syms x y z - assert(logical( partfrac(y/(x + 2)/(x + 1),x) == -y/(x + 2) + y/(x + 1) )) - assert(logical( factor(partfrac(x^2/(x^2 - y^2),y)) == factor(x/(2*(x + y)) + x/(2*(x - y)) ))) - assert(logical( factor(partfrac(x^2/(x^2 - y^2),x)) == factor(-y/(2*(x + y)) + y/(2*(x - y)) + 1 ))) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/tanh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/tanh.m -***** error tanh (sym(1), 2) -***** assert (isequaln (tanh (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); -***** test - f1 = tanh(x); - f2 = tanh(d); - assert( abs(double(f1) - f2) < 1e-15 ) -***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = tanh(A); - f2 = tanh(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) -***** test - % round trip - y = sym('y'); - A = tanh (d); - f = tanh (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/tand.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/tand.m -***** error tand (sym(1), 2) -***** assert (isequaln (tand (sym(nan)), sym(nan))) + % Issue #444: expression as arg + syms x + f(2*x) = 4*x; +25 tests, 25 passed, 0 known failure, 0 skipped +[inst/@symfun/uminus.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/uminus.m ***** test - f1 = tand (sym(1)); - f2 = tand (1); - assert (double (f1), f2, -eps) + % Issue #447 + syms x + f(x) = x^2; + assert (isa (-f, 'symfun')) ***** test - D = [10 30; 110 -45]; - A = sym(D); - f1 = tand (A); - f2 = tand (D); - assert (double (f1), f2, -eps) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@sym/formula.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/formula.m + syms f(x) + h = -f; + assert (isa (h, 'symfun')) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/mtimes.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mtimes.m ***** test syms x - assert (isequal (formula(x), x)) - assert (isequal (formula(2*x), 2*x)) + f(x) = x^2; + assert( isa(f * f, 'symfun')) + assert( isa(f * x, 'symfun')) 1 test, 1 passed, 0 known failure, 0 skipped -[inst/@sym/coeffs.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/coeffs.m -***** error coeffs (sym(1), 2, 3, 4) -***** error coeffs (sym(1), 2, 'al') -***** error coeffs (sym(1), 'al') +[inst/@symfun/isequal.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/isequal.m +***** error isequal (symfun('x + 1', x)) +***** test + syms x y + f(x) = 2*x; + g(x) = 2*x; + assert (isequal (f, g)) ***** test - % simple syms x - [c, t] = coeffs(6*x*x + 27); - assert (isequal (c, [6 27])) - assert (isequal (t, [x*x 1])) + f(x) = 2*x + 1; + g(x) = 2*x + 1; + h(x) = 2*x + 1; + assert (isequal (f, g, h)) ***** test - % specify a variable syms x - [c, t] = coeffs(6*x*x + 27, x); - assert (isequal (c, [6 27])) - assert (isequal (t, [x*x 1])) + f(x) = 2*x + 1; + g(x) = 2*x + 1; + h(x) = 2*x; + assert (~ isequal (f, g, h)) ***** test - % specify another variable syms x y - [c, t] = coeffs(6*x + 27, y); - assert (isequal (c, 6*x + 27)) - assert (isequal (t, 1)) + f(x) = 2*x; + g(x, y) = 2*x; + assert (~ isequal (f, g)) ***** test - % weird SMT order - syms x - a1 = [27 6]; - a2 = [6 27]; - c = coeffs(6*x*x + 27); - assert (isequal (c, a1)) - coeffs(6*x*x + 27); - assert (isequal (ans, a1)) - [c, t] = coeffs(6*x*x + 27); - assert (isequal (c, a2)) + syms x y + f(x) = symfun(nan, x); + g(x) = symfun(nan, x); + assert (~ isequal (f, g)) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@symfun/power.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/power.m ***** test - % no weird order with "all" syms x - c = coeffs(6*x*x + 27, 'all'); - assert (isequal (c, [6 0 27])) + f(x) = 2*x; + h = f.^f; + assert( isa(h, 'symfun')) + assert (isequal (formula (h), (2*x)^(2*x))) ***** test - % "all" syms x - [c, t] = coeffs(6*x*x + 27, 'all'); - assert (isequal (c, [6 0 27])) - assert (isequal (t, [x^2 x 1])) + f(x) = [x 2*x]; + h = f.^[x 3]; + assert( isa(h, 'symfun')) + assert (isequal (formula (h), [x^x 8*x^3])) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/mldivide.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mldivide.m ***** test - % "All" syms x - [c, t] = coeffs(6*x, 'All'); - assert (isequal (c, [6 0])) - assert (isequal (t, [x 1])) -***** test - % multivariable array - syms x y - [c, t] = coeffs(6*x*x + 27*y*x + 36, [x y]); - a = [6 27 36]; - s = [x^2 x*y 1]; - assert (isequal (c, a)) - assert (isequal (t, s)) - % with list - [c, t] = coeffs(6*x*x + 27*y*x + 36, {x y}); - assert (isequal (c, a)) - assert (isequal (t, s)) + f(x) = x^2; + assert( isa(f\f, 'symfun')) + assert( isa(f\x, 'symfun')) +1 test, 1 passed, 0 known failure, 0 skipped +[inst/@symfun/times.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/times.m ***** test - % other symbols treated as part of coeffs - syms x y - [c, t] = coeffs(6*x*x + 27*y*x + 36, x); - a = [6 27*y 36]; - s = [x^2 x 1]; - assert (isequal (c, a)) - assert (isequal (t, s)) -***** error - % TODO: multivariate all not working (https://github.com/cbm755/octsympy/issues/720) - syms x y - [c, t] = coeffs(6*x^2 + 7*y + 19, [x y], 'all'); + syms x + f(x) = x^2; + assert( isa(f .* f, 'symfun')) + assert( isa(f .* x, 'symfun')) ***** test - % empty same as not specifying; maybe not SMT compatible: - % https://github.com/cbm755/octsympy/pull/708#discussion_r94292831 - syms x y - [c, t] = coeffs(6*x*x + 27*y*x + 36, {}); - a = [6 27 36]; - assert (isequal (c, a)) - [c, t] = coeffs(6*x*x + 27*y*x + 36); - assert (isequal (c, a)) + syms x + f(x) = [x 2*x]; + h = f.*[x 3]; + assert( isa(h, 'symfun')) + assert (isequal (formula (h), [x^2 6*x])) +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@symfun/isequaln.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/isequaln.m +***** error isequaln (symfun('x + 1', x)) ***** test - % no input defaults to all symbols (not symvar to get x) syms x y - [c, t] = coeffs(6*x*x + 27*y*x + 36); - assert (isequal (c, [6 27 36])) + f(x) = 2*x; + g(x) = 2*x; + assert (isequaln (f, g)) ***** test - % non sym input syms x - assert (isequal (coeffs(6, x), sym(6))) -***** test - % constant input without x - assert (isequal (coeffs(sym(6)), sym(6))) + f(x) = 2*x + 1; + g(x) = 2*x + 1; + h(x) = 2*x + 1; + assert (isequaln (f, g, h)) ***** test - % constant input without x - assert (isequal (coeffs (sym(6), {}), sym(6))) - % irrational coefficients syms x - f = x^2 + sqrt(sym(2))*x; - [c1, t1] = coeffs (f); - [c2, t2] = coeffs (f, x); - assert (isequal (c1, c2)) - assert (isequal (t1, t2)) -18 tests, 18 passed, 0 known failure, 0 skipped -[inst/@sym/factorial.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/factorial.m -***** error factorial (sym(1), 2) -***** xtest - assert (isequaln (factorial (sym(nan)), sym(nan))) -!!!!! known failure -assert (isequaln (factorial (sym (nan)), sym (nan))) failed -***** shared x, d - d = 1; - x = sym('1'); -***** test - f1 = factorial(x); - f2 = factorial(d); - assert( abs(double(f1) - f2) < 1e-15 ) + f(x) = 2*x + 1; + g(x) = 2*x + 1; + h(x) = 2*x; + assert (~ isequaln (f, g, h)) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = factorial(A); - f2 = factorial(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + syms x y + f(x) = 2*x; + g(x, y) = 2*x; + assert (~ isequaln (f, g)) ***** test - % round trip - y = sym('y'); - A = factorial (d); - f = factorial (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 4 passed, 1 known failure, 0 skipped -[inst/@sym/erfc.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/erfc.m -***** error erfc (sym(1), 2) -***** assert (isequaln (erfc (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + syms x y + f(x) = symfun(nan, x); + g(x) = symfun(nan, x); + assert (isequaln (f, g)) ***** test - f1 = erfc(x); - f2 = erfc(d); - assert( abs(double(f1) - f2) < 1e-15 ) + syms x y + f(x) = symfun(nan, x); + g(x, y) = symfun(nan, x); + assert (~ isequaln (f, g)) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@symfun/int.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@symfun/int.m ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = erfc(A); - f2 = erfc(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % indefinite integral of symfun gives symfun + syms x + f(x) = x^2; + g = int(f); + assert (isa(g, 'symfun')) + g = int(f, x); + assert (isa(g, 'symfun')) ***** test - % round trip - y = sym('y'); - A = erfc (d); - f = erfc (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/cosh.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cosh.m -***** error cosh (sym(1), 2) -***** assert (isequaln (cosh (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + % indefinite integral of abstract symfun gives symfun + syms f(x) + g = int(f); + assert (isa(g, 'symfun')) + g = int(f, x); + assert (isa(g, 'symfun')) ***** test - f1 = cosh(x); - f2 = cosh(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % definite integral does not give symfun + syms x + f(x) = x^2; + g = int(f, x, 0, 2); + assert (isa(g, 'sym')) + assert (~isa(g, 'symfun')) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = cosh(A); - f2 = cosh(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % ... even if it has a variable in it + syms x t + f(x) = x; + g = int(f, x, 0, t); + assert (isa(g, 'sym')) + assert (~isa(g, 'symfun')) ***** test - % round trip - y = sym('y'); - A = cosh (d); - f = cosh (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/any.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/any.m + % ... even if the input is abstract funcion + syms f(x) + g = int(f, x, 0, 2); + assert (isa(g, 'sym')) + assert (~isa(g, 'symfun')) ***** test - % matrix - a = [0 0; 1 0]; - s = sym(a); - assert (isequal (any (s), any (a))) - assert (isequal (any (s,1), any (a,1))) - assert (isequal (any (s,2), any (a,2))) + % symfun in x, integrated in y gives symfun still in x + % (SMT does this too). + syms f(x) y + g = int(f, y); + assert (isa (g, 'symfun')) + assert (isequal (argnames (g), x)) ***** test - % vector - a = [0 1 0]; - s = sym(a); - assert (isequal (any (s), any (a))) - assert (isequal (any (s,1), any (a,1))) - assert (isequal (any (s,2), any (a,2))) + % same as above, but concrete symfun + syms x y + f(x) = x^2; + g = int(f, y); + assert (isa (g, 'symfun')) + assert (isequal (argnames (g), x)) + assert (isequal (formula(g), x^2*y)) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/vpasolve.m] +>>>>> /build/octave-symbolic-3.0.1/inst/vpasolve.m ***** test - % should fail on symbols syms x - s = [0 1 x]; - try - any (s) - waserr = false; - catch - waserr = true; - end - assert (waserr) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@sym/dilog.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/dilog.m -***** assert (isequal (dilog (sym(1)), sym(0))) -***** assert (isequal (dilog (sym(0)), sym(pi)^2/6)) -***** assert (isequal (dilog (sym(2)), -sym(pi)^2/12)) -***** assert (double(dilog(sym(-1))), pi^2/4 - pi*1i*log(2), eps) + vpi = vpa(sym(pi), 64); + e = tan(x/4) == 1; + q = vpasolve(e, x, 3.0); + w = q - vpi ; + assert (double(w) < 1e-30) ***** test - % round-trip syms x - f = dilog (x); - h = function_handle (f); - A = h (1.1); - B = dilog (1.1); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/ei.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/ei.m + vpi = vpa(sym(pi), 64); + e = tan(x/4) == 1; + q = vpasolve(e, x); + w = q - vpi; + assert (double(w) < 1e-30) + q = vpasolve(e); + w = q - vpi; + assert (double(w) < 1e-30) ***** test + % very accurate pi syms x - f = ei(sym(0)); - assert (double(f) == -inf) -***** test - D = [1.895117816355937 4.954234356001890]; - A = ei(sym([1 2])); - assert (all (abs(double(A) - D) < 1e-15)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/acsch.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/acsch.m -***** error acsch (sym(1), 2) -***** assert (isequaln (acsch (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); -***** test - f1 = acsch(x); - f2 = acsch(d); - assert( abs(double(f1) - f2) < 1e-15 ) -***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = acsch(A); - f2 = acsch(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) -***** test - % round trip - y = sym('y'); - A = acsch (d); - f = acsch (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/inv.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/inv.m + e = tan(x/4) == 1; + m = digits(256); + q = vpasolve(e, x, 3); + assert (double(abs(sin(q))) < 1e-256) + digits(m); ***** test - % scalar + % very accurate sqrt 2 syms x - assert (isequal (inv(x), 1/x)) + e = x*x == 2; + m = digits(256); + q = vpasolve(e, x, 1.5); + assert (double(abs(q*q - 2)) < 1e-256) + digits(m); ***** test - % diagonal + % very accurate sqrt pi + % (used to fail https://github.com/sympy/sympy/issues/8564) syms x - A = [sym(1) 0; 0 x]; - B = [sym(1) 0; 0 1/x]; - assert (isequal (inv(A), B)) + e = x*x == sym(pi); + m = digits(256); + q = vpasolve(e, x, 3); + assert (double(abs(sin(q*q))) < 1e-256) + digits(m); ***** test - % 2x2 inverse - A = [1 2; 3 4]; - assert (max (max (abs (double (inv (sym (A))) - inv(A)))) <= 3*eps) -***** error - syms a; - A = [a a; a a]; - inv(A) -***** error - syms a; - A = [a a]; - inv(A) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/rows.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/rows.m + syms x + r = vpasolve(x^2 + 2 == 0, x, 1i); + assert (double (imag(r)^2 - 2), 0, 1e-32) + assert (double (real(r)^2), 0, 1e-32) + r = vpasolve(x^2 + 2 == 0, x, -3i + 5); + assert (double (imag(r)^2 - 2), 0, 1e-32) + assert (double (real(r)^2), 0, 1e-32) ***** test - a = sym([1 2 3]); - assert (rows(a) == 1) + % system + syms x y + f = 3*x^2 - 2*y^2 - 1; + g = x^2 - 2*x + y^2 + 2*y - 8; + r = vpasolve([f; g], [x; y], sym([-1; 1])); + assert (isa (r, 'sym')) + assert (numel (r) == 2) ***** test - a = sym([1 2 3; 4 5 6]); - assert (rows(a) == 2) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/cos.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/cos.m -***** error cos (sym(1), 2) -***** assert (isequaln (cos (sym(nan)), sym(nan))) -***** shared x, d - d = 1; - x = sym('1'); + % system, double guess + syms x y + f = 3*x^2 - 2*y^2 - 1; + g = x^2 - 2*x + y^2 + 2*y - 8; + r = vpasolve([f; g], [x; y], [-1.1 1.2]); ***** test - f1 = cos(x); - f2 = cos(d); - assert( abs(double(f1) - f2) < 1e-15 ) + % system, double guess + syms x y + f = 3*x^2 - 2*y^2 - 1; + g = x^2 - 2*x + y^2 + 2*y - 8; + r1 = vpasolve([f; g], [x; y], [-1.1]); + r2 = vpasolve([f; g], [x; y], [-1.1 -1.1]); + assert (isequal (r1, r2)) ***** test - D = [d d; d d]; - A = [x x; x x]; - f1 = cos(A); - f2 = cos(D); - assert( all(all( abs(double(f1) - f2) < 1e-15 ))) + % system, more eqns than unknowns + syms x y + eqns = [x^3 - x - y == 0; y*exp(x) == 16; log(y) + x == 4*log(sym(2))]; + r = vpasolve (eqns, [x; y], [1; 1]); + A = subs (lhs (eqns), [x; y], r); + err = A - [0; 16; 4*log(sym(2))]; + assert (double (err), zeros (size (err)), 1e-31) +10 tests, 10 passed, 0 known failure, 0 skipped +[inst/findsymbols.m] +>>>>> /build/octave-symbolic-3.0.1/inst/findsymbols.m ***** test - % round trip - y = sym('y'); - A = cos (d); - f = cos (y); - h = function_handle (f); - B = h (d); - assert (A, B, -eps) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/charpoly.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/charpoly.m -***** error charpoly (sym (1), 1, 2) -***** error charpoly (sym ([1 2])) + syms x b y n a arlo + z = a*x + b*pi*sin (n) + exp (y) + exp (sym (1)) + arlo; + s = findsymbols (z); + assert (isequal ([s{:}], [a,arlo,b,n,x,y])) ***** test syms x - A = sym([1 2; 3 4]); - assert (isequal (charpoly(A, x), x^2 - 5*x -2)) + s = findsymbols (x); + assert (isequal (s{1}, x)) ***** test - syms x - A = sym([1 2; 3 4]); - B = sym([1 -5 -2]); - assert (isequal (charpoly(A), B)) + syms z x y a + s = findsymbols ([x y; 1 a]); + assert (isequal ([s{:}], [a x y])) +***** assert (isempty (findsymbols (sym (1)))) +***** assert (isempty (findsymbols (sym ([1 2])))) +***** assert (isempty (findsymbols (sym (nan)))) +***** assert (isempty (findsymbols (sym (inf)))) +***** assert (isempty (findsymbols (exp (sym (2))))) ***** test - syms x - A = sym([x x; x x]); - B = sym([1 -2*x 0]); - assert (isequal (charpoly(A), B)) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/fresnels.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/fresnels.m -***** error fresnels (sym(1), 2) + % empty sym for findsymbols, findsym, and symvar + assert (isempty (findsymbols (sym([])))) + assert (isempty (findsym (sym([])))) + assert (isempty (symvar (sym([])))) ***** test - a = fresnels(sym(0)); - assert (isequal (a, sym(0))) + % diff. assumptions make diff. symbols + x1 = sym('x'); + x2 = sym('x', 'positive'); + f = x1*x2; + assert (length (findsymbols (f)) == 2) ***** test - b = fresnels(sym('oo')); - assert (isequal (b, sym(1)/2)) + % symfun or sym + syms x f(y) + a = f*x; + b = f(y)*x; + assert (isequal (findsymbols(a), {x y})) + assert (isequal (findsymbols(b), {x y})) ***** test - % values in a matrix - syms x - a = fresnels([sym(0) sym('oo') x 1]); - b = [sym(0) sym(1)/2 fresnels(x) fresnels(sym(1))]; - assert (isequal (a, b)) + % findsymbols on symfun does not find the argnames (unless they + % are on the RHS of course, this matches SMT 2014a). + syms a x y + f(x, y) = a; % const symfun + assert (isequal (findsymbols(f), {a})) + syms a x y + f(x, y) = a*y; + assert (isequal (findsymbols(f), {a y})) ***** test - % round trip - syms x - f = fresnels (x); - h = function_handle (f); - A = h (1.1); - B = fresnels (1.1); - assert (A, B) -5 tests, 5 passed, 0 known failure, 0 skipped -[inst/@sym/simplify.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/simplify.m -***** shared x,p,q - syms x - p = x^2 + x + 1; - q = horner (p); -***** assert(~isequal( p - q, 0)) -***** assert(isequal( simplify(p - q), 0)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@sym/hypot.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@sym/hypot.m -***** assert (isequal (hypot (sym(3), 4), sym(5))) + % sorts lexigraphically, same as symvar *with single input* + % (note symvar does something different with 2 inputs). + syms A B a b x y X Y + f = A*a*B*b*y*X*Y*x; + assert (isequal (findsymbols(f), {A B X Y a b x y})) + assert (isequal (symvar(f), [A B X Y a b x y])) ***** test - % compare to @double (note Matlab hypot only takes 2 inputs) - A = hypot (hypot ([1 2 3], [4 5 6]), [7 8 9]); - B = double (hypot (sym([1 2 3]), [4 5 6], [7 8 9])); - assert (A, B, -eps) + % symbols in matpow + syms x y + syms n + A = [sin(x) 2; y 1]; + B = A^n; + L = findsymbols(B); + assert (isequal (L, {n x y})) ***** test - % compare to @double, with complex - A = hypot ([1+2i 3+4i], [1 3+1i]); - B = double (hypot (sym([1+2i 3+4i]), [1 3+1i])); - assert (A, B, -eps) + % array of eq + syms x y + assert (isequal (findsymbols (2 == [2 x y]), {x y})) ***** test - % matrices - x = sym([1 -2; 0 3]); - y = sym([0 0; 8 4]); - A = hypot (x, y); - B = sym([1 2; 8 5]); - assert (isequal (A, B)) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/eulergamma.m] ->>>>> /build/octave-symbolic-3.0.1/inst/eulergamma.m -***** error catalan (sym(1)) -***** assert (double (eulergamma ()) > 0.577215664901) -***** assert (double (eulergamma ()) < 0.577215664902) + % array of ineq + syms x y + A = [x < 1 2*x < y x >= 2 3 <= x x != y]; + assert (isequal (findsymbols (A), {x y})) +16 tests, 16 passed, 0 known failure, 0 skipped +[inst/@logical/isAlways.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@logical/isAlways.m +***** error isAlways (true, false) +***** assert(isAlways(true)) +***** assert(~isAlways(false)) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/poly2sym.m] ->>>>> /build/octave-symbolic-3.0.1/inst/poly2sym.m -***** shared x,y,a,b,c,p - syms x y a b c - p = x^3 + 2*x^2 + 3*x + 4; -***** assert(isAlways( poly2sym([1 2 3 4]) == p )) -***** assert(isAlways( poly2sym([1 2 3 4],x) == p )) -***** assert(isAlways( poly2sym([1 2 3 4],y) == subs(p,x,y) )) -***** assert(isAlways( poly2sym([1 2 3 4],5) == subs(p,x,5) )) -***** assert(isequal( poly2sym ([1]), 1 )) -***** assert(isequal( poly2sym ([]), 0 )) -***** assert(isAlways( poly2sym(sym([1 2 3 4]),x) == p )) -***** assert(isAlways( poly2sym([a b c],x) == a*x^2 + b*x + c )) -***** assert(isAlways( poly2sym([a b c]) == a*x^2 + b*x + c )) -***** assert(isequal( poly2sym(sym([])), 0 )) -***** assert(isAlways( poly2sym({sym(1) sym(2)}, x) == x + 2 )) -***** assert(isequal( poly2sym ({1}), 1 )) -***** assert(isequal( poly2sym ({}), 0 )) -***** assert(isequal( poly2sym ({1}, x), 1 )) -***** assert(isequal( poly2sym ({}, x), 0 )) -***** assert(isAlways( poly2sym([x x], x) == x^2 + x )) -***** test - % mixed cell array with doubles and syms - assert (isequal (poly2sym ({2.0 sym(3) int64(4)}), 2*x^2 + 3*x + 4)) -***** test - % string for x - p = poly2sym ([1 2], 's'); - syms s - assert (isequal (p, s + 2)) -18 tests, 18 passed, 0 known failure, 0 skipped [inst/dirac.m] >>>>> /build/octave-symbolic-3.0.1/inst/dirac.m ***** assert (isinf (dirac (0))) @@ -13723,154 +14452,106 @@ ***** error dirac (1i) ***** assert (isa (dirac (single (0)), 'single')) 6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@double/adjoint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/adjoint.m +[inst/@double/euler.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/euler.m +***** error euler (1, 2, 3) +***** error euler ([1 2], [1 2 3]) +***** error euler ([1 2], [1; 2]) +***** assert (isequal (euler (0), 1)) +***** assert (isequal (euler (1), 0)) +***** assert (isequal (euler (10), -50521)) ***** test - M = [1 2; 3 4]; - A = [4 -2; -3 1]; - assert (isequal (adjoint (M), A)); + n = sym(88); + m = 88; + A = euler (m); + B = double (euler (n)); + assert (A, B, -eps); ***** test - assert (isequal (adjoint (42), 1)); -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@double/pochhammer.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/pochhammer.m -***** error pochhammer (1) -***** error pochhammer (1, 2, 3) -***** error pochhammer ([1 2], [1 2 3]) -***** error pochhammer ([1 2], [1; 2]) + m = [0 1; 2 4]; + n = sym(m); + A = euler (m); + B = double (euler (n)); + assert (isequal (A, B)); ***** test - y = sym(11)/10; - t = sym(3); - x = 1.1; - s = 3; - A = pochhammer (x, s); - B = double (pochhammer (y, t)); - assert (A, B, -2*eps); + y = sym(19)/10; + n = sym(2); + x = 1.9; + m = 2; + A = euler (m, x); + B = double (euler (n, y)); + assert (A, B, -eps); ***** test - % maple - A = 256.798558090310131720; - B = pochhammer (18.1, 1.9); - assert (A, B, -20*eps) + % correct behaviour at floating point infinity + assert (isequal (euler (4, inf), inf)) + assert (isequal (euler (4, -inf), inf)) + assert (isequal (euler (3, inf), inf)) + assert (isequal (euler (3, -inf), -inf)) ***** test - % maple, complex inputs> - A = 2.67921619474318221972 + 1.96716724764630702653*1i; - B = pochhammer (12.1+3.1*i, 0.5+0.2i); - assert (A, B, -4*eps); + assert (isnan (euler(3, nan))) + assert (isnumeric (euler(3, nan))) ***** test - % maple, matrix inputs - A = [5.61467232547723663908 20.6144884613920190965]; - B = pochhammer ([0.9 0.8], [3.1 4.2]); - assert (A, B, -3*eps); + % maple, complex input + A = 113.33970046079423204 - 46.991080726974811540i; + B = euler(7, 2.12345 + 1.23i); + assert (A, B, -eps); ***** test - % x matrix, s scalar + % maple, complex input, large m, small x + A = 0.18034673393294025238e276 + 0.27756266681280689172e276*i; + B = euler (200, 0.123+0.234i); + assert (A, B, -eps); +***** test + % x matrix, m scalar y = [1 2 sym(pi); exp(sym(1)) 5 6]; - t = sym(2); + n = sym(2); x = double (y); - s = 2; - A = pochhammer (s, x); - B = double (pochhammer (t, y)); - assert (A, B, -3*eps); + m = 2; + A = euler (m, x); + B = double (euler (n, y)); + assert (A, B, -eps); ***** test - % s matrix, x scalar - t = [1 2 sym(pi); exp(sym(1)) 5 6]; - y = sym(2); - s = double (t); - x = 2; - A = pochhammer (s, x); - B = double (pochhammer (t, y)); - assert (A, B, -5*eps); -10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@double/fresnelc.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/fresnelc.m -***** error fresnelc (1, 2) + % m matrix, x scalar + m = [1 2 3; 4 5 6]; + n = sym(m); + y = sym(21)/10; + x = 2.1; + A = euler (m, x); + B = double (euler (n, y)); + assert (A, B, -3*eps); +15 tests, 15 passed, 0 known failure, 0 skipped +[inst/@double/dilog.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/dilog.m ***** test x = 1.1; y = sym(11)/10; - A = fresnelc (x); - B = double (fresnelc (y)); + A = dilog (x); + B = double (dilog (y)); assert (A, B, -4*eps); ***** test - y = [2 3 sym(pi); exp(sym(1)) 5 6]; + y = [2 2 sym(pi); exp(sym(1)) 5 6]; x = double (y); - A = fresnelc (x); - B = double (fresnelc (y)); - assert (A, B, -4*eps); + A = dilog (x); + B = double (dilog (y)); + assert (A, B, -eps); ***** test % maple: % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; - % > for a in A do evalf(FresnelC(a)) end do; + % > for a in A do evalf(dilog(a)) end do; x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; - A = [ 16.087871374125480424 - 36.225687992881650217*1i - 0.47688568479874574722e12 + 0.12213736710985573216e13*1i - 0.49999989867881789756 - 0.49989869420551572361*1i - -0.000099999999999999997535 + 0.99999999999999987665e-6*1i - 0.15391592966931193100e26 - 0.75738824160998910388e24*1i ]; - B = fresnelc (x); + A = [ -0.59248494924959145800 - 1.5760154034463234224*1i + -1.0549087538833908441 - 3.8759788000863368495*1i + -12.192421669033171348 + -2.9195729380904939394 - 3.9540920181102973073*1i + 1.6459519160623984119 - 0.00032335296277550987686*1i + -1.5445800511775466879 + 9.4256034277816069684*1i ]; + B = dilog (x); assert (A, B, -eps) -***** assert (fresnelc (inf), 0.5) -***** assert (fresnelc (-inf), -0.5) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@double/chebyshevU.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/chebyshevU.m -***** error chebyshevU (1) -***** error chebyshevU (1, 2, 3) -***** error chebyshevU ([1 2], [1 2 3]) -***** error chebyshevU ([1 2], [1; 2]) -***** test - y = sym(11)/10; - t = sym(2); - x = 1.1; - s = 2; - A = chebyshevU (s, x); - B = double (chebyshevU (t, y)); - assert (A, B, -2*eps); -***** test - % maple - A = 1.661891066691338157; - B = chebyshevU (18.1, 0.9); - assert (A, B, -3*eps) -***** test - % maple, complex inputs> - % ChebyshevU(12.1+3.1*I, 0.5+0.2*I); - A = 1.046959313670290818 - 0.03386773634958834846*1i; - B = chebyshevU (12.1+3.1*i, 0.5+0.2i); - assert (A, B, -3*eps); -***** test - % maple, matrix inputs - A = [2.2543638828875776000 -1.3872651600553574400]; - B = chebyshevU ([16 17], [0.9 0.8]); - assert (A, B, -10*eps); -***** test - % x matrix, s scalar - y = [1 2 sym(pi); exp(sym(1)) 5 6]; - t = sym(2); - x = double (y); - s = 2; - A = chebyshevU (s, x); - B = double (chebyshevU (t, y)); - assert (A, B, -eps); -***** test - % s matrix, x scalar - t = [1 2 sym(pi); exp(sym(1)) 5 6]; - y = sym(2); - s = double (t); - x = 2; - A = chebyshevU (s, x); - B = double (chebyshevU (t, y)); - assert (A, B, -2*eps); ***** xtest - % https://github.com/fredrik-johansson/mpmath/issues/469 - assert (chebyshevU (4, inf), inf) - assert (chebyshevU (4, -inf), inf) - assert (chebyshevU (3, inf), inf) - assert (chebyshevU (3, -inf), -inf) + % https://github.com/fredrik-johansson/mpmath/issues/473 + assert (isinf (dilog (inf))) !!!!! known failure -ASSERT errors for: assert (chebyshevU (4, inf),inf) - - Location | Observed | Expected | Reason - () 5 Inf 'Inf' mismatch -11 tests, 10 passed, 1 known failure, 0 skipped +assert (isinf (dilog (inf))) failed +***** assert (isnan (dilog (-inf))) +5 tests, 4 passed, 1 known failure, 0 skipped [inst/@double/chebyshevT.m] >>>>> /build/octave-symbolic-3.0.1/inst/@double/chebyshevT.m ***** error chebyshevT (1) @@ -13931,84 +14612,100 @@ Location | Observed | Expected | Reason () 1 Inf 'Inf' mismatch 11 tests, 10 passed, 1 known failure, 0 skipped -[inst/@double/zeta.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/zeta.m -***** error zeta (1, 2, 3) -***** assert (isnan (zeta (nan))) +[inst/@double/coshint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/coshint.m +***** error coshint (1, 2) ***** test x = 1.1; y = sym(11)/10; - A = zeta (x); - B = double (zeta (y)); + A = coshint (x); + B = double (coshint (y)); assert (A, B, -4*eps); ***** test y = [2 3 sym(pi); exp(sym(1)) 5 6]; x = double (y); - A = zeta (x); - B = double (zeta (y)); + A = coshint (x); + B = double (coshint (y)); assert (A, B, -4*eps); ***** test % maple: % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; - % > for a in A do evalf(Zeta(a)) end do; + % > for a in A do evalf(Chi(a)) end do; x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; - A = [ 0.59816556976238173670 - 0.35185474521784529050*1i - 0.21425967567391921717 + 0.52503846985036050707*1i - 1.0 - 1.7564685929749629608 - 0.10151198543617116894*1i - -0.49990811617645824900 - 0.91873792757763831501e-6*1i - 175.09070083717643866 - 71.512541417467273425*1i ]; - B = zeta (x); + A = [ 0.58447599687824767874 + 1.8682915044330306402*1i + -0.63131069034703116988 + 1.8986171211850702957*1i + 0.13577763724269399110e42 + -0.045456433004455372635 + 1.5707963267948966192*1i + -8.6330747070747332203 + 3.1315929868531280002*1i + 0.74701205140887966531e7 + 0.10381444259644068585e8*1i ]; + B = coshint (x); assert (A, B, -eps) -***** assert (zeta (inf), 1.0) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@double/harmonic.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/harmonic.m -***** error harmonic (1, 2) +***** assert (coshint (inf), inf) +***** assert (isinf (coshint (-inf))) +***** assert (imag (coshint (-inf)), pi) +7 tests, 7 passed, 0 known failure, 0 skipped +[inst/@double/bernoulli.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/bernoulli.m +***** error bernoulli (1, 2, 3) +***** error bernoulli ([1 2], [1 2 3]) +***** error bernoulli ([1 2], [1; 2]) +***** assert (bernoulli (0), 1) +***** assert (bernoulli (3), 0) +***** assert (bernoulli (1), -0.5, -eps) ***** test - x = 1.1; - y = sym(11)/10; - A = harmonic (x); - B = double (harmonic (y)); - assert (A, B, -4*eps); + n = sym(88); + m = 88; + A = bernoulli (m); + B = double (bernoulli (n)); + assert (A, B, -eps); ***** test - y = [2 3 sym(pi); exp(sym(1)) 5 6]; - x = double (y); - A = harmonic (x); - B = double (harmonic (y)); - assert (A, B, -4*eps); -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@double/sinhint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/sinhint.m -***** error sinhint (1, 2) + m = [0 1; 2 4]; + n = sym(m); + A = bernoulli (m); + B = double (bernoulli (n)); + assert (isequal (A, B)); ***** test - x = 1.1; - y = sym(11)/10; - A = sinhint (x); - B = double (sinhint (y)); - assert (A, B, -4*eps); + y = sym(19)/10; + n = sym(2); + x = 1.9; + m = 2; + A = bernoulli (m, x); + B = double (bernoulli (n, y)); + assert (A, B, -eps); ***** test - y = [2 3 sym(pi); exp(sym(1)) 5 6]; + assert (isequal (bernoulli (4, inf), inf)) + assert (isequal (bernoulli (4, -inf), inf)) +***** xtest + % still broken? + assert (isequal (bernoulli (3, inf), inf)) + assert (isequal (bernoulli (3, -inf), -inf)) +***** test + assert (isnan (bernoulli(3, nan))) + assert (isnumeric (bernoulli(3, nan))) +***** test + % maple, complex input + A = 34.21957245745810513 - 130.0046256649829101i; + B = bernoulli(7, 2.123 + 1.234i); + assert (A, B, -5*eps); +***** test + % x matrix, m scalar + y = [1 2 sym(pi); exp(sym(1)) 5 6]; + n = sym(2); x = double (y); - A = sinhint (x); - B = double (sinhint (y)); - assert (A, B, -4*eps); + m = 2; + A = bernoulli (m, x); + B = double (bernoulli (n, y)); + assert (A, B, -eps); ***** test - % maple: - % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; - % > for a in A do evalf(Shi(a)) end do; - x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; - A = [ 0.45769171128668800567 + 1.8332099215048436239*1i - 0.60888490416819746440 + 1.2482232175376056201*1i - 0.13577763724269399110e42 - 1.6583475942188740493*1i - -0.00010000000005553888891 + 0.10000000016666111119e-5*1i - -0.74701205140887967022e7 - 0.10381447401236722090e8*1i ]; - B = sinhint (x); - assert (A, B, -eps) -***** assert (sinhint (inf), inf) -***** assert (sinhint (-inf), -inf) -6 tests, 6 passed, 0 known failure, 0 skipped + % m matrix, x scalar + m = [1 2 3; 4 5 6]; + n = sym(m); + y = sym(21)/10; + x = 2.1; + A = bernoulli (m, x); + B = double (bernoulli (n, y)); + assert (A, B, -3*eps); +15 tests, 15 passed, 0 known failure, 0 skipped [inst/@double/cosint.m] >>>>> /build/octave-symbolic-3.0.1/inst/@double/cosint.m ***** error cosint (1, 2) @@ -14063,6 +14760,106 @@ assert (C1, C2, -100*eps); assert (S1, S2, -100*eps); 16 tests, 15 passed, 1 known failure, 0 skipped +[inst/@double/adjoint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/adjoint.m +***** test + M = [1 2; 3 4]; + A = [4 -2; -3 1]; + assert (isequal (adjoint (M), A)); +***** test + assert (isequal (adjoint (42), 1)); +2 tests, 2 passed, 0 known failure, 0 skipped +[inst/@double/chebyshevU.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/chebyshevU.m +***** error chebyshevU (1) +***** error chebyshevU (1, 2, 3) +***** error chebyshevU ([1 2], [1 2 3]) +***** error chebyshevU ([1 2], [1; 2]) +***** test + y = sym(11)/10; + t = sym(2); + x = 1.1; + s = 2; + A = chebyshevU (s, x); + B = double (chebyshevU (t, y)); + assert (A, B, -2*eps); +***** test + % maple + A = 1.661891066691338157; + B = chebyshevU (18.1, 0.9); + assert (A, B, -3*eps) +***** test + % maple, complex inputs> + % ChebyshevU(12.1+3.1*I, 0.5+0.2*I); + A = 1.046959313670290818 - 0.03386773634958834846*1i; + B = chebyshevU (12.1+3.1*i, 0.5+0.2i); + assert (A, B, -3*eps); +***** test + % maple, matrix inputs + A = [2.2543638828875776000 -1.3872651600553574400]; + B = chebyshevU ([16 17], [0.9 0.8]); + assert (A, B, -10*eps); +***** test + % x matrix, s scalar + y = [1 2 sym(pi); exp(sym(1)) 5 6]; + t = sym(2); + x = double (y); + s = 2; + A = chebyshevU (s, x); + B = double (chebyshevU (t, y)); + assert (A, B, -eps); +***** test + % s matrix, x scalar + t = [1 2 sym(pi); exp(sym(1)) 5 6]; + y = sym(2); + s = double (t); + x = 2; + A = chebyshevU (s, x); + B = double (chebyshevU (t, y)); + assert (A, B, -2*eps); +***** xtest + % https://github.com/fredrik-johansson/mpmath/issues/469 + assert (chebyshevU (4, inf), inf) + assert (chebyshevU (4, -inf), inf) + assert (chebyshevU (3, inf), inf) + assert (chebyshevU (3, -inf), -inf) +!!!!! known failure +ASSERT errors for: assert (chebyshevU (4, inf),inf) + + Location | Observed | Expected | Reason + () 5 Inf 'Inf' mismatch +11 tests, 10 passed, 1 known failure, 0 skipped +[inst/@double/logint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/logint.m +***** error logint (1, 2) +***** test + x = 1.1; + y = sym(11)/10; + A = logint (x); + B = double (logint (y)); + assert (A, B, -4*eps); +***** test + y = [2 3 sym(pi); exp(sym(1)) 5 6]; + x = double (y); + A = logint (x); + B = double (logint (y)); + assert (A, B, -4*eps); +***** test + % maple: + % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; + % > for a in A do evalf(Li(a)) end do; + x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; + A = [ 1.3876787420229375511 + 2.5087546988592328752*1i + 1.6987684473874802274 + 4.5936366057115204667*1i + 30.126141584079629926 + 3.4936715673748995398 + 5.5260023797127391973*1i + 0.90264689772681592152e-5 + 3.1415953634267361942*1i + -2.3996350854560916779 - 7.6971739096353664559*1i ]; + B = logint (x); + assert (A, B, -eps) +***** assert (logint (inf), inf) +***** assert (isnan (logint (-inf))) +6 tests, 6 passed, 0 known failure, 0 skipped [inst/@double/polylog.m] >>>>> /build/octave-symbolic-3.0.1/inst/@double/polylog.m ***** error polylog (1) @@ -14112,165 +14909,53 @@ B = double (polylog (t, y)); assert (A, B, -eps); 10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@double/euler.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/euler.m -***** error euler (1, 2, 3) -***** error euler ([1 2], [1 2 3]) -***** error euler ([1 2], [1; 2]) -***** assert (isequal (euler (0), 1)) -***** assert (isequal (euler (1), 0)) -***** assert (isequal (euler (10), -50521)) -***** test - n = sym(88); - m = 88; - A = euler (m); - B = double (euler (n)); - assert (A, B, -eps); -***** test - m = [0 1; 2 4]; - n = sym(m); - A = euler (m); - B = double (euler (n)); - assert (isequal (A, B)); -***** test - y = sym(19)/10; - n = sym(2); - x = 1.9; - m = 2; - A = euler (m, x); - B = double (euler (n, y)); - assert (A, B, -eps); -***** test - % correct behaviour at floating point infinity - assert (isequal (euler (4, inf), inf)) - assert (isequal (euler (4, -inf), inf)) - assert (isequal (euler (3, inf), inf)) - assert (isequal (euler (3, -inf), -inf)) -***** test - assert (isnan (euler(3, nan))) - assert (isnumeric (euler(3, nan))) -***** test - % maple, complex input - A = 113.33970046079423204 - 46.991080726974811540i; - B = euler(7, 2.12345 + 1.23i); - assert (A, B, -eps); -***** test - % maple, complex input, large m, small x - A = 0.18034673393294025238e276 + 0.27756266681280689172e276*i; - B = euler (200, 0.123+0.234i); - assert (A, B, -eps); -***** test - % x matrix, m scalar - y = [1 2 sym(pi); exp(sym(1)) 5 6]; - n = sym(2); - x = double (y); - m = 2; - A = euler (m, x); - B = double (euler (n, y)); - assert (A, B, -eps); -***** test - % m matrix, x scalar - m = [1 2 3; 4 5 6]; - n = sym(m); - y = sym(21)/10; - x = 2.1; - A = euler (m, x); - B = double (euler (n, y)); - assert (A, B, -3*eps); -15 tests, 15 passed, 0 known failure, 0 skipped -[inst/@double/logint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/logint.m -***** error logint (1, 2) +[inst/@double/zeta.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/zeta.m +***** error zeta (1, 2, 3) +***** assert (isnan (zeta (nan))) ***** test x = 1.1; y = sym(11)/10; - A = logint (x); - B = double (logint (y)); + A = zeta (x); + B = double (zeta (y)); assert (A, B, -4*eps); ***** test y = [2 3 sym(pi); exp(sym(1)) 5 6]; x = double (y); - A = logint (x); - B = double (logint (y)); + A = zeta (x); + B = double (zeta (y)); assert (A, B, -4*eps); ***** test % maple: % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; - % > for a in A do evalf(Li(a)) end do; + % > for a in A do evalf(Zeta(a)) end do; x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; - A = [ 1.3876787420229375511 + 2.5087546988592328752*1i - 1.6987684473874802274 + 4.5936366057115204667*1i - 30.126141584079629926 - 3.4936715673748995398 + 5.5260023797127391973*1i - 0.90264689772681592152e-5 + 3.1415953634267361942*1i - -2.3996350854560916779 - 7.6971739096353664559*1i ]; - B = logint (x); + A = [ 0.59816556976238173670 - 0.35185474521784529050*1i + 0.21425967567391921717 + 0.52503846985036050707*1i + 1.0 + 1.7564685929749629608 - 0.10151198543617116894*1i + -0.49990811617645824900 - 0.91873792757763831501e-6*1i + 175.09070083717643866 - 71.512541417467273425*1i ]; + B = zeta (x); assert (A, B, -eps) -***** assert (logint (inf), inf) -***** assert (isnan (logint (-inf))) +***** assert (zeta (inf), 1.0) 6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@double/bernoulli.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/bernoulli.m -***** error bernoulli (1, 2, 3) -***** error bernoulli ([1 2], [1 2 3]) -***** error bernoulli ([1 2], [1; 2]) -***** assert (bernoulli (0), 1) -***** assert (bernoulli (3), 0) -***** assert (bernoulli (1), -0.5, -eps) -***** test - n = sym(88); - m = 88; - A = bernoulli (m); - B = double (bernoulli (n)); - assert (A, B, -eps); -***** test - m = [0 1; 2 4]; - n = sym(m); - A = bernoulli (m); - B = double (bernoulli (n)); - assert (isequal (A, B)); -***** test - y = sym(19)/10; - n = sym(2); - x = 1.9; - m = 2; - A = bernoulli (m, x); - B = double (bernoulli (n, y)); - assert (A, B, -eps); -***** test - assert (isequal (bernoulli (4, inf), inf)) - assert (isequal (bernoulli (4, -inf), inf)) -***** xtest - % still broken? - assert (isequal (bernoulli (3, inf), inf)) - assert (isequal (bernoulli (3, -inf), -inf)) -***** test - assert (isnan (bernoulli(3, nan))) - assert (isnumeric (bernoulli(3, nan))) +[inst/@double/harmonic.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/harmonic.m +***** error harmonic (1, 2) ***** test - % maple, complex input - A = 34.21957245745810513 - 130.0046256649829101i; - B = bernoulli(7, 2.123 + 1.234i); - assert (A, B, -5*eps); + x = 1.1; + y = sym(11)/10; + A = harmonic (x); + B = double (harmonic (y)); + assert (A, B, -4*eps); ***** test - % x matrix, m scalar - y = [1 2 sym(pi); exp(sym(1)) 5 6]; - n = sym(2); + y = [2 3 sym(pi); exp(sym(1)) 5 6]; x = double (y); - m = 2; - A = bernoulli (m, x); - B = double (bernoulli (n, y)); - assert (A, B, -eps); -***** test - % m matrix, x scalar - m = [1 2 3; 4 5 6]; - n = sym(m); - y = sym(21)/10; - x = 2.1; - A = bernoulli (m, x); - B = double (bernoulli (n, y)); - assert (A, B, -3*eps); -15 tests, 15 passed, 0 known failure, 0 skipped + A = harmonic (x); + B = double (harmonic (y)); + assert (A, B, -4*eps); +3 tests, 3 passed, 0 known failure, 0 skipped [inst/@double/sinint.m] >>>>> /build/octave-symbolic-3.0.1/inst/@double/sinint.m ***** error sinint (1, 2) @@ -14310,72 +14995,54 @@ B = sinint (x); assert (A, B, -eps) 14 tests, 14 passed, 0 known failure, 0 skipped -[inst/@double/coshint.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/coshint.m -***** error coshint (1, 2) +[inst/@double/pochhammer.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/pochhammer.m +***** error pochhammer (1) +***** error pochhammer (1, 2, 3) +***** error pochhammer ([1 2], [1 2 3]) +***** error pochhammer ([1 2], [1; 2]) ***** test - x = 1.1; y = sym(11)/10; - A = coshint (x); - B = double (coshint (y)); - assert (A, B, -4*eps); -***** test - y = [2 3 sym(pi); exp(sym(1)) 5 6]; - x = double (y); - A = coshint (x); - B = double (coshint (y)); - assert (A, B, -4*eps); + t = sym(3); + x = 1.1; + s = 3; + A = pochhammer (x, s); + B = double (pochhammer (y, t)); + assert (A, B, -2*eps); ***** test - % maple: - % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; - % > for a in A do evalf(Chi(a)) end do; - x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; - A = [ 0.58447599687824767874 + 1.8682915044330306402*1i - -0.63131069034703116988 + 1.8986171211850702957*1i - 0.13577763724269399110e42 - -0.045456433004455372635 + 1.5707963267948966192*1i - -8.6330747070747332203 + 3.1315929868531280002*1i - 0.74701205140887966531e7 + 0.10381444259644068585e8*1i ]; - B = coshint (x); - assert (A, B, -eps) -***** assert (coshint (inf), inf) -***** assert (isinf (coshint (-inf))) -***** assert (imag (coshint (-inf)), pi) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@double/dilog.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@double/dilog.m + % maple + A = 256.798558090310131720; + B = pochhammer (18.1, 1.9); + assert (A, B, -20*eps) ***** test - x = 1.1; - y = sym(11)/10; - A = dilog (x); - B = double (dilog (y)); + % maple, complex inputs> + A = 2.67921619474318221972 + 1.96716724764630702653*1i; + B = pochhammer (12.1+3.1*i, 0.5+0.2i); assert (A, B, -4*eps); ***** test - y = [2 2 sym(pi); exp(sym(1)) 5 6]; + % maple, matrix inputs + A = [5.61467232547723663908 20.6144884613920190965]; + B = pochhammer ([0.9 0.8], [3.1 4.2]); + assert (A, B, -3*eps); +***** test + % x matrix, s scalar + y = [1 2 sym(pi); exp(sym(1)) 5 6]; + t = sym(2); x = double (y); - A = dilog (x); - B = double (dilog (y)); - assert (A, B, -eps); + s = 2; + A = pochhammer (s, x); + B = double (pochhammer (t, y)); + assert (A, B, -3*eps); ***** test - % maple: - % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; - % > for a in A do evalf(dilog(a)) end do; - x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; - A = [ -0.59248494924959145800 - 1.5760154034463234224*1i - -1.0549087538833908441 - 3.8759788000863368495*1i - -12.192421669033171348 - -2.9195729380904939394 - 3.9540920181102973073*1i - 1.6459519160623984119 - 0.00032335296277550987686*1i - -1.5445800511775466879 + 9.4256034277816069684*1i ]; - B = dilog (x); - assert (A, B, -eps) -***** xtest - % https://github.com/fredrik-johansson/mpmath/issues/473 - assert (isinf (dilog (inf))) -!!!!! known failure -assert (isinf (dilog (inf))) failed -***** assert (isnan (dilog (-inf))) -5 tests, 4 passed, 1 known failure, 0 skipped + % s matrix, x scalar + t = [1 2 sym(pi); exp(sym(1)) 5 6]; + y = sym(2); + s = double (t); + x = 2; + A = pochhammer (s, x); + B = double (pochhammer (t, y)); + assert (A, B, -5*eps); +10 tests, 10 passed, 0 known failure, 0 skipped [inst/@double/fresnels.m] >>>>> /build/octave-symbolic-3.0.1/inst/@double/fresnels.m ***** error fresnels (1, 2) @@ -14407,6 +15074,68 @@ ***** assert (fresnels (inf), 0.5) ***** assert (fresnels (-inf), -0.5) 6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@double/fresnelc.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/fresnelc.m +***** error fresnelc (1, 2) +***** test + x = 1.1; + y = sym(11)/10; + A = fresnelc (x); + B = double (fresnelc (y)); + assert (A, B, -4*eps); +***** test + y = [2 3 sym(pi); exp(sym(1)) 5 6]; + x = double (y); + A = fresnelc (x); + B = double (fresnelc (y)); + assert (A, B, -4*eps); +***** test + % maple: + % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; + % > for a in A do evalf(FresnelC(a)) end do; + x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; + A = [ 16.087871374125480424 - 36.225687992881650217*1i + 0.47688568479874574722e12 + 0.12213736710985573216e13*1i + 0.49999989867881789756 + 0.49989869420551572361*1i + -0.000099999999999999997535 + 0.99999999999999987665e-6*1i + 0.15391592966931193100e26 - 0.75738824160998910388e24*1i ]; + B = fresnelc (x); + assert (A, B, -eps) +***** assert (fresnelc (inf), 0.5) +***** assert (fresnelc (-inf), -0.5) +6 tests, 6 passed, 0 known failure, 0 skipped +[inst/@double/sinhint.m] +>>>>> /build/octave-symbolic-3.0.1/inst/@double/sinhint.m +***** error sinhint (1, 2) +***** test + x = 1.1; + y = sym(11)/10; + A = sinhint (x); + B = double (sinhint (y)); + assert (A, B, -4*eps); +***** test + y = [2 3 sym(pi); exp(sym(1)) 5 6]; + x = double (y); + A = sinhint (x); + B = double (sinhint (y)); + assert (A, B, -4*eps); +***** test + % maple: + % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I]; + % > for a in A do evalf(Shi(a)) end do; + x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; + A = [ 0.45769171128668800567 + 1.8332099215048436239*1i + 0.60888490416819746440 + 1.2482232175376056201*1i + 0.13577763724269399110e42 + 1.6583475942188740493*1i + -0.00010000000005553888891 + 0.10000000016666111119e-5*1i + -0.74701205140887967022e7 - 0.10381447401236722090e8*1i ]; + B = sinhint (x); + assert (A, B, -eps) +***** assert (sinhint (inf), inf) +***** assert (sinhint (-inf), -inf) +6 tests, 6 passed, 0 known failure, 0 skipped [inst/assumptions.m] >>>>> /build/octave-symbolic-3.0.1/inst/assumptions.m ***** test @@ -14496,157 +15225,25 @@ a = pycall_sympy__ ('return Symbol("a", real=False)'); assert (strcmp (assumptions (a), {'a: ~real'})) 13 tests, 13 passed, 0 known failure, 0 skipped -[inst/laguerreL.m] ->>>>> /build/octave-symbolic-3.0.1/inst/laguerreL.m -***** error laguerreL (1) -***** error laguerreL (1, 2, 3) -***** assert (isequal (laguerreL (0, rand), 1)) -***** test - x = rand; - assert (isequal (laguerreL (1, x), 1 - x)) -***** test - x=rand; - y1=laguerreL(2, x); - p2=[.5 -2 1]; - y2=polyval(p2,x); - assert(y1 - y2, 0, 10*eps); -***** test - x=rand; - y1=laguerreL(3, x); - p3=[-1/6 9/6 -18/6 1]; - y2=polyval(p3,x); - assert(y1 - y2, 0, 20*eps); -***** test - x=rand; - y1=laguerreL(4, x); - p4=[1/24 -16/24 72/24 -96/24 1]; - y2=polyval(p4,x); - assert(y1 - y2, 0, 30*eps) -***** error laguerreL(1.5, 10) -***** error laguerreL([0 1], [1 2 3]) -***** error laguerreL([0 1], [1; 2]) -***** test - % numerically stable implementation (in n) - L = laguerreL (10, 10); - Lex = 1763/63; - assert (L, Lex, -eps) - L = laguerreL (20, 10); - Lex = -177616901779/14849255421; % e.g., laguerreL(sym(20),10) - assert (L, Lex, -eps) -***** test - % vectorized x - L = laguerreL (2, [5 6 7]); - Lex = [3.5 7 11.5]; - assert (L, Lex, eps) -***** test - L = laguerreL (0, [4 5]); - assert (L, [1 1], eps) -***** test - % vector n - L = laguerreL ([0 1 2 3], [4 5 6 9]); - assert (L, [1 -4 7 -26], eps) -***** test - % vector n, scalar x - L = laguerreL ([0 1 2 3], 6); - assert (L, [1 -5 7 1], eps) -***** assert (isa (laguerreL (0, single (1)), 'single')) -***** assert (isa (laguerreL (1, single ([1 2])), 'single')) -***** assert (isa (laguerreL ([1 2], single ([1 2])), 'single')) -18 tests, 18 passed, 0 known failure, 0 skipped -[inst/octsympy_tests.m] ->>>>> /build/octave-symbolic-3.0.1/inst/octsympy_tests.m -***** assert(true) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/lambertw.m] ->>>>> /build/octave-symbolic-3.0.1/inst/lambertw.m -***** assert (isequal (lambertw (0), 0)) -***** assert (isequal (lambertw (0, 0), 0)) -***** assert (lambertw (-1/exp(1)), -1, 2*eps) -***** assert (lambertw (0, -1/exp(1)), -1, 2*eps) -***** assert (lambertw (-1, -1/exp(1)), -1, 2*eps) -***** test - x = [1 2 3 pi 10 100 1000 12345]; - W = lambertw (x); - assert (W.*exp (W), x, -3*eps) -***** test - x = [1 2 3 pi 10 100 1000 12345]; - k = [-3 -2 -1 0 1 2 3 4]; - W = lambertw (k, x); - assert (W.*exp (W), x, -10*eps) -***** test - % input shape preserved - x = [0 1; 2 3]; - b = x; - W = lambertw (b, x); - assert (W.*exp (W), x, -10*eps) -***** test - % input shape preserved - x = [0 1; 2 3]; - b = 0; - W = lambertw (b, x); - assert (W.*exp (W), x, -10*eps) -***** test - % input shape preserved - x = 10; - b = [0 1; 2 3]; - W = lambertw (b, x); - assert (W.*exp (W), x*ones (size (b)), -10*eps) -***** assert (isnan (lambertw (nan))) -***** test - % limiting behaviour as z large - k = 3; - A = lambertw (k, 1e100); - assert (abs (imag (A) - 2*pi*k) < 0.1) -***** test - % limiting behaviour as z large, up imag axis - k = 1; - A = lambertw (k, 1e100*1i); - assert (abs (imag (A) - (2*k+0.5)*pi) < 0.1) -***** test - % limiting behaviour as z large, down imag axis - k = -2; - A = lambertw (k, -1e100*1i); - assert (abs (imag (A) - (2*k-0.5)*pi) < 0.1) -***** test - % limiting behaviour as z large, near branch - k = 3; - A = lambertw (k, -1e100); - B = lambertw (k, -1e100 + 1i); - C = lambertw (k, -1e100 - 1i); - assert (abs (imag (A) - (2*k+1)*pi) < 0.1) - assert (abs (imag (B) - (2*k+1)*pi) < 0.1) - assert (abs (imag (C) - (2*k-1)*pi) < 0.1) -***** test - % infinities and nan - A = lambertw ([inf exp(1) -inf nan]); - B = [inf 1 inf + pi*1i nan]; - assert (isequaln (A, B)) -***** test - % infinities and nan - A = lambertw (3, [inf 1 -inf nan]); - B = [inf + 2*3*pi*1i lambertw(3,1) inf + (2*3+1)*pi*1i nan]; - assert (isequaln (A, B)) -***** test - % infinities and nan - A = lambertw ([0 1 2 0], [inf -inf nan exp(1)]); - B = [inf inf+3*pi*1i nan 1]; - assert (isequaln (A, B)) -***** test - % scalar infinity z, vector b - A = lambertw ([1 2 -3], inf); - B = [lambertw(1, inf) lambertw(2, inf) lambertw(-3, inf)]; - assert (isequal (A, B)) +[inst/fibonacci.m] +>>>>> /build/octave-symbolic-3.0.1/inst/fibonacci.m +***** assert (isequal ( fibonacci (sym(0)), 0)) +***** assert (isequal ( fibonacci (sym(14)), sym(377))) +***** assert (isequal ( fibonacci (14), 377)) +***** test syms x + assert (isequal (fibonacci (5,x), x^4 + 3*x^2 + 1)) +4 tests, 4 passed, 0 known failure, 0 skipped +[inst/cell2sym.m] +>>>>> /build/octave-symbolic-3.0.1/inst/cell2sym.m ***** test - % scalar -infinity z, vector b - A = lambertw ([1 2 -3], -inf); - B = [lambertw(1, -inf) lambertw(2, -inf) lambertw(-3, -inf)]; - assert (isequal (A, B)) + A = {1 2 3; 4 5 6}; + B = [1 2 3; 4 5 6]; + assert (isequal (cell2sym(A), sym(B))) ***** test - % scalar z nan, vector b - A = lambertw ([1 2 -3], nan); - B = [nan nan nan]; - assert (isequaln (A, B)) -21 tests, 21 passed, 0 known failure, 0 skipped + A = {'a' 'b'; 'c' 10}; + B = [sym('a') sym('b'); sym('c') sym(10)]; + assert (isequal (cell2sym(A), B)) +2 tests, 2 passed, 0 known failure, 0 skipped [inst/syms.m] >>>>> /build/octave-symbolic-3.0.1/inst/syms.m ***** test @@ -14705,839 +15302,281 @@ assert (~ isempty (assumptions (x))) assert (~ isempty (assumptions (argnames (f)))) 13 tests, 13 passed, 0 known failure, 0 skipped -[inst/assume.m] ->>>>> /build/octave-symbolic-3.0.1/inst/assume.m -***** error - a = assume('a', 'real') -***** error - assume positive integer -***** error - assume x y -***** error - assume x clear real -***** error - assume a>0 -***** error - assume 'x/pi' integer -***** test - syms x - assume x positive - a = assumptions(x); - assert(strcmp(a, 'x: positive')) - assume x even - a = assumptions(x); - assert(strcmp(a, 'x: even')) -***** test - % multiple assumptions - syms x - assume x positive integer - [tilde, a] = assumptions(x, 'dict'); - assert(a{1}.integer) - assert(a{1}.positive) -***** test - % does workspace - syms x positive - x2 = x; - f = sin(x); - assume x negative - a = assumptions(x); - assert(strcmp(a, 'x: negative')) - a = assumptions(x2); - assert(strcmp(a, 'x: negative')) - a = assumptions(f); - assert(strcmp(a, 'x: negative')) -***** error - % does not create new variable x - clear x - assume x real -***** error - % no explicit variable named x - clear x - f = 2*sym('x'); - assume x real -***** test - % clear does workspace - syms x positive - f = 2*x; - assume x clear - assert (isempty (assumptions (f))); - assert (isempty (assumptions ())); -***** test - syms x y - f = sin (2*x); - assume x y real - assert (strcmp (assumptions (x), 'x: real')) - assert (strcmp (assumptions (y), 'y: real')) - assert (strcmp (assumptions (f), 'x: real')) -***** test - syms x y - f = sin (2*x); - assume x y positive even - assert (strcmp (assumptions (x), 'x: positive, even') || strcmp (assumptions (x), 'x: even, positive')) - assert (strcmp (assumptions (y), 'y: positive, even') || strcmp (assumptions (y), 'y: even, positive')) - assert (strcmp (assumptions (f), 'x: positive, even') || strcmp (assumptions (f), 'x: even, positive')) -***** test - % works from variable names not symbols - syms x y - a = [x y]; - assume a real - assert (strcmp (assumptions (x), 'x: real')) - assert (strcmp (assumptions (y), 'y: real')) -***** test - % works from variable names not symbols - y = sym('x'); - f = 2*y; - assume y real - assert (strcmp (assumptions (f), 'x: real')) -***** test - % matrix of symbols - syms a b c d - A = [a b; c d]; - assume A real - assert (strcmp (assumptions (a), 'a: real')) - assert (strcmp (assumptions (b), 'b: real')) - assert (strcmp (assumptions (c), 'c: real')) - assert (strcmp (assumptions (d), 'd: real')) -***** test - % assume after symfun - clear x - syms f(x) - assume x real - assert (~ isempty (assumptions (formula (f)))) - assert (~ isempty (assumptions (argnames (f)))) -18 tests, 18 passed, 0 known failure, 0 skipped -[inst/vpasolve.m] ->>>>> /build/octave-symbolic-3.0.1/inst/vpasolve.m -***** test - syms x - vpi = vpa(sym(pi), 64); - e = tan(x/4) == 1; - q = vpasolve(e, x, 3.0); - w = q - vpi ; - assert (double(w) < 1e-30) -***** test - syms x - vpi = vpa(sym(pi), 64); - e = tan(x/4) == 1; - q = vpasolve(e, x); - w = q - vpi; - assert (double(w) < 1e-30) - q = vpasolve(e); - w = q - vpi; - assert (double(w) < 1e-30) -***** test - % very accurate pi - syms x - e = tan(x/4) == 1; - m = digits(256); - q = vpasolve(e, x, 3); - assert (double(abs(sin(q))) < 1e-256) - digits(m); -***** test - % very accurate sqrt 2 - syms x - e = x*x == 2; - m = digits(256); - q = vpasolve(e, x, 1.5); - assert (double(abs(q*q - 2)) < 1e-256) - digits(m); -***** test - % very accurate sqrt pi - % (used to fail https://github.com/sympy/sympy/issues/8564) - syms x - e = x*x == sym(pi); - m = digits(256); - q = vpasolve(e, x, 3); - assert (double(abs(sin(q*q))) < 1e-256) - digits(m); -***** test - syms x - r = vpasolve(x^2 + 2 == 0, x, 1i); - assert (double (imag(r)^2 - 2), 0, 1e-32) - assert (double (real(r)^2), 0, 1e-32) - r = vpasolve(x^2 + 2 == 0, x, -3i + 5); - assert (double (imag(r)^2 - 2), 0, 1e-32) - assert (double (real(r)^2), 0, 1e-32) -***** test - % system - syms x y - f = 3*x^2 - 2*y^2 - 1; - g = x^2 - 2*x + y^2 + 2*y - 8; - r = vpasolve([f; g], [x; y], sym([-1; 1])); - assert (isa (r, 'sym')) - assert (numel (r) == 2) -***** test - % system, double guess - syms x y - f = 3*x^2 - 2*y^2 - 1; - g = x^2 - 2*x + y^2 + 2*y - 8; - r = vpasolve([f; g], [x; y], [-1.1 1.2]); -***** test - % system, double guess - syms x y - f = 3*x^2 - 2*y^2 - 1; - g = x^2 - 2*x + y^2 + 2*y - 8; - r1 = vpasolve([f; g], [x; y], [-1.1]); - r2 = vpasolve([f; g], [x; y], [-1.1 -1.1]); - assert (isequal (r1, r2)) -***** test - % system, more eqns than unknowns - syms x y - eqns = [x^3 - x - y == 0; y*exp(x) == 16; log(y) + x == 4*log(sym(2))]; - r = vpasolve (eqns, [x; y], [1; 1]); - A = subs (lhs (eqns), [x; y], r); - err = A - [0; 16; 4*log(sym(2))]; - assert (double (err), zeros (size (err)), 1e-31) -10 tests, 10 passed, 0 known failure, 0 skipped -[inst/@logical/isAlways.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@logical/isAlways.m -***** error isAlways (true, false) -***** assert(isAlways(true)) -***** assert(~isAlways(false)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@symfun/power.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/power.m -***** test - syms x - f(x) = 2*x; - h = f.^f; - assert( isa(h, 'symfun')) - assert (isequal (formula (h), (2*x)^(2*x))) -***** test - syms x - f(x) = [x 2*x]; - h = f.^[x 3]; - assert( isa(h, 'symfun')) - assert (isequal (formula (h), [x^x 8*x^3])) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/rdivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/rdivide.m -***** test - syms x - f(x) = x^2; - assert( isa(f./f, 'symfun')) - assert( isa(f./[x x^2], 'symfun')) -***** test - syms x - f(x) = [x 2*x]; - h = f./[x 2]; - assert( isa(h, 'symfun')) - assert (isequal (formula (h), [1 x])) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/int.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/int.m -***** test - % indefinite integral of symfun gives symfun - syms x - f(x) = x^2; - g = int(f); - assert (isa(g, 'symfun')) - g = int(f, x); - assert (isa(g, 'symfun')) -***** test - % indefinite integral of abstract symfun gives symfun - syms f(x) - g = int(f); - assert (isa(g, 'symfun')) - g = int(f, x); - assert (isa(g, 'symfun')) -***** test - % definite integral does not give symfun - syms x - f(x) = x^2; - g = int(f, x, 0, 2); - assert (isa(g, 'sym')) - assert (~isa(g, 'symfun')) -***** test - % ... even if it has a variable in it - syms x t - f(x) = x; - g = int(f, x, 0, t); - assert (isa(g, 'sym')) - assert (~isa(g, 'symfun')) -***** test - % ... even if the input is abstract funcion - syms f(x) - g = int(f, x, 0, 2); - assert (isa(g, 'sym')) - assert (~isa(g, 'symfun')) -***** test - % symfun in x, integrated in y gives symfun still in x - % (SMT does this too). - syms f(x) y - g = int(f, y); - assert (isa (g, 'symfun')) - assert (isequal (argnames (g), x)) -***** test - % same as above, but concrete symfun - syms x y - f(x) = x^2; - g = int(f, y); - assert (isa (g, 'symfun')) - assert (isequal (argnames (g), x)) - assert (isequal (formula(g), x^2*y)) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@symfun/uminus.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/uminus.m -***** test - % Issue #447 - syms x - f(x) = x^2; - assert (isa (-f, 'symfun')) -***** test - syms f(x) - h = -f; - assert (isa (h, 'symfun')) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/mldivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mldivide.m -***** test - syms x - f(x) = x^2; - assert( isa(f\f, 'symfun')) - assert( isa(f\x, 'symfun')) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@symfun/minus.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/minus.m -***** test - syms x - f(x) = x^2; - assert( isa(f - f, 'symfun')) - assert( isa(f - x, 'symfun')) -***** test - % Octave bug #42735 fixed in 4.4.2 - syms x - f(x) = x^2; - g = x^2; - h = x - f; assert (isa (h, 'symfun') && isequal (formula (h), x - g)) - h = x + f; assert (isa (h, 'symfun') && isequal (formula (h), x + g)) - h = x * f; assert (isa (h, 'symfun') && isequal (formula (h), x * g)) - h = x / f; assert (isa (h, 'symfun') && isequal (formula (h), x / g)) - h = x ^ f; assert (isa (h, 'symfun') && isequal (formula (h), x ^ g)) - h = x .* f; assert (isa (h, 'symfun') && isequal (formula (h), x .* g)) - h = x ./ f; assert (isa (h, 'symfun') && isequal (formula (h), x ./ g)) - h = x .^ f; assert (isa (h, 'symfun') && isequal (formula (h), x .^ g)) -***** test - % different variables - syms x y - f(x) = 2*x; - g(y) = sin(y); - h = f - g(x); - assert( isa(h, 'symfun')) - assert( isequal (argnames (h), argnames (f))) - assert (isequal (formula (h), 2*x - sin(x))) - % and even if rh-sym has a dummy variable: - h = f - g(y); - assert( isa(h, 'symfun')) - assert( isequal (argnames (h), argnames(f))) - assert (isequal (formula (h), 2*x - sin(y))) -***** test - % different variables, f has more - syms x y - f(x,y) = 2*x*y; - g(y) = sin(y); - h = f - g(y) + g(x); - assert( isa(h, 'symfun')) - assert( isequal (argnames (h), argnames (f))) - assert (isequal (formula (h), 2*x*y - sin(y) + sin(x))) -4 tests, 4 passed, 0 known failure, 0 skipped -[inst/@symfun/symvar.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/symvar.m -***** test - % basic - syms f(t, s) - assert (isempty (symvar (f, 0))) - assert (isequal (symvar (f, 1), t)) - assert (isequal (symvar (f, 2), [t s])) - assert (isequal (symvar (f, 3), [t s])) -***** test - % note preference for vars of symfun, if n requested - syms x f(y) - assert (isequal (symvar(f*x, 1), y)) - assert (isequal (symvar(f(y)*x, 1), x)) -***** test - % symfun, checked smt - syms x f(y) - a = f*x; - b = f(y)*x; - assert (isequal (symvar(a), [x y])) - assert (isequal (symvar(b), [x y])) -***** test - % preference for the explicit variables - syms a x f(t, s) - h = f*a + x; - assert (isequal (symvar (h, 1), t)) - assert (isequal (symvar (h, 2), [t s])) - assert (isequal (symvar (h, 3), [t s x])) - assert (isequal (symvar (h, 4), [t s x a])) - assert (isequal (symvar (h, 5), [t s x a])) - assert (isequal (symvar (h), [a s t x])) -***** test - % symfun dep on some vars only, matches smt w/ n - syms x s t - f(s) = x; - g(s, t) = x*s; - assert (isequal (symvar(f, 1), s)) - assert (isequal (symvar(f, 2), [s x])) - assert (isequal (symvar(g, 1), s)) - assert (isequal (symvar(g, 2), [s t])) - assert (isequal (symvar(g, 3), [s t x])) -***** test - % A documented difference from SMT on symvar(symfun) w/o n - syms x s t - f(s) = x; - g(s, t) = x*s; - % SMT would have - %assert (isequal (symvar(f), x)) % no s - %assert (isequal (symvar(g), [s x])) % no t - assert (isequal (symvar(f), [s x])) - assert (isequal (symvar(g), [s t x])) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@symfun/argnames.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/argnames.m -***** test - % basic test - syms f(x) - assert (isequal (argnames (f), x)) -***** test - % Multiple variables, abstract symfun - syms f(t, x, y) - assert (isequal (argnames (f), [t x y])) -***** test - % Concrete symfun - syms x y z t - f(t, x, y) = x + y + z; - assert (isequal (argnames (f), [t x y])) +[inst/catalan.m] +>>>>> /build/octave-symbolic-3.0.1/inst/catalan.m +***** error catalan (sym(1)) +***** assert (double (catalan ()) > 0.915965594177) +***** assert (double (catalan ()) < 0.915965594178) 3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@symfun/isequaln.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/isequaln.m -***** error isequaln (symfun('x + 1', x)) -***** test - syms x y - f(x) = 2*x; - g(x) = 2*x; - assert (isequaln (f, g)) -***** test - syms x - f(x) = 2*x + 1; - g(x) = 2*x + 1; - h(x) = 2*x + 1; - assert (isequaln (f, g, h)) -***** test - syms x - f(x) = 2*x + 1; - g(x) = 2*x + 1; - h(x) = 2*x; - assert (~ isequaln (f, g, h)) -***** test - syms x y - f(x) = 2*x; - g(x, y) = 2*x; - assert (~ isequaln (f, g)) -***** test - syms x y - f(x) = symfun(nan, x); - g(x) = symfun(nan, x); - assert (isequaln (f, g)) -***** test - syms x y - f(x) = symfun(nan, x); - g(x, y) = symfun(nan, x); - assert (~ isequaln (f, g)) -7 tests, 7 passed, 0 known failure, 0 skipped -[inst/@symfun/diff.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/diff.m -***** test - % concrete fcn - syms x - f(x) = x*x; - g(x) = 2*x; - assert (logical (diff(f) == g)) - assert (isa (diff(f), 'symfun')) -***** test - % abstract fcn - syms y(x) - assert (logical (diff(y) == diff(y(x)))) - assert (isa (diff(y), 'symfun')) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/numel.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/numel.m -***** test - syms x - f(x) = x^2; - assert(numel(f)==1) -***** test - syms x - f(x) = [1 x]; - assert(numel(f)==1) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/mtimes.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mtimes.m -***** test - syms x - f(x) = x^2; - assert( isa(f * f, 'symfun')) - assert( isa(f * x, 'symfun')) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@symfun/plus.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/plus.m -***** test - syms x - f(x) = x^2; - assert( isa(f + f, 'symfun')) - assert( isa(f + x, 'symfun')) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@symfun/size.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/size.m -***** test - syms x - f(x) = x; - d = size(f); - assert (isequal (d, [1 1])) - [n, m] = size(f); - assert (isequal ([n m], [1 1])) - assert (size(f, 1) == 1) - assert (size(f, 2) == 1) -***** test - syms x - f(x) = [1 x]; - d = size(f); - assert (isequal (d, [1 1])) - [n, m] = size(f); - assert (isequal ([n m], [1 1])) - assert (size(f, 1) == 1) - assert (size(f, 2) == 1) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/symfun.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/symfun.m -***** error symfun (1, sym('x'), 3) -***** error symfun ('f', sym('x')) -***** test - syms x y - syms f(x) - assert(isa(f,'symfun')) - clear f - f(x,y) = sym('f(x,y)'); - assert(isa(f,'symfun')) -***** test - % symfuns are syms as well - syms x - f(x) = 2*x; - assert (isa (f, 'symfun')) - assert (isa (f, 'sym')) - assert (isequal (f(3), 6)) - assert (isequal (f(sin(x)), 2*sin(x))) +[inst/pycall_sympy__.m] +>>>>> /build/octave-symbolic-3.0.1/inst/pycall_sympy__.m ***** test - syms x y - f = symfun(sym('f(x)'), {x}); - assert(isa(f, 'symfun')) - f = symfun(sym('f(x,y)'), [x y]); - assert(isa(f, 'symfun')) - f = symfun(sym('f(x,y)'), {x y}); - assert(isa(f, 'symfun')) + % general test + x = 10; y = 6; + cmd = '(x,y) = _ins; return (x+y,x-y)'; + [a,b] = pycall_sympy__ (cmd, x, y); + assert (a == x + y && b == x - y) ***** test - % rhs is not sym - syms x - f = symfun(8, x); - assert (isa (f,'symfun')) - assert (isequal (f(10), sym(8))) + % bool + assert (pycall_sympy__ ('return True,')) + assert (~pycall_sympy__ ('return False,')) ***** test - % vector symfun - syms x y - F(x,y) = [1; 2*x; y; y*sin(x)]; - assert (isa (F, 'symfun')) - assert (isa (F, 'sym')) - assert (isequal (F(sym(pi)/2,4) , [sym(1); sym(pi); 4; 4] )) + % float + assert (abs(pycall_sympy__ ('return 1.0/3,') - 1/3) < 1e-15) ***** test - x = sym('x'); - y = sym('y'); - f(x) = sym('f(x)'); - g(x,y) = sym('g(x,y)'); - % make sure these don't fail - f(1); - g(1,2); - g(x,y); - diff(g, x); - diff(g, y); + % int + r = pycall_sympy__ ('return 123456'); + assert (r == 123456) + assert (isinteger (r)) ***** test - % defining 1D symfun in terms of a 2D symfun - syms x y t - syms 'g(x,y)' - f(t) = g(t,t); - f(5); - assert (length (argnames (f)) == 1) - assert (isequal (argnames (f), t)) - assert (isequal( formula(diff(f,x)), sym(0))) + % string + x = 'octave'; + cmd = 's = _ins[0]; return s.capitalize(),'; + y = pycall_sympy__ (cmd, x); + assert (strcmp(y, 'Octave')) ***** test - % replace g with shorter and specific fcn - syms x g(x) - g; - g(x) = 2*x; - assert( isequal (g(5), 10)) + % string with escaped newlines, comes back as escaped newlines + x = 'a string\nbroke off\nmy guitar\n'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) ***** test - % octave <= 3.8 needs quotes on 2D symfuns, so make sure it works - syms x y - syms 'f(x)' - syms 'g(x,y)' - assert (isa (f, 'symfun')) - assert (isa (g, 'symfun')) + % string with actual newlines, comes back as actual newlines + x = sprintf('a string\nbroke off\nmy guitar\n'); + y = pycall_sympy__ ('return _ins', x); + y2 = strrep(y, sprintf('\n'), sprintf('\r\n')); % windows + assert (strcmp(x, y) || strcmp(x, y2)) ***** test - % Bug #41: Octave <= 3.8 parser fails without quotes around 2D fcn - syms x y - eval('syms g(x,y)') - assert (isa (g, 'symfun')) + % cmd string with newlines, works with cell + y = pycall_sympy__ ('return "string\nbroke",'); + y2 = sprintf('string\nbroke'); + y3 = strrep(y2, sprintf('\n'), sprintf('\r\n')); % windows + assert (strcmp(y, y2) || strcmp(y, y3)) ***** test - % and these days it works without eval trick - syms g(x,y) - assert (isa (g, 'symfun')) + % string with XML escapes + x = '<> >< <<>>'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) + x = '&'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) ***** test - % syms f(x) without defining x - clear x - syms f(x) - assert(isa(f, 'symfun')) - assert(isa(x, 'sym')) + % strings with double quotes + x = 'a\"b\"c'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) + x = '\"'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) ***** test - % SMT compat: symfun indep var overwrites existing var - t = 6; - syms f(t) - assert (logical (t ~= 6)) + % cmd has double quotes, these must be escaped by user + % (of course: she is writing python code) + expy = 'a"b"c'; + y = pycall_sympy__ ('return "a\"b\"c",'); + assert (strcmp(y, expy)) ***** test - % SMT compat: symfun indep var overwrites existing var, even if sym - syms x - t = x; - syms f(t) - assert (~ logical (t == x)) + % strings with quotes + x = 'a''b'; % this is a single quote + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) ***** test - syms x y - f(x) = x^2; - g(x,y) = sym('g(x,y)'); - f2 = 2*f; - assert( isequal (f2(4), 32)) - assert( isa(f2, 'symfun')) - assert( isa(2*g, 'symfun')) - assert( isa(0*g, 'symfun')) % in SMT, this is the zero symfun + % strings with quotes + x = '\"a''b\"c''\"d'; + y = pycall_sympy__ ('return _ins[0]', x); + assert (strcmp(y, x)) ***** test - % syms has its own parsing code, check it works - syms f(x,y) - g = f; - syms f(x, y) - assert (isequal (f, g)) - syms 'f( x, y )' - assert (isequal (f, g)) + % strings with quotes + expy = '"a''b"c''"d'; + y = pycall_sympy__ ('s = "\"a''b\"c''\"d"; return s'); + assert (strcmp(y, expy)) ***** test - % syms own parsing code should not reorder the vars - syms f(y, x) - v = argnames (f); - assert (isequal (v(1), y) && isequal (v(2), x)) + % strings with printf escapes + x = '% %% %%% %%%% %s %g %%s'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) ***** test - % assignment of symfun to symfun, issue #189 - syms t - x(t) = 2*t; - y(t) = x; - assert (isa (y, 'symfun')) - y = symfun(x, t); - assert (isa (y, 'symfun')) - % others - y = x; - assert (isa (y, 'symfun')) - y(t) = x(t); - assert (isa (y, 'symfun')) + % cmd with printf escapes + x = '% %% %%% %%%% %s %g %%s'; + y = pycall_sympy__ (['return "' x '",']); + assert (strcmp(y, x)) ***** test - % assignment of generic symfun to symfun - syms t x(t) - y(t) = x; - assert (isa (y, 'symfun')) - y = symfun(x, t); - assert (isa (y, 'symfun')) -***** error - % Issue #444: invalid args - syms x - f(x, x) = 2*x; -***** error - % Issue #444: invalid args - syms x y - f(x, y, x) = x + y; -***** error - % Issue #444: invalid args - syms x y - f(x, y, x) = x + y; -***** error - % Issue #444: expression as arg - syms x - f(2*x) = 4*x; -25 tests, 25 passed, 0 known failure, 0 skipped -[inst/@symfun/isequal.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/isequal.m -***** error isequal (symfun('x + 1', x)) + % cmd w/ backslash and \n must be escaped by user + expy = 'a\b\\c\nd\'; + y = pycall_sympy__ ('return "a\\b\\\\c\\nd\\",'); + assert (strcmp(y, expy)) ***** test - syms x y - f(x) = 2*x; - g(x) = 2*x; - assert (isequal (f, g)) + % slashes + x = '/\\ // \\\\ \\/\\/\\'; + z = '/\ // \\ \/\/\'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) ***** test - syms x - f(x) = 2*x + 1; - g(x) = 2*x + 1; - h(x) = 2*x + 1; - assert (isequal (f, g, h)) + % slashes + z = '/\ // \\ \/\/\'; + y = pycall_sympy__ ('return "/\\ // \\\\ \\/\\/\\"'); + assert (strcmp(y, z)) ***** test - syms x - f(x) = 2*x + 1; - g(x) = 2*x + 1; - h(x) = 2*x; - assert (~ isequal (f, g, h)) + % strings with special chars + x = '!@#$^&* you!'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) + x = '~-_=+[{]}|;:,.?'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) +***** xtest + % string with backtick trouble for system -c (sysoneline) + x = '`'; + y = pycall_sympy__ ('return _ins', x); + assert (strcmp(y, x)) ***** test - syms x y - f(x) = 2*x; - g(x, y) = 2*x; - assert (~ isequal (f, g)) + % unicode + s1 = '我爱你'; + cmd = 'return u"\u6211\u7231\u4f60",'; + s2 = pycall_sympy__ (cmd); + assert (strcmp (s1, s2)) ***** test - syms x y - f(x) = symfun(nan, x); - g(x) = symfun(nan, x); - assert (~ isequal (f, g)) -6 tests, 6 passed, 0 known failure, 0 skipped -[inst/@symfun/subsref.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/subsref.m + % unicode with \x + s1 = '我'; + cmd = 'return b"\xe6\x88\x91".decode("utf-8")'; + s2 = pycall_sympy__ (cmd); + assert (strcmp (s1, s2)) ***** test - syms x - f(x) = x^2; - v = f.vars; - assert(iscell(v)) - assert(length(v)==1) - assert(isequal(v{1},x)) + % unicode with \x and some escaped backslashes + s1 = '\我\'; + cmd = 'return b"\\\xe6\x88\x91\\".decode("utf-8")'; + s2 = pycall_sympy__ (cmd); + assert (strcmp (s1, s2)) +***** xtest + % unicode passthru + s = '我爱你'; + s2 = pycall_sympy__ ('return _ins', s); + assert (strcmp (s, s2)) + s = '我爱你<>\&//\#%% %\我'; + s2 = pycall_sympy__ ('return _ins', s); + assert (strcmp (s, s2)) +***** xtest + % unicode w/ slashes, escapes + s = '我<>\&//\#%% %\我'; + s2 = pycall_sympy__ ('return "我<>\\&//\\#%% %\\我"'); + assert (strcmp (s, s2)) ***** test - %% pass through to sym properties - syms x - f(x) = x^2; - y = x^2; % not a symfun - assert(strcmp(f.flat, y.flat)) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/mrdivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mrdivide.m + % list, tuple + assert (isequal (pycall_sympy__ ('return [1,2,3],'), {1, 2, 3})) + assert (isequal (pycall_sympy__ ('return (4,5),'), {4, 5})) + assert (isequal (pycall_sympy__ ('return (6,),'), {6,})) + assert (isequal (pycall_sympy__ ('return [],'), {})) ***** test - syms x - f(x) = x^2; - assert( isa(f/f, 'symfun')) - assert( isa(f/x, 'symfun')) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@symfun/private_disp_name.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/private_disp_name.m + % dict + cmd = 'd = dict(); d["a"] = 6; d["b"] = 10; return d,'; + d = pycall_sympy__ (cmd); + assert (d.a == 6 && d.b == 10) ***** test - syms f(x) - s = private_disp_name(f, 'f'); - assert (strcmp (s, 'f(x)')) + r = pycall_sympy__ ('return 6'); + assert (isequal (r, 6)) ***** test - syms x y - g(y, x) = x + y; - s = private_disp_name(g, 'g'); - assert (strcmp (s, 'g(y, x)')) + r = pycall_sympy__ ('return "Hi"'); + assert (strcmp (r, 'Hi')) ***** test - syms f(x) - assert (isempty (private_disp_name(f, ''))) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/@symfun/times.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/times.m + % blank lines, lines with spaces + a = pycall_sympy__ ({ '', '', ' ', 'return 6', ' ', ''}); + assert (isequal (a, 6)) ***** test - syms x - f(x) = x^2; - assert( isa(f .* f, 'symfun')) - assert( isa(f .* x, 'symfun')) + % blank lines, strange comment lines + cmd = {'a = 1', '', '#', '', '# ', ' #', 'a = a + 2', ' #', 'return a'}; + a = pycall_sympy__ (cmd); + assert (isequal (a, 3)) ***** test - syms x - f(x) = [x 2*x]; - h = f.*[x 3]; - assert( isa(h, 'symfun')) - assert (isequal (formula (h), [x^2 6*x])) -2 tests, 2 passed, 0 known failure, 0 skipped -[inst/@symfun/ldivide.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/ldivide.m + % return empty string (was https://bugs.python.org/issue25270) + assert (isempty (pycall_sympy__ ('return ""'))) ***** test - syms x - f(x) = x^2; - assert( isa(f .\ f, 'symfun')) - assert( isa(f .\ x, 'symfun')) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@symfun/mpower.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/mpower.m + % return nothing (via an empty list) + % note distinct from 'return [],' + pycall_sympy__ ('return []') ***** test - syms x - f(x) = 2*x; - h = f^f; - assert( isa(h, 'symfun')) - assert (isequal (formula (h), (2*x)^(2*x))) - h = f^sym(2); - assert( isa(h, 'symfun')) - assert (isequal (formula (h), 4*x^2)) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/@symfun/formula.m] ->>>>> /build/octave-symbolic-3.0.1/inst/@symfun/formula.m + % return nothing (because no return command) + pycall_sympy__ ('dummy = 1') ***** test - % simple - syms x - f(x) = sin(x); - g = formula(f); - assert (isequal (g, sin(x))); + % return nothing (because no command) + pycall_sympy__ ('') ***** test - % concrete: return is a sym, not a symfun - syms x - f(x) = sin(x); - g = formula(f); - assert (~isa(g, 'symfun')); + % return nothing (because no command) + pycall_sympy__ ({}) +***** error + % python exception while passing variables to python + % This tests the "INTERNAL_PYTHON_ERROR" path. + % FIXME: this is a very specialized test, relies on internal octsympy + % implementation details, and may need to be adjusted for changes. + disp('') + disp('**********************************************************************') + disp('') + disp(' Some deliberate AttributeError and ValueError may appear next') + disp('') + disp('v v v v v v v v v v v v v v v v v v v v v v v v') + b = sym([], 'S.This_is_supposed_to_make_an_exception', [1 1], 'Test', 'Test', 'Test'); + c = b + 1; + +********************************************************************** + + Some deliberate AttributeError and ValueError may appear next + +v v v v v v v v v v v v v v v v v v v v v v v v +Traceback (most recent call last): + File "", line 4, in + File "/usr/lib/python3/dist-packages/sympy/core/singleton.py", line 119, in __getattr__ + raise AttributeError( +AttributeError: Attribute 'This_is_supposed_to_make_an_exception' was not installed on SymPy registry S ***** test - % abstract: return is a sym, not a symfun - syms f(x) - g = formula(f); - assert (~isa(g, 'symfun')); -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/digits.m] ->>>>> /build/octave-symbolic-3.0.1/inst/digits.m + % ...and after the above test, the pipe should still work + a = pycall_sympy__ ('return _ins[0]*2', 3); + assert (isequal (a, 6)) ***** test - orig = digits(32); % to reset later - m = digits(64); - p = vpa(sym(pi)); - assert (abs (double (sin(p))) < 1e-64) - n = digits(m); - assert (n == 64) - p = vpa(sym(pi)); - assert (abs (double (sin(p))) < 1e-32) - assert (abs (double (sin(p))) > 1e-40) - digits(orig) -1 test, 1 passed, 0 known failure, 0 skipped -[inst/catalan.m] ->>>>> /build/octave-symbolic-3.0.1/inst/catalan.m -***** error catalan (sym(1)) -***** assert (double (catalan ()) > 0.915965594177) -***** assert (double (catalan ()) < 0.915965594178) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/finiteset.m] ->>>>> /build/octave-symbolic-3.0.1/inst/finiteset.m + % This command does not fail with native interface and '@pyobject' + s = warning ('off', 'OctSymPy:pythonic_no_convert'); + try + q = pycall_sympy__ ({'return type(int)'}); + catch + msg = lasterror.message; + assert (~ isempty (regexp (msg, '.*does not know how to.*'))) + end + warning (s) + disp('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^') + disp(' End of deliberate errors!') + disp(' You should see "46/46" or "Passes 46 out of 46 tests" below') + disp('**********************************************************************') + % ...and after the above test, the pipe should still work + a = pycall_sympy__ ('return _ins[0]*2', 3); + assert (isequal (a, 6)) +Traceback (most recent call last): + File "", line 2, in + File "", line 12, in octoutput_drv + File "", line 96, in octoutput +ValueError: octoutput does not know how to export type +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + End of deliberate errors! + You should see "46/46" or "Passes 46 out of 46 tests" below +********************************************************************** ***** test - s1 = finiteset(sym(1), 2, 2); - s2 = finiteset(sym(1), 2, 2, 2); - assert (isequal (s1, s2)) + % complex input + [A, B] = pycall_sympy__ ('z = 2*_ins[0]; return (z.real,z.imag)', 3+4i); + assert (A, 6) + assert (B, 8) ***** test - s1 = finiteset(sym(0), 1); - s2 = finiteset(sym(0), 2, 3); - s = finiteset(sym(0), 1, 2, 3); - assert (isequal (s1 + s2, s)) + % complex output + z = pycall_sympy__ ('return 3+2j'); + assert (z, 3+2i) +***** error + s = char ('abc', 'defgh', '12345'); + r = pycall_sympy__ ('return _ins[0]', s); ***** test - e = finiteset(); - s = finiteset(sym(1)); - s2 = e + s; - assert (isequal (s, s2)) -3 tests, 3 passed, 0 known failure, 0 skipped -[inst/cell2sym.m] ->>>>> /build/octave-symbolic-3.0.1/inst/cell2sym.m + r = pycall_sympy__ ('return len(_ins[0])', ''); + assert (r == 0) ***** test - A = {1 2 3; 4 5 6}; - B = [1 2 3; 4 5 6]; - assert (isequal (cell2sym(A), sym(B))) + % ensure the 0x0 matrix in octave gets mapped to the empty list in python + % @sym/subsasgn currently replies on this behaviour + assert (pycall_sympy__ ('return _ins[0] == []', [])); ***** test - A = {'a' 'b'; 'c' 10}; - B = [sym('a') sym('b'); sym('c') sym(10)]; - assert (isequal (cell2sym(A), B)) -2 tests, 2 passed, 0 known failure, 0 skipped + % ensure the empty string gets mapped to the empty string in python + assert (pycall_sympy__ ('return _ins[0] == ""', '')); +46 tests, 46 passed, 0 known failure, 0 skipped Checking C++ files ... Summary: 2386 tests, 2357 passed, 29 known failures, 0 skipped @@ -15565,12 +15604,14 @@ dpkg-buildpackage: info: binary-only upload (no source included) dpkg-genchanges: info: not including original source code in upload I: copying local configuration +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/B01_cleanup starting +I: user script /srv/workspace/pbuilder/11944/tmp/hooks/B01_cleanup finished I: unmounting dev/ptmx filesystem I: unmounting dev/pts filesystem I: unmounting dev/shm filesystem I: unmounting proc filesystem I: unmounting sys filesystem I: cleaning the build env -I: removing directory /srv/workspace/pbuilder/16123 and its subdirectories -I: Current time: Thu Jun 8 10:17:37 -12 2023 -I: pbuilder-time-stamp: 1686262657 +I: removing directory /srv/workspace/pbuilder/11944 and its subdirectories +I: Current time: Fri Jun 9 13:13:11 +14 2023 +I: pbuilder-time-stamp: 1686265991