
(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 -3.1e+94)
(* y z)
(if (<= y -1.0)
t_0
(if (<= y 5.4e-131)
x
(if (or (<= y 2.4e+177) (and (not (<= y 2.5e+253)) (<= y 1.02e+282)))
(* y z)
t_0))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.1e+94) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.4e-131) {
tmp = x;
} else if ((y <= 2.4e+177) || (!(y <= 2.5e+253) && (y <= 1.02e+282))) {
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 <= (-3.1d+94)) then
tmp = y * z
else if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 5.4d-131) then
tmp = x
else if ((y <= 2.4d+177) .or. (.not. (y <= 2.5d+253)) .and. (y <= 1.02d+282)) 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 <= -3.1e+94) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.4e-131) {
tmp = x;
} else if ((y <= 2.4e+177) || (!(y <= 2.5e+253) && (y <= 1.02e+282))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3.1e+94: tmp = y * z elif y <= -1.0: tmp = t_0 elif y <= 5.4e-131: tmp = x elif (y <= 2.4e+177) or (not (y <= 2.5e+253) and (y <= 1.02e+282)): 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 <= -3.1e+94) tmp = Float64(y * z); elseif (y <= -1.0) tmp = t_0; elseif (y <= 5.4e-131) tmp = x; elseif ((y <= 2.4e+177) || (!(y <= 2.5e+253) && (y <= 1.02e+282))) 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 <= -3.1e+94) tmp = y * z; elseif (y <= -1.0) tmp = t_0; elseif (y <= 5.4e-131) tmp = x; elseif ((y <= 2.4e+177) || (~((y <= 2.5e+253)) && (y <= 1.02e+282))) 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, -3.1e+94], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 5.4e-131], x, If[Or[LessEqual[y, 2.4e+177], And[N[Not[LessEqual[y, 2.5e+253]], $MachinePrecision], LessEqual[y, 1.02e+282]]], 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.1 \cdot 10^{+94}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{-131}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+177} \lor \neg \left(y \leq 2.5 \cdot 10^{+253}\right) \land y \leq 1.02 \cdot 10^{+282}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.09999999999999991e94 or 5.40000000000000042e-131 < y < 2.4e177 or 2.4999999999999998e253 < y < 1.02e282Initial program 100.0%
Taylor expanded in x around 0 65.0%
if -3.09999999999999991e94 < y < -1 or 2.4e177 < y < 2.4999999999999998e253 or 1.02e282 < y Initial program 100.0%
Taylor expanded in x around inf 74.5%
mul-1-neg74.5%
unsub-neg74.5%
Simplified74.5%
Taylor expanded in y around inf 72.3%
mul-1-neg72.3%
*-commutative72.3%
distribute-rgt-neg-in72.3%
Simplified72.3%
if -1 < y < 5.40000000000000042e-131Initial program 100.0%
Taylor expanded in y around 0 73.0%
Final simplification68.9%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.2e+100)
(not (or (<= z -3.1e+34) (and (not (<= z -3.3e+16)) (<= z 3.8e-69)))))
(* y z)
(* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.2e+100) || !((z <= -3.1e+34) || (!(z <= -3.3e+16) && (z <= 3.8e-69)))) {
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.2d+100)) .or. (.not. (z <= (-3.1d+34)) .or. (.not. (z <= (-3.3d+16))) .and. (z <= 3.8d-69))) 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.2e+100) || !((z <= -3.1e+34) || (!(z <= -3.3e+16) && (z <= 3.8e-69)))) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.2e+100) or not ((z <= -3.1e+34) or (not (z <= -3.3e+16) and (z <= 3.8e-69))): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.2e+100) || !((z <= -3.1e+34) || (!(z <= -3.3e+16) && (z <= 3.8e-69)))) 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.2e+100) || ~(((z <= -3.1e+34) || (~((z <= -3.3e+16)) && (z <= 3.8e-69))))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.2e+100], N[Not[Or[LessEqual[z, -3.1e+34], And[N[Not[LessEqual[z, -3.3e+16]], $MachinePrecision], LessEqual[z, 3.8e-69]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{+100} \lor \neg \left(z \leq -3.1 \cdot 10^{+34} \lor \neg \left(z \leq -3.3 \cdot 10^{+16}\right) \land z \leq 3.8 \cdot 10^{-69}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -1.20000000000000006e100 or -3.09999999999999977e34 < z < -3.3e16 or 3.7999999999999998e-69 < z Initial program 100.0%
Taylor expanded in x around 0 76.4%
if -1.20000000000000006e100 < z < -3.09999999999999977e34 or -3.3e16 < z < 3.7999999999999998e-69Initial program 100.0%
Taylor expanded in x around inf 82.3%
mul-1-neg82.3%
unsub-neg82.3%
Simplified82.3%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.000225) (not (<= y 5.8e-131))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000225) || !(y <= 5.8e-131)) {
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 ((y <= (-0.000225d0)) .or. (.not. (y <= 5.8d-131))) 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 ((y <= -0.000225) || !(y <= 5.8e-131)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.000225) or not (y <= 5.8e-131): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.000225) || !(y <= 5.8e-131)) 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 ((y <= -0.000225) || ~((y <= 5.8e-131))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.000225], N[Not[LessEqual[y, 5.8e-131]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000225 \lor \neg \left(y \leq 5.8 \cdot 10^{-131}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -2.2499999999999999e-4 or 5.8000000000000004e-131 < y Initial program 100.0%
Taylor expanded in y around inf 91.5%
if -2.2499999999999999e-4 < y < 5.8000000000000004e-131Initial program 100.0%
Taylor expanded in x around inf 74.3%
mul-1-neg74.3%
unsub-neg74.3%
Simplified74.3%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00041) (not (<= y 2.8e-132))) (* y (- z x)) (- x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00041) || !(y <= 2.8e-132)) {
tmp = y * (z - x);
} else {
tmp = x - (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 ((y <= (-0.00041d0)) .or. (.not. (y <= 2.8d-132))) then
tmp = y * (z - x)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00041) || !(y <= 2.8e-132)) {
tmp = y * (z - x);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00041) or not (y <= 2.8e-132): tmp = y * (z - x) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00041) || !(y <= 2.8e-132)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00041) || ~((y <= 2.8e-132))) tmp = y * (z - x); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00041], N[Not[LessEqual[y, 2.8e-132]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00041 \lor \neg \left(y \leq 2.8 \cdot 10^{-132}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if y < -4.0999999999999999e-4 or 2.80000000000000002e-132 < y Initial program 100.0%
Taylor expanded in y around inf 91.5%
if -4.0999999999999999e-4 < y < 2.80000000000000002e-132Initial program 100.0%
Taylor expanded in x around inf 74.3%
mul-1-neg74.3%
unsub-neg74.3%
Simplified74.3%
sub-neg74.3%
distribute-rgt-in74.3%
*-un-lft-identity74.3%
Applied egg-rr74.3%
distribute-lft-neg-out74.3%
unsub-neg74.3%
*-commutative74.3%
Applied egg-rr74.3%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.8e-5) (not (<= y 5.8e-131))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.8e-5) || !(y <= 5.8e-131)) {
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 <= (-8.8d-5)) .or. (.not. (y <= 5.8d-131))) 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 <= -8.8e-5) || !(y <= 5.8e-131)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.8e-5) or not (y <= 5.8e-131): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.8e-5) || !(y <= 5.8e-131)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.8e-5) || ~((y <= 5.8e-131))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.8e-5], N[Not[LessEqual[y, 5.8e-131]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-5} \lor \neg \left(y \leq 5.8 \cdot 10^{-131}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.7999999999999998e-5 or 5.8000000000000004e-131 < y Initial program 100.0%
Taylor expanded in x around 0 56.9%
if -8.7999999999999998e-5 < y < 5.8000000000000004e-131Initial program 100.0%
Taylor expanded in y around 0 73.0%
Final simplification62.5%
(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 31.6%
Final simplification31.6%
herbie shell --seed 2024073
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))