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

Percentage Accurate: 99.9% → 99.9%
Time: 7.5s
Alternatives: 11
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 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 + \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. Add Preprocessing
  3. Final simplification99.9%

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

Alternative 2: 82.3% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;z \leq -1.95 \cdot 10^{+68}:\\
\;\;\;\;x + z\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.5e137 or -1.95000000000000009e68 < z < -0.0719999999999999946 or 1.6e18 < z

    1. Initial program 99.9%

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

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

    if -1.5e137 < z < -1.95000000000000009e68

    1. Initial program 100.0%

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

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

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

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

    if -0.0719999999999999946 < z < 1.6e18

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\sin y + x} \]
    5. Simplified91.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{+137}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{+68}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -0.072 \lor \neg \left(z \leq 1.6 \cdot 10^{+18}\right):\\ \;\;\;\;z \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 95.2% accurate, 1.8× speedup?

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

    1. Initial program 99.9%

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

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

    if -0.034000000000000002 < z < 5.9e-12

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\sin y + x} \]
    5. Simplified91.6%

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

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

Alternative 4: 99.4% accurate, 1.8× speedup?

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

    1. Initial program 99.9%

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

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

    if -0.75 < z < 3e-11

    1. Initial program 100.0%

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

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

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

Alternative 5: 72.8% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2300000000 \lor \neg \left(x \leq 2.2 \cdot 10^{-14}\right):\\
\;\;\;\;x + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.3e9 or 2.2000000000000001e-14 < x

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{z + x} \]
    5. Simplified90.8%

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

    if -2.3e9 < x < 2.2000000000000001e-14

    1. Initial program 99.9%

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

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

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

Alternative 6: 67.8% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

    if -7e6 < y < 7.6000000000000004e66

    1. Initial program 100.0%

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

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

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

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

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

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

    if 7.6000000000000004e66 < y

    1. Initial program 99.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7000000:\\ \;\;\;\;x + z\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{+66}:\\ \;\;\;\;z + \left(x + y\right)\\ \mathbf{else}:\\ \;\;\;\;\sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 70.9% accurate, 13.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1900000 \lor \neg \left(y \leq 5.5 \cdot 10^{-8}\right):\\
\;\;\;\;x + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.9e6 or 5.5000000000000003e-8 < y

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{z + x} \]
    5. Simplified41.0%

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

    if -1.9e6 < y < 5.5000000000000003e-8

    1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 8: 59.5% accurate, 15.9× speedup?

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

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

\mathbf{elif}\;x \leq 14800000:\\
\;\;\;\;y + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.25e14 or 1.48e7 < x

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\cos y \cdot z} + \left(x + \sin y\right) \]
      3. add-cube-cbrt99.9%

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

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

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

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

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

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

    if -1.25e14 < x < 1.48e7

    1. Initial program 99.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 14800000:\\ \;\;\;\;y + z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 55.9% accurate, 18.8× speedup?

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

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

\mathbf{elif}\;x \leq 11000000000:\\
\;\;\;\;z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.25e14 or 1.1e10 < x

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\cos y \cdot z} + \left(x + \sin y\right) \]
      3. add-cube-cbrt99.9%

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

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

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

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

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

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

    if -1.25e14 < x < 1.1e10

    1. Initial program 99.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 11000000000:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 66.6% 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. Add Preprocessing
  3. Taylor expanded in y around 0 65.7%

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

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

    \[\leadsto \color{blue}{z + x} \]
  6. Final simplification65.7%

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

Alternative 11: 42.7% accurate, 207.0× speedup?

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

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

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

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

      \[\leadsto \color{blue}{\cos y \cdot z} + \left(x + \sin y\right) \]
    3. add-cube-cbrt99.7%

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

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

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

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

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

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

    \[\leadsto x \]
  7. Add Preprocessing

Reproduce

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