
(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 -1.6e+255)
t_0
(if (<= y -2.1e+105)
(* y z)
(if (<= y -7.5e+37)
t_0
(if (<= y -1.75e-59)
(* y z)
(if (<= y 2.35e-8)
x
(if (or (<= y 1.05e+21)
(and (not (<= y 4.8e+96)) (<= y 6.2e+168)))
(* y z)
t_0))))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -1.6e+255) {
tmp = t_0;
} else if (y <= -2.1e+105) {
tmp = y * z;
} else if (y <= -7.5e+37) {
tmp = t_0;
} else if (y <= -1.75e-59) {
tmp = y * z;
} else if (y <= 2.35e-8) {
tmp = x;
} else if ((y <= 1.05e+21) || (!(y <= 4.8e+96) && (y <= 6.2e+168))) {
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 = x * -y
if (y <= (-1.6d+255)) then
tmp = t_0
else if (y <= (-2.1d+105)) then
tmp = y * z
else if (y <= (-7.5d+37)) then
tmp = t_0
else if (y <= (-1.75d-59)) then
tmp = y * z
else if (y <= 2.35d-8) then
tmp = x
else if ((y <= 1.05d+21) .or. (.not. (y <= 4.8d+96)) .and. (y <= 6.2d+168)) 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 = x * -y;
double tmp;
if (y <= -1.6e+255) {
tmp = t_0;
} else if (y <= -2.1e+105) {
tmp = y * z;
} else if (y <= -7.5e+37) {
tmp = t_0;
} else if (y <= -1.75e-59) {
tmp = y * z;
} else if (y <= 2.35e-8) {
tmp = x;
} else if ((y <= 1.05e+21) || (!(y <= 4.8e+96) && (y <= 6.2e+168))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if y <= -1.6e+255: tmp = t_0 elif y <= -2.1e+105: tmp = y * z elif y <= -7.5e+37: tmp = t_0 elif y <= -1.75e-59: tmp = y * z elif y <= 2.35e-8: tmp = x elif (y <= 1.05e+21) or (not (y <= 4.8e+96) and (y <= 6.2e+168)): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -1.6e+255) tmp = t_0; elseif (y <= -2.1e+105) tmp = Float64(y * z); elseif (y <= -7.5e+37) tmp = t_0; elseif (y <= -1.75e-59) tmp = Float64(y * z); elseif (y <= 2.35e-8) tmp = x; elseif ((y <= 1.05e+21) || (!(y <= 4.8e+96) && (y <= 6.2e+168))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (y <= -1.6e+255) tmp = t_0; elseif (y <= -2.1e+105) tmp = y * z; elseif (y <= -7.5e+37) tmp = t_0; elseif (y <= -1.75e-59) tmp = y * z; elseif (y <= 2.35e-8) tmp = x; elseif ((y <= 1.05e+21) || (~((y <= 4.8e+96)) && (y <= 6.2e+168))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -1.6e+255], t$95$0, If[LessEqual[y, -2.1e+105], N[(y * z), $MachinePrecision], If[LessEqual[y, -7.5e+37], t$95$0, If[LessEqual[y, -1.75e-59], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.35e-8], x, If[Or[LessEqual[y, 1.05e+21], And[N[Not[LessEqual[y, 4.8e+96]], $MachinePrecision], LessEqual[y, 6.2e+168]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -1.6 \cdot 10^{+255}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.1 \cdot 10^{+105}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -7.5 \cdot 10^{+37}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.75 \cdot 10^{-59}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+21} \lor \neg \left(y \leq 4.8 \cdot 10^{+96}\right) \land y \leq 6.2 \cdot 10^{+168}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.5999999999999999e255 or -2.1000000000000001e105 < y < -7.5000000000000003e37 or 1.05e21 < y < 4.79999999999999986e96 or 6.19999999999999993e168 < y Initial program 100.0%
Taylor expanded in x around inf 70.3%
+-commutative70.3%
distribute-rgt1-in70.3%
mul-1-neg70.3%
cancel-sign-sub-inv70.3%
Simplified70.3%
Taylor expanded in y around inf 70.3%
associate-*r*70.3%
mul-1-neg70.3%
Simplified70.3%
if -1.5999999999999999e255 < y < -2.1000000000000001e105 or -7.5000000000000003e37 < y < -1.75e-59 or 2.3499999999999999e-8 < y < 1.05e21 or 4.79999999999999986e96 < y < 6.19999999999999993e168Initial program 100.0%
Taylor expanded in x around 0 72.6%
if -1.75e-59 < y < 2.3499999999999999e-8Initial program 100.0%
Taylor expanded in y around 0 76.0%
Final simplification73.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e-62) (not (<= y 6.5e-8))) (* y (- z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-62) || !(y <= 6.5e-8)) {
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 <= (-3.4d-62)) .or. (.not. (y <= 6.5d-8))) 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 <= -3.4e-62) || !(y <= 6.5e-8)) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e-62) or not (y <= 6.5e-8): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-62) || !(y <= 6.5e-8)) 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 <= -3.4e-62) || ~((y <= 6.5e-8))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e-62], N[Not[LessEqual[y, 6.5e-8]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-62} \lor \neg \left(y \leq 6.5 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.39999999999999988e-62 or 6.49999999999999997e-8 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
if -3.39999999999999988e-62 < y < 6.49999999999999997e-8Initial program 100.0%
Taylor expanded in y around 0 76.0%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e-60) (not (<= y 0.00145))) (* y (- z x)) (- x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e-60) || !(y <= 0.00145)) {
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 ((y <= (-4.4d-60)) .or. (.not. (y <= 0.00145d0))) 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 ((y <= -4.4e-60) || !(y <= 0.00145)) {
tmp = y * (z - x);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.4e-60) or not (y <= 0.00145): tmp = y * (z - x) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e-60) || !(y <= 0.00145)) 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 ((y <= -4.4e-60) || ~((y <= 0.00145))) tmp = y * (z - x); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e-60], N[Not[LessEqual[y, 0.00145]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-60} \lor \neg \left(y \leq 0.00145\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if y < -4.3999999999999998e-60 or 0.00145 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
if -4.3999999999999998e-60 < y < 0.00145Initial program 100.0%
Taylor expanded in x around inf 76.5%
+-commutative76.5%
distribute-rgt1-in76.5%
mul-1-neg76.5%
cancel-sign-sub-inv76.5%
Simplified76.5%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= y -3.7e-62) (* y z) (if (<= y 1.7e-8) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e-62) {
tmp = y * z;
} else if (y <= 1.7e-8) {
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 <= (-3.7d-62)) then
tmp = y * z
else if (y <= 1.7d-8) 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 <= -3.7e-62) {
tmp = y * z;
} else if (y <= 1.7e-8) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.7e-62: tmp = y * z elif y <= 1.7e-8: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.7e-62) tmp = Float64(y * z); elseif (y <= 1.7e-8) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.7e-62) tmp = y * z; elseif (y <= 1.7e-8) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.7e-62], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.7e-8], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-62}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -3.6999999999999998e-62 or 1.7e-8 < y Initial program 100.0%
Taylor expanded in x around 0 52.8%
if -3.6999999999999998e-62 < y < 1.7e-8Initial program 100.0%
Taylor expanded in y around 0 76.0%
Final simplification63.5%
(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 37.6%
Final simplification37.6%
herbie shell --seed 2023279
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))