
(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
(let* ((t_0 (* y (- x))))
(if (<= y -450000000.0)
t_0
(if (<= y 5.8e-104)
x
(if (or (<= y 3e+52) (and (not (<= y 3.1e+91)) (<= y 5e+207)))
(* y z)
t_0)))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -450000000.0) {
tmp = t_0;
} else if (y <= 5.8e-104) {
tmp = x;
} else if ((y <= 3e+52) || (!(y <= 3.1e+91) && (y <= 5e+207))) {
tmp = y * z;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-450000000.0d0)) then
tmp = t_0
else if (y <= 5.8d-104) then
tmp = x
else if ((y <= 3d+52) .or. (.not. (y <= 3.1d+91)) .and. (y <= 5d+207)) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -450000000.0) {
tmp = t_0;
} else if (y <= 5.8e-104) {
tmp = x;
} else if ((y <= 3e+52) || (!(y <= 3.1e+91) && (y <= 5e+207))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -450000000.0: tmp = t_0 elif y <= 5.8e-104: tmp = x elif (y <= 3e+52) or (not (y <= 3.1e+91) and (y <= 5e+207)): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -450000000.0) tmp = t_0; elseif (y <= 5.8e-104) tmp = x; elseif ((y <= 3e+52) || (!(y <= 3.1e+91) && (y <= 5e+207))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -450000000.0) tmp = t_0; elseif (y <= 5.8e-104) tmp = x; elseif ((y <= 3e+52) || (~((y <= 3.1e+91)) && (y <= 5e+207))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -450000000.0], t$95$0, If[LessEqual[y, 5.8e-104], x, If[Or[LessEqual[y, 3e+52], And[N[Not[LessEqual[y, 3.1e+91]], $MachinePrecision], LessEqual[y, 5e+207]]], N[(y * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -450000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-104}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+52} \lor \neg \left(y \leq 3.1 \cdot 10^{+91}\right) \land y \leq 5 \cdot 10^{+207}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -4.5e8 or 3e52 < y < 3.09999999999999998e91 or 4.9999999999999999e207 < y Initial program 100.0%
Taylor expanded in x around inf 59.1%
+-commutative59.1%
distribute-rgt1-in59.1%
mul-1-neg59.1%
cancel-sign-sub-inv59.1%
Simplified59.1%
Taylor expanded in y around inf 59.1%
mul-1-neg59.1%
distribute-rgt-neg-in59.1%
Simplified59.1%
if -4.5e8 < y < 5.8000000000000002e-104Initial program 100.0%
Taylor expanded in y around 0 72.3%
if 5.8000000000000002e-104 < y < 3e52 or 3.09999999999999998e91 < y < 4.9999999999999999e207Initial program 100.0%
Taylor expanded in x around 0 59.4%
Final simplification64.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.054) (not (<= y 6.5e-96))) (* y (- z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.054) || !(y <= 6.5e-96)) {
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 <= (-0.054d0)) .or. (.not. (y <= 6.5d-96))) 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 <= -0.054) || !(y <= 6.5e-96)) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.054) or not (y <= 6.5e-96): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.054) || !(y <= 6.5e-96)) 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 <= -0.054) || ~((y <= 6.5e-96))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.054], N[Not[LessEqual[y, 6.5e-96]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.054 \lor \neg \left(y \leq 6.5 \cdot 10^{-96}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.0539999999999999994 or 6.50000000000000001e-96 < y Initial program 100.0%
Taylor expanded in y around inf 92.5%
if -0.0539999999999999994 < y < 6.50000000000000001e-96Initial program 100.0%
Taylor expanded in y around 0 72.9%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.5e+71) (not (<= z 3.1e-23))) (* y (- z x)) (- x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e+71) || !(z <= 3.1e-23)) {
tmp = y * (z - x);
} 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 ((z <= (-1.5d+71)) .or. (.not. (z <= 3.1d-23))) then
tmp = y * (z - x)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e+71) || !(z <= 3.1e-23)) {
tmp = y * (z - x);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.5e+71) or not (z <= 3.1e-23): tmp = y * (z - x) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.5e+71) || !(z <= 3.1e-23)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.5e+71) || ~((z <= 3.1e-23))) tmp = y * (z - x); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.5e+71], N[Not[LessEqual[z, 3.1e-23]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+71} \lor \neg \left(z \leq 3.1 \cdot 10^{-23}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if z < -1.50000000000000006e71 or 3.0999999999999999e-23 < z Initial program 100.0%
Taylor expanded in y around inf 85.6%
if -1.50000000000000006e71 < z < 3.0999999999999999e-23Initial program 100.0%
Taylor expanded in x around inf 86.3%
+-commutative86.3%
distribute-rgt1-in86.3%
mul-1-neg86.3%
cancel-sign-sub-inv86.3%
Simplified86.3%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (<= y -0.054) (* y z) (if (<= y 6.5e-96) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.054) {
tmp = y * z;
} else if (y <= 6.5e-96) {
tmp = x;
} 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 (y <= (-0.054d0)) then
tmp = y * z
else if (y <= 6.5d-96) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.054) {
tmp = y * z;
} else if (y <= 6.5e-96) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.054: tmp = y * z elif y <= 6.5e-96: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.054) tmp = Float64(y * z); elseif (y <= 6.5e-96) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.054) tmp = y * z; elseif (y <= 6.5e-96) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.054], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.5e-96], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.054:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-96}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -0.0539999999999999994 or 6.50000000000000001e-96 < y Initial program 100.0%
Taylor expanded in x around 0 51.6%
if -0.0539999999999999994 < y < 6.50000000000000001e-96Initial program 100.0%
Taylor expanded in y around 0 72.9%
Final simplification60.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 36.3%
Final simplification36.3%
herbie shell --seed 2023257
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))