simplify_sqrt

Function simplify_sqrt 

Source
pub fn simplify_sqrt(arg: &Expression) -> Expression
Expand description

Simplify square root expressions

Applies mathematical simplification rules for square root.

§Simplification Rules

  • sqrt(0) = 0
  • sqrt(1) = 1
  • sqrt(4) = 2, sqrt(9) = 3, etc. (perfect squares)
  • sqrt(x²) = |x|
  • sqrt(x⁴) = x² (even powers)
  • sqrt(a*b) = sqrt(a)*sqrt(b) (when a, b ≥ 0)
  • sqrt(a²b) = asqrt(b) (factor perfect squares)
  • sqrt(1/4) = 1/2 (rational perfect squares)

§Arguments

  • arg - The argument to the square root function

§Returns

Simplified expression

§Examples

use mathhook_core::core::Expression;
use mathhook_core::functions::elementary::sqrt::simplify_sqrt;

let zero = Expression::integer(0);
assert_eq!(simplify_sqrt(&zero), Expression::integer(0));

let four = Expression::integer(4);
assert_eq!(simplify_sqrt(&four), Expression::integer(2));

let squared = Expression::pow(Expression::symbol("x"), Expression::integer(2));
assert_eq!(
    simplify_sqrt(&squared),
    Expression::function("abs", vec![Expression::symbol("x")])
);