
(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 7 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 (let* ((t_0 (+ (* x y) (* (+ x -1.0) z)))) (if (<= t_0 INFINITY) t_0 (* x (+ y z)))))
double code(double x, double y, double z) {
double t_0 = (x * y) + ((x + -1.0) * z);
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = x * (y + z);
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (x * y) + ((x + -1.0) * z);
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = x * (y + z);
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) + ((x + -1.0) * z) tmp = 0 if t_0 <= math.inf: tmp = t_0 else: tmp = x * (y + z) return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) + Float64(Float64(x + -1.0) * z)) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64(x * Float64(y + z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) + ((x + -1.0) * z); tmp = 0.0; if (t_0 <= Inf) tmp = t_0; else tmp = x * (y + z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] + N[(N[(x + -1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot y + \left(x + -1\right) \cdot z\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + z\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 (-.f64 x #s(literal 1 binary64)) z)) < +inf.0Initial program 100.0%
if +inf.0 < (+.f64 (*.f64 x y) (*.f64 (-.f64 x #s(literal 1 binary64)) z)) Initial program 0.0%
Taylor expanded in x around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -3.6e+28)
(* x z)
(if (<= x -2.7e-24)
(* x y)
(if (<= x 1.7e-80) (- z) (if (<= x 3.3e+119) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e+28) {
tmp = x * z;
} else if (x <= -2.7e-24) {
tmp = x * y;
} else if (x <= 1.7e-80) {
tmp = -z;
} else if (x <= 3.3e+119) {
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 <= (-3.6d+28)) then
tmp = x * z
else if (x <= (-2.7d-24)) then
tmp = x * y
else if (x <= 1.7d-80) then
tmp = -z
else if (x <= 3.3d+119) 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 <= -3.6e+28) {
tmp = x * z;
} else if (x <= -2.7e-24) {
tmp = x * y;
} else if (x <= 1.7e-80) {
tmp = -z;
} else if (x <= 3.3e+119) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.6e+28: tmp = x * z elif x <= -2.7e-24: tmp = x * y elif x <= 1.7e-80: tmp = -z elif x <= 3.3e+119: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.6e+28) tmp = Float64(x * z); elseif (x <= -2.7e-24) tmp = Float64(x * y); elseif (x <= 1.7e-80) tmp = Float64(-z); elseif (x <= 3.3e+119) 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 <= -3.6e+28) tmp = x * z; elseif (x <= -2.7e-24) tmp = x * y; elseif (x <= 1.7e-80) tmp = -z; elseif (x <= 3.3e+119) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.6e+28], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.7e-24], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.7e-80], (-z), If[LessEqual[x, 3.3e+119], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+28}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.7 \cdot 10^{-24}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-80}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{+119}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -3.5999999999999999e28 or 3.3000000000000002e119 < x Initial program 92.5%
Taylor expanded in y around 0
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6462.4
Applied rewrites62.4%
Taylor expanded in x around inf
Applied rewrites62.4%
if -3.5999999999999999e28 < x < -2.70000000000000007e-24 or 1.7e-80 < x < 3.3000000000000002e119Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6463.6
Applied rewrites63.6%
if -2.70000000000000007e-24 < x < 1.7e-80Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6476.2
Applied rewrites76.2%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -92.0) t_0 (if (<= x 0.055) (+ (* x y) (- z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -92.0) {
tmp = t_0;
} else if (x <= 0.055) {
tmp = (x * 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 + z)
if (x <= (-92.0d0)) then
tmp = t_0
else if (x <= 0.055d0) then
tmp = (x * 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 + z);
double tmp;
if (x <= -92.0) {
tmp = t_0;
} else if (x <= 0.055) {
tmp = (x * y) + -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -92.0: tmp = t_0 elif x <= 0.055: tmp = (x * y) + -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -92.0) tmp = t_0; elseif (x <= 0.055) tmp = Float64(Float64(x * y) + Float64(-z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + z); tmp = 0.0; if (x <= -92.0) tmp = t_0; elseif (x <= 0.055) tmp = (x * y) + -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -92.0], t$95$0, If[LessEqual[x, 0.055], N[(N[(x * y), $MachinePrecision] + (-z)), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -92:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.055:\\
\;\;\;\;x \cdot y + \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -92 or 0.0550000000000000003 < x Initial program 94.8%
Taylor expanded in x around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.3
Applied rewrites98.3%
if -92 < x < 0.0550000000000000003Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6499.3
Applied rewrites99.3%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -1.5e-24) t_0 (if (<= x 1.7e-80) (- z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -1.5e-24) {
tmp = t_0;
} else if (x <= 1.7e-80) {
tmp = -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 + z)
if (x <= (-1.5d-24)) then
tmp = t_0
else if (x <= 1.7d-80) then
tmp = -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 + z);
double tmp;
if (x <= -1.5e-24) {
tmp = t_0;
} else if (x <= 1.7e-80) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -1.5e-24: tmp = t_0 elif x <= 1.7e-80: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -1.5e-24) tmp = t_0; elseif (x <= 1.7e-80) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + z); tmp = 0.0; if (x <= -1.5e-24) tmp = t_0; elseif (x <= 1.7e-80) tmp = -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.5e-24], t$95$0, If[LessEqual[x, 1.7e-80], (-z), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -1.5 \cdot 10^{-24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-80}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.49999999999999998e-24 or 1.7e-80 < x Initial program 95.6%
Taylor expanded in x around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6493.0
Applied rewrites93.0%
if -1.49999999999999998e-24 < x < 1.7e-80Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6476.2
Applied rewrites76.2%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (<= x -0.00031) (* x z) (if (<= x 13.8) (- z) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.00031) {
tmp = x * z;
} else if (x <= 13.8) {
tmp = -z;
} 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 <= (-0.00031d0)) then
tmp = x * z
else if (x <= 13.8d0) then
tmp = -z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.00031) {
tmp = x * z;
} else if (x <= 13.8) {
tmp = -z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.00031: tmp = x * z elif x <= 13.8: tmp = -z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.00031) tmp = Float64(x * z); elseif (x <= 13.8) tmp = Float64(-z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.00031) tmp = x * z; elseif (x <= 13.8) tmp = -z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.00031], N[(x * z), $MachinePrecision], If[LessEqual[x, 13.8], (-z), N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00031:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 13.8:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -3.1e-4 or 13.800000000000001 < x Initial program 94.8%
Taylor expanded in y around 0
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6455.5
Applied rewrites55.5%
Taylor expanded in x around inf
Applied rewrites53.8%
if -3.1e-4 < x < 13.800000000000001Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6468.3
Applied rewrites68.3%
Final simplification60.7%
(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.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6434.2
Applied rewrites34.2%
(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 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.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6434.2
Applied rewrites34.2%
Applied rewrites2.6%
herbie shell --seed 2024220
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))