
(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 6 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 (- z x) y x))
double code(double x, double y, double z) {
return fma((z - x), y, x);
}
function code(x, y, z) return fma(Float64(z - x), y, x) end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (* x y)))) (if (<= x -1.85e+47) t_0 (if (<= x 0.42) (+ x (* z y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x * y);
double tmp;
if (x <= -1.85e+47) {
tmp = t_0;
} else if (x <= 0.42) {
tmp = x + (z * y);
} 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 - (x * y)
if (x <= (-1.85d+47)) then
tmp = t_0
else if (x <= 0.42d0) then
tmp = x + (z * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - (x * y);
double tmp;
if (x <= -1.85e+47) {
tmp = t_0;
} else if (x <= 0.42) {
tmp = x + (z * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x * y) tmp = 0 if x <= -1.85e+47: tmp = t_0 elif x <= 0.42: tmp = x + (z * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x * y)) tmp = 0.0 if (x <= -1.85e+47) tmp = t_0; elseif (x <= 0.42) tmp = Float64(x + Float64(z * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (x * y); tmp = 0.0; if (x <= -1.85e+47) tmp = t_0; elseif (x <= 0.42) tmp = x + (z * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.85e+47], t$95$0, If[LessEqual[x, 0.42], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - x \cdot y\\
\mathbf{if}\;x \leq -1.85 \cdot 10^{+47}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.42:\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.8500000000000002e47 or 0.419999999999999984 < x Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6493.7
Applied rewrites93.7%
if -1.8500000000000002e47 < x < 0.419999999999999984Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6492.5
Applied rewrites92.5%
Final simplification93.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (* x y)))) (if (<= x -2.8e-67) t_0 (if (<= x 5.6e-139) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x * y);
double tmp;
if (x <= -2.8e-67) {
tmp = t_0;
} else if (x <= 5.6e-139) {
tmp = z * y;
} 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 - (x * y)
if (x <= (-2.8d-67)) then
tmp = t_0
else if (x <= 5.6d-139) then
tmp = z * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - (x * y);
double tmp;
if (x <= -2.8e-67) {
tmp = t_0;
} else if (x <= 5.6e-139) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x * y) tmp = 0 if x <= -2.8e-67: tmp = t_0 elif x <= 5.6e-139: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x * y)) tmp = 0.0 if (x <= -2.8e-67) tmp = t_0; elseif (x <= 5.6e-139) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (x * y); tmp = 0.0; if (x <= -2.8e-67) tmp = t_0; elseif (x <= 5.6e-139) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.8e-67], t$95$0, If[LessEqual[x, 5.6e-139], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - x \cdot y\\
\mathbf{if}\;x \leq -2.8 \cdot 10^{-67}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-139}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.8000000000000001e-67 or 5.5999999999999997e-139 < x Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6484.9
Applied rewrites84.9%
if -2.8000000000000001e-67 < x < 5.5999999999999997e-139Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6482.4
Applied rewrites82.4%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y)))) (if (<= x -1.85e+47) t_0 (if (<= x 0.39) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -1.85e+47) {
tmp = t_0;
} else if (x <= 0.39) {
tmp = z * y;
} 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 (x <= (-1.85d+47)) then
tmp = t_0
else if (x <= 0.39d0) then
tmp = z * y
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 (x <= -1.85e+47) {
tmp = t_0;
} else if (x <= 0.39) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if x <= -1.85e+47: tmp = t_0 elif x <= 0.39: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (x <= -1.85e+47) tmp = t_0; elseif (x <= 0.39) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (x <= -1.85e+47) tmp = t_0; elseif (x <= 0.39) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[x, -1.85e+47], t$95$0, If[LessEqual[x, 0.39], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;x \leq -1.85 \cdot 10^{+47}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.39:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.8500000000000002e47 or 0.39000000000000001 < x Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6493.7
Applied rewrites93.7%
Taylor expanded in y around inf
Applied rewrites45.2%
if -1.8500000000000002e47 < x < 0.39000000000000001Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6468.6
Applied rewrites68.6%
Final simplification57.2%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6442.3
Applied rewrites42.3%
Final simplification42.3%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6463.2
Applied rewrites63.2%
Taylor expanded in y around inf
Applied rewrites28.0%
Applied rewrites4.0%
Final simplification4.0%
herbie shell --seed 2024219
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))