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

Percentage Accurate: 99.8% → 99.8%
Time: 9.8s
Alternatives: 9
Speedup: 1.0×

Specification

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

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

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

Alternative 1: 99.8% accurate, 0.7× speedup?

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

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

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

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

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

Alternative 2: 86.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{+81} \lor \neg \left(z \leq 1.35 \cdot 10^{+19}\right):\\ \;\;\;\;z \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -5.4e+81) (not (<= z 1.35e+19)))
   (* z (cos y))
   (fma x (sin y) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -5.4e+81) || !(z <= 1.35e+19)) {
		tmp = z * cos(y);
	} else {
		tmp = fma(x, sin(y), z);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((z <= -5.4e+81) || !(z <= 1.35e+19))
		tmp = Float64(z * cos(y));
	else
		tmp = fma(x, sin(y), z);
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.4e+81], N[Not[LessEqual[z, 1.35e+19]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{+81} \lor \neg \left(z \leq 1.35 \cdot 10^{+19}\right):\\
\;\;\;\;z \cdot \cos y\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.3999999999999999e81 or 1.35e19 < z

    1. Initial program 99.8%

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

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

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

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

    if -5.3999999999999999e81 < z < 1.35e19

    1. Initial program 99.9%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Step-by-step derivation
      1. fma-define99.9%

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

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

      \[\leadsto \mathsf{fma}\left(x, \sin y, \color{blue}{z}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{+81} \lor \neg \left(z \leq 1.35 \cdot 10^{+19}\right):\\ \;\;\;\;z \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.8% accurate, 1.0× speedup?

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

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

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

    \[\leadsto z \cdot \cos y + x \cdot \sin y \]
  4. Add Preprocessing

Alternative 4: 86.5% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+84} \lor \neg \left(z \leq 2.5 \cdot 10^{+16}\right):\\
\;\;\;\;z \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.2000000000000002e84 or 2.5e16 < z

    1. Initial program 99.8%

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

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

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

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

    if -5.2000000000000002e84 < z < 2.5e16

    1. Initial program 99.9%

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

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

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

Alternative 5: 74.5% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-117} \lor \neg \left(z \leq 5.8 \cdot 10^{-107}\right):\\
\;\;\;\;z \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.14999999999999997e-117 or 5.7999999999999996e-107 < z

    1. Initial program 99.8%

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

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

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

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

    if -1.14999999999999997e-117 < z < 5.7999999999999996e-107

    1. Initial program 99.9%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Step-by-step derivation
      1. fma-define99.9%

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

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

      \[\leadsto \color{blue}{x \cdot \sin y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{-117} \lor \neg \left(z \leq 5.8 \cdot 10^{-107}\right):\\ \;\;\;\;z \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 74.1% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0012 \lor \neg \left(y \leq 6.6 \cdot 10^{+23}\right):\\
\;\;\;\;x \cdot \sin y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.00119999999999999989 or 6.60000000000000059e23 < y

    1. Initial program 99.7%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Step-by-step derivation
      1. fma-define99.7%

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

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

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

    if -0.00119999999999999989 < y < 6.60000000000000059e23

    1. Initial program 99.9%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Step-by-step derivation
      1. fma-define100.0%

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

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

      \[\leadsto \color{blue}{z + x \cdot y} \]
    6. Step-by-step derivation
      1. +-commutative96.5%

        \[\leadsto \color{blue}{x \cdot y + z} \]
    7. Simplified96.5%

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

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

Alternative 7: 53.0% accurate, 41.4× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{z + x \cdot y} \]
  6. Step-by-step derivation
    1. +-commutative48.1%

      \[\leadsto \color{blue}{x \cdot y + z} \]
  7. Simplified48.1%

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

    \[\leadsto z + x \cdot y \]
  9. Add Preprocessing

Alternative 8: 33.3% accurate, 41.4× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{z + x \cdot y} \]
  6. Step-by-step derivation
    1. +-commutative48.1%

      \[\leadsto \color{blue}{x \cdot y + z} \]
  7. Simplified48.1%

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

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

    \[\leadsto x \cdot \color{blue}{\frac{z}{x}} \]
  10. Add Preprocessing

Alternative 9: 17.3% accurate, 69.0× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{z + x \cdot y} \]
  6. Step-by-step derivation
    1. +-commutative48.1%

      \[\leadsto \color{blue}{x \cdot y + z} \]
  7. Simplified48.1%

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

    \[\leadsto \color{blue}{x \cdot y} \]
  9. Step-by-step derivation
    1. *-commutative12.4%

      \[\leadsto \color{blue}{y \cdot x} \]
  10. Simplified12.4%

    \[\leadsto \color{blue}{y \cdot x} \]
  11. Final simplification12.4%

    \[\leadsto x \cdot y \]
  12. Add Preprocessing

Reproduce

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