Skip to content

Commit

Permalink
Merge pull request #932 from Alex-Jordan/update-contextLimitedRadical
Browse files Browse the repository at this point in the history
add a convenience subroutine for getting a simplified radical expression
  • Loading branch information
pstaabp authored Feb 7, 2024
2 parents f10eac1 + 19675f8 commit 64b5543
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions macros/contexts/contextLimitedRadical.pl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ sub _contextLimitedRadical_init {
};
}

###########################
#
# Convenience
#
# Pass $a,$b, get Formula("$a sqrt($b)") but simplified

sub preprad {
my ($a, $b) = @_;
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)");
}

###########################
#
# Create root(n, x)
Expand Down

0 comments on commit 64b5543

Please sign in to comment.