?

Average Accuracy: 58.5% → 84.2%
Time: 18.7s
Precision: binary64
Cost: 22088

?

\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;t_0 \leq 10^{+287}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= t_0 (- INFINITY))
     (/ b d)
     (if (<= t_0 1e+287)
       (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
       (+ (/ a c) (/ (/ b c) (/ c d)))))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = b / d;
	} else if (t_0 <= 1e+287) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (a / c) + ((b / c) / (c / d));
	}
	return tmp;
}
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(b / d);
	elseif (t_0 <= 1e+287)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(b / c) / Float64(c / d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(b / d), $MachinePrecision], If[LessEqual[t$95$0, 1e+287], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;t_0 \leq 10^{+287}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\


\end{array}

Error?

Target

Original58.5%
Target99.4%
Herbie84.2%
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0

    1. Initial program 0.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around 0 44.9%

      \[\leadsto \color{blue}{\frac{b}{d}} \]

    if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.0000000000000001e287

    1. Initial program 81.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied egg-rr98.4%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
      Proof

      [Start]81.4

      \[ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]

      *-un-lft-identity [=>]81.4

      \[ \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]

      add-sqr-sqrt [=>]81.4

      \[ \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]

      times-frac [=>]81.4

      \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]

      hypot-def [=>]81.4

      \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]

      fma-def [=>]81.4

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]

      hypot-def [=>]98.4

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]

    if 1.0000000000000001e287 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 2.1%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 36.0%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Simplified49.5%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}} \]
      Proof

      [Start]36.0

      \[ \frac{a}{c} + \frac{d \cdot b}{{c}^{2}} \]

      *-commutative [<=]36.0

      \[ \frac{a}{c} + \frac{\color{blue}{b \cdot d}}{{c}^{2}} \]

      unpow2 [=>]36.0

      \[ \frac{a}{c} + \frac{b \cdot d}{\color{blue}{c \cdot c}} \]

      times-frac [=>]49.5

      \[ \frac{a}{c} + \color{blue}{\frac{b}{c} \cdot \frac{d}{c}} \]
    4. Applied egg-rr49.5%

      \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{b}{c}}{\frac{c}{d}}} \]
      Proof

      [Start]49.5

      \[ \frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c} \]

      associate-*r/ [=>]49.3

      \[ \frac{a}{c} + \color{blue}{\frac{\frac{b}{c} \cdot d}{c}} \]

      associate-/l* [=>]49.5

      \[ \frac{a}{c} + \color{blue}{\frac{\frac{b}{c}}{\frac{c}{d}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq -\infty:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+287}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy78.7%
Cost14164
\[\begin{array}{l} t_0 := \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -9.5 \cdot 10^{+101}:\\ \;\;\;\;t_0 \cdot \left(a + b \cdot \frac{d}{c}\right)\\ \mathbf{elif}\;c \leq -8 \cdot 10^{+67}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -1.85 \cdot 10^{+50}:\\ \;\;\;\;a \cdot t_0\\ \mathbf{elif}\;c \leq -4.3 \cdot 10^{-7}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \leq -9.5 \cdot 10^{-133}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{-23}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ \mathbf{elif}\;c \leq 2.25 \cdot 10^{+77}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \end{array} \]
Alternative 2
Accuracy78.6%
Cost13904
\[\begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -7 \cdot 10^{+102}:\\ \;\;\;\;t_1 \cdot \left(a + b \cdot \frac{d}{c}\right)\\ \mathbf{elif}\;c \leq -1.9 \cdot 10^{+69}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -7.5 \cdot 10^{+48}:\\ \;\;\;\;a \cdot t_1\\ \mathbf{elif}\;c \leq -1.15 \cdot 10^{-6}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-23}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{+75}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \end{array} \]
Alternative 3
Accuracy78.7%
Cost8092
\[\begin{array}{l} t_0 := \frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -1.15 \cdot 10^{+102}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -7.6 \cdot 10^{+68}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -4.4 \cdot 10^{+47}:\\ \;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -115:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{-21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{+76}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \end{array} \]
Alternative 4
Accuracy81.0%
Cost7696
\[\begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -4.9 \cdot 10^{+103}:\\ \;\;\;\;\frac{-1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + b \cdot \frac{d}{c}\right)\\ \mathbf{elif}\;c \leq -9.4 \cdot 10^{-133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{-23}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ \mathbf{elif}\;c \leq 1.35 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \end{array} \]
Alternative 5
Accuracy78.4%
Cost7180
\[\begin{array}{l} t_0 := \frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -9.5 \cdot 10^{+101}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{+69}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -1.6 \cdot 10^{+50}:\\ \;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -115:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -2.45 \cdot 10^{-133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{+77}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]
Alternative 6
Accuracy78.3%
Cost1884
\[\begin{array}{l} t_0 := \frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -1.7 \cdot 10^{+103}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -6 \cdot 10^{+67}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3.8 \cdot 10^{+47}:\\ \;\;\;\;a \cdot \frac{1}{c}\\ \mathbf{elif}\;c \leq -114:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4.8 \cdot 10^{-133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.26 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.5 \cdot 10^{+76}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]
Alternative 7
Accuracy69.9%
Cost1232
\[\begin{array}{l} t_0 := \frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \mathbf{if}\;c \leq -3 \cdot 10^{+102}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -4.7 \cdot 10^{+66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1.35 \cdot 10^{+50}:\\ \;\;\;\;a \cdot \frac{1}{c}\\ \mathbf{elif}\;c \leq 6 \cdot 10^{+79}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
Alternative 8
Accuracy74.1%
Cost1232
\[\begin{array}{l} t_0 := \frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ t_1 := \frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{if}\;c \leq -2 \cdot 10^{+102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -8.5 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -7 \cdot 10^{+48}:\\ \;\;\;\;a \cdot \frac{1}{c}\\ \mathbf{elif}\;c \leq 1.28 \cdot 10^{+79}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Accuracy74.0%
Cost1232
\[\begin{array}{l} t_0 := \frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \mathbf{if}\;c \leq -9.5 \cdot 10^{+101}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -4.4 \cdot 10^{+66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -4 \cdot 10^{+49}:\\ \;\;\;\;a \cdot \frac{1}{c}\\ \mathbf{elif}\;c \leq 3.05 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]
Alternative 10
Accuracy74.1%
Cost1232
\[\begin{array}{l} \mathbf{if}\;c \leq -9.5 \cdot 10^{+101}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{+68}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -1 \cdot 10^{+47}:\\ \;\;\;\;a \cdot \frac{1}{c}\\ \mathbf{elif}\;c \leq 3.05 \cdot 10^{+78}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]
Alternative 11
Accuracy74.1%
Cost1232
\[\begin{array}{l} \mathbf{if}\;c \leq -5 \cdot 10^{+103}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -1.95 \cdot 10^{+68}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -7.5 \cdot 10^{+46}:\\ \;\;\;\;a \cdot \frac{1}{c}\\ \mathbf{elif}\;c \leq 9 \cdot 10^{+78}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]
Alternative 12
Accuracy63.7%
Cost456
\[\begin{array}{l} \mathbf{if}\;d \leq -9 \cdot 10^{-45}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{+28}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
Alternative 13
Accuracy40.9%
Cost192
\[\frac{a}{c} \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))