
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma x (+ y z) (- z)))
double code(double x, double y, double z) {
return fma(x, (y + z), -z);
}
function code(x, y, z) return fma(x, Float64(y + z), Float64(-z)) end
code[x_, y_, z_] := N[(x * N[(y + z), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + z, -z\right)
\end{array}
Initial program 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
associate-+r+97.6%
distribute-lft-out100.0%
fma-def100.0%
metadata-eval100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.0)
(* x z)
(if (<= x 1.65e-38)
(- z)
(if (or (<= x 7e+46) (and (not (<= x 3.05e+165)) (<= x 1.75e+239)))
(* x y)
(* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= 1.65e-38) {
tmp = -z;
} else if ((x <= 7e+46) || (!(x <= 3.05e+165) && (x <= 1.75e+239))) {
tmp = x * y;
} else {
tmp = x * 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.0d0)) then
tmp = x * z
else if (x <= 1.65d-38) then
tmp = -z
else if ((x <= 7d+46) .or. (.not. (x <= 3.05d+165)) .and. (x <= 1.75d+239)) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= 1.65e-38) {
tmp = -z;
} else if ((x <= 7e+46) || (!(x <= 3.05e+165) && (x <= 1.75e+239))) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = x * z elif x <= 1.65e-38: tmp = -z elif (x <= 7e+46) or (not (x <= 3.05e+165) and (x <= 1.75e+239)): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * z); elseif (x <= 1.65e-38) tmp = Float64(-z); elseif ((x <= 7e+46) || (!(x <= 3.05e+165) && (x <= 1.75e+239))) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.0) tmp = x * z; elseif (x <= 1.65e-38) tmp = -z; elseif ((x <= 7e+46) || (~((x <= 3.05e+165)) && (x <= 1.75e+239))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.65e-38], (-z), If[Or[LessEqual[x, 7e+46], And[N[Not[LessEqual[x, 3.05e+165]], $MachinePrecision], LessEqual[x, 1.75e+239]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{-38}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+46} \lor \neg \left(x \leq 3.05 \cdot 10^{+165}\right) \land x \leq 1.75 \cdot 10^{+239}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1 or 6.9999999999999997e46 < x < 3.04999999999999983e165 or 1.7500000000000001e239 < x Initial program 94.0%
Taylor expanded in x around inf 99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in z around inf 61.5%
if -1 < x < 1.6500000000000001e-38Initial program 100.0%
Taylor expanded in x around 0 72.7%
mul-1-neg72.7%
Simplified72.7%
if 1.6500000000000001e-38 < x < 6.9999999999999997e46 or 3.04999999999999983e165 < x < 1.7500000000000001e239Initial program 100.0%
Taylor expanded in y around inf 61.9%
Final simplification66.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.31) (not (<= x 7.5e-38))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.31) || !(x <= 7.5e-38)) {
tmp = x * (y + z);
} else {
tmp = -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 <= (-0.31d0)) .or. (.not. (x <= 7.5d-38))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.31) || !(x <= 7.5e-38)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.31) or not (x <= 7.5e-38): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.31) || !(x <= 7.5e-38)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.31) || ~((x <= 7.5e-38))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.31], N[Not[LessEqual[x, 7.5e-38]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.31 \lor \neg \left(x \leq 7.5 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -0.309999999999999998 or 7.5e-38 < x Initial program 95.7%
Taylor expanded in x around inf 95.0%
+-commutative95.0%
Simplified95.0%
if -0.309999999999999998 < x < 7.5e-38Initial program 100.0%
Taylor expanded in x around 0 72.7%
mul-1-neg72.7%
Simplified72.7%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e+15) (not (<= x 7.5e-38))) (* x (+ y z)) (* z (- x 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+15) || !(x <= 7.5e-38)) {
tmp = x * (y + z);
} else {
tmp = z * (x - 1.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) :: tmp
if ((x <= (-1.9d+15)) .or. (.not. (x <= 7.5d-38))) then
tmp = x * (y + z)
else
tmp = z * (x - 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+15) || !(x <= 7.5e-38)) {
tmp = x * (y + z);
} else {
tmp = z * (x - 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e+15) or not (x <= 7.5e-38): tmp = x * (y + z) else: tmp = z * (x - 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e+15) || !(x <= 7.5e-38)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x - 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.9e+15) || ~((x <= 7.5e-38))) tmp = x * (y + z); else tmp = z * (x - 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e+15], N[Not[LessEqual[x, 7.5e-38]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+15} \lor \neg \left(x \leq 7.5 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x - 1\right)\\
\end{array}
\end{array}
if x < -1.9e15 or 7.5e-38 < x Initial program 95.6%
Taylor expanded in x around inf 95.3%
+-commutative95.3%
Simplified95.3%
if -1.9e15 < x < 7.5e-38Initial program 100.0%
Taylor expanded in y around 0 74.5%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e+15) (not (<= x 4.1e-38))) (* x (+ y z)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+15) || !(x <= 4.1e-38)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - 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.9d+15)) .or. (.not. (x <= 4.1d-38))) then
tmp = x * (y + z)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+15) || !(x <= 4.1e-38)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e+15) or not (x <= 4.1e-38): tmp = x * (y + z) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e+15) || !(x <= 4.1e-38)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.9e+15) || ~((x <= 4.1e-38))) tmp = x * (y + z); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e+15], N[Not[LessEqual[x, 4.1e-38]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+15} \lor \neg \left(x \leq 4.1 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -1.9e15 or 4.0999999999999998e-38 < x Initial program 95.6%
Taylor expanded in x around inf 95.3%
+-commutative95.3%
Simplified95.3%
if -1.9e15 < x < 4.0999999999999998e-38Initial program 100.0%
Taylor expanded in y around 0 74.5%
sub-neg74.5%
metadata-eval74.5%
*-commutative74.5%
distribute-rgt-in74.5%
mul-1-neg74.5%
sub-neg74.5%
*-commutative74.5%
Simplified74.5%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e+15) (* x y) (if (<= x 5.5e-38) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+15) {
tmp = x * y;
} else if (x <= 5.5e-38) {
tmp = -z;
} else {
tmp = x * 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 (x <= (-1.9d+15)) then
tmp = x * y
else if (x <= 5.5d-38) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+15) {
tmp = x * y;
} else if (x <= 5.5e-38) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e+15: tmp = x * y elif x <= 5.5e-38: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e+15) tmp = Float64(x * y); elseif (x <= 5.5e-38) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e+15) tmp = x * y; elseif (x <= 5.5e-38) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e+15], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.5e-38], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+15}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-38}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.9e15 or 5.50000000000000005e-38 < x Initial program 95.6%
Taylor expanded in y around inf 48.2%
if -1.9e15 < x < 5.50000000000000005e-38Initial program 100.0%
Taylor expanded in x around 0 71.6%
mul-1-neg71.6%
Simplified71.6%
Final simplification59.0%
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
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)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
associate-+r+97.6%
metadata-eval97.6%
mul-1-neg97.6%
unsub-neg97.6%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 97.6%
Taylor expanded in x around 0 35.8%
mul-1-neg35.8%
Simplified35.8%
Final simplification35.8%
herbie shell --seed 2023176
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))