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

Percentage Accurate: 99.9% → 99.9%
Time: 9.5s
Alternatives: 11
Speedup: 1.0×

Specification

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

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

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

Alternative 1: 99.9% accurate, 1.0× speedup?

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

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

    \[\left(x + \cos y\right) - z \cdot \sin y \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 99.3% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -58000000 \lor \neg \left(z \leq 0.0135\right):\\
\;\;\;\;\left(x + 1\right) - z \cdot \sin y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.8e7 or 0.0134999999999999998 < z

    1. Initial program 99.8%

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

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

    if -5.8e7 < z < 0.0134999999999999998

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x + \cos y} \]
    4. Step-by-step derivation
      1. +-commutative99.0%

        \[\leadsto \color{blue}{\cos y + x} \]
    5. Simplified99.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -58000000 \lor \neg \left(z \leq 0.0135\right):\\ \;\;\;\;\left(x + 1\right) - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;x + \cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 84.7% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.12 \cdot 10^{+110} \lor \neg \left(z \leq 8.5 \cdot 10^{+78}\right):\\
\;\;\;\;1 - z \cdot \sin y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.1200000000000001e110 or 8.50000000000000079e78 < z

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\cos y - z \cdot \sin y} \]
    4. Taylor expanded in y around 0 78.4%

      \[\leadsto \color{blue}{1} - z \cdot \sin y \]

    if -1.1200000000000001e110 < z < 8.50000000000000079e78

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x + \cos y} \]
    4. Step-by-step derivation
      1. +-commutative92.7%

        \[\leadsto \color{blue}{\cos y + x} \]
    5. Simplified92.7%

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

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

Alternative 4: 80.9% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+176} \lor \neg \left(z \leq 5 \cdot 10^{+72}\right):\\
\;\;\;\;\sin y \cdot \left(-z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.4999999999999995e176 or 4.99999999999999992e72 < z

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right)} \]
    4. Step-by-step derivation
      1. mul-1-neg73.8%

        \[\leadsto \color{blue}{-z \cdot \sin y} \]
      2. *-commutative73.8%

        \[\leadsto -\color{blue}{\sin y \cdot z} \]
      3. distribute-rgt-neg-in73.8%

        \[\leadsto \color{blue}{\sin y \cdot \left(-z\right)} \]
    5. Simplified73.8%

      \[\leadsto \color{blue}{\sin y \cdot \left(-z\right)} \]

    if -5.4999999999999995e176 < z < 4.99999999999999992e72

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x + \cos y} \]
    4. Step-by-step derivation
      1. +-commutative89.4%

        \[\leadsto \color{blue}{\cos y + x} \]
    5. Simplified89.4%

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

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

Alternative 5: 79.7% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1420000000000 \lor \neg \left(y \leq 1.9 \cdot 10^{-27}\right):\\
\;\;\;\;x + \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.42e12 or 1.9e-27 < y

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{\cos y + x} \]
    5. Simplified65.9%

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

    if -1.42e12 < y < 1.9e-27

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(y \cdot \left(0.16666666666666666 \cdot \left(y \cdot z\right) - 0.5\right) - z\right)\right)} \]
    4. Taylor expanded in y around inf 99.2%

      \[\leadsto 1 + \left(x + y \cdot \left(y \cdot \color{blue}{\left(0.16666666666666666 \cdot \left(y \cdot z\right)\right)} - z\right)\right) \]
    5. Step-by-step derivation
      1. *-commutative99.2%

        \[\leadsto 1 + \left(x + y \cdot \left(y \cdot \color{blue}{\left(\left(y \cdot z\right) \cdot 0.16666666666666666\right)} - z\right)\right) \]
      2. associate-*r*99.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1420000000000 \lor \neg \left(y \leq 1.9 \cdot 10^{-27}\right):\\ \;\;\;\;x + \cos y\\ \mathbf{else}:\\ \;\;\;\;1 + \left(x + y \cdot \left(y \cdot \left(y \cdot \left(z \cdot 0.16666666666666666\right)\right) - z\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 72.5% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00092 \lor \neg \left(x \leq 0.0013\right):\\
\;\;\;\;x + 1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.2000000000000003e-4 or 0.0012999999999999999 < x

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{1 + x} \]
    4. Step-by-step derivation
      1. +-commutative79.9%

        \[\leadsto \color{blue}{x + 1} \]
    5. Simplified79.9%

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

    if -9.2000000000000003e-4 < x < 0.0012999999999999999

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{\cos y + x} \]
    5. Simplified65.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.00092 \lor \neg \left(x \leq 0.0013\right):\\ \;\;\;\;x + 1\\ \mathbf{else}:\\ \;\;\;\;\cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 70.2% accurate, 12.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -100:\\
\;\;\;\;x + 1\\

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

\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + \frac{1}{x}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -100

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{1 + x} \]
    4. Step-by-step derivation
      1. +-commutative30.3%

        \[\leadsto \color{blue}{x + 1} \]
    5. Simplified30.3%

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

    if -100 < y < 2.2e11

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1 + \left(x + -1 \cdot \left(y \cdot z\right)\right)} \]
    4. Step-by-step derivation
      1. associate-+r+98.5%

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

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

        \[\leadsto \color{blue}{x + \left(1 + -1 \cdot \left(y \cdot z\right)\right)} \]
      4. mul-1-neg98.5%

        \[\leadsto x + \left(1 + \color{blue}{\left(-y \cdot z\right)}\right) \]
      5. unsub-neg98.5%

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

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

    if 2.2e11 < y

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{1 + x} \]
    4. Step-by-step derivation
      1. +-commutative46.9%

        \[\leadsto \color{blue}{x + 1} \]
    5. Simplified46.9%

      \[\leadsto \color{blue}{x + 1} \]
    6. Taylor expanded in x around inf 46.9%

      \[\leadsto \color{blue}{x \cdot \left(1 + \frac{1}{x}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 67.5% accurate, 13.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-21}:\\
\;\;\;\;\left(x + 2\right) + -1\\

\mathbf{elif}\;x \leq 19500:\\
\;\;\;\;1 - y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.49999999999999996e-21

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{x + 1} \]
    5. Simplified76.4%

      \[\leadsto \color{blue}{x + 1} \]
    6. Step-by-step derivation
      1. expm1-log1p-u2.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x + 1\right)\right)} \]
      2. expm1-undefine2.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(x + 1\right)} - 1} \]
    7. Applied egg-rr2.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(x + 1\right)} - 1} \]
    8. Step-by-step derivation
      1. sub-neg2.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(x + 1\right)} + \left(-1\right)} \]
      2. log1p-undefine2.6%

        \[\leadsto e^{\color{blue}{\log \left(1 + \left(x + 1\right)\right)}} + \left(-1\right) \]
      3. rem-exp-log76.4%

        \[\leadsto \color{blue}{\left(1 + \left(x + 1\right)\right)} + \left(-1\right) \]
      4. +-commutative76.4%

        \[\leadsto \left(1 + \color{blue}{\left(1 + x\right)}\right) + \left(-1\right) \]
      5. associate-+r+76.4%

        \[\leadsto \color{blue}{\left(\left(1 + 1\right) + x\right)} + \left(-1\right) \]
      6. metadata-eval76.4%

        \[\leadsto \left(\color{blue}{2} + x\right) + \left(-1\right) \]
      7. metadata-eval76.4%

        \[\leadsto \left(2 + x\right) + \color{blue}{-1} \]
    9. Simplified76.4%

      \[\leadsto \color{blue}{\left(2 + x\right) + -1} \]

    if -1.49999999999999996e-21 < x < 19500

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x \cdot \left(\left(1 + \frac{\cos y}{x}\right) - \frac{z \cdot \sin y}{x}\right)} \]
    4. Step-by-step derivation
      1. associate--l+86.3%

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(\frac{\cos y}{x} - \frac{z \cdot \sin y}{x}\right)\right)} \]
      2. div-sub86.3%

        \[\leadsto x \cdot \left(1 + \color{blue}{\frac{\cos y - z \cdot \sin y}{x}}\right) \]
    5. Simplified86.3%

      \[\leadsto \color{blue}{x \cdot \left(1 + \frac{\cos y - z \cdot \sin y}{x}\right)} \]
    6. Taylor expanded in y around 0 44.8%

      \[\leadsto x \cdot \left(1 + \frac{\color{blue}{1 + -1 \cdot \left(y \cdot z\right)}}{x}\right) \]
    7. Step-by-step derivation
      1. mul-1-neg44.8%

        \[\leadsto x \cdot \left(1 + \frac{1 + \color{blue}{\left(-y \cdot z\right)}}{x}\right) \]
    8. Simplified44.8%

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

      \[\leadsto \color{blue}{1 - y \cdot z} \]

    if 19500 < x

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{1 + x} \]
    4. Step-by-step derivation
      1. +-commutative80.3%

        \[\leadsto \color{blue}{x + 1} \]
    5. Simplified80.3%

      \[\leadsto \color{blue}{x + 1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification63.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{-21}:\\ \;\;\;\;\left(x + 2\right) + -1\\ \mathbf{elif}\;x \leq 19500:\\ \;\;\;\;1 - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + 1\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 62.0% accurate, 18.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 0.00125:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.0) x (if (<= x 0.00125) 1.0 x)))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.0) {
		tmp = x;
	} else if (x <= 0.00125) {
		tmp = 1.0;
	} 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.0d0)) then
        tmp = x
    else if (x <= 0.00125d0) then
        tmp = 1.0d0
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.0) {
		tmp = x;
	} else if (x <= 0.00125) {
		tmp = 1.0;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.0:
		tmp = x
	elif x <= 0.00125:
		tmp = 1.0
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.0)
		tmp = x;
	elseif (x <= 0.00125)
		tmp = 1.0;
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.0)
		tmp = x;
	elseif (x <= 0.00125)
		tmp = 1.0;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.0], x, If[LessEqual[x, 0.00125], 1.0, x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq 0.00125:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 0.00125000000000000003 < x

    1. Initial program 99.9%

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

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

    if -1 < x < 0.00125000000000000003

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{1 + x} \]
    4. Step-by-step derivation
      1. +-commutative38.5%

        \[\leadsto \color{blue}{x + 1} \]
    5. Simplified38.5%

      \[\leadsto \color{blue}{x + 1} \]
    6. Taylor expanded in x around 0 38.5%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 62.6% accurate, 69.0× speedup?

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

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

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

    \[\leadsto \color{blue}{1 + x} \]
  4. Step-by-step derivation
    1. +-commutative58.7%

      \[\leadsto \color{blue}{x + 1} \]
  5. Simplified58.7%

    \[\leadsto \color{blue}{x + 1} \]
  6. Add Preprocessing

Alternative 11: 21.8% accurate, 207.0× speedup?

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

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

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

    \[\leadsto \color{blue}{1 + x} \]
  4. Step-by-step derivation
    1. +-commutative58.7%

      \[\leadsto \color{blue}{x + 1} \]
  5. Simplified58.7%

    \[\leadsto \color{blue}{x + 1} \]
  6. Taylor expanded in x around 0 21.0%

    \[\leadsto \color{blue}{1} \]
  7. Add Preprocessing

Reproduce

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