
(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 (if (or (<= x -2.6e+94) (not (<= x 1.15e+90))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+94) || !(x <= 1.15e+90)) {
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 <= (-2.6d+94)) .or. (.not. (x <= 1.15d+90))) 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 <= -2.6e+94) || !(x <= 1.15e+90)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e+94) or not (x <= 1.15e+90): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e+94) || !(x <= 1.15e+90)) 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 <= -2.6e+94) || ~((x <= 1.15e+90))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e+94], N[Not[LessEqual[x, 1.15e+90]], $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.6 \cdot 10^{+94} \lor \neg \left(x \leq 1.15 \cdot 10^{+90}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.5999999999999999e94 or 1.15e90 < x Initial program 100.0%
Taylor expanded in x around inf 93.8%
mul-1-neg93.8%
unsub-neg93.8%
Simplified93.8%
if -2.5999999999999999e94 < x < 1.15e90Initial program 100.0%
Taylor expanded in z around inf 89.1%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-54) (not (<= x 5.5e-113))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-54) || !(x <= 5.5e-113)) {
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 <= (-1.2d-54)) .or. (.not. (x <= 5.5d-113))) 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 <= -1.2e-54) || !(x <= 5.5e-113)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-54) or not (x <= 5.5e-113): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-54) || !(x <= 5.5e-113)) 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 <= -1.2e-54) || ~((x <= 5.5e-113))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-54], N[Not[LessEqual[x, 5.5e-113]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-54} \lor \neg \left(x \leq 5.5 \cdot 10^{-113}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.20000000000000007e-54 or 5.50000000000000053e-113 < x Initial program 100.0%
Taylor expanded in x around inf 78.4%
mul-1-neg78.4%
unsub-neg78.4%
Simplified78.4%
if -1.20000000000000007e-54 < x < 5.50000000000000053e-113Initial program 100.0%
Taylor expanded in z around inf 94.8%
Taylor expanded in z around inf 94.8%
Taylor expanded in y around inf 74.2%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (<= x -9e+92) (* x (- 1.0 y)) (if (<= x 1.8e+91) (+ x (* y z)) (- x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9e+92) {
tmp = x * (1.0 - y);
} else if (x <= 1.8e+91) {
tmp = x + (y * z);
} else {
tmp = x - (y * 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 <= (-9d+92)) then
tmp = x * (1.0d0 - y)
else if (x <= 1.8d+91) then
tmp = x + (y * z)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -9e+92) {
tmp = x * (1.0 - y);
} else if (x <= 1.8e+91) {
tmp = x + (y * z);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9e+92: tmp = x * (1.0 - y) elif x <= 1.8e+91: tmp = x + (y * z) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9e+92) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 1.8e+91) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9e+92) tmp = x * (1.0 - y); elseif (x <= 1.8e+91) tmp = x + (y * z); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9e+92], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.8e+91], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+92}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{+91}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if x < -8.9999999999999998e92Initial program 100.0%
Taylor expanded in x around inf 93.5%
mul-1-neg93.5%
unsub-neg93.5%
Simplified93.5%
if -8.9999999999999998e92 < x < 1.8e91Initial program 100.0%
Taylor expanded in z around inf 89.1%
if 1.8e91 < x Initial program 100.0%
Taylor expanded in x around inf 94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
sub-neg94.0%
distribute-rgt-in94.1%
*-un-lft-identity94.1%
distribute-lft-neg-in94.1%
unsub-neg94.1%
Applied egg-rr94.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.8e-51) (not (<= y 7.5e-32))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.8e-51) || !(y <= 7.5e-32)) {
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 <= (-4.8d-51)) .or. (.not. (y <= 7.5d-32))) 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 <= -4.8e-51) || !(y <= 7.5e-32)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.8e-51) or not (y <= 7.5e-32): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.8e-51) || !(y <= 7.5e-32)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.8e-51) || ~((y <= 7.5e-32))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.8e-51], N[Not[LessEqual[y, 7.5e-32]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-51} \lor \neg \left(y \leq 7.5 \cdot 10^{-32}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.8e-51 or 7.49999999999999953e-32 < y Initial program 100.0%
Taylor expanded in z around inf 64.3%
Taylor expanded in z around inf 67.2%
Taylor expanded in y around inf 59.5%
if -4.8e-51 < y < 7.49999999999999953e-32Initial program 100.0%
Taylor expanded in y around 0 75.9%
Final simplification67.0%
(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 38.7%
herbie shell --seed 2024163
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))