
(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:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x y z) :precision binary64 (fma (- z x) y x))
double code(double x, double y, double z) {
return fma((z - x), y, x);
}
function code(x, y, z) return fma(Float64(z - x), y, x) end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.45e+226)
(* y z)
(if (<= y -3.8e+128)
(* (- y) x)
(if (<= y -9e-31) (* y z) (if (<= y 7e-56) (* 1.0 x) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.45e+226) {
tmp = y * z;
} else if (y <= -3.8e+128) {
tmp = -y * x;
} else if (y <= -9e-31) {
tmp = y * z;
} else if (y <= 7e-56) {
tmp = 1.0 * 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 <= (-1.45d+226)) then
tmp = y * z
else if (y <= (-3.8d+128)) then
tmp = -y * x
else if (y <= (-9d-31)) then
tmp = y * z
else if (y <= 7d-56) then
tmp = 1.0d0 * 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 <= -1.45e+226) {
tmp = y * z;
} else if (y <= -3.8e+128) {
tmp = -y * x;
} else if (y <= -9e-31) {
tmp = y * z;
} else if (y <= 7e-56) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.45e+226: tmp = y * z elif y <= -3.8e+128: tmp = -y * x elif y <= -9e-31: tmp = y * z elif y <= 7e-56: tmp = 1.0 * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.45e+226) tmp = Float64(y * z); elseif (y <= -3.8e+128) tmp = Float64(Float64(-y) * x); elseif (y <= -9e-31) tmp = Float64(y * z); elseif (y <= 7e-56) tmp = Float64(1.0 * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.45e+226) tmp = y * z; elseif (y <= -3.8e+128) tmp = -y * x; elseif (y <= -9e-31) tmp = y * z; elseif (y <= 7e-56) tmp = 1.0 * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.45e+226], N[(y * z), $MachinePrecision], If[LessEqual[y, -3.8e+128], N[((-y) * x), $MachinePrecision], If[LessEqual[y, -9e-31], N[(y * z), $MachinePrecision], If[LessEqual[y, 7e-56], N[(1.0 * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+226}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -3.8 \cdot 10^{+128}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq -9 \cdot 10^{-31}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-56}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.44999999999999987e226 or -3.7999999999999999e128 < y < -9.0000000000000008e-31 or 6.9999999999999996e-56 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6462.8
Applied rewrites62.8%
if -1.44999999999999987e226 < y < -3.7999999999999999e128Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6473.5
Applied rewrites73.5%
Taylor expanded in y around inf
Applied rewrites73.5%
if -9.0000000000000008e-31 < y < 6.9999999999999996e-56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.1
Applied rewrites77.1%
Taylor expanded in y around 0
Applied rewrites77.1%
Final simplification69.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -7.1e-31) t_0 (if (<= y 1.3e-55) (* (- 1.0 y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -7.1e-31) {
tmp = t_0;
} else if (y <= 1.3e-55) {
tmp = (1.0 - y) * x;
} 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 = y * (z - x)
if (y <= (-7.1d-31)) then
tmp = t_0
else if (y <= 1.3d-55) then
tmp = (1.0d0 - y) * x
else
tmp = t_0
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 <= -7.1e-31) {
tmp = t_0;
} else if (y <= 1.3e-55) {
tmp = (1.0 - y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -7.1e-31: tmp = t_0 elif y <= 1.3e-55: tmp = (1.0 - y) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -7.1e-31) tmp = t_0; elseif (y <= 1.3e-55) tmp = Float64(Float64(1.0 - y) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (y <= -7.1e-31) tmp = t_0; elseif (y <= 1.3e-55) tmp = (1.0 - y) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.1e-31], t$95$0, If[LessEqual[y, 1.3e-55], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -7.1 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-55}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.0999999999999999e-31 or 1.2999999999999999e-55 < y Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f6496.0
Applied rewrites96.0%
Taylor expanded in y around inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
lower--.f6497.3
Applied rewrites97.3%
if -7.0999999999999999e-31 < y < 1.2999999999999999e-55Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.1
Applied rewrites77.1%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.24e-5) (* y z) (if (<= z 1e+142) (fma (- y) x x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.24e-5) {
tmp = y * z;
} else if (z <= 1e+142) {
tmp = fma(-y, x, x);
} else {
tmp = y * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.24e-5) tmp = Float64(y * z); elseif (z <= 1e+142) tmp = fma(Float64(-y), x, x); else tmp = Float64(y * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.24e-5], N[(y * z), $MachinePrecision], If[LessEqual[z, 1e+142], N[((-y) * x + x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.24 \cdot 10^{-5}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 10^{+142}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.24e-5 or 1.00000000000000005e142 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6474.2
Applied rewrites74.2%
if -1.24e-5 < z < 1.00000000000000005e142Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6482.3
Applied rewrites82.3%
Applied rewrites82.3%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.24e-5) (* y z) (if (<= z 1e+142) (* (- 1.0 y) x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.24e-5) {
tmp = y * z;
} else if (z <= 1e+142) {
tmp = (1.0 - y) * 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 (z <= (-1.24d-5)) then
tmp = y * z
else if (z <= 1d+142) then
tmp = (1.0d0 - y) * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.24e-5) {
tmp = y * z;
} else if (z <= 1e+142) {
tmp = (1.0 - y) * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.24e-5: tmp = y * z elif z <= 1e+142: tmp = (1.0 - y) * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.24e-5) tmp = Float64(y * z); elseif (z <= 1e+142) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.24e-5) tmp = y * z; elseif (z <= 1e+142) tmp = (1.0 - y) * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.24e-5], N[(y * z), $MachinePrecision], If[LessEqual[z, 1e+142], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.24 \cdot 10^{-5}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 10^{+142}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.24e-5 or 1.00000000000000005e142 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6474.2
Applied rewrites74.2%
if -1.24e-5 < z < 1.00000000000000005e142Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6482.3
Applied rewrites82.3%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (<= y -9e-31) (* y z) (if (<= y 7e-56) (* 1.0 x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-31) {
tmp = y * z;
} else if (y <= 7e-56) {
tmp = 1.0 * 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 <= (-9d-31)) then
tmp = y * z
else if (y <= 7d-56) then
tmp = 1.0d0 * 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 <= -9e-31) {
tmp = y * z;
} else if (y <= 7e-56) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9e-31: tmp = y * z elif y <= 7e-56: tmp = 1.0 * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9e-31) tmp = Float64(y * z); elseif (y <= 7e-56) tmp = Float64(1.0 * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9e-31) tmp = y * z; elseif (y <= 7e-56) tmp = 1.0 * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9e-31], N[(y * z), $MachinePrecision], If[LessEqual[y, 7e-56], N[(1.0 * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-31}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-56}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -9.0000000000000008e-31 or 6.9999999999999996e-56 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6457.0
Applied rewrites57.0%
if -9.0000000000000008e-31 < y < 6.9999999999999996e-56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.1
Applied rewrites77.1%
Taylor expanded in y around 0
Applied rewrites77.1%
Final simplification65.2%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6444.3
Applied rewrites44.3%
Final simplification44.3%
herbie shell --seed 2024295
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))