
(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 8 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%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -6.9e+273) (* y (- x)) (if (or (<= y -1.42e-8) (not (<= y 9.8e-51))) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.9e+273) {
tmp = y * -x;
} else if ((y <= -1.42e-8) || !(y <= 9.8e-51)) {
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 <= (-6.9d+273)) then
tmp = y * -x
else if ((y <= (-1.42d-8)) .or. (.not. (y <= 9.8d-51))) 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 <= -6.9e+273) {
tmp = y * -x;
} else if ((y <= -1.42e-8) || !(y <= 9.8e-51)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.9e+273: tmp = y * -x elif (y <= -1.42e-8) or not (y <= 9.8e-51): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.9e+273) tmp = Float64(y * Float64(-x)); elseif ((y <= -1.42e-8) || !(y <= 9.8e-51)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.9e+273) tmp = y * -x; elseif ((y <= -1.42e-8) || ~((y <= 9.8e-51))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.9e+273], N[(y * (-x)), $MachinePrecision], If[Or[LessEqual[y, -1.42e-8], N[Not[LessEqual[y, 9.8e-51]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.9 \cdot 10^{+273}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq -1.42 \cdot 10^{-8} \lor \neg \left(y \leq 9.8 \cdot 10^{-51}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.9000000000000001e273Initial program 100.0%
Taylor expanded in x around inf 87.6%
mul-1-neg87.6%
unsub-neg87.6%
Simplified87.6%
Taylor expanded in y around inf 87.6%
associate-*r*87.6%
mul-1-neg87.6%
Simplified87.6%
if -6.9000000000000001e273 < y < -1.41999999999999998e-8 or 9.79999999999999948e-51 < y Initial program 100.0%
Taylor expanded in x around 0 96.5%
fma-define99.3%
+-commutative99.3%
mul-1-neg99.3%
Simplified99.3%
Taylor expanded in x around 0 63.0%
if -1.41999999999999998e-8 < y < 9.79999999999999948e-51Initial program 100.0%
Taylor expanded in y around 0 75.7%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.5e-86) (not (<= x 6.5e-43))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-86) || !(x <= 6.5e-43)) {
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.5d-86)) .or. (.not. (x <= 6.5d-43))) 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.5e-86) || !(x <= 6.5e-43)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.5e-86) or not (x <= 6.5e-43): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.5e-86) || !(x <= 6.5e-43)) 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.5e-86) || ~((x <= 6.5e-43))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.5e-86], N[Not[LessEqual[x, 6.5e-43]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-86} \lor \neg \left(x \leq 6.5 \cdot 10^{-43}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.50000000000000021e-86 or 6.50000000000000001e-43 < x Initial program 100.0%
Taylor expanded in x around inf 79.9%
mul-1-neg79.9%
unsub-neg79.9%
Simplified79.9%
if -3.50000000000000021e-86 < x < 6.50000000000000001e-43Initial program 100.0%
Taylor expanded in x around 0 100.0%
fma-define100.0%
+-commutative100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 77.3%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.7e-8) (not (<= y 9e-50))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e-8) || !(y <= 9e-50)) {
tmp = y * (z - x);
} 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 ((y <= (-1.7d-8)) .or. (.not. (y <= 9d-50))) then
tmp = y * (z - x)
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 ((y <= -1.7e-8) || !(y <= 9e-50)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.7e-8) or not (y <= 9e-50): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.7e-8) || !(y <= 9e-50)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.7e-8) || ~((y <= 9e-50))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.7e-8], N[Not[LessEqual[y, 9e-50]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-8} \lor \neg \left(y \leq 9 \cdot 10^{-50}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1.7e-8 or 8.99999999999999924e-50 < y Initial program 100.0%
Taylor expanded in x around 0 96.0%
fma-define98.7%
+-commutative98.7%
mul-1-neg98.7%
Simplified98.7%
Taylor expanded in y around inf 95.1%
mul-1-neg95.1%
unsub-neg95.1%
Simplified95.1%
if -1.7e-8 < y < 8.99999999999999924e-50Initial program 100.0%
Taylor expanded in x around inf 76.4%
mul-1-neg76.4%
unsub-neg76.4%
Simplified76.4%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (z - x);
} 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 ((y <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (z - x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 95.7%
fma-define98.6%
+-commutative98.6%
mul-1-neg98.6%
Simplified98.6%
Taylor expanded in y around inf 98.1%
mul-1-neg98.1%
unsub-neg98.1%
Simplified98.1%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf 98.6%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.42e-8) (not (<= y 9.5e-50))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e-8) || !(y <= 9.5e-50)) {
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 <= (-1.42d-8)) .or. (.not. (y <= 9.5d-50))) 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 <= -1.42e-8) || !(y <= 9.5e-50)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.42e-8) or not (y <= 9.5e-50): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.42e-8) || !(y <= 9.5e-50)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.42e-8) || ~((y <= 9.5e-50))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.42e-8], N[Not[LessEqual[y, 9.5e-50]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{-8} \lor \neg \left(y \leq 9.5 \cdot 10^{-50}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.41999999999999998e-8 or 9.4999999999999993e-50 < y Initial program 100.0%
Taylor expanded in x around 0 96.0%
fma-define98.7%
+-commutative98.7%
mul-1-neg98.7%
Simplified98.7%
Taylor expanded in x around 0 60.4%
if -1.41999999999999998e-8 < y < 9.4999999999999993e-50Initial program 100.0%
Taylor expanded in y around 0 75.7%
Final simplification66.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%
Final simplification100.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 34.4%
Final simplification34.4%
herbie shell --seed 2024075
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))