
(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 1e+308) 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 <= 1e+308) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (x * y) + ((x + (-1.0d0)) * z)
if (t_0 <= 1d+308) then
tmp = t_0
else
tmp = x * (y + z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * y) + ((x + -1.0) * z);
double tmp;
if (t_0 <= 1e+308) {
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 <= 1e+308: 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 <= 1e+308) 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 <= 1e+308) 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, 1e+308], 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 10^{+308}:\\
\;\;\;\;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)) < 1e308Initial program 100.0%
if 1e308 < (+.f64 (*.f64 x y) (*.f64 (-.f64 x #s(literal 1 binary64)) z)) Initial program 85.3%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -490.0) t_0 (if (<= x 1.0) (- (* x y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -490.0) {
tmp = t_0;
} else if (x <= 1.0) {
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 <= (-490.0d0)) then
tmp = t_0
else if (x <= 1.0d0) 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 <= -490.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = (x * y) - z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -490.0: tmp = t_0 elif x <= 1.0: 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 <= -490.0) tmp = t_0; elseif (x <= 1.0) tmp = Float64(Float64(x * y) - 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 <= -490.0) tmp = t_0; elseif (x <= 1.0) 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, -490.0], t$95$0, If[LessEqual[x, 1.0], 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 -490:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;x \cdot y - z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -490 or 1 < x Initial program 96.3%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6498.6
Simplified98.6%
if -490 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6498.8
Simplified98.8%
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6498.8
Applied egg-rr98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y z)))) (if (<= x -1.35e-25) t_0 (if (<= x 5.5e-64) (- z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -1.35e-25) {
tmp = t_0;
} else if (x <= 5.5e-64) {
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.35d-25)) then
tmp = t_0
else if (x <= 5.5d-64) 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.35e-25) {
tmp = t_0;
} else if (x <= 5.5e-64) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -1.35e-25: tmp = t_0 elif x <= 5.5e-64: 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.35e-25) tmp = t_0; elseif (x <= 5.5e-64) 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.35e-25) tmp = t_0; elseif (x <= 5.5e-64) 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.35e-25], t$95$0, If[LessEqual[x, 5.5e-64], (-z), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{-25}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-64}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.35000000000000008e-25 or 5.4999999999999999e-64 < x Initial program 96.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6495.0
Simplified95.0%
if -1.35000000000000008e-25 < x < 5.4999999999999999e-64Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6477.8
Simplified77.8%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.2) (* x z) (if (<= x 4.2e-91) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2) {
tmp = x * z;
} else if (x <= 4.2e-91) {
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.2d0)) then
tmp = x * z
else if (x <= 4.2d-91) 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.2) {
tmp = x * z;
} else if (x <= 4.2e-91) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.2: tmp = x * z elif x <= 4.2e-91: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.2) tmp = Float64(x * z); elseif (x <= 4.2e-91) 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.2) tmp = x * z; elseif (x <= 4.2e-91) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.2], N[(x * z), $MachinePrecision], If[LessEqual[x, 4.2e-91], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-91}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.19999999999999996Initial program 96.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6499.0
Simplified99.0%
Taylor expanded in z around inf
*-commutativeN/A
*-lowering-*.f6457.1
Simplified57.1%
if -1.19999999999999996 < x < 4.1999999999999998e-91Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6476.5
Simplified76.5%
if 4.1999999999999998e-91 < x Initial program 96.6%
Taylor expanded in y around inf
*-lowering-*.f6453.6
Simplified53.6%
Final simplification63.9%
(FPCore (x y z) :precision binary64 (if (<= x -7e-5) (* x y) (if (<= x 4.2e-91) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7e-5) {
tmp = x * y;
} else if (x <= 4.2e-91) {
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 <= (-7d-5)) then
tmp = x * y
else if (x <= 4.2d-91) 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 <= -7e-5) {
tmp = x * y;
} else if (x <= 4.2e-91) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7e-5: tmp = x * y elif x <= 4.2e-91: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7e-5) tmp = Float64(x * y); elseif (x <= 4.2e-91) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7e-5) tmp = x * y; elseif (x <= 4.2e-91) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7e-5], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.2e-91], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-5}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-91}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -6.9999999999999994e-5 or 4.1999999999999998e-91 < x Initial program 96.7%
Taylor expanded in y around inf
*-lowering-*.f6451.9
Simplified51.9%
if -6.9999999999999994e-5 < x < 4.1999999999999998e-91Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6477.3
Simplified77.3%
(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 98.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6435.1
Simplified35.1%
(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 98.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6435.1
Simplified35.1%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
neg-sub0N/A
cube-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow12.7
Applied egg-rr2.7%
herbie shell --seed 2024198
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))