
(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 -1.0) t_0 (if (<= y 2.1e-14) x (if (<= y 7.5e+14) (* y z) t_0)))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.1e-14) {
tmp = x;
} else if (y <= 7.5e+14) {
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 <= (-1.0d0)) then
tmp = t_0
else if (y <= 2.1d-14) then
tmp = x
else if (y <= 7.5d+14) 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 <= -1.0) {
tmp = t_0;
} else if (y <= 2.1e-14) {
tmp = x;
} else if (y <= 7.5e+14) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 2.1e-14: tmp = x elif y <= 7.5e+14: 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 <= -1.0) tmp = t_0; elseif (y <= 2.1e-14) tmp = x; elseif (y <= 7.5e+14) 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 <= -1.0) tmp = t_0; elseif (y <= 2.1e-14) tmp = x; elseif (y <= 7.5e+14) 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, -1.0], t$95$0, If[LessEqual[y, 2.1e-14], x, If[LessEqual[y, 7.5e+14], N[(y * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+14}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 7.5e14 < y Initial program 100.0%
Taylor expanded in x around inf 60.6%
mul-1-neg60.6%
unsub-neg60.6%
Simplified60.6%
Taylor expanded in y around inf 60.2%
neg-mul-160.2%
Simplified60.2%
if -1 < y < 2.0999999999999999e-14Initial program 100.0%
Taylor expanded in y around 0 73.5%
if 2.0999999999999999e-14 < y < 7.5e14Initial program 99.8%
Taylor expanded in z around inf 75.1%
Taylor expanded in z around inf 75.1%
Taylor expanded in y around inf 75.2%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.4e-15) (not (<= z 8200.0))) (+ x (* y z)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-15) || !(z <= 8200.0)) {
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 <= (-1.4d-15)) .or. (.not. (z <= 8200.0d0))) 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 <= -1.4e-15) || !(z <= 8200.0)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.4e-15) or not (z <= 8200.0): tmp = x + (y * z) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.4e-15) || !(z <= 8200.0)) 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 <= -1.4e-15) || ~((z <= 8200.0))) tmp = x + (y * z); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.4e-15], N[Not[LessEqual[z, 8200.0]], $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 -1.4 \cdot 10^{-15} \lor \neg \left(z \leq 8200\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -1.40000000000000007e-15 or 8200 < z Initial program 99.9%
Taylor expanded in z around inf 89.1%
if -1.40000000000000007e-15 < z < 8200Initial program 100.0%
Taylor expanded in x around inf 91.0%
mul-1-neg91.0%
unsub-neg91.0%
Simplified91.0%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -30500000.0) (not (<= z 8.5e+125))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -30500000.0) || !(z <= 8.5e+125)) {
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 <= (-30500000.0d0)) .or. (.not. (z <= 8.5d+125))) 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 <= -30500000.0) || !(z <= 8.5e+125)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -30500000.0) or not (z <= 8.5e+125): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -30500000.0) || !(z <= 8.5e+125)) 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 <= -30500000.0) || ~((z <= 8.5e+125))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -30500000.0], N[Not[LessEqual[z, 8.5e+125]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -30500000 \lor \neg \left(z \leq 8.5 \cdot 10^{+125}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -3.05e7 or 8.49999999999999974e125 < z Initial program 99.9%
Taylor expanded in z around inf 91.3%
Taylor expanded in z around inf 91.2%
Taylor expanded in y around inf 71.9%
if -3.05e7 < z < 8.49999999999999974e125Initial program 100.0%
Taylor expanded in x around inf 85.1%
mul-1-neg85.1%
unsub-neg85.1%
Simplified85.1%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.4e-17) (not (<= y 2.3e-13))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e-17) || !(y <= 2.3e-13)) {
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 <= (-5.4d-17)) .or. (.not. (y <= 2.3d-13))) 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 <= -5.4e-17) || !(y <= 2.3e-13)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.4e-17) or not (y <= 2.3e-13): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.4e-17) || !(y <= 2.3e-13)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.4e-17) || ~((y <= 2.3e-13))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.4e-17], N[Not[LessEqual[y, 2.3e-13]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-17} \lor \neg \left(y \leq 2.3 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.4000000000000002e-17 or 2.29999999999999979e-13 < y Initial program 100.0%
Taylor expanded in z around inf 47.0%
Taylor expanded in z around inf 53.9%
Taylor expanded in y around inf 46.1%
if -5.4000000000000002e-17 < y < 2.29999999999999979e-13Initial program 100.0%
Taylor expanded in y around 0 74.3%
Final simplification59.2%
(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 36.5%
herbie shell --seed 2024139
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))