Clio Corvid

Writer – Teacher

Menu
  • Welcome
  • Writing
    • Poetry
    • Fragments
    • AI-generated
  • Mathematics
    • Algebra
    • Calculus
    • General
    • Geometry
    • Notation
    • Pedagogy
    • Puzzles and Memes
  • Reflections
    • Diary
    • Reflections
    • Bein’ Enby (Medium)
    • Inside My Mind
    • Other essays
  • Closed Blogs
    • Cerebri Laevi
    • Father’s Opinion
    • Good Men Project
    • Into the Labyrinth
    • Sisyphus Winced
    • Prawn Salad, Ltd.
Menu

Simplify Radicals: Python code

Posted on September 23, 2014June 19, 2023 by Clio

I’m exploring if it’s possible to create a function in GeoGebra that would take an integer as input and create a simplified radical as output. For instance, it would take \(20\) as input and return \(2\sqrt{5}\) as output. I don’t know a way, so if someone does, please tell me. (Edit: There is the SurdText command, which does exactly what I want. I still wish there was a way to create one’s own commands for use in GeoGebra textboxes… I’ll explore the CAS.)

In the meantime, I wrote the function for formatting the output in Python:

from math import floor
def simpleradical(n):
  nabs = abs(n)
  trial = floor(nabs**0.5)
  coeff = 1
  while trial > 1:
    if n % (trial**2) == 0:
      coeff = trial
      trial = 0
    trial -= 1
  remainder = nabs // coeff**2
  return coeff, remainder

def simpleradicalformat(n):
  if not(isinstance(n, int)):
    return "Input must be an integer"
  elif n == 0 or n == 1:
    return str(n)
  else:
    coeff, remainder = simpleradical(n)
    returnstring = ''
    if coeff > 1:
      returnstring = str(coeff)
    if n < 0:
      returnstring += "i"     
    if remainder > 1:
      returnstring += '√' + str(remainder)
  return returnstring

Share this:

  • Email a link to a friend (Opens in new window) Email
  • Print (Opens in new window) Print
  • Share on Facebook (Opens in new window) Facebook
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on X (Opens in new window) X
  • Share on WhatsApp (Opens in new window) WhatsApp

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Checking In
  • Fractious Fractions
  • Into the Cornfield
  • How Soon Is Now?
  • Roman Re-enacting: Malden 2025

Archives

Log in
©2026 Clio Corvid