Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3

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

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

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

    \[x \cdot \cos y + z \cdot \sin y \]
  2. Step-by-step derivation
    1. +-commutative99.8%

      \[\leadsto \color{blue}{z \cdot \sin y + x \cdot \cos y} \]
    2. *-commutative99.8%

      \[\leadsto \color{blue}{\sin y \cdot z} + x \cdot \cos y \]
    3. fma-def99.8%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)} \]
  4. Final simplification99.8%

    \[\leadsto \mathsf{fma}\left(\sin y, z, x \cdot \cos y\right) \]

Alternative 2: 99.8% accurate, 1.0× speedup?

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

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

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

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

Alternative 3: 75.1% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ t_1 := \sin y \cdot z\\ \mathbf{if}\;y \leq -1 \cdot 10^{+158}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.9 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -16:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-7} \lor \neg \left(y \leq 4.8 \cdot 10^{-6}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot z + \left(x + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (cos y))) (t_1 (* (sin y) z)))
   (if (<= y -1e+158)
     t_0
     (if (<= y -4.9e+61)
       t_1
       (if (<= y -16.0)
         t_0
         (if (or (<= y -1.05e-7) (not (<= y 4.8e-6)))
           t_1
           (+ (* y z) (+ x (* -0.5 (* x (* y y)))))))))))
double code(double x, double y, double z) {
	double t_0 = x * cos(y);
	double t_1 = sin(y) * z;
	double tmp;
	if (y <= -1e+158) {
		tmp = t_0;
	} else if (y <= -4.9e+61) {
		tmp = t_1;
	} else if (y <= -16.0) {
		tmp = t_0;
	} else if ((y <= -1.05e-7) || !(y <= 4.8e-6)) {
		tmp = t_1;
	} else {
		tmp = (y * z) + (x + (-0.5 * (x * (y * 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x * cos(y)
    t_1 = sin(y) * z
    if (y <= (-1d+158)) then
        tmp = t_0
    else if (y <= (-4.9d+61)) then
        tmp = t_1
    else if (y <= (-16.0d0)) then
        tmp = t_0
    else if ((y <= (-1.05d-7)) .or. (.not. (y <= 4.8d-6))) then
        tmp = t_1
    else
        tmp = (y * z) + (x + ((-0.5d0) * (x * (y * y))))
    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 = Math.sin(y) * z;
	double tmp;
	if (y <= -1e+158) {
		tmp = t_0;
	} else if (y <= -4.9e+61) {
		tmp = t_1;
	} else if (y <= -16.0) {
		tmp = t_0;
	} else if ((y <= -1.05e-7) || !(y <= 4.8e-6)) {
		tmp = t_1;
	} else {
		tmp = (y * z) + (x + (-0.5 * (x * (y * y))));
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.cos(y)
	t_1 = math.sin(y) * z
	tmp = 0
	if y <= -1e+158:
		tmp = t_0
	elif y <= -4.9e+61:
		tmp = t_1
	elif y <= -16.0:
		tmp = t_0
	elif (y <= -1.05e-7) or not (y <= 4.8e-6):
		tmp = t_1
	else:
		tmp = (y * z) + (x + (-0.5 * (x * (y * y))))
	return tmp
function code(x, y, z)
	t_0 = Float64(x * cos(y))
	t_1 = Float64(sin(y) * z)
	tmp = 0.0
	if (y <= -1e+158)
		tmp = t_0;
	elseif (y <= -4.9e+61)
		tmp = t_1;
	elseif (y <= -16.0)
		tmp = t_0;
	elseif ((y <= -1.05e-7) || !(y <= 4.8e-6))
		tmp = t_1;
	else
		tmp = Float64(Float64(y * z) + Float64(x + Float64(-0.5 * Float64(x * Float64(y * y)))));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * cos(y);
	t_1 = sin(y) * z;
	tmp = 0.0;
	if (y <= -1e+158)
		tmp = t_0;
	elseif (y <= -4.9e+61)
		tmp = t_1;
	elseif (y <= -16.0)
		tmp = t_0;
	elseif ((y <= -1.05e-7) || ~((y <= 4.8e-6)))
		tmp = t_1;
	else
		tmp = (y * z) + (x + (-0.5 * (x * (y * y))));
	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[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -1e+158], t$95$0, If[LessEqual[y, -4.9e+61], t$95$1, If[LessEqual[y, -16.0], t$95$0, If[Or[LessEqual[y, -1.05e-7], N[Not[LessEqual[y, 4.8e-6]], $MachinePrecision]], t$95$1, N[(N[(y * z), $MachinePrecision] + N[(x + N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := \sin y \cdot z\\
\mathbf{if}\;y \leq -1 \cdot 10^{+158}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -4.9 \cdot 10^{+61}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -16:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.05 \cdot 10^{-7} \lor \neg \left(y \leq 4.8 \cdot 10^{-6}\right):\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -9.99999999999999953e157 or -4.90000000000000025e61 < y < -16

    1. Initial program 99.5%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{z \cdot \sin y + x \cdot \cos y} \]
      2. *-commutative99.5%

        \[\leadsto \color{blue}{\sin y \cdot z} + x \cdot \cos y \]
      3. fma-def99.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)} \]
    4. Taylor expanded in z around 0 67.6%

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

    if -9.99999999999999953e157 < y < -4.90000000000000025e61 or -16 < y < -1.05e-7 or 4.7999999999999998e-6 < y

    1. Initial program 99.7%

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

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

    if -1.05e-7 < y < 4.7999999999999998e-6

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto y \cdot z + \left(-0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\left(y \cdot y\right)} \cdot x\right)} - 1\right) + x\right) \]
      4. associate-*l*97.7%

        \[\leadsto y \cdot z + \left(-0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{y \cdot \left(y \cdot x\right)}\right)} - 1\right) + x\right) \]
    4. Applied egg-rr97.7%

      \[\leadsto y \cdot z + \left(-0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(y \cdot \left(y \cdot x\right)\right)} - 1\right)} + x\right) \]
    5. Step-by-step derivation
      1. expm1-def97.7%

        \[\leadsto y \cdot z + \left(-0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(y \cdot \left(y \cdot x\right)\right)\right)} + x\right) \]
      2. expm1-log1p100.0%

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

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

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

        \[\leadsto y \cdot z + \left(-0.5 \cdot \color{blue}{\left(x \cdot \left(y \cdot y\right)\right)} + x\right) \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+158}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;y \leq -4.9 \cdot 10^{+61}:\\ \;\;\;\;\sin y \cdot z\\ \mathbf{elif}\;y \leq -16:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-7} \lor \neg \left(y \leq 4.8 \cdot 10^{-6}\right):\\ \;\;\;\;\sin y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z + \left(x + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\right)\\ \end{array} \]

Alternative 4: 85.6% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+125} \lor \neg \left(x \leq 1.8 \cdot 10^{+70}\right):\\
\;\;\;\;x \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.9999999999999997e125 or 1.8e70 < x

    1. Initial program 99.8%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \color{blue}{z \cdot \sin y + x \cdot \cos y} \]
      2. *-commutative99.8%

        \[\leadsto \color{blue}{\sin y \cdot z} + x \cdot \cos y \]
      3. fma-def99.8%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)} \]
    4. Taylor expanded in z around 0 91.5%

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

    if -3.9999999999999997e125 < x < 1.8e70

    1. Initial program 99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+125} \lor \neg \left(x \leq 1.8 \cdot 10^{+70}\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + \sin y \cdot z\\ \end{array} \]

Alternative 5: 74.7% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-7} \lor \neg \left(y \leq 4.8 \cdot 10^{-6}\right):\\
\;\;\;\;\sin y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.05e-7 or 4.7999999999999998e-6 < y

    1. Initial program 99.6%

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

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

    if -1.05e-7 < y < 4.7999999999999998e-6

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto y \cdot z + \left(-0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\left(y \cdot y\right)} \cdot x\right)} - 1\right) + x\right) \]
      4. associate-*l*97.7%

        \[\leadsto y \cdot z + \left(-0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{y \cdot \left(y \cdot x\right)}\right)} - 1\right) + x\right) \]
    4. Applied egg-rr97.7%

      \[\leadsto y \cdot z + \left(-0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(y \cdot \left(y \cdot x\right)\right)} - 1\right)} + x\right) \]
    5. Step-by-step derivation
      1. expm1-def97.7%

        \[\leadsto y \cdot z + \left(-0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(y \cdot \left(y \cdot x\right)\right)\right)} + x\right) \]
      2. expm1-log1p100.0%

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

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

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

        \[\leadsto y \cdot z + \left(-0.5 \cdot \color{blue}{\left(x \cdot \left(y \cdot y\right)\right)} + x\right) \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{-7} \lor \neg \left(y \leq 4.8 \cdot 10^{-6}\right):\\ \;\;\;\;\sin y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z + \left(x + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\right)\\ \end{array} \]

Alternative 6: 39.5% accurate, 22.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 5.8 \cdot 10^{+67}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{+147}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+203}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z 5.8e+67)
   x
   (if (<= z 2.9e+147) (* y z) (if (<= z 1.05e+203) x (* y z)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= 5.8e+67) {
		tmp = x;
	} else if (z <= 2.9e+147) {
		tmp = y * z;
	} else if (z <= 1.05e+203) {
		tmp = x;
	} else {
		tmp = 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 (z <= 5.8d+67) then
        tmp = x
    else if (z <= 2.9d+147) then
        tmp = y * z
    else if (z <= 1.05d+203) then
        tmp = x
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= 5.8e+67) {
		tmp = x;
	} else if (z <= 2.9e+147) {
		tmp = y * z;
	} else if (z <= 1.05e+203) {
		tmp = x;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= 5.8e+67:
		tmp = x
	elif z <= 2.9e+147:
		tmp = y * z
	elif z <= 1.05e+203:
		tmp = x
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= 5.8e+67)
		tmp = x;
	elseif (z <= 2.9e+147)
		tmp = Float64(y * z);
	elseif (z <= 1.05e+203)
		tmp = x;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= 5.8e+67)
		tmp = x;
	elseif (z <= 2.9e+147)
		tmp = y * z;
	elseif (z <= 1.05e+203)
		tmp = x;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, 5.8e+67], x, If[LessEqual[z, 2.9e+147], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.05e+203], x, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.8 \cdot 10^{+67}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 2.9 \cdot 10^{+147}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq 1.05 \cdot 10^{+203}:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;y \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 5.80000000000000047e67 or 2.8999999999999998e147 < z < 1.04999999999999992e203

    1. Initial program 99.8%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \color{blue}{z \cdot \sin y + x \cdot \cos y} \]
      2. *-commutative99.8%

        \[\leadsto \color{blue}{\sin y \cdot z} + x \cdot \cos y \]
      3. fma-def99.8%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)} \]
    4. Taylor expanded in y around 0 46.3%

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

    if 5.80000000000000047e67 < z < 2.8999999999999998e147 or 1.04999999999999992e203 < z

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{y \cdot z + x} \]
    3. Taylor expanded in y around inf 50.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 5.8 \cdot 10^{+67}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{+147}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+203}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 7: 52.7% 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 54.8%

    \[\leadsto \color{blue}{y \cdot z + x} \]
  3. Final simplification54.8%

    \[\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. Step-by-step derivation
    1. +-commutative99.8%

      \[\leadsto \color{blue}{z \cdot \sin y + x \cdot \cos y} \]
    2. *-commutative99.8%

      \[\leadsto \color{blue}{\sin y \cdot z} + x \cdot \cos y \]
    3. fma-def99.8%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)} \]
  4. Taylor expanded in y around 0 41.4%

    \[\leadsto \color{blue}{x} \]
  5. Final simplification41.4%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023256 
(FPCore (x y z)
  :name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
  :precision binary64
  (+ (* x (cos y)) (* z (sin y))))