
(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 (* x (- y))))
(if (<= y -2700000000.0)
t_0
(if (<= y -6e-143) (* y z) (if (<= y 3.6) x t_0)))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -2700000000.0) {
tmp = t_0;
} else if (y <= -6e-143) {
tmp = y * z;
} else if (y <= 3.6) {
tmp = x;
} 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 = x * -y
if (y <= (-2700000000.0d0)) then
tmp = t_0
else if (y <= (-6d-143)) then
tmp = y * z
else if (y <= 3.6d0) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -2700000000.0) {
tmp = t_0;
} else if (y <= -6e-143) {
tmp = y * z;
} else if (y <= 3.6) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if y <= -2700000000.0: tmp = t_0 elif y <= -6e-143: tmp = y * z elif y <= 3.6: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -2700000000.0) tmp = t_0; elseif (y <= -6e-143) tmp = Float64(y * z); elseif (y <= 3.6) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (y <= -2700000000.0) tmp = t_0; elseif (y <= -6e-143) tmp = y * z; elseif (y <= 3.6) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -2700000000.0], t$95$0, If[LessEqual[y, -6e-143], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.6], x, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -2700000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -6 \cdot 10^{-143}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.6:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.7e9 or 3.60000000000000009 < y Initial program 100.0%
Taylor expanded in z around 0 58.8%
mul-1-neg58.8%
distribute-rgt-neg-out58.8%
Simplified58.8%
Taylor expanded in y around inf 57.0%
associate-*r*57.0%
neg-mul-157.0%
Simplified57.0%
if -2.7e9 < y < -5.9999999999999997e-143Initial program 99.9%
Taylor expanded in z around inf 96.9%
Taylor expanded in x around 0 58.0%
if -5.9999999999999997e-143 < y < 3.60000000000000009Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 80.1%
Final simplification65.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e-31) (not (<= x 1.8e+66))) (- x (* y x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-31) || !(x <= 1.8e+66)) {
tmp = x - (y * 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 ((x <= (-6.2d-31)) .or. (.not. (x <= 1.8d+66))) then
tmp = x - (y * 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 ((x <= -6.2e-31) || !(x <= 1.8e+66)) {
tmp = x - (y * x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e-31) or not (x <= 1.8e+66): tmp = x - (y * x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-31) || !(x <= 1.8e+66)) tmp = Float64(x - Float64(y * x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.2e-31) || ~((x <= 1.8e+66))) tmp = x - (y * x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-31], N[Not[LessEqual[x, 1.8e+66]], $MachinePrecision]], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-31} \lor \neg \left(x \leq 1.8 \cdot 10^{+66}\right):\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -6.19999999999999999e-31 or 1.8e66 < x Initial program 100.0%
Taylor expanded in z around 0 91.3%
mul-1-neg91.3%
distribute-rgt-neg-out91.3%
Simplified91.3%
Taylor expanded in x around 0 91.3%
neg-mul-191.3%
+-commutative91.3%
distribute-rgt1-in91.3%
cancel-sign-sub-inv91.3%
Simplified91.3%
if -6.19999999999999999e-31 < x < 1.8e66Initial program 100.0%
Taylor expanded in z around inf 85.5%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (<= y -6e-143) (* y z) (if (<= y 6.8e-27) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6e-143) {
tmp = y * z;
} else if (y <= 6.8e-27) {
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 <= (-6d-143)) then
tmp = y * z
else if (y <= 6.8d-27) 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 <= -6e-143) {
tmp = y * z;
} else if (y <= 6.8e-27) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6e-143: tmp = y * z elif y <= 6.8e-27: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6e-143) tmp = Float64(y * z); elseif (y <= 6.8e-27) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6e-143) tmp = y * z; elseif (y <= 6.8e-27) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6e-143], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.8e-27], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-143}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-27}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -5.9999999999999997e-143 or 6.7999999999999994e-27 < y Initial program 100.0%
Taylor expanded in z around inf 55.7%
Taylor expanded in x around 0 47.9%
if -5.9999999999999997e-143 < y < 6.7999999999999994e-27Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 85.0%
Final simplification59.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.95e+148) (* x (- y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+148) {
tmp = x * -y;
} 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 (x <= (-1.95d+148)) then
tmp = x * -y
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+148) {
tmp = x * -y;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.95e+148: tmp = x * -y else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.95e+148) tmp = Float64(x * Float64(-y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.95e+148) tmp = x * -y; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.95e+148], N[(x * (-y)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+148}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.95000000000000001e148Initial program 100.0%
Taylor expanded in z around 0 96.9%
mul-1-neg96.9%
distribute-rgt-neg-out96.9%
Simplified96.9%
Taylor expanded in y around inf 75.3%
associate-*r*75.3%
neg-mul-175.3%
Simplified75.3%
if -1.95000000000000001e148 < x Initial program 100.0%
Taylor expanded in z around inf 75.7%
Final simplification75.6%
(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%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 33.5%
Final simplification33.5%
herbie shell --seed 2023207
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))