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

Percentage Accurate: 99.8% → 99.8%
Time: 8.8s
Alternatives: 10
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 10 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, 0.7× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma z (- (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
	return fma(z, -sin(y), (x * cos(y)));
}
function code(x, y, z)
	return fma(z, Float64(-sin(y)), Float64(x * cos(y)))
end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)
\end{array}
Derivation
  1. Initial program 99.7%

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Step-by-step derivation
    1. cancel-sign-sub-inv99.7%

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

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

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

      \[\leadsto \color{blue}{z \cdot \left(-\sin y\right)} + x \cdot \cos y \]
    5. sin-neg99.7%

      \[\leadsto z \cdot \color{blue}{\sin \left(-y\right)} + x \cdot \cos y \]
    6. fma-define99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \sin \left(-y\right), x \cdot \cos y\right)} \]
    7. sin-neg99.7%

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{-\sin y}, x \cdot \cos y\right) \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 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.7%

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 3: 84.9% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+183} \lor \neg \left(x \leq -2.65 \cdot 10^{+129}\right) \land \left(x \leq -2.6 \cdot 10^{+22} \lor \neg \left(x \leq 7.4 \cdot 10^{-13}\right)\right):\\
\;\;\;\;x \cdot \cos y\\

\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.5000000000000003e183 or -2.6499999999999999e129 < x < -2.6e22 or 7.39999999999999977e-13 < x

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 91.7%

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

    if -9.5000000000000003e183 < x < -2.6499999999999999e129 or -2.6e22 < x < 7.39999999999999977e-13

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cbrt-cube64.7%

        \[\leadsto x \cdot \cos y - \color{blue}{\sqrt[3]{\left(\left(z \cdot \sin y\right) \cdot \left(z \cdot \sin y\right)\right) \cdot \left(z \cdot \sin y\right)}} \]
      2. pow364.7%

        \[\leadsto x \cdot \cos y - \sqrt[3]{\color{blue}{{\left(z \cdot \sin y\right)}^{3}}} \]
    4. Applied egg-rr64.7%

      \[\leadsto x \cdot \cos y - \color{blue}{\sqrt[3]{{\left(z \cdot \sin y\right)}^{3}}} \]
    5. Taylor expanded in y around 0 59.7%

      \[\leadsto \color{blue}{x} - \sqrt[3]{{\left(z \cdot \sin y\right)}^{3}} \]
    6. Step-by-step derivation
      1. rem-cbrt-cube93.6%

        \[\leadsto x - \color{blue}{z \cdot \sin y} \]
      2. *-commutative93.6%

        \[\leadsto x - \color{blue}{\sin y \cdot z} \]
    7. Applied egg-rr93.6%

      \[\leadsto x - \color{blue}{\sin y \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+183} \lor \neg \left(x \leq -2.65 \cdot 10^{+129}\right) \land \left(x \leq -2.6 \cdot 10^{+22} \lor \neg \left(x \leq 7.4 \cdot 10^{-13}\right)\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.9% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+183} \lor \neg \left(x \leq -5 \cdot 10^{+135} \lor \neg \left(x \leq -1.75 \cdot 10^{+21}\right) \land x \leq 10^{-11}\right):\\
\;\;\;\;x \cdot \cos y\\

\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -6.8e183 or -5.00000000000000029e135 < x < -1.75e21 or 9.99999999999999939e-12 < x

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 91.7%

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

    if -6.8e183 < x < -5.00000000000000029e135 or -1.75e21 < x < 9.99999999999999939e-12

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 93.6%

      \[\leadsto \color{blue}{x} - z \cdot \sin y \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.8 \cdot 10^{+183} \lor \neg \left(x \leq -5 \cdot 10^{+135} \lor \neg \left(x \leq -1.75 \cdot 10^{+21}\right) \land x \leq 10^{-11}\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.8% 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}\;x \leq -4.5 \cdot 10^{-29}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -4.4 \cdot 10^{-92}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-141}:\\ \;\;\;\;\mathsf{fma}\left(-y, z, x\right)\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-108}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (cos y))) (t_1 (* z (- (sin y)))))
   (if (<= x -4.5e-29)
     t_0
     (if (<= x -4.4e-92)
       t_1
       (if (<= x -2e-141) (fma (- y) z x) (if (<= x 2.1e-108) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = x * cos(y);
	double t_1 = z * -sin(y);
	double tmp;
	if (x <= -4.5e-29) {
		tmp = t_0;
	} else if (x <= -4.4e-92) {
		tmp = t_1;
	} else if (x <= -2e-141) {
		tmp = fma(-y, z, x);
	} else if (x <= 2.1e-108) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(x * cos(y))
	t_1 = Float64(z * Float64(-sin(y)))
	tmp = 0.0
	if (x <= -4.5e-29)
		tmp = t_0;
	elseif (x <= -4.4e-92)
		tmp = t_1;
	elseif (x <= -2e-141)
		tmp = fma(Float64(-y), z, x);
	elseif (x <= 2.1e-108)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return 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[x, -4.5e-29], t$95$0, If[LessEqual[x, -4.4e-92], t$95$1, If[LessEqual[x, -2e-141], N[((-y) * z + x), $MachinePrecision], If[LessEqual[x, 2.1e-108], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := z \cdot \left(-\sin y\right)\\
\mathbf{if}\;x \leq -4.5 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -4.4 \cdot 10^{-92}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq -2 \cdot 10^{-141}:\\
\;\;\;\;\mathsf{fma}\left(-y, z, x\right)\\

\mathbf{elif}\;x \leq 2.1 \cdot 10^{-108}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.4999999999999998e-29 or 2.0999999999999999e-108 < x

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 82.9%

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

    if -4.4999999999999998e-29 < x < -4.39999999999999974e-92 or -2.0000000000000001e-141 < x < 2.0999999999999999e-108

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 76.5%

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right)} \]
    4. Step-by-step derivation
      1. neg-mul-176.5%

        \[\leadsto \color{blue}{-z \cdot \sin y} \]
      2. distribute-rgt-neg-in76.5%

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

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

    if -4.39999999999999974e-92 < x < -2.0000000000000001e-141

    1. Initial program 99.9%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 84.5%

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

        \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right) + x} \]
      2. associate-*r*84.5%

        \[\leadsto \color{blue}{\left(-1 \cdot y\right) \cdot z} + x \]
      3. fma-define84.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-1 \cdot y, z, x\right)} \]
      4. mul-1-neg84.5%

        \[\leadsto \mathsf{fma}\left(\color{blue}{-y}, z, x\right) \]
    5. Simplified84.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-y, z, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 73.5% 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}\;x \leq -1.45 \cdot 10^{-28}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-92}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-154}:\\ \;\;\;\;x - z \cdot y\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-109}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (cos y))) (t_1 (* z (- (sin y)))))
   (if (<= x -1.45e-28)
     t_0
     (if (<= x -4.8e-92)
       t_1
       (if (<= x -6.2e-154) (- x (* z y)) (if (<= x 3.3e-109) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = x * cos(y);
	double t_1 = z * -sin(y);
	double tmp;
	if (x <= -1.45e-28) {
		tmp = t_0;
	} else if (x <= -4.8e-92) {
		tmp = t_1;
	} else if (x <= -6.2e-154) {
		tmp = x - (z * y);
	} else if (x <= 3.3e-109) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	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 (x <= (-1.45d-28)) then
        tmp = t_0
    else if (x <= (-4.8d-92)) then
        tmp = t_1
    else if (x <= (-6.2d-154)) then
        tmp = x - (z * y)
    else if (x <= 3.3d-109) then
        tmp = t_1
    else
        tmp = t_0
    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 (x <= -1.45e-28) {
		tmp = t_0;
	} else if (x <= -4.8e-92) {
		tmp = t_1;
	} else if (x <= -6.2e-154) {
		tmp = x - (z * y);
	} else if (x <= 3.3e-109) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.cos(y)
	t_1 = z * -math.sin(y)
	tmp = 0
	if x <= -1.45e-28:
		tmp = t_0
	elif x <= -4.8e-92:
		tmp = t_1
	elif x <= -6.2e-154:
		tmp = x - (z * y)
	elif x <= 3.3e-109:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * cos(y))
	t_1 = Float64(z * Float64(-sin(y)))
	tmp = 0.0
	if (x <= -1.45e-28)
		tmp = t_0;
	elseif (x <= -4.8e-92)
		tmp = t_1;
	elseif (x <= -6.2e-154)
		tmp = Float64(x - Float64(z * y));
	elseif (x <= 3.3e-109)
		tmp = t_1;
	else
		tmp = t_0;
	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 (x <= -1.45e-28)
		tmp = t_0;
	elseif (x <= -4.8e-92)
		tmp = t_1;
	elseif (x <= -6.2e-154)
		tmp = x - (z * y);
	elseif (x <= 3.3e-109)
		tmp = t_1;
	else
		tmp = t_0;
	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[x, -1.45e-28], t$95$0, If[LessEqual[x, -4.8e-92], t$95$1, If[LessEqual[x, -6.2e-154], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.3e-109], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := z \cdot \left(-\sin y\right)\\
\mathbf{if}\;x \leq -1.45 \cdot 10^{-28}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -4.8 \cdot 10^{-92}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq -6.2 \cdot 10^{-154}:\\
\;\;\;\;x - z \cdot y\\

\mathbf{elif}\;x \leq 3.3 \cdot 10^{-109}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.45000000000000006e-28 or 3.2999999999999999e-109 < x

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 82.9%

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

    if -1.45000000000000006e-28 < x < -4.8000000000000002e-92 or -6.19999999999999963e-154 < x < 3.2999999999999999e-109

    1. Initial program 99.7%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 76.5%

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right)} \]
    4. Step-by-step derivation
      1. neg-mul-176.5%

        \[\leadsto \color{blue}{-z \cdot \sin y} \]
      2. distribute-rgt-neg-in76.5%

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

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

    if -4.8000000000000002e-92 < x < -6.19999999999999963e-154

    1. Initial program 99.9%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 84.5%

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

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

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

      \[\leadsto \color{blue}{x - y \cdot z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-28}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-92}:\\ \;\;\;\;z \cdot \left(-\sin y\right)\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-154}:\\ \;\;\;\;x - z \cdot y\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-109}:\\ \;\;\;\;z \cdot \left(-\sin y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 74.1% accurate, 1.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.5000000000000002e-4 or 33000 < y

    1. Initial program 99.5%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 53.9%

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

    if -7.5000000000000002e-4 < y < 33000

    1. Initial program 100.0%

      \[x \cdot \cos y - z \cdot \sin y \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 99.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.00075 \lor \neg \left(y \leq 33000\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + \left(z \cdot y\right) \cdot 0.16666666666666666\right) - z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 41.5% accurate, 14.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+212} \lor \neg \left(z \leq 3.9 \cdot 10^{+119}\right):\\
\;\;\;\;z \cdot \left(-y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.49999999999999996e212 or 3.8999999999999998e119 < z

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
    4. 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} \]
    5. Simplified50.7%

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

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

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

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

        \[\leadsto \color{blue}{z \cdot \left(-y\right)} \]
    8. Simplified41.7%

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

    if -2.49999999999999996e212 < z < 3.8999999999999998e119

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
    4. 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} \]
    5. Simplified51.7%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification43.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.5 \cdot 10^{+212} \lor \neg \left(z \leq 3.9 \cdot 10^{+119}\right):\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 52.1% accurate, 41.4× speedup?

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

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

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

    \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
  4. 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} \]
  5. Simplified51.5%

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

    \[\leadsto x - z \cdot y \]
  7. Add Preprocessing

Alternative 10: 38.5% 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.7%

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

    \[\leadsto \color{blue}{x + -1 \cdot \left(y \cdot z\right)} \]
  4. 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} \]
  5. Simplified51.5%

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

    \[\leadsto \color{blue}{x} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024103 
(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))))