
(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
(if (<= y -64000.0)
(* y z)
(if (<= y -2.45e-45)
x
(if (<= y -1e-63)
(* y z)
(if (<= y 1.0)
x
(if (or (<= y 6.8e+93) (not (<= y 8.5e+257)))
(* y (- x))
(* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -64000.0) {
tmp = y * z;
} else if (y <= -2.45e-45) {
tmp = x;
} else if (y <= -1e-63) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if ((y <= 6.8e+93) || !(y <= 8.5e+257)) {
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 (y <= (-64000.0d0)) then
tmp = y * z
else if (y <= (-2.45d-45)) then
tmp = x
else if (y <= (-1d-63)) then
tmp = y * z
else if (y <= 1.0d0) then
tmp = x
else if ((y <= 6.8d+93) .or. (.not. (y <= 8.5d+257))) 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 (y <= -64000.0) {
tmp = y * z;
} else if (y <= -2.45e-45) {
tmp = x;
} else if (y <= -1e-63) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if ((y <= 6.8e+93) || !(y <= 8.5e+257)) {
tmp = y * -x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -64000.0: tmp = y * z elif y <= -2.45e-45: tmp = x elif y <= -1e-63: tmp = y * z elif y <= 1.0: tmp = x elif (y <= 6.8e+93) or not (y <= 8.5e+257): tmp = y * -x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -64000.0) tmp = Float64(y * z); elseif (y <= -2.45e-45) tmp = x; elseif (y <= -1e-63) tmp = Float64(y * z); elseif (y <= 1.0) tmp = x; elseif ((y <= 6.8e+93) || !(y <= 8.5e+257)) tmp = Float64(y * Float64(-x)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -64000.0) tmp = y * z; elseif (y <= -2.45e-45) tmp = x; elseif (y <= -1e-63) tmp = y * z; elseif (y <= 1.0) tmp = x; elseif ((y <= 6.8e+93) || ~((y <= 8.5e+257))) tmp = y * -x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -64000.0], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.45e-45], x, If[LessEqual[y, -1e-63], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.0], x, If[Or[LessEqual[y, 6.8e+93], N[Not[LessEqual[y, 8.5e+257]], $MachinePrecision]], N[(y * (-x)), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -64000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.45 \cdot 10^{-45}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -1 \cdot 10^{-63}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+93} \lor \neg \left(y \leq 8.5 \cdot 10^{+257}\right):\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -64000 or -2.4499999999999999e-45 < y < -1.00000000000000007e-63 or 6.8000000000000001e93 < y < 8.49999999999999952e257Initial program 100.0%
Taylor expanded in x around 0 97.9%
fma-def98.9%
mul-1-neg98.9%
Simplified98.9%
Taylor expanded in x around 0 62.0%
if -64000 < y < -2.4499999999999999e-45 or -1.00000000000000007e-63 < y < 1Initial program 100.0%
Taylor expanded in y around 0 69.6%
if 1 < y < 6.8000000000000001e93 or 8.49999999999999952e257 < y Initial program 99.9%
Taylor expanded in x around inf 81.6%
mul-1-neg81.6%
unsub-neg81.6%
Simplified81.6%
Taylor expanded in y around inf 76.5%
associate-*r*76.5%
mul-1-neg76.5%
Simplified76.5%
Final simplification67.7%
(FPCore (x y z)
:precision binary64
(if (or (<= z -2.25e+114)
(not (or (<= z -2.3e+71) (and (not (<= z -6.6e-9)) (<= z 5.8e+88)))))
(* y z)
(* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.25e+114) || !((z <= -2.3e+71) || (!(z <= -6.6e-9) && (z <= 5.8e+88)))) {
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 <= (-2.25d+114)) .or. (.not. (z <= (-2.3d+71)) .or. (.not. (z <= (-6.6d-9))) .and. (z <= 5.8d+88))) 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 <= -2.25e+114) || !((z <= -2.3e+71) || (!(z <= -6.6e-9) && (z <= 5.8e+88)))) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.25e+114) or not ((z <= -2.3e+71) or (not (z <= -6.6e-9) and (z <= 5.8e+88))): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.25e+114) || !((z <= -2.3e+71) || (!(z <= -6.6e-9) && (z <= 5.8e+88)))) 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 <= -2.25e+114) || ~(((z <= -2.3e+71) || (~((z <= -6.6e-9)) && (z <= 5.8e+88))))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.25e+114], N[Not[Or[LessEqual[z, -2.3e+71], And[N[Not[LessEqual[z, -6.6e-9]], $MachinePrecision], LessEqual[z, 5.8e+88]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.25 \cdot 10^{+114} \lor \neg \left(z \leq -2.3 \cdot 10^{+71} \lor \neg \left(z \leq -6.6 \cdot 10^{-9}\right) \land z \leq 5.8 \cdot 10^{+88}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -2.25e114 or -2.3000000000000002e71 < z < -6.60000000000000037e-9 or 5.7999999999999999e88 < z Initial program 100.0%
Taylor expanded in x around 0 98.2%
fma-def99.1%
mul-1-neg99.1%
Simplified99.1%
Taylor expanded in x around 0 76.0%
if -2.25e114 < z < -2.3000000000000002e71 or -6.60000000000000037e-9 < z < 5.7999999999999999e88Initial program 99.9%
Taylor expanded in x around inf 86.6%
mul-1-neg86.6%
unsub-neg86.6%
Simplified86.6%
Final simplification82.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.4e-54) (not (<= z 5.3e+88))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-54) || !(z <= 5.3e+88)) {
tmp = y * (z - x);
} 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.4d-54)) .or. (.not. (z <= 5.3d+88))) then
tmp = y * (z - x)
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.4e-54) || !(z <= 5.3e+88)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.4e-54) or not (z <= 5.3e+88): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.4e-54) || !(z <= 5.3e+88)) tmp = Float64(y * Float64(z - x)); 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.4e-54) || ~((z <= 5.3e+88))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.4e-54], N[Not[LessEqual[z, 5.3e+88]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{-54} \lor \neg \left(z \leq 5.3 \cdot 10^{+88}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -1.4000000000000001e-54 or 5.29999999999999987e88 < z Initial program 100.0%
Taylor expanded in x around 0 96.8%
fma-def97.6%
mul-1-neg97.6%
Simplified97.6%
Taylor expanded in y around inf 79.9%
mul-1-neg79.9%
unsub-neg79.9%
Simplified79.9%
if -1.4000000000000001e-54 < z < 5.29999999999999987e88Initial program 99.9%
Taylor expanded in x around inf 88.1%
mul-1-neg88.1%
unsub-neg88.1%
Simplified88.1%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.0045))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.0045)) {
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 <= 0.0045d0))) 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 <= 0.0045)) {
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 <= 0.0045): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.0045)) 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 <= 0.0045))) 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, 0.0045]], $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 0.0045\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 0.00449999999999999966 < y Initial program 99.9%
Taylor expanded in x around 0 96.7%
fma-def97.5%
mul-1-neg97.5%
Simplified97.5%
Taylor expanded in y around inf 97.9%
mul-1-neg97.9%
unsub-neg97.9%
Simplified97.9%
if -1 < y < 0.00449999999999999966Initial program 100.0%
Taylor expanded in z around inf 97.9%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e-16) (not (<= z 4.5e+88))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e-16) || !(z <= 4.5e+88)) {
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 ((z <= (-1d-16)) .or. (.not. (z <= 4.5d+88))) 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 ((z <= -1e-16) || !(z <= 4.5e+88)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e-16) or not (z <= 4.5e+88): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e-16) || !(z <= 4.5e+88)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1e-16) || ~((z <= 4.5e+88))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e-16], N[Not[LessEqual[z, 4.5e+88]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-16} \lor \neg \left(z \leq 4.5 \cdot 10^{+88}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.9999999999999998e-17 or 4.5e88 < z Initial program 100.0%
Taylor expanded in x around 0 96.6%
fma-def97.5%
mul-1-neg97.5%
Simplified97.5%
Taylor expanded in x around 0 72.1%
if -9.9999999999999998e-17 < z < 4.5e88Initial program 99.9%
Taylor expanded in y around 0 50.1%
Final simplification60.3%
(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 36.5%
Final simplification36.5%
herbie shell --seed 2024031
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))