
(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 8 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 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}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -3e+242)
t_0
(if (<= y -8.5e+113)
(* y z)
(if (<= y -32.0)
t_0
(if (<= y -3e-93)
x
(if (<= y -9.2e-104)
(* y z)
(if (<= y 5.5e-20)
x
(if (or (<= y 380000000000.0)
(not
(or (<= y 4.1e+37)
(and (not (<= y 1.6e+127)) (<= y 3.5e+262)))))
(* y z)
t_0)))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3e+242) {
tmp = t_0;
} else if (y <= -8.5e+113) {
tmp = y * z;
} else if (y <= -32.0) {
tmp = t_0;
} else if (y <= -3e-93) {
tmp = x;
} else if (y <= -9.2e-104) {
tmp = y * z;
} else if (y <= 5.5e-20) {
tmp = x;
} else if ((y <= 380000000000.0) || !((y <= 4.1e+37) || (!(y <= 1.6e+127) && (y <= 3.5e+262)))) {
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 = y * -x
if (y <= (-3d+242)) then
tmp = t_0
else if (y <= (-8.5d+113)) then
tmp = y * z
else if (y <= (-32.0d0)) then
tmp = t_0
else if (y <= (-3d-93)) then
tmp = x
else if (y <= (-9.2d-104)) then
tmp = y * z
else if (y <= 5.5d-20) then
tmp = x
else if ((y <= 380000000000.0d0) .or. (.not. (y <= 4.1d+37) .or. (.not. (y <= 1.6d+127)) .and. (y <= 3.5d+262))) 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 = y * -x;
double tmp;
if (y <= -3e+242) {
tmp = t_0;
} else if (y <= -8.5e+113) {
tmp = y * z;
} else if (y <= -32.0) {
tmp = t_0;
} else if (y <= -3e-93) {
tmp = x;
} else if (y <= -9.2e-104) {
tmp = y * z;
} else if (y <= 5.5e-20) {
tmp = x;
} else if ((y <= 380000000000.0) || !((y <= 4.1e+37) || (!(y <= 1.6e+127) && (y <= 3.5e+262)))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3e+242: tmp = t_0 elif y <= -8.5e+113: tmp = y * z elif y <= -32.0: tmp = t_0 elif y <= -3e-93: tmp = x elif y <= -9.2e-104: tmp = y * z elif y <= 5.5e-20: tmp = x elif (y <= 380000000000.0) or not ((y <= 4.1e+37) or (not (y <= 1.6e+127) and (y <= 3.5e+262))): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -3e+242) tmp = t_0; elseif (y <= -8.5e+113) tmp = Float64(y * z); elseif (y <= -32.0) tmp = t_0; elseif (y <= -3e-93) tmp = x; elseif (y <= -9.2e-104) tmp = Float64(y * z); elseif (y <= 5.5e-20) tmp = x; elseif ((y <= 380000000000.0) || !((y <= 4.1e+37) || (!(y <= 1.6e+127) && (y <= 3.5e+262)))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -3e+242) tmp = t_0; elseif (y <= -8.5e+113) tmp = y * z; elseif (y <= -32.0) tmp = t_0; elseif (y <= -3e-93) tmp = x; elseif (y <= -9.2e-104) tmp = y * z; elseif (y <= 5.5e-20) tmp = x; elseif ((y <= 380000000000.0) || ~(((y <= 4.1e+37) || (~((y <= 1.6e+127)) && (y <= 3.5e+262))))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -3e+242], t$95$0, If[LessEqual[y, -8.5e+113], N[(y * z), $MachinePrecision], If[LessEqual[y, -32.0], t$95$0, If[LessEqual[y, -3e-93], x, If[LessEqual[y, -9.2e-104], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.5e-20], x, If[Or[LessEqual[y, 380000000000.0], N[Not[Or[LessEqual[y, 4.1e+37], And[N[Not[LessEqual[y, 1.6e+127]], $MachinePrecision], LessEqual[y, 3.5e+262]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -3 \cdot 10^{+242}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{+113}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -32:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{-104}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-20}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 380000000000 \lor \neg \left(y \leq 4.1 \cdot 10^{+37} \lor \neg \left(y \leq 1.6 \cdot 10^{+127}\right) \land y \leq 3.5 \cdot 10^{+262}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3e242 or -8.5000000000000001e113 < y < -32 or 3.8e11 < y < 4.0999999999999998e37 or 1.59999999999999988e127 < y < 3.4999999999999997e262Initial program 99.9%
Taylor expanded in x around inf 70.6%
mul-1-neg70.6%
unsub-neg70.6%
Simplified70.6%
Taylor expanded in y around inf 69.0%
associate-*r*69.0%
mul-1-neg69.0%
Simplified69.0%
if -3e242 < y < -8.5000000000000001e113 or -3.0000000000000001e-93 < y < -9.1999999999999998e-104 or 5.4999999999999996e-20 < y < 3.8e11 or 4.0999999999999998e37 < y < 1.59999999999999988e127 or 3.4999999999999997e262 < y Initial program 100.0%
Taylor expanded in x around 0 97.3%
fma-define100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 74.1%
if -32 < y < -3.0000000000000001e-93 or -9.1999999999999998e-104 < y < 5.4999999999999996e-20Initial program 100.0%
Taylor expanded in y around 0 73.0%
Final simplification72.2%
(FPCore (x y z)
:precision binary64
(if (or (<= x -9.5e-31)
(not (or (<= x 7e-94) (and (not (<= x 1.7e-73)) (<= x 1.4e-21)))))
(* x (- 1.0 y))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-31) || !((x <= 7e-94) || (!(x <= 1.7e-73) && (x <= 1.4e-21)))) {
tmp = x * (1.0 - y);
} 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 ((x <= (-9.5d-31)) .or. (.not. (x <= 7d-94) .or. (.not. (x <= 1.7d-73)) .and. (x <= 1.4d-21))) then
tmp = x * (1.0d0 - y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-31) || !((x <= 7e-94) || (!(x <= 1.7e-73) && (x <= 1.4e-21)))) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e-31) or not ((x <= 7e-94) or (not (x <= 1.7e-73) and (x <= 1.4e-21))): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e-31) || !((x <= 7e-94) || (!(x <= 1.7e-73) && (x <= 1.4e-21)))) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.5e-31) || ~(((x <= 7e-94) || (~((x <= 1.7e-73)) && (x <= 1.4e-21))))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e-31], N[Not[Or[LessEqual[x, 7e-94], And[N[Not[LessEqual[x, 1.7e-73]], $MachinePrecision], LessEqual[x, 1.4e-21]]]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-31} \lor \neg \left(x \leq 7 \cdot 10^{-94} \lor \neg \left(x \leq 1.7 \cdot 10^{-73}\right) \land x \leq 1.4 \cdot 10^{-21}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -9.5000000000000008e-31 or 6.99999999999999996e-94 < x < 1.7000000000000001e-73 or 1.40000000000000002e-21 < x Initial program 100.0%
Taylor expanded in x around inf 85.8%
mul-1-neg85.8%
unsub-neg85.8%
Simplified85.8%
if -9.5000000000000008e-31 < x < 6.99999999999999996e-94 or 1.7000000000000001e-73 < x < 1.40000000000000002e-21Initial program 100.0%
Taylor expanded in x around 0 100.0%
fma-define100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 75.6%
Final simplification81.4%
(FPCore (x y z)
:precision binary64
(if (or (<= y -6.2e-5)
(not
(or (<= y -9.5e-91) (and (not (<= y -4.8e-103)) (<= y 2.3e-18)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-5) || !((y <= -9.5e-91) || (!(y <= -4.8e-103) && (y <= 2.3e-18)))) {
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 <= (-6.2d-5)) .or. (.not. (y <= (-9.5d-91)) .or. (.not. (y <= (-4.8d-103))) .and. (y <= 2.3d-18))) 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 <= -6.2e-5) || !((y <= -9.5e-91) || (!(y <= -4.8e-103) && (y <= 2.3e-18)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e-5) or not ((y <= -9.5e-91) or (not (y <= -4.8e-103) and (y <= 2.3e-18))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e-5) || !((y <= -9.5e-91) || (!(y <= -4.8e-103) && (y <= 2.3e-18)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.2e-5) || ~(((y <= -9.5e-91) || (~((y <= -4.8e-103)) && (y <= 2.3e-18))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e-5], N[Not[Or[LessEqual[y, -9.5e-91], And[N[Not[LessEqual[y, -4.8e-103]], $MachinePrecision], LessEqual[y, 2.3e-18]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-5} \lor \neg \left(y \leq -9.5 \cdot 10^{-91} \lor \neg \left(y \leq -4.8 \cdot 10^{-103}\right) \land y \leq 2.3 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.20000000000000027e-5 or -9.5e-91 < y < -4.8000000000000004e-103 or 2.3000000000000001e-18 < y Initial program 100.0%
Taylor expanded in x around 0 97.9%
fma-define99.3%
mul-1-neg99.3%
Simplified99.3%
Taylor expanded in x around 0 54.7%
if -6.20000000000000027e-5 < y < -9.5e-91 or -4.8000000000000004e-103 < y < 2.3000000000000001e-18Initial program 100.0%
Taylor expanded in y around 0 73.6%
Final simplification63.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -620000000.0) (not (<= x 2.6e+94))) (* x (- 1.0 y)) (* y (- z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -620000000.0) || !(x <= 2.6e+94)) {
tmp = x * (1.0 - y);
} else {
tmp = y * (z - 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 ((x <= (-620000000.0d0)) .or. (.not. (x <= 2.6d+94))) then
tmp = x * (1.0d0 - y)
else
tmp = y * (z - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -620000000.0) || !(x <= 2.6e+94)) {
tmp = x * (1.0 - y);
} else {
tmp = y * (z - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -620000000.0) or not (x <= 2.6e+94): tmp = x * (1.0 - y) else: tmp = y * (z - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -620000000.0) || !(x <= 2.6e+94)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * Float64(z - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -620000000.0) || ~((x <= 2.6e+94))) tmp = x * (1.0 - y); else tmp = y * (z - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -620000000.0], N[Not[LessEqual[x, 2.6e+94]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -620000000 \lor \neg \left(x \leq 2.6 \cdot 10^{+94}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z - x\right)\\
\end{array}
\end{array}
if x < -6.2e8 or 2.5999999999999999e94 < x Initial program 100.0%
Taylor expanded in x around inf 88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
if -6.2e8 < x < 2.5999999999999999e94Initial program 100.0%
Taylor expanded in x around 0 99.3%
fma-define99.3%
mul-1-neg99.3%
Simplified99.3%
Taylor expanded in y around inf 82.3%
mul-1-neg82.3%
unsub-neg82.3%
Simplified82.3%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -32.0) (not (<= y 0.045))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -32.0) || !(y <= 0.045)) {
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 <= (-32.0d0)) .or. (.not. (y <= 0.045d0))) 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 <= -32.0) || !(y <= 0.045)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -32.0) or not (y <= 0.045): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -32.0) || !(y <= 0.045)) 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 <= -32.0) || ~((y <= 0.045))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -32.0], N[Not[LessEqual[y, 0.045]], $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 -32 \lor \neg \left(y \leq 0.045\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -32 or 0.044999999999999998 < y Initial program 100.0%
Taylor expanded in x around 0 97.7%
fma-define99.2%
mul-1-neg99.2%
Simplified99.2%
Taylor expanded in y around inf 99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
if -32 < y < 0.044999999999999998Initial program 100.0%
Taylor expanded in z around inf 98.2%
Final simplification98.6%
(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}
Initial program 100.0%
Final simplification100.0%
(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}
Initial program 100.0%
Taylor expanded in y around 0 34.4%
Final simplification34.4%
herbie shell --seed 2024044
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))