
(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 (if (or (<= z -3.8e-103) (not (<= z 8e-19))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-103) || !(z <= 8e-19)) {
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 <= (-3.8d-103)) .or. (.not. (z <= 8d-19))) 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 <= -3.8e-103) || !(z <= 8e-19)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e-103) or not (z <= 8e-19): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e-103) || !(z <= 8e-19)) 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 <= -3.8e-103) || ~((z <= 8e-19))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e-103], N[Not[LessEqual[z, 8e-19]], $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 -3.8 \cdot 10^{-103} \lor \neg \left(z \leq 8 \cdot 10^{-19}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -3.8000000000000001e-103 or 7.9999999999999998e-19 < z Initial program 100.0%
Taylor expanded in z around inf 85.2%
if -3.8000000000000001e-103 < z < 7.9999999999999998e-19Initial program 100.0%
Taylor expanded in x around inf 93.1%
mul-1-neg93.1%
unsub-neg93.1%
Simplified93.1%
sub-neg93.1%
distribute-rgt-in93.1%
*-un-lft-identity93.1%
distribute-lft-neg-in93.1%
unsub-neg93.1%
Applied egg-rr93.1%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-102) (not (<= z 1.02e-19))) (+ x (* y z)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-102) || !(z <= 1.02e-19)) {
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 <= (-6.5d-102)) .or. (.not. (z <= 1.02d-19))) 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 <= -6.5e-102) || !(z <= 1.02e-19)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-102) or not (z <= 1.02e-19): tmp = x + (y * z) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-102) || !(z <= 1.02e-19)) 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 <= -6.5e-102) || ~((z <= 1.02e-19))) tmp = x + (y * z); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-102], N[Not[LessEqual[z, 1.02e-19]], $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 -6.5 \cdot 10^{-102} \lor \neg \left(z \leq 1.02 \cdot 10^{-19}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -6.5000000000000003e-102 or 1.02000000000000004e-19 < z Initial program 100.0%
Taylor expanded in z around inf 85.2%
if -6.5000000000000003e-102 < z < 1.02000000000000004e-19Initial program 100.0%
Taylor expanded in x around inf 93.1%
mul-1-neg93.1%
unsub-neg93.1%
Simplified93.1%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 50000000000.0))) (* x (- y)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 50000000000.0)) {
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.0d0)) .or. (.not. (y <= 50000000000.0d0))) 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.0) || !(y <= 50000000000.0)) {
tmp = x * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 50000000000.0): tmp = x * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 50000000000.0)) 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.0) || ~((y <= 50000000000.0))) tmp = x * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 50000000000.0]], $MachinePrecision]], N[(x * (-y)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 50000000000\right):\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 5e10 < y Initial program 100.0%
Taylor expanded in x around inf 54.3%
mul-1-neg54.3%
unsub-neg54.3%
Simplified54.3%
Taylor expanded in y around inf 53.5%
neg-mul-153.5%
Simplified53.5%
if -1 < y < 5e10Initial program 100.0%
Taylor expanded in y around 0 70.3%
Final simplification61.2%
(FPCore (x y z) :precision binary64 (* x (- 1.0 y)))
double code(double x, double y, double z) {
return x * (1.0 - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - y)
end function
public static double code(double x, double y, double z) {
return x * (1.0 - y);
}
def code(x, y, z): return x * (1.0 - y)
function code(x, y, z) return Float64(x * Float64(1.0 - y)) end
function tmp = code(x, y, z) tmp = x * (1.0 - y); end
code[x_, y_, z_] := N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 62.2%
mul-1-neg62.2%
unsub-neg62.2%
Simplified62.2%
(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 2024146
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))