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

Percentage Accurate: 99.8% → 99.8%
Time: 7.2s
Alternatives: 7
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 7 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, 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.9%

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

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

Alternative 2: 74.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ t_1 := x \cdot \sin y\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+243}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -0.25:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 30500:\\ \;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+209} \lor \neg \left(y \leq 1.8 \cdot 10^{+233}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
   (if (<= y -2.6e+243)
     t_0
     (if (<= y -0.25)
       t_1
       (if (<= y 30500.0)
         (+ (* -0.5 (* y (* y z))) (+ z (* x y)))
         (if (or (<= y 3e+209) (not (<= y 1.8e+233))) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double t_1 = x * sin(y);
	double tmp;
	if (y <= -2.6e+243) {
		tmp = t_0;
	} else if (y <= -0.25) {
		tmp = t_1;
	} else if (y <= 30500.0) {
		tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
	} else if ((y <= 3e+209) || !(y <= 1.8e+233)) {
		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 = z * cos(y)
    t_1 = x * sin(y)
    if (y <= (-2.6d+243)) then
        tmp = t_0
    else if (y <= (-0.25d0)) then
        tmp = t_1
    else if (y <= 30500.0d0) then
        tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
    else if ((y <= 3d+209) .or. (.not. (y <= 1.8d+233))) 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 = z * Math.cos(y);
	double t_1 = x * Math.sin(y);
	double tmp;
	if (y <= -2.6e+243) {
		tmp = t_0;
	} else if (y <= -0.25) {
		tmp = t_1;
	} else if (y <= 30500.0) {
		tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
	} else if ((y <= 3e+209) || !(y <= 1.8e+233)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * math.cos(y)
	t_1 = x * math.sin(y)
	tmp = 0
	if y <= -2.6e+243:
		tmp = t_0
	elif y <= -0.25:
		tmp = t_1
	elif y <= 30500.0:
		tmp = (-0.5 * (y * (y * z))) + (z + (x * y))
	elif (y <= 3e+209) or not (y <= 1.8e+233):
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(z * cos(y))
	t_1 = Float64(x * sin(y))
	tmp = 0.0
	if (y <= -2.6e+243)
		tmp = t_0;
	elseif (y <= -0.25)
		tmp = t_1;
	elseif (y <= 30500.0)
		tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y)));
	elseif ((y <= 3e+209) || !(y <= 1.8e+233))
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z * cos(y);
	t_1 = x * sin(y);
	tmp = 0.0;
	if (y <= -2.6e+243)
		tmp = t_0;
	elseif (y <= -0.25)
		tmp = t_1;
	elseif (y <= 30500.0)
		tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
	elseif ((y <= 3e+209) || ~((y <= 1.8e+233)))
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.6e+243], t$95$0, If[LessEqual[y, -0.25], t$95$1, If[LessEqual[y, 30500.0], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3e+209], N[Not[LessEqual[y, 1.8e+233]], $MachinePrecision]], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -0.25:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;y \leq 3 \cdot 10^{+209} \lor \neg \left(y \leq 1.8 \cdot 10^{+233}\right):\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.59999999999999997e243 or 2.99999999999999985e209 < y < 1.7999999999999999e233

    1. Initial program 99.7%

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

        \[\leadsto \color{blue}{\sin y \cdot x} + z \cdot \cos y \]
      2. add-cube-cbrt99.2%

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \sqrt[3]{\sin y}\right)} \cdot x + z \cdot \cos y \]
      3. associate-*l*99.4%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \left(\sqrt[3]{\sin y} \cdot x\right)} + z \cdot \cos y \]
      4. fma-def99.4%

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

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

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

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

    if -2.59999999999999997e243 < y < -0.25 or 30500 < y < 2.99999999999999985e209 or 1.7999999999999999e233 < y

    1. Initial program 99.7%

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

        \[\leadsto \color{blue}{\sin y \cdot x} + z \cdot \cos y \]
      2. add-cube-cbrt98.6%

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \sqrt[3]{\sin y}\right)} \cdot x + z \cdot \cos y \]
      3. associate-*l*98.6%

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{\sin y}\right)}^{2}, \sqrt[3]{\sin y} \cdot x, z \cdot \cos y\right)} \]
    4. Taylor expanded in x around inf 64.0%

      \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot \left(\sin y \cdot x\right)} \]
    5. Step-by-step derivation
      1. pow-base-164.0%

        \[\leadsto \color{blue}{1} \cdot \left(\sin y \cdot x\right) \]
      2. *-lft-identity64.0%

        \[\leadsto \color{blue}{\sin y \cdot x} \]
    6. Simplified64.0%

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

    if -0.25 < y < 30500

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+243}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;y \leq -0.25:\\ \;\;\;\;x \cdot \sin y\\ \mathbf{elif}\;y \leq 30500:\\ \;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+209} \lor \neg \left(y \leq 1.8 \cdot 10^{+233}\right):\\ \;\;\;\;x \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]

Alternative 3: 85.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+39} \lor \neg \left(x \leq 10^{-19}\right):\\
\;\;\;\;z + x \cdot \sin y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.1000000000000001e39 or 9.9999999999999998e-20 < x

    1. Initial program 99.8%

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

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

    if -1.1000000000000001e39 < x < 9.9999999999999998e-20

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{\sin y \cdot x} + z \cdot \cos y \]
      2. add-cube-cbrt99.7%

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \sqrt[3]{\sin y}\right)} \cdot x + z \cdot \cos y \]
      3. associate-*l*99.7%

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

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

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

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

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

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

Alternative 4: 75.1% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.06 \lor \neg \left(y \leq 0.0078\right):\\
\;\;\;\;z \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.059999999999999998 or 0.0077999999999999996 < y

    1. Initial program 99.7%

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

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

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \sqrt[3]{\sin y}\right)} \cdot x + z \cdot \cos y \]
      3. associate-*l*98.8%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \left(\sqrt[3]{\sin y} \cdot x\right)} + z \cdot \cos y \]
      4. fma-def98.8%

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

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

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

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

    if -0.059999999999999998 < y < 0.0077999999999999996

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 42.5% accurate, 29.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-112}:\\
\;\;\;\;z\\

\mathbf{elif}\;z \leq 4.3 \cdot 10^{-193}:\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.14999999999999995e-112 or 4.3000000000000002e-193 < z

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{\sin y \cdot x} + z \cdot \cos y \]
      2. add-cube-cbrt99.3%

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \sqrt[3]{\sin y}\right)} \cdot x + z \cdot \cos y \]
      3. associate-*l*99.4%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \left(\sqrt[3]{\sin y} \cdot x\right)} + z \cdot \cos y \]
      4. fma-def99.4%

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

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

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

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

    if -1.14999999999999995e-112 < z < 4.3000000000000002e-193

    1. Initial program 99.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{-112}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-193}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternative 6: 52.5% 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.9%

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

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

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

Alternative 7: 38.8% accurate, 207.0× speedup?

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

\\
z
\end{array}
Derivation
  1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\sin y \cdot x} + z \cdot \cos y \]
    2. add-cube-cbrt99.1%

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \sqrt[3]{\sin y}\right)} \cdot x + z \cdot \cos y \]
    3. associate-*l*99.1%

      \[\leadsto \color{blue}{\left(\sqrt[3]{\sin y} \cdot \sqrt[3]{\sin y}\right) \cdot \left(\sqrt[3]{\sin y} \cdot x\right)} + z \cdot \cos y \]
    4. fma-def99.1%

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

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

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

    \[\leadsto \color{blue}{z} \]
  5. Final simplification44.0%

    \[\leadsto z \]

Reproduce

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