From e14a6d664a8186d7afa4e781c13dcf80ba207a4e Mon Sep 17 00:00:00 2001 From: KG Date: Sat, 16 Nov 2024 00:09:36 -0500 Subject: [PATCH] Make `#` for radicals more explicit --- tivars/types/real.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tivars/types/real.py b/tivars/types/real.py index bb77ab4..db8fcba 100644 --- a/tivars/types/real.py +++ b/tivars/types/real.py @@ -413,11 +413,11 @@ def reduce(part): case _: return part - left = reduce(f"{self.left_scalar * (-1 if self.sign_type % 2 else 1)}√{self.left_radicand}") - right = reduce(f"{self.right_scalar * (-1 if self.sign_type > 1 else 1)}√{self.right_radicand}") - match format_spec: case "": + left = reduce(f"{self.left_scalar * (-1 if self.sign_type % 2 else 1)}√{self.left_radicand}") + right = reduce(f"{self.right_scalar * (-1 if self.sign_type > 1 else 1)}√{self.right_radicand}") + match left, right, self.denominator: case "", "", _: string = "0" @@ -440,6 +440,9 @@ def reduce(part): return string.replace("+-", "-") case "#": + left = f"{self.left_scalar * (-1 if self.sign_type % 2 else 1)}√{self.left_radicand}" + right = f"{self.right_scalar * (-1 if self.sign_type > 1 else 1)}√{self.right_radicand}" + return f"({left}+{right})/{self.denominator}".replace("+-", "-") case _: