
(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 -9.5e+105)
t_0
(if (<= y -2.8e-96)
(* y z)
(if (<= y 7.8e-70)
x
(if (<= y 7.2e+36)
(* y z)
(if (or (<= y 2.05e+90) (and (not (<= y 5e+119)) (<= y 3e+226)))
t_0
(* y z))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -9.5e+105) {
tmp = t_0;
} else if (y <= -2.8e-96) {
tmp = y * z;
} else if (y <= 7.8e-70) {
tmp = x;
} else if (y <= 7.2e+36) {
tmp = y * z;
} else if ((y <= 2.05e+90) || (!(y <= 5e+119) && (y <= 3e+226))) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-9.5d+105)) then
tmp = t_0
else if (y <= (-2.8d-96)) then
tmp = y * z
else if (y <= 7.8d-70) then
tmp = x
else if (y <= 7.2d+36) then
tmp = y * z
else if ((y <= 2.05d+90) .or. (.not. (y <= 5d+119)) .and. (y <= 3d+226)) then
tmp = t_0
else
tmp = y * z
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 <= -9.5e+105) {
tmp = t_0;
} else if (y <= -2.8e-96) {
tmp = y * z;
} else if (y <= 7.8e-70) {
tmp = x;
} else if (y <= 7.2e+36) {
tmp = y * z;
} else if ((y <= 2.05e+90) || (!(y <= 5e+119) && (y <= 3e+226))) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -9.5e+105: tmp = t_0 elif y <= -2.8e-96: tmp = y * z elif y <= 7.8e-70: tmp = x elif y <= 7.2e+36: tmp = y * z elif (y <= 2.05e+90) or (not (y <= 5e+119) and (y <= 3e+226)): tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -9.5e+105) tmp = t_0; elseif (y <= -2.8e-96) tmp = Float64(y * z); elseif (y <= 7.8e-70) tmp = x; elseif (y <= 7.2e+36) tmp = Float64(y * z); elseif ((y <= 2.05e+90) || (!(y <= 5e+119) && (y <= 3e+226))) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -9.5e+105) tmp = t_0; elseif (y <= -2.8e-96) tmp = y * z; elseif (y <= 7.8e-70) tmp = x; elseif (y <= 7.2e+36) tmp = y * z; elseif ((y <= 2.05e+90) || (~((y <= 5e+119)) && (y <= 3e+226))) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -9.5e+105], t$95$0, If[LessEqual[y, -2.8e-96], N[(y * z), $MachinePrecision], If[LessEqual[y, 7.8e-70], x, If[LessEqual[y, 7.2e+36], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, 2.05e+90], And[N[Not[LessEqual[y, 5e+119]], $MachinePrecision], LessEqual[y, 3e+226]]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{+105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.8 \cdot 10^{-96}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-70}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+36}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+90} \lor \neg \left(y \leq 5 \cdot 10^{+119}\right) \land y \leq 3 \cdot 10^{+226}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -9.4999999999999995e105 or 7.1999999999999995e36 < y < 2.05000000000000021e90 or 4.9999999999999999e119 < y < 2.99999999999999975e226Initial program 100.0%
Taylor expanded in x around 0 98.7%
fma-def100.0%
+-commutative100.0%
metadata-eval100.0%
distribute-lft-in100.0%
metadata-eval100.0%
sub-neg100.0%
associate-*r*100.0%
mul-1-neg100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around -inf 100.0%
associate-*r*100.0%
mul-1-neg100.0%
+-commutative100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 72.1%
mul-1-neg72.1%
distribute-rgt-neg-in72.1%
Simplified72.1%
if -9.4999999999999995e105 < y < -2.80000000000000015e-96 or 7.80000000000000038e-70 < y < 7.1999999999999995e36 or 2.05000000000000021e90 < y < 4.9999999999999999e119 or 2.99999999999999975e226 < y Initial program 100.0%
Taylor expanded in z around inf 81.7%
Taylor expanded in x around 0 68.9%
if -2.80000000000000015e-96 < y < 7.80000000000000038e-70Initial program 100.0%
Taylor expanded in y around 0 74.3%
Final simplification72.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.65e-96) (not (<= y 1.9e-19))) (* y (- z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.65e-96) || !(y <= 1.9e-19)) {
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 <= (-2.65d-96)) .or. (.not. (y <= 1.9d-19))) 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 <= -2.65e-96) || !(y <= 1.9e-19)) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.65e-96) or not (y <= 1.9e-19): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.65e-96) || !(y <= 1.9e-19)) 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 <= -2.65e-96) || ~((y <= 1.9e-19))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.65e-96], N[Not[LessEqual[y, 1.9e-19]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{-96} \lor \neg \left(y \leq 1.9 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.6500000000000001e-96 or 1.9e-19 < y Initial program 100.0%
Taylor expanded in x around 0 98.0%
fma-def99.3%
+-commutative99.3%
metadata-eval99.3%
distribute-lft-in99.3%
metadata-eval99.3%
sub-neg99.3%
associate-*r*99.3%
mul-1-neg99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
distribute-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in y around -inf 94.7%
associate-*r*94.7%
mul-1-neg94.7%
+-commutative94.7%
mul-1-neg94.7%
sub-neg94.7%
Simplified94.7%
Taylor expanded in x around 0 92.6%
mul-1-neg92.6%
distribute-rgt-neg-in92.6%
distribute-lft-in94.7%
sub-neg94.7%
Simplified94.7%
if -2.6500000000000001e-96 < y < 1.9e-19Initial program 100.0%
Taylor expanded in y around 0 72.6%
Final simplification85.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 2.3e-19))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 2.3e-19)) {
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 <= 2.3d-19))) 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 <= 2.3e-19)) {
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 <= 2.3e-19): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 2.3e-19)) 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 <= 2.3e-19))) 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, 2.3e-19]], $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 2.3 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 2.2999999999999998e-19 < y Initial program 100.0%
Taylor expanded in x around 0 97.6%
fma-def99.2%
+-commutative99.2%
metadata-eval99.2%
distribute-lft-in99.2%
metadata-eval99.2%
sub-neg99.2%
associate-*r*99.2%
mul-1-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
distribute-neg-in99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in y around -inf 99.5%
associate-*r*99.5%
mul-1-neg99.5%
+-commutative99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
Taylor expanded in x around 0 97.1%
mul-1-neg97.1%
distribute-rgt-neg-in97.1%
distribute-lft-in99.5%
sub-neg99.5%
Simplified99.5%
if -1 < y < 2.2999999999999998e-19Initial program 100.0%
Taylor expanded in z around inf 98.6%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.65e-96) (* y z) (if (<= y 4.7e-70) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-96) {
tmp = y * z;
} else if (y <= 4.7e-70) {
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 <= (-1.65d-96)) then
tmp = y * z
else if (y <= 4.7d-70) 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 <= -1.65e-96) {
tmp = y * z;
} else if (y <= 4.7e-70) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e-96: tmp = y * z elif y <= 4.7e-70: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e-96) tmp = Float64(y * z); elseif (y <= 4.7e-70) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.65e-96) tmp = y * z; elseif (y <= 4.7e-70) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e-96], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.7e-70], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-96}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{-70}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.64999999999999995e-96 or 4.6999999999999998e-70 < y Initial program 100.0%
Taylor expanded in z around inf 58.1%
Taylor expanded in x around 0 51.5%
if -1.64999999999999995e-96 < y < 4.6999999999999998e-70Initial program 100.0%
Taylor expanded in y around 0 74.3%
Final simplification60.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 34.9%
Final simplification34.9%
herbie shell --seed 2023194
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))