Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, B

Percentage Accurate: 99.8% → 99.8%
Time: 21.5s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (/ 1.0 2.0) (+ x (* y (sqrt z)))))
double code(double x, double y, double z) {
	return (1.0 / 2.0) * (x + (y * sqrt(z)));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (1.0d0 / 2.0d0) * (x + (y * sqrt(z)))
end function
public static double code(double x, double y, double z) {
	return (1.0 / 2.0) * (x + (y * Math.sqrt(z)));
}
def code(x, y, z):
	return (1.0 / 2.0) * (x + (y * math.sqrt(z)))
function code(x, y, z)
	return Float64(Float64(1.0 / 2.0) * Float64(x + Float64(y * sqrt(z))))
end
function tmp = code(x, y, z)
	tmp = (1.0 / 2.0) * (x + (y * sqrt(z)));
end
code[x_, y_, z_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(x + N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (/ 1.0 2.0) (+ x (* y (sqrt z)))))
double code(double x, double y, double z) {
	return (1.0 / 2.0) * (x + (y * sqrt(z)));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (1.0d0 / 2.0d0) * (x + (y * sqrt(z)))
end function
public static double code(double x, double y, double z) {
	return (1.0 / 2.0) * (x + (y * Math.sqrt(z)));
}
def code(x, y, z):
	return (1.0 / 2.0) * (x + (y * math.sqrt(z)))
function code(x, y, z)
	return Float64(Float64(1.0 / 2.0) * Float64(x + Float64(y * sqrt(z))))
end
function tmp = code(x, y, z)
	tmp = (1.0 / 2.0) * (x + (y * sqrt(z)));
end
code[x_, y_, z_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(x + N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right)
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \left(x + y \cdot \sqrt{z}\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* 0.5 (+ x (* y (sqrt z)))))
double code(double x, double y, double z) {
	return 0.5 * (x + (y * sqrt(z)));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.5d0 * (x + (y * sqrt(z)))
end function
public static double code(double x, double y, double z) {
	return 0.5 * (x + (y * Math.sqrt(z)));
}
def code(x, y, z):
	return 0.5 * (x + (y * math.sqrt(z)))
function code(x, y, z)
	return Float64(0.5 * Float64(x + Float64(y * sqrt(z))))
end
function tmp = code(x, y, z)
	tmp = 0.5 * (x + (y * sqrt(z)));
end
code[x_, y_, z_] := N[(0.5 * N[(x + N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \left(x + y \cdot \sqrt{z}\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  2. Step-by-step derivation
    1. metadata-eval99.8%

      \[\leadsto \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(x + y \cdot \sqrt{z}\right)} \]
  4. Final simplification99.8%

    \[\leadsto 0.5 \cdot \left(x + y \cdot \sqrt{z}\right) \]

Alternative 2: 74.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{-11}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq 1.86 \cdot 10^{+55}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \sqrt{z}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x - y \cdot \frac{y}{\frac{x}{z}}\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -2.5e-11)
   (* 0.5 x)
   (if (<= x 1.86e+55)
     (* 0.5 (* y (sqrt z)))
     (* 0.5 (- x (* y (/ y (/ x z))))))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.5e-11) {
		tmp = 0.5 * x;
	} else if (x <= 1.86e+55) {
		tmp = 0.5 * (y * sqrt(z));
	} else {
		tmp = 0.5 * (x - (y * (y / (x / z))));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-2.5d-11)) then
        tmp = 0.5d0 * x
    else if (x <= 1.86d+55) then
        tmp = 0.5d0 * (y * sqrt(z))
    else
        tmp = 0.5d0 * (x - (y * (y / (x / z))))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.5e-11) {
		tmp = 0.5 * x;
	} else if (x <= 1.86e+55) {
		tmp = 0.5 * (y * Math.sqrt(z));
	} else {
		tmp = 0.5 * (x - (y * (y / (x / z))));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -2.5e-11:
		tmp = 0.5 * x
	elif x <= 1.86e+55:
		tmp = 0.5 * (y * math.sqrt(z))
	else:
		tmp = 0.5 * (x - (y * (y / (x / z))))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -2.5e-11)
		tmp = Float64(0.5 * x);
	elseif (x <= 1.86e+55)
		tmp = Float64(0.5 * Float64(y * sqrt(z)));
	else
		tmp = Float64(0.5 * Float64(x - Float64(y * Float64(y / Float64(x / z)))));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -2.5e-11)
		tmp = 0.5 * x;
	elseif (x <= 1.86e+55)
		tmp = 0.5 * (y * sqrt(z));
	else
		tmp = 0.5 * (x - (y * (y / (x / z))));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -2.5e-11], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 1.86e+55], N[(0.5 * N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x - N[(y * N[(y / N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-11}:\\
\;\;\;\;0.5 \cdot x\\

\mathbf{elif}\;x \leq 1.86 \cdot 10^{+55}:\\
\;\;\;\;0.5 \cdot \left(y \cdot \sqrt{z}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x - y \cdot \frac{y}{\frac{x}{z}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.50000000000000009e-11

    1. Initial program 99.9%

      \[\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \]
    2. Step-by-step derivation
      1. metadata-eval99.9%

        \[\leadsto \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y \cdot \sqrt{z}\right)} \]
    4. Taylor expanded in x around inf 80.4%

      \[\leadsto 0.5 \cdot \color{blue}{x} \]

    if -2.50000000000000009e-11 < x < 1.86e55

    1. Initial program 99.7%

      \[\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \]
    2. Step-by-step derivation
      1. metadata-eval99.7%

        \[\leadsto \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y \cdot \sqrt{z}\right)} \]
    4. Taylor expanded in x around 0 82.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(y \cdot \sqrt{z}\right)} \]

    if 1.86e55 < x

    1. Initial program 99.9%

      \[\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \]
    2. Step-by-step derivation
      1. metadata-eval99.9%

        \[\leadsto \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y \cdot \sqrt{z}\right)} \]
    4. Step-by-step derivation
      1. cancel-sign-sub99.9%

        \[\leadsto 0.5 \cdot \color{blue}{\left(x - \left(-y\right) \cdot \sqrt{z}\right)} \]
      2. distribute-lft-neg-in99.9%

        \[\leadsto 0.5 \cdot \left(x - \color{blue}{\left(-y \cdot \sqrt{z}\right)}\right) \]
      3. flip--30.6%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot x - \left(-y \cdot \sqrt{z}\right) \cdot \left(-y \cdot \sqrt{z}\right)}{x + \left(-y \cdot \sqrt{z}\right)}} \]
      4. sqr-neg30.6%

        \[\leadsto 0.5 \cdot \frac{x \cdot x - \color{blue}{\left(y \cdot \sqrt{z}\right) \cdot \left(y \cdot \sqrt{z}\right)}}{x + \left(-y \cdot \sqrt{z}\right)} \]
      5. swap-sqr30.3%

        \[\leadsto 0.5 \cdot \frac{x \cdot x - \color{blue}{\left(y \cdot y\right) \cdot \left(\sqrt{z} \cdot \sqrt{z}\right)}}{x + \left(-y \cdot \sqrt{z}\right)} \]
      6. rem-square-sqrt30.3%

        \[\leadsto 0.5 \cdot \frac{x \cdot x - \left(y \cdot y\right) \cdot \color{blue}{z}}{x + \left(-y \cdot \sqrt{z}\right)} \]
      7. sub-neg30.3%

        \[\leadsto 0.5 \cdot \frac{x \cdot x - \left(y \cdot y\right) \cdot z}{\color{blue}{x - y \cdot \sqrt{z}}} \]
    5. Applied egg-rr30.3%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot x - \left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}} \]
    6. Step-by-step derivation
      1. div-sub30.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x \cdot x}{x - y \cdot \sqrt{z}} - \frac{\left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}\right)} \]
      2. associate-/l*74.0%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{x}{\frac{x - y \cdot \sqrt{z}}{x}}} - \frac{\left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}\right) \]
      3. associate-*r*77.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{x - y \cdot \sqrt{z}}{x}} - \frac{\color{blue}{y \cdot \left(y \cdot z\right)}}{x - y \cdot \sqrt{z}}\right) \]
      4. frac-2neg77.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{x - y \cdot \sqrt{z}}{x}} - \color{blue}{\frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}}\right) \]
      5. sub-neg77.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{x + \left(-y \cdot \sqrt{z}\right)}}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
      6. +-commutative77.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{\left(-y \cdot \sqrt{z}\right) + x}}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
      7. distribute-rgt-neg-in77.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{y \cdot \left(-\sqrt{z}\right)} + x}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
      8. fma-def77.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
      9. distribute-lft-neg-in77.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \frac{\color{blue}{\left(-y\right) \cdot \left(y \cdot z\right)}}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
      10. neg-mul-177.8%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \frac{\left(-y\right) \cdot \left(y \cdot z\right)}{\color{blue}{-1 \cdot \left(x - y \cdot \sqrt{z}\right)}}\right) \]
      11. times-frac89.0%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \color{blue}{\frac{-y}{-1} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}}\right) \]
      12. metadata-eval89.0%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \frac{-y}{\color{blue}{-1}} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}\right) \]
      13. frac-2neg89.0%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \color{blue}{\frac{y}{1}} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}\right) \]
      14. /-rgt-identity89.0%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \color{blue}{y} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}\right) \]
      15. sub-neg89.0%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - y \cdot \frac{y \cdot z}{\color{blue}{x + \left(-y \cdot \sqrt{z}\right)}}\right) \]
      16. +-commutative89.0%

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - y \cdot \frac{y \cdot z}{\color{blue}{\left(-y \cdot \sqrt{z}\right) + x}}\right) \]
    7. Applied egg-rr89.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - y \cdot \frac{y \cdot z}{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}\right)} \]
    8. Taylor expanded in y around 0 87.9%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\color{blue}{1}} - y \cdot \frac{y \cdot z}{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}\right) \]
    9. Taylor expanded in y around 0 87.3%

      \[\leadsto 0.5 \cdot \left(\frac{x}{1} - y \cdot \color{blue}{\frac{y \cdot z}{x}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*89.3%

        \[\leadsto 0.5 \cdot \left(\frac{x}{1} - y \cdot \color{blue}{\frac{y}{\frac{x}{z}}}\right) \]
    11. Simplified89.3%

      \[\leadsto 0.5 \cdot \left(\frac{x}{1} - y \cdot \color{blue}{\frac{y}{\frac{x}{z}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{-11}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq 1.86 \cdot 10^{+55}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \sqrt{z}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x - y \cdot \frac{y}{\frac{x}{z}}\right)\\ \end{array} \]

Alternative 3: 53.3% accurate, 9.9× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \left(x - \frac{y}{x} \cdot \left(y \cdot z\right)\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* 0.5 (- x (* (/ y x) (* y z)))))
double code(double x, double y, double z) {
	return 0.5 * (x - ((y / x) * (y * z)));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.5d0 * (x - ((y / x) * (y * z)))
end function
public static double code(double x, double y, double z) {
	return 0.5 * (x - ((y / x) * (y * z)));
}
def code(x, y, z):
	return 0.5 * (x - ((y / x) * (y * z)))
function code(x, y, z)
	return Float64(0.5 * Float64(x - Float64(Float64(y / x) * Float64(y * z))))
end
function tmp = code(x, y, z)
	tmp = 0.5 * (x - ((y / x) * (y * z)));
end
code[x_, y_, z_] := N[(0.5 * N[(x - N[(N[(y / x), $MachinePrecision] * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \left(x - \frac{y}{x} \cdot \left(y \cdot z\right)\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  2. Step-by-step derivation
    1. metadata-eval99.8%

      \[\leadsto \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(x + y \cdot \sqrt{z}\right)} \]
  4. Step-by-step derivation
    1. cancel-sign-sub99.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(x - \left(-y\right) \cdot \sqrt{z}\right)} \]
    2. distribute-lft-neg-in99.8%

      \[\leadsto 0.5 \cdot \left(x - \color{blue}{\left(-y \cdot \sqrt{z}\right)}\right) \]
    3. flip--53.9%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot x - \left(-y \cdot \sqrt{z}\right) \cdot \left(-y \cdot \sqrt{z}\right)}{x + \left(-y \cdot \sqrt{z}\right)}} \]
    4. sqr-neg53.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \color{blue}{\left(y \cdot \sqrt{z}\right) \cdot \left(y \cdot \sqrt{z}\right)}}{x + \left(-y \cdot \sqrt{z}\right)} \]
    5. swap-sqr49.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \color{blue}{\left(y \cdot y\right) \cdot \left(\sqrt{z} \cdot \sqrt{z}\right)}}{x + \left(-y \cdot \sqrt{z}\right)} \]
    6. rem-square-sqrt49.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \left(y \cdot y\right) \cdot \color{blue}{z}}{x + \left(-y \cdot \sqrt{z}\right)} \]
    7. sub-neg49.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \left(y \cdot y\right) \cdot z}{\color{blue}{x - y \cdot \sqrt{z}}} \]
  5. Applied egg-rr49.9%

    \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot x - \left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}} \]
  6. Step-by-step derivation
    1. div-sub49.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x \cdot x}{x - y \cdot \sqrt{z}} - \frac{\left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}\right)} \]
    2. associate-*r*53.8%

      \[\leadsto 0.5 \cdot \left(\frac{x \cdot x}{x - y \cdot \sqrt{z}} - \frac{\color{blue}{y \cdot \left(y \cdot z\right)}}{x - y \cdot \sqrt{z}}\right) \]
    3. *-commutative53.8%

      \[\leadsto 0.5 \cdot \left(\frac{x \cdot x}{x - y \cdot \sqrt{z}} - \frac{\color{blue}{\left(y \cdot z\right) \cdot y}}{x - y \cdot \sqrt{z}}\right) \]
    4. associate-/l*64.6%

      \[\leadsto 0.5 \cdot \left(\frac{x \cdot x}{x - y \cdot \sqrt{z}} - \color{blue}{\frac{y \cdot z}{\frac{x - y \cdot \sqrt{z}}{y}}}\right) \]
    5. frac-sub41.4%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{\left(x \cdot x\right) \cdot \frac{x - y \cdot \sqrt{z}}{y} - \left(x - y \cdot \sqrt{z}\right) \cdot \left(y \cdot z\right)}{\left(x - y \cdot \sqrt{z}\right) \cdot \frac{x - y \cdot \sqrt{z}}{y}}} \]
    6. frac-2neg41.4%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{-\left(\left(x \cdot x\right) \cdot \frac{x - y \cdot \sqrt{z}}{y} - \left(x - y \cdot \sqrt{z}\right) \cdot \left(y \cdot z\right)\right)}{-\left(x - y \cdot \sqrt{z}\right) \cdot \frac{x - y \cdot \sqrt{z}}{y}}} \]
    7. neg-mul-141.4%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{-1 \cdot \left(\left(x \cdot x\right) \cdot \frac{x - y \cdot \sqrt{z}}{y} - \left(x - y \cdot \sqrt{z}\right) \cdot \left(y \cdot z\right)\right)}}{-\left(x - y \cdot \sqrt{z}\right) \cdot \frac{x - y \cdot \sqrt{z}}{y}} \]
    8. distribute-lft-neg-in41.4%

      \[\leadsto 0.5 \cdot \frac{-1 \cdot \left(\left(x \cdot x\right) \cdot \frac{x - y \cdot \sqrt{z}}{y} - \left(x - y \cdot \sqrt{z}\right) \cdot \left(y \cdot z\right)\right)}{\color{blue}{\left(-\left(x - y \cdot \sqrt{z}\right)\right) \cdot \frac{x - y \cdot \sqrt{z}}{y}}} \]
    9. times-frac39.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{-1}{-\left(x - y \cdot \sqrt{z}\right)} \cdot \frac{\left(x \cdot x\right) \cdot \frac{x - y \cdot \sqrt{z}}{y} - \left(x - y \cdot \sqrt{z}\right) \cdot \left(y \cdot z\right)}{\frac{x - y \cdot \sqrt{z}}{y}}\right)} \]
  7. Applied egg-rr53.7%

    \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{1}{\mathsf{fma}\left(y, -\sqrt{z}, x\right)} \cdot \left(\frac{x \cdot x}{1} \cdot 1 - 1 \cdot \frac{y \cdot z}{\frac{1}{y}}\right)\right)} \]
  8. Taylor expanded in y around 0 26.8%

    \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{1}{x}} \cdot \left(\frac{x \cdot x}{1} \cdot 1 - 1 \cdot \frac{y \cdot z}{\frac{1}{y}}\right)\right) \]
  9. Taylor expanded in x around 0 44.3%

    \[\leadsto 0.5 \cdot \color{blue}{\left(x + -1 \cdot \frac{{y}^{2} \cdot z}{x}\right)} \]
  10. Step-by-step derivation
    1. *-lft-identity44.3%

      \[\leadsto 0.5 \cdot \left(\color{blue}{1 \cdot x} + -1 \cdot \frac{{y}^{2} \cdot z}{x}\right) \]
    2. fma-def44.3%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{fma}\left(1, x, -1 \cdot \frac{{y}^{2} \cdot z}{x}\right)} \]
    3. mul-1-neg44.3%

      \[\leadsto 0.5 \cdot \mathsf{fma}\left(1, x, \color{blue}{-\frac{{y}^{2} \cdot z}{x}}\right) \]
    4. fma-neg44.3%

      \[\leadsto 0.5 \cdot \color{blue}{\left(1 \cdot x - \frac{{y}^{2} \cdot z}{x}\right)} \]
    5. *-lft-identity44.3%

      \[\leadsto 0.5 \cdot \left(\color{blue}{x} - \frac{{y}^{2} \cdot z}{x}\right) \]
    6. unpow244.3%

      \[\leadsto 0.5 \cdot \left(x - \frac{\color{blue}{\left(y \cdot y\right)} \cdot z}{x}\right) \]
    7. associate-*r*45.9%

      \[\leadsto 0.5 \cdot \left(x - \frac{\color{blue}{y \cdot \left(y \cdot z\right)}}{x}\right) \]
    8. *-lft-identity45.9%

      \[\leadsto 0.5 \cdot \left(x - \frac{\color{blue}{1 \cdot \left(y \cdot \left(y \cdot z\right)\right)}}{x}\right) \]
    9. associate-*l/45.9%

      \[\leadsto 0.5 \cdot \left(x - \color{blue}{\frac{1}{x} \cdot \left(y \cdot \left(y \cdot z\right)\right)}\right) \]
    10. associate-*r*48.6%

      \[\leadsto 0.5 \cdot \left(x - \color{blue}{\left(\frac{1}{x} \cdot y\right) \cdot \left(y \cdot z\right)}\right) \]
    11. *-commutative48.6%

      \[\leadsto 0.5 \cdot \left(x - \color{blue}{\left(y \cdot \frac{1}{x}\right)} \cdot \left(y \cdot z\right)\right) \]
    12. associate-*r/48.6%

      \[\leadsto 0.5 \cdot \left(x - \color{blue}{\frac{y \cdot 1}{x}} \cdot \left(y \cdot z\right)\right) \]
    13. *-rgt-identity48.6%

      \[\leadsto 0.5 \cdot \left(x - \frac{\color{blue}{y}}{x} \cdot \left(y \cdot z\right)\right) \]
  11. Simplified48.6%

    \[\leadsto 0.5 \cdot \color{blue}{\left(x - \frac{y}{x} \cdot \left(y \cdot z\right)\right)} \]
  12. Final simplification48.6%

    \[\leadsto 0.5 \cdot \left(x - \frac{y}{x} \cdot \left(y \cdot z\right)\right) \]

Alternative 4: 53.3% accurate, 9.9× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \left(x - y \cdot \frac{y}{\frac{x}{z}}\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* 0.5 (- x (* y (/ y (/ x z))))))
double code(double x, double y, double z) {
	return 0.5 * (x - (y * (y / (x / z))));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.5d0 * (x - (y * (y / (x / z))))
end function
public static double code(double x, double y, double z) {
	return 0.5 * (x - (y * (y / (x / z))));
}
def code(x, y, z):
	return 0.5 * (x - (y * (y / (x / z))))
function code(x, y, z)
	return Float64(0.5 * Float64(x - Float64(y * Float64(y / Float64(x / z)))))
end
function tmp = code(x, y, z)
	tmp = 0.5 * (x - (y * (y / (x / z))));
end
code[x_, y_, z_] := N[(0.5 * N[(x - N[(y * N[(y / N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \left(x - y \cdot \frac{y}{\frac{x}{z}}\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  2. Step-by-step derivation
    1. metadata-eval99.8%

      \[\leadsto \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(x + y \cdot \sqrt{z}\right)} \]
  4. Step-by-step derivation
    1. cancel-sign-sub99.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(x - \left(-y\right) \cdot \sqrt{z}\right)} \]
    2. distribute-lft-neg-in99.8%

      \[\leadsto 0.5 \cdot \left(x - \color{blue}{\left(-y \cdot \sqrt{z}\right)}\right) \]
    3. flip--53.9%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot x - \left(-y \cdot \sqrt{z}\right) \cdot \left(-y \cdot \sqrt{z}\right)}{x + \left(-y \cdot \sqrt{z}\right)}} \]
    4. sqr-neg53.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \color{blue}{\left(y \cdot \sqrt{z}\right) \cdot \left(y \cdot \sqrt{z}\right)}}{x + \left(-y \cdot \sqrt{z}\right)} \]
    5. swap-sqr49.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \color{blue}{\left(y \cdot y\right) \cdot \left(\sqrt{z} \cdot \sqrt{z}\right)}}{x + \left(-y \cdot \sqrt{z}\right)} \]
    6. rem-square-sqrt49.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \left(y \cdot y\right) \cdot \color{blue}{z}}{x + \left(-y \cdot \sqrt{z}\right)} \]
    7. sub-neg49.9%

      \[\leadsto 0.5 \cdot \frac{x \cdot x - \left(y \cdot y\right) \cdot z}{\color{blue}{x - y \cdot \sqrt{z}}} \]
  5. Applied egg-rr49.9%

    \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot x - \left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}} \]
  6. Step-by-step derivation
    1. div-sub49.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x \cdot x}{x - y \cdot \sqrt{z}} - \frac{\left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}\right)} \]
    2. associate-/l*67.2%

      \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{x}{\frac{x - y \cdot \sqrt{z}}{x}}} - \frac{\left(y \cdot y\right) \cdot z}{x - y \cdot \sqrt{z}}\right) \]
    3. associate-*r*72.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{x - y \cdot \sqrt{z}}{x}} - \frac{\color{blue}{y \cdot \left(y \cdot z\right)}}{x - y \cdot \sqrt{z}}\right) \]
    4. frac-2neg72.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{x - y \cdot \sqrt{z}}{x}} - \color{blue}{\frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}}\right) \]
    5. sub-neg72.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{x + \left(-y \cdot \sqrt{z}\right)}}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
    6. +-commutative72.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{\left(-y \cdot \sqrt{z}\right) + x}}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
    7. distribute-rgt-neg-in72.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{y \cdot \left(-\sqrt{z}\right)} + x}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
    8. fma-def72.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\color{blue}{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}}{x}} - \frac{-y \cdot \left(y \cdot z\right)}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
    9. distribute-lft-neg-in72.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \frac{\color{blue}{\left(-y\right) \cdot \left(y \cdot z\right)}}{-\left(x - y \cdot \sqrt{z}\right)}\right) \]
    10. neg-mul-172.1%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \frac{\left(-y\right) \cdot \left(y \cdot z\right)}{\color{blue}{-1 \cdot \left(x - y \cdot \sqrt{z}\right)}}\right) \]
    11. times-frac87.0%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \color{blue}{\frac{-y}{-1} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}}\right) \]
    12. metadata-eval87.0%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \frac{-y}{\color{blue}{-1}} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}\right) \]
    13. frac-2neg87.0%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \color{blue}{\frac{y}{1}} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}\right) \]
    14. /-rgt-identity87.0%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - \color{blue}{y} \cdot \frac{y \cdot z}{x - y \cdot \sqrt{z}}\right) \]
    15. sub-neg87.0%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - y \cdot \frac{y \cdot z}{\color{blue}{x + \left(-y \cdot \sqrt{z}\right)}}\right) \]
    16. +-commutative87.0%

      \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - y \cdot \frac{y \cdot z}{\color{blue}{\left(-y \cdot \sqrt{z}\right) + x}}\right) \]
  7. Applied egg-rr87.0%

    \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{\frac{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}{x}} - y \cdot \frac{y \cdot z}{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}\right)} \]
  8. Taylor expanded in y around 0 85.5%

    \[\leadsto 0.5 \cdot \left(\frac{x}{\color{blue}{1}} - y \cdot \frac{y \cdot z}{\mathsf{fma}\left(y, -\sqrt{z}, x\right)}\right) \]
  9. Taylor expanded in y around 0 48.6%

    \[\leadsto 0.5 \cdot \left(\frac{x}{1} - y \cdot \color{blue}{\frac{y \cdot z}{x}}\right) \]
  10. Step-by-step derivation
    1. associate-/l*49.5%

      \[\leadsto 0.5 \cdot \left(\frac{x}{1} - y \cdot \color{blue}{\frac{y}{\frac{x}{z}}}\right) \]
  11. Simplified49.5%

    \[\leadsto 0.5 \cdot \left(\frac{x}{1} - y \cdot \color{blue}{\frac{y}{\frac{x}{z}}}\right) \]
  12. Final simplification49.5%

    \[\leadsto 0.5 \cdot \left(x - y \cdot \frac{y}{\frac{x}{z}}\right) \]

Alternative 5: 50.5% accurate, 36.3× speedup?

\[\begin{array}{l} \\ 0.5 \cdot x \end{array} \]
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
	return 0.5 * x;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
	return 0.5 * x;
}
def code(x, y, z):
	return 0.5 * x
function code(x, y, z)
	return Float64(0.5 * x)
end
function tmp = code(x, y, z)
	tmp = 0.5 * x;
end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot x
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  2. Step-by-step derivation
    1. metadata-eval99.8%

      \[\leadsto \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(x + y \cdot \sqrt{z}\right)} \]
  4. Taylor expanded in x around inf 47.5%

    \[\leadsto 0.5 \cdot \color{blue}{x} \]
  5. Final simplification47.5%

    \[\leadsto 0.5 \cdot x \]

Reproduce

?
herbie shell --seed 2023297 
(FPCore (x y z)
  :name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, B"
  :precision binary64
  (* (/ 1.0 2.0) (+ x (* y (sqrt z)))))