Skip to content

Implemented Infty::pow and Infty::rpow functions#1160

Merged
isuruf merged 4 commits intosymengine:masterfrom
ShikharJ:InftyClass
Jan 6, 2017
Merged

Implemented Infty::pow and Infty::rpow functions#1160
isuruf merged 4 commits intosymengine:masterfrom
ShikharJ:InftyClass

Conversation

@ShikharJ
Copy link
Copy Markdown
Member

As always, please review and suggest changes.

@certik
Copy link
Copy Markdown
Contributor

certik commented Dec 19, 2016

Thanks for implementing these. Please do not forget to also add some tests.

@ShikharJ
Copy link
Copy Markdown
Member Author

ping @isuruf

RCP<const Number> Infty::rpow(const Number &other) const
{
return zero;
if (is_a<Infty>(other)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpow doesn't need this case, it is handled in pow

REQUIRE(n1->__str__() == "zoo");
n1 = b->rpow(*a);
REQUIRE(eq(*n1, *zero));
n1 = b->rpow(*c);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use rpow directly. Use c->rpow(*b)

@ShikharJ ShikharJ force-pushed the InftyClass branch 2 times, most recently from de1ec99 to 3404ba5 Compare December 31, 2016 07:17
@ShikharJ ShikharJ changed the title [WIP] Implemented Infty::pow and Infty::rpow functions Implemented Infty::pow and Infty::rpow functions Dec 31, 2016
@ShikharJ
Copy link
Copy Markdown
Member Author

ShikharJ commented Jan 1, 2017

@isuruf @certik The changes have been made. Please review and suggest improvements.

{
return zero;
if (is_a<Infty>(other)) {
return other.pow(*this);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not need this at all, since rpow is not directly called.

throw SymEngineException("Indeterminate Expression: `0 ** +- "
"unsigned Infty` encountered");
} else {
const RealDouble &s = static_cast<const RealDouble &>(other);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you know that other is a RealDouble?

Copy link
Copy Markdown
Member Author

@ShikharJ ShikharJ Jan 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I wanted to down-cast the value held by the object into a double and compare with 1. But using 'down_cast()' is raising an error. I'll look for other workarounds.

RCP<const Infty> c = ComplexInf;

RCP<const Number> n1;
n1 = a->rpow(*integer(10));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't call rpow directly

throw SymEngineException("Indeterminate Expression: `1 ** +- "
"unsigned Infty` encountered");
} else if (is_positive_infinity()) {
if (other.compare(*one) == -1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comparison is not mathematical, but structural. check whether other - 1 is positive or zero or negative.

RCP<const Number> Infty::rpow(const Number &other) const
{
return zero;
if (is_a<Complex>(other)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for ComplexDouble and ComplexMPC here as well.

@ShikharJ ShikharJ force-pushed the InftyClass branch 2 times, most recently from 2db9fcd to 6778821 Compare January 2, 2017 16:44
@ShikharJ
Copy link
Copy Markdown
Member Author

ShikharJ commented Jan 6, 2017

Ping @isuruf.

@isuruf isuruf merged commit 7b5b5a4 into symengine:master Jan 6, 2017
@ShikharJ ShikharJ deleted the InftyClass branch January 6, 2017 16:24
ranjithkumar007 pushed a commit to ranjithkumar007/symengine that referenced this pull request Jan 31, 2017
Implemented Infty::pow and Infty::rpow functions
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.

3 participants