import java.lang.Math._

class Approx(val : Double, val : Double = 0.0) {
    def this(a: Approx) = this(a., a.)
    def this(n: Number) = this(n.doubleValue(), 0.0)

    override def toString = s"$ $"

    def +(a: Approx) = Approx( + a., sqrt( *  + a. * a.))
    def +(d: Double) = Approx( + d, )
    def -(a: Approx) = Approx( - a., sqrt( *  + a. * a.))
    def -(d: Double) = Approx( - d, )

    def *(a: Approx) = {
        val v =  * a.
        Approx(v, sqrt(v * v *  *  / ( * ) + a. * a. / (a. * a.)))
    }

    def *(d: Double) = Approx( * d, abs(d * ))

    def /(a: Approx) = {
        val t =  / a.
        Approx(t, sqrt(t * t *  *  / ( * ) + a. * a. / (a. * a.)))
    }

    def /(d: Double) = Approx( / d, abs(d * ))

    def ^(d: Double) = {
        val t = pow(, d)
        Approx(t, abs(t * d *  / ))
    }
}

object Approx { def apply(: Double, : Double = 0.0) = new Approx(, ) }

object NumericError extends App {
    def (a: Approx) = a^0.5
    val x1 = Approx(100.0, 1.1)
    val x2 = Approx(50.0, 1.2)
    val y1 = Approx(200.0, 2.2)
    val y2 = Approx(100.0, 2.3)
    println((((x1 - x2)^2.0) + ((y1 - y2)^2.0)))