
(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
(let* ((t_0 (* y (- x))))
(if (<= y -8e+205)
t_0
(if (<= y -3.8e+48)
(* y z)
(if (<= y -1.4e+22)
t_0
(if (<= y -3e-70)
(* y z)
(if (<= y 1e-41) x (if (<= y 25000000000.0) (* y z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -8e+205) {
tmp = t_0;
} else if (y <= -3.8e+48) {
tmp = y * z;
} else if (y <= -1.4e+22) {
tmp = t_0;
} else if (y <= -3e-70) {
tmp = y * z;
} else if (y <= 1e-41) {
tmp = x;
} else if (y <= 25000000000.0) {
tmp = y * z;
} else {
tmp = t_0;
}
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 = y * -x
if (y <= (-8d+205)) then
tmp = t_0
else if (y <= (-3.8d+48)) then
tmp = y * z
else if (y <= (-1.4d+22)) then
tmp = t_0
else if (y <= (-3d-70)) then
tmp = y * z
else if (y <= 1d-41) then
tmp = x
else if (y <= 25000000000.0d0) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -8e+205) {
tmp = t_0;
} else if (y <= -3.8e+48) {
tmp = y * z;
} else if (y <= -1.4e+22) {
tmp = t_0;
} else if (y <= -3e-70) {
tmp = y * z;
} else if (y <= 1e-41) {
tmp = x;
} else if (y <= 25000000000.0) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -8e+205: tmp = t_0 elif y <= -3.8e+48: tmp = y * z elif y <= -1.4e+22: tmp = t_0 elif y <= -3e-70: tmp = y * z elif y <= 1e-41: tmp = x elif y <= 25000000000.0: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -8e+205) tmp = t_0; elseif (y <= -3.8e+48) tmp = Float64(y * z); elseif (y <= -1.4e+22) tmp = t_0; elseif (y <= -3e-70) tmp = Float64(y * z); elseif (y <= 1e-41) tmp = x; elseif (y <= 25000000000.0) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -8e+205) tmp = t_0; elseif (y <= -3.8e+48) tmp = y * z; elseif (y <= -1.4e+22) tmp = t_0; elseif (y <= -3e-70) tmp = y * z; elseif (y <= 1e-41) tmp = x; elseif (y <= 25000000000.0) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -8e+205], t$95$0, If[LessEqual[y, -3.8e+48], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.4e+22], t$95$0, If[LessEqual[y, -3e-70], N[(y * z), $MachinePrecision], If[LessEqual[y, 1e-41], x, If[LessEqual[y, 25000000000.0], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -8 \cdot 10^{+205}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.8 \cdot 10^{+48}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{+22}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3 \cdot 10^{-70}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 10^{-41}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 25000000000:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.00000000000000013e205 or -3.8e48 < y < -1.4e22 or 2.5e10 < y Initial program 100.0%
Taylor expanded in x around inf 64.9%
mul-1-neg64.9%
unsub-neg64.9%
Simplified64.9%
Taylor expanded in y around inf 64.6%
associate-*r*64.6%
mul-1-neg64.6%
Simplified64.6%
if -8.00000000000000013e205 < y < -3.8e48 or -1.4e22 < y < -3.0000000000000001e-70 or 1.00000000000000001e-41 < y < 2.5e10Initial program 100.0%
Taylor expanded in z around inf 79.2%
Taylor expanded in x around 0 63.4%
if -3.0000000000000001e-70 < y < 1.00000000000000001e-41Initial program 100.0%
Taylor expanded in y around 0 75.7%
Final simplification68.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.6e-29) (not (<= z 1.1e-53))) (+ x (* y z)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e-29) || !(z <= 1.1e-53)) {
tmp = x + (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.6d-29)) .or. (.not. (z <= 1.1d-53))) then
tmp = x + (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.6e-29) || !(z <= 1.1e-53)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.6e-29) or not (z <= 1.1e-53): tmp = x + (y * z) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.6e-29) || !(z <= 1.1e-53)) tmp = Float64(x + 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.6e-29) || ~((z <= 1.1e-53))) tmp = x + (y * z); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.6e-29], N[Not[LessEqual[z, 1.1e-53]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-29} \lor \neg \left(z \leq 1.1 \cdot 10^{-53}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -2.6000000000000002e-29 or 1.10000000000000009e-53 < z Initial program 100.0%
Taylor expanded in z around inf 86.8%
if -2.6000000000000002e-29 < z < 1.10000000000000009e-53Initial program 100.0%
Taylor expanded in x around inf 91.4%
mul-1-neg91.4%
unsub-neg91.4%
Simplified91.4%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-115) (not (<= x 2.25e-104))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-115) || !(x <= 2.25e-104)) {
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 <= (-3.1d-115)) .or. (.not. (x <= 2.25d-104))) 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 <= -3.1e-115) || !(x <= 2.25e-104)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-115) or not (x <= 2.25e-104): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-115) || !(x <= 2.25e-104)) 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 <= -3.1e-115) || ~((x <= 2.25e-104))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-115], N[Not[LessEqual[x, 2.25e-104]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-115} \lor \neg \left(x \leq 2.25 \cdot 10^{-104}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.10000000000000007e-115 or 2.2499999999999999e-104 < x Initial program 100.0%
Taylor expanded in x around inf 81.5%
mul-1-neg81.5%
unsub-neg81.5%
Simplified81.5%
if -3.10000000000000007e-115 < x < 2.2499999999999999e-104Initial program 100.0%
Taylor expanded in z around inf 93.4%
Taylor expanded in x around 0 81.4%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.85e-70) (not (<= y 1e-40))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.85e-70) || !(y <= 1e-40)) {
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 <= (-2.85d-70)) .or. (.not. (y <= 1d-40))) 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 <= -2.85e-70) || !(y <= 1e-40)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.85e-70) or not (y <= 1e-40): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.85e-70) || !(y <= 1e-40)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.85e-70) || ~((y <= 1e-40))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.85e-70], N[Not[LessEqual[y, 1e-40]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.85 \cdot 10^{-70} \lor \neg \left(y \leq 10^{-40}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.85000000000000014e-70 or 9.9999999999999993e-41 < y Initial program 100.0%
Taylor expanded in z around inf 55.0%
Taylor expanded in x around 0 48.7%
if -2.85000000000000014e-70 < y < 9.9999999999999993e-41Initial program 100.0%
Taylor expanded in y around 0 75.7%
Final simplification58.7%
(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 33.6%
herbie shell --seed 2024086
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))