Skip to content

Wrap Maxima's demoivre and exponentialize #10038

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

Closed
qed777 mannequin opened this issue Sep 30, 2010 · 27 comments
Closed

Wrap Maxima's demoivre and exponentialize #10038

qed777 mannequin opened this issue Sep 30, 2010 · 27 comments

Comments

@qed777
Copy link
Mannequin

qed777 mannequin commented Sep 30, 2010

Sage does not appear to have easily accesible analogues of Mathematica's TrigToExp and ExpToTrig. From AskSage:

sage: x = var('x')
sage: t1 = cos(x)
sage: t2 = e^(I * x) / 2 / I - e^(-I * x) / 2 / I
sage: sageobj(t1._maxima_().exponentialize())
1/2*e^(-I*x) + 1/2*e^(I*x)
sage: sageobj(t2._maxima_().demoivre())
sin(x)

CC: @kcrisman @sagetrac-fmaltey @slel

Component: symbolics

Keywords: expression tree

Author: Emmanuel Charpentier

Branch/Commit: e913bee

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/10038

@qed777 qed777 mannequin added c: symbolics labels Sep 30, 2010
@qed777 qed777 mannequin assigned burcin Sep 30, 2010
@burcin
Copy link
Contributor

burcin commented Oct 1, 2010

comment:1

You can use maxima_methods() to access the maxima functions easily.

sage: x = var('x')
sage: t1 = cos(x)
sage: t2 = e^(I * x) / 2 / I - e^(-I * x) / 2 / I
sage: res = t1.maxima_methods().exponentialize(); res
1/2*e^(-I*x) + 1/2*e^(I*x)
sage: type(res)
<type 'sage.symbolic.expression.Expression'>
sage: t2.maxima_methods().demoivre()
sin(x)

I am very much against wrapping each maxima function for manipulating symbolic expressions individually from Sage. Even though maxima provides a lot of functionality, their user interface is far from intuitive.

IMHO, the user interface to these functions should be something like:

sage: t1.rewrite(exp)
1/2*e^(-I*x) + 1/2*e^(I*x)
sage: t2.rewrite(sin)
sin(x)

BTW, it would be great if we could think about how to provide basic functionality like this directly in Sage without relying on maxima. It's possible that this requires wrapping more of pynac's features, for example

but it's well worth the effort.

@kcrisman
Copy link
Member

kcrisman commented Oct 1, 2010

comment:2

Replying to @burcin:

You can use maxima_methods() to access the maxima functions easily.

Yes, thanks for that reminder!

I am very much against wrapping each maxima function for manipulating symbolic expressions individually from Sage. Even though maxima provides a lot of functionality, their user interface is far from intuitive.

I don't see why we can't provide a more intuitive user interface for some of them, though. Just because a ticket is opened doesn't mean it will ever be fulfilled, but at least it's here now if enough people want it.

IMHO, the user interface to these functions should be something like:

sage: t1.rewrite(exp)
1/2*e^(-I*x) + 1/2*e^(I*x)
sage: t2.rewrite(sin)
sin(x)

This seems awkward, esp. if you don't know ahead of time whether it's sin or cos. I think that simplify_* makes sense, the way we have it now. For now it's not worth having the discussion - I doubt anyone has time to do this right now. But if someone does, maybe it's time to revisit that.

BTW, it would be great if we could think about how to provide basic functionality like this directly in Sage without relying on

Yes, of course. If only we could have that Sage Days solely about symbolics...

but it's well worth the effort.

@kcrisman kcrisman added this to the sage-4.6.1 milestone Oct 1, 2010
@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@slel
Copy link
Member

slel commented Aug 5, 2021

Changed keywords from none to expression tree

@slel
Copy link
Member

slel commented Aug 5, 2021

comment:7

Replying to @burcin:

BTW, it would be great if we could think about how to provide basic functionality like this directly in Sage without relying on maxima. It's possible that this requires wrapping more of pynac's features, for example

but it's well worth the effort.

The links seem to have slightly changed:

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 12, 2021

Branch: u/charpent/dm2

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 12, 2021

comment:9

Replying to @EmmanuelCharpentier:

Eleven years later, it seems obvious that no one ever undertook to wrap Pynac's tree traversal utilities. However, the expressionTreeWalker class offers means to implement such utilities not too painfully.

This proposal passes ptestlong with no new failures.

==>needs_review


New commits:

22d0354de Moivre/exponentialize methods for symbolic expressions (Sage)

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 12, 2021

Commit: 22d0354

@EmmanuelCharpentier EmmanuelCharpentier mannequin modified the milestones: sage-6.4, sage-9.5 Aug 12, 2021
@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 17, 2021

comment:10

Wups. A nice typo : _init__ for __init__...

==> needs_work.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 17, 2021

Changed commit from 22d0354 to 43bce84

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 17, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

43bce84Exponentialize : typo.

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 17, 2021

comment:12

Typo fixed ==>needs_review.

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 17, 2021

Author: Emmanuel Charpentier

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 18, 2021

comment:14

One doctest (src/sage/doctest/sources.py) fails.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

7810b80deMoivre : reformatting doctests.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

Changed commit from 43bce84 to 7810b80

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 18, 2021

comment:16

New patchbot attempt ==>needs_review

@tscrim
Copy link
Collaborator

tscrim commented Aug 23, 2021

comment:17

A few little things:

It would be good to use Sage's doc conventions:

-        """Returns this sumbolic expression with all circular and hyperbolic
+        """
+        Return this sumbolic expression with all circular and hyperbolic
         functions replaced by their respective exponential
         expressions.

Exponentialize.__init__ is missing a doctest.

The import here

    def demoivre(self, force=False):
        from sage.symbolic.expression_conversions import DeMoivre
        """

should go after the docstring (which probably is not being picked up as a docstring but instead just a string being created within the function).

-return op(*[self(_) for _ in ex.operands()])
+return op(*[self(oper) for oper in ex.operands()])

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 23, 2021

Changed commit from 7810b80 to 518361f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 23, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

518361fde Moivre/exponentialize : documentation fixes, code streamlining.

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 23, 2021

comment:20

Replying to @sagetrac-git:

Branch pushed to git repo; I updated commit sha1. New commits:

518361fde Moivre/exponentialize : documentation fixes, code streamlining.

Fixed doctests pass. setting needs_review to start the patchbots.

@tscrim
Copy link
Collaborator

tscrim commented Aug 25, 2021

Changed commit from 518361f to e913bee

@tscrim
Copy link
Collaborator

tscrim commented Aug 25, 2021

comment:21

I did a few more reviewer changes. If my changes are good, then positive review.


New commits:

751776bMerge branch 'u/charpent/dm2' of git://trac.sagemath.org/sage into u/tscrim/demoivre_exp-10038
e913beeTrac #10038: reviewer changes.

@tscrim
Copy link
Collaborator

tscrim commented Aug 25, 2021

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Aug 25, 2021

Changed branch from u/charpent/dm2 to u/tscrim/demoivre_exp-10038

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Aug 25, 2021

comment:22

Thanks !

Okay with your cosmetics (notwithstanding the fact that I do not grasp their rationale) ==> positive_review.

@tscrim
Copy link
Collaborator

tscrim commented Aug 25, 2021

comment:23

Thank you.

Most of them are formatting corrections, so after a :: is needed to be indented (which becomes code) and the corresponding text needs to be at the base level. If something is followed by text, then it should be a single colon :. Convention says we should start docstrings with Return not Returns, and a few other small tweaks for that and PEP8.

@vbraun
Copy link
Member

vbraun commented Aug 31, 2021

Changed branch from u/tscrim/demoivre_exp-10038 to e913bee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants