
(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%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e-41) (* y z) (if (<= y 0.0065) x (if (<= y 7.2e+65) (* y z) (* y (- x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-41) {
tmp = y * z;
} else if (y <= 0.0065) {
tmp = x;
} else if (y <= 7.2e+65) {
tmp = y * z;
} else {
tmp = 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 <= (-6.8d-41)) then
tmp = y * z
else if (y <= 0.0065d0) then
tmp = x
else if (y <= 7.2d+65) then
tmp = y * z
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-41) {
tmp = y * z;
} else if (y <= 0.0065) {
tmp = x;
} else if (y <= 7.2e+65) {
tmp = y * z;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e-41: tmp = y * z elif y <= 0.0065: tmp = x elif y <= 7.2e+65: tmp = y * z else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e-41) tmp = Float64(y * z); elseif (y <= 0.0065) tmp = x; elseif (y <= 7.2e+65) tmp = Float64(y * z); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e-41) tmp = y * z; elseif (y <= 0.0065) tmp = x; elseif (y <= 7.2e+65) tmp = y * z; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e-41], N[(y * z), $MachinePrecision], If[LessEqual[y, 0.0065], x, If[LessEqual[y, 7.2e+65], N[(y * z), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-41}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 0.0065:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+65}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -6.7999999999999997e-41 or 0.0064999999999999997 < y < 7.19999999999999957e65Initial program 99.9%
Taylor expanded in x around 0 97.3%
fma-define98.6%
+-commutative98.6%
mul-1-neg98.6%
Simplified98.6%
Taylor expanded in x around 0 55.8%
if -6.7999999999999997e-41 < y < 0.0064999999999999997Initial program 100.0%
Taylor expanded in y around 0 73.0%
if 7.19999999999999957e65 < y Initial program 100.0%
Taylor expanded in x around 0 91.6%
fma-define96.7%
+-commutative96.7%
mul-1-neg96.7%
Simplified96.7%
Taylor expanded in y around inf 100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 70.0%
mul-1-neg70.0%
distribute-lft-neg-out70.0%
*-commutative70.0%
Simplified70.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 94.4%
fma-define97.6%
+-commutative97.6%
mul-1-neg97.6%
Simplified97.6%
Taylor expanded in y around inf 98.5%
neg-mul-198.5%
sub-neg98.5%
Simplified98.5%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf 98.2%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00023) (not (<= y 0.25))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00023) || !(y <= 0.25)) {
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.00023d0)) .or. (.not. (y <= 0.25d0))) 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.00023) || !(y <= 0.25)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00023) or not (y <= 0.25): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00023) || !(y <= 0.25)) 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.00023) || ~((y <= 0.25))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00023], N[Not[LessEqual[y, 0.25]], $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.00023 \lor \neg \left(y \leq 0.25\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -2.3000000000000001e-4 or 0.25 < y Initial program 100.0%
Taylor expanded in x around 0 94.5%
fma-define97.6%
+-commutative97.6%
mul-1-neg97.6%
Simplified97.6%
Taylor expanded in y around inf 98.5%
neg-mul-198.5%
sub-neg98.5%
Simplified98.5%
if -2.3000000000000001e-4 < y < 0.25Initial program 100.0%
Taylor expanded in x around inf 73.0%
mul-1-neg73.0%
unsub-neg73.0%
Simplified73.0%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.22e+64) (not (<= z 6.8e+167))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.22e+64) || !(z <= 6.8e+167)) {
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.22d+64)) .or. (.not. (z <= 6.8d+167))) 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.22e+64) || !(z <= 6.8e+167)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.22e+64) or not (z <= 6.8e+167): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.22e+64) || !(z <= 6.8e+167)) 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.22e+64) || ~((z <= 6.8e+167))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.22e+64], N[Not[LessEqual[z, 6.8e+167]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.22 \cdot 10^{+64} \lor \neg \left(z \leq 6.8 \cdot 10^{+167}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -1.21999999999999994e64 or 6.8000000000000001e167 < z Initial program 100.0%
Taylor expanded in x around 0 94.2%
fma-define97.7%
+-commutative97.7%
mul-1-neg97.7%
Simplified97.7%
Taylor expanded in x around 0 72.1%
if -1.21999999999999994e64 < z < 6.8000000000000001e167Initial program 100.0%
Taylor expanded in x around inf 80.7%
mul-1-neg80.7%
unsub-neg80.7%
Simplified80.7%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e-41) (not (<= y 0.006))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e-41) || !(y <= 0.006)) {
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-41)) .or. (.not. (y <= 0.006d0))) 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-41) || !(y <= 0.006)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e-41) or not (y <= 0.006): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e-41) || !(y <= 0.006)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4e-41) || ~((y <= 0.006))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e-41], N[Not[LessEqual[y, 0.006]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-41} \lor \neg \left(y \leq 0.006\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.00000000000000002e-41 or 0.0060000000000000001 < y Initial program 100.0%
Taylor expanded in x around 0 94.8%
fma-define97.8%
+-commutative97.8%
mul-1-neg97.8%
Simplified97.8%
Taylor expanded in x around 0 48.2%
if -4.00000000000000002e-41 < y < 0.0060000000000000001Initial program 100.0%
Taylor expanded in y around 0 73.0%
Final simplification59.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%
(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 37.3%
herbie shell --seed 2024145
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))