
(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%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -3.6e+127)
(* y z)
(if (<= y -26000000.0)
t_0
(if (<= y -3.6e-7) (* y z) (if (<= y 210.0) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.6e+127) {
tmp = y * z;
} else if (y <= -26000000.0) {
tmp = t_0;
} else if (y <= -3.6e-7) {
tmp = y * z;
} else if (y <= 210.0) {
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 = y * -x
if (y <= (-3.6d+127)) then
tmp = y * z
else if (y <= (-26000000.0d0)) then
tmp = t_0
else if (y <= (-3.6d-7)) then
tmp = y * z
else if (y <= 210.0d0) 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 = y * -x;
double tmp;
if (y <= -3.6e+127) {
tmp = y * z;
} else if (y <= -26000000.0) {
tmp = t_0;
} else if (y <= -3.6e-7) {
tmp = y * z;
} else if (y <= 210.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3.6e+127: tmp = y * z elif y <= -26000000.0: tmp = t_0 elif y <= -3.6e-7: tmp = y * z elif y <= 210.0: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -3.6e+127) tmp = Float64(y * z); elseif (y <= -26000000.0) tmp = t_0; elseif (y <= -3.6e-7) tmp = Float64(y * z); elseif (y <= 210.0) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -3.6e+127) tmp = y * z; elseif (y <= -26000000.0) tmp = t_0; elseif (y <= -3.6e-7) tmp = y * z; elseif (y <= 210.0) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -3.6e+127], N[(y * z), $MachinePrecision], If[LessEqual[y, -26000000.0], t$95$0, If[LessEqual[y, -3.6e-7], N[(y * z), $MachinePrecision], If[LessEqual[y, 210.0], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+127}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -26000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 210:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.59999999999999979e127 or -2.6e7 < y < -3.59999999999999994e-7Initial program 100.0%
Taylor expanded in z around inf 69.4%
Taylor expanded in x around 0 69.0%
if -3.59999999999999979e127 < y < -2.6e7 or 210 < y Initial program 100.0%
Taylor expanded in x around inf 62.7%
mul-1-neg62.7%
unsub-neg62.7%
Simplified62.7%
Taylor expanded in y around inf 61.8%
neg-mul-161.8%
distribute-lft-neg-in61.8%
Simplified61.8%
if -3.59999999999999994e-7 < y < 210Initial program 100.0%
Taylor expanded in y around 0 72.6%
Final simplification68.7%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.12e-7)
(not (or (<= y 9e-148) (and (not (<= y 4e-138)) (<= y 6.6e-12)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.12e-7) || !((y <= 9e-148) || (!(y <= 4e-138) && (y <= 6.6e-12)))) {
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.12d-7)) .or. (.not. (y <= 9d-148) .or. (.not. (y <= 4d-138)) .and. (y <= 6.6d-12))) 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.12e-7) || !((y <= 9e-148) || (!(y <= 4e-138) && (y <= 6.6e-12)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.12e-7) or not ((y <= 9e-148) or (not (y <= 4e-138) and (y <= 6.6e-12))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.12e-7) || !((y <= 9e-148) || (!(y <= 4e-138) && (y <= 6.6e-12)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.12e-7) || ~(((y <= 9e-148) || (~((y <= 4e-138)) && (y <= 6.6e-12))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.12e-7], N[Not[Or[LessEqual[y, 9e-148], And[N[Not[LessEqual[y, 4e-138]], $MachinePrecision], LessEqual[y, 6.6e-12]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.12 \cdot 10^{-7} \lor \neg \left(y \leq 9 \cdot 10^{-148} \lor \neg \left(y \leq 4 \cdot 10^{-138}\right) \land y \leq 6.6 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.12e-7 or 9.00000000000000029e-148 < y < 4.00000000000000027e-138 or 6.6000000000000001e-12 < y Initial program 100.0%
Taylor expanded in z around inf 55.1%
Taylor expanded in x around 0 54.4%
if -1.12e-7 < y < 9.00000000000000029e-148 or 4.00000000000000027e-138 < y < 6.6000000000000001e-12Initial program 100.0%
Taylor expanded in y around 0 77.4%
Final simplification65.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e+61) (not (<= x 2.2e+21))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+61) || !(x <= 2.2e+21)) {
tmp = x * (1.0 - 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 <= (-2.8d+61)) .or. (.not. (x <= 2.2d+21))) then
tmp = x * (1.0d0 - 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 <= -2.8e+61) || !(x <= 2.2e+21)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e+61) or not (x <= 2.2e+21): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e+61) || !(x <= 2.2e+21)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.8e+61) || ~((x <= 2.2e+21))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e+61], N[Not[LessEqual[x, 2.2e+21]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+61} \lor \neg \left(x \leq 2.2 \cdot 10^{+21}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.8000000000000001e61 or 2.2e21 < x Initial program 100.0%
Taylor expanded in x around inf 91.2%
mul-1-neg91.2%
unsub-neg91.2%
Simplified91.2%
if -2.8000000000000001e61 < x < 2.2e21Initial program 100.0%
Taylor expanded in z around inf 88.8%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.3e+130) (not (<= z 3.8e+25))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e+130) || !(z <= 3.8e+25)) {
tmp = y * z;
} 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 ((z <= (-3.3d+130)) .or. (.not. (z <= 3.8d+25))) then
tmp = y * z
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 ((z <= -3.3e+130) || !(z <= 3.8e+25)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.3e+130) or not (z <= 3.8e+25): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.3e+130) || !(z <= 3.8e+25)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.3e+130) || ~((z <= 3.8e+25))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.3e+130], N[Not[LessEqual[z, 3.8e+25]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+130} \lor \neg \left(z \leq 3.8 \cdot 10^{+25}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -3.3e130 or 3.8e25 < z Initial program 100.0%
Taylor expanded in z around inf 90.2%
Taylor expanded in x around 0 71.9%
if -3.3e130 < z < 3.8e25Initial program 100.0%
Taylor expanded in x around inf 81.9%
mul-1-neg81.9%
unsub-neg81.9%
Simplified81.9%
Final simplification78.1%
(FPCore (x y z) :precision binary64 (if (<= x -2.6e+61) (* x (- 1.0 y)) (if (<= x 4.9e+16) (+ x (* y z)) (- x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e+61) {
tmp = x * (1.0 - y);
} else if (x <= 4.9e+16) {
tmp = x + (y * z);
} 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 (x <= (-2.6d+61)) then
tmp = x * (1.0d0 - y)
else if (x <= 4.9d+16) then
tmp = x + (y * z)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e+61) {
tmp = x * (1.0 - y);
} else if (x <= 4.9e+16) {
tmp = x + (y * z);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.6e+61: tmp = x * (1.0 - y) elif x <= 4.9e+16: tmp = x + (y * z) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.6e+61) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 4.9e+16) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.6e+61) tmp = x * (1.0 - y); elseif (x <= 4.9e+16) tmp = x + (y * z); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.6e+61], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.9e+16], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+61}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{+16}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if x < -2.59999999999999973e61Initial program 100.0%
Taylor expanded in x around inf 92.9%
mul-1-neg92.9%
unsub-neg92.9%
Simplified92.9%
if -2.59999999999999973e61 < x < 4.9e16Initial program 100.0%
Taylor expanded in z around inf 88.8%
if 4.9e16 < x Initial program 100.0%
Taylor expanded in x around inf 89.8%
mul-1-neg89.8%
unsub-neg89.8%
Simplified89.8%
sub-neg89.8%
distribute-rgt-in89.9%
*-un-lft-identity89.9%
distribute-lft-neg-in89.9%
unsub-neg89.9%
*-commutative89.9%
Applied egg-rr89.9%
Final simplification90.0%
(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%
(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.1%
herbie shell --seed 2024110
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))