SynthBasics:oscSampleBasedAux from YampaSynth-0.2

Percentage Accurate: 100.0% → 100.0%
Time: 3.2s
Alternatives: 7
Speedup: 1.0×

Specification

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

\\
x + y \cdot \left(z - x\right)
\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 7 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: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

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

\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, z - x, x\right)} \]
  4. Final simplification100.0%

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

Alternative 2: 61.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -3.9 \cdot 10^{+253}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{+111}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+22} \lor \neg \left(y \leq 3.5 \cdot 10^{+177}\right) \land \left(y \leq 1.1 \cdot 10^{+186} \lor \neg \left(y \leq 4.1 \cdot 10^{+207}\right) \land y \leq 5.4 \cdot 10^{+223}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- y))))
   (if (<= y -3.9e+253)
     t_0
     (if (<= y -8.5e+111)
       (* y z)
       (if (<= y -1.0)
         t_0
         (if (<= y 3.3e-24)
           x
           (if (or (<= y 9e+22)
                   (and (not (<= y 3.5e+177))
                        (or (<= y 1.1e+186)
                            (and (not (<= y 4.1e+207)) (<= y 5.4e+223)))))
             (* y z)
             t_0)))))))
double code(double x, double y, double z) {
	double t_0 = x * -y;
	double tmp;
	if (y <= -3.9e+253) {
		tmp = t_0;
	} else if (y <= -8.5e+111) {
		tmp = y * z;
	} else if (y <= -1.0) {
		tmp = t_0;
	} else if (y <= 3.3e-24) {
		tmp = x;
	} else if ((y <= 9e+22) || (!(y <= 3.5e+177) && ((y <= 1.1e+186) || (!(y <= 4.1e+207) && (y <= 5.4e+223))))) {
		tmp = y * 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 = x * -y
    if (y <= (-3.9d+253)) then
        tmp = t_0
    else if (y <= (-8.5d+111)) then
        tmp = y * z
    else if (y <= (-1.0d0)) then
        tmp = t_0
    else if (y <= 3.3d-24) then
        tmp = x
    else if ((y <= 9d+22) .or. (.not. (y <= 3.5d+177)) .and. (y <= 1.1d+186) .or. (.not. (y <= 4.1d+207)) .and. (y <= 5.4d+223)) then
        tmp = y * z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * -y;
	double tmp;
	if (y <= -3.9e+253) {
		tmp = t_0;
	} else if (y <= -8.5e+111) {
		tmp = y * z;
	} else if (y <= -1.0) {
		tmp = t_0;
	} else if (y <= 3.3e-24) {
		tmp = x;
	} else if ((y <= 9e+22) || (!(y <= 3.5e+177) && ((y <= 1.1e+186) || (!(y <= 4.1e+207) && (y <= 5.4e+223))))) {
		tmp = y * z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * -y
	tmp = 0
	if y <= -3.9e+253:
		tmp = t_0
	elif y <= -8.5e+111:
		tmp = y * z
	elif y <= -1.0:
		tmp = t_0
	elif y <= 3.3e-24:
		tmp = x
	elif (y <= 9e+22) or (not (y <= 3.5e+177) and ((y <= 1.1e+186) or (not (y <= 4.1e+207) and (y <= 5.4e+223)))):
		tmp = y * z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(-y))
	tmp = 0.0
	if (y <= -3.9e+253)
		tmp = t_0;
	elseif (y <= -8.5e+111)
		tmp = Float64(y * z);
	elseif (y <= -1.0)
		tmp = t_0;
	elseif (y <= 3.3e-24)
		tmp = x;
	elseif ((y <= 9e+22) || (!(y <= 3.5e+177) && ((y <= 1.1e+186) || (!(y <= 4.1e+207) && (y <= 5.4e+223)))))
		tmp = Float64(y * z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * -y;
	tmp = 0.0;
	if (y <= -3.9e+253)
		tmp = t_0;
	elseif (y <= -8.5e+111)
		tmp = y * z;
	elseif (y <= -1.0)
		tmp = t_0;
	elseif (y <= 3.3e-24)
		tmp = x;
	elseif ((y <= 9e+22) || (~((y <= 3.5e+177)) && ((y <= 1.1e+186) || (~((y <= 4.1e+207)) && (y <= 5.4e+223)))))
		tmp = y * z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -3.9e+253], t$95$0, If[LessEqual[y, -8.5e+111], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 3.3e-24], x, If[Or[LessEqual[y, 9e+22], And[N[Not[LessEqual[y, 3.5e+177]], $MachinePrecision], Or[LessEqual[y, 1.1e+186], And[N[Not[LessEqual[y, 4.1e+207]], $MachinePrecision], LessEqual[y, 5.4e+223]]]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -3.9 \cdot 10^{+253}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -8.5 \cdot 10^{+111}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq -1:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 3.3 \cdot 10^{-24}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 9 \cdot 10^{+22} \lor \neg \left(y \leq 3.5 \cdot 10^{+177}\right) \land \left(y \leq 1.1 \cdot 10^{+186} \lor \neg \left(y \leq 4.1 \cdot 10^{+207}\right) \land y \leq 5.4 \cdot 10^{+223}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.9000000000000001e253 or -8.49999999999999983e111 < y < -1 or 8.9999999999999996e22 < y < 3.49999999999999991e177 or 1.0999999999999999e186 < y < 4.1e207 or 5.4000000000000001e223 < y

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(1 + -1 \cdot y\right) \cdot x} \]
    3. Step-by-step derivation
      1. +-commutative73.1%

        \[\leadsto \color{blue}{\left(-1 \cdot y + 1\right)} \cdot x \]
      2. distribute-rgt1-in73.1%

        \[\leadsto \color{blue}{x + \left(-1 \cdot y\right) \cdot x} \]
      3. mul-1-neg73.1%

        \[\leadsto x + \color{blue}{\left(-y\right)} \cdot x \]
      4. cancel-sign-sub-inv73.1%

        \[\leadsto \color{blue}{x - y \cdot x} \]
    4. Simplified73.1%

      \[\leadsto \color{blue}{x - y \cdot x} \]
    5. Taylor expanded in y around inf 71.9%

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

        \[\leadsto \color{blue}{-y \cdot x} \]
      2. distribute-rgt-neg-in71.9%

        \[\leadsto \color{blue}{y \cdot \left(-x\right)} \]
    7. Simplified71.9%

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

    if -3.9000000000000001e253 < y < -8.49999999999999983e111 or 3.29999999999999984e-24 < y < 8.9999999999999996e22 or 3.49999999999999991e177 < y < 1.0999999999999999e186 or 4.1e207 < y < 5.4000000000000001e223

    1. Initial program 100.0%

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

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

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

    if -1 < y < 3.29999999999999984e-24

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification72.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+253}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{+111}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -1:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+22} \lor \neg \left(y \leq 3.5 \cdot 10^{+177}\right) \land \left(y \leq 1.1 \cdot 10^{+186} \lor \neg \left(y \leq 4.1 \cdot 10^{+207}\right) \land y \leq 5.4 \cdot 10^{+223}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \end{array} \]

Alternative 3: 76.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-y\right)\\ t_1 := x + y \cdot z\\ \mathbf{if}\;y \leq -4.3 \cdot 10^{+254}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{+112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+173} \lor \neg \left(y \leq 1.1 \cdot 10^{+186}\right) \land \left(y \leq 2.05 \cdot 10^{+207} \lor \neg \left(y \leq 4 \cdot 10^{+223}\right)\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- y))) (t_1 (+ x (* y z))))
   (if (<= y -4.3e+254)
     t_0
     (if (<= y -2.8e+112)
       t_1
       (if (<= y -1.35e+38)
         t_0
         (if (<= y 6.4e+29)
           t_1
           (if (or (<= y 2.9e+173)
                   (and (not (<= y 1.1e+186))
                        (or (<= y 2.05e+207) (not (<= y 4e+223)))))
             t_0
             (* y z))))))))
double code(double x, double y, double z) {
	double t_0 = x * -y;
	double t_1 = x + (y * z);
	double tmp;
	if (y <= -4.3e+254) {
		tmp = t_0;
	} else if (y <= -2.8e+112) {
		tmp = t_1;
	} else if (y <= -1.35e+38) {
		tmp = t_0;
	} else if (y <= 6.4e+29) {
		tmp = t_1;
	} else if ((y <= 2.9e+173) || (!(y <= 1.1e+186) && ((y <= 2.05e+207) || !(y <= 4e+223)))) {
		tmp = t_0;
	} else {
		tmp = y * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x * -y
    t_1 = x + (y * z)
    if (y <= (-4.3d+254)) then
        tmp = t_0
    else if (y <= (-2.8d+112)) then
        tmp = t_1
    else if (y <= (-1.35d+38)) then
        tmp = t_0
    else if (y <= 6.4d+29) then
        tmp = t_1
    else if ((y <= 2.9d+173) .or. (.not. (y <= 1.1d+186)) .and. (y <= 2.05d+207) .or. (.not. (y <= 4d+223))) then
        tmp = t_0
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * -y;
	double t_1 = x + (y * z);
	double tmp;
	if (y <= -4.3e+254) {
		tmp = t_0;
	} else if (y <= -2.8e+112) {
		tmp = t_1;
	} else if (y <= -1.35e+38) {
		tmp = t_0;
	} else if (y <= 6.4e+29) {
		tmp = t_1;
	} else if ((y <= 2.9e+173) || (!(y <= 1.1e+186) && ((y <= 2.05e+207) || !(y <= 4e+223)))) {
		tmp = t_0;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * -y
	t_1 = x + (y * z)
	tmp = 0
	if y <= -4.3e+254:
		tmp = t_0
	elif y <= -2.8e+112:
		tmp = t_1
	elif y <= -1.35e+38:
		tmp = t_0
	elif y <= 6.4e+29:
		tmp = t_1
	elif (y <= 2.9e+173) or (not (y <= 1.1e+186) and ((y <= 2.05e+207) or not (y <= 4e+223))):
		tmp = t_0
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(-y))
	t_1 = Float64(x + Float64(y * z))
	tmp = 0.0
	if (y <= -4.3e+254)
		tmp = t_0;
	elseif (y <= -2.8e+112)
		tmp = t_1;
	elseif (y <= -1.35e+38)
		tmp = t_0;
	elseif (y <= 6.4e+29)
		tmp = t_1;
	elseif ((y <= 2.9e+173) || (!(y <= 1.1e+186) && ((y <= 2.05e+207) || !(y <= 4e+223))))
		tmp = t_0;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * -y;
	t_1 = x + (y * z);
	tmp = 0.0;
	if (y <= -4.3e+254)
		tmp = t_0;
	elseif (y <= -2.8e+112)
		tmp = t_1;
	elseif (y <= -1.35e+38)
		tmp = t_0;
	elseif (y <= 6.4e+29)
		tmp = t_1;
	elseif ((y <= 2.9e+173) || (~((y <= 1.1e+186)) && ((y <= 2.05e+207) || ~((y <= 4e+223)))))
		tmp = t_0;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.3e+254], t$95$0, If[LessEqual[y, -2.8e+112], t$95$1, If[LessEqual[y, -1.35e+38], t$95$0, If[LessEqual[y, 6.4e+29], t$95$1, If[Or[LessEqual[y, 2.9e+173], And[N[Not[LessEqual[y, 1.1e+186]], $MachinePrecision], Or[LessEqual[y, 2.05e+207], N[Not[LessEqual[y, 4e+223]], $MachinePrecision]]]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
t_1 := x + y \cdot z\\
\mathbf{if}\;y \leq -4.3 \cdot 10^{+254}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -2.8 \cdot 10^{+112}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -1.35 \cdot 10^{+38}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 6.4 \cdot 10^{+29}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 2.9 \cdot 10^{+173} \lor \neg \left(y \leq 1.1 \cdot 10^{+186}\right) \land \left(y \leq 2.05 \cdot 10^{+207} \lor \neg \left(y \leq 4 \cdot 10^{+223}\right)\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.30000000000000012e254 or -2.8000000000000001e112 < y < -1.34999999999999998e38 or 6.39999999999999973e29 < y < 2.90000000000000007e173 or 1.0999999999999999e186 < y < 2.05e207 or 4.00000000000000019e223 < y

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(1 + -1 \cdot y\right) \cdot x} \]
    3. Step-by-step derivation
      1. +-commutative75.1%

        \[\leadsto \color{blue}{\left(-1 \cdot y + 1\right)} \cdot x \]
      2. distribute-rgt1-in75.1%

        \[\leadsto \color{blue}{x + \left(-1 \cdot y\right) \cdot x} \]
      3. mul-1-neg75.1%

        \[\leadsto x + \color{blue}{\left(-y\right)} \cdot x \]
      4. cancel-sign-sub-inv75.1%

        \[\leadsto \color{blue}{x - y \cdot x} \]
    4. Simplified75.1%

      \[\leadsto \color{blue}{x - y \cdot x} \]
    5. Taylor expanded in y around inf 75.1%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot x\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg75.1%

        \[\leadsto \color{blue}{-y \cdot x} \]
      2. distribute-rgt-neg-in75.1%

        \[\leadsto \color{blue}{y \cdot \left(-x\right)} \]
    7. Simplified75.1%

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

    if -4.30000000000000012e254 < y < -2.8000000000000001e112 or -1.34999999999999998e38 < y < 6.39999999999999973e29

    1. Initial program 100.0%

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

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

    if 2.90000000000000007e173 < y < 1.0999999999999999e186 or 2.05e207 < y < 4.00000000000000019e223

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{+254}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{+112}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{+38}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{+29}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+173} \lor \neg \left(y \leq 1.1 \cdot 10^{+186}\right) \land \left(y \leq 2.05 \cdot 10^{+207} \lor \neg \left(y \leq 4 \cdot 10^{+223}\right)\right):\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 4: 83.7% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-49} \lor \neg \left(x \leq 7 \cdot 10^{-118} \lor \neg \left(x \leq 6.2 \cdot 10^{-30}\right) \land x \leq 2.6 \cdot 10^{+55}\right):\\
\;\;\;\;x - y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.15e-49 or 7e-118 < x < 6.19999999999999982e-30 or 2.6e55 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(1 + -1 \cdot y\right) \cdot x} \]
    3. Step-by-step derivation
      1. +-commutative90.5%

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

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

        \[\leadsto x + \color{blue}{\left(-y\right)} \cdot x \]
      4. cancel-sign-sub-inv90.5%

        \[\leadsto \color{blue}{x - y \cdot x} \]
    4. Simplified90.5%

      \[\leadsto \color{blue}{x - y \cdot x} \]

    if -1.15e-49 < x < 7e-118 or 6.19999999999999982e-30 < x < 2.6e55

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{-49} \lor \neg \left(x \leq 7 \cdot 10^{-118} \lor \neg \left(x \leq 6.2 \cdot 10^{-30}\right) \land x \leq 2.6 \cdot 10^{+55}\right):\\ \;\;\;\;x - y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]

Alternative 5: 61.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 2.6 \cdot 10^{-24}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.00000000000000036e-18 or 2.6e-24 < y

    1. Initial program 100.0%

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

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

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

    if -5.00000000000000036e-18 < y < 2.6e-24

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification59.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-18}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 6: 100.0% accurate, 1.0× speedup?

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

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

    \[x + y \cdot \left(z - x\right) \]
  2. Final simplification100.0%

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

Alternative 7: 36.2% accurate, 7.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 100.0%

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

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

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023230 
(FPCore (x y z)
  :name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
  :precision binary64
  (+ x (* y (- z x))))