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

Percentage Accurate: 99.9% → 99.9%
Time: 6.5s
Alternatives: 10
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 10 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} \\ z \cdot \cos y + \left(x + \sin y\right) \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 + \left(x + \sin y\right)
\end{array}
Derivation
  1. Initial program 99.9%

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

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

Alternative 2: 81.9% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;z \leq -7 \cdot 10^{+198}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+112}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{+64}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-96}:\\ \;\;\;\;x + \sin y\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+162}:\\ \;\;\;\;x + z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))))
   (if (<= z -7e+198)
     t_0
     (if (<= z -4.5e+112)
       (+ x z)
       (if (<= z -5.8e+64)
         t_0
         (if (<= z 1.65e-96)
           (+ x (sin y))
           (if (<= z 3.4e+162) (+ x z) t_0)))))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double tmp;
	if (z <= -7e+198) {
		tmp = t_0;
	} else if (z <= -4.5e+112) {
		tmp = x + z;
	} else if (z <= -5.8e+64) {
		tmp = t_0;
	} else if (z <= 1.65e-96) {
		tmp = x + sin(y);
	} else if (z <= 3.4e+162) {
		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 <= (-7d+198)) then
        tmp = t_0
    else if (z <= (-4.5d+112)) then
        tmp = x + z
    else if (z <= (-5.8d+64)) then
        tmp = t_0
    else if (z <= 1.65d-96) then
        tmp = x + sin(y)
    else if (z <= 3.4d+162) 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 <= -7e+198) {
		tmp = t_0;
	} else if (z <= -4.5e+112) {
		tmp = x + z;
	} else if (z <= -5.8e+64) {
		tmp = t_0;
	} else if (z <= 1.65e-96) {
		tmp = x + Math.sin(y);
	} else if (z <= 3.4e+162) {
		tmp = x + z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * math.cos(y)
	tmp = 0
	if z <= -7e+198:
		tmp = t_0
	elif z <= -4.5e+112:
		tmp = x + z
	elif z <= -5.8e+64:
		tmp = t_0
	elif z <= 1.65e-96:
		tmp = x + math.sin(y)
	elif z <= 3.4e+162:
		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 <= -7e+198)
		tmp = t_0;
	elseif (z <= -4.5e+112)
		tmp = Float64(x + z);
	elseif (z <= -5.8e+64)
		tmp = t_0;
	elseif (z <= 1.65e-96)
		tmp = Float64(x + sin(y));
	elseif (z <= 3.4e+162)
		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 <= -7e+198)
		tmp = t_0;
	elseif (z <= -4.5e+112)
		tmp = x + z;
	elseif (z <= -5.8e+64)
		tmp = t_0;
	elseif (z <= 1.65e-96)
		tmp = x + sin(y);
	elseif (z <= 3.4e+162)
		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, -7e+198], t$95$0, If[LessEqual[z, -4.5e+112], N[(x + z), $MachinePrecision], If[LessEqual[z, -5.8e+64], t$95$0, If[LessEqual[z, 1.65e-96], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.4e+162], N[(x + z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -7 \cdot 10^{+198}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;z \leq -5.8 \cdot 10^{+64}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;z \leq 3.4 \cdot 10^{+162}:\\
\;\;\;\;x + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -7.00000000000000026e198 or -4.4999999999999999e112 < z < -5.79999999999999986e64 or 3.40000000000000003e162 < z

    1. Initial program 99.8%

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

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

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

    if -7.00000000000000026e198 < z < -4.4999999999999999e112 or 1.64999999999999995e-96 < z < 3.40000000000000003e162

    1. Initial program 99.9%

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

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

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

    if -5.79999999999999986e64 < z < 1.64999999999999995e-96

    1. Initial program 100.0%

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

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

        \[\leadsto \left(x + \sin y\right) + \color{blue}{\mathsf{fma}\left(-0.5, {y}^{2} \cdot z, z\right)} \]
      2. *-commutative76.3%

        \[\leadsto \left(x + \sin y\right) + \mathsf{fma}\left(-0.5, \color{blue}{z \cdot {y}^{2}}, z\right) \]
      3. unpow276.3%

        \[\leadsto \left(x + \sin y\right) + \mathsf{fma}\left(-0.5, z \cdot \color{blue}{\left(y \cdot y\right)}, z\right) \]
    4. Simplified76.3%

      \[\leadsto \left(x + \sin y\right) + \color{blue}{\mathsf{fma}\left(-0.5, z \cdot \left(y \cdot y\right), z\right)} \]
    5. Taylor expanded in z around 0 93.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7 \cdot 10^{+198}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+112}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{+64}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-96}:\\ \;\;\;\;x + \sin y\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+162}:\\ \;\;\;\;x + z\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]

Alternative 3: 68.8% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;z \leq -6 \cdot 10^{+203}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-97}:\\ \;\;\;\;z + \left(x + y\right)\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{+158}:\\ \;\;\;\;x + z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))))
   (if (<= z -6e+203)
     t_0
     (if (<= z 4.5e-97) (+ z (+ x y)) (if (<= z 9.5e+158) (+ x z) t_0)))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double tmp;
	if (z <= -6e+203) {
		tmp = t_0;
	} else if (z <= 4.5e-97) {
		tmp = z + (x + y);
	} else if (z <= 9.5e+158) {
		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 <= (-6d+203)) then
        tmp = t_0
    else if (z <= 4.5d-97) then
        tmp = z + (x + y)
    else if (z <= 9.5d+158) 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 <= -6e+203) {
		tmp = t_0;
	} else if (z <= 4.5e-97) {
		tmp = z + (x + y);
	} else if (z <= 9.5e+158) {
		tmp = x + z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * math.cos(y)
	tmp = 0
	if z <= -6e+203:
		tmp = t_0
	elif z <= 4.5e-97:
		tmp = z + (x + y)
	elif z <= 9.5e+158:
		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 <= -6e+203)
		tmp = t_0;
	elseif (z <= 4.5e-97)
		tmp = Float64(z + Float64(x + y));
	elseif (z <= 9.5e+158)
		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 <= -6e+203)
		tmp = t_0;
	elseif (z <= 4.5e-97)
		tmp = z + (x + y);
	elseif (z <= 9.5e+158)
		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, -6e+203], t$95$0, If[LessEqual[z, 4.5e-97], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9.5e+158], N[(x + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -6 \cdot 10^{+203}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;z \leq 9.5 \cdot 10^{+158}:\\
\;\;\;\;x + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -5.9999999999999999e203 or 9.49999999999999913e158 < z

    1. Initial program 99.8%

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

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

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

    if -5.9999999999999999e203 < z < 4.5000000000000001e-97

    1. Initial program 100.0%

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

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

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

    if 4.5000000000000001e-97 < z < 9.49999999999999913e158

    1. Initial program 99.9%

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

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

      \[\leadsto \color{blue}{z + x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{+203}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-97}:\\ \;\;\;\;z + \left(x + y\right)\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{+158}:\\ \;\;\;\;x + z\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]

Alternative 4: 94.2% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.06 \lor \neg \left(z \leq 2.9 \cdot 10^{-114}\right):\\
\;\;\;\;x + z \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.059999999999999998 or 2.89999999999999997e-114 < z

    1. Initial program 99.9%

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

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

    if -0.059999999999999998 < z < 2.89999999999999997e-114

    1. Initial program 100.0%

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

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

        \[\leadsto \left(x + \sin y\right) + \color{blue}{\mathsf{fma}\left(-0.5, {y}^{2} \cdot z, z\right)} \]
      2. *-commutative78.2%

        \[\leadsto \left(x + \sin y\right) + \mathsf{fma}\left(-0.5, \color{blue}{z \cdot {y}^{2}}, z\right) \]
      3. unpow278.2%

        \[\leadsto \left(x + \sin y\right) + \mathsf{fma}\left(-0.5, z \cdot \color{blue}{\left(y \cdot y\right)}, z\right) \]
    4. Simplified78.2%

      \[\leadsto \left(x + \sin y\right) + \color{blue}{\mathsf{fma}\left(-0.5, z \cdot \left(y \cdot y\right), z\right)} \]
    5. Taylor expanded in z around 0 96.1%

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

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

Alternative 5: 98.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -9.6 \cdot 10^{+37} \lor \neg \left(z \leq 2.65 \cdot 10^{-14}\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 -9.6e+37) (not (<= z 2.65e-14)))
   (+ x (* z (cos y)))
   (+ z (+ x (sin y)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -9.6e+37) || !(z <= 2.65e-14)) {
		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 <= (-9.6d+37)) .or. (.not. (z <= 2.65d-14))) 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 <= -9.6e+37) || !(z <= 2.65e-14)) {
		tmp = x + (z * Math.cos(y));
	} else {
		tmp = z + (x + Math.sin(y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -9.6e+37) or not (z <= 2.65e-14):
		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 <= -9.6e+37) || !(z <= 2.65e-14))
		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 <= -9.6e+37) || ~((z <= 2.65e-14)))
		tmp = x + (z * cos(y));
	else
		tmp = z + (x + sin(y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.6e+37], N[Not[LessEqual[z, 2.65e-14]], $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 -9.6 \cdot 10^{+37} \lor \neg \left(z \leq 2.65 \cdot 10^{-14}\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 < -9.5999999999999999e37 or 2.6500000000000001e-14 < z

    1. Initial program 99.8%

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

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

    if -9.5999999999999999e37 < z < 2.6500000000000001e-14

    1. Initial program 100.0%

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

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

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

Alternative 6: 70.1% accurate, 22.7× speedup?

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

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

\mathbf{elif}\;y \leq 3.1:\\
\;\;\;\;z + \left(x + y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -6.2e5 or 3.10000000000000009 < y

    1. Initial program 99.8%

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

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

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

    if -6.2e5 < y < 3.10000000000000009

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -620000:\\ \;\;\;\;x + z\\ \mathbf{elif}\;y \leq 3.1:\\ \;\;\;\;z + \left(x + y\right)\\ \mathbf{else}:\\ \;\;\;\;x + z\\ \end{array} \]

Alternative 7: 46.5% accurate, 29.1× speedup?

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

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

\mathbf{elif}\;x \leq 4 \cdot 10^{-68}:\\
\;\;\;\;x + y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.7999999999999999e-14 or 4.00000000000000027e-68 < x

    1. Initial program 99.9%

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

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

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

    if -1.7999999999999999e-14 < x < 4.00000000000000027e-68

    1. Initial program 99.9%

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

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

        \[\leadsto \left(x + \sin y\right) + \color{blue}{\mathsf{fma}\left(-0.5, {y}^{2} \cdot z, z\right)} \]
      2. *-commutative67.4%

        \[\leadsto \left(x + \sin y\right) + \mathsf{fma}\left(-0.5, \color{blue}{z \cdot {y}^{2}}, z\right) \]
      3. unpow267.4%

        \[\leadsto \left(x + \sin y\right) + \mathsf{fma}\left(-0.5, z \cdot \color{blue}{\left(y \cdot y\right)}, z\right) \]
    4. Simplified67.4%

      \[\leadsto \left(x + \sin y\right) + \color{blue}{\mathsf{fma}\left(-0.5, z \cdot \left(y \cdot y\right), z\right)} \]
    5. Taylor expanded in z around 0 44.6%

      \[\leadsto \color{blue}{\sin y + x} \]
    6. Taylor expanded in y around 0 28.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-68}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 8: 67.6% accurate, 29.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.19999999999999942e-164 or 1.80000000000000006e-83 < x

    1. Initial program 99.9%

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

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

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

    if -9.19999999999999942e-164 < x < 1.80000000000000006e-83

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\sin y} + z \cdot \cos y \]
    3. Taylor expanded in y around 0 57.9%

      \[\leadsto \color{blue}{y + z} \]
    4. Step-by-step derivation
      1. +-commutative57.9%

        \[\leadsto \color{blue}{z + y} \]
    5. Simplified57.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.2 \cdot 10^{-164}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-83}:\\ \;\;\;\;y + z\\ \mathbf{else}:\\ \;\;\;\;x + z\\ \end{array} \]

Alternative 9: 65.8% 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. Taylor expanded in x around inf 84.1%

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

    \[\leadsto \color{blue}{z + x} \]
  4. Final simplification70.4%

    \[\leadsto x + z \]

Alternative 10: 42.5% 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. Taylor expanded in x around inf 84.1%

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

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

    \[\leadsto x \]

Reproduce

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