
(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 5 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%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.1e-295) (not (<= z 9.8e-167))) (+ x (* y z)) (* x (- y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.1e-295) || !(z <= 9.8e-167)) {
tmp = x + (y * z);
} else {
tmp = 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 <= (-4.1d-295)) .or. (.not. (z <= 9.8d-167))) then
tmp = x + (y * z)
else
tmp = x * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.1e-295) || !(z <= 9.8e-167)) {
tmp = x + (y * z);
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.1e-295) or not (z <= 9.8e-167): tmp = x + (y * z) else: tmp = x * -y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.1e-295) || !(z <= 9.8e-167)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.1e-295) || ~((z <= 9.8e-167))) tmp = x + (y * z); else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.1e-295], N[Not[LessEqual[z, 9.8e-167]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{-295} \lor \neg \left(z \leq 9.8 \cdot 10^{-167}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < -4.10000000000000005e-295 or 9.80000000000000006e-167 < z Initial program 100.0%
Taylor expanded in z around inf 82.8%
if -4.10000000000000005e-295 < z < 9.80000000000000006e-167Initial program 100.0%
Taylor expanded in z around 0 97.2%
mul-1-neg97.2%
distribute-rgt-neg-out97.2%
Simplified97.2%
Taylor expanded in y around inf 61.9%
associate-*r*61.9%
neg-mul-161.9%
Simplified61.9%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.4e+28) (not (<= z 6e-143))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.4e+28) || !(z <= 6e-143)) {
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 <= (-6.4d+28)) .or. (.not. (z <= 6d-143))) 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 <= -6.4e+28) || !(z <= 6e-143)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.4e+28) or not (z <= 6e-143): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.4e+28) || !(z <= 6e-143)) 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 <= -6.4e+28) || ~((z <= 6e-143))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.4e+28], N[Not[LessEqual[z, 6e-143]], $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 -6.4 \cdot 10^{+28} \lor \neg \left(z \leq 6 \cdot 10^{-143}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -6.4000000000000001e28 or 5.9999999999999997e-143 < z Initial program 100.0%
Taylor expanded in z around inf 91.1%
if -6.4000000000000001e28 < z < 5.9999999999999997e-143Initial program 100.0%
Taylor expanded in z around 0 92.5%
mul-1-neg92.5%
distribute-rgt-neg-out92.5%
Simplified92.5%
Taylor expanded in x around 0 92.4%
neg-mul-192.4%
+-commutative92.4%
distribute-rgt1-in92.5%
cancel-sign-sub-inv92.5%
Simplified92.5%
Final simplification91.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -3e-5) (not (<= y 1.0))) (* x (- y)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3e-5) || !(y <= 1.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 <= (-3d-5)) .or. (.not. (y <= 1.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 <= -3e-5) || !(y <= 1.0)) {
tmp = x * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3e-5) or not (y <= 1.0): tmp = x * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3e-5) || !(y <= 1.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 <= -3e-5) || ~((y <= 1.0))) tmp = x * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3e-5], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * (-y)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-5} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.00000000000000008e-5 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 51.3%
mul-1-neg51.3%
distribute-rgt-neg-out51.3%
Simplified51.3%
Taylor expanded in y around inf 50.3%
associate-*r*50.3%
neg-mul-150.3%
Simplified50.3%
if -3.00000000000000008e-5 < y < 1Initial program 100.0%
Taylor expanded in z around 0 79.9%
mul-1-neg79.9%
distribute-rgt-neg-out79.9%
Simplified79.9%
Taylor expanded in y around 0 79.2%
Final simplification63.8%
(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 z around 0 64.7%
mul-1-neg64.7%
distribute-rgt-neg-out64.7%
Simplified64.7%
Taylor expanded in y around 0 38.7%
Final simplification38.7%
herbie shell --seed 2023242
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))