Simplify radicands












2












$begingroup$


I am attempting to create a program that can, given an integer as input, simplify the radicand by removing all square factors. For use on my TI 84+ CE
Code: for clarity reasons I've indented conditional blocks and added a new line after Delvar.



If not(A:Input “√(“,A
1→Y
While not(remainder(A,4
A/4→A
2Y→Y
End
3→X
While X²<=A
X²→θ
While not(remainder(A,θ
A/θ→A
XY→Y
End
X+2→X
End
{Y,A
DelVar A
If 1=Ans(2:Then
Disp “√(“+toString(Ans(2))+”)
Else:If 1=Ans(1:Then
Disp Ans(1
Else
Disp toString(Ans(1))+“√(“+toString(Ans(2))+”)


The program asks for input if one is not already provided in the A variable. It also initializes a Y variable to store the removed factors (part outside the radical sign). It then proceeds, for X from 2 counting up until X is greater than the square root of A to successively divide out squares of X and multiply Y by X for each iteration. After doing this for 2, it only tests odd numbers. At the end, A stores the value left inside the radicand. If A=1, then it simply displays Y as the answer. If Y=1, then it displays √Y as the answer. Otherwise, it shows A√Y as the result.



The worst case input for the algorithm is any number without a square factor, because it then has to run all the iterations to complete.



Are there any optimizations I can make? As space is not a problem (yet) on my calculator, I would prefer a speed optimization over a space optimization, but both are welcome.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    It would be helpful if you gave a brief algorithm overview. given the formatting, and the fact that it is a kind of obscure language, it will let people give better advice.
    $endgroup$
    – Oscar Smith
    Jan 11 '18 at 6:47










  • $begingroup$
    Also indentation and adding closing brackets would help - at least here. The 84s display is probably not suited for the latter one.
    $endgroup$
    – Markus Deibel
    Jan 11 '18 at 8:00








  • 1




    $begingroup$
    If you had a list of prime numbers on my calculator (at some point I generated the first 999, which is the most that can fit in a list), you could iterate those instead of all the numbers (then iterate all the odds after the primes run out).
    $endgroup$
    – Solomon Ucko
    Feb 28 '18 at 20:10










  • $begingroup$
    How large is the integer? It seems like you need an integer factorisation algorithm, depending on the size of the number, different algorithms would be appropriate.
    $endgroup$
    – George Barwood
    4 hours ago
















2












$begingroup$


I am attempting to create a program that can, given an integer as input, simplify the radicand by removing all square factors. For use on my TI 84+ CE
Code: for clarity reasons I've indented conditional blocks and added a new line after Delvar.



If not(A:Input “√(“,A
1→Y
While not(remainder(A,4
A/4→A
2Y→Y
End
3→X
While X²<=A
X²→θ
While not(remainder(A,θ
A/θ→A
XY→Y
End
X+2→X
End
{Y,A
DelVar A
If 1=Ans(2:Then
Disp “√(“+toString(Ans(2))+”)
Else:If 1=Ans(1:Then
Disp Ans(1
Else
Disp toString(Ans(1))+“√(“+toString(Ans(2))+”)


The program asks for input if one is not already provided in the A variable. It also initializes a Y variable to store the removed factors (part outside the radical sign). It then proceeds, for X from 2 counting up until X is greater than the square root of A to successively divide out squares of X and multiply Y by X for each iteration. After doing this for 2, it only tests odd numbers. At the end, A stores the value left inside the radicand. If A=1, then it simply displays Y as the answer. If Y=1, then it displays √Y as the answer. Otherwise, it shows A√Y as the result.



The worst case input for the algorithm is any number without a square factor, because it then has to run all the iterations to complete.



Are there any optimizations I can make? As space is not a problem (yet) on my calculator, I would prefer a speed optimization over a space optimization, but both are welcome.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    It would be helpful if you gave a brief algorithm overview. given the formatting, and the fact that it is a kind of obscure language, it will let people give better advice.
    $endgroup$
    – Oscar Smith
    Jan 11 '18 at 6:47










  • $begingroup$
    Also indentation and adding closing brackets would help - at least here. The 84s display is probably not suited for the latter one.
    $endgroup$
    – Markus Deibel
    Jan 11 '18 at 8:00








  • 1




    $begingroup$
    If you had a list of prime numbers on my calculator (at some point I generated the first 999, which is the most that can fit in a list), you could iterate those instead of all the numbers (then iterate all the odds after the primes run out).
    $endgroup$
    – Solomon Ucko
    Feb 28 '18 at 20:10










  • $begingroup$
    How large is the integer? It seems like you need an integer factorisation algorithm, depending on the size of the number, different algorithms would be appropriate.
    $endgroup$
    – George Barwood
    4 hours ago














2












2








2





$begingroup$


I am attempting to create a program that can, given an integer as input, simplify the radicand by removing all square factors. For use on my TI 84+ CE
Code: for clarity reasons I've indented conditional blocks and added a new line after Delvar.



If not(A:Input “√(“,A
1→Y
While not(remainder(A,4
A/4→A
2Y→Y
End
3→X
While X²<=A
X²→θ
While not(remainder(A,θ
A/θ→A
XY→Y
End
X+2→X
End
{Y,A
DelVar A
If 1=Ans(2:Then
Disp “√(“+toString(Ans(2))+”)
Else:If 1=Ans(1:Then
Disp Ans(1
Else
Disp toString(Ans(1))+“√(“+toString(Ans(2))+”)


The program asks for input if one is not already provided in the A variable. It also initializes a Y variable to store the removed factors (part outside the radical sign). It then proceeds, for X from 2 counting up until X is greater than the square root of A to successively divide out squares of X and multiply Y by X for each iteration. After doing this for 2, it only tests odd numbers. At the end, A stores the value left inside the radicand. If A=1, then it simply displays Y as the answer. If Y=1, then it displays √Y as the answer. Otherwise, it shows A√Y as the result.



The worst case input for the algorithm is any number without a square factor, because it then has to run all the iterations to complete.



Are there any optimizations I can make? As space is not a problem (yet) on my calculator, I would prefer a speed optimization over a space optimization, but both are welcome.










share|improve this question











$endgroup$




I am attempting to create a program that can, given an integer as input, simplify the radicand by removing all square factors. For use on my TI 84+ CE
Code: for clarity reasons I've indented conditional blocks and added a new line after Delvar.



If not(A:Input “√(“,A
1→Y
While not(remainder(A,4
A/4→A
2Y→Y
End
3→X
While X²<=A
X²→θ
While not(remainder(A,θ
A/θ→A
XY→Y
End
X+2→X
End
{Y,A
DelVar A
If 1=Ans(2:Then
Disp “√(“+toString(Ans(2))+”)
Else:If 1=Ans(1:Then
Disp Ans(1
Else
Disp toString(Ans(1))+“√(“+toString(Ans(2))+”)


The program asks for input if one is not already provided in the A variable. It also initializes a Y variable to store the removed factors (part outside the radical sign). It then proceeds, for X from 2 counting up until X is greater than the square root of A to successively divide out squares of X and multiply Y by X for each iteration. After doing this for 2, it only tests odd numbers. At the end, A stores the value left inside the radicand. If A=1, then it simply displays Y as the answer. If Y=1, then it displays √Y as the answer. Otherwise, it shows A√Y as the result.



The worst case input for the algorithm is any number without a square factor, because it then has to run all the iterations to complete.



Are there any optimizations I can make? As space is not a problem (yet) on my calculator, I would prefer a speed optimization over a space optimization, but both are welcome.







symbolic-math ti-basic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago









200_success

129k15153415




129k15153415










asked Jan 11 '18 at 6:41









Neil A.Neil A.

1785




1785








  • 1




    $begingroup$
    It would be helpful if you gave a brief algorithm overview. given the formatting, and the fact that it is a kind of obscure language, it will let people give better advice.
    $endgroup$
    – Oscar Smith
    Jan 11 '18 at 6:47










  • $begingroup$
    Also indentation and adding closing brackets would help - at least here. The 84s display is probably not suited for the latter one.
    $endgroup$
    – Markus Deibel
    Jan 11 '18 at 8:00








  • 1




    $begingroup$
    If you had a list of prime numbers on my calculator (at some point I generated the first 999, which is the most that can fit in a list), you could iterate those instead of all the numbers (then iterate all the odds after the primes run out).
    $endgroup$
    – Solomon Ucko
    Feb 28 '18 at 20:10










  • $begingroup$
    How large is the integer? It seems like you need an integer factorisation algorithm, depending on the size of the number, different algorithms would be appropriate.
    $endgroup$
    – George Barwood
    4 hours ago














  • 1




    $begingroup$
    It would be helpful if you gave a brief algorithm overview. given the formatting, and the fact that it is a kind of obscure language, it will let people give better advice.
    $endgroup$
    – Oscar Smith
    Jan 11 '18 at 6:47










  • $begingroup$
    Also indentation and adding closing brackets would help - at least here. The 84s display is probably not suited for the latter one.
    $endgroup$
    – Markus Deibel
    Jan 11 '18 at 8:00








  • 1




    $begingroup$
    If you had a list of prime numbers on my calculator (at some point I generated the first 999, which is the most that can fit in a list), you could iterate those instead of all the numbers (then iterate all the odds after the primes run out).
    $endgroup$
    – Solomon Ucko
    Feb 28 '18 at 20:10










  • $begingroup$
    How large is the integer? It seems like you need an integer factorisation algorithm, depending on the size of the number, different algorithms would be appropriate.
    $endgroup$
    – George Barwood
    4 hours ago








1




1




$begingroup$
It would be helpful if you gave a brief algorithm overview. given the formatting, and the fact that it is a kind of obscure language, it will let people give better advice.
$endgroup$
– Oscar Smith
Jan 11 '18 at 6:47




$begingroup$
It would be helpful if you gave a brief algorithm overview. given the formatting, and the fact that it is a kind of obscure language, it will let people give better advice.
$endgroup$
– Oscar Smith
Jan 11 '18 at 6:47












$begingroup$
Also indentation and adding closing brackets would help - at least here. The 84s display is probably not suited for the latter one.
$endgroup$
– Markus Deibel
Jan 11 '18 at 8:00






$begingroup$
Also indentation and adding closing brackets would help - at least here. The 84s display is probably not suited for the latter one.
$endgroup$
– Markus Deibel
Jan 11 '18 at 8:00






1




1




$begingroup$
If you had a list of prime numbers on my calculator (at some point I generated the first 999, which is the most that can fit in a list), you could iterate those instead of all the numbers (then iterate all the odds after the primes run out).
$endgroup$
– Solomon Ucko
Feb 28 '18 at 20:10




$begingroup$
If you had a list of prime numbers on my calculator (at some point I generated the first 999, which is the most that can fit in a list), you could iterate those instead of all the numbers (then iterate all the odds after the primes run out).
$endgroup$
– Solomon Ucko
Feb 28 '18 at 20:10












$begingroup$
How large is the integer? It seems like you need an integer factorisation algorithm, depending on the size of the number, different algorithms would be appropriate.
$endgroup$
– George Barwood
4 hours ago




$begingroup$
How large is the integer? It seems like you need an integer factorisation algorithm, depending on the size of the number, different algorithms would be appropriate.
$endgroup$
– George Barwood
4 hours ago










0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f184825%2fsimplify-radicands%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f184825%2fsimplify-radicands%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

第一次世界大戦

Touch on Surface Book