Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C

Percentage Accurate: 99.9% → 99.9%
Time: 7.4s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x + \sin y\right) + 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}

\\
\left(x + \sin y\right) + 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 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.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + \sin y\right) + 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}

\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + \sin y\right) + 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}

\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x + \sin y\right) + z \cdot \cos y \]
  2. Add Preprocessing
  3. Final simplification99.9%

    \[\leadsto \left(x + \sin y\right) + z \cdot \cos y \]
  4. Add Preprocessing

Alternative 2: 71.7% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{+51}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{+30}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-221}:\\ \;\;\;\;z + \left(x + y\right)\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+112}:\\ \;\;\;\;x + z\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))))
   (if (<= z -3.2e+147)
     t_0
     (if (<= z -3.5e+51)
       (+ x z)
       (if (<= z -1.6e+30)
         t_0
         (if (<= z -8.8e-221)
           (+ z (+ x y))
           (if (<= z 1.15e+112) (+ x z) t_0)))))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double tmp;
	if (z <= -3.2e+147) {
		tmp = t_0;
	} else if (z <= -3.5e+51) {
		tmp = x + z;
	} else if (z <= -1.6e+30) {
		tmp = t_0;
	} else if (z <= -8.8e-221) {
		tmp = z + (x + y);
	} else if (z <= 1.15e+112) {
		tmp = x + z;
	} 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) :: tmp
    t_0 = z * cos(y)
    if (z <= (-3.2d+147)) then
        tmp = t_0
    else if (z <= (-3.5d+51)) then
        tmp = x + z
    else if (z <= (-1.6d+30)) then
        tmp = t_0
    else if (z <= (-8.8d-221)) then
        tmp = z + (x + y)
    else if (z <= 1.15d+112) then
        tmp = x + z
    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 tmp;
	if (z <= -3.2e+147) {
		tmp = t_0;
	} else if (z <= -3.5e+51) {
		tmp = x + z;
	} else if (z <= -1.6e+30) {
		tmp = t_0;
	} else if (z <= -8.8e-221) {
		tmp = z + (x + y);
	} else if (z <= 1.15e+112) {
		tmp = x + z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * math.cos(y)
	tmp = 0
	if z <= -3.2e+147:
		tmp = t_0
	elif z <= -3.5e+51:
		tmp = x + z
	elif z <= -1.6e+30:
		tmp = t_0
	elif z <= -8.8e-221:
		tmp = z + (x + y)
	elif z <= 1.15e+112:
		tmp = x + z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(z * cos(y))
	tmp = 0.0
	if (z <= -3.2e+147)
		tmp = t_0;
	elseif (z <= -3.5e+51)
		tmp = Float64(x + z);
	elseif (z <= -1.6e+30)
		tmp = t_0;
	elseif (z <= -8.8e-221)
		tmp = Float64(z + Float64(x + y));
	elseif (z <= 1.15e+112)
		tmp = Float64(x + z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z * cos(y);
	tmp = 0.0;
	if (z <= -3.2e+147)
		tmp = t_0;
	elseif (z <= -3.5e+51)
		tmp = x + z;
	elseif (z <= -1.6e+30)
		tmp = t_0;
	elseif (z <= -8.8e-221)
		tmp = z + (x + y);
	elseif (z <= 1.15e+112)
		tmp = x + z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.2e+147], t$95$0, If[LessEqual[z, -3.5e+51], N[(x + z), $MachinePrecision], If[LessEqual[z, -1.6e+30], t$95$0, If[LessEqual[z, -8.8e-221], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.15e+112], N[(x + z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -3.2 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq -3.5 \cdot 10^{+51}:\\
\;\;\;\;x + z\\

\mathbf{elif}\;z \leq -1.6 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq -8.8 \cdot 10^{-221}:\\
\;\;\;\;z + \left(x + y\right)\\

\mathbf{elif}\;z \leq 1.15 \cdot 10^{+112}:\\
\;\;\;\;x + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -3.19999999999999979e147 or -3.5e51 < z < -1.59999999999999986e30 or 1.15e112 < z

    1. Initial program 99.8%

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

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

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

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

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

    if -3.19999999999999979e147 < z < -3.5e51 or -8.80000000000000005e-221 < z < 1.15e112

    1. Initial program 100.0%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

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

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

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

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

        \[\leadsto \color{blue}{z + x} \]
    7. Simplified75.5%

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

    if -1.59999999999999986e30 < z < -8.80000000000000005e-221

    1. Initial program 100.0%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

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

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

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

      \[\leadsto \color{blue}{x + \left(y + z\right)} \]
    6. Step-by-step derivation
      1. +-commutative66.9%

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

        \[\leadsto \color{blue}{\left(z + y\right)} + x \]
      3. associate-+l+66.9%

        \[\leadsto \color{blue}{z + \left(y + x\right)} \]
    7. Simplified66.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{+147}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{+51}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{+30}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-221}:\\ \;\;\;\;z + \left(x + y\right)\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+112}:\\ \;\;\;\;x + z\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.3% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;z \leq -6.5 \cdot 10^{+147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+51}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -18 \lor \neg \left(z \leq 3 \cdot 10^{+95}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;x + \sin y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))))
   (if (<= z -6.5e+147)
     t_0
     (if (<= z -4.5e+51)
       (+ x z)
       (if (or (<= z -18.0) (not (<= z 3e+95))) t_0 (+ x (sin y)))))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double tmp;
	if (z <= -6.5e+147) {
		tmp = t_0;
	} else if (z <= -4.5e+51) {
		tmp = x + z;
	} else if ((z <= -18.0) || !(z <= 3e+95)) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = z * cos(y)
    if (z <= (-6.5d+147)) then
        tmp = t_0
    else if (z <= (-4.5d+51)) then
        tmp = x + z
    else if ((z <= (-18.0d0)) .or. (.not. (z <= 3d+95))) then
        tmp = t_0
    else
        tmp = x + sin(y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = z * Math.cos(y);
	double tmp;
	if (z <= -6.5e+147) {
		tmp = t_0;
	} else if (z <= -4.5e+51) {
		tmp = x + z;
	} else if ((z <= -18.0) || !(z <= 3e+95)) {
		tmp = t_0;
	} else {
		tmp = x + Math.sin(y);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * math.cos(y)
	tmp = 0
	if z <= -6.5e+147:
		tmp = t_0
	elif z <= -4.5e+51:
		tmp = x + z
	elif (z <= -18.0) or not (z <= 3e+95):
		tmp = t_0
	else:
		tmp = x + math.sin(y)
	return tmp
function code(x, y, z)
	t_0 = Float64(z * cos(y))
	tmp = 0.0
	if (z <= -6.5e+147)
		tmp = t_0;
	elseif (z <= -4.5e+51)
		tmp = Float64(x + z);
	elseif ((z <= -18.0) || !(z <= 3e+95))
		tmp = t_0;
	else
		tmp = Float64(x + sin(y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z * cos(y);
	tmp = 0.0;
	if (z <= -6.5e+147)
		tmp = t_0;
	elseif (z <= -4.5e+51)
		tmp = x + z;
	elseif ((z <= -18.0) || ~((z <= 3e+95)))
		tmp = t_0;
	else
		tmp = x + sin(y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.5e+147], t$95$0, If[LessEqual[z, -4.5e+51], N[(x + z), $MachinePrecision], If[Or[LessEqual[z, -18.0], N[Not[LessEqual[z, 3e+95]], $MachinePrecision]], t$95$0, N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -6.5 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq -4.5 \cdot 10^{+51}:\\
\;\;\;\;x + z\\

\mathbf{elif}\;z \leq -18 \lor \neg \left(z \leq 3 \cdot 10^{+95}\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -6.5e147 or -4.5e51 < z < -18 or 2.99999999999999991e95 < z

    1. Initial program 99.8%

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

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

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

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

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

    if -6.5e147 < z < -4.5e51

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \color{blue}{z + x} \]
    7. Simplified77.4%

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

    if -18 < z < 2.99999999999999991e95

    1. Initial program 100.0%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

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

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

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

      \[\leadsto \color{blue}{x + \sin y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{+147}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+51}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -18 \lor \neg \left(z \leq 3 \cdot 10^{+95}\right):\\ \;\;\;\;z \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 89.5% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{+146} \lor \neg \left(z \leq 1.5 \cdot 10^{+107}\right):\\
\;\;\;\;z \cdot \cos y\\

\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.1000000000000002e146 or 1.50000000000000012e107 < z

    1. Initial program 99.8%

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

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

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

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

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

    if -3.1000000000000002e146 < z < 1.50000000000000012e107

    1. Initial program 100.0%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 94.2%

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

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

Alternative 5: 69.9% accurate, 13.8× speedup?

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

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

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


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

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \color{blue}{z + x} \]
    7. Simplified48.5%

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

    if -4e20 < y < 6.1999999999999998e-19

    1. Initial program 100.0%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(z + y\right)} + x \]
      3. associate-+l+98.1%

        \[\leadsto \color{blue}{z + \left(y + x\right)} \]
    7. Simplified98.1%

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

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

Alternative 6: 55.2% accurate, 18.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.55 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-48}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -2.55e-8) x (if (<= x 3.7e-48) z x)))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.55e-8) {
		tmp = x;
	} else if (x <= 3.7e-48) {
		tmp = z;
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-2.55d-8)) then
        tmp = x
    else if (x <= 3.7d-48) then
        tmp = z
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.55e-8) {
		tmp = x;
	} else if (x <= 3.7e-48) {
		tmp = z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -2.55e-8:
		tmp = x
	elif x <= 3.7e-48:
		tmp = z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -2.55e-8)
		tmp = x;
	elseif (x <= 3.7e-48)
		tmp = z;
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -2.55e-8)
		tmp = x;
	elseif (x <= 3.7e-48)
		tmp = z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -2.55e-8], x, If[LessEqual[x, 3.7e-48], z, x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.55 \cdot 10^{-8}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq 3.7 \cdot 10^{-48}:\\
\;\;\;\;z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.55e-8 or 3.6999999999999998e-48 < x

    1. Initial program 99.9%

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

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

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

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

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

    if -2.55e-8 < x < 3.6999999999999998e-48

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{z \cdot \cos y} \]
    6. Taylor expanded in y around 0 38.2%

      \[\leadsto \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.55 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-48}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 65.9% accurate, 69.0× speedup?

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{z + x} \]
  7. Simplified67.9%

    \[\leadsto \color{blue}{z + x} \]
  8. Final simplification67.9%

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

Alternative 8: 42.7% 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.9%

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

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

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

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

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

    \[\leadsto x \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024053 
(FPCore (x y z)
  :name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
  :precision binary64
  (+ (+ x (sin y)) (* z (cos y))))