
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.7e-84) (* y z) (if (<= y 1.25e-37) x (if (<= y 4e+23) (* y z) (* y (- x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e-84) {
tmp = y * z;
} else if (y <= 1.25e-37) {
tmp = x;
} else if (y <= 4e+23) {
tmp = y * z;
} else {
tmp = 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 (y <= (-2.7d-84)) then
tmp = y * z
else if (y <= 1.25d-37) then
tmp = x
else if (y <= 4d+23) then
tmp = y * z
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e-84) {
tmp = y * z;
} else if (y <= 1.25e-37) {
tmp = x;
} else if (y <= 4e+23) {
tmp = y * z;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.7e-84: tmp = y * z elif y <= 1.25e-37: tmp = x elif y <= 4e+23: tmp = y * z else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.7e-84) tmp = Float64(y * z); elseif (y <= 1.25e-37) tmp = x; elseif (y <= 4e+23) tmp = Float64(y * z); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.7e-84) tmp = y * z; elseif (y <= 1.25e-37) tmp = x; elseif (y <= 4e+23) tmp = y * z; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.7e-84], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.25e-37], x, If[LessEqual[y, 4e+23], N[(y * z), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{-84}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-37}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+23}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -2.6999999999999999e-84 or 1.2499999999999999e-37 < y < 3.9999999999999997e23Initial program 100.0%
Taylor expanded in x around 0 62.1%
if -2.6999999999999999e-84 < y < 1.2499999999999999e-37Initial program 100.0%
Taylor expanded in y around 0 79.4%
if 3.9999999999999997e23 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around 0 61.6%
mul-1-neg61.6%
*-commutative61.6%
distribute-rgt-neg-out61.6%
Simplified61.6%
Final simplification69.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e-114) (not (<= x 1.55e-108))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e-114) || !(x <= 1.55e-108)) {
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.6d-114)) .or. (.not. (x <= 1.55d-108))) 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.6e-114) || !(x <= 1.55e-108)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e-114) or not (x <= 1.55e-108): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e-114) || !(x <= 1.55e-108)) 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.6e-114) || ~((x <= 1.55e-108))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e-114], N[Not[LessEqual[x, 1.55e-108]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-114} \lor \neg \left(x \leq 1.55 \cdot 10^{-108}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.6000000000000001e-114 or 1.55000000000000007e-108 < x Initial program 100.0%
Taylor expanded in x around inf 80.9%
mul-1-neg80.9%
unsub-neg80.9%
Simplified80.9%
if -1.6000000000000001e-114 < x < 1.55000000000000007e-108Initial program 100.0%
Taylor expanded in x around 0 76.7%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.12e-91) (not (<= y 1.4e-37))) (* y (- z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.12e-91) || !(y <= 1.4e-37)) {
tmp = y * (z - x);
} 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.12d-91)) .or. (.not. (y <= 1.4d-37))) then
tmp = y * (z - x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.12e-91) || !(y <= 1.4e-37)) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.12e-91) or not (y <= 1.4e-37): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.12e-91) || !(y <= 1.4e-37)) tmp = Float64(y * Float64(z - x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.12e-91) || ~((y <= 1.4e-37))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.12e-91], N[Not[LessEqual[y, 1.4e-37]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.12 \cdot 10^{-91} \lor \neg \left(y \leq 1.4 \cdot 10^{-37}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.12e-91 or 1.4000000000000001e-37 < y Initial program 100.0%
Taylor expanded in y around inf 92.1%
if -1.12e-91 < y < 1.4000000000000001e-37Initial program 100.0%
Taylor expanded in y around 0 79.4%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e-87) (not (<= y 1.6e-37))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-87) || !(y <= 1.6e-37)) {
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 <= (-9.5d-87)) .or. (.not. (y <= 1.6d-37))) 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 <= -9.5e-87) || !(y <= 1.6e-37)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.5e-87) or not (y <= 1.6e-37): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e-87) || !(y <= 1.6e-37)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.5e-87) || ~((y <= 1.6e-37))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e-87], N[Not[LessEqual[y, 1.6e-37]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-87} \lor \neg \left(y \leq 1.6 \cdot 10^{-37}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.5e-87 or 1.5999999999999999e-37 < y Initial program 100.0%
Taylor expanded in x around 0 55.7%
if -9.5e-87 < y < 1.5999999999999999e-37Initial program 100.0%
Taylor expanded in y around 0 79.4%
Final simplification66.4%
(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 40.8%
Final simplification40.8%
herbie shell --seed 2023301
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))