
(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) (* z y) (if (<= z -5.5e-290) (* 1.0 x) (if (<= z 1.22e-26) (* (- y) x) (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e+55) {
tmp = z * y;
} else if (z <= -5.5e-290) {
tmp = 1.0 * x;
} else if (z <= 1.22e-26) {
tmp = -y * x;
} else {
tmp = z * 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 <= (-9.2d+55)) then
tmp = z * y
else if (z <= (-5.5d-290)) then
tmp = 1.0d0 * x
else if (z <= 1.22d-26) then
tmp = -y * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e+55) {
tmp = z * y;
} else if (z <= -5.5e-290) {
tmp = 1.0 * x;
} else if (z <= 1.22e-26) {
tmp = -y * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.2e+55: tmp = z * y elif z <= -5.5e-290: tmp = 1.0 * x elif z <= 1.22e-26: tmp = -y * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.2e+55) tmp = Float64(z * y); elseif (z <= -5.5e-290) tmp = Float64(1.0 * x); elseif (z <= 1.22e-26) tmp = Float64(Float64(-y) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.2e+55) tmp = z * y; elseif (z <= -5.5e-290) tmp = 1.0 * x; elseif (z <= 1.22e-26) tmp = -y * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.2e+55], N[(z * y), $MachinePrecision], If[LessEqual[z, -5.5e-290], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 1.22e-26], N[((-y) * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+55}:\\
\;\;\;\;z \cdot y\\
\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}:\\
\;\;\;\;z \cdot y\\
\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%
(FPCore (x y z) :precision binary64 (if (or (<= y -1e-65) (not (<= y 1.15e-66))) (* (- z x) y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1e-65) || !(y <= 1.15e-66)) {
tmp = (z - x) * y;
} else {
tmp = 1.0 * 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 <= (-1d-65)) .or. (.not. (y <= 1.15d-66))) then
tmp = (z - x) * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1e-65) || !(y <= 1.15e-66)) {
tmp = (z - x) * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1e-65) or not (y <= 1.15e-66): tmp = (z - x) * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1e-65) || !(y <= 1.15e-66)) tmp = Float64(Float64(z - x) * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1e-65) || ~((y <= 1.15e-66))) tmp = (z - x) * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1e-65], N[Not[LessEqual[y, 1.15e-66]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-65} \lor \neg \left(y \leq 1.15 \cdot 10^{-66}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\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 (or (<= z -1.65e+91) (not (<= z 1.6e-19))) (* z y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65e+91) || !(z <= 1.6e-19)) {
tmp = z * y;
} else {
tmp = (1.0 - 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 ((z <= (-1.65d+91)) .or. (.not. (z <= 1.6d-19))) then
tmp = z * y
else
tmp = (1.0d0 - y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65e+91) || !(z <= 1.6e-19)) {
tmp = z * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.65e+91) or not (z <= 1.6e-19): tmp = z * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.65e+91) || !(z <= 1.6e-19)) tmp = Float64(z * y); else tmp = Float64(Float64(1.0 - y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.65e+91) || ~((z <= 1.6e-19))) tmp = z * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.65e+91], N[Not[LessEqual[z, 1.6e-19]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{+91} \lor \neg \left(z \leq 1.6 \cdot 10^{-19}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\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 (or (<= y -1.35e-65) (not (<= y 3.8e-67))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-65) || !(y <= 3.8e-67)) {
tmp = z * y;
} else {
tmp = 1.0 * 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-65)) .or. (.not. (y <= 3.8d-67))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-65) || !(y <= 3.8e-67)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-65) or not (y <= 3.8e-67): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-65) || !(y <= 3.8e-67)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.35e-65) || ~((y <= 3.8e-67))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-65], N[Not[LessEqual[y, 3.8e-67]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-65} \lor \neg \left(y \leq 3.8 \cdot 10^{-67}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\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 (* z y))
double code(double x, double y, double z) {
return z * 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 * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6442.1
Applied rewrites42.1%
herbie shell --seed 2024296
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))