
(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 7 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 (or (<= y -1800000.0) (not (<= y 1.0))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1800000.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 <= (-1800000.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 <= -1800000.0) || !(y <= 1.0)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1800000.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 <= -1800000.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 <= -1800000.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, -1800000.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 -1800000 \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.8e6 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 99.0%
if -1.8e6 < y < 1Initial program 100.0%
Taylor expanded in z around inf 98.8%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.1e-51) (not (<= y 1.06e-17))) (* y (- z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.1e-51) || !(y <= 1.06e-17)) {
tmp = y * (z - x);
} 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 <= (-4.1d-51)) .or. (.not. (y <= 1.06d-17))) then
tmp = y * (z - x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.1e-51) || !(y <= 1.06e-17)) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.1e-51) or not (y <= 1.06e-17): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.1e-51) || !(y <= 1.06e-17)) tmp = Float64(y * Float64(z - x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.1e-51) || ~((y <= 1.06e-17))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.1e-51], N[Not[LessEqual[y, 1.06e-17]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-51} \lor \neg \left(y \leq 1.06 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.09999999999999973e-51 or 1.06000000000000006e-17 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
Taylor expanded in z around inf 95.3%
if -4.09999999999999973e-51 < y < 1.06000000000000006e-17Initial program 100.0%
Taylor expanded in y around 0 70.8%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.9e+21) (not (<= z 4.8e+110))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.9e+21) || !(z <= 4.8e+110)) {
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.9d+21)) .or. (.not. (z <= 4.8d+110))) 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.9e+21) || !(z <= 4.8e+110)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.9e+21) or not (z <= 4.8e+110): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.9e+21) || !(z <= 4.8e+110)) 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.9e+21) || ~((z <= 4.8e+110))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.9e+21], N[Not[LessEqual[z, 4.8e+110]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{+21} \lor \neg \left(z \leq 4.8 \cdot 10^{+110}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -2.9e21 or 4.80000000000000025e110 < z Initial program 100.0%
Taylor expanded in z around inf 96.4%
+-commutative96.4%
mul-1-neg96.4%
unsub-neg96.4%
div-sub96.4%
unsub-neg96.4%
mul-1-neg96.4%
mul-1-neg96.4%
unsub-neg96.4%
*-lft-identity96.4%
*-commutative96.4%
distribute-rgt-out--96.4%
Simplified96.4%
Taylor expanded in z around inf 76.6%
*-commutative76.6%
Simplified76.6%
if -2.9e21 < z < 4.80000000000000025e110Initial program 100.0%
Taylor expanded in x around inf 79.5%
mul-1-neg79.5%
unsub-neg79.5%
Simplified79.5%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e-52) (not (<= y 2.2e-16))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-52) || !(y <= 2.2e-16)) {
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.4d-52)) .or. (.not. (y <= 2.2d-16))) 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.4e-52) || !(y <= 2.2e-16)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e-52) or not (y <= 2.2e-16): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-52) || !(y <= 2.2e-16)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.4e-52) || ~((y <= 2.2e-16))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e-52], N[Not[LessEqual[y, 2.2e-16]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-52} \lor \neg \left(y \leq 2.2 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.40000000000000017e-52 or 2.2e-16 < y Initial program 100.0%
Taylor expanded in z around inf 86.5%
+-commutative86.5%
mul-1-neg86.5%
unsub-neg86.5%
div-sub87.9%
unsub-neg87.9%
mul-1-neg87.9%
mul-1-neg87.9%
unsub-neg87.9%
*-lft-identity87.9%
*-commutative87.9%
distribute-rgt-out--87.9%
Simplified87.9%
Taylor expanded in z around inf 58.8%
*-commutative58.8%
Simplified58.8%
if -3.40000000000000017e-52 < y < 2.2e-16Initial program 100.0%
Taylor expanded in y around 0 70.8%
Final simplification64.1%
(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 34.8%
herbie shell --seed 2024132
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))