SynthBasics:oscSampleBasedAux from YampaSynth-0.2

Percentage Accurate: 100.0% → 100.0%
Time: 5.5s
Alternatives: 8
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 8 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-define100.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. Add Preprocessing
  5. Final simplification100.0%

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

Alternative 2: 60.4% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;y \leq -2.35 \cdot 10^{-90}:\\
\;\;\;\;x\\

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

\mathbf{elif}\;y \leq 1.18 \cdot 10^{-49}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 4.8 \cdot 10^{+68}:\\
\;\;\;\;y \cdot z\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.65e-64 or -2.35e-90 < y < -4.09999999999999968e-111 or 1.18e-49 < y < 4.80000000000000016e68

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{y \cdot \left(z + \frac{x}{y}\right)} \]
    5. Taylor expanded in y around inf 65.1%

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

    if -1.65e-64 < y < -2.35e-90 or -4.09999999999999968e-111 < y < 1.18e-49

    1. Initial program 100.0%

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

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

    if 4.80000000000000016e68 < y

    1. Initial program 100.0%

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

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

      \[\leadsto y \cdot \left(\color{blue}{z} - x\right) \]
    5. Taylor expanded in z around 0 57.5%

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

        \[\leadsto \color{blue}{-x \cdot y} \]
      2. distribute-lft-neg-out57.5%

        \[\leadsto \color{blue}{\left(-x\right) \cdot y} \]
      3. *-commutative57.5%

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

      \[\leadsto \color{blue}{y \cdot \left(-x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification68.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{-64}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -2.35 \cdot 10^{-90}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{-111}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.18 \cdot 10^{-49}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+68}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 83.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(z - x\right)\\ \mathbf{if}\;y \leq -6.8 \cdot 10^{-65}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-88}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-112} \lor \neg \left(y \leq 1.55 \cdot 10^{-50}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- z x))))
   (if (<= y -6.8e-65)
     t_0
     (if (<= y -3.6e-88)
       (* x (- 1.0 y))
       (if (or (<= y -3.7e-112) (not (<= y 1.55e-50))) t_0 x)))))
double code(double x, double y, double z) {
	double t_0 = y * (z - x);
	double tmp;
	if (y <= -6.8e-65) {
		tmp = t_0;
	} else if (y <= -3.6e-88) {
		tmp = x * (1.0 - y);
	} else if ((y <= -3.7e-112) || !(y <= 1.55e-50)) {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = y * (z - x)
    if (y <= (-6.8d-65)) then
        tmp = t_0
    else if (y <= (-3.6d-88)) then
        tmp = x * (1.0d0 - y)
    else if ((y <= (-3.7d-112)) .or. (.not. (y <= 1.55d-50))) then
        tmp = t_0
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (z - x);
	double tmp;
	if (y <= -6.8e-65) {
		tmp = t_0;
	} else if (y <= -3.6e-88) {
		tmp = x * (1.0 - y);
	} else if ((y <= -3.7e-112) || !(y <= 1.55e-50)) {
		tmp = t_0;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (z - x)
	tmp = 0
	if y <= -6.8e-65:
		tmp = t_0
	elif y <= -3.6e-88:
		tmp = x * (1.0 - y)
	elif (y <= -3.7e-112) or not (y <= 1.55e-50):
		tmp = t_0
	else:
		tmp = x
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(z - x))
	tmp = 0.0
	if (y <= -6.8e-65)
		tmp = t_0;
	elseif (y <= -3.6e-88)
		tmp = Float64(x * Float64(1.0 - y));
	elseif ((y <= -3.7e-112) || !(y <= 1.55e-50))
		tmp = t_0;
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (z - x);
	tmp = 0.0;
	if (y <= -6.8e-65)
		tmp = t_0;
	elseif (y <= -3.6e-88)
		tmp = x * (1.0 - y);
	elseif ((y <= -3.7e-112) || ~((y <= 1.55e-50)))
		tmp = t_0;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.8e-65], t$95$0, If[LessEqual[y, -3.6e-88], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -3.7e-112], N[Not[LessEqual[y, 1.55e-50]], $MachinePrecision]], t$95$0, x]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -6.8 \cdot 10^{-65}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -3.6 \cdot 10^{-88}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\

\mathbf{elif}\;y \leq -3.7 \cdot 10^{-112} \lor \neg \left(y \leq 1.55 \cdot 10^{-50}\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -6.79999999999999973e-65 or -3.5999999999999999e-88 < y < -3.6999999999999998e-112 or 1.5500000000000001e-50 < y

    1. Initial program 100.0%

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

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

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

    if -6.79999999999999973e-65 < y < -3.5999999999999999e-88

    1. Initial program 100.0%

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

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

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

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

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

    if -3.6999999999999998e-112 < y < 1.5500000000000001e-50

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.8 \cdot 10^{-65}:\\ \;\;\;\;y \cdot \left(z - x\right)\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-88}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-112} \lor \neg \left(y \leq 1.55 \cdot 10^{-50}\right):\\ \;\;\;\;y \cdot \left(z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 60.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.35 \cdot 10^{-64} \lor \neg \left(y \leq -5.5 \cdot 10^{-89} \lor \neg \left(y \leq -8.4 \cdot 10^{-111}\right) \land y \leq 8 \cdot 10^{-51}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.35e-64)
         (not (or (<= y -5.5e-89) (and (not (<= y -8.4e-111)) (<= y 8e-51)))))
   (* y z)
   x))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.35e-64) || !((y <= -5.5e-89) || (!(y <= -8.4e-111) && (y <= 8e-51)))) {
		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 ((y <= (-1.35d-64)) .or. (.not. (y <= (-5.5d-89)) .or. (.not. (y <= (-8.4d-111))) .and. (y <= 8d-51))) 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 ((y <= -1.35e-64) || !((y <= -5.5e-89) || (!(y <= -8.4e-111) && (y <= 8e-51)))) {
		tmp = y * z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.35e-64) or not ((y <= -5.5e-89) or (not (y <= -8.4e-111) and (y <= 8e-51))):
		tmp = y * z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.35e-64) || !((y <= -5.5e-89) || (!(y <= -8.4e-111) && (y <= 8e-51))))
		tmp = Float64(y * z);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1.35e-64) || ~(((y <= -5.5e-89) || (~((y <= -8.4e-111)) && (y <= 8e-51)))))
		tmp = y * z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-64], N[Not[Or[LessEqual[y, -5.5e-89], And[N[Not[LessEqual[y, -8.4e-111]], $MachinePrecision], LessEqual[y, 8e-51]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-64} \lor \neg \left(y \leq -5.5 \cdot 10^{-89} \lor \neg \left(y \leq -8.4 \cdot 10^{-111}\right) \land y \leq 8 \cdot 10^{-51}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.34999999999999993e-64 or -5.50000000000000012e-89 < y < -8.3999999999999995e-111 or 8.0000000000000001e-51 < y

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{y \cdot \left(z + \frac{x}{y}\right)} \]
    5. Taylor expanded in y around inf 58.9%

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

    if -1.34999999999999993e-64 < y < -5.50000000000000012e-89 or -8.3999999999999995e-111 < y < 8.0000000000000001e-51

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.35 \cdot 10^{-64} \lor \neg \left(y \leq -5.5 \cdot 10^{-89} \lor \neg \left(y \leq -8.4 \cdot 10^{-111}\right) \land y \leq 8 \cdot 10^{-51}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 75.0% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -450000000000 \lor \neg \left(z \leq 4.8 \cdot 10^{+69}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.5e11 or 4.8000000000000003e69 < z

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{y \cdot \left(z + \frac{x}{y}\right)} \]
    5. Taylor expanded in y around inf 77.6%

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

    if -4.5e11 < z < 4.8000000000000003e69

    1. Initial program 100.0%

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

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

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

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

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

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

Alternative 6: 98.8% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

    if -1.4e6 < y < 1

    1. Initial program 100.0%

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

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

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

Alternative 7: 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. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 8: 36.6% 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. Add Preprocessing
  3. Taylor expanded in y around 0 37.6%

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

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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