Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fluent interface #1

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
inst/jython/Lib/distutils/command/wininst-.*\.exe
sympy-0.7.6.1.tar.gz
.gitignore
.gitattributes
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configure.win text eol=lf
configure text eol=lf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sympy-0.7.6.1.tar.gz
inst/Lib
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Package: rSymPy
Version: 0.2-1.1
Date: 2010-07-31
Version: 0.3-1
Date: 2015-11-06
Title: R interface to SymPy computer algebra system
Author: G Grothendieck (SymPy itself is by Ondrej Certik and others),
Kevin Jin,
Contributors: Carlos J. Gil Bellosta
Maintainer: G Grothendieck <[email protected]>
Description: Access SymPy computer algebra system from R via Jython
Depends: rJython
Depends: PythonInR, R.methodsS3
License: GPL
URL: http://rsympy.googlecode.com
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default NAMESPACE created by R
# Remove the previous line if you edit this file

# Export all names
exportPattern(".")

# Import all packages listed as Imports or Depends
import(
PythonInR,
R.methodsS3
)
64 changes: 64 additions & 0 deletions R/Sym.GroupGenericFuncs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# methods

# Ops.Sym group generic overrides
Ops.Sym <- function (e1, e2) if (missing(e2)) Sym(.Generic, e1) else Sym(e1, .Generic, e2)
`^.Sym` <- function(e1, e2) if (missing(e2)) Sym("**", e1) else Sym(e1, "**", e2)
`%%.Sym` <- function(e1, e2) if (missing(e2)) Sym("mod(", e1, ")") else Sym("Mod(", e1, ",", e2, ")")
`%/%.Sym` <- function(e1, e2) if (missing(e2)) trunc(Sym("/", e1)) else trunc(Sym(e1, "/", e2)) # "//" doesn't work
`!.Sym` <- function(e1, e2) if (missing(e2)) Sym("~", e1) else Sym(e1, "~", e2)
# Safer: `&` => And(), `|` => Or(), `!` => Not(), `==` => Eq(), `!=` => Ne(),
# `<` => Lt(), `<=` => Le(), `>=` => Ge(), `>` => Gt()


# Math.Sym group generic overrides
transtab <- rbind(
c("Abs", NA, "abs"),
c("lgamma", NA, "loggamma")
)
Math.Sym <- function(x, ...) {
idx <- match(.Generic, transtab[,1], nomatch = 0)
fn <- if (idx > 0) transtab[idx, 3] else .Generic
Sym(fn, "(", x, ")")
}
# TODO: this evaluates the passed expression three times. Very inefficient
trunc.Sym <- function(x) Sym("Piecewise((floor(", x, "),", x, ">= 0), (ceiling(", x, "), True))")
round.Sym <- function(x, digits = 0) Sym("round(", x, ",", digits, ")")
signif.Sym <- function(x, digits = 6) Sym("round(", x, ",", digits, "- (floor(log(", x, ", 10)) + 1))")
expm1.Sym <- function(x) Sym("exp(", x, ") - 1")
log1p.Sym <- function(x) Sym("log(1 +", x, ")")
cospi.Sym <- function(x) Sym("cos(", x, " * pi)")
sinpi.Sym <- function(x) Sym("sin(", x, " * pi)")
tanpi.Sym <- function(x) Sym("tan(", x, " * pi)")
cumsum.Sym <- function(x) stop(paste(match.call()[[1]], "() not implemented", sep = ""))
cumprod.Sym <- function(x) stop(paste(match.call()[[1]], "() not implemented", sep = ""))
cummax.Sym <- function(x) stop(paste(match.call()[[1]], "() not implemented", sep = ""))
cummin.Sym <- function(x) stop(paste(match.call()[[1]], "() not implemented", sep = ""))


# Summary.Sym group generic overrides
all.Sym <- function(x) stop(paste(match.call()[[1]], "() not implemented", sep = ""))
any.Sym <- function(x) stop(paste(match.call()[[1]], "() not implemented", sep = ""))
sum.Sym <- function(x, lower, upper, name = coalesce(sympySymbols(x), "x"), ...) {
if (!is.numeric(lower) || !is.numeric(upper))
stop("lower and upper must both be specified")

# TODO: use named arguments ... to plug into other variables as constants
Sym("Sum(", x, ",(", name[1], ",", lower[1], ",", upper[1], ")).doit()")
}
prod.Sym <- function(x, lower, upper, name = coalesce(sympySymbols(x), "x"), ...) {
if (!is.numeric(lower) || !is.numeric(upper))
stop("lower and upper must both be specified")

# TODO: use named arguments ... to plug into other variables as constants
Sym("Product(", x, ",(", name[1], ",", lower[1], ",", upper[1], ")).doit()")
}
min.Sym <- function(..., na.rm = FALSE) Sym("Min(", paste(..., sep = ","), ")")
max.Sym <- function(..., na.rm = FALSE) Sym("Max(", paste(..., sep = ","), ")")
range.Sym <- function(x) stop(paste(match.call()[[1]], "() not implemented", sep = ""))

# Complex.Sym group generic overrides
Arg.Sym <- function(x) Sym("arg(", x, ")")
Conj.Sym <- function(x) Sym("conjugate(", x, ")")
Im.Sym <- function(x) Sym("im(", x, ")")
Mod.Sym <- function(x) abs(x)
Re.Sym <- function(x) Sym("re(", x, ")")
Loading