-
-
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 #873 from Mathics3/add-ComplexExpand
Add complex expand
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
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() | ||
if hasattr(vars, "elements"): | ||
sympy_vars = {v.to_sympy() for v in vars.elements} | ||
else: | ||
sympy_vars = {vars.to_sympy()} | ||
# 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