
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.0)
t_0
(if (<= y 1e-105)
x
(if (<= y 6.5e-76)
(* y z)
(if (<= y 6.5e-19)
x
(if (or (<= y 2e+68)
(not
(or (<= y 6.6e+150)
(and (not (<= y 4e+255)) (<= y 1.25e+278)))))
(* y z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1e-105) {
tmp = x;
} else if (y <= 6.5e-76) {
tmp = y * z;
} else if (y <= 6.5e-19) {
tmp = x;
} else if ((y <= 2e+68) || !((y <= 6.6e+150) || (!(y <= 4e+255) && (y <= 1.25e+278)))) {
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 <= (-1.0d0)) then
tmp = t_0
else if (y <= 1d-105) then
tmp = x
else if (y <= 6.5d-76) then
tmp = y * z
else if (y <= 6.5d-19) then
tmp = x
else if ((y <= 2d+68) .or. (.not. (y <= 6.6d+150) .or. (.not. (y <= 4d+255)) .and. (y <= 1.25d+278))) 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 <= -1.0) {
tmp = t_0;
} else if (y <= 1e-105) {
tmp = x;
} else if (y <= 6.5e-76) {
tmp = y * z;
} else if (y <= 6.5e-19) {
tmp = x;
} else if ((y <= 2e+68) || !((y <= 6.6e+150) || (!(y <= 4e+255) && (y <= 1.25e+278)))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1e-105: tmp = x elif y <= 6.5e-76: tmp = y * z elif y <= 6.5e-19: tmp = x elif (y <= 2e+68) or not ((y <= 6.6e+150) or (not (y <= 4e+255) and (y <= 1.25e+278))): 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 <= -1.0) tmp = t_0; elseif (y <= 1e-105) tmp = x; elseif (y <= 6.5e-76) tmp = Float64(y * z); elseif (y <= 6.5e-19) tmp = x; elseif ((y <= 2e+68) || !((y <= 6.6e+150) || (!(y <= 4e+255) && (y <= 1.25e+278)))) 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 <= -1.0) tmp = t_0; elseif (y <= 1e-105) tmp = x; elseif (y <= 6.5e-76) tmp = y * z; elseif (y <= 6.5e-19) tmp = x; elseif ((y <= 2e+68) || ~(((y <= 6.6e+150) || (~((y <= 4e+255)) && (y <= 1.25e+278))))) 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, -1.0], t$95$0, If[LessEqual[y, 1e-105], x, If[LessEqual[y, 6.5e-76], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.5e-19], x, If[Or[LessEqual[y, 2e+68], N[Not[Or[LessEqual[y, 6.6e+150], And[N[Not[LessEqual[y, 4e+255]], $MachinePrecision], LessEqual[y, 1.25e+278]]]], $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 -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 10^{-105}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-76}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+68} \lor \neg \left(y \leq 6.6 \cdot 10^{+150} \lor \neg \left(y \leq 4 \cdot 10^{+255}\right) \land y \leq 1.25 \cdot 10^{+278}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1 or 1.99999999999999991e68 < y < 6.59999999999999962e150 or 3.99999999999999995e255 < y < 1.25000000000000007e278Initial program 100.0%
Taylor expanded in y around inf 98.6%
Taylor expanded in z around 0 63.4%
mul-1-neg63.4%
distribute-lft-neg-out63.4%
*-commutative63.4%
Simplified63.4%
if -1 < y < 9.99999999999999965e-106 or 6.5e-76 < y < 6.5000000000000001e-19Initial program 100.0%
Taylor expanded in y around 0 82.0%
if 9.99999999999999965e-106 < y < 6.5e-76 or 6.5000000000000001e-19 < y < 1.99999999999999991e68 or 6.59999999999999962e150 < y < 3.99999999999999995e255 or 1.25000000000000007e278 < y Initial program 100.0%
Taylor expanded in x around 0 74.4%
Final simplification73.2%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.9e+71)
(and (not (<= z -3.8e+31)) (or (<= z -1.2e-14) (not (<= z 2.1e+38)))))
(* y z)
(* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+71) || (!(z <= -3.8e+31) && ((z <= -1.2e-14) || !(z <= 2.1e+38)))) {
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 <= (-1.9d+71)) .or. (.not. (z <= (-3.8d+31))) .and. (z <= (-1.2d-14)) .or. (.not. (z <= 2.1d+38))) 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 <= -1.9e+71) || (!(z <= -3.8e+31) && ((z <= -1.2e-14) || !(z <= 2.1e+38)))) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.9e+71) or (not (z <= -3.8e+31) and ((z <= -1.2e-14) or not (z <= 2.1e+38))): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.9e+71) || (!(z <= -3.8e+31) && ((z <= -1.2e-14) || !(z <= 2.1e+38)))) 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 <= -1.9e+71) || (~((z <= -3.8e+31)) && ((z <= -1.2e-14) || ~((z <= 2.1e+38))))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.9e+71], And[N[Not[LessEqual[z, -3.8e+31]], $MachinePrecision], Or[LessEqual[z, -1.2e-14], N[Not[LessEqual[z, 2.1e+38]], $MachinePrecision]]]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+71} \lor \neg \left(z \leq -3.8 \cdot 10^{+31}\right) \land \left(z \leq -1.2 \cdot 10^{-14} \lor \neg \left(z \leq 2.1 \cdot 10^{+38}\right)\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -1.9e71 or -3.8000000000000001e31 < z < -1.2e-14 or 2.1e38 < z Initial program 100.0%
Taylor expanded in x around 0 78.5%
if -1.9e71 < z < -3.8000000000000001e31 or -1.2e-14 < z < 2.1e38Initial program 100.0%
Taylor expanded in x around inf 86.5%
mul-1-neg86.5%
unsub-neg86.5%
Simplified86.5%
Final simplification83.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z x))))
(if (<= y -4.1e-48)
t_0
(if (<= y 3.1e-105)
x
(if (<= y 6.8e-75) (* y z) (if (<= y 4.6e-15) (* x (- 1.0 y)) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -4.1e-48) {
tmp = t_0;
} else if (y <= 3.1e-105) {
tmp = x;
} else if (y <= 6.8e-75) {
tmp = y * z;
} else if (y <= 4.6e-15) {
tmp = x * (1.0 - y);
} 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 <= (-4.1d-48)) then
tmp = t_0
else if (y <= 3.1d-105) then
tmp = x
else if (y <= 6.8d-75) then
tmp = y * z
else if (y <= 4.6d-15) then
tmp = x * (1.0d0 - y)
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 <= -4.1e-48) {
tmp = t_0;
} else if (y <= 3.1e-105) {
tmp = x;
} else if (y <= 6.8e-75) {
tmp = y * z;
} else if (y <= 4.6e-15) {
tmp = x * (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -4.1e-48: tmp = t_0 elif y <= 3.1e-105: tmp = x elif y <= 6.8e-75: tmp = y * z elif y <= 4.6e-15: tmp = x * (1.0 - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -4.1e-48) tmp = t_0; elseif (y <= 3.1e-105) tmp = x; elseif (y <= 6.8e-75) tmp = Float64(y * z); elseif (y <= 4.6e-15) tmp = Float64(x * Float64(1.0 - y)); 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 <= -4.1e-48) tmp = t_0; elseif (y <= 3.1e-105) tmp = x; elseif (y <= 6.8e-75) tmp = y * z; elseif (y <= 4.6e-15) tmp = x * (1.0 - y); 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, -4.1e-48], t$95$0, If[LessEqual[y, 3.1e-105], x, If[LessEqual[y, 6.8e-75], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.6e-15], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -4.1 \cdot 10^{-48}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-105}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-75}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{-15}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -4.10000000000000014e-48 or 4.59999999999999981e-15 < y Initial program 100.0%
Taylor expanded in y around inf 97.4%
if -4.10000000000000014e-48 < y < 3.10000000000000014e-105Initial program 100.0%
Taylor expanded in y around 0 83.7%
if 3.10000000000000014e-105 < y < 6.8000000000000003e-75Initial program 100.0%
Taylor expanded in x around 0 88.3%
if 6.8000000000000003e-75 < y < 4.59999999999999981e-15Initial program 100.0%
Taylor expanded in x around inf 91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
Final simplification92.2%
(FPCore (x y z)
:precision binary64
(if (or (<= y -3.7e-14)
(not (or (<= y 9.5e-114) (and (not (<= y 6.2e-76)) (<= y 1.25e-17)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e-14) || !((y <= 9.5e-114) || (!(y <= 6.2e-76) && (y <= 1.25e-17)))) {
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 <= (-3.7d-14)) .or. (.not. (y <= 9.5d-114) .or. (.not. (y <= 6.2d-76)) .and. (y <= 1.25d-17))) 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 <= -3.7e-14) || !((y <= 9.5e-114) || (!(y <= 6.2e-76) && (y <= 1.25e-17)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7e-14) or not ((y <= 9.5e-114) or (not (y <= 6.2e-76) and (y <= 1.25e-17))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7e-14) || !((y <= 9.5e-114) || (!(y <= 6.2e-76) && (y <= 1.25e-17)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.7e-14) || ~(((y <= 9.5e-114) || (~((y <= 6.2e-76)) && (y <= 1.25e-17))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7e-14], N[Not[Or[LessEqual[y, 9.5e-114], And[N[Not[LessEqual[y, 6.2e-76]], $MachinePrecision], LessEqual[y, 1.25e-17]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-14} \lor \neg \left(y \leq 9.5 \cdot 10^{-114} \lor \neg \left(y \leq 6.2 \cdot 10^{-76}\right) \land y \leq 1.25 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.70000000000000001e-14 or 9.49999999999999958e-114 < y < 6.19999999999999939e-76 or 1.25e-17 < y Initial program 100.0%
Taylor expanded in x around 0 52.6%
if -3.70000000000000001e-14 < y < 9.49999999999999958e-114 or 6.19999999999999939e-76 < y < 1.25e-17Initial program 100.0%
Taylor expanded in y around 0 83.9%
Final simplification64.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 4.4e-13))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 4.4e-13)) {
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 <= (-1.0d0)) .or. (.not. (y <= 4.4d-13))) 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 <= -1.0) || !(y <= 4.4e-13)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 4.4e-13): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 4.4e-13)) 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 <= -1.0) || ~((y <= 4.4e-13))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 4.4e-13]], $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 -1 \lor \neg \left(y \leq 4.4 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 4.39999999999999993e-13 < y Initial program 100.0%
Taylor expanded in y around inf 98.5%
if -1 < y < 4.39999999999999993e-13Initial program 100.0%
sub-neg100.0%
distribute-rgt-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 99.5%
Final simplification98.9%
(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.9%
Final simplification34.9%
herbie shell --seed 2023331
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))