
(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 5 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 (+ 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 (if (or (<= y -4.2e+38) (and (not (<= y 7.8e+28)) (<= y 1e+252))) (* x (- y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.2e+38) || (!(y <= 7.8e+28) && (y <= 1e+252))) {
tmp = x * -y;
} 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 <= (-4.2d+38)) .or. (.not. (y <= 7.8d+28)) .and. (y <= 1d+252)) then
tmp = x * -y
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 <= -4.2e+38) || (!(y <= 7.8e+28) && (y <= 1e+252))) {
tmp = x * -y;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.2e+38) or (not (y <= 7.8e+28) and (y <= 1e+252)): tmp = x * -y else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.2e+38) || (!(y <= 7.8e+28) && (y <= 1e+252))) tmp = Float64(x * Float64(-y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.2e+38) || (~((y <= 7.8e+28)) && (y <= 1e+252))) tmp = x * -y; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.2e+38], And[N[Not[LessEqual[y, 7.8e+28]], $MachinePrecision], LessEqual[y, 1e+252]]], N[(x * (-y)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+38} \lor \neg \left(y \leq 7.8 \cdot 10^{+28}\right) \land y \leq 10^{+252}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -4.2e38 or 7.7999999999999997e28 < y < 1.0000000000000001e252Initial program 100.0%
Taylor expanded in z around 0 60.2%
mul-1-neg60.2%
distribute-lft-neg-out60.2%
*-commutative60.2%
Simplified60.2%
Taylor expanded in y around inf 60.2%
associate-*r*60.2%
mul-1-neg60.2%
Simplified60.2%
if -4.2e38 < y < 7.7999999999999997e28 or 1.0000000000000001e252 < y Initial program 100.0%
Taylor expanded in z around inf 91.5%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.4e-18) (not (<= z 7.5e-84))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.4e-18) || !(z <= 7.5e-84)) {
tmp = x + (y * z);
} else {
tmp = x - (x * 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 <= (-4.4d-18)) .or. (.not. (z <= 7.5d-84))) then
tmp = x + (y * z)
else
tmp = x - (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.4e-18) || !(z <= 7.5e-84)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.4e-18) or not (z <= 7.5e-84): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.4e-18) || !(z <= 7.5e-84)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.4e-18) || ~((z <= 7.5e-84))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.4e-18], N[Not[LessEqual[z, 7.5e-84]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{-18} \lor \neg \left(z \leq 7.5 \cdot 10^{-84}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -4.3999999999999997e-18 or 7.50000000000000026e-84 < z Initial program 100.0%
Taylor expanded in z around inf 85.5%
if -4.3999999999999997e-18 < z < 7.50000000000000026e-84Initial program 100.0%
Taylor expanded in z around 0 86.2%
mul-1-neg86.2%
distribute-lft-neg-out86.2%
*-commutative86.2%
Simplified86.2%
*-commutative86.2%
distribute-lft-neg-out86.2%
unsub-neg86.2%
Applied egg-rr86.2%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* x (- y)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * -y;
} 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 <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = x * -y
else
tmp = x
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 = x * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = x * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(x * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = x * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * (-y)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 55.5%
mul-1-neg55.5%
distribute-lft-neg-out55.5%
*-commutative55.5%
Simplified55.5%
Taylor expanded in y around inf 54.0%
associate-*r*54.0%
mul-1-neg54.0%
Simplified54.0%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around 0 68.3%
mul-1-neg68.3%
distribute-lft-neg-out68.3%
*-commutative68.3%
Simplified68.3%
Taylor expanded in y around 0 65.7%
Final simplification59.3%
(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 z around 0 61.3%
mul-1-neg61.3%
distribute-lft-neg-out61.3%
*-commutative61.3%
Simplified61.3%
Taylor expanded in y around 0 31.4%
Final simplification31.4%
herbie shell --seed 2023310
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))