-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
refactor arithmetic power #886
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,7 +197,7 @@ def test_directed_infinity_precedence(str_expr, str_expected, msg): | |
("I^(2/3)", "(-1) ^ (1 / 3)", None), | ||
# In WMA, the next test would return ``-(-I)^(2/3)`` | ||
# which is less compact and elegant... | ||
# ("(-I)^(2/3)", "(-1) ^ (-1 / 3)", None), | ||
("(-I)^(2/3)", "(-1) ^ (-1 / 3)", None), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. master returns -1 right now, so what we have is wrong. Do you know what part of the code fixes this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is related to the new rules you mention before... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nop. The rule at the end seems to be useless. The computation is done by |
||
("(2+3I)^3", "-46 + 9 I", None), | ||
("(1.+3. I)^.6", "1.46069 + 1.35921 I", None), | ||
("3^(1+2 I)", "3 ^ (1 + 2 I)", None), | ||
|
@@ -208,15 +208,15 @@ def test_directed_infinity_precedence(str_expr, str_expected, msg): | |
# sympy, which produces the result | ||
("(3/Pi)^(-I)", "(3 / Pi) ^ (-I)", None), | ||
# Association rules | ||
# ('(a^"w")^2', 'a^(2 "w")', "Integer power of a power with string exponent"), | ||
('(a^"w")^2', 'a^(2 "w")', "Integer power of a power with string exponent"), | ||
('(a^2)^"w"', '(a ^ 2) ^ "w"', None), | ||
('(a^2)^"w"', '(a ^ 2) ^ "w"', None), | ||
("(a^2)^(1/2)", "Sqrt[a ^ 2]", None), | ||
("(a^(1/2))^2", "a", None), | ||
("(a^(1/2))^2", "a", None), | ||
("(a^(3/2))^3.", "(a ^ (3 / 2)) ^ 3.", None), | ||
# ("(a^(1/2))^3.", "a ^ 1.5", "Power associativity rational, real"), | ||
# ("(a^(.3))^3.", "a ^ 0.9", "Power associativity for real powers"), | ||
("(a^(1/2))^3.", "a ^ 1.5", "Power associativity rational, real"), | ||
("(a^(.3))^3.", "a ^ 0.9", "Power associativity for real powers"), | ||
("(a^(1.3))^3.", "(a ^ 1.3) ^ 3.", None), | ||
# Exponentials involving expressions | ||
("(a^(p-2 q))^3", "a ^ (3 p - 6 q)", None), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,34 +456,53 @@ | |
"Sqrt[1/(1+1/(1+1/a))]": { | ||
"msg": "SqrtBox", | ||
"text": { | ||
"System`StandardForm": "Sqrt[1 / (1+1 / (1+1 / a))]", | ||
"System`TraditionalForm": "Sqrt[1 / (1+1 / (1+1 / a))]", | ||
"System`InputForm": "Sqrt[1 / (1 + 1 / (1 + 1 / a))]", | ||
"System`OutputForm": "Sqrt[1 / (1 + 1 / (1 + 1 / a))]", | ||
"System`StandardForm": "1 / Sqrt[1+1 / (1+1 / a)]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the change in test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the effect of implementing the associativity of powers. In master,
produces
while here,
On the other hand, looking at WMA, it seems that it does not implement the associativity in this case either. |
||
"System`TraditionalForm": "1 / Sqrt[1+1 / (1+1 / a)]", | ||
"System`InputForm": "1 / Sqrt[1 + 1 / (1 + 1 / a)]", | ||
"System`OutputForm": "1 / Sqrt[1 + 1 / (1 + 1 / a)]", | ||
}, | ||
"mathml": { | ||
"System`StandardForm": ( | ||
"<msqrt> <mfrac><mn>1</mn> <mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> <mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> <mi>a</mi></mfrac></mrow></mfrac></mrow></mfrac> </msqrt>", | ||
( | ||
r"<mfrac><mn>1</mn> <msqrt> <mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> " | ||
r"<mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> <mi>a</mi></mfrac></mrow></mfrac></mrow> " | ||
r"</msqrt></mfrac>" | ||
), | ||
"Fragile!", | ||
), | ||
"System`TraditionalForm": ( | ||
"<msqrt> <mfrac><mn>1</mn> <mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> <mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> <mi>a</mi></mfrac></mrow></mfrac></mrow></mfrac> </msqrt>", | ||
( | ||
r"<mfrac><mn>1</mn> <msqrt> <mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> " | ||
r"<mrow><mn>1</mn> <mo>+</mo> <mfrac><mn>1</mn> <mi>a</mi></mfrac></mrow></mfrac></mrow> " | ||
r"</msqrt></mfrac>" | ||
), | ||
"Fragile!", | ||
), | ||
"System`InputForm": ( | ||
"<mrow><mi>Sqrt</mi> <mo>[</mo> <mrow><mtext>1</mtext> <mtext> / </mtext> <mrow><mo>(</mo> <mrow><mtext>1</mtext> <mtext> + </mtext> <mrow><mtext>1</mtext> <mtext> / </mtext> <mrow><mo>(</mo> <mrow><mtext>1</mtext> <mtext> + </mtext> <mrow><mtext>1</mtext> <mtext> / </mtext> <mi>a</mi></mrow></mrow> <mo>)</mo></mrow></mrow></mrow> <mo>)</mo></mrow></mrow> <mo>]</mo></mrow>", | ||
( | ||
r"<mrow><mtext>1</mtext> <mtext> / </mtext> <mrow><mi>Sqrt</mi> <mo>[</mo> " | ||
r"<mrow><mtext>1</mtext> <mtext> + </mtext> <mrow><mtext>1</mtext> <mtext> / </mtext> " | ||
r"<mrow><mo>(</mo> <mrow><mtext>1</mtext> <mtext> + </mtext> <mrow><mtext>1</mtext> <mtext>" | ||
r" / </mtext> <mi>a</mi></mrow></mrow> <mo>)</mo></mrow></mrow></mrow> <mo>]</mo></mrow></mrow>" | ||
), | ||
"Fragile!", | ||
), | ||
"System`OutputForm": ( | ||
"<mrow><mi>Sqrt</mi> <mo>[</mo> <mrow><mn>1</mn> <mtext> / </mtext> <mrow><mo>(</mo> <mrow><mn>1</mn> <mtext> + </mtext> <mrow><mn>1</mn> <mtext> / </mtext> <mrow><mo>(</mo> <mrow><mn>1</mn> <mtext> + </mtext> <mrow><mn>1</mn> <mtext> / </mtext> <mi>a</mi></mrow></mrow> <mo>)</mo></mrow></mrow></mrow> <mo>)</mo></mrow></mrow> <mo>]</mo></mrow>", | ||
( | ||
r"<mrow><mn>1</mn> <mtext> / </mtext> <mrow><mi>Sqrt</mi> <mo>[" | ||
r"</mo> <mrow><mn>1</mn> <mtext> + </mtext> <mrow><mn>1</mn> " | ||
r"<mtext> / </mtext> <mrow><mo>(</mo> <mrow><mn>1</mn> <mtext>" | ||
r" + </mtext> <mrow><mn>1</mn> <mtext> / </mtext> " | ||
r"<mi>a</mi></mrow></mrow> <mo>)</mo></mrow></mrow></mrow> <mo>]</mo></mrow></mrow>" | ||
), | ||
"Fragile!", | ||
), | ||
}, | ||
"latex": { | ||
"System`StandardForm": "\\sqrt{\\frac{1}{1+\\frac{1}{1+\\frac{1}{a}}}}", | ||
"System`TraditionalForm": "\\sqrt{\\frac{1}{1+\\frac{1}{1+\\frac{1}{a}}}}", | ||
"System`InputForm": "\\text{Sqrt}\\left[1\\text{ / }\\left(1\\text{ + }1\\text{ / }\\left(1\\text{ + }1\\text{ / }a\\right)\\right)\\right]", | ||
"System`OutputForm": "\\text{Sqrt}\\left[1\\text{ / }\\left(1\\text{ + }1\\text{ / }\\left(1\\text{ + }1\\text{ / }a\\right)\\right)\\right]", | ||
"System`StandardForm": "\\frac{1}{\\sqrt{1+\\frac{1}{1+\\frac{1}{a}}}}", | ||
"System`TraditionalForm": "\\frac{1}{\\sqrt{1+\\frac{1}{1+\\frac{1}{a}}}}", | ||
"System`InputForm": r"1\text{ / }\text{Sqrt}\left[1\text{ + }1\text{ / }\left(1\text{ + }1\text{ / }a\right)\right]", | ||
"System`OutputForm": r"1\text{ / }\text{Sqrt}\left[1\text{ + }1\text{ / }\left(1\text{ + }1\text{ / }a\right)\right]", | ||
}, | ||
}, | ||
# Grids, arrays and matrices | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this kind of thing can't be done in Sympy. Have we tried this?
For another thing brought up and in a previous PR, with Sign, I see in that a problem there mentioned in StackOverflow was just about not tagging a variable as being in the right type (complex vs real).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is not if we can find a way to use Sympy, but if we can do it "natively", without the cost of back-and-forth conversions. Even if we can make these conversions more efficient, avoiding them at all would always be a win, mostly if the native implementation is not too complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.