From aa0cdc8744d550f865b0f2bc2300b4aa2e2e8808 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Fri, 29 Sep 2023 16:27:07 -0700 Subject: [PATCH 1/3] add a convenience subroutine for getting a simplified radical expression --- macros/contexts/contextLimitedRadical.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/macros/contexts/contextLimitedRadical.pl b/macros/contexts/contextLimitedRadical.pl index 8c7bbd291f..a064dacd3f 100644 --- a/macros/contexts/contextLimitedRadical.pl +++ b/macros/contexts/contextLimitedRadical.pl @@ -128,6 +128,25 @@ sub _contextLimitedRadical_init { }; } +########################### +# +# Convenience +# +# Pass $a,$b, get Formula("$a sqrt($b)") but simplified + +sub preprad { + my $a = shift; + my $b = shift; + if ($a == 0 or $b == 0) { return Formula("0"); } + my $sign = ($a > 0) ? '' : '-'; + my $simplifieda = (abs($a) == 1) ? $sign : $a; + if ($b == 1) { + return Formula("$a"); + } else { + return Formula("$simplifieda sqrt($b)"); + } +} + ########################### # # Create root(n, x) From 90dc3ccff83bd05d7d156e160046f7246686bc37 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Tue, 10 Oct 2023 16:29:15 -0700 Subject: [PATCH 2/3] Update macros/contexts/contextLimitedRadical.pl Co-authored-by: Glenn Rice <47527406+drgrice1@users.noreply.github.com> --- macros/contexts/contextLimitedRadical.pl | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/macros/contexts/contextLimitedRadical.pl b/macros/contexts/contextLimitedRadical.pl index a064dacd3f..e9e8e0b90d 100644 --- a/macros/contexts/contextLimitedRadical.pl +++ b/macros/contexts/contextLimitedRadical.pl @@ -135,16 +135,11 @@ sub _contextLimitedRadical_init { # Pass $a,$b, get Formula("$a sqrt($b)") but simplified sub preprad { - my $a = shift; - my $b = shift; - if ($a == 0 or $b == 0) { return Formula("0"); } - my $sign = ($a > 0) ? '' : '-'; - my $simplifieda = (abs($a) == 1) ? $sign : $a; - if ($b == 1) { - return Formula("$a"); - } else { - return Formula("$simplifieda sqrt($b)"); - } + my ($a, $b) = @_; + return Formula("0") if $a == 0 or $b == 0; + return Formula("$a") if $b == 1; + my $simplifieda = abs($a) == 1 ? ($a > 0 ? '' : '-') : $a; + return Formula("$simplifieda sqrt($b)"); } ########################### From 19675f850977e7733ae980e1f390935ac8582a4f Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Tue, 10 Oct 2023 16:31:49 -0700 Subject: [PATCH 3/3] code cleanup --- macros/contexts/contextLimitedRadical.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/contexts/contextLimitedRadical.pl b/macros/contexts/contextLimitedRadical.pl index e9e8e0b90d..49569d2ecd 100644 --- a/macros/contexts/contextLimitedRadical.pl +++ b/macros/contexts/contextLimitedRadical.pl @@ -136,7 +136,7 @@ sub _contextLimitedRadical_init { sub preprad { my ($a, $b) = @_; - return Formula("0") if $a == 0 or $b == 0; + return Formula("0") if $a == 0 || $b == 0; return Formula("$a") if $b == 1; my $simplifieda = abs($a) == 1 ? ($a > 0 ? '' : '-') : $a; return Formula("$simplifieda sqrt($b)");