
(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 6 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
(let* ((t_0 (* x (- y))))
(if (<= x -3.3e+62)
t_0
(if (<= x 2.1e-68)
(* y z)
(if (or (<= x 4.2e+110) (not (<= x 3.2e+193))) t_0 x)))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -3.3e+62) {
tmp = t_0;
} else if (x <= 2.1e-68) {
tmp = y * z;
} else if ((x <= 4.2e+110) || !(x <= 3.2e+193)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * -y
if (x <= (-3.3d+62)) then
tmp = t_0
else if (x <= 2.1d-68) then
tmp = y * z
else if ((x <= 4.2d+110) .or. (.not. (x <= 3.2d+193))) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -3.3e+62) {
tmp = t_0;
} else if (x <= 2.1e-68) {
tmp = y * z;
} else if ((x <= 4.2e+110) || !(x <= 3.2e+193)) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if x <= -3.3e+62: tmp = t_0 elif x <= 2.1e-68: tmp = y * z elif (x <= 4.2e+110) or not (x <= 3.2e+193): tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (x <= -3.3e+62) tmp = t_0; elseif (x <= 2.1e-68) tmp = Float64(y * z); elseif ((x <= 4.2e+110) || !(x <= 3.2e+193)) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (x <= -3.3e+62) tmp = t_0; elseif (x <= 2.1e-68) tmp = y * z; elseif ((x <= 4.2e+110) || ~((x <= 3.2e+193))) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[x, -3.3e+62], t$95$0, If[LessEqual[x, 2.1e-68], N[(y * z), $MachinePrecision], If[Or[LessEqual[x, 4.2e+110], N[Not[LessEqual[x, 3.2e+193]], $MachinePrecision]], t$95$0, x]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;x \leq -3.3 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-68}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{+110} \lor \neg \left(x \leq 3.2 \cdot 10^{+193}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -3.3e62 or 2.10000000000000008e-68 < x < 4.2000000000000003e110 or 3.20000000000000013e193 < x Initial program 100.0%
Taylor expanded in x around inf 89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
Taylor expanded in y around inf 57.4%
neg-mul-157.4%
distribute-rgt-neg-in57.4%
Simplified57.4%
if -3.3e62 < x < 2.10000000000000008e-68Initial program 100.0%
Taylor expanded in z around inf 90.2%
Taylor expanded in x around 0 72.3%
if 4.2000000000000003e110 < x < 3.20000000000000013e193Initial program 100.0%
Taylor expanded in y around 0 74.5%
Final simplification66.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e+60) (not (<= x 7.5e-69))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+60) || !(x <= 7.5e-69)) {
tmp = x * (1.0 - 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 ((x <= (-2d+60)) .or. (.not. (x <= 7.5d-69))) then
tmp = x * (1.0d0 - 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 ((x <= -2e+60) || !(x <= 7.5e-69)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e+60) or not (x <= 7.5e-69): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e+60) || !(x <= 7.5e-69)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e+60) || ~((x <= 7.5e-69))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e+60], N[Not[LessEqual[x, 7.5e-69]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+60} \lor \neg \left(x \leq 7.5 \cdot 10^{-69}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.9999999999999999e60 or 7.5e-69 < x Initial program 100.0%
Taylor expanded in x around inf 90.8%
mul-1-neg90.8%
unsub-neg90.8%
Simplified90.8%
if -1.9999999999999999e60 < x < 7.5e-69Initial program 100.0%
Taylor expanded in z around inf 90.2%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e-39) (not (<= x 1.05e-80))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e-39) || !(x <= 1.05e-80)) {
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 <= (-7.5d-39)) .or. (.not. (x <= 1.05d-80))) 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 <= -7.5e-39) || !(x <= 1.05e-80)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e-39) or not (x <= 1.05e-80): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e-39) || !(x <= 1.05e-80)) 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 <= -7.5e-39) || ~((x <= 1.05e-80))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e-39], N[Not[LessEqual[x, 1.05e-80]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-39} \lor \neg \left(x \leq 1.05 \cdot 10^{-80}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -7.49999999999999971e-39 or 1.05000000000000001e-80 < x Initial program 100.0%
Taylor expanded in x around inf 85.7%
mul-1-neg85.7%
unsub-neg85.7%
Simplified85.7%
if -7.49999999999999971e-39 < x < 1.05000000000000001e-80Initial program 100.0%
Taylor expanded in z around inf 91.3%
Taylor expanded in x around 0 80.6%
Final simplification83.6%
(FPCore (x y z) :precision binary64 (if (<= x -3.8e-38) x (if (<= x 6.8e+104) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e-38) {
tmp = x;
} else if (x <= 6.8e+104) {
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 (x <= (-3.8d-38)) then
tmp = x
else if (x <= 6.8d+104) 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 (x <= -3.8e-38) {
tmp = x;
} else if (x <= 6.8e+104) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.8e-38: tmp = x elif x <= 6.8e+104: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.8e-38) tmp = x; elseif (x <= 6.8e+104) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.8e-38) tmp = x; elseif (x <= 6.8e+104) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.8e-38], x, If[LessEqual[x, 6.8e+104], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{+104}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -3.8e-38 or 6.7999999999999994e104 < x Initial program 100.0%
Taylor expanded in y around 0 45.4%
if -3.8e-38 < x < 6.7999999999999994e104Initial program 100.0%
Taylor expanded in z around inf 84.5%
Taylor expanded in x around 0 70.1%
(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 30.1%
herbie shell --seed 2024191
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))