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

Conversation

Kevin-Jin
Copy link

  • Bump to SymPy 0.7.6.1 and replace rJython with PythonInR. SymPy is downloaded automatically so that build is not dependent on developer's environment.
  • Renamed Integrate() and Limit() to integrate() and limit() and updated some function signatures for consistency with R's standard math functions.
  • Implemented all functions/operators in Math, Ops, Summary, Complex generic groups in terms of SymPy or Python functions except for cumsum(), cumprod(), cummax(), cummin(), all(), any(), and range().
  • Sym methods derive(), integrate(), limit(), sum(), prod(), eval(), and as.function() automatically choose dummy variable in the trivial case.
  • Add numerical computation capabilities.

Examples of improvements:

  • "z <- 3; as.Sym(x + y + z)" is equivalent to "Var('x') + Var('y') + 3".
  • "z <- 3; as.function(as.Sym(x + y + z))(x = 2, y = 3)"
  • "z <- 3; eval(as.Sym(x + y + z), envir = list(x = 2, y = 3))"
  • "eval(as.Sym(deriv(x ^ 2)), envir = list(x = 5))"

Use PythonInR instead of Jython to support Python 3.x for SymPy 0.7.6.
Update kopy.bat script for my development PC.
Accept NULL rather than "NULL" for retclass in Var() and sympy() functions.
Fix inconsistent whitespace.
Write configure and configure.win shell scripts to download SymPy 0.7.6.1 tarball from GitHub and extract it to inst/Lib.
Delete development PC specific kopy.bat.
Make base integrate() function a generic function and have an implementation for Sym objects.
Make a new generic function limit().
Var(), List(), Matrix(), Zero(), Eye(), and Zeros() grouped together as static factories.
Ensure all functions in Math, Ops, Summary, and Complex generic groups are handled by Sym class.
Add exception throwing stubs for vector and boolean related R math functions.
Implement smarter deriv(), limit(), and integrate() functions that by default grabs the first (alphabetically) variable in the expression as the name of the variable to operate on.
Simplify usage of integrate() function. Signature mimics stats integrate() function. Takes in optional lower and upper bounds and follows SymPy syntax to create definite or indefinite integrals.
Expressions from SymPy can now be numerically computed.
Overrides eval() and as.function() generic functions respectively.
Fix typos in limit() and deriv() for sympySymbols().
Support differentiation, integration, evaluation, and limit of Syms without any variables (i.e. unevaluated constants).
Add stubs for parsing MathML expressions into native R.
Fix sympySymbols() to ignore dummy variables in e.g. summations, products, integrals.
Fix eval.Sym() not simplifying any summations, products, integrals when there are no free symbols remaining.
Eliminate need to manually call Var() on all undeclared symbols. E.g. if x and y are not defined in the current scope and z == 5, then as.Sym(x + deriv(y) + z) is equivalent to (Var('x') + deriv(Var('y')) + 5).
The lambda returned by as.function.Sym() no longer provides defaults for formal arguments.
Fix logical error in as.function.Sym() when x requires no variables.
Add myself to authors.
Do not import mpmath because its diff() function overwrites SymPy's.
Fix problems when passing in just a single variable name to as.Sym(), without any function calls or operations.
Fix overwriting of variables already declared in Python but not in R. If both R and Python variables exist, the R variable has precedence. Only when a variable does not exist in both R and Python do we call var('x') in Python.
Fix passing of Inf and NaN to SymPy.
Any functions that are not recognized in R are passed through to Python with the function name intact.
Ensure that as.Sym() wraps even constant expressions with the Sym class.
sum.Sym() and prod.Sym() simplify the sums and products. deriv.Sym(), limit.Sym(), and integrate.Sym() updated to use a similar form.
Implement variable assignment in as.Sym().
Implement named arguments in wrapped functions in as.Sym().
Fix as.Sym() improperly wrapping functions with multiple arguments.
Fix as.Sym() improperly wrapping string constants.
Use .onLoad() and .onUnload() hooks instead of calls to an initialization function in all functions in sympy.R.
Add code stubs for future features.
as.Sym() converts R objects of class complex, Date, datediff, POSIXlt, POSIXct into the equivalent Python objects.
as.Sym() converts R keyword literals NULL, NA, TRUE, FALSE into the equivalent Python keyword literals.
as.Sym() no longer fails if calling a Python function that takes no arguments.
pyGet() converts Python objects of the class complex, date, timedelta, datetime, and time into the equivalent R objects.
pyGet() converts Python lists by recursive calls to pyGet() and simplifies mixed int/double lists into numeric vectors.
E.g. simple R functions such as `identity` are expanded to Sym("lambda x: x") rather than Sym("function(x) x").
Use deparse() instead of as.character(). Syntax such as `a(b)(c)` - i.e. `a(b)` evaluates to a function that takes in the argument `c` - was being converted into string vectors rather than the expected Sym("a(b)", "(", "c", ")").
pythonHasVariable() checks if a variable is defined in Python's __builtin__ module.
Move most of the pass-through function processing logic to two other functions defined within as.Sym().
Reuse some of the R to Python object translation logic for the lambda body processing logic.
Within the scope of the as.Sym() argument, provide functions pl() for creating Python tuples and as.pl() for converting lists to tuples.
Within the scope of the as.Sym() argument, provide function .() for escaping the first symbol within its argument as a Python variable or call, e.g. .(print(x)) will force the translator to not execute print() in R but may still resolve `x` in R. Also prevents the translator from interpreting R keywords, e.g. .(FALSE) will translate to a reference to a Python variable named FALSE rather than to the equivalent constant False.
Translate any resolved R data.frames, arrays, matrices, lists, or vectors into row-major jagged lists in Python.
Translate default values of lambda formals to Python. Append equals sign and default value to formal parameter name if there is a default value.
Fix usages of formal parameters in function calls inside a lambda e.g. `function(x) type(x)` failing to be resolved.
Fix formal parameters being expanded if they share the same name as a function handle in an ancestor scope e.g. `function(identity) identity(2)`. Local variables of a function, including formal parameters, should hide global variables.
Fix outer formal parameters not being resolved in nested lambdas e.g. translator won't resolve usage of `x` in `function(x) function(y) type(x, y)`.
Pass-through function processing evaluates functions called on a function.
Pass-through and lambda function processing convert instances of Sym("f()")() to Sym("f()()") to fix "attempt to apply non-function" errors.
`$` in R is equivalent to `.` in Python.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant