
(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%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e+258) (and (not (<= y -5.2e+223)) (<= y -4.8e+137))) (* x (- y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e+258) || (!(y <= -5.2e+223) && (y <= -4.8e+137))) {
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 <= (-7.5d+258)) .or. (.not. (y <= (-5.2d+223))) .and. (y <= (-4.8d+137))) 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 <= -7.5e+258) || (!(y <= -5.2e+223) && (y <= -4.8e+137))) {
tmp = x * -y;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e+258) or (not (y <= -5.2e+223) and (y <= -4.8e+137)): tmp = x * -y else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e+258) || (!(y <= -5.2e+223) && (y <= -4.8e+137))) 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 <= -7.5e+258) || (~((y <= -5.2e+223)) && (y <= -4.8e+137))) tmp = x * -y; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e+258], And[N[Not[LessEqual[y, -5.2e+223]], $MachinePrecision], LessEqual[y, -4.8e+137]]], N[(x * (-y)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+258} \lor \neg \left(y \leq -5.2 \cdot 10^{+223}\right) \land y \leq -4.8 \cdot 10^{+137}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -7.50000000000000032e258 or -5.2000000000000005e223 < y < -4.79999999999999966e137Initial program 100.0%
Taylor expanded in z around 0 83.8%
mul-1-neg83.8%
distribute-rgt-neg-in83.8%
Simplified83.8%
Taylor expanded in y around inf 83.8%
mul-1-neg83.8%
Simplified83.8%
if -7.50000000000000032e258 < y < -5.2000000000000005e223 or -4.79999999999999966e137 < y Initial program 100.0%
Taylor expanded in z around inf 81.8%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.9e-38) (not (<= z 2.1e-90))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e-38) || !(z <= 2.1e-90)) {
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 <= (-1.9d-38)) .or. (.not. (z <= 2.1d-90))) 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 <= -1.9e-38) || !(z <= 2.1e-90)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.9e-38) or not (z <= 2.1e-90): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.9e-38) || !(z <= 2.1e-90)) 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 <= -1.9e-38) || ~((z <= 2.1e-90))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.9e-38], N[Not[LessEqual[z, 2.1e-90]], $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 -1.9 \cdot 10^{-38} \lor \neg \left(z \leq 2.1 \cdot 10^{-90}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -1.9e-38 or 2.0999999999999999e-90 < z Initial program 100.0%
Taylor expanded in z around inf 91.1%
if -1.9e-38 < z < 2.0999999999999999e-90Initial program 100.0%
Taylor expanded in z around 0 91.3%
mul-1-neg91.3%
distribute-rgt-neg-in91.3%
Simplified91.3%
distribute-rgt-neg-out91.3%
unsub-neg91.3%
Applied egg-rr91.3%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.7e-33) (not (<= y 0.0072))) (* x (- y)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e-33) || !(y <= 0.0072)) {
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.7d-33)) .or. (.not. (y <= 0.0072d0))) 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.7e-33) || !(y <= 0.0072)) {
tmp = x * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.7e-33) or not (y <= 0.0072): tmp = x * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.7e-33) || !(y <= 0.0072)) 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.7e-33) || ~((y <= 0.0072))) tmp = x * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.7e-33], N[Not[LessEqual[y, 0.0072]], $MachinePrecision]], N[(x * (-y)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-33} \lor \neg \left(y \leq 0.0072\right):\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.7e-33 or 0.0071999999999999998 < y Initial program 100.0%
Taylor expanded in z around 0 50.0%
mul-1-neg50.0%
distribute-rgt-neg-in50.0%
Simplified50.0%
Taylor expanded in y around inf 49.7%
mul-1-neg49.7%
Simplified49.7%
if -1.7e-33 < y < 0.0071999999999999998Initial program 100.0%
Taylor expanded in z around 0 69.1%
mul-1-neg69.1%
distribute-rgt-neg-in69.1%
Simplified69.1%
Taylor expanded in y around 0 68.8%
Final simplification58.8%
(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 59.1%
mul-1-neg59.1%
distribute-rgt-neg-in59.1%
Simplified59.1%
Taylor expanded in y around 0 34.4%
herbie shell --seed 2024096
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))