
(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 6 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 (<= z -9.2e+55) (* y z) (if (<= z -5.5e-290) (* 1.0 x) (if (<= z 1.22e-26) (* (- y) x) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e+55) {
tmp = y * z;
} else if (z <= -5.5e-290) {
tmp = 1.0 * x;
} else if (z <= 1.22e-26) {
tmp = -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 <= (-9.2d+55)) then
tmp = y * z
else if (z <= (-5.5d-290)) then
tmp = 1.0d0 * x
else if (z <= 1.22d-26) then
tmp = -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 <= -9.2e+55) {
tmp = y * z;
} else if (z <= -5.5e-290) {
tmp = 1.0 * x;
} else if (z <= 1.22e-26) {
tmp = -y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.2e+55: tmp = y * z elif z <= -5.5e-290: tmp = 1.0 * x elif z <= 1.22e-26: tmp = -y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.2e+55) tmp = Float64(y * z); elseif (z <= -5.5e-290) tmp = Float64(1.0 * x); elseif (z <= 1.22e-26) tmp = Float64(Float64(-y) * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.2e+55) tmp = y * z; elseif (z <= -5.5e-290) tmp = 1.0 * x; elseif (z <= 1.22e-26) tmp = -y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.2e+55], N[(y * z), $MachinePrecision], If[LessEqual[z, -5.5e-290], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 1.22e-26], N[((-y) * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+55}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-290}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;z \leq 1.22 \cdot 10^{-26}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -9.1999999999999995e55 or 1.22e-26 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6473.9
Applied rewrites73.9%
if -9.1999999999999995e55 < z < -5.5e-290Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6489.2
Applied rewrites89.2%
Taylor expanded in y around 0
Applied rewrites59.3%
if -5.5e-290 < z < 1.22e-26Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6487.9
Applied rewrites87.9%
Taylor expanded in y around inf
Applied rewrites58.7%
Final simplification66.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -1e-65) t_0 (if (<= y 1.15e-66) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -1e-65) {
tmp = t_0;
} else if (y <= 1.15e-66) {
tmp = 1.0 * 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 <= (-1d-65)) then
tmp = t_0
else if (y <= 1.15d-66) then
tmp = 1.0d0 * 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 <= -1e-65) {
tmp = t_0;
} else if (y <= 1.15e-66) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -1e-65: tmp = t_0 elif y <= 1.15e-66: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -1e-65) tmp = t_0; elseif (y <= 1.15e-66) tmp = Float64(1.0 * 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 <= -1e-65) tmp = t_0; elseif (y <= 1.15e-66) tmp = 1.0 * 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, -1e-65], t$95$0, If[LessEqual[y, 1.15e-66], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -1 \cdot 10^{-65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-66}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.99999999999999923e-66 or 1.14999999999999996e-66 < y Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6494.5
Applied rewrites94.5%
if -9.99999999999999923e-66 < y < 1.14999999999999996e-66Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6478.2
Applied rewrites78.2%
Taylor expanded in y around 0
Applied rewrites78.2%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.65e+91) (* y z) (if (<= z 1.6e-19) (* (- 1.0 y) x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.65e+91) {
tmp = y * z;
} else if (z <= 1.6e-19) {
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.65d+91)) then
tmp = y * z
else if (z <= 1.6d-19) 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.65e+91) {
tmp = y * z;
} else if (z <= 1.6e-19) {
tmp = (1.0 - y) * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.65e+91: tmp = y * z elif z <= 1.6e-19: tmp = (1.0 - y) * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.65e+91) tmp = Float64(y * z); elseif (z <= 1.6e-19) 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.65e+91) tmp = y * z; elseif (z <= 1.6e-19) tmp = (1.0 - y) * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.65e+91], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.6e-19], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{+91}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-19}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.65000000000000009e91 or 1.59999999999999991e-19 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6475.1
Applied rewrites75.1%
if -1.65000000000000009e91 < z < 1.59999999999999991e-19Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6487.1
Applied rewrites87.1%
Final simplification81.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.35e-65) (* y z) (if (<= y 3.8e-67) (* 1.0 x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.35e-65) {
tmp = y * z;
} else if (y <= 3.8e-67) {
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.35d-65)) then
tmp = y * z
else if (y <= 3.8d-67) 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.35e-65) {
tmp = y * z;
} else if (y <= 3.8e-67) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.35e-65: tmp = y * z elif y <= 3.8e-67: tmp = 1.0 * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.35e-65) tmp = Float64(y * z); elseif (y <= 3.8e-67) 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.35e-65) tmp = y * z; elseif (y <= 3.8e-67) tmp = 1.0 * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.35e-65], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.8e-67], N[(1.0 * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-65}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-67}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.3499999999999999e-65 or 3.79999999999999988e-67 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6454.0
Applied rewrites54.0%
if -1.3499999999999999e-65 < y < 3.79999999999999988e-67Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6478.2
Applied rewrites78.2%
Taylor expanded in y around 0
Applied rewrites78.2%
Final simplification64.1%
(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-*.f6442.1
Applied rewrites42.1%
Final simplification42.1%
herbie shell --seed 2024296
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))