-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #869 from vitrun/add-ComplexExpand
Implement ComplexExpand
- Loading branch information
Showing
3 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
""" | ||
Mathics3 builtins from mathics.core.numbers.hyperbolic | ||
""" | ||
from sympy import Symbol as SympySymbol | ||
|
||
from mathics.core.convert.sympy import from_sympy | ||
|
||
|
||
def eval_ComplexExpand(expr, vars): | ||
sympy_expr = expr.to_sympy() | ||
# Turn Re[x] -> x and remove Im[x] for all variables X that are not in vars. | ||
sympy_vars = {v.to_sympy() for v in vars.elements} | ||
# All vars are assumed to be real | ||
replaces = [ | ||
(fs, SympySymbol(fs.name, real=True)) | ||
for fs in sympy_expr.free_symbols | ||
if fs not in sympy_vars | ||
] | ||
sympy_expr = sympy_expr.subs(replaces) | ||
return from_sympy(sympy_expr.expand(complex=True)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters