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

Percentage Accurate: 99.9% → 99.9%
Time: 7.7s
Alternatives: 12
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 12 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, 0.7× speedup?

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

\\
\mathsf{fma}\left(z, \cos y, x + \sin y\right)
\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-def99.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. Final simplification99.9%

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

Alternative 2: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{+62}:\\ \;\;\;\;x + z \cdot \cos y\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-17}:\\ \;\;\;\;z + \left(x + \sin y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \cos y, x\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -2.4e+62)
   (+ x (* z (cos y)))
   (if (<= z 2e-17) (+ z (+ x (sin y))) (fma z (cos y) x))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.4e+62) {
		tmp = x + (z * cos(y));
	} else if (z <= 2e-17) {
		tmp = z + (x + sin(y));
	} else {
		tmp = fma(z, cos(y), x);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= -2.4e+62)
		tmp = Float64(x + Float64(z * cos(y)));
	elseif (z <= 2e-17)
		tmp = Float64(z + Float64(x + sin(y)));
	else
		tmp = fma(z, cos(y), x);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, -2.4e+62], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e-17], N[(z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+62}:\\
\;\;\;\;x + z \cdot \cos y\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -2.4e62

    1. Initial program 100.0%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Taylor expanded in x around inf 100.0%

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

    if -2.4e62 < z < 2.00000000000000014e-17

    1. Initial program 100.0%

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

      \[\leadsto \left(x + \sin y\right) + \color{blue}{z} \]

    if 2.00000000000000014e-17 < 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-def99.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. Taylor expanded in x around inf 98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{+62}:\\ \;\;\;\;x + z \cdot \cos y\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-17}:\\ \;\;\;\;z + \left(x + \sin y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \cos y, x\right)\\ \end{array} \]

Alternative 3: 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. Final simplification99.9%

    \[\leadsto \left(x + \sin y\right) + z \cdot \cos y \]

Alternative 4: 85.7% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-81} \lor \neg \left(x \leq 4 \cdot 10^{-140}\right):\\
\;\;\;\;x + z \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.9999999999999998e-81 or 3.9999999999999999e-140 < x

    1. Initial program 99.9%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Taylor expanded in x around inf 95.6%

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

    if -5.9999999999999998e-81 < x < 3.9999999999999999e-140

    1. Initial program 99.9%

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

      \[\leadsto \left(x + \sin y\right) + \color{blue}{z} \]
    3. Taylor expanded in x around 0 84.3%

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

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

Alternative 5: 97.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+62} \lor \neg \left(z \leq 2 \cdot 10^{-17}\right):\\
\;\;\;\;x + z \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.4e62 or 2.00000000000000014e-17 < z

    1. Initial program 99.9%

      \[\left(x + \sin y\right) + z \cdot \cos y \]
    2. Taylor expanded in x around inf 98.8%

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

    if -2.4e62 < z < 2.00000000000000014e-17

    1. Initial program 100.0%

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

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

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

Alternative 6: 77.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{-71}:\\ \;\;\;\;z + x\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-52}:\\ \;\;\;\;z + \sin y\\ \mathbf{else}:\\ \;\;\;\;z + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -2.5e-71) (+ z x) (if (<= x 1.65e-52) (+ z (sin y)) (+ z x))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.5e-71) {
		tmp = z + x;
	} else if (x <= 1.65e-52) {
		tmp = z + sin(y);
	} else {
		tmp = z + 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.5d-71)) then
        tmp = z + x
    else if (x <= 1.65d-52) then
        tmp = z + sin(y)
    else
        tmp = z + x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.5e-71) {
		tmp = z + x;
	} else if (x <= 1.65e-52) {
		tmp = z + Math.sin(y);
	} else {
		tmp = z + x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -2.5e-71:
		tmp = z + x
	elif x <= 1.65e-52:
		tmp = z + math.sin(y)
	else:
		tmp = z + x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -2.5e-71)
		tmp = Float64(z + x);
	elseif (x <= 1.65e-52)
		tmp = Float64(z + sin(y));
	else
		tmp = Float64(z + x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -2.5e-71)
		tmp = z + x;
	elseif (x <= 1.65e-52)
		tmp = z + sin(y);
	else
		tmp = z + x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -2.5e-71], N[(z + x), $MachinePrecision], If[LessEqual[x, 1.65e-52], N[(z + N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-71}:\\
\;\;\;\;z + x\\

\mathbf{elif}\;x \leq 1.65 \cdot 10^{-52}:\\
\;\;\;\;z + \sin y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.49999999999999999e-71 or 1.64999999999999998e-52 < x

    1. Initial program 99.9%

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

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

    if -2.49999999999999999e-71 < x < 1.64999999999999998e-52

    1. Initial program 99.9%

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

      \[\leadsto \left(x + \sin y\right) + \color{blue}{z} \]
    3. Taylor expanded in x around 0 84.5%

      \[\leadsto \color{blue}{\sin y} + z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{-71}:\\ \;\;\;\;z + x\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-52}:\\ \;\;\;\;z + \sin y\\ \mathbf{else}:\\ \;\;\;\;z + x\\ \end{array} \]

Alternative 7: 70.4% accurate, 22.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -275000000000:\\
\;\;\;\;z + x\\

\mathbf{elif}\;y \leq 2 \cdot 10^{+27}:\\
\;\;\;\;y + \left(z + x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.75e11 or 2e27 < y

    1. Initial program 99.9%

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

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

    if -2.75e11 < y < 2e27

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -275000000000:\\ \;\;\;\;z + x\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+27}:\\ \;\;\;\;y + \left(z + x\right)\\ \mathbf{else}:\\ \;\;\;\;z + x\\ \end{array} \]

Alternative 8: 58.1% accurate, 29.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.2e-9 or 2.50000000000000002e-51 < 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-def100.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. Taylor expanded in x around inf 96.9%

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

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

    if -1.2e-9 < x < 2.50000000000000002e-51

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{y + \left(z + x\right)} \]
    3. Taylor expanded in x around 0 59.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-51}:\\ \;\;\;\;z + y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 9: 67.6% accurate, 29.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{-191}:\\
\;\;\;\;z + x\\

\mathbf{elif}\;x \leq 4.6 \cdot 10^{-57}:\\
\;\;\;\;z + y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.7999999999999999e-191 or 4.6e-57 < x

    1. Initial program 99.9%

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

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

    if -9.7999999999999999e-191 < x < 4.6e-57

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{y + \left(z + x\right)} \]
    3. Taylor expanded in x around 0 68.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.8 \cdot 10^{-191}:\\ \;\;\;\;z + x\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-57}:\\ \;\;\;\;z + y\\ \mathbf{else}:\\ \;\;\;\;z + x\\ \end{array} \]

Alternative 10: 44.4% accurate, 40.4× speedup?

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

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

\mathbf{elif}\;x \leq 1.7 \cdot 10^{-52}:\\
\;\;\;\;y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.7999999999999999e-191 or 1.70000000000000009e-52 < 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-def100.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. Taylor expanded in x around inf 90.9%

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

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

    if -9.7999999999999999e-191 < x < 1.70000000000000009e-52

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{y + \left(z + x\right)} \]
    3. Taylor expanded in y around inf 25.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.8 \cdot 10^{-191}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-52}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 11: 54.8% accurate, 40.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-51}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.7e-9) x (if (<= x 5.6e-51) z x)))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.7e-9) {
		tmp = x;
	} else if (x <= 5.6e-51) {
		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 <= (-1.7d-9)) then
        tmp = x
    else if (x <= 5.6d-51) 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 <= -1.7e-9) {
		tmp = x;
	} else if (x <= 5.6e-51) {
		tmp = z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.7e-9:
		tmp = x
	elif x <= 5.6e-51:
		tmp = z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.7e-9)
		tmp = x;
	elseif (x <= 5.6e-51)
		tmp = z;
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.7e-9)
		tmp = x;
	elseif (x <= 5.6e-51)
		tmp = z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.7e-9], x, If[LessEqual[x, 5.6e-51], z, x]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.6999999999999999e-9 or 5.6e-51 < 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-def100.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. Taylor expanded in x around inf 96.9%

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

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

    if -1.6999999999999999e-9 < x < 5.6e-51

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{y + \left(z + x\right)} \]
    3. Taylor expanded in z around inf 44.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-51}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 12: 42.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.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-def99.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. Taylor expanded in x around inf 81.6%

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

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

    \[\leadsto x \]

Reproduce

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