Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A

Percentage Accurate: 99.8% → 99.8%
Time: 8.9s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ x \cdot \cos y - z \cdot \sin y \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
	return (x * cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
	return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z):
	return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z)
	return Float64(Float64(x * cos(y)) - Float64(z * sin(y)))
end
function tmp = code(x, y, z)
	tmp = (x * cos(y)) - (z * sin(y));
end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \cos y - z \cdot \sin y
\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 8 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} \\ x \cdot \cos y - z \cdot \sin y \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
	return (x * cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
	return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z):
	return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z)
	return Float64(Float64(x * cos(y)) - Float64(z * sin(y)))
end
function tmp = code(x, y, z)
	tmp = (x * cos(y)) - (z * sin(y));
end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \cos y - z \cdot \sin y
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

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

\\
x \cdot \cos y - z \cdot \sin y
\end{array}
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Final simplification99.8%

    \[\leadsto x \cdot \cos y - z \cdot \sin y \]

Alternative 2: 75.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ t_1 := z \cdot \left(-\sin y\right)\\ \mathbf{if}\;y \leq -5.5 \cdot 10^{+230}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{+166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{+58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{+19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -0.12 \lor \neg \left(y \leq 0.0048\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \left(x \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) - y \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (cos y))) (t_1 (* z (- (sin y)))))
   (if (<= y -5.5e+230)
     t_0
     (if (<= y -4.1e+207)
       t_1
       (if (<= y -1.5e+166)
         t_0
         (if (<= y -1.2e+58)
           t_1
           (if (<= y -1.25e+19)
             t_0
             (if (or (<= y -0.12) (not (<= y 0.0048)))
               t_1
               (+ x (- (* x (* (* y y) -0.5)) (* y z)))))))))))
double code(double x, double y, double z) {
	double t_0 = x * cos(y);
	double t_1 = z * -sin(y);
	double tmp;
	if (y <= -5.5e+230) {
		tmp = t_0;
	} else if (y <= -4.1e+207) {
		tmp = t_1;
	} else if (y <= -1.5e+166) {
		tmp = t_0;
	} else if (y <= -1.2e+58) {
		tmp = t_1;
	} else if (y <= -1.25e+19) {
		tmp = t_0;
	} else if ((y <= -0.12) || !(y <= 0.0048)) {
		tmp = t_1;
	} else {
		tmp = x + ((x * ((y * y) * -0.5)) - (y * 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x * cos(y)
    t_1 = z * -sin(y)
    if (y <= (-5.5d+230)) then
        tmp = t_0
    else if (y <= (-4.1d+207)) then
        tmp = t_1
    else if (y <= (-1.5d+166)) then
        tmp = t_0
    else if (y <= (-1.2d+58)) then
        tmp = t_1
    else if (y <= (-1.25d+19)) then
        tmp = t_0
    else if ((y <= (-0.12d0)) .or. (.not. (y <= 0.0048d0))) then
        tmp = t_1
    else
        tmp = x + ((x * ((y * y) * (-0.5d0))) - (y * z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * Math.cos(y);
	double t_1 = z * -Math.sin(y);
	double tmp;
	if (y <= -5.5e+230) {
		tmp = t_0;
	} else if (y <= -4.1e+207) {
		tmp = t_1;
	} else if (y <= -1.5e+166) {
		tmp = t_0;
	} else if (y <= -1.2e+58) {
		tmp = t_1;
	} else if (y <= -1.25e+19) {
		tmp = t_0;
	} else if ((y <= -0.12) || !(y <= 0.0048)) {
		tmp = t_1;
	} else {
		tmp = x + ((x * ((y * y) * -0.5)) - (y * z));
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.cos(y)
	t_1 = z * -math.sin(y)
	tmp = 0
	if y <= -5.5e+230:
		tmp = t_0
	elif y <= -4.1e+207:
		tmp = t_1
	elif y <= -1.5e+166:
		tmp = t_0
	elif y <= -1.2e+58:
		tmp = t_1
	elif y <= -1.25e+19:
		tmp = t_0
	elif (y <= -0.12) or not (y <= 0.0048):
		tmp = t_1
	else:
		tmp = x + ((x * ((y * y) * -0.5)) - (y * z))
	return tmp
function code(x, y, z)
	t_0 = Float64(x * cos(y))
	t_1 = Float64(z * Float64(-sin(y)))
	tmp = 0.0
	if (y <= -5.5e+230)
		tmp = t_0;
	elseif (y <= -4.1e+207)
		tmp = t_1;
	elseif (y <= -1.5e+166)
		tmp = t_0;
	elseif (y <= -1.2e+58)
		tmp = t_1;
	elseif (y <= -1.25e+19)
		tmp = t_0;
	elseif ((y <= -0.12) || !(y <= 0.0048))
		tmp = t_1;
	else
		tmp = Float64(x + Float64(Float64(x * Float64(Float64(y * y) * -0.5)) - Float64(y * z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * cos(y);
	t_1 = z * -sin(y);
	tmp = 0.0;
	if (y <= -5.5e+230)
		tmp = t_0;
	elseif (y <= -4.1e+207)
		tmp = t_1;
	elseif (y <= -1.5e+166)
		tmp = t_0;
	elseif (y <= -1.2e+58)
		tmp = t_1;
	elseif (y <= -1.25e+19)
		tmp = t_0;
	elseif ((y <= -0.12) || ~((y <= 0.0048)))
		tmp = t_1;
	else
		tmp = x + ((x * ((y * y) * -0.5)) - (y * z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[y, -5.5e+230], t$95$0, If[LessEqual[y, -4.1e+207], t$95$1, If[LessEqual[y, -1.5e+166], t$95$0, If[LessEqual[y, -1.2e+58], t$95$1, If[LessEqual[y, -1.25e+19], t$95$0, If[Or[LessEqual[y, -0.12], N[Not[LessEqual[y, 0.0048]], $MachinePrecision]], t$95$1, N[(x + N[(N[(x * N[(N[(y * y), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := z \cdot \left(-\sin y\right)\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+230}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -4.1 \cdot 10^{+207}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -1.5 \cdot 10^{+166}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.2 \cdot 10^{+58}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -1.25 \cdot 10^{+19}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -0.12 \lor \neg \left(y \leq 0.0048\right):\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.49999999999999979e230 or -4.1e207 < y < -1.49999999999999999e166 or -1.2e58 < y < -1.25e19

    1. Initial program 99.6%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in x around inf 78.7%

      \[\leadsto \color{blue}{x \cdot \cos y} \]

    if -5.49999999999999979e230 < y < -4.1e207 or -1.49999999999999999e166 < y < -1.2e58 or -1.25e19 < y < -0.12 or 0.00479999999999999958 < y

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in x around 0 72.3%

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right)} \]
    3. Step-by-step derivation
      1. associate-*r*72.3%

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot \sin y} \]
      2. neg-mul-172.3%

        \[\leadsto \color{blue}{\left(-z\right)} \cdot \sin y \]
    4. Simplified72.3%

      \[\leadsto \color{blue}{\left(-z\right) \cdot \sin y} \]

    if -0.12 < y < 0.00479999999999999958

    1. Initial program 100.0%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 99.7%

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

        \[\leadsto x + \color{blue}{\left(-0.5 \cdot \left(x \cdot {y}^{2}\right) + -1 \cdot \left(y \cdot z\right)\right)} \]
      2. mul-1-neg99.7%

        \[\leadsto x + \left(-0.5 \cdot \left(x \cdot {y}^{2}\right) + \color{blue}{\left(-y \cdot z\right)}\right) \]
      3. unsub-neg99.7%

        \[\leadsto x + \color{blue}{\left(-0.5 \cdot \left(x \cdot {y}^{2}\right) - y \cdot z\right)} \]
      4. *-commutative99.7%

        \[\leadsto x + \left(\color{blue}{\left(x \cdot {y}^{2}\right) \cdot -0.5} - y \cdot z\right) \]
      5. associate-*l*99.7%

        \[\leadsto x + \left(\color{blue}{x \cdot \left({y}^{2} \cdot -0.5\right)} - y \cdot z\right) \]
      6. unpow299.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{+230}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+207}:\\ \;\;\;\;z \cdot \left(-\sin y\right)\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{+166}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{+58}:\\ \;\;\;\;z \cdot \left(-\sin y\right)\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{+19}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;y \leq -0.12 \lor \neg \left(y \leq 0.0048\right):\\ \;\;\;\;z \cdot \left(-\sin y\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(x \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) - y \cdot z\right)\\ \end{array} \]

Alternative 3: 85.0% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{-152} \lor \neg \left(z \leq 2.5 \cdot 10^{-64}\right):\\ \;\;\;\;x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -4.8e-152) (not (<= z 2.5e-64)))
   (- x (* z (sin y)))
   (* x (cos y))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -4.8e-152) || !(z <= 2.5e-64)) {
		tmp = x - (z * sin(y));
	} else {
		tmp = x * cos(y);
	}
	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 ((z <= (-4.8d-152)) .or. (.not. (z <= 2.5d-64))) then
        tmp = x - (z * sin(y))
    else
        tmp = x * cos(y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -4.8e-152) || !(z <= 2.5e-64)) {
		tmp = x - (z * Math.sin(y));
	} else {
		tmp = x * Math.cos(y);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -4.8e-152) or not (z <= 2.5e-64):
		tmp = x - (z * math.sin(y))
	else:
		tmp = x * math.cos(y)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -4.8e-152) || !(z <= 2.5e-64))
		tmp = Float64(x - Float64(z * sin(y)));
	else
		tmp = Float64(x * cos(y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -4.8e-152) || ~((z <= 2.5e-64)))
		tmp = x - (z * sin(y));
	else
		tmp = x * cos(y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e-152], N[Not[LessEqual[z, 2.5e-64]], $MachinePrecision]], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-152} \lor \neg \left(z \leq 2.5 \cdot 10^{-64}\right):\\
\;\;\;\;x - z \cdot \sin y\\

\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.8e-152 or 2.50000000000000017e-64 < z

    1. Initial program 99.8%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 90.1%

      \[\leadsto \color{blue}{x} - z \cdot \sin y \]

    if -4.8e-152 < z < 2.50000000000000017e-64

    1. Initial program 99.8%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in x around inf 90.0%

      \[\leadsto \color{blue}{x \cdot \cos y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{-152} \lor \neg \left(z \leq 2.5 \cdot 10^{-64}\right):\\ \;\;\;\;x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \]

Alternative 4: 74.9% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.00205 \lor \neg \left(y \leq 420000\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + \left(x \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) - y \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -0.00205) (not (<= y 420000.0)))
   (* x (cos y))
   (+ x (- (* x (* (* y y) -0.5)) (* y z)))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -0.00205) || !(y <= 420000.0)) {
		tmp = x * cos(y);
	} else {
		tmp = x + ((x * ((y * y) * -0.5)) - (y * 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 ((y <= (-0.00205d0)) .or. (.not. (y <= 420000.0d0))) then
        tmp = x * cos(y)
    else
        tmp = x + ((x * ((y * y) * (-0.5d0))) - (y * z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -0.00205) || !(y <= 420000.0)) {
		tmp = x * Math.cos(y);
	} else {
		tmp = x + ((x * ((y * y) * -0.5)) - (y * z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -0.00205) or not (y <= 420000.0):
		tmp = x * math.cos(y)
	else:
		tmp = x + ((x * ((y * y) * -0.5)) - (y * z))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -0.00205) || !(y <= 420000.0))
		tmp = Float64(x * cos(y));
	else
		tmp = Float64(x + Float64(Float64(x * Float64(Float64(y * y) * -0.5)) - Float64(y * z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -0.00205) || ~((y <= 420000.0)))
		tmp = x * cos(y);
	else
		tmp = x + ((x * ((y * y) * -0.5)) - (y * z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00205], N[Not[LessEqual[y, 420000.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(x * N[(N[(y * y), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00205 \lor \neg \left(y \leq 420000\right):\\
\;\;\;\;x \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.00205000000000000017 or 4.2e5 < y

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in x around inf 45.7%

      \[\leadsto \color{blue}{x \cdot \cos y} \]

    if -0.00205000000000000017 < y < 4.2e5

    1. Initial program 100.0%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 97.1%

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

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

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

        \[\leadsto x + \color{blue}{\left(-0.5 \cdot \left(x \cdot {y}^{2}\right) - y \cdot z\right)} \]
      4. *-commutative97.1%

        \[\leadsto x + \left(\color{blue}{\left(x \cdot {y}^{2}\right) \cdot -0.5} - y \cdot z\right) \]
      5. associate-*l*97.1%

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

        \[\leadsto x + \left(x \cdot \left(\color{blue}{\left(y \cdot y\right)} \cdot -0.5\right) - y \cdot z\right) \]
    4. Simplified97.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.00205 \lor \neg \left(y \leq 420000\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + \left(x \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) - y \cdot z\right)\\ \end{array} \]

Alternative 5: 40.4% accurate, 16.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+18}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.22 \cdot 10^{-29} \lor \neg \left(x \leq -1.62 \cdot 10^{-199}\right) \land x \leq 1.7 \cdot 10^{-145}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.25e+18)
   x
   (if (or (<= x -1.22e-29) (and (not (<= x -1.62e-199)) (<= x 1.7e-145)))
     (* y (- z))
     x)))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.25e+18) {
		tmp = x;
	} else if ((x <= -1.22e-29) || (!(x <= -1.62e-199) && (x <= 1.7e-145))) {
		tmp = y * -z;
	} else {
		tmp = x;
	}
	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 <= (-1.25d+18)) then
        tmp = x
    else if ((x <= (-1.22d-29)) .or. (.not. (x <= (-1.62d-199))) .and. (x <= 1.7d-145)) then
        tmp = y * -z
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.25e+18) {
		tmp = x;
	} else if ((x <= -1.22e-29) || (!(x <= -1.62e-199) && (x <= 1.7e-145))) {
		tmp = y * -z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.25e+18:
		tmp = x
	elif (x <= -1.22e-29) or (not (x <= -1.62e-199) and (x <= 1.7e-145)):
		tmp = y * -z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.25e+18)
		tmp = x;
	elseif ((x <= -1.22e-29) || (!(x <= -1.62e-199) && (x <= 1.7e-145)))
		tmp = Float64(y * Float64(-z));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.25e+18)
		tmp = x;
	elseif ((x <= -1.22e-29) || (~((x <= -1.62e-199)) && (x <= 1.7e-145)))
		tmp = y * -z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.25e+18], x, If[Or[LessEqual[x, -1.22e-29], And[N[Not[LessEqual[x, -1.62e-199]], $MachinePrecision], LessEqual[x, 1.7e-145]]], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+18}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq -1.22 \cdot 10^{-29} \lor \neg \left(x \leq -1.62 \cdot 10^{-199}\right) \land x \leq 1.7 \cdot 10^{-145}:\\
\;\;\;\;y \cdot \left(-z\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.25e18 or -1.21999999999999996e-29 < x < -1.62000000000000008e-199 or 1.6999999999999999e-145 < x

    1. Initial program 99.8%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 51.5%

      \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg51.5%

        \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \]
      2. unsub-neg51.5%

        \[\leadsto \color{blue}{x - y \cdot z} \]
    4. Simplified51.5%

      \[\leadsto \color{blue}{x - y \cdot z} \]
    5. Taylor expanded in x around inf 44.3%

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

    if -1.25e18 < x < -1.21999999999999996e-29 or -1.62000000000000008e-199 < x < 1.6999999999999999e-145

    1. Initial program 99.8%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 50.0%

      \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg50.0%

        \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \]
      2. unsub-neg50.0%

        \[\leadsto \color{blue}{x - y \cdot z} \]
    4. Simplified50.0%

      \[\leadsto \color{blue}{x - y \cdot z} \]
    5. Taylor expanded in x around 0 43.1%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification44.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+18}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.22 \cdot 10^{-29} \lor \neg \left(x \leq -1.62 \cdot 10^{-199}\right) \land x \leq 1.7 \cdot 10^{-145}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 6: 40.2% accurate, 16.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -1.25 \cdot 10^{+18}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{-196}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- z))))
   (if (<= x -1.25e+18)
     x
     (if (<= x -2.5e-29)
       t_0
       (if (<= x -6.6e-196) (+ x (* y z)) (if (<= x 1.8e-142) t_0 x))))))
double code(double x, double y, double z) {
	double t_0 = y * -z;
	double tmp;
	if (x <= -1.25e+18) {
		tmp = x;
	} else if (x <= -2.5e-29) {
		tmp = t_0;
	} else if (x <= -6.6e-196) {
		tmp = x + (y * z);
	} else if (x <= 1.8e-142) {
		tmp = t_0;
	} else {
		tmp = x;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = y * -z
    if (x <= (-1.25d+18)) then
        tmp = x
    else if (x <= (-2.5d-29)) then
        tmp = t_0
    else if (x <= (-6.6d-196)) then
        tmp = x + (y * z)
    else if (x <= 1.8d-142) then
        tmp = t_0
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * -z;
	double tmp;
	if (x <= -1.25e+18) {
		tmp = x;
	} else if (x <= -2.5e-29) {
		tmp = t_0;
	} else if (x <= -6.6e-196) {
		tmp = x + (y * z);
	} else if (x <= 1.8e-142) {
		tmp = t_0;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * -z
	tmp = 0
	if x <= -1.25e+18:
		tmp = x
	elif x <= -2.5e-29:
		tmp = t_0
	elif x <= -6.6e-196:
		tmp = x + (y * z)
	elif x <= 1.8e-142:
		tmp = t_0
	else:
		tmp = x
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(-z))
	tmp = 0.0
	if (x <= -1.25e+18)
		tmp = x;
	elseif (x <= -2.5e-29)
		tmp = t_0;
	elseif (x <= -6.6e-196)
		tmp = Float64(x + Float64(y * z));
	elseif (x <= 1.8e-142)
		tmp = t_0;
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * -z;
	tmp = 0.0;
	if (x <= -1.25e+18)
		tmp = x;
	elseif (x <= -2.5e-29)
		tmp = t_0;
	elseif (x <= -6.6e-196)
		tmp = x + (y * z);
	elseif (x <= 1.8e-142)
		tmp = t_0;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[x, -1.25e+18], x, If[LessEqual[x, -2.5e-29], t$95$0, If[LessEqual[x, -6.6e-196], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.8e-142], t$95$0, x]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;x \leq -1.25 \cdot 10^{+18}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq -2.5 \cdot 10^{-29}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -6.6 \cdot 10^{-196}:\\
\;\;\;\;x + y \cdot z\\

\mathbf{elif}\;x \leq 1.8 \cdot 10^{-142}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.25e18 or 1.8e-142 < x

    1. Initial program 99.8%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 51.7%

      \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg51.7%

        \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \]
      2. unsub-neg51.7%

        \[\leadsto \color{blue}{x - y \cdot z} \]
    4. Simplified51.7%

      \[\leadsto \color{blue}{x - y \cdot z} \]
    5. Taylor expanded in x around inf 45.7%

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

    if -1.25e18 < x < -2.49999999999999993e-29 or -6.59999999999999997e-196 < x < 1.8e-142

    1. Initial program 99.8%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 50.0%

      \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg50.0%

        \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \]
      2. unsub-neg50.0%

        \[\leadsto \color{blue}{x - y \cdot z} \]
    4. Simplified50.0%

      \[\leadsto \color{blue}{x - y \cdot z} \]
    5. Taylor expanded in x around 0 43.1%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]

    if -2.49999999999999993e-29 < x < -6.59999999999999997e-196

    1. Initial program 99.9%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Taylor expanded in y around 0 50.7%

      \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg50.7%

        \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \]
      2. unsub-neg50.7%

        \[\leadsto \color{blue}{x - y \cdot z} \]
    4. Simplified50.7%

      \[\leadsto \color{blue}{x - y \cdot z} \]
    5. Step-by-step derivation
      1. sub-neg50.7%

        \[\leadsto \color{blue}{x + \left(-y \cdot z\right)} \]
      2. +-commutative50.7%

        \[\leadsto \color{blue}{\left(-y \cdot z\right) + x} \]
      3. *-commutative50.7%

        \[\leadsto \left(-\color{blue}{z \cdot y}\right) + x \]
      4. distribute-lft-neg-in50.7%

        \[\leadsto \color{blue}{\left(-z\right) \cdot y} + x \]
      5. add-sqr-sqrt37.8%

        \[\leadsto \color{blue}{\left(\sqrt{-z} \cdot \sqrt{-z}\right)} \cdot y + x \]
      6. sqrt-unprod45.5%

        \[\leadsto \color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}} \cdot y + x \]
      7. sqr-neg45.5%

        \[\leadsto \sqrt{\color{blue}{z \cdot z}} \cdot y + x \]
      8. sqrt-unprod10.6%

        \[\leadsto \color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)} \cdot y + x \]
      9. add-sqr-sqrt38.3%

        \[\leadsto \color{blue}{z} \cdot y + x \]
    6. Applied egg-rr38.3%

      \[\leadsto \color{blue}{z \cdot y + x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification44.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+18}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-29}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{-196}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-142}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 7: 52.5% accurate, 41.4× speedup?

\[\begin{array}{l} \\ x - y \cdot z \end{array} \]
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
	return 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 = x - (y * z)
end function
public static double code(double x, double y, double z) {
	return x - (y * z);
}
def code(x, y, z):
	return x - (y * z)
function code(x, y, z)
	return Float64(x - Float64(y * z))
end
function tmp = code(x, y, z)
	tmp = x - (y * z);
end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x - y \cdot z
\end{array}
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Taylor expanded in y around 0 51.1%

    \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
  3. Step-by-step derivation
    1. mul-1-neg51.1%

      \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \]
    2. unsub-neg51.1%

      \[\leadsto \color{blue}{x - y \cdot z} \]
  4. Simplified51.1%

    \[\leadsto \color{blue}{x - y \cdot z} \]
  5. Final simplification51.1%

    \[\leadsto x - y \cdot z \]

Alternative 8: 38.9% accurate, 207.0× speedup?

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

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

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Taylor expanded in y around 0 51.1%

    \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
  3. Step-by-step derivation
    1. mul-1-neg51.1%

      \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \]
    2. unsub-neg51.1%

      \[\leadsto \color{blue}{x - y \cdot z} \]
  4. Simplified51.1%

    \[\leadsto \color{blue}{x - y \cdot z} \]
  5. Taylor expanded in x around inf 35.3%

    \[\leadsto \color{blue}{x} \]
  6. Final simplification35.3%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023290 
(FPCore (x y z)
  :name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
  :precision binary64
  (- (* x (cos y)) (* z (sin y))))