
(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.16e-8)
t_0
(if (<= y 0.0016)
x
(if (or (<= y 2.6e+216) (not (<= y 2.3e+286))) (* y z) t_0)))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.16e-8) {
tmp = t_0;
} else if (y <= 0.0016) {
tmp = x;
} else if ((y <= 2.6e+216) || !(y <= 2.3e+286)) {
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.16d-8)) then
tmp = t_0
else if (y <= 0.0016d0) then
tmp = x
else if ((y <= 2.6d+216) .or. (.not. (y <= 2.3d+286))) 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.16e-8) {
tmp = t_0;
} else if (y <= 0.0016) {
tmp = x;
} else if ((y <= 2.6e+216) || !(y <= 2.3e+286)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -1.16e-8: tmp = t_0 elif y <= 0.0016: tmp = x elif (y <= 2.6e+216) or not (y <= 2.3e+286): 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.16e-8) tmp = t_0; elseif (y <= 0.0016) tmp = x; elseif ((y <= 2.6e+216) || !(y <= 2.3e+286)) 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.16e-8) tmp = t_0; elseif (y <= 0.0016) tmp = x; elseif ((y <= 2.6e+216) || ~((y <= 2.3e+286))) 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.16e-8], t$95$0, If[LessEqual[y, 0.0016], x, If[Or[LessEqual[y, 2.6e+216], N[Not[LessEqual[y, 2.3e+286]], $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.16 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.0016:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+216} \lor \neg \left(y \leq 2.3 \cdot 10^{+286}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.15999999999999996e-8 or 2.5999999999999999e216 < y < 2.3000000000000001e286Initial program 100.0%
sub-neg100.0%
distribute-rgt-in96.9%
fma-def98.4%
Applied egg-rr98.4%
Taylor expanded in x around 0 96.9%
fma-def98.4%
mul-1-neg98.4%
sub-neg98.4%
Simplified98.4%
Taylor expanded in y around inf 99.5%
mul-1-neg99.5%
unsub-neg99.5%
Simplified99.5%
Taylor expanded in z around 0 66.8%
mul-1-neg66.8%
distribute-lft-neg-out66.8%
*-commutative66.8%
Simplified66.8%
if -1.15999999999999996e-8 < y < 0.00160000000000000008Initial program 100.0%
Taylor expanded in y around 0 70.3%
if 0.00160000000000000008 < y < 2.5999999999999999e216 or 2.3000000000000001e286 < y Initial program 100.0%
Taylor expanded in z around inf 61.7%
Taylor expanded in x around 0 62.3%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e+28) (not (<= x 6.8e-57))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+28) || !(x <= 6.8e-57)) {
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 <= (-2.8d+28)) .or. (.not. (x <= 6.8d-57))) 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 <= -2.8e+28) || !(x <= 6.8e-57)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e+28) or not (x <= 6.8e-57): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e+28) || !(x <= 6.8e-57)) 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 <= -2.8e+28) || ~((x <= 6.8e-57))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e+28], N[Not[LessEqual[x, 6.8e-57]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+28} \lor \neg \left(x \leq 6.8 \cdot 10^{-57}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.8000000000000001e28 or 6.80000000000000032e-57 < x Initial program 100.0%
Taylor expanded in x around inf 89.8%
mul-1-neg89.8%
unsub-neg89.8%
Simplified89.8%
if -2.8000000000000001e28 < x < 6.80000000000000032e-57Initial program 100.0%
Taylor expanded in z around inf 89.2%
Taylor expanded in x around 0 67.4%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.56e+32) (not (<= x 3.5e-12))) (* x (- 1.0 y)) (* y (- z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.56e+32) || !(x <= 3.5e-12)) {
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 <= (-1.56d+32)) .or. (.not. (x <= 3.5d-12))) 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 <= -1.56e+32) || !(x <= 3.5e-12)) {
tmp = x * (1.0 - y);
} else {
tmp = y * (z - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.56e+32) or not (x <= 3.5e-12): tmp = x * (1.0 - y) else: tmp = y * (z - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.56e+32) || !(x <= 3.5e-12)) 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 <= -1.56e+32) || ~((x <= 3.5e-12))) tmp = x * (1.0 - y); else tmp = y * (z - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.56e+32], N[Not[LessEqual[x, 3.5e-12]], $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 -1.56 \cdot 10^{+32} \lor \neg \left(x \leq 3.5 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z - x\right)\\
\end{array}
\end{array}
if x < -1.56e32 or 3.5e-12 < x Initial program 100.0%
Taylor expanded in x around inf 92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
if -1.56e32 < x < 3.5e-12Initial program 100.0%
sub-neg100.0%
distribute-rgt-in99.9%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 99.9%
fma-def100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 77.1%
mul-1-neg77.1%
unsub-neg77.1%
Simplified77.1%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.0085))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.0085)) {
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.0085d0))) 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.0085)) {
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.0085): 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.0085)) 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.0085))) 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.0085]], $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.0085\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 0.0085000000000000006 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt-in98.1%
fma-def99.1%
Applied egg-rr99.1%
Taylor expanded in x around 0 98.1%
fma-def99.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
if -1 < y < 0.0085000000000000006Initial program 100.0%
Taylor expanded in z around inf 98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e-9) (not (<= y 0.00192))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e-9) || !(y <= 0.00192)) {
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 <= (-4d-9)) .or. (.not. (y <= 0.00192d0))) 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 <= -4e-9) || !(y <= 0.00192)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e-9) or not (y <= 0.00192): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e-9) || !(y <= 0.00192)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4e-9) || ~((y <= 0.00192))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e-9], N[Not[LessEqual[y, 0.00192]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-9} \lor \neg \left(y \leq 0.00192\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.00000000000000025e-9 or 0.00192000000000000005 < y Initial program 100.0%
Taylor expanded in z around inf 46.5%
Taylor expanded in x around 0 46.1%
if -4.00000000000000025e-9 < y < 0.00192000000000000005Initial program 100.0%
Taylor expanded in y around 0 70.3%
Final simplification59.8%
(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 41.2%
Final simplification41.2%
herbie shell --seed 2024019
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))